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 */
125 int dirpath = 0; /* -P flag */
126 int fd; /* fd for our test file */
128 blksize_t block_size = 0;
131 unsigned long testcalls = 0; /* calls to function "test" */
133 unsigned long simulatedopcount = 0; /* -b flag */
134 int closeprob = 0; /* -c flag */
135 int debug = 0; /* -d flag */
136 unsigned long debugstart = 0; /* -D flag */
137 char filldata = 0; /* -g flag */
138 int flush = 0; /* -f flag */
139 int do_fsync = 0; /* -y flag */
140 unsigned long maxfilelen = 256 * 1024; /* -l flag */
141 int sizechecks = 1; /* -n flag disables them */
142 int maxoplen = 64 * 1024; /* -o flag */
143 int quiet = 0; /* -q flag */
144 unsigned long progressinterval = 0; /* -p flag */
145 int readbdy = 1; /* -r flag */
146 int style = 0; /* -s flag */
147 int prealloc = 0; /* -x flag */
148 int truncbdy = 1; /* -t flag */
149 int writebdy = 1; /* -w flag */
150 long monitorstart = -1; /* -m flag */
151 long monitorend = -1; /* -m flag */
152 int lite = 0; /* -L flag */
153 long numops = -1; /* -N flag */
154 int randomoplen = 1; /* -O flag disables it */
155 int seed = 1; /* -S flag */
156 int mapped_writes = 1; /* -W flag disables */
157 int fallocate_calls = 1; /* -F flag disables */
158 int keep_size_calls = 1; /* -K flag disables */
159 int punch_hole_calls = 1; /* -H flag disables */
160 int zero_range_calls = 1; /* -z flag disables */
161 int collapse_range_calls = 1; /* -C flag disables */
162 int insert_range_calls = 1; /* -I flag disables */
163 int mapped_reads = 1; /* -R flag disables it */
164 int integrity = 0; /* -i flag */
166 int o_direct; /* -Z */
174 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
177 #define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d)
178 #define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d)
180 #define fsxread(a,b,c,d) read(a,b,c)
181 #define fsxwrite(a,b,c,d) write(a,b,c)
184 const char *replayops = NULL;
185 const char *recordops = NULL;
186 FILE * fsxlogf = NULL;
187 FILE * replayopsf = NULL;
192 static void *round_ptr_up(void *ptr, unsigned long align, unsigned long offset)
194 unsigned long ret = (unsigned long)ptr;
196 ret = ((ret + align - 1) & ~(align - 1));
202 vwarnc(int code, const char *fmt, va_list ap)
205 fprintf(stderr, "%s: ", logid);
206 fprintf(stderr, "fsx: ");
208 vfprintf(stderr, fmt, ap);
209 fprintf(stderr, ": ");
211 fprintf(stderr, "%s\n", strerror(code));
215 warn(const char * fmt, ...) {
218 vwarnc(errno, fmt, ap);
223 prt(const char *fmt, ...)
228 fprintf(stdout, "%s: ", logid);
230 vfprintf(stdout, fmt, args);
234 vfprintf(fsxlogf, fmt, args);
240 prterr(const char *prefix)
242 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
246 static const char *op_names[] = {
248 [OP_WRITE] = "write",
249 [OP_MAPREAD] = "mapread",
250 [OP_MAPWRITE] = "mapwrite",
251 [OP_TRUNCATE] = "truncate",
252 [OP_FALLOCATE] = "fallocate",
253 [OP_PUNCH_HOLE] = "punch_hole",
254 [OP_ZERO_RANGE] = "zero_range",
255 [OP_COLLAPSE_RANGE] = "collapse_range",
256 [OP_INSERT_RANGE] = "insert_range",
257 [OP_FSYNC] = "fsync",
260 static const char *op_name(int operation)
262 if (operation >= 0 &&
263 operation < sizeof(op_names) / sizeof(op_names[0]))
264 return op_names[operation];
268 static int op_code(const char *name)
272 for (i = 0; i < sizeof(op_names) / sizeof(op_names[0]); i++)
273 if (op_names[i] && strcmp(name, op_names[i]) == 0)
279 log4(int operation, int arg0, int arg1, enum opflags flags)
281 struct log_entry *le;
284 le->operation = operation;
286 flags |= FL_CLOSE_OPEN;
289 le->args[2] = file_size;
293 if (logptr >= LOGSIZE)
303 struct log_entry *lp;
305 prt("LOG DUMP (%d total operations):\n", logcount);
307 logopsf = fopen(opsfile, "w");
311 if (logcount < LOGSIZE) {
318 for ( ; count > 0; count--) {
322 opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
323 prt("%d(%3d mod 256): ", opnum, opnum%256);
326 overlap = badoff >= lp->args[0] &&
327 badoff < lp->args[0] + lp->args[1];
329 if (lp->flags & FL_SKIPPED) {
330 prt("SKIPPED (no operation)");
334 switch (lp->operation) {
336 prt("MAPREAD 0x%x thru 0x%x\t(0x%x bytes)",
337 lp->args[0], lp->args[0] + lp->args[1] - 1,
343 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
344 lp->args[0], lp->args[0] + lp->args[1] - 1,
350 prt("READ 0x%x thru 0x%x\t(0x%x bytes)",
351 lp->args[0], lp->args[0] + lp->args[1] - 1,
357 prt("WRITE 0x%x thru 0x%x\t(0x%x bytes)",
358 lp->args[0], lp->args[0] + lp->args[1] - 1,
360 if (lp->args[0] > lp->args[2])
362 else if (lp->args[0] + lp->args[1] > lp->args[2])
364 overlap = (badoff >= lp->args[0] ||
365 badoff >=lp->args[2]) &&
366 badoff < lp->args[0] + lp->args[1];
371 down = lp->args[1] < lp->args[2];
372 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
373 down ? "DOWN" : "UP", lp->args[2], lp->args[1]);
374 overlap = badoff >= lp->args[1 + !down] &&
375 badoff < lp->args[1 + !!down];
380 /* 0: offset 1: length 2: where alloced */
381 prt("FALLOC 0x%x thru 0x%x\t(0x%x bytes) ",
382 lp->args[0], lp->args[0] + lp->args[1],
384 if (lp->args[0] + lp->args[1] <= lp->args[2])
386 else if (lp->flags & FL_KEEP_SIZE)
394 prt("PUNCH 0x%x thru 0x%x\t(0x%x bytes)",
395 lp->args[0], lp->args[0] + lp->args[1] - 1,
401 prt("ZERO 0x%x thru 0x%x\t(0x%x bytes)",
402 lp->args[0], lp->args[0] + lp->args[1] - 1,
407 case OP_COLLAPSE_RANGE:
408 prt("COLLAPSE 0x%x thru 0x%x\t(0x%x bytes)",
409 lp->args[0], lp->args[0] + lp->args[1] - 1,
414 case OP_INSERT_RANGE:
415 prt("INSERT 0x%x thru 0x%x\t(0x%x bytes)",
416 lp->args[0], lp->args[0] + lp->args[1] - 1,
425 prt("BOGUS LOG ENTRY (operation code = %d)!",
431 if (lp->flags & FL_CLOSE_OPEN)
432 prt("\n\t\tCLOSE/OPEN");
439 if (lp->flags & FL_SKIPPED)
440 fprintf(logopsf, "skip ");
441 fprintf(logopsf, "%s 0x%x 0x%x 0x%x",
442 op_name(lp->operation),
443 lp->args[0], lp->args[1], lp->args[2]);
444 if (lp->flags & FL_KEEP_SIZE)
445 fprintf(logopsf, " keep_size");
446 if (lp->flags & FL_CLOSE_OPEN)
447 fprintf(logopsf, " close_open");
449 fprintf(logopsf, " *");
450 fprintf(logopsf, "\n");
455 if (fclose(logopsf) != 0)
458 prt("Log of operations saved to \"%s\"; "
459 "replay with --replay-ops\n",
466 save_buffer(char *buffer, off_t bufferlength, int fd)
469 ssize_t byteswritten;
471 if (fd <= 0 || bufferlength == 0)
474 if (bufferlength > SSIZE_MAX) {
475 prt("fsx flaw: overflow in save_buffer\n");
479 off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
480 if (size_by_seek == (off_t)-1)
481 prterr("save_buffer: lseek eof");
482 else if (bufferlength > size_by_seek) {
483 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
484 (unsigned long long)bufferlength);
485 bufferlength = size_by_seek;
489 ret = lseek(fd, (off_t)0, SEEK_SET);
490 if (ret == (off_t)-1)
491 prterr("save_buffer: lseek 0");
493 byteswritten = write(fd, buffer, (size_t)bufferlength);
494 if (byteswritten != bufferlength) {
495 if (byteswritten == -1)
496 prterr("save_buffer write");
498 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
499 (unsigned)byteswritten,
500 (unsigned long long)bufferlength);
506 report_failure(int status)
512 save_buffer(good_buf, file_size, fsxgoodfd);
513 prt("Correct content saved for comparison\n");
514 prt("(maybe hexdump \"%s\" vs \"%s\")\n",
523 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
524 *(((unsigned char *)(cp)) + 1)))
532 snprintf(command, 256, "dmsetup message %s 0 mark %s.mark%d", logdev,
534 ret = system(command);
536 prterr("dmsetup mark failed");
542 dump_fsync_buffer(void)
544 char fname_buffer[1024];
550 snprintf(fname_buffer, 1024, "%s%s.mark%d", dname,
552 good_fd = open(fname_buffer, O_WRONLY|O_CREAT|O_TRUNC, 0666);
554 prterr(fname_buffer);
558 save_buffer(good_buf, file_size, good_fd);
560 prt("Dumped fsync buffer to %s\n", fname_buffer + dirpath);
564 check_buffers(unsigned offset, unsigned size)
572 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
573 prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
574 offset, size, fname);
575 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
577 c = good_buf[offset];
581 bad = short_at(&temp_buf[i]);
582 prt("0x%05x\t0x%04x\t0x%04x", offset,
583 short_at(&good_buf[offset]), bad);
584 op = temp_buf[offset & 1 ? i+1 : i];
585 prt("\t0x%05x\n", n);
587 prt("operation# (mod 256) for "
588 "the bad data may be %u\n",
589 ((unsigned)op & 0xff));
591 prt("operation# (mod 256) for "
592 "the bad data unknown, check"
593 " HOLE and EXTEND ops\n");
613 if (fstat(fd, &statbuf)) {
614 prterr("check_size: fstat");
615 statbuf.st_size = -1;
617 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
618 if (file_size != statbuf.st_size || file_size != size_by_seek) {
619 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
620 (unsigned long long)file_size,
621 (unsigned long long)statbuf.st_size,
622 (unsigned long long)size_by_seek);
629 check_trunc_hack(void)
632 off_t offset = file_size + (off_t)100000;
634 if (ftruncate(fd, file_size))
636 if (ftruncate(fd, offset))
639 if (statbuf.st_size != offset) {
640 prt("no extend on truncate! not posix!\n");
643 if (ftruncate(fd, file_size)) {
645 prterr("check_trunc_hack: ftruncate");
651 doflush(unsigned offset, unsigned size)
657 if (o_direct == O_DIRECT)
660 pg_offset = offset & mmap_mask;
661 map_size = pg_offset + size;
663 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
664 MAP_FILE | MAP_SHARED, fd,
665 (off_t)(offset - pg_offset))) == (char *)-1) {
666 prterr("doflush: mmap");
669 if (msync(p, map_size, MS_INVALIDATE) != 0) {
670 prterr("doflush: msync");
673 if (munmap(p, map_size) != 0) {
674 prterr("doflush: munmap");
680 doread(unsigned offset, unsigned size)
685 offset -= offset % readbdy;
687 size -= size % readbdy;
689 if (!quiet && testcalls > simulatedopcount && !o_direct)
690 prt("skipping zero size read\n");
691 log4(OP_READ, offset, size, FL_SKIPPED);
694 if (size + offset > file_size) {
695 if (!quiet && testcalls > simulatedopcount)
696 prt("skipping seek/read past end of file\n");
697 log4(OP_READ, offset, size, FL_SKIPPED);
701 log4(OP_READ, offset, size, FL_NONE);
703 if (testcalls <= simulatedopcount)
707 ((progressinterval && testcalls % progressinterval == 0) ||
709 (monitorstart == -1 ||
710 (offset + size > monitorstart &&
711 (monitorend == -1 || offset <= monitorend))))))
712 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
713 offset, offset + size - 1, size);
714 ret = lseek(fd, (off_t)offset, SEEK_SET);
715 if (ret == (off_t)-1) {
716 prterr("doread: lseek");
719 iret = fsxread(fd, temp_buf, size, offset);
722 prterr("doread: read");
724 prt("short read: 0x%x bytes instead of 0x%x\n",
728 check_buffers(offset, size);
733 check_eofpage(char *s, unsigned offset, char *p, int size)
735 unsigned long last_page, should_be_zero;
737 if (offset + size <= (file_size & ~page_mask))
740 * we landed in the last page of the file
741 * test to make sure the VM system provided 0's
742 * beyond the true end of the file mapping
743 * (as required by mmap def in 1996 posix 1003.1)
745 last_page = ((unsigned long)p + (offset & page_mask) + size) & ~page_mask;
747 for (should_be_zero = last_page + (file_size & page_mask);
748 should_be_zero < last_page + page_size;
750 if (*(char *)should_be_zero) {
751 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
752 s, file_size - 1, should_be_zero & page_mask,
753 short_at(should_be_zero));
760 domapread(unsigned offset, unsigned size)
766 offset -= offset % readbdy;
768 if (!quiet && testcalls > simulatedopcount)
769 prt("skipping zero size read\n");
770 log4(OP_MAPREAD, offset, size, FL_SKIPPED);
773 if (size + offset > file_size) {
774 if (!quiet && testcalls > simulatedopcount)
775 prt("skipping seek/read past end of file\n");
776 log4(OP_MAPREAD, offset, size, FL_SKIPPED);
780 log4(OP_MAPREAD, offset, size, FL_NONE);
782 if (testcalls <= simulatedopcount)
786 ((progressinterval && testcalls % progressinterval == 0) ||
788 (monitorstart == -1 ||
789 (offset + size > monitorstart &&
790 (monitorend == -1 || offset <= monitorend))))))
791 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
792 offset, offset + size - 1, size);
794 pg_offset = offset & PAGE_MASK;
795 map_size = pg_offset + size;
797 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd,
798 (off_t)(offset - pg_offset))) == (char *)-1) {
799 prterr("domapread: mmap");
802 memcpy(temp_buf, p + pg_offset, size);
804 check_eofpage("Read", offset, p, size);
806 if (munmap(p, map_size) != 0) {
807 prterr("domapread: munmap");
811 check_buffers(offset, size);
816 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
820 good_buf[offset] = filldata;
822 good_buf[offset] = testcalls % 256;
824 good_buf[offset] += original_buf[offset];
832 dowrite(unsigned offset, unsigned size)
837 offset -= offset % writebdy;
839 size -= size % writebdy;
841 if (!quiet && testcalls > simulatedopcount && !o_direct)
842 prt("skipping zero size write\n");
843 log4(OP_WRITE, offset, size, FL_SKIPPED);
847 log4(OP_WRITE, offset, size, FL_NONE);
849 gendata(original_buf, good_buf, offset, size);
850 if (file_size < offset + size) {
851 if (file_size < offset)
852 memset(good_buf + file_size, '\0', offset - file_size);
853 file_size = offset + size;
855 warn("Lite file size bug in fsx!");
860 if (testcalls <= simulatedopcount)
864 ((progressinterval && testcalls % progressinterval == 0) ||
866 (monitorstart == -1 ||
867 (offset + size > monitorstart &&
868 (monitorend == -1 || offset <= monitorend))))))
869 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
870 offset, offset + size - 1, size);
871 ret = lseek(fd, (off_t)offset, SEEK_SET);
872 if (ret == (off_t)-1) {
873 prterr("dowrite: lseek");
876 iret = fsxwrite(fd, good_buf + offset, size, offset);
879 prterr("dowrite: write");
881 prt("short write: 0x%x bytes instead of 0x%x\n",
887 prt("fsync() failed: %s\n", strerror(errno));
892 doflush(offset, size);
898 domapwrite(unsigned offset, unsigned size)
905 offset -= offset % writebdy;
907 if (!quiet && testcalls > simulatedopcount)
908 prt("skipping zero size write\n");
909 log4(OP_MAPWRITE, offset, size, FL_SKIPPED);
912 cur_filesize = file_size;
914 log4(OP_MAPWRITE, offset, size, FL_NONE);
916 gendata(original_buf, good_buf, offset, size);
917 if (file_size < offset + size) {
918 if (file_size < offset)
919 memset(good_buf + file_size, '\0', offset - file_size);
920 file_size = offset + size;
922 warn("Lite file size bug in fsx!");
927 if (testcalls <= simulatedopcount)
931 ((progressinterval && testcalls % progressinterval == 0) ||
933 (monitorstart == -1 ||
934 (offset + size > monitorstart &&
935 (monitorend == -1 || offset <= monitorend))))))
936 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
937 offset, offset + size - 1, size);
939 if (file_size > cur_filesize) {
940 if (ftruncate(fd, file_size) == -1) {
941 prterr("domapwrite: ftruncate");
945 pg_offset = offset & PAGE_MASK;
946 map_size = pg_offset + size;
948 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
949 MAP_FILE | MAP_SHARED, fd,
950 (off_t)(offset - pg_offset))) == (char *)-1) {
951 prterr("domapwrite: mmap");
954 memcpy(p + pg_offset, good_buf + offset, size);
955 if (msync(p, map_size, MS_SYNC) != 0) {
956 prterr("domapwrite: msync");
960 check_eofpage("Write", offset, p, size);
962 if (munmap(p, map_size) != 0) {
963 prterr("domapwrite: munmap");
970 dotruncate(unsigned size)
972 int oldsize = file_size;
974 size -= size % truncbdy;
975 if (size > biggest) {
977 if (!quiet && testcalls > simulatedopcount)
978 prt("truncating to largest ever: 0x%x\n", size);
981 log4(OP_TRUNCATE, 0, size, FL_NONE);
983 if (size > file_size)
984 memset(good_buf + file_size, '\0', size - file_size);
987 if (testcalls <= simulatedopcount)
990 if ((progressinterval && testcalls % progressinterval == 0) ||
991 (debug && (monitorstart == -1 || monitorend == -1 ||
992 size <= monitorend)))
993 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
994 if (ftruncate(fd, (off_t)size) == -1) {
995 prt("ftruncate1: %x\n", size);
996 prterr("dotruncate: ftruncate");
1001 #ifdef FALLOC_FL_PUNCH_HOLE
1003 do_punch_hole(unsigned offset, unsigned length)
1005 unsigned end_offset;
1008 int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
1011 if (!quiet && testcalls > simulatedopcount)
1012 prt("skipping zero length punch hole\n");
1013 log4(OP_PUNCH_HOLE, offset, length, FL_SKIPPED);
1017 if (file_size <= (loff_t)offset) {
1018 if (!quiet && testcalls > simulatedopcount)
1019 prt("skipping hole punch off the end of the file\n");
1020 log4(OP_PUNCH_HOLE, offset, length, FL_SKIPPED);
1024 end_offset = offset + length;
1026 log4(OP_PUNCH_HOLE, offset, length, FL_NONE);
1028 if (testcalls <= simulatedopcount)
1031 if ((progressinterval && testcalls % progressinterval == 0) ||
1032 (debug && (monitorstart == -1 || monitorend == -1 ||
1033 end_offset <= monitorend))) {
1034 prt("%lu punch\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1035 offset, offset+length, length);
1037 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1038 prt("punch hole: 0x%x to 0x%x\n", offset, offset + length);
1039 prterr("do_punch_hole: fallocate");
1040 report_failure(161);
1044 max_offset = offset < file_size ? offset : file_size;
1045 max_len = max_offset + length <= file_size ? length :
1046 file_size - max_offset;
1047 memset(good_buf + max_offset, '\0', max_len);
1052 do_punch_hole(unsigned offset, unsigned length)
1058 #ifdef FALLOC_FL_ZERO_RANGE
1060 do_zero_range(unsigned offset, unsigned length, int keep_size)
1062 unsigned end_offset;
1063 int mode = FALLOC_FL_ZERO_RANGE;
1066 if (!quiet && testcalls > simulatedopcount)
1067 prt("skipping zero length zero range\n");
1068 log4(OP_ZERO_RANGE, offset, length, FL_SKIPPED |
1069 (keep_size ? FL_KEEP_SIZE : FL_NONE));
1073 end_offset = keep_size ? 0 : offset + length;
1075 if (end_offset > biggest) {
1076 biggest = end_offset;
1077 if (!quiet && testcalls > simulatedopcount)
1078 prt("zero_range to largest ever: 0x%x\n", end_offset);
1082 * last arg matches fallocate string array index in logdump:
1083 * 0: allocate past EOF
1084 * 1: extending prealloc
1085 * 2: interior prealloc
1087 log4(OP_ZERO_RANGE, offset, length,
1088 keep_size ? FL_KEEP_SIZE : FL_NONE);
1090 if (testcalls <= simulatedopcount)
1093 if ((progressinterval && testcalls % progressinterval == 0) ||
1094 (debug && (monitorstart == -1 || monitorend == -1 ||
1095 end_offset <= monitorend))) {
1096 prt("%lu zero\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1097 offset, offset+length, length);
1099 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1100 prt("zero range: 0x%x to 0x%x\n", offset, offset + length);
1101 prterr("do_zero_range: fallocate");
1102 report_failure(161);
1105 memset(good_buf + offset, '\0', length);
1110 do_zero_range(unsigned offset, unsigned length, int keep_size)
1116 #ifdef FALLOC_FL_COLLAPSE_RANGE
1118 do_collapse_range(unsigned offset, unsigned length)
1120 unsigned end_offset;
1121 int mode = FALLOC_FL_COLLAPSE_RANGE;
1124 if (!quiet && testcalls > simulatedopcount)
1125 prt("skipping zero length collapse range\n");
1126 log4(OP_COLLAPSE_RANGE, offset, length, FL_SKIPPED);
1130 end_offset = offset + length;
1131 if ((loff_t)end_offset >= file_size) {
1132 if (!quiet && testcalls > simulatedopcount)
1133 prt("skipping collapse range behind EOF\n");
1134 log4(OP_COLLAPSE_RANGE, offset, length, FL_SKIPPED);
1138 log4(OP_COLLAPSE_RANGE, offset, length, FL_NONE);
1140 if (testcalls <= simulatedopcount)
1143 if ((progressinterval && testcalls % progressinterval == 0) ||
1144 (debug && (monitorstart == -1 || monitorend == -1 ||
1145 end_offset <= monitorend))) {
1146 prt("%lu collapse\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1147 offset, offset+length, length);
1149 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1150 prt("collapse range: 0x%x to 0x%x\n", offset, offset + length);
1151 prterr("do_collapse_range: fallocate");
1152 report_failure(161);
1155 memmove(good_buf + offset, good_buf + end_offset,
1156 file_size - end_offset);
1157 file_size -= length;
1162 do_collapse_range(unsigned offset, unsigned length)
1168 #ifdef FALLOC_FL_INSERT_RANGE
1170 do_insert_range(unsigned offset, unsigned length)
1172 unsigned end_offset;
1173 int mode = FALLOC_FL_INSERT_RANGE;
1176 if (!quiet && testcalls > simulatedopcount)
1177 prt("skipping zero length insert range\n");
1178 log4(OP_INSERT_RANGE, offset, length, FL_SKIPPED);
1182 if ((loff_t)offset >= file_size) {
1183 if (!quiet && testcalls > simulatedopcount)
1184 prt("skipping insert range behind EOF\n");
1185 log4(OP_INSERT_RANGE, offset, length, FL_SKIPPED);
1189 log4(OP_INSERT_RANGE, offset, length, FL_NONE);
1191 if (testcalls <= simulatedopcount)
1194 end_offset = offset + length;
1195 if ((progressinterval && testcalls % progressinterval == 0) ||
1196 (debug && (monitorstart == -1 || monitorend == -1 ||
1197 end_offset <= monitorend))) {
1198 prt("%lu insert\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
1199 offset, offset+length, length);
1201 if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
1202 prt("insert range: 0x%x to 0x%x\n", offset, offset + length);
1203 prterr("do_insert_range: fallocate");
1204 report_failure(161);
1207 memmove(good_buf + end_offset, good_buf + offset,
1208 file_size - offset);
1209 memset(good_buf + offset, '\0', length);
1210 file_size += length;
1215 do_insert_range(unsigned offset, unsigned length)
1221 #ifdef HAVE_LINUX_FALLOC_H
1222 /* fallocate is basically a no-op unless extending, then a lot like a truncate */
1224 do_preallocate(unsigned offset, unsigned length, int keep_size)
1226 unsigned end_offset;
1229 if (!quiet && testcalls > simulatedopcount)
1230 prt("skipping zero length fallocate\n");
1231 log4(OP_FALLOCATE, offset, length, FL_SKIPPED |
1232 (keep_size ? FL_KEEP_SIZE : FL_NONE));
1236 end_offset = keep_size ? 0 : offset + length;
1238 if (end_offset > biggest) {
1239 biggest = end_offset;
1240 if (!quiet && testcalls > simulatedopcount)
1241 prt("fallocating to largest ever: 0x%x\n", end_offset);
1245 * last arg matches fallocate string array index in logdump:
1246 * 0: allocate past EOF
1247 * 1: extending prealloc
1248 * 2: interior prealloc
1250 log4(OP_FALLOCATE, offset, length,
1251 keep_size ? FL_KEEP_SIZE : FL_NONE);
1253 if (end_offset > file_size) {
1254 memset(good_buf + file_size, '\0', end_offset - file_size);
1255 file_size = end_offset;
1258 if (testcalls <= simulatedopcount)
1261 if ((progressinterval && testcalls % progressinterval == 0) ||
1262 (debug && (monitorstart == -1 || monitorend == -1 ||
1263 end_offset <= monitorend)))
1264 prt("%lu falloc\tfrom 0x%x to 0x%x (0x%x bytes)\n", testcalls,
1265 offset, offset + length, length);
1266 if (fallocate(fd, keep_size ? FALLOC_FL_KEEP_SIZE : 0, (loff_t)offset, (loff_t)length) == -1) {
1267 prt("fallocate: 0x%x to 0x%x\n", offset, offset + length);
1268 prterr("do_preallocate: fallocate");
1269 report_failure(161);
1274 do_preallocate(unsigned offset, unsigned length, int keep_size)
1285 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
1286 prterr("writefileimage: lseek");
1287 report_failure(171);
1289 iret = write(fd, good_buf, file_size);
1290 if ((off_t)iret != file_size) {
1292 prterr("writefileimage: write");
1294 prt("short write: 0x%x bytes instead of 0x%llx\n",
1295 iret, (unsigned long long)file_size);
1296 report_failure(172);
1298 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
1299 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
1300 prterr("writefileimage: ftruncate");
1301 report_failure(173);
1309 if (testcalls <= simulatedopcount)
1313 prt("%lu close/open\n", testcalls);
1315 prterr("docloseopen: close");
1316 report_failure(180);
1318 fd = open(fname, O_RDWR|o_direct, 0);
1320 prterr("docloseopen: open");
1321 report_failure(181);
1330 if (testcalls <= simulatedopcount)
1333 prt("%lu fsync\n", testcalls);
1334 log4(OP_FSYNC, 0, 0, 0);
1338 report_failure(210);
1341 dump_fsync_buffer();
1345 #define TRIM_OFF(off, size) \
1353 #define TRIM_LEN(off, len, size) \
1355 if ((off) + (len) > (size)) \
1356 (len) = (size) - (off); \
1359 #define TRIM_OFF_LEN(off, len, size) \
1361 TRIM_OFF(off, size); \
1362 TRIM_LEN(off, len, size); \
1369 prt("signal %d\n", sig);
1370 prt("testcalls = %lu\n", testcalls);
1375 read_op(struct log_entry *log_entry)
1379 memset(log_entry, 0, sizeof(*log_entry));
1380 log_entry->operation = -1;
1382 while (log_entry->operation == -1) {
1387 if (!fgets(line, sizeof(line), replayopsf)) {
1388 if (feof(replayopsf)) {
1394 str = strtok(line, " \t\n");
1395 } while (!str || str[0] == '#');
1397 if (strcmp(str, "skip") == 0) {
1398 log_entry->flags |= FL_SKIPPED;
1399 str = strtok(NULL, " \t\n");
1403 log_entry->operation = op_code(str);
1404 if (log_entry->operation == -1)
1406 for (i = 0; i < 3; i++) {
1409 str = strtok(NULL, " \t\n");
1412 log_entry->args[i] = strtoul(str, &end, 0);
1416 while ((str = strtok(NULL, " \t\n"))) {
1417 if (strcmp(str, "keep_size") == 0)
1418 log_entry->flags |= FL_KEEP_SIZE;
1419 else if (strcmp(str, "close_open") == 0)
1420 log_entry->flags |= FL_CLOSE_OPEN;
1421 else if (strcmp(str, "*") == 0)
1422 ; /* overlap marker; ignore */
1430 fprintf(stderr, "%s: parse error\n", replayops);
1433 cleanup(100); /* doesn't return */
1441 unsigned long offset;
1447 if (simulatedopcount > 0 && testcalls == simulatedopcount)
1452 if (debugstart > 0 && testcalls >= debugstart)
1455 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
1456 prt("%lu...\n", testcalls);
1459 struct log_entry log_entry;
1461 while (read_op(&log_entry)) {
1462 if (log_entry.flags & FL_SKIPPED) {
1463 log4(log_entry.operation,
1464 log_entry.args[0], log_entry.args[1],
1469 op = log_entry.operation;
1470 offset = log_entry.args[0];
1471 size = log_entry.args[1];
1472 closeopen = !!(log_entry.flags & FL_CLOSE_OPEN);
1473 keep_size = !!(log_entry.flags & FL_KEEP_SIZE);
1481 closeopen = (rv >> 3) < (1 << 28) / closeprob;
1486 size = random() % (maxoplen + 1);
1488 /* calculate appropriate op to run */
1490 op = rv % OP_MAX_LITE;
1491 else if (!integrity)
1492 op = rv % OP_MAX_FULL;
1494 op = rv % OP_MAX_INTEGRITY;
1499 size = random() % maxfilelen;
1502 if (fallocate_calls && size && keep_size_calls)
1503 keep_size = random() % 2;
1506 if (zero_range_calls && size && keep_size_calls)
1507 keep_size = random() % 2;
1523 if (!fallocate_calls) {
1524 log4(OP_FALLOCATE, offset, size, FL_SKIPPED);
1529 if (!punch_hole_calls) {
1530 log4(OP_PUNCH_HOLE, offset, size, FL_SKIPPED);
1535 if (!zero_range_calls) {
1536 log4(OP_ZERO_RANGE, offset, size, FL_SKIPPED);
1540 case OP_COLLAPSE_RANGE:
1541 if (!collapse_range_calls) {
1542 log4(OP_COLLAPSE_RANGE, offset, size, FL_SKIPPED);
1546 case OP_INSERT_RANGE:
1547 if (!insert_range_calls) {
1548 log4(OP_INSERT_RANGE, offset, size, FL_SKIPPED);
1556 TRIM_OFF_LEN(offset, size, file_size);
1557 doread(offset, size);
1561 TRIM_OFF_LEN(offset, size, maxfilelen);
1562 dowrite(offset, size);
1566 TRIM_OFF_LEN(offset, size, file_size);
1567 domapread(offset, size);
1571 TRIM_OFF_LEN(offset, size, maxfilelen);
1572 domapwrite(offset, size);
1580 TRIM_OFF_LEN(offset, size, maxfilelen);
1581 do_preallocate(offset, size, keep_size);
1585 TRIM_OFF_LEN(offset, size, file_size);
1586 do_punch_hole(offset, size);
1589 TRIM_OFF_LEN(offset, size, file_size);
1590 do_zero_range(offset, size, keep_size);
1592 case OP_COLLAPSE_RANGE:
1593 TRIM_OFF_LEN(offset, size, file_size - 1);
1594 offset = offset & ~(block_size - 1);
1595 size = size & ~(block_size - 1);
1597 log4(OP_COLLAPSE_RANGE, offset, size, FL_SKIPPED);
1600 do_collapse_range(offset, size);
1602 case OP_INSERT_RANGE:
1603 TRIM_OFF(offset, file_size);
1604 TRIM_LEN(file_size, size, maxfilelen);
1605 offset = offset & ~(block_size - 1);
1606 size = size & ~(block_size - 1);
1608 log4(OP_INSERT_RANGE, offset, size, FL_SKIPPED);
1611 if (file_size + size > maxfilelen) {
1612 log4(OP_INSERT_RANGE, offset, size, FL_SKIPPED);
1616 do_insert_range(offset, size);
1622 prterr("test: unknown operation");
1628 if (sizechecks && testcalls > simulatedopcount)
1639 fprintf(stdout, "usage: %s",
1640 "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\
1641 -b opnum: beginning operation number (default 1)\n\
1642 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
1643 -d: debug output for all operations\n\
1644 -f flush and invalidate cache after I/O\n\
1645 -g X: write character X instead of random generated data\n\
1646 -i logdev: do integrity testing, logdev is the dm log writes device\n\
1647 -j logid: prefix debug log messsages with this id\n\
1648 -k: do not truncate existing file and use its size as upper bound on file size\n\
1649 -l flen: the upper bound on file size (default 262144)\n\
1650 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
1651 -n: no verifications of file size\n\
1652 -o oplen: the upper bound on operation size (default 65536)\n\
1653 -p progressinterval: debug output at specified operation interval\n\
1654 -q: quieter operation\n\
1655 -r readbdy: 4096 would make reads page aligned (default 1)\n\
1656 -s style: 1 gives smaller truncates (default 0)\n\
1657 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
1658 -w writebdy: 4096 would make writes page aligned (default 1)\n\
1659 -x: preallocate file space before starting, XFS only (default 0)\n\
1660 -y synchronize changes to a file\n"
1663 " -A: Use the AIO system calls\n"
1665 " -D startingop: debug output starting at specified operation\n"
1666 #ifdef HAVE_LINUX_FALLOC_H
1667 " -F: Do not use fallocate (preallocation) calls\n"
1669 #ifdef FALLOC_FL_PUNCH_HOLE
1670 " -H: Do not use punch hole calls\n"
1672 #ifdef FALLOC_FL_ZERO_RANGE
1673 " -z: Do not use zero range calls\n"
1675 #ifdef FALLOC_FL_COLLAPSE_RANGE
1676 " -C: Do not use collapse range calls\n"
1678 #ifdef FALLOC_FL_INSERT_RANGE
1679 " -I: Do not use insert range calls\n"
1681 " -L: fsxLite - no file creations & no file size changes\n\
1682 -N numops: total # operations to do (default infinity)\n\
1683 -O: use oplen (see -o flag) for every op (default random)\n\
1684 -P: save .fsxlog .fsxops and .fsxgood files in dirpath (default ./)\n\
1685 -S seed: for random # generator (default 1) 0 gets timestamp\n\
1686 -W: mapped write operations DISabled\n\
1687 -R: read() system calls only (mapped reads disabled)\n\
1688 -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
1689 --replay-ops opsfile: replay ops from recorded .fsxops file\n\
1690 --record-ops[=opsfile]: dump ops file also on success. optionally specify ops file name\n\
1691 fname: this filename is REQUIRED (no default)\n");
1697 getnum(char *s, char **e)
1702 ret = strtol(s, e, 0);
1732 io_context_t io_ctx;
1738 ret = io_queue_init(QSZ, &io_ctx);
1740 fprintf(stderr, "aio_setup: io_queue_init failed: %s\n",
1748 __aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
1750 struct io_event event;
1751 static struct timespec ts;
1752 struct iocb *iocbs[] = { &iocb };
1757 io_prep_pread(&iocb, fd, buf, len, offset);
1759 io_prep_pwrite(&iocb, fd, buf, len, offset);
1764 ret = io_submit(io_ctx, 1, iocbs);
1766 fprintf(stderr, "errcode=%d\n", ret);
1767 fprintf(stderr, "aio_rw: io_submit failed: %s\n",
1772 ret = io_getevents(io_ctx, 1, 1, &event, &ts);
1775 fprintf(stderr, "aio_rw: no events available\n");
1777 fprintf(stderr, "errcode=%d\n", -ret);
1778 fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
1783 if (len != event.res) {
1785 * The b0rked libaio defines event.res as unsigned.
1786 * However the kernel strucuture has it signed,
1787 * and it's used to pass negated error value.
1788 * Till the library is fixed use the temp var.
1790 res = (long)event.res;
1792 fprintf(stderr, "bad io length: %lu instead of %u\n",
1795 fprintf(stderr, "errcode=%ld\n", -res);
1796 fprintf(stderr, "aio_rw: async io failed: %s\n",
1807 * The caller expects error return in traditional libc
1808 * convention, i.e. -1 and the errno set to error.
1814 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
1819 ret = __aio_rw(rw, fd, buf, len, offset);
1822 ret = read(fd, buf, len);
1824 ret = write(fd, buf, len);
1831 #define test_fallocate(mode) __test_fallocate(mode, #mode)
1834 __test_fallocate(int mode, const char *mode_str)
1836 #ifdef HAVE_LINUX_FALLOC_H
1839 if (fallocate(fd, mode, file_size, 1) && errno == EOPNOTSUPP) {
1842 "main: filesystem does not support "
1843 "fallocate mode %s, disabling!\n",
1847 if (ftruncate(fd, file_size)) {
1848 warn("main: ftruncate");
1857 static struct option longopts[] = {
1858 {"replay-ops", required_argument, 0, 256},
1859 {"record-ops", optional_argument, 0, 255},
1864 main(int argc, char **argv)
1869 struct stat statbuf;
1870 int o_flags = O_RDWR|O_CREAT|O_TRUNC;
1875 page_size = getpagesize();
1876 page_mask = page_size - 1;
1877 mmap_mask = page_mask;
1880 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1882 while ((ch = getopt_long(argc, argv,
1883 "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyAD:FKHzCILN:OP:RS:WZ",
1884 longopts, NULL)) != EOF)
1887 simulatedopcount = getnum(optarg, &endp);
1889 prt("Will begin at operation %ld\n", simulatedopcount);
1890 if (simulatedopcount == 0)
1892 simulatedopcount -= 1;
1895 closeprob = getnum(optarg, &endp);
1897 prt("Chance of close/open is 1 in %d\n", closeprob);
1912 logdev = strdup(optarg);
1919 logid = strdup(optarg);
1926 o_flags &= ~O_TRUNC;
1929 maxfilelen = getnum(optarg, &endp);
1930 if (maxfilelen <= 0)
1934 monitorstart = getnum(optarg, &endp);
1935 if (monitorstart < 0)
1937 if (!endp || *endp++ != ':')
1939 monitorend = getnum(endp, &endp);
1942 if (monitorend == 0)
1943 monitorend = -1; /* aka infinity */
1949 maxoplen = getnum(optarg, &endp);
1954 progressinterval = getnum(optarg, &endp);
1955 if (progressinterval == 0)
1962 readbdy = getnum(optarg, &endp);
1967 style = getnum(optarg, &endp);
1968 if (style < 0 || style > 1)
1972 truncbdy = getnum(optarg, &endp);
1977 writebdy = getnum(optarg, &endp);
1991 debugstart = getnum(optarg, &endp);
1996 fallocate_calls = 0;
1999 keep_size_calls = 0;
2002 punch_hole_calls = 0;
2005 zero_range_calls = 0;
2008 collapse_range_calls = 0;
2011 insert_range_calls = 0;
2015 o_flags &= ~(O_CREAT|O_TRUNC);
2018 numops = getnum(optarg, &endp);
2026 strncpy(dname, optarg, sizeof(dname));
2028 dirpath = strlen(dname);
2034 seed = getnum(optarg, &endp);
2036 seed = time(0) % 10000;
2037 seed += (int)getpid();
2045 prt("mapped writes DISABLED\n");
2048 o_direct = O_DIRECT;
2049 o_flags |= O_DIRECT;
2051 case 255: /* --record-ops */
2053 strncpy(opsfile, optarg, sizeof(opsfile));
2054 recordops = opsfile;
2056 case 256: /* --replay-ops */
2068 if (integrity && !dirpath) {
2069 fprintf(stderr, "option -i <logdev> requires -P <dirpath>\n");
2074 tmp = strdup(fname);
2079 bname = basename(tmp);
2081 signal(SIGHUP, cleanup);
2082 signal(SIGINT, cleanup);
2083 signal(SIGPIPE, cleanup);
2084 signal(SIGALRM, cleanup);
2085 signal(SIGTERM, cleanup);
2086 signal(SIGXCPU, cleanup);
2087 signal(SIGXFSZ, cleanup);
2088 signal(SIGVTALRM, cleanup);
2089 signal(SIGUSR1, cleanup);
2090 signal(SIGUSR2, cleanup);
2093 prt("Seed set to %d\n", seed);
2095 fd = open(fname, o_flags, 0666);
2100 if (fstat(fd, &statbuf)) {
2101 prterr("check_size: fstat");
2104 block_size = statbuf.st_blksize;
2107 xfs_flock64_t resv = { 0 };
2108 #ifdef HAVE_XFS_PLATFORM_DEFS_H
2109 if (!platform_test_xfs_fd(fd)) {
2111 fprintf(stderr, "main: cannot prealloc, non XFS\n");
2115 resv.l_len = maxfilelen;
2116 if ((xfsctl(fname, fd, XFS_IOC_RESVSP, &resv)) < 0) {
2124 snprintf(goodfile, sizeof(goodfile), "%s%s.fsxgood", dname, bname);
2125 snprintf(logfile, sizeof(logfile), "%s%s.fsxlog", dname, bname);
2127 snprintf(opsfile, sizeof(opsfile), "%s%s.fsxops", dname, bname);
2129 snprintf(goodfile, sizeof(goodfile), "%s.fsxgood", fname);
2130 snprintf(logfile, sizeof(logfile), "%s.fsxlog", fname);
2132 snprintf(opsfile, sizeof(opsfile), "%s.fsxops", fname);
2134 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
2135 if (fsxgoodfd < 0) {
2139 fsxlogf = fopen(logfile, "w");
2140 if (fsxlogf == NULL) {
2147 replayopsf = fopen(replayops, "r");
2159 if (!(o_flags & O_TRUNC)) {
2161 file_size = maxfilelen = biggest = lseek(fd, (off_t)0, SEEK_END);
2162 if (file_size == (off_t)-1) {
2164 warn("main: lseek eof");
2167 ret = lseek(fd, (off_t)0, SEEK_SET);
2168 if (ret == (off_t)-1) {
2170 warn("main: lseek 0");
2174 original_buf = (char *) malloc(maxfilelen);
2175 for (i = 0; i < maxfilelen; i++)
2176 original_buf[i] = random() % 256;
2177 good_buf = (char *) malloc(maxfilelen + writebdy);
2178 good_buf = round_ptr_up(good_buf, writebdy, 0);
2179 memset(good_buf, '\0', maxfilelen);
2180 temp_buf = (char *) malloc(maxoplen + readbdy);
2181 temp_buf = round_ptr_up(temp_buf, readbdy, 0);
2182 memset(temp_buf, '\0', maxoplen);
2183 if (lite) { /* zero entire existing file */
2186 written = write(fd, good_buf, (size_t)maxfilelen);
2187 if (written != maxfilelen) {
2188 if (written == -1) {
2190 warn("main: error on write");
2192 warn("main: short write, 0x%x bytes instead "
2199 ssize_t ret, len = file_size;
2203 ret = read(fd, good_buf + off, len);
2206 warn("main: error on read");
2216 if (fallocate_calls)
2217 fallocate_calls = test_fallocate(0);
2218 if (keep_size_calls)
2219 keep_size_calls = test_fallocate(FALLOC_FL_KEEP_SIZE);
2220 if (punch_hole_calls)
2221 punch_hole_calls = test_fallocate(FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
2222 if (zero_range_calls)
2223 zero_range_calls = test_fallocate(FALLOC_FL_ZERO_RANGE);
2224 if (collapse_range_calls)
2225 collapse_range_calls = test_fallocate(FALLOC_FL_COLLAPSE_RANGE);
2226 if (insert_range_calls)
2227 insert_range_calls = test_fallocate(FALLOC_FL_INSERT_RANGE);
2229 while (numops == -1 || numops--)
2238 prt("All %lu operations completed A-OK!\n", testcalls);