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.
40 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
43 * A log entry is an operation and a bunch of arguments.
53 struct log_entry oplog[LOGSIZE]; /* the log */
54 int logptr = 0; /* current position in log */
55 int logcount = 0; /* total ops */
64 #define OP_CLOSEOPEN 4
70 #define PAGE_SIZE getpagesize()
72 #define PAGE_MASK (PAGE_SIZE - 1)
74 char *original_buf; /* a pointer to the original data */
75 char *good_buf; /* a pointer to the correct data */
76 char *temp_buf; /* a pointer to the current data */
77 char *fname; /* name of our test file */
78 int fd; /* fd for our test file */
83 unsigned long testcalls = 0; /* calls to function "test" */
85 unsigned long simulatedopcount = 0; /* -b flag */
86 int closeprob = 0; /* -c flag */
87 int debug = 0; /* -d flag */
88 unsigned long debugstart = 0; /* -D flag */
89 int flush = 0; /* -f flag */
90 int do_fsync = 0; /* -y flag */
91 unsigned long maxfilelen = 256 * 1024; /* -l flag */
92 int sizechecks = 1; /* -n flag disables them */
93 int maxoplen = 64 * 1024; /* -o flag */
94 int quiet = 0; /* -q flag */
95 unsigned long progressinterval = 0; /* -p flag */
96 int readbdy = 1; /* -r flag */
97 int style = 0; /* -s flag */
98 int prealloc = 0; /* -x flag */
99 int truncbdy = 1; /* -t flag */
100 int writebdy = 1; /* -w flag */
101 long monitorstart = -1; /* -m flag */
102 long monitorend = -1; /* -m flag */
103 int lite = 0; /* -L flag */
104 long numops = -1; /* -N flag */
105 int randomoplen = 1; /* -O flag disables it */
106 int seed = 1; /* -S flag */
107 int mapped_writes = 1; /* -W flag disables */
108 int mapped_reads = 1; /* -R flag disables it */
110 int o_direct; /* -Z */
117 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
120 #define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d)
121 #define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d)
123 #define fsxread(a,b,c,d) read(a,b,c)
124 #define fsxwrite(a,b,c,d) write(a,b,c)
127 FILE * fsxlogf = NULL;
131 static void *round_up(void *ptr, unsigned long align, unsigned long offset)
133 unsigned long ret = (unsigned long)ptr;
135 ret = ((ret + align - 1) & ~(align - 1));
141 vwarnc(int code, const char *fmt, va_list ap) {
142 fprintf(stderr, "fsx: ");
144 vfprintf(stderr, fmt, ap);
145 fprintf(stderr, ": ");
147 fprintf(stderr, "%s\n", strerror(code));
151 warn(const char * fmt, ...) {
154 vwarnc(errno, fmt, ap);
158 #define BUF_SIZE 1024
164 char buffer[BUF_SIZE];
167 vsnprintf(buffer, BUF_SIZE, fmt, args);
169 fprintf(stdout, buffer);
171 fprintf(fsxlogf, buffer);
177 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
182 log4(int operation, int arg0, int arg1, int arg2)
184 struct log_entry *le;
187 le->operation = operation;
189 le->operation = ~ le->operation;
195 if (logptr >= LOGSIZE)
204 struct log_entry *lp;
206 prt("LOG DUMP (%d total operations):\n", logcount);
207 if (logcount < LOGSIZE) {
214 for ( ; count > 0; count--) {
217 opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
218 prt("%d(%d mod 256): ", opnum, opnum%256);
220 if ((closeopen = lp->operation < 0))
221 lp->operation = ~ lp->operation;
223 switch (lp->operation) {
225 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
226 lp->args[0], lp->args[0] + lp->args[1] - 1,
228 if (badoff >= lp->args[0] && badoff <
229 lp->args[0] + lp->args[1])
233 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
234 lp->args[0], lp->args[0] + lp->args[1] - 1,
236 if (badoff >= lp->args[0] && badoff <
237 lp->args[0] + lp->args[1])
241 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
242 lp->args[0], lp->args[0] + lp->args[1] - 1,
244 if (badoff >= lp->args[0] &&
245 badoff < lp->args[0] + lp->args[1])
249 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
250 lp->args[0], lp->args[0] + lp->args[1] - 1,
252 if (lp->args[0] > lp->args[2])
254 else if (lp->args[0] + lp->args[1] > lp->args[2])
256 if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
257 badoff < lp->args[0] + lp->args[1])
261 down = lp->args[0] < lp->args[1];
262 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
263 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
264 if (badoff >= lp->args[!down] &&
265 badoff < lp->args[!!down])
269 prt("SKIPPED (no operation)");
272 prt("BOGUS LOG ENTRY (operation code = %d)!",
276 prt("\n\t\tCLOSE/OPEN");
286 save_buffer(char *buffer, off_t bufferlength, int fd)
289 ssize_t byteswritten;
291 if (fd <= 0 || bufferlength == 0)
294 if (bufferlength > SSIZE_MAX) {
295 prt("fsx flaw: overflow in save_buffer\n");
299 off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
300 if (size_by_seek == (off_t)-1)
301 prterr("save_buffer: lseek eof");
302 else if (bufferlength > size_by_seek) {
303 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
304 (unsigned long long)bufferlength);
305 bufferlength = size_by_seek;
309 ret = lseek(fd, (off_t)0, SEEK_SET);
310 if (ret == (off_t)-1)
311 prterr("save_buffer: lseek 0");
313 byteswritten = write(fd, buffer, (size_t)bufferlength);
314 if (byteswritten != bufferlength) {
315 if (byteswritten == -1)
316 prterr("save_buffer write");
318 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
319 (unsigned)byteswritten,
320 (unsigned long long)bufferlength);
326 report_failure(int status)
332 save_buffer(good_buf, file_size, fsxgoodfd);
333 prt("Correct content saved for comparison\n");
334 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
343 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
344 *(((unsigned char *)(cp)) + 1)))
347 check_buffers(unsigned offset, unsigned size)
355 if (memcmp(good_buf + offset, temp_buf, size) != 0) {
356 prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
357 offset, size, fname);
358 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
360 c = good_buf[offset];
364 bad = short_at(&temp_buf[i]);
365 prt("0x%5x\t0x%04x\t0x%04x", offset,
366 short_at(&good_buf[offset]), bad);
367 op = temp_buf[offset & 1 ? i+1 : i];
370 prt("operation# (mod 256) for "
371 "the bad data may be %u\n",
372 ((unsigned)op & 0xff));
374 prt("operation# (mod 256) for "
375 "the bad data unknown, check"
376 " HOLE and EXTEND ops\n");
396 if (fstat(fd, &statbuf)) {
397 prterr("check_size: fstat");
398 statbuf.st_size = -1;
400 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
401 if (file_size != statbuf.st_size || file_size != size_by_seek) {
402 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
403 (unsigned long long)file_size,
404 (unsigned long long)statbuf.st_size,
405 (unsigned long long)size_by_seek);
412 check_trunc_hack(void)
416 ftruncate(fd, (off_t)0);
417 ftruncate(fd, (off_t)100000);
419 if (statbuf.st_size != (off_t)100000) {
420 prt("no extend on truncate! not posix!\n");
427 doflush(unsigned offset, unsigned size)
433 if (o_direct == O_DIRECT)
436 pg_offset = offset & mmap_mask;
437 map_size = pg_offset + size;
439 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
440 MAP_FILE | MAP_SHARED, fd,
441 (off_t)(offset - pg_offset))) == (char *)-1) {
442 prterr("doflush: mmap");
445 if (msync(p, map_size, MS_INVALIDATE) != 0) {
446 prterr("doflush: msync");
449 if (munmap(p, map_size) != 0) {
450 prterr("doflush: munmap");
456 doread(unsigned offset, unsigned size)
461 offset -= offset % readbdy;
463 size -= size % readbdy;
465 if (!quiet && testcalls > simulatedopcount && !o_direct)
466 prt("skipping zero size read\n");
467 log4(OP_SKIPPED, OP_READ, offset, size);
470 if (size + offset > file_size) {
471 if (!quiet && testcalls > simulatedopcount)
472 prt("skipping seek/read past end of file\n");
473 log4(OP_SKIPPED, OP_READ, offset, size);
477 log4(OP_READ, offset, size, 0);
479 if (testcalls <= simulatedopcount)
483 ((progressinterval && testcalls % progressinterval == 0) ||
485 (monitorstart == -1 ||
486 (offset + size > monitorstart &&
487 (monitorend == -1 || offset <= monitorend))))))
488 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
489 offset, offset + size - 1, size);
490 ret = lseek(fd, (off_t)offset, SEEK_SET);
491 if (ret == (off_t)-1) {
492 prterr("doread: lseek");
495 iret = fsxread(fd, temp_buf, size, offset);
498 prterr("doread: read");
500 prt("short read: 0x%x bytes instead of 0x%x\n",
504 check_buffers(offset, size);
509 check_eofpage(char *s, unsigned offset, char *p, int size)
511 unsigned long last_page, should_be_zero;
513 if (offset + size <= (file_size & ~page_mask))
516 * we landed in the last page of the file
517 * test to make sure the VM system provided 0's
518 * beyond the true end of the file mapping
519 * (as required by mmap def in 1996 posix 1003.1)
521 last_page = ((unsigned long)p + (offset & page_mask) + size) & ~page_mask;
523 for (should_be_zero = last_page + (file_size & page_mask);
524 should_be_zero < last_page + page_size;
526 if (*(char *)should_be_zero) {
527 prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
528 s, file_size - 1, should_be_zero & page_mask,
529 short_at(should_be_zero));
536 domapread(unsigned offset, unsigned size)
542 offset -= offset % readbdy;
544 if (!quiet && testcalls > simulatedopcount)
545 prt("skipping zero size read\n");
546 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
549 if (size + offset > file_size) {
550 if (!quiet && testcalls > simulatedopcount)
551 prt("skipping seek/read past end of file\n");
552 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
556 log4(OP_MAPREAD, offset, size, 0);
558 if (testcalls <= simulatedopcount)
562 ((progressinterval && testcalls % progressinterval == 0) ||
564 (monitorstart == -1 ||
565 (offset + size > monitorstart &&
566 (monitorend == -1 || offset <= monitorend))))))
567 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
568 offset, offset + size - 1, size);
570 pg_offset = offset & PAGE_MASK;
571 map_size = pg_offset + size;
573 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd,
574 (off_t)(offset - pg_offset))) == (char *)-1) {
575 prterr("domapread: mmap");
578 memcpy(temp_buf, p + pg_offset, size);
580 check_eofpage("Read", offset, p, size);
582 if (munmap(p, map_size) != 0) {
583 prterr("domapread: munmap");
587 check_buffers(offset, size);
592 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
595 good_buf[offset] = testcalls % 256;
597 good_buf[offset] += original_buf[offset];
604 dowrite(unsigned offset, unsigned size)
609 offset -= offset % writebdy;
611 size -= size % writebdy;
613 if (!quiet && testcalls > simulatedopcount && !o_direct)
614 prt("skipping zero size write\n");
615 log4(OP_SKIPPED, OP_WRITE, offset, size);
619 log4(OP_WRITE, offset, size, file_size);
621 gendata(original_buf, good_buf, offset, size);
622 if (file_size < offset + size) {
623 if (file_size < offset)
624 memset(good_buf + file_size, '\0', offset - file_size);
625 file_size = offset + size;
627 warn("Lite file size bug in fsx!");
632 if (testcalls <= simulatedopcount)
636 ((progressinterval && testcalls % progressinterval == 0) ||
638 (monitorstart == -1 ||
639 (offset + size > monitorstart &&
640 (monitorend == -1 || offset <= monitorend))))))
641 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
642 offset, offset + size - 1, size);
643 ret = lseek(fd, (off_t)offset, SEEK_SET);
644 if (ret == (off_t)-1) {
645 prterr("dowrite: lseek");
648 iret = fsxwrite(fd, good_buf + offset, size, offset);
651 prterr("dowrite: write");
653 prt("short write: 0x%x bytes instead of 0x%x\n",
659 prt("fsync() failed: %s\n", strerror(errno));
664 doflush(offset, size);
670 domapwrite(unsigned offset, unsigned size)
677 offset -= offset % writebdy;
679 if (!quiet && testcalls > simulatedopcount)
680 prt("skipping zero size write\n");
681 log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
684 cur_filesize = file_size;
686 log4(OP_MAPWRITE, offset, size, 0);
688 gendata(original_buf, good_buf, offset, size);
689 if (file_size < offset + size) {
690 if (file_size < offset)
691 memset(good_buf + file_size, '\0', offset - file_size);
692 file_size = offset + size;
694 warn("Lite file size bug in fsx!");
699 if (testcalls <= simulatedopcount)
703 ((progressinterval && testcalls % progressinterval == 0) ||
705 (monitorstart == -1 ||
706 (offset + size > monitorstart &&
707 (monitorend == -1 || offset <= monitorend))))))
708 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
709 offset, offset + size - 1, size);
711 if (file_size > cur_filesize) {
712 if (ftruncate(fd, file_size) == -1) {
713 prterr("domapwrite: ftruncate");
717 pg_offset = offset & PAGE_MASK;
718 map_size = pg_offset + size;
720 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
721 MAP_FILE | MAP_SHARED, fd,
722 (off_t)(offset - pg_offset))) == (char *)-1) {
723 prterr("domapwrite: mmap");
726 memcpy(p + pg_offset, good_buf + offset, size);
727 if (msync(p, map_size, 0) != 0) {
728 prterr("domapwrite: msync");
732 check_eofpage("Write", offset, p, size);
734 if (munmap(p, map_size) != 0) {
735 prterr("domapwrite: munmap");
742 dotruncate(unsigned size)
744 int oldsize = file_size;
746 size -= size % truncbdy;
747 if (size > biggest) {
749 if (!quiet && testcalls > simulatedopcount)
750 prt("truncating to largest ever: 0x%x\n", size);
753 log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
755 if (size > file_size)
756 memset(good_buf + file_size, '\0', size - file_size);
759 if (testcalls <= simulatedopcount)
762 if ((progressinterval && testcalls % progressinterval == 0) ||
763 (debug && (monitorstart == -1 || monitorend == -1 ||
764 size <= monitorend)))
765 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
766 if (ftruncate(fd, (off_t)size) == -1) {
767 prt("ftruncate1: %x\n", size);
768 prterr("dotruncate: ftruncate");
779 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
780 prterr("writefileimage: lseek");
783 iret = write(fd, good_buf, file_size);
784 if ((off_t)iret != file_size) {
786 prterr("writefileimage: write");
788 prt("short write: 0x%x bytes instead of 0x%llx\n",
789 iret, (unsigned long long)file_size);
792 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
793 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
794 prterr("writefileimage: ftruncate");
803 if (testcalls <= simulatedopcount)
807 prt("%lu close/open\n", testcalls);
809 prterr("docloseopen: close");
812 fd = open(fname, O_RDWR|o_direct, 0);
814 prterr("docloseopen: open");
823 unsigned long offset;
824 unsigned long size = maxoplen;
825 unsigned long rv = random();
826 unsigned long op = rv % (3 + !lite + mapped_writes);
828 /* turn off the map read if necessary */
830 if (op == 2 && !mapped_reads)
833 if (simulatedopcount > 0 && testcalls == simulatedopcount)
839 closeopen = (rv >> 3) < (1 << 28) / closeprob;
841 if (debugstart > 0 && testcalls >= debugstart)
844 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
845 prt("%lu...\n", testcalls);
852 * MAPWRITE: op = 3 or 4
854 if (lite ? 0 : op == 3 && (style & 1) == 0) /* vanilla truncate? */
855 dotruncate(random() % maxfilelen);
858 size = random() % (maxoplen+1);
859 if (lite ? 0 : op == 3)
863 if (op == 1 || op == (lite ? 3 : 4)) {
864 offset %= maxfilelen;
865 if (offset + size > maxfilelen)
866 size = maxfilelen - offset;
868 domapwrite(offset, size);
870 dowrite(offset, size);
876 if (offset + size > file_size)
877 size = file_size - offset;
879 domapread(offset, size);
881 doread(offset, size);
885 if (sizechecks && testcalls > simulatedopcount)
897 prt("signal %d\n", sig);
898 prt("testcalls = %lu\n", testcalls);
906 fprintf(stdout, "usage: %s",
907 "fsx [-dnqxALOWZ] [-b opnum] [-c Prob] [-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\
908 -b opnum: beginning operation number (default 1)\n\
909 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
910 -d: debug output for all operations\n\
911 -f flush and invalidate cache after I/O\n\
912 -l flen: the upper bound on file size (default 262144)\n\
913 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
914 -n: no verifications of file size\n\
915 -o oplen: the upper bound on operation size (default 65536)\n\
916 -p progressinterval: debug output at specified operation interval\n\
917 -q: quieter operation\n\
918 -r readbdy: 4096 would make reads page aligned (default 1)\n\
919 -s style: 1 gives smaller truncates (default 0)\n\
920 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
921 -w writebdy: 4096 would make writes page aligned (default 1)\n\
922 -x: preallocate file space before starting, XFS only (default 0)\n\
923 -y synchronize changes to a file\n"
926 " -A: Use the AIO system calls\n"
928 " -D startingop: debug output starting at specified operation\n\
929 -L: fsxLite - no file creations & no file size changes\n\
930 -N numops: total # operations to do (default infinity)\n\
931 -O: use oplen (see -o flag) for every op (default random)\n\
932 -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
933 -S seed: for random # generator (default 1) 0 gets timestamp\n\
934 -W: mapped write operations DISabled\n\
935 -R: read() system calls only (mapped reads disabled)\n\
936 -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
937 fname: this filename is REQUIRED (no default)\n");
943 getnum(char *s, char **e)
948 ret = strtol(s, e, 0);
984 ret = io_queue_init(QSZ, &io_ctx);
986 fprintf(stderr, "aio_setup: io_queue_init failed: %s\n",
994 __aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
996 struct io_event event;
997 static struct timespec ts;
998 struct iocb *iocbs[] = { &iocb };
1003 io_prep_pread(&iocb, fd, buf, len, offset);
1005 io_prep_pwrite(&iocb, fd, buf, len, offset);
1010 ret = io_submit(io_ctx, 1, iocbs);
1012 fprintf(stderr, "errcode=%d\n", ret);
1013 fprintf(stderr, "aio_rw: io_submit failed: %s\n",
1018 ret = io_getevents(io_ctx, 1, 1, &event, &ts);
1021 fprintf(stderr, "aio_rw: no events available\n");
1023 fprintf(stderr, "errcode=%d\n", -ret);
1024 fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
1029 if (len != event.res) {
1031 * The b0rked libaio defines event.res as unsigned.
1032 * However the kernel strucuture has it signed,
1033 * and it's used to pass negated error value.
1034 * Till the library is fixed use the temp var.
1036 res = (long)event.res;
1038 fprintf(stderr, "bad io length: %lu instead of %u\n",
1041 fprintf(stderr, "errcode=%d\n", -res);
1042 fprintf(stderr, "aio_rw: async io failed: %s\n",
1053 * The caller expects error return in traditional libc
1054 * convention, i.e. -1 and the errno set to error.
1060 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
1065 ret = __aio_rw(rw, fd, buf, len, offset);
1068 ret = read(fd, buf, len);
1070 ret = write(fd, buf, len);
1078 main(int argc, char **argv)
1082 char goodfile[1024];
1088 page_size = getpagesize();
1089 page_mask = page_size - 1;
1090 mmap_mask = page_mask;
1093 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1095 while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:LN:OP:RS:WZ"))
1099 simulatedopcount = getnum(optarg, &endp);
1101 fprintf(stdout, "Will begin at operation %ld\n",
1103 if (simulatedopcount == 0)
1105 simulatedopcount -= 1;
1108 closeprob = getnum(optarg, &endp);
1111 "Chance of close/open is 1 in %d\n",
1123 maxfilelen = getnum(optarg, &endp);
1124 if (maxfilelen <= 0)
1128 monitorstart = getnum(optarg, &endp);
1129 if (monitorstart < 0)
1131 if (!endp || *endp++ != ':')
1133 monitorend = getnum(endp, &endp);
1136 if (monitorend == 0)
1137 monitorend = -1; /* aka infinity */
1143 maxoplen = getnum(optarg, &endp);
1148 progressinterval = getnum(optarg, &endp);
1149 if (progressinterval == 0)
1156 readbdy = getnum(optarg, &endp);
1161 style = getnum(optarg, &endp);
1162 if (style < 0 || style > 1)
1166 truncbdy = getnum(optarg, &endp);
1171 writebdy = getnum(optarg, &endp);
1185 debugstart = getnum(optarg, &endp);
1193 numops = getnum(optarg, &endp);
1201 strncpy(goodfile, optarg, sizeof(goodfile));
1202 strcat(goodfile, "/");
1203 strncpy(logfile, optarg, sizeof(logfile));
1204 strcat(logfile, "/");
1210 seed = getnum(optarg, &endp);
1212 seed = time(0) % 10000;
1214 fprintf(stdout, "Seed set to %d\n", seed);
1221 fprintf(stdout, "mapped writes DISABLED\n");
1224 o_direct = O_DIRECT;
1236 signal(SIGHUP, cleanup);
1237 signal(SIGINT, cleanup);
1238 signal(SIGPIPE, cleanup);
1239 signal(SIGALRM, cleanup);
1240 signal(SIGTERM, cleanup);
1241 signal(SIGXCPU, cleanup);
1242 signal(SIGXFSZ, cleanup);
1243 signal(SIGVTALRM, cleanup);
1244 signal(SIGUSR1, cleanup);
1245 signal(SIGUSR2, cleanup);
1247 initstate(seed, state, 256);
1250 O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666);
1257 xfs_flock64_t resv = { 0 };
1258 #ifdef HAVE_XFS_PLATFORM_DEFS_H
1259 if (!platform_test_xfs_fd(fd)) {
1261 fprintf(stderr, "main: cannot prealloc, non XFS\n");
1265 resv.l_len = maxfilelen;
1266 if ((xfsctl(fname, fd, XFS_IOC_RESVSP, &resv)) < 0) {
1272 strncat(goodfile, fname, 256);
1273 strcat (goodfile, ".fsxgood");
1274 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1275 if (fsxgoodfd < 0) {
1279 strncat(logfile, fname, 256);
1280 strcat (logfile, ".fsxlog");
1281 fsxlogf = fopen(logfile, "w");
1282 if (fsxlogf == NULL) {
1294 file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
1295 if (file_size == (off_t)-1) {
1297 warn("main: lseek eof");
1300 ret = lseek(fd, (off_t)0, SEEK_SET);
1301 if (ret == (off_t)-1) {
1303 warn("main: lseek 0");
1307 original_buf = (char *) malloc(maxfilelen);
1308 for (i = 0; i < maxfilelen; i++)
1309 original_buf[i] = random() % 256;
1310 good_buf = (char *) malloc(maxfilelen + writebdy);
1311 good_buf = round_up(good_buf, writebdy, 0);
1312 memset(good_buf, '\0', maxfilelen);
1313 temp_buf = (char *) malloc(maxoplen + readbdy);
1314 temp_buf = round_up(temp_buf, readbdy, 0);
1315 memset(temp_buf, '\0', maxoplen);
1316 if (lite) { /* zero entire existing file */
1319 written = write(fd, good_buf, (size_t)maxfilelen);
1320 if (written != maxfilelen) {
1321 if (written == -1) {
1323 warn("main: error on write");
1325 warn("main: short write, 0x%x bytes instead "
1334 while (numops == -1 || numops--)
1341 prt("All operations completed A-OK!\n");