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.
38 #define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
41 * A log entry is an operation and a bunch of arguments.
51 struct log_entry oplog[LOGSIZE]; /* the log */
52 int logptr = 0; /* current position in log */
53 int logcount = 0; /* total ops */
62 #define OP_CLOSEOPEN 4
68 #define PAGE_SIZE getpagesize()
70 #define PAGE_MASK (PAGE_SIZE - 1)
72 char *original_buf; /* a pointer to the original data */
73 char *good_buf; /* a pointer to the correct data */
74 char *temp_buf; /* a pointer to the current data */
75 char *fname; /* name of our test file */
76 int fd; /* fd for our test file */
81 unsigned long testcalls = 0; /* calls to function "test" */
83 unsigned long simulatedopcount = 0; /* -b flag */
84 int closeprob = 0; /* -c flag */
85 int debug = 0; /* -d flag */
86 unsigned long debugstart = 0; /* -D flag */
87 int flush = 0; /* -f flag */
88 int do_fsync = 0; /* -y flag */
89 unsigned long maxfilelen = 256 * 1024; /* -l flag */
90 int sizechecks = 1; /* -n flag disables them */
91 int maxoplen = 64 * 1024; /* -o flag */
92 int quiet = 0; /* -q flag */
93 unsigned long progressinterval = 0; /* -p flag */
94 int readbdy = 1; /* -r flag */
95 int style = 0; /* -s flag */
96 int prealloc = 0; /* -x flag */
97 int truncbdy = 1; /* -t flag */
98 int writebdy = 1; /* -w flag */
99 long monitorstart = -1; /* -m flag */
100 long monitorend = -1; /* -m flag */
101 int lite = 0; /* -L flag */
102 long numops = -1; /* -N flag */
103 int randomoplen = 1; /* -O flag disables it */
104 int seed = 1; /* -S flag */
105 int mapped_writes = 1; /* -W flag disables */
106 int mapped_reads = 1; /* -R flag disables it */
108 int o_direct; /* -Z */
115 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
118 #define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d)
119 #define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d)
121 #define fsxread(a,b,c,d) read(a,b,c)
122 #define fsxwrite(a,b,c,d) write(a,b,c)
125 FILE * fsxlogf = NULL;
129 static void *round_up(void *ptr, unsigned long align, unsigned long offset)
131 unsigned long ret = (unsigned long)ptr;
133 ret = ((ret + align - 1) & ~(align - 1));
139 vwarnc(int code, const char *fmt, va_list ap) {
140 fprintf(stderr, "fsx: ");
142 vfprintf(stderr, fmt, ap);
143 fprintf(stderr, ": ");
145 fprintf(stderr, "%s\n", strerror(code));
149 warn(const char * fmt, ...) {
152 vwarnc(errno, fmt, ap);
156 #define BUF_SIZE 1024
162 char buffer[BUF_SIZE];
165 vsnprintf(buffer, BUF_SIZE, fmt, args);
167 fprintf(stdout, buffer);
169 fprintf(fsxlogf, buffer);
175 prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
180 log4(int operation, int arg0, int arg1, int arg2)
182 struct log_entry *le;
185 le->operation = operation;
187 le->operation = ~ le->operation;
193 if (logptr >= LOGSIZE)
202 struct log_entry *lp;
204 prt("LOG DUMP (%d total operations):\n", logcount);
205 if (logcount < LOGSIZE) {
212 for ( ; count > 0; count--) {
215 opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
216 prt("%d(%d mod 256): ", opnum, opnum%256);
218 if ((closeopen = lp->operation < 0))
219 lp->operation = ~ lp->operation;
221 switch (lp->operation) {
223 prt("MAPREAD\t0x%x thru 0x%x\t(0x%x bytes)",
224 lp->args[0], lp->args[0] + lp->args[1] - 1,
226 if (badoff >= lp->args[0] && badoff <
227 lp->args[0] + lp->args[1])
231 prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
232 lp->args[0], lp->args[0] + lp->args[1] - 1,
234 if (badoff >= lp->args[0] && badoff <
235 lp->args[0] + lp->args[1])
239 prt("READ\t0x%x thru 0x%x\t(0x%x bytes)",
240 lp->args[0], lp->args[0] + lp->args[1] - 1,
242 if (badoff >= lp->args[0] &&
243 badoff < lp->args[0] + lp->args[1])
247 prt("WRITE\t0x%x thru 0x%x\t(0x%x bytes)",
248 lp->args[0], lp->args[0] + lp->args[1] - 1,
250 if (lp->args[0] > lp->args[2])
252 else if (lp->args[0] + lp->args[1] > lp->args[2])
254 if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
255 badoff < lp->args[0] + lp->args[1])
259 down = lp->args[0] < lp->args[1];
260 prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
261 down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
262 if (badoff >= lp->args[!down] &&
263 badoff < lp->args[!!down])
267 prt("SKIPPED (no operation)");
270 prt("BOGUS LOG ENTRY (operation code = %d)!",
274 prt("\n\t\tCLOSE/OPEN");
284 save_buffer(char *buffer, off_t bufferlength, int fd)
287 ssize_t byteswritten;
289 if (fd <= 0 || bufferlength == 0)
292 if (bufferlength > SSIZE_MAX) {
293 prt("fsx flaw: overflow in save_buffer\n");
297 off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
298 if (size_by_seek == (off_t)-1)
299 prterr("save_buffer: lseek eof");
300 else if (bufferlength > size_by_seek) {
301 warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
302 (unsigned long long)bufferlength);
303 bufferlength = size_by_seek;
307 ret = lseek(fd, (off_t)0, SEEK_SET);
308 if (ret == (off_t)-1)
309 prterr("save_buffer: lseek 0");
311 byteswritten = write(fd, buffer, (size_t)bufferlength);
312 if (byteswritten != bufferlength) {
313 if (byteswritten == -1)
314 prterr("save_buffer write");
316 warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
317 (unsigned)byteswritten,
318 (unsigned long long)bufferlength);
324 report_failure(int status)
330 save_buffer(good_buf, file_size, fsxgoodfd);
331 prt("Correct content saved for comparison\n");
332 prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
341 #define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
342 *(((unsigned char *)(cp)) + 1)))
345 check_buffers(unsigned offset, unsigned size)
353 if (bcmp(good_buf + offset, temp_buf, size) != 0) {
354 prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
355 offset, size, fname);
356 prt("OFFSET\tGOOD\tBAD\tRANGE\n");
358 c = good_buf[offset];
362 bad = short_at(&temp_buf[i]);
363 prt("0x%5x\t0x%04x\t0x%04x", offset,
364 short_at(&good_buf[offset]), bad);
365 op = temp_buf[offset & 1 ? i+1 : i];
368 prt("operation# (mod 256) for "
369 "the bad data may be %u\n",
370 ((unsigned)op & 0xff));
372 prt("operation# (mod 256) for "
373 "the bad data unknown, check"
374 " HOLE and EXTEND ops\n");
394 if (fstat(fd, &statbuf)) {
395 prterr("check_size: fstat");
396 statbuf.st_size = -1;
398 size_by_seek = lseek(fd, (off_t)0, SEEK_END);
399 if (file_size != statbuf.st_size || file_size != size_by_seek) {
400 prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
401 (unsigned long long)file_size,
402 (unsigned long long)statbuf.st_size,
403 (unsigned long long)size_by_seek);
410 check_trunc_hack(void)
414 ftruncate(fd, (off_t)0);
415 ftruncate(fd, (off_t)100000);
417 if (statbuf.st_size != (off_t)100000) {
418 prt("no extend on truncate! not posix!\n");
425 doflush(unsigned offset, unsigned size)
431 if (o_direct == O_DIRECT)
434 pg_offset = offset & mmap_mask;
435 map_size = pg_offset + size;
437 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
438 MAP_FILE | MAP_SHARED, fd,
439 (off_t)(offset - pg_offset))) == (char *)-1) {
440 prterr("doflush: mmap");
443 if (msync(p, map_size, MS_INVALIDATE) != 0) {
444 prterr("doflush: msync");
447 if (munmap(p, map_size) != 0) {
448 prterr("doflush: munmap");
454 doread(unsigned offset, unsigned size)
459 offset -= offset % readbdy;
461 size -= size % readbdy;
463 if (!quiet && testcalls > simulatedopcount && !o_direct)
464 prt("skipping zero size read\n");
465 log4(OP_SKIPPED, OP_READ, offset, size);
468 if (size + offset > file_size) {
469 if (!quiet && testcalls > simulatedopcount)
470 prt("skipping seek/read past end of file\n");
471 log4(OP_SKIPPED, OP_READ, offset, size);
475 log4(OP_READ, offset, size, 0);
477 if (testcalls <= simulatedopcount)
481 ((progressinterval && testcalls % progressinterval == 0) ||
483 (monitorstart == -1 ||
484 (offset + size > monitorstart &&
485 (monitorend == -1 || offset <= monitorend))))))
486 prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
487 offset, offset + size - 1, size);
488 ret = lseek(fd, (off_t)offset, SEEK_SET);
489 if (ret == (off_t)-1) {
490 prterr("doread: lseek");
493 iret = fsxread(fd, temp_buf, size, offset);
496 prterr("doread: read");
498 prt("short read: 0x%x bytes instead of 0x%x\n",
502 check_buffers(offset, size);
507 domapread(unsigned offset, unsigned size)
513 offset -= offset % readbdy;
515 if (!quiet && testcalls > simulatedopcount)
516 prt("skipping zero size read\n");
517 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
520 if (size + offset > file_size) {
521 if (!quiet && testcalls > simulatedopcount)
522 prt("skipping seek/read past end of file\n");
523 log4(OP_SKIPPED, OP_MAPREAD, offset, size);
527 log4(OP_MAPREAD, offset, size, 0);
529 if (testcalls <= simulatedopcount)
533 ((progressinterval && testcalls % progressinterval == 0) ||
535 (monitorstart == -1 ||
536 (offset + size > monitorstart &&
537 (monitorend == -1 || offset <= monitorend))))))
538 prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
539 offset, offset + size - 1, size);
541 pg_offset = offset & PAGE_MASK;
542 map_size = pg_offset + size;
544 if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd,
545 (off_t)(offset - pg_offset))) == (char *)-1) {
546 prterr("domapread: mmap");
549 memcpy(temp_buf, p + pg_offset, size);
550 if (munmap(p, map_size) != 0) {
551 prterr("domapread: munmap");
555 check_buffers(offset, size);
560 gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
563 good_buf[offset] = testcalls % 256;
565 good_buf[offset] += original_buf[offset];
572 dowrite(unsigned offset, unsigned size)
577 offset -= offset % writebdy;
579 size -= size % writebdy;
581 if (!quiet && testcalls > simulatedopcount && !o_direct)
582 prt("skipping zero size write\n");
583 log4(OP_SKIPPED, OP_WRITE, offset, size);
587 log4(OP_WRITE, offset, size, file_size);
589 gendata(original_buf, good_buf, offset, size);
590 if (file_size < offset + size) {
591 if (file_size < offset)
592 bzero(good_buf + file_size, offset - file_size);
593 file_size = offset + size;
595 warn("Lite file size bug in fsx!");
600 if (testcalls <= simulatedopcount)
604 ((progressinterval && testcalls % progressinterval == 0) ||
606 (monitorstart == -1 ||
607 (offset + size > monitorstart &&
608 (monitorend == -1 || offset <= monitorend))))))
609 prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
610 offset, offset + size - 1, size);
611 ret = lseek(fd, (off_t)offset, SEEK_SET);
612 if (ret == (off_t)-1) {
613 prterr("dowrite: lseek");
616 iret = fsxwrite(fd, good_buf + offset, size, offset);
619 prterr("dowrite: write");
621 prt("short write: 0x%x bytes instead of 0x%x\n",
627 prt("fsync() failed: %s\n", strerror(errno));
632 doflush(offset, size);
638 domapwrite(unsigned offset, unsigned size)
645 offset -= offset % writebdy;
647 if (!quiet && testcalls > simulatedopcount)
648 prt("skipping zero size write\n");
649 log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
652 cur_filesize = file_size;
654 log4(OP_MAPWRITE, offset, size, 0);
656 gendata(original_buf, good_buf, offset, size);
657 if (file_size < offset + size) {
658 if (file_size < offset)
659 bzero(good_buf + file_size, offset - file_size);
660 file_size = offset + size;
662 warn("Lite file size bug in fsx!");
667 if (testcalls <= simulatedopcount)
671 ((progressinterval && testcalls % progressinterval == 0) ||
673 (monitorstart == -1 ||
674 (offset + size > monitorstart &&
675 (monitorend == -1 || offset <= monitorend))))))
676 prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
677 offset, offset + size - 1, size);
679 if (file_size > cur_filesize) {
680 if (ftruncate(fd, file_size) == -1) {
681 prterr("domapwrite: ftruncate");
685 pg_offset = offset & PAGE_MASK;
686 map_size = pg_offset + size;
688 if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
689 MAP_FILE | MAP_SHARED, fd,
690 (off_t)(offset - pg_offset))) == (char *)-1) {
691 prterr("domapwrite: mmap");
694 memcpy(p + pg_offset, good_buf + offset, size);
695 if (msync(p, map_size, 0) != 0) {
696 prterr("domapwrite: msync");
699 if (munmap(p, map_size) != 0) {
700 prterr("domapwrite: munmap");
707 dotruncate(unsigned size)
709 int oldsize = file_size;
711 size -= size % truncbdy;
712 if (size > biggest) {
714 if (!quiet && testcalls > simulatedopcount)
715 prt("truncating to largest ever: 0x%x\n", size);
718 log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
720 if (size > file_size)
721 bzero(good_buf + file_size, size - file_size);
724 if (testcalls <= simulatedopcount)
727 if ((progressinterval && testcalls % progressinterval == 0) ||
728 (debug && (monitorstart == -1 || monitorend == -1 ||
729 size <= monitorend)))
730 prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
731 if (ftruncate(fd, (off_t)size) == -1) {
732 prt("ftruncate1: %x\n", size);
733 prterr("dotruncate: ftruncate");
744 if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
745 prterr("writefileimage: lseek");
748 iret = write(fd, good_buf, file_size);
749 if ((off_t)iret != file_size) {
751 prterr("writefileimage: write");
753 prt("short write: 0x%x bytes instead of 0x%llx\n",
754 iret, (unsigned long long)file_size);
757 if (lite ? 0 : ftruncate(fd, file_size) == -1) {
758 prt("ftruncate2: %llx\n", (unsigned long long)file_size);
759 prterr("writefileimage: ftruncate");
768 if (testcalls <= simulatedopcount)
772 prt("%lu close/open\n", testcalls);
774 prterr("docloseopen: close");
777 fd = open(fname, O_RDWR|o_direct, 0);
779 prterr("docloseopen: open");
788 unsigned long offset;
789 unsigned long size = maxoplen;
790 unsigned long rv = random();
791 unsigned long op = rv % (3 + !lite + mapped_writes);
793 /* turn off the map read if necessary */
795 if (op == 2 && !mapped_reads)
798 if (simulatedopcount > 0 && testcalls == simulatedopcount)
804 closeopen = (rv >> 3) < (1 << 28) / closeprob;
806 if (debugstart > 0 && testcalls >= debugstart)
809 if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
810 prt("%lu...\n", testcalls);
817 * MAPWRITE: op = 3 or 4
819 if (lite ? 0 : op == 3 && (style & 1) == 0) /* vanilla truncate? */
820 dotruncate(random() % maxfilelen);
823 size = random() % (maxoplen+1);
824 if (lite ? 0 : op == 3)
828 if (op == 1 || op == (lite ? 3 : 4)) {
829 offset %= maxfilelen;
830 if (offset + size > maxfilelen)
831 size = maxfilelen - offset;
833 domapwrite(offset, size);
835 dowrite(offset, size);
841 if (offset + size > file_size)
842 size = file_size - offset;
844 domapread(offset, size);
846 doread(offset, size);
850 if (sizechecks && testcalls > simulatedopcount)
862 prt("signal %d\n", sig);
863 prt("testcalls = %lu\n", testcalls);
871 fprintf(stdout, "usage: %s",
872 "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\
873 -b opnum: beginning operation number (default 1)\n\
874 -c P: 1 in P chance of file close+open at each op (default infinity)\n\
875 -d: debug output for all operations\n\
876 -f flush and invalidate cache after I/O\n\
877 -l flen: the upper bound on file size (default 262144)\n\
878 -m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
879 -n: no verifications of file size\n\
880 -o oplen: the upper bound on operation size (default 65536)\n\
881 -p progressinterval: debug output at specified operation interval\n\
882 -q: quieter operation\n\
883 -r readbdy: 4096 would make reads page aligned (default 1)\n\
884 -s style: 1 gives smaller truncates (default 0)\n\
885 -t truncbdy: 4096 would make truncates page aligned (default 1)\n\
886 -w writebdy: 4096 would make writes page aligned (default 1)\n\
887 -x: preallocate file space before starting, XFS only (default 0)\n\
888 -y synchronize changes to a file\n"
891 " -A: Use the AIO system calls\n"
893 " -D startingop: debug output starting at specified operation\n\
894 -L: fsxLite - no file creations & no file size changes\n\
895 -N numops: total # operations to do (default infinity)\n\
896 -O: use oplen (see -o flag) for every op (default random)\n\
897 -P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
898 -S seed: for random # generator (default 1) 0 gets timestamp\n\
899 -W: mapped write operations DISabled\n\
900 -R: read() system calls only (mapped reads disabled)\n\
901 -Z: O_DIRECT (use -R, -W, -r and -w too)\n\
902 fname: this filename is REQUIRED (no default)\n");
908 getnum(char *s, char **e)
913 ret = strtol(s, e, 0);
949 ret = io_queue_init(QSZ, &io_ctx);
951 fprintf(stderr, "aio_setup: io_queue_init failed: %s\n",
959 __aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
961 struct io_event event;
962 static struct timespec ts;
963 struct iocb *iocbs[] = { &iocb };
968 io_prep_pread(&iocb, fd, buf, len, offset);
970 io_prep_pwrite(&iocb, fd, buf, len, offset);
975 ret = io_submit(io_ctx, 1, iocbs);
977 fprintf(stderr, "errcode=%d\n", ret);
978 fprintf(stderr, "aio_rw: io_submit failed: %s\n",
983 ret = io_getevents(io_ctx, 1, 1, &event, &ts);
986 fprintf(stderr, "aio_rw: no events available\n");
988 fprintf(stderr, "errcode=%d\n", -ret);
989 fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
994 if (len != event.res) {
996 * The b0rked libaio defines event.res as unsigned.
997 * However the kernel strucuture has it signed,
998 * and it's used to pass negated error value.
999 * Till the library is fixed use the temp var.
1001 res = (long)event.res;
1003 fprintf(stderr, "bad io length: %lu instead of %u\n",
1006 fprintf(stderr, "errcode=%d\n", -res);
1007 fprintf(stderr, "aio_rw: async io failed: %s\n",
1018 * The caller expects error return in traditional libc
1019 * convention, i.e. -1 and the errno set to error.
1025 int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
1030 ret = __aio_rw(rw, fd, buf, len, offset);
1033 ret = read(fd, buf, len);
1035 ret = write(fd, buf, len);
1043 main(int argc, char **argv)
1047 char goodfile[1024];
1053 page_size = getpagesize();
1054 page_mask = page_size - 1;
1055 mmap_mask = page_mask;
1058 setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
1060 while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:LN:OP:RS:WZ"))
1064 simulatedopcount = getnum(optarg, &endp);
1066 fprintf(stdout, "Will begin at operation %ld\n",
1068 if (simulatedopcount == 0)
1070 simulatedopcount -= 1;
1073 closeprob = getnum(optarg, &endp);
1076 "Chance of close/open is 1 in %d\n",
1088 maxfilelen = getnum(optarg, &endp);
1089 if (maxfilelen <= 0)
1093 monitorstart = getnum(optarg, &endp);
1094 if (monitorstart < 0)
1096 if (!endp || *endp++ != ':')
1098 monitorend = getnum(endp, &endp);
1101 if (monitorend == 0)
1102 monitorend = -1; /* aka infinity */
1108 maxoplen = getnum(optarg, &endp);
1113 progressinterval = getnum(optarg, &endp);
1114 if (progressinterval == 0)
1121 readbdy = getnum(optarg, &endp);
1126 style = getnum(optarg, &endp);
1127 if (style < 0 || style > 1)
1131 truncbdy = getnum(optarg, &endp);
1136 writebdy = getnum(optarg, &endp);
1150 debugstart = getnum(optarg, &endp);
1158 numops = getnum(optarg, &endp);
1166 strncpy(goodfile, optarg, sizeof(goodfile));
1167 strcat(goodfile, "/");
1168 strncpy(logfile, optarg, sizeof(logfile));
1169 strcat(logfile, "/");
1175 seed = getnum(optarg, &endp);
1177 seed = time(0) % 10000;
1179 fprintf(stdout, "Seed set to %d\n", seed);
1186 fprintf(stdout, "mapped writes DISABLED\n");
1189 o_direct = O_DIRECT;
1201 signal(SIGHUP, cleanup);
1202 signal(SIGINT, cleanup);
1203 signal(SIGPIPE, cleanup);
1204 signal(SIGALRM, cleanup);
1205 signal(SIGTERM, cleanup);
1206 signal(SIGXCPU, cleanup);
1207 signal(SIGXFSZ, cleanup);
1208 signal(SIGVTALRM, cleanup);
1209 signal(SIGUSR1, cleanup);
1210 signal(SIGUSR2, cleanup);
1212 initstate(seed, state, 256);
1215 O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666);
1222 xfs_flock64_t resv = { 0 };
1223 #ifdef HAVE_XFS_PLATFORM_DEFS_H
1224 if (!platform_test_xfs_fd(fd)) {
1226 fprintf(stderr, "main: cannot prealloc, non XFS\n");
1230 resv.l_len = maxfilelen;
1231 if ((xfsctl(fname, fd, XFS_IOC_RESVSP, &resv)) < 0) {
1237 strncat(goodfile, fname, 256);
1238 strcat (goodfile, ".fsxgood");
1239 fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
1240 if (fsxgoodfd < 0) {
1244 strncat(logfile, fname, 256);
1245 strcat (logfile, ".fsxlog");
1246 fsxlogf = fopen(logfile, "w");
1247 if (fsxlogf == NULL) {
1259 file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
1260 if (file_size == (off_t)-1) {
1262 warn("main: lseek eof");
1265 ret = lseek(fd, (off_t)0, SEEK_SET);
1266 if (ret == (off_t)-1) {
1268 warn("main: lseek 0");
1272 original_buf = (char *) malloc(maxfilelen);
1273 for (i = 0; i < maxfilelen; i++)
1274 original_buf[i] = random() % 256;
1275 good_buf = (char *) malloc(maxfilelen + writebdy);
1276 good_buf = round_up(good_buf, writebdy, 0);
1277 bzero(good_buf, maxfilelen);
1278 temp_buf = (char *) malloc(maxoplen + readbdy);
1279 temp_buf = round_up(temp_buf, readbdy, 0);
1280 bzero(temp_buf, maxoplen);
1281 if (lite) { /* zero entire existing file */
1284 written = write(fd, good_buf, (size_t)maxfilelen);
1285 if (written != maxfilelen) {
1286 if (written == -1) {
1288 warn("main: error on write");
1290 warn("main: short write, 0x%x bytes instead "
1299 while (numops == -1 || numops--)
1306 prt("All operations completed A-OK!\n");