* Rewritten 8/98 by Conrad Minshall.
*
* Small changes to work under Linux -- davej.
+ *
+ * Checks for mmap last-page zero fill.
*/
#include "global.h"
#ifdef AIO
#include <libaio.h>
#endif
+#ifdef FALLOCATE
+#include <linux/falloc.h>
+#endif
#ifndef MAP_FILE
# define MAP_FILE 0
#define OP_MAPREAD 5
#define OP_MAPWRITE 6
#define OP_SKIPPED 7
+#define OP_FALLOCATE 8
#undef PAGE_SIZE
#define PAGE_SIZE getpagesize()
int randomoplen = 1; /* -O flag disables it */
int seed = 1; /* -S flag */
int mapped_writes = 1; /* -W flag disables */
+int fallocate_calls = 1; /* -F flag disables */
int mapped_reads = 1; /* -R flag disables it */
int fsxgoodfd = 0;
int o_direct; /* -Z */
{
int i, count, down;
struct log_entry *lp;
+ char *falloc_type[3] = {"PAST_EOF", "EXTENDING", "INTERIOR"};
prt("LOG DUMP (%d total operations):\n", logcount);
if (logcount < LOGSIZE) {
badoff < lp->args[!!down])
prt("\t******WWWW");
break;
+ case OP_FALLOCATE:
+ /* 0: offset 1: length 2: where alloced */
+ prt("FALLOCATE %s\tfrom 0x%x to 0x%x",
+ falloc_type[lp->args[2]], lp->args[0], lp->args[0] + lp->args[1]);
+ if (badoff >= lp->args[0] &&
+ badoff < lp->args[0] + lp->args[1])
+ prt("\t******FFFF");
+ break;
case OP_SKIPPED:
prt("SKIPPED (no operation)");
break;
exit(67);
}
if (lite) {
- off_t size_by_seek = lseek(fd, (off_t)0, L_XTND);
+ off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
if (size_by_seek == (off_t)-1)
prterr("save_buffer: lseek eof");
else if (bufferlength > size_by_seek) {
- warn("save_buffer: .fsxgood file too short... will save 0x%qx bytes instead of 0x%qx\n", (unsigned long long)size_by_seek,
+ warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
(unsigned long long)bufferlength);
bufferlength = size_by_seek;
}
if (byteswritten == -1)
prterr("save_buffer write");
else
- warn("save_buffer: short write, 0x%x bytes instead of 0x%qx\n",
+ warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
(unsigned)byteswritten,
(unsigned long long)bufferlength);
}
unsigned op = 0;
unsigned bad = 0;
- if (bcmp(good_buf + offset, temp_buf, size) != 0) {
+ if (memcmp(good_buf + offset, temp_buf, size) != 0) {
prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
offset, size, fname);
prt("OFFSET\tGOOD\tBAD\tRANGE\n");
prterr("check_size: fstat");
statbuf.st_size = -1;
}
- size_by_seek = lseek(fd, (off_t)0, L_XTND);
+ size_by_seek = lseek(fd, (off_t)0, SEEK_END);
if (file_size != statbuf.st_size || file_size != size_by_seek) {
- prt("Size error: expected 0x%qx stat 0x%qx seek 0x%qx\n",
+ prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
(unsigned long long)file_size,
(unsigned long long)statbuf.st_size,
(unsigned long long)size_by_seek);
}
+void
+check_eofpage(char *s, unsigned offset, char *p, int size)
+{
+ unsigned long last_page, should_be_zero;
+
+ if (offset + size <= (file_size & ~page_mask))
+ return;
+ /*
+ * we landed in the last page of the file
+ * test to make sure the VM system provided 0's
+ * beyond the true end of the file mapping
+ * (as required by mmap def in 1996 posix 1003.1)
+ */
+ last_page = ((unsigned long)p + (offset & page_mask) + size) & ~page_mask;
+
+ for (should_be_zero = last_page + (file_size & page_mask);
+ should_be_zero < last_page + page_size;
+ should_be_zero++)
+ if (*(char *)should_be_zero) {
+ prt("Mapped %s: non-zero data past EOF (0x%llx) page offset 0x%x is 0x%04x\n",
+ s, file_size - 1, should_be_zero & page_mask,
+ short_at(should_be_zero));
+ report_failure(205);
+ }
+}
+
+
void
domapread(unsigned offset, unsigned size)
{
report_failure(190);
}
memcpy(temp_buf, p + pg_offset, size);
+
+ check_eofpage("Read", offset, p, size);
+
if (munmap(p, map_size) != 0) {
prterr("domapread: munmap");
report_failure(191);
gendata(original_buf, good_buf, offset, size);
if (file_size < offset + size) {
if (file_size < offset)
- bzero(good_buf + file_size, offset - file_size);
+ memset(good_buf + file_size, '\0', offset - file_size);
file_size = offset + size;
if (lite) {
warn("Lite file size bug in fsx!");
gendata(original_buf, good_buf, offset, size);
if (file_size < offset + size) {
if (file_size < offset)
- bzero(good_buf + file_size, offset - file_size);
+ memset(good_buf + file_size, '\0', offset - file_size);
file_size = offset + size;
if (lite) {
warn("Lite file size bug in fsx!");
prterr("domapwrite: msync");
report_failure(203);
}
+
+ check_eofpage("Write", offset, p, size);
+
if (munmap(p, map_size) != 0) {
prterr("domapwrite: munmap");
report_failure(204);
log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
if (size > file_size)
- bzero(good_buf + file_size, size - file_size);
+ memset(good_buf + file_size, '\0', size - file_size);
file_size = size;
if (testcalls <= simulatedopcount)
}
}
+#ifdef FALLOCATE
+/* fallocate is basically a no-op unless extending, then a lot like a truncate */
+void
+dofallocate(unsigned offset, unsigned length)
+{
+ unsigned end_offset;
+ int keep_size;
+
+ if (length == 0) {
+ if (!quiet && testcalls > simulatedopcount)
+ prt("skipping zero length fallocate\n");
+ log4(OP_SKIPPED, OP_FALLOCATE, offset, length);
+ return;
+ }
+
+ keep_size = random() % 2;
+
+ end_offset = keep_size ? 0 : offset + length;
+
+ if (end_offset > biggest) {
+ biggest = end_offset;
+ if (!quiet && testcalls > simulatedopcount)
+ prt("fallocating to largest ever: 0x%x\n", end_offset);
+ }
+
+ /*
+ * last arg:
+ * 1: allocate past EOF
+ * 2: extending prealloc
+ * 3: interior prealloc
+ */
+ log4(OP_FALLOCATE, offset, length, (end_offset > file_size) ? (keep_size ? 1 : 2) : 3);
+
+ if (end_offset > file_size) {
+ memset(good_buf + file_size, '\0', end_offset - file_size);
+ file_size = end_offset;
+ }
+
+ if (testcalls <= simulatedopcount)
+ return;
+
+ if ((progressinterval && testcalls % progressinterval == 0) ||
+ (debug && (monitorstart == -1 || monitorend == -1 ||
+ end_offset <= monitorend)))
+ prt("%lu falloc\tfrom 0x%x to 0x%x\n", testcalls, offset, length);
+ if (fallocate(fd, keep_size ? FALLOC_FL_KEEP_SIZE : 0, (loff_t)offset, (loff_t)length) == -1) {
+ prt("fallocate: %x to %x\n", offset, length);
+ prterr("dofallocate: fallocate");
+ report_failure(161);
+ }
+}
+#else
+void
+dofallocate(unsigned offset, unsigned length)
+{
+ return;
+}
+#endif
void
writefileimage()
if (iret == -1)
prterr("writefileimage: write");
else
- prt("short write: 0x%x bytes instead of 0x%qx\n",
+ prt("short write: 0x%x bytes instead of 0x%llx\n",
iret, (unsigned long long)file_size);
report_failure(172);
}
if (lite ? 0 : ftruncate(fd, file_size) == -1) {
- prt("ftruncate2: %qx\n", (unsigned long long)file_size);
+ prt("ftruncate2: %llx\n", (unsigned long long)file_size);
prterr("writefileimage: ftruncate");
report_failure(173);
}
unsigned long offset;
unsigned long size = maxoplen;
unsigned long rv = random();
- unsigned long op = rv % (3 + !lite + mapped_writes);
+ unsigned long op = rv % (3 + !lite + mapped_writes + fallocate_calls);
/* turn off the map read if necessary */
prt("%lu...\n", testcalls);
/*
- * READ: op = 0
- * WRITE: op = 1
- * MAPREAD: op = 2
- * TRUNCATE: op = 3
- * MAPWRITE: op = 3 or 4
+ * lite !lite
+ * READ: op = 0 0
+ * WRITE: op = 1 1
+ * MAPREAD: op = 2 2
+ * TRUNCATE: op = - 3
+ * MAPWRITE: op = 3 4
+ * FALLOCATE: op = - 5
*/
if (lite ? 0 : op == 3 && (style & 1) == 0) /* vanilla truncate? */
dotruncate(random() % maxfilelen);
else {
if (randomoplen)
size = random() % (maxoplen+1);
- if (lite ? 0 : op == 3)
+
+ if (lite ? 0 : op == 3) {
+ /* truncate */
dotruncate(size);
- else {
+ } else {
offset = random();
- if (op == 1 || op == (lite ? 3 : 4)) {
+ if (op == 5) {
+ /* fallocate */
+ offset %= maxfilelen;
+ if (offset + size > maxfilelen)
+ size = maxfilelen - offset;
+ dofallocate(offset, size);
+ } else if (op == 1 || op == (lite ? 3 : 4)) {
+ /* write / mapwrite */
offset %= maxfilelen;
if (offset + size > maxfilelen)
size = maxfilelen - offset;
else
dowrite(offset, size);
} else {
+ /* read / mapread */
if (file_size)
offset %= file_size;
else
usage(void)
{
fprintf(stdout, "usage: %s",
- "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\
+ "fsx [-dnqxAFLOWZ] [-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\
-b opnum: beginning operation number (default 1)\n\
-c P: 1 in P chance of file close+open at each op (default infinity)\n\
-d: debug output for all operations\n\
#ifdef AIO
" -A: Use the AIO system calls\n"
#endif
-" -D startingop: debug output starting at specified operation\n\
- -L: fsxLite - no file creations & no file size changes\n\
+" -D startingop: debug output starting at specified operation\n"
+#ifdef FALLOCATE
+" -F: Do not use fallocate (preallocation) calls\n"
+#endif
+" -L: fsxLite - no file creations & no file size changes\n\
-N numops: total # operations to do (default infinity)\n\
-O: use oplen (see -o flag) for every op (default random)\n\
-P: save .fsxlog and .fsxgood files in dirpath (default ./)\n\
fprintf(stderr, "bad io length: %lu instead of %u\n",
res, len);
else {
- fprintf(stderr, "errcode=%d\n", -res);
+ fprintf(stderr, "errcode=%ld\n", -res);
fprintf(stderr, "aio_rw: async io failed: %s\n",
strerror(-res));
ret = res;
setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
- while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:LN:OP:RS:WZ"))
+ while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:FLN:OP:RS:WZ"))
!= EOF)
switch (ch) {
case 'b':
if (debugstart < 1)
usage();
break;
+ case 'F':
+ fallocate_calls = 0;
+ break;
case 'L':
lite = 1;
break;
if (lite) {
off_t ret;
- file_size = maxfilelen = lseek(fd, (off_t)0, L_XTND);
+ file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
if (file_size == (off_t)-1) {
prterr(fname);
warn("main: lseek eof");
original_buf[i] = random() % 256;
good_buf = (char *) malloc(maxfilelen + writebdy);
good_buf = round_up(good_buf, writebdy, 0);
- bzero(good_buf, maxfilelen);
+ memset(good_buf, '\0', maxfilelen);
temp_buf = (char *) malloc(maxoplen + readbdy);
temp_buf = round_up(temp_buf, readbdy, 0);
- bzero(temp_buf, maxoplen);
+ memset(temp_buf, '\0', maxoplen);
if (lite) { /* zero entire existing file */
ssize_t written;
} else
check_trunc_hack();
+#ifdef FALLOCATE
+ if (!lite && fallocate_calls) {
+ if (fallocate(fd, 0, 0, 1) && errno == EOPNOTSUPP) {
+ warn("main: filesystem does not support fallocate, disabling");
+ fallocate_calls = 0;
+ } else
+ ftruncate(fd, 0);
+ }
+#else /* ! FALLOCATE */
+ fallocate_calls = 0;
+#endif
+
while (numops == -1 || numops--)
test();