2 * Copyright (C) 1991, NeXT Computer, Inc. All Rights Reserverd.
5 * Author: Avadis Tevanian, Jr.
7 * File system exerciser.
9 * Rewritten 8/98 by Conrad Minshall.
11 * Small changes to work under Linux -- davej.
13 * Checks for mmap last-page zero fill.
42 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
46 enum opflags { FL_NONE = 0, FL_SKIPPED = 1, FL_CLOSE_OPEN = 2, FL_KEEP_SIZE = 4 };
49 * A log entry is an operation and a bunch of arguments.
60 struct log_entry oplog[LOGSIZE]; /* the log */
61 int logptr = 0; /* current position in log */
62 int logcount = 0; /* total ops */
65 * The operation matrix is complex due to conditional execution of different
66 * features. Hence when we come to deciding what operation to run, we need to
67 * be careful in how we select the different operations. The active operations
68 * are mapped to numbers as follows:
70 * lite !lite integrity
79 * COLLAPSE RANGE: - 8 8
82 * When mapped read/writes are disabled, they are simply converted to normal
83 * reads and writes. When fallocate/fpunch calls are disabled, they are
86 * Because of the "lite" version, we also need to have different "maximum
87 * operation" defines to allow the ops to be selected correctly based on the
91 /* common operations */
98 /* !lite operations */
100 #define OP_FALLOCATE 5
101 #define OP_PUNCH_HOLE 6
102 #define OP_ZERO_RANGE 7
103 #define OP_COLLAPSE_RANGE 8
104 #define OP_INSERT_RANGE 9
105 #define OP_MAX_FULL 10
107 /* integrity operations */
109 #define OP_MAX_INTEGRITY 11
112 #define PAGE_SIZE getpagesize()
114 #define PAGE_MASK (PAGE_SIZE - 1)
116 char *original_buf; /* a pointer to the original data */
117 char *good_buf; /* a pointer to the correct data */
118 char *temp_buf; /* a pointer to the current data */
119 char *fname; /* name of our test file */
120 char *bname; /* basename of our test file */
121 char *logdev; /* -i flag */
122 char *logid; /* -j flag */
123 char dname[1024]; /* -P flag */
124 int dirpath = 0; /* -P flag */
125 int fd; /* fd for our test file */
127 blksize_t block_size = 0;
130 unsigned long testcalls = 0; /* calls to function "test" */
132 unsigned long simulatedopcount = 0; /* -b flag */
133 int closeprob = 0; /* -c flag */
134 int debug = 0; /* -d flag */
135 unsigned long debugstart = 0; /* -D flag */
136 char filldata = 0; /* -g flag */
137 int flush = 0; /* -f flag */
138 int do_fsync = 0; /* -y flag */
139 unsigned long maxfilelen = 256 * 1024; /* -l flag */
140 int sizechecks = 1; /* -n flag disables them */
141 int maxoplen = 64 * 1024; /* -o flag */
142 int quiet = 0; /* -q flag */
143 unsigned long progressinterval = 0; /* -p flag */
144 int readbdy = 1; /* -r flag */
145 int style = 0; /* -s flag */
146 int prealloc = 0; /* -x flag */
147 int truncbdy = 1; /* -t flag */
148 int writebdy = 1; /* -w flag */
149 long monitorstart = -1; /* -m flag */
150 long monitorend = -1; /* -m flag */
151 int lite = 0; /* -L flag */
152 long numops = -1; /* -N flag */
153 int randomoplen = 1; /* -O flag disables it */
154 int seed = 1; /* -S flag */
155 int mapped_writes = 1; /* -W flag disables */
156 int fallocate_calls = 1; /* -F flag disables */
157 int keep_size_calls = 1; /* -K flag disables */
158 int punch_hole_calls = 1; /* -H flag disables */
159 int zero_range_calls = 1; /* -z flag disables */
160 int collapse_range_calls = 1; /* -C flag disables */
161 int insert_range_calls = 1; /* -I flag disables */
162 int mapped_reads = 1; /* -R flag disables it */
163 int integrity = 0; /* -i flag */
165 int o_direct; /* -Z */
173 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
176 #define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d)
177 #define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d)
179 #define fsxread(a,b,c,d) read(a,b,c)
180 #define fsxwrite(a,b,c,d) write(a,b,c)
183 const char *replayops = NULL;
184 const char *recordops = NULL;
185 FILE * fsxlogf = NULL;
186 FILE * replayopsf = NULL;
191 static void *round_ptr_up(void *ptr, unsigned long align, unsigned long offset)
193 unsigned long ret = (unsigned long)ptr;
195 ret = ((ret + align - 1) & ~(align - 1));
201 vwarnc(int code, const char *fmt, va_list ap)
204 fprintf(stderr, "%s: ", logid);
205 fprintf(stderr, "fsx: ");
207 vfprintf(stderr, fmt, ap);
208 fprintf(stderr, ": ");
210 fprintf(stderr, "%s\n", strerror(code));
214 warn(const char * fmt, ...) {
217 vwarnc(errno, fmt, ap);
222 prt(const char *fmt, ...)
227 fprintf(stdout, "%s: ", logid);
229 vfprintf(stdout, fmt, args);
233 vfprintf(fsxlogf, fmt, args);
239 prterr(const char *prefix)
241 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
245 static const char *op_names[] = {
247 [OP_WRITE] = "write",
248 [OP_MAPREAD] = "mapread",
249 [OP_MAPWRITE] = "mapwrite",
250 [OP_TRUNCATE] = "truncate",
251 [OP_FALLOCATE] = "fallocate",
252 [OP_PUNCH_HOLE] = "punch_hole",
253 [OP_ZERO_RANGE] = "zero_range",
254 [OP_COLLAPSE_RANGE] = "collapse_range",
255 [OP_INSERT_RANGE] = "insert_range",
256 [OP_FSYNC] = "fsync",
259 static const char *op_name(int operation)
261 if (operation >= 0 &&
262 operation < sizeof(op_names) / sizeof(op_names[0]))
263 return op_names[operation];
267 static int op_code(const char *name)
271 for (i = 0; i < sizeof(op_names) / sizeof(op_names[0]); i++)
272 if (op_names[i] && strcmp(name, op_names[i]) == 0)
278 log4(int operation, int arg0, int arg1, enum opflags flags)
280 struct log_entry *le;
283 le->operation = operation;
285 flags |= FL_CLOSE_OPEN;
288 le->args[2] = file_size;
292 if (logptr >= LOGSIZE)
302 struct log_entry *lp;
304 prt("LOG DUMP (%d total operations):\n", logcount);
306 logopsf = fopen(opsfile, "w");
310 if (logcount < LOGSIZE) {
317 for ( ; count > 0; count--) {
321 opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
322 prt("%d(%3d mod 256): ", opnum, opnum%256);
325 overlap = badoff >= lp->args[0] &&
326 badoff < lp->args[0] + lp->args[1];
328 if (lp->flags & FL_SKIPPED) {
329 prt("SKIPPED (no operation)");
333 switch (lp->operation) {
335 prt("MAPREAD 0x%x thru 0x%x\t(0x%x bytes)",
336 lp->args[0], lp->args[0] + lp->args[1] - 1,
342 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
343 lp->args[0], lp->args[0] + lp->args[1] - 1,
349 prt("READ 0x%x thru 0x%x\t(0x%x bytes)",
350 lp->args[0], lp->args[0] + lp->args[1] - 1,
356 prt("WRITE 0x%x thru 0x%x\t(0x%x bytes)",
357 lp->args[0], lp->args[0] + lp->args[1] - 1,
359 if (lp->args[0] > lp->args[2])
361 else if (lp->args[0] + lp->args[1] > lp->args[2])
363 overlap = (badoff >= lp->args[0] ||
364 badoff >=lp->args[2]) &&
365 badoff < lp->args[0] + lp->args[1];
370 down = lp->args[1] < lp->args[2];
371 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
372 down ? "DOWN" : "UP", lp->args[2], lp->args[1]);
373 overlap = badoff >= lp->args[1 + !down] &&
374 badoff < lp->args[1 + !!down];
379 /* 0: offset 1: length 2: where alloced */
380 prt("FALLOC 0x%x thru 0x%x\t(0x%x bytes) ",
381 lp->args[0], lp->args[0] + lp->args[1],
383 if (lp->args[0] + lp->args[1] <= lp->args[2])
385 else if (lp->flags & FL_KEEP_SIZE)
393 prt("PUNCH 0x%x thru 0x%x\t(0x%x bytes)",
394 lp->args[0], lp->args[0] + lp->args[1] - 1,
400 prt("ZERO 0x%x thru 0x%x\t(0x%x bytes)",
401 lp->args[0], lp->args[0] + lp->args[1] - 1,
406 case OP_COLLAPSE_RANGE:
407 prt("COLLAPSE 0x%x thru 0x%x\t(0x%x bytes)",
408 lp->args[0], lp->args[0] + lp->args[1] - 1,
413 case OP_INSERT_RANGE:
414 prt("INSERT 0x%x thru 0x%x\t(0x%x bytes)",
415 lp->args[0], lp->args[0] + lp->args[1] - 1,
424 prt("BOGUS LOG ENTRY (operation code = %d)!",
430 if (lp->flags & FL_CLOSE_OPEN)
431 prt("\n\t\tCLOSE/OPEN");
438 if (lp->flags & FL_SKIPPED)
439 fprintf(logopsf, "skip ");
440 fprintf(logopsf, "%s 0x%x 0x%x 0x%x",
441 op_name(lp->operation),
442 lp->args[0], lp->args[1], lp->args[2]);
443 if (lp->flags & FL_KEEP_SIZE)
444 fprintf(logopsf, " keep_size");
445 if (lp->flags & FL_CLOSE_OPEN)
446 fprintf(logopsf, " close_open");
448 fprintf(logopsf, " *");
449 fprintf(logopsf, "\n");
454 if (fclose(logopsf) != 0)
457 prt("Log of operations saved to \"%s\"; "
458 "replay with --replay-ops\n",
465 save_buffer(char *buffer, off_t bufferlength, int fd)
468 ssize_t byteswritten;
470 if (fd <= 0 || bufferlength == 0)
473 if (bufferlength > SSIZE_MAX) {
474 prt("fsx flaw: overflow in save_buffer\n");
478 off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
479 if (size_by_seek == (off_t)-1)
480 prterr("save_buffer: lseek eof");
481 else if (bufferlength > size_by_seek) {
482 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
483 (unsigned long long)bufferlength);
484 bufferlength = size_by_seek;
488 ret = lseek(fd, (off_t)0, SEEK_SET);
489 if (ret == (off_t)-1)
490 prterr("save_buffer: lseek 0");
492 byteswritten = write(fd, buffer, (size_t)bufferlength);
493 if (byteswritten != bufferlength) {
494 if (byteswritten == -1)
495 prterr("save_buffer write");
497 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
498 (unsigned)byteswritten,
499 (unsigned long long)bufferlength);
505 report_failure(int status)
511 save_buffer(good_buf, file_size, fsxgoodfd);
512 prt("Correct content saved for comparison\n");
513 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
522 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
523 *(((unsigned char *)(cp)) + 1)))
531 snprintf(command, 256, "dmsetup message %s 0 mark %s.mark%d", logdev,
533 ret = system(command);
535 prterr("dmsetup mark failed");
541 dump_fsync_buffer(void)
543 char fname_buffer[1024];
549 snprintf(fname_buffer, 1024, "%s%s.mark%d", dname,
551 good_fd = open(fname_buffer, O_WRONLY|O_CREAT|O_TRUNC, 0666);
553 prterr(fname_buffer);
557 save_buffer(good_buf, file_size, good_fd);
559 prt("Dumped fsync buffer to %s\n", fname_buffer + dirpath);
563 check_buffers(unsigned offset, unsigned size)
571 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
572 prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
573 offset, size, fname);
574 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
576 c = good_buf[offset];
580 bad = short_at(&temp_buf[i]);
581 prt("0x%05x\t0x%04x\t0x%04x", offset,
582 short_at(&good_buf[offset]), bad);
583 op = temp_buf[offset & 1 ? i+1 : i];
584 prt("\t0x%05x\n", n);
586 prt("operation# (mod 256) for "
587 "the bad data may be %u\n",
588 ((unsigned)op & 0xff));
590 prt("operation# (mod 256) for "
591 "the bad data unknown, check"
592 " HOLE and EXTEND ops\n");
612 if (fstat(fd, &statbuf)) {
613 prterr("check_size: fstat");
614 statbuf.st_size = -1;
616 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
617 if (file_size != statbuf.st_size || file_size != size_by_seek) {
618 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
619 (unsigned long long)file_size,
620 (unsigned long long)statbuf.st_size,
621 (unsigned long long)size_by_seek);
628 check_trunc_hack(void)
631 off_t offset = file_size + (off_t)100000;
633 if (ftruncate(fd, file_size))
635 if (ftruncate(fd, offset))
638 if (statbuf.st_size != offset) {
639 prt("no extend on truncate! not posix!\n");
642 if (ftruncate(fd, file_size)) {
644 prterr("check_trunc_hack: ftruncate");
650 doflush(unsigned offset, unsigned size)
656 if (o_direct == O_DIRECT)
659 pg_offset = offset & mmap_mask;
660 map_size = pg_offset + size;
662 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
663 MAP_FILE | MAP_SHARED, fd,
664 (off_t)(offset - pg_offset))) == (char *)-1) {
665 prterr("doflush: mmap");
668 if (msync(p, map_size, MS_INVALIDATE) != 0) {
669 prterr("doflush: msync");
672 if (munmap(p, map_size) != 0) {
673 prterr("doflush: munmap");
679 doread(unsigned offset, unsigned size)
684 offset -= offset % readbdy;
686 size -= size % readbdy;
688 if (!quiet && testcalls > simulatedopcount && !o_direct)
689 prt("skipping zero size read\n");
690 log4(OP_READ, offset, size, FL_SKIPPED);
693 if (size + offset > file_size) {
694 if (!quiet && testcalls > simulatedopcount)
695 prt("skipping seek/read past end of file\n");
696 log4(OP_READ, offset, size, FL_SKIPPED);
700 log4(OP_READ, offset, size, FL_NONE);
702 if (testcalls <= simulatedopcount)
706 ((progressinterval && testcalls % progressinterval == 0) ||
708 (monitorstart == -1 ||
709 (offset + size > monitorstart &&
710 (monitorend == -1 || offset <= monitorend))))))
711 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
712 offset, offset + size - 1, size);
713 ret = lseek(fd, (off_t)offset, SEEK_SET);
714 if (ret == (off_t)-1) {
715 prterr("doread: lseek");
718 iret = fsxread(fd, temp_buf, size, offset);
721 prterr("doread: read");
723 prt("short read: 0x%x bytes instead of 0x%x\n",
727 check_buffers(offset, size);
732 check_eofpage(char *s, unsigned offset, char *p, int size)
734 unsigned long last_page, should_be_zero;
736 if (offset + size <= (file_size & ~page_mask))
739 * we landed in the last page of the file
740 * test to make sure the VM system provided 0's
741 * beyond the true end of the file mapping
742 * (as required by mmap def in 1996 posix 1003.1)
744 last_page = ((unsigned long)p + (offset & page_mask) + size) & ~page_mask;
746 for (should_be_zero = last_page + (file_size & page_mask);
747 should_be_zero < last_page + page_size;
749 if (*(char *)should_be_zero) {
750 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
751 s, file_size - 1, should_be_zero & page_mask,
752 short_at(should_be_zero));
759 domapread(unsigned offset, unsigned size)
765 offset -= offset % readbdy;
767 if (!quiet && testcalls > simulatedopcount)
768 prt("skipping zero size read\n");
769 log4(OP_MAPREAD, offset, size, FL_SKIPPED);
772 if (size + offset > file_size) {
773 if (!quiet && testcalls > simulatedopcount)
774 prt("skipping seek/read past end of file\n");
775 log4(OP_MAPREAD, offset, size, FL_SKIPPED);
779 log4(OP_MAPREAD, offset, size, FL_NONE);
781 if (testcalls <= simulatedopcount)
785 ((progressinterval && testcalls % progressinterval == 0) ||
787 (monitorstart == -1 ||
788 (offset + size > monitorstart &&
789 (monitorend == -1 || offset <= monitorend))))))
790 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
791 offset, offset + size - 1, size);
793 pg_offset = offset & PAGE_MASK;
794 map_size = pg_offset + size;
796 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd,
797 (off_t)(offset - pg_offset))) == (char *)-1) {
798 prterr("domapread: mmap");
801 memcpy(temp_buf, p + pg_offset, size);
803 check_eofpage("Read", offset, p, size);
805 if (munmap(p, map_size) != 0) {
806 prterr("domapread: munmap");
810 check_buffers(offset, size);
815 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
819 good_buf[offset] = filldata;
821 good_buf[offset] = testcalls % 256;
823 good_buf[offset] += original_buf[offset];
831 dowrite(unsigned offset, unsigned size)
836 offset -= offset % writebdy;
838 size -= size % writebdy;
840 if (!quiet && testcalls > simulatedopcount && !o_direct)
841 prt("skipping zero size write\n");
842 log4(OP_WRITE, offset, size, FL_SKIPPED);
846 log4(OP_WRITE, offset, size, FL_NONE);
848 gendata(original_buf, good_buf, offset, size);
849 if (file_size < offset + size) {
850 if (file_size < offset)
851 memset(good_buf + file_size, '\0', offset - file_size);
852 file_size = offset + size;
854 warn("Lite file size bug in fsx!");
859 if (testcalls <= simulatedopcount)
863 ((progressinterval && testcalls % progressinterval == 0) ||
865 (monitorstart == -1 ||
866 (offset + size > monitorstart &&
867 (monitorend == -1 || offset <= monitorend))))))
868 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
869 offset, offset + size - 1, size);
870 ret = lseek(fd, (off_t)offset, SEEK_SET);
871 if (ret == (off_t)-1) {
872 prterr("dowrite: lseek");
875 iret = fsxwrite(fd, good_buf + offset, size, offset);
878 prterr("dowrite: write");
880 prt("short write: 0x%x bytes instead of 0x%x\n",
886 prt("fsync() failed: %s\n", strerror(errno));
891 doflush(offset, size);
897 domapwrite(unsigned offset, unsigned size)
904 offset -= offset % writebdy;
906 if (!quiet && testcalls > simulatedopcount)
907 prt("skipping zero size write\n");
908 log4(OP_MAPWRITE, offset, size, FL_SKIPPED);
911 cur_filesize = file_size;
913 log4(OP_MAPWRITE, offset, size, FL_NONE);
915 gendata(original_buf, good_buf, offset, size);
916 if (file_size < offset + size) {
917 if (file_size < offset)
918 memset(good_buf + file_size, '\0', offset - file_size);
919 file_size = offset + size;
921 warn("Lite file size bug in fsx!");
926 if (testcalls <= simulatedopcount)
930 ((progressinterval && testcalls % progressinterval == 0) ||
932 (monitorstart == -1 ||
933 (offset + size > monitorstart &&
934 (monitorend == -1 || offset <= monitorend))))))
935 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
936 offset, offset + size - 1, size);
938 if (file_size > cur_filesize) {
939 if (ftruncate(fd, file_size) == -1) {
940 prterr("domapwrite: ftruncate");
944 pg_offset = offset & PAGE_MASK;
945 map_size = pg_offset + size;
947 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
948 MAP_FILE | MAP_SHARED, fd,
949 (off_t)(offset - pg_offset))) == (char *)-1) {
950 prterr("domapwrite: mmap");
953 memcpy(p + pg_offset, good_buf + offset, size);
954 if (msync(p, map_size, MS_SYNC) != 0) {
955 prterr("domapwrite: msync");
959 check_eofpage("Write", offset, p, size);
961 if (munmap(p, map_size) != 0) {
962 prterr("domapwrite: munmap");
969 dotruncate(unsigned size)
971 int oldsize = file_size;
973 size -= size % truncbdy;
974 if (size > biggest) {
976 if (!quiet && testcalls > simulatedopcount)
977 prt("truncating to largest ever: 0x%x\n", size);
980 log4(OP_TRUNCATE, 0, size, FL_NONE);
982 if (size > file_size)
983 memset(good_buf + file_size, '\0', size - file_size);
986 if (testcalls <= simulatedopcount)
989 if ((progressinterval && testcalls % progressinterval == 0) ||
990 (debug && (monitorstart == -1 || monitorend == -1 ||
991 size <= monitorend)))
992 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
993 if (ftruncate(fd, (off_t)size) == -1) {
994 prt("ftruncate1: %x\n", size);
995 prterr("dotruncate: ftruncate");
1000 #ifdef FALLOC_FL_PUNCH_HOLE
1002 do_punch_hole(unsigned offset, unsigned length)
1004 unsigned end_offset;
1007 int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
1010 if (!quiet && testcalls > simulatedopcount)
1011 prt("skipping zero length punch hole\n");
1012 log4(OP_PUNCH_HOLE, offset, length, FL_SKIPPED);
1016 if (file_size <= (loff_t)offset) {
1017 if (!quiet && testcalls > simulatedopcount)
1018 prt("skipping hole punch off the end of the file\n");
1019 log4(OP_PUNCH_HOLE, offset, length, FL_SKIPPED);
1023 end_offset = offset + length;
1025 log4(OP_PUNCH_HOLE, offset, length, FL_NONE);
1027 if (testcalls <= simulatedopcount)
1030 if ((progressinterval && testcalls % progressinterval == 0) ||
1031 (debug && (monitorstart == -1 || monitorend == -1 ||
1032 end_offset <= monitorend))) {
1033 prt("%lu punch\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1034 offset, offset+length, length);
1036 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1037 prt("punch hole: 0x%x to 0x%x\n", offset, offset + length);
1038 prterr("do_punch_hole: fallocate");
1039 report_failure(161);
1043 max_offset = offset < file_size ? offset : file_size;
1044 max_len = max_offset + length <= file_size ? length :
1045 file_size - max_offset;
1046 memset(good_buf + max_offset, '\0', max_len);
1051 do_punch_hole(unsigned offset, unsigned length)
1057 #ifdef FALLOC_FL_ZERO_RANGE
1059 do_zero_range(unsigned offset, unsigned length, int keep_size)
1061 unsigned end_offset;
1062 int mode = FALLOC_FL_ZERO_RANGE;
1065 if (!quiet && testcalls > simulatedopcount)
1066 prt("skipping zero length zero range\n");
1067 log4(OP_ZERO_RANGE, offset, length, FL_SKIPPED |
1068 (keep_size ? FL_KEEP_SIZE : FL_NONE));
1072 end_offset = keep_size ? 0 : offset + length;
1074 if (end_offset > biggest) {
1075 biggest = end_offset;
1076 if (!quiet && testcalls > simulatedopcount)
1077 prt("zero_range to largest ever: 0x%x\n", end_offset);
1081 * last arg matches fallocate string array index in logdump:
1082 * 0: allocate past EOF
1083 * 1: extending prealloc
1084 * 2: interior prealloc
1086 log4(OP_ZERO_RANGE, offset, length,
1087 keep_size ? FL_KEEP_SIZE : FL_NONE);
1089 if (testcalls <= simulatedopcount)
1092 if ((progressinterval && testcalls % progressinterval == 0) ||
1093 (debug && (monitorstart == -1 || monitorend == -1 ||
1094 end_offset <= monitorend))) {
1095 prt("%lu zero\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1096 offset, offset+length, length);
1098 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1099 prt("zero range: 0x%x to 0x%x\n", offset, offset + length);
1100 prterr("do_zero_range: fallocate");
1101 report_failure(161);
1104 memset(good_buf + offset, '\0', length);
1109 do_zero_range(unsigned offset, unsigned length, int keep_size)
1115 #ifdef FALLOC_FL_COLLAPSE_RANGE
1117 do_collapse_range(unsigned offset, unsigned length)
1119 unsigned end_offset;
1120 int mode = FALLOC_FL_COLLAPSE_RANGE;
1123 if (!quiet && testcalls > simulatedopcount)
1124 prt("skipping zero length collapse range\n");
1125 log4(OP_COLLAPSE_RANGE, offset, length, FL_SKIPPED);
1129 end_offset = offset + length;
1130 if ((loff_t)end_offset >= file_size) {
1131 if (!quiet && testcalls > simulatedopcount)
1132 prt("skipping collapse range behind EOF\n");
1133 log4(OP_COLLAPSE_RANGE, offset, length, FL_SKIPPED);
1137 log4(OP_COLLAPSE_RANGE, offset, length, FL_NONE);
1139 if (testcalls <= simulatedopcount)
1142 if ((progressinterval && testcalls % progressinterval == 0) ||
1143 (debug && (monitorstart == -1 || monitorend == -1 ||
1144 end_offset <= monitorend))) {
1145 prt("%lu collapse\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1146 offset, offset+length, length);
1148 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1149 prt("collapse range: 0x%x to 0x%x\n", offset, offset + length);
1150 prterr("do_collapse_range: fallocate");
1151 report_failure(161);
1154 memmove(good_buf + offset, good_buf + end_offset,
1155 file_size - end_offset);
1156 file_size -= length;
1161 do_collapse_range(unsigned offset, unsigned length)
1167 #ifdef FALLOC_FL_INSERT_RANGE
1169 do_insert_range(unsigned offset, unsigned length)
1171 unsigned end_offset;
1172 int mode = FALLOC_FL_INSERT_RANGE;
1175 if (!quiet && testcalls > simulatedopcount)
1176 prt("skipping zero length insert range\n");
1177 log4(OP_INSERT_RANGE, offset, length, FL_SKIPPED);
1181 if ((loff_t)offset >= file_size) {
1182 if (!quiet && testcalls > simulatedopcount)
1183 prt("skipping insert range behind EOF\n");
1184 log4(OP_INSERT_RANGE, offset, length, FL_SKIPPED);
1188 log4(OP_INSERT_RANGE, offset, length, FL_NONE);
1190 if (testcalls <= simulatedopcount)
1193 end_offset = offset + length;
1194 if ((progressinterval && testcalls % progressinterval == 0) ||
1195 (debug && (monitorstart == -1 || monitorend == -1 ||
1196 end_offset <= monitorend))) {
1197 prt("%lu insert\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1198 offset, offset+length, length);
1200 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1201 prt("insert range: 0x%x to 0x%x\n", offset, offset + length);
1202 prterr("do_insert_range: fallocate");
1203 report_failure(161);
1206 memmove(good_buf + end_offset, good_buf + offset,
1207 file_size - offset);
1208 memset(good_buf + offset, '\0', length);
1209 file_size += length;
1214 do_insert_range(unsigned offset, unsigned length)
1220 #ifdef HAVE_LINUX_FALLOC_H
1221 /* fallocate is basically a no-op unless extending, then a lot like a truncate */
1223 do_preallocate(unsigned offset, unsigned length, int keep_size)
1225 unsigned end_offset;
1228 if (!quiet && testcalls > simulatedopcount)
1229 prt("skipping zero length fallocate\n");
1230 log4(OP_FALLOCATE, offset, length, FL_SKIPPED |
1231 (keep_size ? FL_KEEP_SIZE : FL_NONE));
1235 end_offset = keep_size ? 0 : offset + length;
1237 if (end_offset > biggest) {
1238 biggest = end_offset;
1239 if (!quiet && testcalls > simulatedopcount)
1240 prt("fallocating to largest ever: 0x%x\n", end_offset);
1244 * last arg matches fallocate string array index in logdump:
1245 * 0: allocate past EOF
1246 * 1: extending prealloc
1247 * 2: interior prealloc
1249 log4(OP_FALLOCATE, offset, length,
1250 keep_size ? FL_KEEP_SIZE : FL_NONE);
1252 if (end_offset > file_size) {
1253 memset(good_buf + file_size, '\0', end_offset - file_size);
1254 file_size = end_offset;
1257 if (testcalls <= simulatedopcount)
1260 if ((progressinterval && testcalls % progressinterval == 0) ||
1261 (debug && (monitorstart == -1 || monitorend == -1 ||
1262 end_offset <= monitorend)))
1263 prt("%lu falloc\tfrom 0x%x to 0x%x (0x%x bytes)\n", testcalls,
1264 offset, offset + length, length);
1265 if (fallocate(fd, keep_size ? FALLOC_FL_KEEP_SIZE : 0, (loff_t)offset, (loff_t)length) == -1) {
1266 prt("fallocate: 0x%x to 0x%x\n", offset, offset + length);
1267 prterr("do_preallocate: fallocate");
1268 report_failure(161);
1273 do_preallocate(unsigned offset, unsigned length, int keep_size)
1284 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
1285 prterr("writefileimage: lseek");
1286 report_failure(171);
1288 iret = write(fd, good_buf, file_size);
1289 if ((off_t)iret != file_size) {
1291 prterr("writefileimage: write");
1293 prt("short write: 0x%x bytes instead of 0x%llx\n",
1294 iret, (unsigned long long)file_size);
1295 report_failure(172);
1297 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
1298 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
1299 prterr("writefileimage: ftruncate");
1300 report_failure(173);
1308 if (testcalls <= simulatedopcount)
1312 prt("%lu close/open\n", testcalls);
1314 prterr("docloseopen: close");
1315 report_failure(180);
1317 fd = open(fname, O_RDWR|o_direct, 0);
1319 prterr("docloseopen: open");
1320 report_failure(181);
1329 if (testcalls <= simulatedopcount)
1332 prt("%lu fsync\n", testcalls);
1333 log4(OP_FSYNC, 0, 0, 0);
1337 report_failure(210);
1340 dump_fsync_buffer();
1344 #define TRIM_OFF(off, size) \
1352 #define TRIM_LEN(off, len, size) \
1354 if ((off) + (len) > (size)) \
1355 (len) = (size) - (off); \
1358 #define TRIM_OFF_LEN(off, len, size) \
1360 TRIM_OFF(off, size); \
1361 TRIM_LEN(off, len, size); \
1368 prt("signal %d\n", sig);
1369 prt("testcalls = %lu\n", testcalls);
1374 read_op(struct log_entry *log_entry)
1378 memset(log_entry, 0, sizeof(*log_entry));
1379 log_entry->operation = -1;
1381 while (log_entry->operation == -1) {
1386 if (!fgets(line, sizeof(line), replayopsf)) {
1387 if (feof(replayopsf)) {
1393 str = strtok(line, " \t\n");
1396 if (strcmp(str, "skip") == 0) {
1397 log_entry->flags |= FL_SKIPPED;
1398 str = strtok(NULL, " \t\n");
1402 log_entry->operation = op_code(str);
1403 if (log_entry->operation == -1)
1405 for (i = 0; i < 3; i++) {
1408 str = strtok(NULL, " \t\n");
1411 log_entry->args[i] = strtoul(str, &end, 0);
1415 while ((str = strtok(NULL, " \t\n"))) {
1416 if (strcmp(str, "keep_size") == 0)
1417 log_entry->flags |= FL_KEEP_SIZE;
1418 else if (strcmp(str, "close_open") == 0)
1419 log_entry->flags |= FL_CLOSE_OPEN;
1420 else if (strcmp(str, "*") == 0)
1421 ; /* overlap marker; ignore */
1429 fprintf(stderr, "%s: parse error\n", replayops);
1432 cleanup(100); /* doesn't return */
1440 unsigned long offset;
1446 if (simulatedopcount > 0 && testcalls == simulatedopcount)
1451 if (debugstart > 0 && testcalls >= debugstart)
1454 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
1455 prt("%lu...\n", testcalls);
1458 struct log_entry log_entry;
1460 while (read_op(&log_entry)) {
1461 if (log_entry.flags & FL_SKIPPED) {
1462 log4(log_entry.operation,
1463 log_entry.args[0], log_entry.args[1],
1468 op = log_entry.operation;
1469 offset = log_entry.args[0];
1470 size = log_entry.args[1];
1471 closeopen = !!(log_entry.flags & FL_CLOSE_OPEN);
1472 keep_size = !!(log_entry.flags & FL_KEEP_SIZE);
1480 closeopen = (rv >> 3) < (1 << 28) / closeprob;
1485 size = random() % (maxoplen + 1);
1487 /* calculate appropriate op to run */
1489 op = rv % OP_MAX_LITE;
1490 else if (!integrity)
1491 op = rv % OP_MAX_FULL;
1493 op = rv % OP_MAX_INTEGRITY;
1498 size = random() % maxfilelen;
1501 if (fallocate_calls && size && keep_size_calls)
1502 keep_size = random() % 2;
1505 if (zero_range_calls && size && keep_size_calls)
1506 keep_size = random() % 2;
1522 if (!fallocate_calls) {
1523 log4(OP_FALLOCATE, offset, size, FL_SKIPPED);
1528 if (!punch_hole_calls) {
1529 log4(OP_PUNCH_HOLE, offset, size, FL_SKIPPED);
1534 if (!zero_range_calls) {
1535 log4(OP_ZERO_RANGE, offset, size, FL_SKIPPED);
1539 case OP_COLLAPSE_RANGE:
1540 if (!collapse_range_calls) {
1541 log4(OP_COLLAPSE_RANGE, offset, size, FL_SKIPPED);
1545 case OP_INSERT_RANGE:
1546 if (!insert_range_calls) {
1547 log4(OP_INSERT_RANGE, offset, size, FL_SKIPPED);
1555 TRIM_OFF_LEN(offset, size, file_size);
1556 doread(offset, size);
1560 TRIM_OFF_LEN(offset, size, maxfilelen);
1561 dowrite(offset, size);
1565 TRIM_OFF_LEN(offset, size, file_size);
1566 domapread(offset, size);
1570 TRIM_OFF_LEN(offset, size, maxfilelen);
1571 domapwrite(offset, size);
1579 TRIM_OFF_LEN(offset, size, maxfilelen);
1580 do_preallocate(offset, size, keep_size);
1584 TRIM_OFF_LEN(offset, size, file_size);
1585 do_punch_hole(offset, size);
1588 TRIM_OFF_LEN(offset, size, file_size);
1589 do_zero_range(offset, size, keep_size);
1591 case OP_COLLAPSE_RANGE:
1592 TRIM_OFF_LEN(offset, size, file_size - 1);
1593 offset = offset & ~(block_size - 1);
1594 size = size & ~(block_size - 1);
1596 log4(OP_COLLAPSE_RANGE, offset, size, FL_SKIPPED);
1599 do_collapse_range(offset, size);
1601 case OP_INSERT_RANGE:
1602 TRIM_OFF(offset, file_size);
1603 TRIM_LEN(file_size, size, maxfilelen);
1604 offset = offset & ~(block_size - 1);
1605 size = size & ~(block_size - 1);
1607 log4(OP_INSERT_RANGE, offset, size, FL_SKIPPED);
1610 if (file_size + size > maxfilelen) {
1611 log4(OP_INSERT_RANGE, offset, size, FL_SKIPPED);
1615 do_insert_range(offset, size);
1621 prterr("test: unknown operation");
1627 if (sizechecks && testcalls > simulatedopcount)
1638 fprintf(stdout, "usage: %s",
1639 "fsx [-dknqxAFLOWZ] [-b opnum] [-c Prob] [-g filldata] [-i logdev] [-j logid] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\
1640 -b opnum: beginning operation number (default 1)\n\
1641 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
1642 -d: debug output for all operations\n\
1643 -f flush and invalidate cache after I/O\n\
1644 -g X: write character X instead of random generated data\n\
1645 -i logdev: do integrity testing, logdev is the dm log writes device\n\
1646 -j logid: prefix debug log messsages with this id\n\
1647 -k: do not truncate existing file and use its size as upper bound on file size\n\
1648 -l flen: the upper bound on file size (default 262144)\n\
1649 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
1650 -n: no verifications of file size\n\
1651 -o oplen: the upper bound on operation size (default 65536)\n\
1652 -p progressinterval: debug output at specified operation interval\n\
1653 -q: quieter operation\n\
1654 -r readbdy: 4096 would make reads page aligned (default 1)\n\
1655 -s style: 1 gives smaller truncates (default 0)\n\
1656 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
1657 -w writebdy: 4096 would make writes page aligned (default 1)\n\
1658 -x: preallocate file space before starting, XFS only (default 0)\n\
1659 -y synchronize changes to a file\n"
1662 " -A: Use the AIO system calls\n"
1664 " -D startingop: debug output starting at specified operation\n"
1665 #ifdef HAVE_LINUX_FALLOC_H
1666 " -F: Do not use fallocate (preallocation) calls\n"
1668 #ifdef FALLOC_FL_PUNCH_HOLE
1669 " -H: Do not use punch hole calls\n"
1671 #ifdef FALLOC_FL_ZERO_RANGE
1672 " -z: Do not use zero range calls\n"
1674 #ifdef FALLOC_FL_COLLAPSE_RANGE
1675 " -C: Do not use collapse range calls\n"
1677 #ifdef FALLOC_FL_INSERT_RANGE
1678 " -I: Do not use insert range calls\n"
1680 " -L: fsxLite - no file creations & no file size changes\n\
1681 -N numops: total # operations to do (default infinity)\n\
1682 -O: use oplen (see -o flag) for every op (default random)\n\
1683 -P: save .fsxlog .fsxops and .fsxgood files in dirpath (default ./)\n\
1684 -S seed: for random # generator (default 1) 0 gets timestamp\n\
1685 -W: mapped write operations DISabled\n\
1686 -R: read() system calls only (mapped reads disabled)\n\
1687 -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
1688 --replay-ops opsfile: replay ops from recorded .fsxops file\n\
1689 --record-ops[=opsfile]: dump ops file also on success. optionally specify ops file name\n\
1690 fname: this filename is REQUIRED (no default)\n");
1696 getnum(char *s, char **e)
1701 ret = strtol(s, e, 0);
1731 io_context_t io_ctx;
1737 ret = io_queue_init(QSZ, &io_ctx);
1739 fprintf(stderr, "aio_setup: io_queue_init failed: %s\n",
1747 __aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
1749 struct io_event event;
1750 static struct timespec ts;
1751 struct iocb *iocbs[] = { &iocb };
1756 io_prep_pread(&iocb, fd, buf, len, offset);
1758 io_prep_pwrite(&iocb, fd, buf, len, offset);
1763 ret = io_submit(io_ctx, 1, iocbs);
1765 fprintf(stderr, "errcode=%d\n", ret);
1766 fprintf(stderr, "aio_rw: io_submit failed: %s\n",
1771 ret = io_getevents(io_ctx, 1, 1, &event, &ts);
1774 fprintf(stderr, "aio_rw: no events available\n");
1776 fprintf(stderr, "errcode=%d\n", -ret);
1777 fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
1782 if (len != event.res) {
1784 * The b0rked libaio defines event.res as unsigned.
1785 * However the kernel strucuture has it signed,
1786 * and it's used to pass negated error value.
1787 * Till the library is fixed use the temp var.
1789 res = (long)event.res;
1791 fprintf(stderr, "bad io length: %lu instead of %u\n",
1794 fprintf(stderr, "errcode=%ld\n", -res);
1795 fprintf(stderr, "aio_rw: async io failed: %s\n",
1806 * The caller expects error return in traditional libc
1807 * convention, i.e. -1 and the errno set to error.
1813 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
1818 ret = __aio_rw(rw, fd, buf, len, offset);
1821 ret = read(fd, buf, len);
1823 ret = write(fd, buf, len);
1830 #define test_fallocate(mode) __test_fallocate(mode, #mode)
1833 __test_fallocate(int mode, const char *mode_str)
1835 #ifdef HAVE_LINUX_FALLOC_H
1838 if (fallocate(fd, mode, file_size, 1) && errno == EOPNOTSUPP) {
1841 "main: filesystem does not support "
1842 "fallocate mode %s, disabling!\n",
1846 if (ftruncate(fd, file_size)) {
1847 warn("main: ftruncate");
1856 static struct option longopts[] = {
1857 {"replay-ops", required_argument, 0, 256},
1858 {"record-ops", optional_argument, 0, 255},
1863 main(int argc, char **argv)
1867 char goodfile[1024];
1869 struct stat statbuf;
1870 int o_flags = O_RDWR|O_CREAT|O_TRUNC;
1876 page_size = getpagesize();
1877 page_mask = page_size - 1;
1878 mmap_mask = page_mask;
1881 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1883 while ((ch = getopt_long(argc, argv,
1884 "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZ",
1885 longopts, NULL)) != EOF)
1888 simulatedopcount = getnum(optarg, &endp);
1890 prt("Will begin at operation %ld\n", simulatedopcount);
1891 if (simulatedopcount == 0)
1893 simulatedopcount -= 1;
1896 closeprob = getnum(optarg, &endp);
1898 prt("Chance of close/open is 1 in %d\n", closeprob);
1913 logdev = strdup(optarg);
1920 logid = strdup(optarg);
1927 o_flags &= ~O_TRUNC;
1930 maxfilelen = getnum(optarg, &endp);
1931 if (maxfilelen <= 0)
1935 monitorstart = getnum(optarg, &endp);
1936 if (monitorstart < 0)
1938 if (!endp || *endp++ != ':')
1940 monitorend = getnum(endp, &endp);
1943 if (monitorend == 0)
1944 monitorend = -1; /* aka infinity */
1950 maxoplen = getnum(optarg, &endp);
1955 progressinterval = getnum(optarg, &endp);
1956 if (progressinterval == 0)
1963 readbdy = getnum(optarg, &endp);
1968 style = getnum(optarg, &endp);
1969 if (style < 0 || style > 1)
1973 truncbdy = getnum(optarg, &endp);
1978 writebdy = getnum(optarg, &endp);
1992 debugstart = getnum(optarg, &endp);
1997 fallocate_calls = 0;
2000 keep_size_calls = 0;
2003 punch_hole_calls = 0;
2006 zero_range_calls = 0;
2009 collapse_range_calls = 0;
2012 insert_range_calls = 0;
2016 o_flags &= ~(O_CREAT|O_TRUNC);
2019 numops = getnum(optarg, &endp);
2027 strncpy(dname, optarg, sizeof(dname));
2029 dirpath = strlen(dname);
2031 strncpy(goodfile, dname, sizeof(goodfile));
2032 strncpy(logfile, dname, sizeof(logfile));
2033 strncpy(opsfile, dname, sizeof(logfile));
2039 seed = getnum(optarg, &endp);
2041 seed = time(0) % 10000;
2042 seed += (int)getpid();
2045 prt("Seed set to %d\n", seed);
2052 prt("mapped writes DISABLED\n");
2055 o_direct = O_DIRECT;
2056 o_flags |= O_DIRECT;
2058 case 255: /* --record-ops */
2060 strncpy(opsfile, optarg, sizeof(opsfile));
2061 recordops = opsfile;
2063 case 256: /* --replay-ops */
2075 if (integrity && !dirpath) {
2076 fprintf(stderr, "option -i <logdev> requires -P <dirpath>\n");
2081 tmp = strdup(fname);
2086 bname = basename(tmp);
2088 signal(SIGHUP, cleanup);
2089 signal(SIGINT, cleanup);
2090 signal(SIGPIPE, cleanup);
2091 signal(SIGALRM, cleanup);
2092 signal(SIGTERM, cleanup);
2093 signal(SIGXCPU, cleanup);
2094 signal(SIGXFSZ, cleanup);
2095 signal(SIGVTALRM, cleanup);
2096 signal(SIGUSR1, cleanup);
2097 signal(SIGUSR2, cleanup);
2100 fd = open(fname, o_flags, 0666);
2105 if (fstat(fd, &statbuf)) {
2106 prterr("check_size: fstat");
2109 block_size = statbuf.st_blksize;
2112 xfs_flock64_t resv = { 0 };
2113 #ifdef HAVE_XFS_PLATFORM_DEFS_H
2114 if (!platform_test_xfs_fd(fd)) {
2116 fprintf(stderr, "main: cannot prealloc, non XFS\n");
2120 resv.l_len = maxfilelen;
2121 if ((xfsctl(fname, fd, XFS_IOC_RESVSP, &resv)) < 0) {
2127 strncat(goodfile, dirpath ? bname : fname, 256);
2128 strcat (goodfile, ".fsxgood");
2129 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
2130 if (fsxgoodfd < 0) {
2134 strncat(logfile, dirpath ? bname : fname, 256);
2135 strcat (logfile, ".fsxlog");
2136 fsxlogf = fopen(logfile, "w");
2137 if (fsxlogf == NULL) {
2142 strncat(opsfile, dirpath ? bname : fname, 256);
2143 strcat(opsfile, ".fsxops");
2148 replayopsf = fopen(replayops, "r");
2160 if (!(o_flags & O_TRUNC)) {
2162 file_size = maxfilelen = biggest = lseek(fd, (off_t)0, SEEK_END);
2163 if (file_size == (off_t)-1) {
2165 warn("main: lseek eof");
2168 ret = lseek(fd, (off_t)0, SEEK_SET);
2169 if (ret == (off_t)-1) {
2171 warn("main: lseek 0");
2175 original_buf = (char *) malloc(maxfilelen);
2176 for (i = 0; i < maxfilelen; i++)
2177 original_buf[i] = random() % 256;
2178 good_buf = (char *) malloc(maxfilelen + writebdy);
2179 good_buf = round_ptr_up(good_buf, writebdy, 0);
2180 memset(good_buf, '\0', maxfilelen);
2181 temp_buf = (char *) malloc(maxoplen + readbdy);
2182 temp_buf = round_ptr_up(temp_buf, readbdy, 0);
2183 memset(temp_buf, '\0', maxoplen);
2184 if (lite) { /* zero entire existing file */
2187 written = write(fd, good_buf, (size_t)maxfilelen);
2188 if (written != maxfilelen) {
2189 if (written == -1) {
2191 warn("main: error on write");
2193 warn("main: short write, 0x%x bytes instead "
2200 ssize_t ret, len = file_size;
2204 ret = read(fd, good_buf + off, len);
2207 warn("main: error on read");
2217 if (fallocate_calls)
2218 fallocate_calls = test_fallocate(0);
2219 if (keep_size_calls)
2220 keep_size_calls = test_fallocate(FALLOC_FL_KEEP_SIZE);
2221 if (punch_hole_calls)
2222 punch_hole_calls = test_fallocate(FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
2223 if (zero_range_calls)
2224 zero_range_calls = test_fallocate(FALLOC_FL_ZERO_RANGE);
2225 if (collapse_range_calls)
2226 collapse_range_calls = test_fallocate(FALLOC_FL_COLLAPSE_RANGE);
2227 if (insert_range_calls)
2228 insert_range_calls = test_fallocate(FALLOC_FL_INSERT_RANGE);
2230 while (numops == -1 || numops--)
2239 prt("All %lu operations completed A-OK!\n", testcalls);