* Rewritten 8/98 by Conrad Minshall.
*
* Small changes to work under Linux -- davej.
+ *
+ * Checks for mmap last-page zero fill.
*/
#include "global.h"
int closeprob = 0; /* -c flag */
int debug = 0; /* -d flag */
unsigned long debugstart = 0; /* -D flag */
-int do_fsync = 0; /* -f flag */
+int flush = 0; /* -f flag */
+int do_fsync = 0; /* -y flag */
unsigned long maxfilelen = 256 * 1024; /* -l flag */
int sizechecks = 1; /* -n flag disables them */
int maxoplen = 64 * 1024; /* -o flag */
int o_direct; /* -Z */
int aio = 0;
+int page_size;
+int page_mask;
+int mmap_mask;
#ifdef AIO
int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
#define READ 0
va_end(ap);
}
+#define BUF_SIZE 1024
+
void
prt(char *fmt, ...)
{
va_list args;
+ char buffer[BUF_SIZE];
va_start(args, fmt);
- vfprintf(stdout, fmt, args);
- if (fsxlogf)
- vfprintf(fsxlogf, fmt, args);
+ vsnprintf(buffer, BUF_SIZE, fmt, args);
va_end(args);
+ fprintf(stdout, buffer);
+ if (fsxlogf)
+ fprintf(fsxlogf, buffer);
}
void
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);
ftruncate(fd, 0);
}
+void
+doflush(unsigned offset, unsigned size)
+{
+ unsigned pg_offset;
+ unsigned map_size;
+ char *p;
+
+ if (o_direct == O_DIRECT)
+ return;
+
+ pg_offset = offset & mmap_mask;
+ map_size = pg_offset + size;
+
+ if ((p = (char *)mmap(0, map_size, PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_SHARED, fd,
+ (off_t)(offset - pg_offset))) == (char *)-1) {
+ prterr("doflush: mmap");
+ report_failure(202);
+ }
+ if (msync(p, map_size, MS_INVALIDATE) != 0) {
+ prterr("doflush: msync");
+ report_failure(203);
+ }
+ if (munmap(p, map_size) != 0) {
+ prterr("doflush: munmap");
+ report_failure(204);
+ }
+}
void
doread(unsigned offset, unsigned size)
}
+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!");
report_failure(152);
}
}
+ if (flush) {
+ doflush(offset, size);
+ }
}
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)
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);
}
-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\
+ -f flush and invalidate cache after I/O\n\
-l flen: the upper bound on file size (default 262144)\n\
-m startop:endop: monitor (print debug output) specified byte range (default 0:infinity)\n\
-n: no verifications of file size\n\
-t truncbdy: 4096 would make truncates page aligned (default 1)\n\
-w writebdy: 4096 would make writes page aligned (default 1)\n\
-x: preallocate file space before starting, XFS only (default 0)\n\
- -A: Use the AIO system calls\n\
- -D startingop: debug output starting at specified operation\n\
+ -y synchronize changes to a file\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\
-N numops: total # operations to do (default infinity)\n\
-O: use oplen (see -o flag) for every op (default random)\n\
int
getnum(char *s, char **e)
{
- int ret = -1;
+ int ret;
*e = (char *) 0;
ret = strtol(s, e, 0);
static struct timespec ts;
struct iocb *iocbs[] = { &iocb };
int ret;
+ long res;
if (rw == READ) {
io_prep_pread(&iocb, fd, buf, len, offset);
fprintf(stderr, "errcode=%d\n", ret);
fprintf(stderr, "aio_rw: io_submit failed: %s\n",
strerror(ret));
- return(-1);
+ goto out_error;
}
ret = io_getevents(io_ctx, 1, 1, &event, &ts);
if (ret != 1) {
- fprintf(stderr, "errcode=%d\n", ret);
- fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
- strerror(ret));
- return -1;
+ if (ret == 0)
+ fprintf(stderr, "aio_rw: no events available\n");
+ else {
+ fprintf(stderr, "errcode=%d\n", -ret);
+ fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
+ strerror(-ret));
+ }
+ goto out_error;
}
if (len != event.res) {
- fprintf(stderr, "bad read length: %lu instead of %u\n",
- event.res, len);
+ /*
+ * The b0rked libaio defines event.res as unsigned.
+ * However the kernel strucuture has it signed,
+ * and it's used to pass negated error value.
+ * Till the library is fixed use the temp var.
+ */
+ res = (long)event.res;
+ if (res >= 0)
+ fprintf(stderr, "bad io length: %lu instead of %u\n",
+ res, len);
+ else {
+ fprintf(stderr, "errcode=%ld\n", -res);
+ fprintf(stderr, "aio_rw: async io failed: %s\n",
+ strerror(-res));
+ ret = res;
+ goto out_error;
+ }
+
}
return event.res;
+
+out_error:
+ /*
+ * The caller expects error return in traditional libc
+ * convention, i.e. -1 and the errno set to error.
+ */
+ errno = -ret;
+ return -1;
}
int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
goodfile[0] = 0;
logfile[0] = 0;
+ page_size = getpagesize();
+ page_mask = page_size - 1;
+ mmap_mask = page_mask;
+
+
setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
- while ((ch = getopt(argc, argv, "b:c:dl:m:no:p:qr:s:t:w:xAD:LN:OP:RS:WZ"))
+ while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:LN:OP:RS:WZ"))
!= EOF)
switch (ch) {
case 'b':
debug = 1;
break;
case 'f':
- do_fsync = 1;
+ flush = 1;
break;
case 'l':
maxfilelen = getnum(optarg, &endp);
break;
case 'p':
progressinterval = getnum(optarg, &endp);
- if (progressinterval < 0)
+ if (progressinterval == 0)
usage();
break;
case 'q':
case 'x':
prealloc = 1;
break;
+ case 'y':
+ do_fsync = 1;
+ break;
case 'A':
aio = 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;