X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Ffsx.c;h=5217a906e8da3c9ef2750f8dd29ddf0080bf0bcc;hb=b2608aff6654f329c19414377a898f2d0201435c;hp=2f765c04273cca591181635eea6c0fbcbcf768d5;hpb=72617588ac8cb2e3e5a7b8e5ebc201cab524d938;p=fs%2Flustre-release.git diff --git a/lustre/tests/fsx.c b/lustre/tests/fsx.c index 2f765c0..5217a906 100644 --- a/lustre/tests/fsx.c +++ b/lustre/tests/fsx.c @@ -136,8 +136,7 @@ jmp_buf jmpbuf; #define OP_MAX_FULL 9 #define OP_SKIPPED 101 -/* _GNU_SOURCE defines O_DIRECT as 14th bit which is 0x4000(16384) */ -#define OP_DIRECT 16384 +#define OP_DIRECT O_DIRECT #ifndef FALLOC_FL_PUNCH_HOLE #define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */ @@ -359,15 +358,15 @@ logdump(void) break; case OP_TRUNCATE: down = lp->args[0] < lp->args[1]; - prt("TRUNCATE %s\tfrom 0x%05x to 0x%05x", - down ? "DOWN" : "UP", lp->args[1], lp->args[0]); + prt("TRUNC%s 0x%05x to 0x%05x", + down ? "_DN" : "_UP", lp->args[1], lp->args[0]); if (badoff >= lp->args[!down] && badoff < lp->args[!!down]) - prt("\t******WWWW"); + prt("\t******TTTT"); break; case OP_FALLOCATE: /* 0: offset 1: length 2: where alloced */ - prt("FALLOC \tfrom 0x%05x to 0x%05x\t(0x%05x bytes)%s", + prt("FALLOC 0x%05x thru 0x%05x\t(0x%05x bytes)%s", lp->args[0], lp->args[0] + lp->args[1], lp->args[1], falloc_type[lp->args[2]]); if (badoff >= lp->args[0] && @@ -583,9 +582,7 @@ open_test_files(char **argv, int argc) for (i = 0, tf = test_files; i < num_test_files; i++, tf++) { tf->path = argv[i]; -#ifdef O_DIRECT tf->o_direct = (random() % (o_direct + 1)) ? OP_DIRECT : 0; -#endif tf->fd = open(tf->path, O_RDWR | (lite ? 0 : O_CREAT | O_TRUNC) | tf->o_direct, 0666); @@ -679,6 +676,7 @@ output_line(struct test_file *tf, int op, unsigned int offset, [OP_READ + OP_DIRECT] = "read_OD", [OP_WRITE + OP_DIRECT] = "write_OD", [OP_FALLOCATE] = "fallocate", + [OP_PUNCH_HOLE] = "punch from", }; /* W. */ @@ -689,10 +687,11 @@ output_line(struct test_file *tf, int op, unsigned int offset, (monitorend == -1 || offset <= monitorend))))))) return; - prt("%06lu%s %lu.%06u %-10s %#08x %s %#08x\t(0x05%x bytes)\n", + prt("%06lu%s %lu.%06u %-10s %#08x %s %#08x\t(0x%x bytes)\n", testcalls, fill_tf_buf(tf), tv.tv_sec, (int)tv.tv_usec, - ops[op], offset, op == OP_TRUNCATE ? " to " : "thru", - offset + size - 1, (int)size < 0 ? -(int)size : size); + ops[op], offset, op == OP_TRUNCATE || op == OP_PUNCH_HOLE ? + " to " : "thru", offset + size - 1, + (int)size < 0 ? -(int)size : size); } void output_debug(unsigned int offset, unsigned int size, const char *what) @@ -1167,7 +1166,6 @@ void do_preallocate(unsigned int offset, unsigned int length) { off_t end_offset; - off_t new_offset; int keep_size; int fd; struct stat statbufs; @@ -1183,8 +1181,7 @@ do_preallocate(unsigned int offset, unsigned int length) keep_size = fl_keep_size && (random() % 2); - end_offset = keep_size ? 0 : offset + length; - + end_offset = offset + length; if (end_offset > biggest) { biggest = end_offset; if (!quiet && testcalls > simulatedopcount) @@ -1200,12 +1197,9 @@ do_preallocate(unsigned int offset, unsigned int length) log4(OP_FALLOCATE, offset, length, (end_offset > file_size) ? (keep_size ? 0 : 1) : 2); - if (end_offset > file_size) { + if (end_offset > file_size && !keep_size) { memset(good_buf + file_size, '\0', end_offset - file_size); file_size = end_offset; - } else { - new_offset = file_size - (offset + length); - length = length + new_offset; } if (testcalls <= simulatedopcount) @@ -1258,9 +1252,7 @@ docloseopen(void) return; tf = get_tf(); -#ifdef O_DIRECT direct = (random() % (o_direct + 1)) ? OP_DIRECT : 0; -#endif log4(OP_CLOSEOPEN + direct, file_size, (unsigned int)file_size, 0); if (fd_policy != FD_SINGLE) @@ -1478,9 +1470,7 @@ usage(void) " -S seed: for random # generator (default 1) 0 gets timestamp\n" /* OSX: -T datasize: atomic data element write size [1,2,4] (default 4)\n\ */ " -W: mapped write operations DISabled\n" -#ifdef O_DIRECT " -Z[P]: O_DIRECT file IO [1 in P chance for each open] (default off)\n" -#endif " fname: this filename is REQUIRED (no default)\n", page_size); exit(90); @@ -1526,7 +1516,8 @@ test_fallocate(int mode) int fd = get_fd(); if (!lite) { - if (fallocate(fd, mode, 0, 1) && errno == EOPNOTSUPP) { + /* Must go more than a page away so let's go 4M to be sure */ + if (fallocate(fd, mode, 0, 4096*1024) && errno == EOPNOTSUPP) { if (!quiet) warn("%s: filesystem does not support fallocate mode 0x%x, disabling!", __func__, mode); @@ -1534,8 +1525,10 @@ test_fallocate(int mode) ret = 1; } - /* Call truncate only when fallocate succeeds */ - if (ret == 1 && ftruncate(fd, 0) == -1) + /* Always call ftruncate since file size might be adjusted + * by fallocate even on error + */ + if (ftruncate(fd, 0) == -1) warn("ftruncate to 0 size failed"); } return ret; @@ -1693,12 +1686,10 @@ main(int argc, char **argv) fprintf(stdout, "mapped writes DISABLED\n"); break; case 'Z': -#ifdef O_DIRECT if (optarg) o_direct = getnum(optarg, &endp); if (!optarg || o_direct == 0) o_direct = 1; -#endif break; default: usage();