2003-07-07 06:36:46 +00:00
|
|
|
/*
|
2004-03-18 23:46:57 +00:00
|
|
|
* Copyright (C) 1991, NeXT Computer, Inc. All Rights Reserverd.
|
2003-07-07 06:36:46 +00:00
|
|
|
*
|
|
|
|
|
* File: fsx.c
|
|
|
|
|
* Author: Avadis Tevanian, Jr.
|
|
|
|
|
*
|
|
|
|
|
* File system exerciser.
|
|
|
|
|
*
|
|
|
|
|
* Rewritten 8/98 by Conrad Minshall.
|
|
|
|
|
*
|
|
|
|
|
* Small changes to work under Linux -- davej.
|
2009-05-13 15:52:42 -05:00
|
|
|
*
|
|
|
|
|
* Checks for mmap last-page zero fill.
|
2003-07-07 06:36:46 +00:00
|
|
|
*/
|
|
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <strings.h>
|
|
|
|
|
#include <sys/file.h>
|
|
|
|
|
#include <sys/mman.h>
|
2004-06-15 07:32:36 +00:00
|
|
|
#ifdef HAVE_ERR_H
|
2003-07-07 06:36:46 +00:00
|
|
|
#include <err.h>
|
2004-06-15 07:32:36 +00:00
|
|
|
#endif
|
2003-07-07 06:36:46 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdio.h>
|
2011-07-14 15:40:47 +10:00
|
|
|
#include <stddef.h>
|
2003-07-07 06:36:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <errno.h>
|
2004-03-18 23:46:57 +00:00
|
|
|
#ifdef AIO
|
|
|
|
|
#include <libaio.h>
|
|
|
|
|
#endif
|
2003-08-01 05:48:02 +00:00
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
#ifndef MAP_FILE
|
|
|
|
|
# define MAP_FILE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define NUMPRINTCOLUMNS 32 /* # columns of data to print on each line */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A log entry is an operation and a bunch of arguments.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct log_entry {
|
|
|
|
|
int operation;
|
|
|
|
|
int args[3];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define LOGSIZE 1000
|
|
|
|
|
|
|
|
|
|
struct log_entry oplog[LOGSIZE]; /* the log */
|
|
|
|
|
int logptr = 0; /* current position in log */
|
|
|
|
|
int logcount = 0; /* total ops */
|
|
|
|
|
|
|
|
|
|
/*
|
2011-07-14 15:27:01 +10:00
|
|
|
* The operation matrix is complex due to conditional execution of different
|
|
|
|
|
* features. Hence when we come to deciding what operation to run, we need to
|
|
|
|
|
* be careful in how we select the different operations. The active operations
|
|
|
|
|
* are mapped to numbers as follows:
|
|
|
|
|
*
|
|
|
|
|
* lite !lite
|
|
|
|
|
* READ: 0 0
|
|
|
|
|
* WRITE: 1 1
|
|
|
|
|
* MAPREAD: 2 2
|
|
|
|
|
* MAPWRITE: 3 3
|
|
|
|
|
* TRUNCATE: - 4
|
|
|
|
|
* FALLOCATE: - 5
|
|
|
|
|
* PUNCH HOLE: - 6
|
2014-03-13 15:19:58 +11:00
|
|
|
* ZERO RANGE: - 7
|
2011-07-14 15:27:01 +10:00
|
|
|
*
|
|
|
|
|
* When mapped read/writes are disabled, they are simply converted to normal
|
|
|
|
|
* reads and writes. When fallocate/fpunch calls are disabled, they are
|
|
|
|
|
* converted to OP_SKIPPED. Hence OP_SKIPPED needs to have a number higher than
|
|
|
|
|
* the operation selction matrix, as does the OP_CLOSEOPEN which is an
|
|
|
|
|
* operation modifier rather than an operation in itself.
|
|
|
|
|
*
|
|
|
|
|
* Because of the "lite" version, we also need to have different "maximum
|
|
|
|
|
* operation" defines to allow the ops to be selected correctly based on the
|
|
|
|
|
* mode being run.
|
2003-07-07 06:36:46 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-07-14 15:27:01 +10:00
|
|
|
/* common operations */
|
|
|
|
|
#define OP_READ 0
|
|
|
|
|
#define OP_WRITE 1
|
|
|
|
|
#define OP_MAPREAD 2
|
|
|
|
|
#define OP_MAPWRITE 3
|
|
|
|
|
#define OP_MAX_LITE 4
|
|
|
|
|
|
|
|
|
|
/* !lite operations */
|
2014-04-04 17:22:29 +11:00
|
|
|
#define OP_TRUNCATE 4
|
|
|
|
|
#define OP_FALLOCATE 5
|
|
|
|
|
#define OP_PUNCH_HOLE 6
|
|
|
|
|
#define OP_ZERO_RANGE 7
|
|
|
|
|
#define OP_COLLAPSE_RANGE 8
|
|
|
|
|
#define OP_MAX_FULL 9
|
2011-07-14 15:27:01 +10:00
|
|
|
|
|
|
|
|
/* operation modifiers */
|
|
|
|
|
#define OP_CLOSEOPEN 100
|
|
|
|
|
#define OP_SKIPPED 101
|
2003-07-07 06:36:46 +00:00
|
|
|
|
2004-03-18 23:46:57 +00:00
|
|
|
#undef PAGE_SIZE
|
2003-07-07 06:36:46 +00:00
|
|
|
#define PAGE_SIZE getpagesize()
|
2004-03-18 23:46:57 +00:00
|
|
|
#undef PAGE_MASK
|
2003-07-07 06:36:46 +00:00
|
|
|
#define PAGE_MASK (PAGE_SIZE - 1)
|
|
|
|
|
|
|
|
|
|
char *original_buf; /* a pointer to the original data */
|
|
|
|
|
char *good_buf; /* a pointer to the correct data */
|
|
|
|
|
char *temp_buf; /* a pointer to the current data */
|
|
|
|
|
char *fname; /* name of our test file */
|
|
|
|
|
int fd; /* fd for our test file */
|
|
|
|
|
|
2014-04-04 17:22:29 +11:00
|
|
|
blksize_t block_size = 0;
|
2003-07-07 06:36:46 +00:00
|
|
|
off_t file_size = 0;
|
|
|
|
|
off_t biggest = 0;
|
|
|
|
|
char state[256];
|
|
|
|
|
unsigned long testcalls = 0; /* calls to function "test" */
|
|
|
|
|
|
|
|
|
|
unsigned long simulatedopcount = 0; /* -b flag */
|
|
|
|
|
int closeprob = 0; /* -c flag */
|
|
|
|
|
int debug = 0; /* -d flag */
|
|
|
|
|
unsigned long debugstart = 0; /* -D flag */
|
2006-08-04 13:44:58 +00:00
|
|
|
int flush = 0; /* -f flag */
|
|
|
|
|
int do_fsync = 0; /* -y flag */
|
2003-07-07 06:36:46 +00:00
|
|
|
unsigned long maxfilelen = 256 * 1024; /* -l flag */
|
|
|
|
|
int sizechecks = 1; /* -n flag disables them */
|
|
|
|
|
int maxoplen = 64 * 1024; /* -o flag */
|
|
|
|
|
int quiet = 0; /* -q flag */
|
|
|
|
|
unsigned long progressinterval = 0; /* -p flag */
|
|
|
|
|
int readbdy = 1; /* -r flag */
|
|
|
|
|
int style = 0; /* -s flag */
|
2004-03-18 23:46:57 +00:00
|
|
|
int prealloc = 0; /* -x flag */
|
2003-07-07 06:36:46 +00:00
|
|
|
int truncbdy = 1; /* -t flag */
|
|
|
|
|
int writebdy = 1; /* -w flag */
|
|
|
|
|
long monitorstart = -1; /* -m flag */
|
|
|
|
|
long monitorend = -1; /* -m flag */
|
|
|
|
|
int lite = 0; /* -L flag */
|
|
|
|
|
long numops = -1; /* -N flag */
|
|
|
|
|
int randomoplen = 1; /* -O flag disables it */
|
|
|
|
|
int seed = 1; /* -S flag */
|
|
|
|
|
int mapped_writes = 1; /* -W flag disables */
|
2011-03-09 10:35:19 -06:00
|
|
|
int fallocate_calls = 1; /* -F flag disables */
|
2011-06-06 16:33:37 -07:00
|
|
|
int punch_hole_calls = 1; /* -H flag disables */
|
2014-03-13 15:19:58 +11:00
|
|
|
int zero_range_calls = 1; /* -z flag disables */
|
2014-04-04 17:22:29 +11:00
|
|
|
int collapse_range_calls = 1; /* -C flag disables */
|
2003-07-07 06:36:46 +00:00
|
|
|
int mapped_reads = 1; /* -R flag disables it */
|
|
|
|
|
int fsxgoodfd = 0;
|
2004-03-18 23:46:57 +00:00
|
|
|
int o_direct; /* -Z */
|
|
|
|
|
int aio = 0;
|
2003-07-07 06:36:46 +00:00
|
|
|
|
2006-08-04 13:44:58 +00:00
|
|
|
int page_size;
|
|
|
|
|
int page_mask;
|
|
|
|
|
int mmap_mask;
|
2004-03-18 23:46:57 +00:00
|
|
|
#ifdef AIO
|
|
|
|
|
int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset);
|
|
|
|
|
#define READ 0
|
|
|
|
|
#define WRITE 1
|
|
|
|
|
#define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d)
|
|
|
|
|
#define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d)
|
|
|
|
|
#else
|
|
|
|
|
#define fsxread(a,b,c,d) read(a,b,c)
|
|
|
|
|
#define fsxwrite(a,b,c,d) write(a,b,c)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
FILE * fsxlogf = NULL;
|
|
|
|
|
int badoff = -1;
|
|
|
|
|
int closeopen = 0;
|
|
|
|
|
|
2011-07-26 12:12:47 +02:00
|
|
|
static void *round_ptr_up(void *ptr, unsigned long align, unsigned long offset)
|
2004-03-18 23:46:57 +00:00
|
|
|
{
|
|
|
|
|
unsigned long ret = (unsigned long)ptr;
|
|
|
|
|
|
|
|
|
|
ret = ((ret + align - 1) & ~(align - 1));
|
|
|
|
|
ret += offset;
|
|
|
|
|
return (void *)ret;
|
|
|
|
|
}
|
2003-07-07 06:36:46 +00:00
|
|
|
|
2004-06-15 07:32:36 +00:00
|
|
|
void
|
|
|
|
|
vwarnc(int code, const char *fmt, va_list ap) {
|
|
|
|
|
fprintf(stderr, "fsx: ");
|
|
|
|
|
if (fmt != NULL) {
|
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
|
fprintf(stderr, ": ");
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "%s\n", strerror(code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
warn(const char * fmt, ...) {
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
vwarnc(errno, fmt, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-08 03:02:20 +00:00
|
|
|
#define BUF_SIZE 1024
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
void
|
|
|
|
|
prt(char *fmt, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
2007-03-08 03:02:20 +00:00
|
|
|
char buffer[BUF_SIZE];
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2007-03-08 03:02:20 +00:00
|
|
|
vsnprintf(buffer, BUF_SIZE, fmt, args);
|
2003-07-07 06:36:46 +00:00
|
|
|
va_end(args);
|
2007-03-08 03:02:20 +00:00
|
|
|
fprintf(stdout, buffer);
|
|
|
|
|
if (fsxlogf)
|
|
|
|
|
fprintf(fsxlogf, buffer);
|
2003-07-07 06:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
prterr(char *prefix)
|
|
|
|
|
{
|
|
|
|
|
prt("%s%s%s\n", prefix, prefix ? ": " : "", strerror(errno));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
log4(int operation, int arg0, int arg1, int arg2)
|
|
|
|
|
{
|
|
|
|
|
struct log_entry *le;
|
|
|
|
|
|
|
|
|
|
le = &oplog[logptr];
|
|
|
|
|
le->operation = operation;
|
|
|
|
|
if (closeopen)
|
|
|
|
|
le->operation = ~ le->operation;
|
|
|
|
|
le->args[0] = arg0;
|
|
|
|
|
le->args[1] = arg1;
|
|
|
|
|
le->args[2] = arg2;
|
|
|
|
|
logptr++;
|
|
|
|
|
logcount++;
|
|
|
|
|
if (logptr >= LOGSIZE)
|
|
|
|
|
logptr = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
logdump(void)
|
|
|
|
|
{
|
|
|
|
|
int i, count, down;
|
|
|
|
|
struct log_entry *lp;
|
2011-03-09 10:35:19 -06:00
|
|
|
char *falloc_type[3] = {"PAST_EOF", "EXTENDING", "INTERIOR"};
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
prt("LOG DUMP (%d total operations):\n", logcount);
|
|
|
|
|
if (logcount < LOGSIZE) {
|
|
|
|
|
i = 0;
|
|
|
|
|
count = logcount;
|
|
|
|
|
} else {
|
|
|
|
|
i = logptr;
|
|
|
|
|
count = LOGSIZE;
|
|
|
|
|
}
|
|
|
|
|
for ( ; count > 0; count--) {
|
|
|
|
|
int opnum;
|
|
|
|
|
|
|
|
|
|
opnum = i+1 + (logcount/LOGSIZE)*LOGSIZE;
|
2011-07-14 15:27:16 +10:00
|
|
|
prt("%d(%3d mod 256): ", opnum, opnum%256);
|
2003-07-07 06:36:46 +00:00
|
|
|
lp = &oplog[i];
|
|
|
|
|
if ((closeopen = lp->operation < 0))
|
|
|
|
|
lp->operation = ~ lp->operation;
|
|
|
|
|
|
|
|
|
|
switch (lp->operation) {
|
|
|
|
|
case OP_MAPREAD:
|
2011-07-14 15:27:16 +10:00
|
|
|
prt("MAPREAD 0x%x thru 0x%x\t(0x%x bytes)",
|
2003-07-07 06:36:46 +00:00
|
|
|
lp->args[0], lp->args[0] + lp->args[1] - 1,
|
|
|
|
|
lp->args[1]);
|
|
|
|
|
if (badoff >= lp->args[0] && badoff <
|
|
|
|
|
lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t***RRRR***");
|
|
|
|
|
break;
|
|
|
|
|
case OP_MAPWRITE:
|
|
|
|
|
prt("MAPWRITE 0x%x thru 0x%x\t(0x%x bytes)",
|
|
|
|
|
lp->args[0], lp->args[0] + lp->args[1] - 1,
|
|
|
|
|
lp->args[1]);
|
|
|
|
|
if (badoff >= lp->args[0] && badoff <
|
|
|
|
|
lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t******WWWW");
|
|
|
|
|
break;
|
|
|
|
|
case OP_READ:
|
2011-07-14 15:27:16 +10:00
|
|
|
prt("READ 0x%x thru 0x%x\t(0x%x bytes)",
|
2003-07-07 06:36:46 +00:00
|
|
|
lp->args[0], lp->args[0] + lp->args[1] - 1,
|
|
|
|
|
lp->args[1]);
|
|
|
|
|
if (badoff >= lp->args[0] &&
|
|
|
|
|
badoff < lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t***RRRR***");
|
|
|
|
|
break;
|
|
|
|
|
case OP_WRITE:
|
2011-07-14 15:27:16 +10:00
|
|
|
prt("WRITE 0x%x thru 0x%x\t(0x%x bytes)",
|
2003-07-07 06:36:46 +00:00
|
|
|
lp->args[0], lp->args[0] + lp->args[1] - 1,
|
|
|
|
|
lp->args[1]);
|
|
|
|
|
if (lp->args[0] > lp->args[2])
|
|
|
|
|
prt(" HOLE");
|
|
|
|
|
else if (lp->args[0] + lp->args[1] > lp->args[2])
|
|
|
|
|
prt(" EXTEND");
|
|
|
|
|
if ((badoff >= lp->args[0] || badoff >=lp->args[2]) &&
|
|
|
|
|
badoff < lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t***WWWW");
|
|
|
|
|
break;
|
|
|
|
|
case OP_TRUNCATE:
|
|
|
|
|
down = lp->args[0] < lp->args[1];
|
|
|
|
|
prt("TRUNCATE %s\tfrom 0x%x to 0x%x",
|
|
|
|
|
down ? "DOWN" : "UP", lp->args[1], lp->args[0]);
|
|
|
|
|
if (badoff >= lp->args[!down] &&
|
|
|
|
|
badoff < lp->args[!!down])
|
|
|
|
|
prt("\t******WWWW");
|
|
|
|
|
break;
|
2011-03-09 10:35:19 -06:00
|
|
|
case OP_FALLOCATE:
|
|
|
|
|
/* 0: offset 1: length 2: where alloced */
|
2011-07-14 15:27:16 +10:00
|
|
|
prt("FALLOC 0x%x thru 0x%x\t(0x%x bytes) %s",
|
|
|
|
|
lp->args[0], lp->args[0] + lp->args[1],
|
|
|
|
|
lp->args[1], falloc_type[lp->args[2]]);
|
2011-03-09 10:35:19 -06:00
|
|
|
if (badoff >= lp->args[0] &&
|
|
|
|
|
badoff < lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t******FFFF");
|
|
|
|
|
break;
|
2011-06-06 16:33:37 -07:00
|
|
|
case OP_PUNCH_HOLE:
|
2011-07-14 15:27:16 +10:00
|
|
|
prt("PUNCH 0x%x thru 0x%x\t(0x%x bytes)",
|
2011-06-06 16:33:37 -07:00
|
|
|
lp->args[0], lp->args[0] + lp->args[1] - 1,
|
|
|
|
|
lp->args[1]);
|
|
|
|
|
if (badoff >= lp->args[0] && badoff <
|
|
|
|
|
lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t******PPPP");
|
|
|
|
|
break;
|
2014-03-13 15:19:58 +11:00
|
|
|
case OP_ZERO_RANGE:
|
2014-04-04 17:22:29 +11:00
|
|
|
prt("ZERO 0x%x thru 0x%x\t(0x%x bytes)",
|
2014-03-13 15:19:58 +11:00
|
|
|
lp->args[0], lp->args[0] + lp->args[1] - 1,
|
|
|
|
|
lp->args[1]);
|
|
|
|
|
if (badoff >= lp->args[0] && badoff <
|
|
|
|
|
lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t******ZZZZ");
|
|
|
|
|
break;
|
2014-04-04 17:22:29 +11:00
|
|
|
case OP_COLLAPSE_RANGE:
|
|
|
|
|
prt("COLLAPSE 0x%x thru 0x%x\t(0x%x bytes)",
|
|
|
|
|
lp->args[0], lp->args[0] + lp->args[1] - 1,
|
|
|
|
|
lp->args[1]);
|
|
|
|
|
if (badoff >= lp->args[0] && badoff <
|
|
|
|
|
lp->args[0] + lp->args[1])
|
|
|
|
|
prt("\t******CCCC");
|
|
|
|
|
break;
|
2003-07-07 06:36:46 +00:00
|
|
|
case OP_SKIPPED:
|
|
|
|
|
prt("SKIPPED (no operation)");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
prt("BOGUS LOG ENTRY (operation code = %d)!",
|
|
|
|
|
lp->operation);
|
|
|
|
|
}
|
|
|
|
|
if (closeopen)
|
|
|
|
|
prt("\n\t\tCLOSE/OPEN");
|
|
|
|
|
prt("\n");
|
|
|
|
|
i++;
|
|
|
|
|
if (i == LOGSIZE)
|
|
|
|
|
i = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
save_buffer(char *buffer, off_t bufferlength, int fd)
|
|
|
|
|
{
|
|
|
|
|
off_t ret;
|
|
|
|
|
ssize_t byteswritten;
|
|
|
|
|
|
|
|
|
|
if (fd <= 0 || bufferlength == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (bufferlength > SSIZE_MAX) {
|
|
|
|
|
prt("fsx flaw: overflow in save_buffer\n");
|
|
|
|
|
exit(67);
|
|
|
|
|
}
|
|
|
|
|
if (lite) {
|
2009-05-13 13:31:47 -05:00
|
|
|
off_t size_by_seek = lseek(fd, (off_t)0, SEEK_END);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (size_by_seek == (off_t)-1)
|
|
|
|
|
prterr("save_buffer: lseek eof");
|
|
|
|
|
else if (bufferlength > size_by_seek) {
|
2009-05-13 13:31:46 -05:00
|
|
|
warn("save_buffer: .fsxgood file too short... will save 0x%llx bytes instead of 0x%llx\n", (unsigned long long)size_by_seek,
|
2003-07-07 06:36:46 +00:00
|
|
|
(unsigned long long)bufferlength);
|
|
|
|
|
bufferlength = size_by_seek;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = lseek(fd, (off_t)0, SEEK_SET);
|
|
|
|
|
if (ret == (off_t)-1)
|
|
|
|
|
prterr("save_buffer: lseek 0");
|
|
|
|
|
|
|
|
|
|
byteswritten = write(fd, buffer, (size_t)bufferlength);
|
|
|
|
|
if (byteswritten != bufferlength) {
|
|
|
|
|
if (byteswritten == -1)
|
|
|
|
|
prterr("save_buffer write");
|
|
|
|
|
else
|
2009-05-13 13:31:46 -05:00
|
|
|
warn("save_buffer: short write, 0x%x bytes instead of 0x%llx\n",
|
2003-07-07 06:36:46 +00:00
|
|
|
(unsigned)byteswritten,
|
|
|
|
|
(unsigned long long)bufferlength);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
report_failure(int status)
|
|
|
|
|
{
|
|
|
|
|
logdump();
|
|
|
|
|
|
|
|
|
|
if (fsxgoodfd) {
|
|
|
|
|
if (good_buf) {
|
|
|
|
|
save_buffer(good_buf, file_size, fsxgoodfd);
|
|
|
|
|
prt("Correct content saved for comparison\n");
|
|
|
|
|
prt("(maybe hexdump \"%s\" vs \"%s.fsxgood\")\n",
|
|
|
|
|
fname, fname);
|
|
|
|
|
}
|
|
|
|
|
close(fsxgoodfd);
|
|
|
|
|
}
|
|
|
|
|
exit(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define short_at(cp) ((unsigned short)((*((unsigned char *)(cp)) << 8) | \
|
|
|
|
|
*(((unsigned char *)(cp)) + 1)))
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
check_buffers(unsigned offset, unsigned size)
|
|
|
|
|
{
|
|
|
|
|
unsigned char c, t;
|
|
|
|
|
unsigned i = 0;
|
|
|
|
|
unsigned n = 0;
|
|
|
|
|
unsigned op = 0;
|
|
|
|
|
unsigned bad = 0;
|
|
|
|
|
|
2009-05-13 15:52:23 -05:00
|
|
|
if (memcmp(good_buf + offset, temp_buf, size) != 0) {
|
2004-03-18 23:46:57 +00:00
|
|
|
prt("READ BAD DATA: offset = 0x%x, size = 0x%x, fname = %s\n",
|
|
|
|
|
offset, size, fname);
|
2003-07-07 06:36:46 +00:00
|
|
|
prt("OFFSET\tGOOD\tBAD\tRANGE\n");
|
|
|
|
|
while (size > 0) {
|
|
|
|
|
c = good_buf[offset];
|
|
|
|
|
t = temp_buf[i];
|
|
|
|
|
if (c != t) {
|
2004-03-18 23:46:57 +00:00
|
|
|
if (n < 16) {
|
2003-07-07 06:36:46 +00:00
|
|
|
bad = short_at(&temp_buf[i]);
|
|
|
|
|
prt("0x%5x\t0x%04x\t0x%04x", offset,
|
|
|
|
|
short_at(&good_buf[offset]), bad);
|
|
|
|
|
op = temp_buf[offset & 1 ? i+1 : i];
|
2004-03-18 23:46:57 +00:00
|
|
|
prt("\t0x%5x\n", n);
|
|
|
|
|
if (op)
|
|
|
|
|
prt("operation# (mod 256) for "
|
|
|
|
|
"the bad data may be %u\n",
|
|
|
|
|
((unsigned)op & 0xff));
|
|
|
|
|
else
|
|
|
|
|
prt("operation# (mod 256) for "
|
|
|
|
|
"the bad data unknown, check"
|
|
|
|
|
" HOLE and EXTEND ops\n");
|
2003-07-07 06:36:46 +00:00
|
|
|
}
|
|
|
|
|
n++;
|
|
|
|
|
badoff = offset;
|
|
|
|
|
}
|
|
|
|
|
offset++;
|
|
|
|
|
i++;
|
|
|
|
|
size--;
|
|
|
|
|
}
|
|
|
|
|
report_failure(110);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
check_size(void)
|
|
|
|
|
{
|
|
|
|
|
struct stat statbuf;
|
|
|
|
|
off_t size_by_seek;
|
|
|
|
|
|
|
|
|
|
if (fstat(fd, &statbuf)) {
|
|
|
|
|
prterr("check_size: fstat");
|
|
|
|
|
statbuf.st_size = -1;
|
|
|
|
|
}
|
2009-05-13 13:31:47 -05:00
|
|
|
size_by_seek = lseek(fd, (off_t)0, SEEK_END);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (file_size != statbuf.st_size || file_size != size_by_seek) {
|
2009-05-13 13:31:46 -05:00
|
|
|
prt("Size error: expected 0x%llx stat 0x%llx seek 0x%llx\n",
|
2003-07-07 06:36:46 +00:00
|
|
|
(unsigned long long)file_size,
|
|
|
|
|
(unsigned long long)statbuf.st_size,
|
|
|
|
|
(unsigned long long)size_by_seek);
|
|
|
|
|
report_failure(120);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
check_trunc_hack(void)
|
|
|
|
|
{
|
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
|
|
ftruncate(fd, (off_t)0);
|
|
|
|
|
ftruncate(fd, (off_t)100000);
|
|
|
|
|
fstat(fd, &statbuf);
|
|
|
|
|
if (statbuf.st_size != (off_t)100000) {
|
|
|
|
|
prt("no extend on truncate! not posix!\n");
|
|
|
|
|
exit(130);
|
|
|
|
|
}
|
|
|
|
|
ftruncate(fd, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-04 13:44:58 +00:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
doread(unsigned offset, unsigned size)
|
|
|
|
|
{
|
|
|
|
|
off_t ret;
|
|
|
|
|
unsigned iret;
|
|
|
|
|
|
|
|
|
|
offset -= offset % readbdy;
|
2004-03-18 23:46:57 +00:00
|
|
|
if (o_direct)
|
|
|
|
|
size -= size % readbdy;
|
2003-07-07 06:36:46 +00:00
|
|
|
if (size == 0) {
|
2004-03-18 23:46:57 +00:00
|
|
|
if (!quiet && testcalls > simulatedopcount && !o_direct)
|
2003-07-07 06:36:46 +00:00
|
|
|
prt("skipping zero size read\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_READ, offset, size);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (size + offset > file_size) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping seek/read past end of file\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_READ, offset, size);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log4(OP_READ, offset, size, 0);
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
2004-03-18 23:46:57 +00:00
|
|
|
if (!quiet &&
|
|
|
|
|
((progressinterval && testcalls % progressinterval == 0) ||
|
|
|
|
|
(debug &&
|
|
|
|
|
(monitorstart == -1 ||
|
|
|
|
|
(offset + size > monitorstart &&
|
|
|
|
|
(monitorend == -1 || offset <= monitorend))))))
|
2003-07-07 06:36:46 +00:00
|
|
|
prt("%lu read\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset + size - 1, size);
|
|
|
|
|
ret = lseek(fd, (off_t)offset, SEEK_SET);
|
|
|
|
|
if (ret == (off_t)-1) {
|
|
|
|
|
prterr("doread: lseek");
|
|
|
|
|
report_failure(140);
|
|
|
|
|
}
|
2004-03-18 23:46:57 +00:00
|
|
|
iret = fsxread(fd, temp_buf, size, offset);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (iret != size) {
|
|
|
|
|
if (iret == -1)
|
|
|
|
|
prterr("doread: read");
|
|
|
|
|
else
|
|
|
|
|
prt("short read: 0x%x bytes instead of 0x%x\n",
|
|
|
|
|
iret, size);
|
|
|
|
|
report_failure(141);
|
|
|
|
|
}
|
|
|
|
|
check_buffers(offset, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-05-13 15:52:42 -05:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
void
|
|
|
|
|
domapread(unsigned offset, unsigned size)
|
|
|
|
|
{
|
|
|
|
|
unsigned pg_offset;
|
|
|
|
|
unsigned map_size;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
offset -= offset % readbdy;
|
|
|
|
|
if (size == 0) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping zero size read\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_MAPREAD, offset, size);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (size + offset > file_size) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping seek/read past end of file\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_MAPREAD, offset, size);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log4(OP_MAPREAD, offset, size, 0);
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
2004-03-18 23:46:57 +00:00
|
|
|
if (!quiet &&
|
|
|
|
|
((progressinterval && testcalls % progressinterval == 0) ||
|
2003-07-07 06:36:46 +00:00
|
|
|
(debug &&
|
2004-03-18 23:46:57 +00:00
|
|
|
(monitorstart == -1 ||
|
|
|
|
|
(offset + size > monitorstart &&
|
|
|
|
|
(monitorend == -1 || offset <= monitorend))))))
|
2003-07-07 06:36:46 +00:00
|
|
|
prt("%lu mapread\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset + size - 1, size);
|
|
|
|
|
|
|
|
|
|
pg_offset = offset & PAGE_MASK;
|
|
|
|
|
map_size = pg_offset + size;
|
|
|
|
|
|
|
|
|
|
if ((p = (char *)mmap(0, map_size, PROT_READ, MAP_SHARED, fd,
|
|
|
|
|
(off_t)(offset - pg_offset))) == (char *)-1) {
|
|
|
|
|
prterr("domapread: mmap");
|
|
|
|
|
report_failure(190);
|
|
|
|
|
}
|
|
|
|
|
memcpy(temp_buf, p + pg_offset, size);
|
2009-05-13 15:52:42 -05:00
|
|
|
|
|
|
|
|
check_eofpage("Read", offset, p, size);
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
if (munmap(p, map_size) != 0) {
|
|
|
|
|
prterr("domapread: munmap");
|
|
|
|
|
report_failure(191);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_buffers(offset, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gendata(char *original_buf, char *good_buf, unsigned offset, unsigned size)
|
|
|
|
|
{
|
|
|
|
|
while (size--) {
|
|
|
|
|
good_buf[offset] = testcalls % 256;
|
|
|
|
|
if (offset % 2)
|
|
|
|
|
good_buf[offset] += original_buf[offset];
|
|
|
|
|
offset++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
dowrite(unsigned offset, unsigned size)
|
|
|
|
|
{
|
|
|
|
|
off_t ret;
|
|
|
|
|
unsigned iret;
|
|
|
|
|
|
|
|
|
|
offset -= offset % writebdy;
|
2004-03-18 23:46:57 +00:00
|
|
|
if (o_direct)
|
|
|
|
|
size -= size % writebdy;
|
2003-07-07 06:36:46 +00:00
|
|
|
if (size == 0) {
|
2004-03-18 23:46:57 +00:00
|
|
|
if (!quiet && testcalls > simulatedopcount && !o_direct)
|
2003-07-07 06:36:46 +00:00
|
|
|
prt("skipping zero size write\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_WRITE, offset, size);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log4(OP_WRITE, offset, size, file_size);
|
|
|
|
|
|
|
|
|
|
gendata(original_buf, good_buf, offset, size);
|
|
|
|
|
if (file_size < offset + size) {
|
|
|
|
|
if (file_size < offset)
|
2009-05-13 13:31:46 -05:00
|
|
|
memset(good_buf + file_size, '\0', offset - file_size);
|
2003-07-07 06:36:46 +00:00
|
|
|
file_size = offset + size;
|
|
|
|
|
if (lite) {
|
2004-03-18 23:46:57 +00:00
|
|
|
warn("Lite file size bug in fsx!");
|
2003-07-07 06:36:46 +00:00
|
|
|
report_failure(149);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
2004-03-18 23:46:57 +00:00
|
|
|
|
|
|
|
|
if (!quiet &&
|
|
|
|
|
((progressinterval && testcalls % progressinterval == 0) ||
|
2003-07-07 06:36:46 +00:00
|
|
|
(debug &&
|
2004-03-18 23:46:57 +00:00
|
|
|
(monitorstart == -1 ||
|
|
|
|
|
(offset + size > monitorstart &&
|
|
|
|
|
(monitorend == -1 || offset <= monitorend))))))
|
2003-07-07 06:36:46 +00:00
|
|
|
prt("%lu write\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset + size - 1, size);
|
|
|
|
|
ret = lseek(fd, (off_t)offset, SEEK_SET);
|
|
|
|
|
if (ret == (off_t)-1) {
|
|
|
|
|
prterr("dowrite: lseek");
|
|
|
|
|
report_failure(150);
|
|
|
|
|
}
|
2004-03-18 23:46:57 +00:00
|
|
|
iret = fsxwrite(fd, good_buf + offset, size, offset);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (iret != size) {
|
|
|
|
|
if (iret == -1)
|
|
|
|
|
prterr("dowrite: write");
|
|
|
|
|
else
|
|
|
|
|
prt("short write: 0x%x bytes instead of 0x%x\n",
|
|
|
|
|
iret, size);
|
|
|
|
|
report_failure(151);
|
|
|
|
|
}
|
2004-03-18 23:46:57 +00:00
|
|
|
if (do_fsync) {
|
|
|
|
|
if (fsync(fd)) {
|
|
|
|
|
prt("fsync() failed: %s\n", strerror(errno));
|
|
|
|
|
report_failure(152);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-08-04 13:44:58 +00:00
|
|
|
if (flush) {
|
|
|
|
|
doflush(offset, size);
|
|
|
|
|
}
|
2003-07-07 06:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
domapwrite(unsigned offset, unsigned size)
|
|
|
|
|
{
|
|
|
|
|
unsigned pg_offset;
|
|
|
|
|
unsigned map_size;
|
|
|
|
|
off_t cur_filesize;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
offset -= offset % writebdy;
|
|
|
|
|
if (size == 0) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping zero size write\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_MAPWRITE, offset, size);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
cur_filesize = file_size;
|
|
|
|
|
|
|
|
|
|
log4(OP_MAPWRITE, offset, size, 0);
|
|
|
|
|
|
|
|
|
|
gendata(original_buf, good_buf, offset, size);
|
|
|
|
|
if (file_size < offset + size) {
|
|
|
|
|
if (file_size < offset)
|
2009-05-13 13:31:46 -05:00
|
|
|
memset(good_buf + file_size, '\0', offset - file_size);
|
2003-07-07 06:36:46 +00:00
|
|
|
file_size = offset + size;
|
|
|
|
|
if (lite) {
|
2004-03-18 23:46:57 +00:00
|
|
|
warn("Lite file size bug in fsx!");
|
2003-07-07 06:36:46 +00:00
|
|
|
report_failure(200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
2004-03-18 23:46:57 +00:00
|
|
|
if (!quiet &&
|
|
|
|
|
((progressinterval && testcalls % progressinterval == 0) ||
|
2003-07-07 06:36:46 +00:00
|
|
|
(debug &&
|
2004-03-18 23:46:57 +00:00
|
|
|
(monitorstart == -1 ||
|
|
|
|
|
(offset + size > monitorstart &&
|
|
|
|
|
(monitorend == -1 || offset <= monitorend))))))
|
2003-07-07 06:36:46 +00:00
|
|
|
prt("%lu mapwrite\t0x%x thru\t0x%x\t(0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset + size - 1, size);
|
|
|
|
|
|
|
|
|
|
if (file_size > cur_filesize) {
|
|
|
|
|
if (ftruncate(fd, file_size) == -1) {
|
|
|
|
|
prterr("domapwrite: ftruncate");
|
|
|
|
|
exit(201);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pg_offset = offset & PAGE_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("domapwrite: mmap");
|
|
|
|
|
report_failure(202);
|
|
|
|
|
}
|
|
|
|
|
memcpy(p + pg_offset, good_buf + offset, size);
|
2012-02-07 11:16:06 -08:00
|
|
|
if (msync(p, map_size, MS_SYNC) != 0) {
|
2003-07-07 06:36:46 +00:00
|
|
|
prterr("domapwrite: msync");
|
|
|
|
|
report_failure(203);
|
|
|
|
|
}
|
2009-05-13 15:52:42 -05:00
|
|
|
|
|
|
|
|
check_eofpage("Write", offset, p, size);
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
if (munmap(p, map_size) != 0) {
|
|
|
|
|
prterr("domapwrite: munmap");
|
|
|
|
|
report_failure(204);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
dotruncate(unsigned size)
|
|
|
|
|
{
|
|
|
|
|
int oldsize = file_size;
|
|
|
|
|
|
|
|
|
|
size -= size % truncbdy;
|
|
|
|
|
if (size > biggest) {
|
|
|
|
|
biggest = size;
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("truncating to largest ever: 0x%x\n", size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log4(OP_TRUNCATE, size, (unsigned)file_size, 0);
|
|
|
|
|
|
|
|
|
|
if (size > file_size)
|
2009-05-13 13:31:46 -05:00
|
|
|
memset(good_buf + file_size, '\0', size - file_size);
|
2003-07-07 06:36:46 +00:00
|
|
|
file_size = size;
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
2004-03-18 23:46:57 +00:00
|
|
|
if ((progressinterval && testcalls % progressinterval == 0) ||
|
2003-07-07 06:36:46 +00:00
|
|
|
(debug && (monitorstart == -1 || monitorend == -1 ||
|
|
|
|
|
size <= monitorend)))
|
|
|
|
|
prt("%lu trunc\tfrom 0x%x to 0x%x\n", testcalls, oldsize, size);
|
|
|
|
|
if (ftruncate(fd, (off_t)size) == -1) {
|
|
|
|
|
prt("ftruncate1: %x\n", size);
|
|
|
|
|
prterr("dotruncate: ftruncate");
|
|
|
|
|
report_failure(160);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-06 16:33:37 -07:00
|
|
|
#ifdef FALLOC_FL_PUNCH_HOLE
|
|
|
|
|
void
|
|
|
|
|
do_punch_hole(unsigned offset, unsigned length)
|
|
|
|
|
{
|
|
|
|
|
unsigned end_offset;
|
|
|
|
|
int max_offset = 0;
|
|
|
|
|
int max_len = 0;
|
|
|
|
|
int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
|
|
|
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping zero length punch hole\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, length);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file_size <= (loff_t)offset) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping hole punch off the end of the file\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, length);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end_offset = offset + length;
|
|
|
|
|
|
|
|
|
|
log4(OP_PUNCH_HOLE, offset, length, 0);
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((progressinterval && testcalls % progressinterval == 0) ||
|
|
|
|
|
(debug && (monitorstart == -1 || monitorend == -1 ||
|
|
|
|
|
end_offset <= monitorend))) {
|
|
|
|
|
prt("%lu punch\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset+length, length);
|
|
|
|
|
}
|
|
|
|
|
if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
|
|
|
|
|
prt("%punch hole: %x to %x\n", offset, length);
|
|
|
|
|
prterr("do_punch_hole: fallocate");
|
|
|
|
|
report_failure(161);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
max_offset = offset < file_size ? offset : file_size;
|
|
|
|
|
max_len = max_offset + length <= file_size ? length :
|
|
|
|
|
file_size - max_offset;
|
|
|
|
|
memset(good_buf + max_offset, '\0', max_len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
void
|
|
|
|
|
do_punch_hole(unsigned offset, unsigned length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-03-13 15:19:58 +11:00
|
|
|
#ifdef FALLOC_FL_ZERO_RANGE
|
|
|
|
|
void
|
|
|
|
|
do_zero_range(unsigned offset, unsigned length)
|
|
|
|
|
{
|
|
|
|
|
unsigned end_offset;
|
|
|
|
|
int mode = FALLOC_FL_ZERO_RANGE;
|
|
|
|
|
int keep_size;
|
|
|
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping zero length zero range\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_ZERO_RANGE, 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("zero_range to largest ever: 0x%x\n", end_offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* last arg matches fallocate string array index in logdump:
|
|
|
|
|
* 0: allocate past EOF
|
|
|
|
|
* 1: extending prealloc
|
|
|
|
|
* 2: interior prealloc
|
|
|
|
|
*/
|
|
|
|
|
log4(OP_ZERO_RANGE, offset, length, (end_offset > file_size) ? (keep_size ? 0 : 1) : 2);
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((progressinterval && testcalls % progressinterval == 0) ||
|
|
|
|
|
(debug && (monitorstart == -1 || monitorend == -1 ||
|
|
|
|
|
end_offset <= monitorend))) {
|
|
|
|
|
prt("%lu zero\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset+length, length);
|
|
|
|
|
}
|
|
|
|
|
if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
|
|
|
|
|
prt("%pzero range: %x to %x\n", offset, length);
|
|
|
|
|
prterr("do_zero_range: fallocate");
|
|
|
|
|
report_failure(161);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(good_buf + offset, '\0', length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
void
|
|
|
|
|
do_zero_range(unsigned offset, unsigned length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-04-04 17:22:29 +11:00
|
|
|
#ifdef FALLOC_FL_COLLAPSE_RANGE
|
|
|
|
|
void
|
|
|
|
|
do_collapse_range(unsigned offset, unsigned length)
|
|
|
|
|
{
|
|
|
|
|
unsigned end_offset;
|
|
|
|
|
int mode = FALLOC_FL_COLLAPSE_RANGE;
|
|
|
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping zero length collapse range\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_COLLAPSE_RANGE, offset, length);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end_offset = offset + length;
|
|
|
|
|
if ((loff_t)end_offset >= file_size) {
|
|
|
|
|
if (!quiet && testcalls > simulatedopcount)
|
|
|
|
|
prt("skipping collapse range behind EOF\n");
|
|
|
|
|
log4(OP_SKIPPED, OP_COLLAPSE_RANGE, offset, length);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log4(OP_COLLAPSE_RANGE, offset, length, 0);
|
|
|
|
|
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if ((progressinterval && testcalls % progressinterval == 0) ||
|
|
|
|
|
(debug && (monitorstart == -1 || monitorend == -1 ||
|
|
|
|
|
end_offset <= monitorend))) {
|
|
|
|
|
prt("%lu collapse\tfrom 0x%x to 0x%x, (0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset+length, length);
|
|
|
|
|
}
|
|
|
|
|
if (fallocate(fd, mode, (loff_t)offset, (loff_t)length) == -1) {
|
|
|
|
|
prt("collapse range: %x to %x\n", offset, length);
|
|
|
|
|
prterr("do_collapse_range: fallocate");
|
|
|
|
|
report_failure(161);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memmove(good_buf + offset, good_buf + end_offset,
|
|
|
|
|
file_size - end_offset);
|
|
|
|
|
file_size -= length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
void
|
|
|
|
|
do_collapse_range(unsigned offset, unsigned length)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-03-13 15:19:52 +11:00
|
|
|
#ifdef HAVE_LINUX_FALLOC_H
|
2011-03-09 10:35:19 -06:00
|
|
|
/* fallocate is basically a no-op unless extending, then a lot like a truncate */
|
|
|
|
|
void
|
2011-06-06 16:33:37 -07:00
|
|
|
do_preallocate(unsigned offset, unsigned length)
|
2011-03-09 10:35:19 -06:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2011-07-14 15:27:16 +10:00
|
|
|
* last arg matches fallocate string array index in logdump:
|
|
|
|
|
* 0: allocate past EOF
|
|
|
|
|
* 1: extending prealloc
|
|
|
|
|
* 2: interior prealloc
|
2011-03-09 10:35:19 -06:00
|
|
|
*/
|
2011-07-14 15:27:16 +10:00
|
|
|
log4(OP_FALLOCATE, offset, length, (end_offset > file_size) ? (keep_size ? 0 : 1) : 2);
|
2011-03-09 10:35:19 -06:00
|
|
|
|
|
|
|
|
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)))
|
2011-07-14 15:27:16 +10:00
|
|
|
prt("%lu falloc\tfrom 0x%x to 0x%x (0x%x bytes)\n", testcalls,
|
|
|
|
|
offset, offset + length, length);
|
2011-03-09 10:35:19 -06:00
|
|
|
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);
|
2011-06-06 16:33:37 -07:00
|
|
|
prterr("do_preallocate: fallocate");
|
2011-03-09 10:35:19 -06:00
|
|
|
report_failure(161);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
void
|
2011-06-06 16:33:37 -07:00
|
|
|
do_preallocate(unsigned offset, unsigned length)
|
2011-03-09 10:35:19 -06:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
writefileimage()
|
|
|
|
|
{
|
|
|
|
|
ssize_t iret;
|
|
|
|
|
|
|
|
|
|
if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) {
|
|
|
|
|
prterr("writefileimage: lseek");
|
|
|
|
|
report_failure(171);
|
|
|
|
|
}
|
|
|
|
|
iret = write(fd, good_buf, file_size);
|
|
|
|
|
if ((off_t)iret != file_size) {
|
|
|
|
|
if (iret == -1)
|
|
|
|
|
prterr("writefileimage: write");
|
|
|
|
|
else
|
2009-05-13 13:31:46 -05:00
|
|
|
prt("short write: 0x%x bytes instead of 0x%llx\n",
|
2003-07-07 06:36:46 +00:00
|
|
|
iret, (unsigned long long)file_size);
|
|
|
|
|
report_failure(172);
|
|
|
|
|
}
|
|
|
|
|
if (lite ? 0 : ftruncate(fd, file_size) == -1) {
|
2009-05-13 13:31:46 -05:00
|
|
|
prt("ftruncate2: %llx\n", (unsigned long long)file_size);
|
2003-07-07 06:36:46 +00:00
|
|
|
prterr("writefileimage: ftruncate");
|
|
|
|
|
report_failure(173);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
docloseopen(void)
|
|
|
|
|
{
|
|
|
|
|
if (testcalls <= simulatedopcount)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
|
prt("%lu close/open\n", testcalls);
|
|
|
|
|
if (close(fd)) {
|
|
|
|
|
prterr("docloseopen: close");
|
|
|
|
|
report_failure(180);
|
|
|
|
|
}
|
2004-03-18 23:46:57 +00:00
|
|
|
fd = open(fname, O_RDWR|o_direct, 0);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
|
prterr("docloseopen: open");
|
|
|
|
|
report_failure(181);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 15:17:51 -05:00
|
|
|
#define TRIM_OFF_LEN(off, len, size) \
|
|
|
|
|
do { \
|
|
|
|
|
if (size) \
|
|
|
|
|
(off) %= (size); \
|
|
|
|
|
else \
|
|
|
|
|
(off) = 0; \
|
|
|
|
|
if ((off) + (len) > (size)) \
|
|
|
|
|
(len) = (size) - (off); \
|
2011-07-14 15:27:01 +10:00
|
|
|
} while (0)
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
test(void)
|
|
|
|
|
{
|
|
|
|
|
unsigned long offset;
|
|
|
|
|
unsigned long size = maxoplen;
|
|
|
|
|
unsigned long rv = random();
|
2011-07-14 15:27:01 +10:00
|
|
|
unsigned long op;
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
if (simulatedopcount > 0 && testcalls == simulatedopcount)
|
|
|
|
|
writefileimage();
|
|
|
|
|
|
|
|
|
|
testcalls++;
|
|
|
|
|
|
|
|
|
|
if (closeprob)
|
|
|
|
|
closeopen = (rv >> 3) < (1 << 28) / closeprob;
|
|
|
|
|
|
|
|
|
|
if (debugstart > 0 && testcalls >= debugstart)
|
|
|
|
|
debug = 1;
|
|
|
|
|
|
|
|
|
|
if (!quiet && testcalls < simulatedopcount && testcalls % 100000 == 0)
|
|
|
|
|
prt("%lu...\n", testcalls);
|
|
|
|
|
|
2011-07-14 15:27:01 +10:00
|
|
|
offset = random();
|
|
|
|
|
if (randomoplen)
|
|
|
|
|
size = random() % (maxoplen + 1);
|
2011-03-09 10:35:19 -06:00
|
|
|
|
2011-07-14 15:27:01 +10:00
|
|
|
/* calculate appropriate op to run */
|
|
|
|
|
if (lite)
|
|
|
|
|
op = rv % OP_MAX_LITE;
|
|
|
|
|
else
|
|
|
|
|
op = rv % OP_MAX_FULL;
|
|
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case OP_MAPREAD:
|
|
|
|
|
if (!mapped_reads)
|
|
|
|
|
op = OP_READ;
|
|
|
|
|
break;
|
|
|
|
|
case OP_MAPWRITE:
|
|
|
|
|
if (!mapped_writes)
|
|
|
|
|
op = OP_WRITE;
|
|
|
|
|
break;
|
|
|
|
|
case OP_FALLOCATE:
|
|
|
|
|
if (!fallocate_calls) {
|
|
|
|
|
log4(OP_SKIPPED, OP_FALLOCATE, offset, size);
|
|
|
|
|
goto out;
|
2003-07-07 06:36:46 +00:00
|
|
|
}
|
2011-07-14 15:27:01 +10:00
|
|
|
break;
|
|
|
|
|
case OP_PUNCH_HOLE:
|
|
|
|
|
if (!punch_hole_calls) {
|
|
|
|
|
log4(OP_SKIPPED, OP_PUNCH_HOLE, offset, size);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-03-13 15:19:58 +11:00
|
|
|
case OP_ZERO_RANGE:
|
|
|
|
|
if (!zero_range_calls) {
|
|
|
|
|
log4(OP_SKIPPED, OP_ZERO_RANGE, offset, size);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-04-04 17:22:29 +11:00
|
|
|
case OP_COLLAPSE_RANGE:
|
|
|
|
|
if (!collapse_range_calls) {
|
|
|
|
|
log4(OP_SKIPPED, OP_COLLAPSE_RANGE, offset, size);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-07-07 06:36:46 +00:00
|
|
|
}
|
2011-07-14 15:27:01 +10:00
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
|
case OP_READ:
|
2011-09-21 15:17:51 -05:00
|
|
|
TRIM_OFF_LEN(offset, size, file_size);
|
2011-07-14 15:27:01 +10:00
|
|
|
doread(offset, size);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OP_WRITE:
|
2011-09-21 15:17:51 -05:00
|
|
|
TRIM_OFF_LEN(offset, size, maxfilelen);
|
2011-07-14 15:27:01 +10:00
|
|
|
dowrite(offset, size);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OP_MAPREAD:
|
2011-09-21 15:17:51 -05:00
|
|
|
TRIM_OFF_LEN(offset, size, file_size);
|
2011-07-14 15:27:01 +10:00
|
|
|
domapread(offset, size);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OP_MAPWRITE:
|
2011-09-21 15:17:51 -05:00
|
|
|
TRIM_OFF_LEN(offset, size, maxfilelen);
|
2011-07-14 15:27:01 +10:00
|
|
|
domapwrite(offset, size);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OP_TRUNCATE:
|
|
|
|
|
if (!style)
|
|
|
|
|
size = random() % maxfilelen;
|
|
|
|
|
dotruncate(size);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OP_FALLOCATE:
|
2011-09-21 15:17:51 -05:00
|
|
|
TRIM_OFF_LEN(offset, size, maxfilelen);
|
2011-07-14 15:27:01 +10:00
|
|
|
do_preallocate(offset, size);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OP_PUNCH_HOLE:
|
2011-10-07 22:41:38 +00:00
|
|
|
TRIM_OFF_LEN(offset, size, file_size);
|
2011-07-14 15:27:01 +10:00
|
|
|
do_punch_hole(offset, size);
|
|
|
|
|
break;
|
2014-03-13 15:19:58 +11:00
|
|
|
case OP_ZERO_RANGE:
|
|
|
|
|
TRIM_OFF_LEN(offset, size, file_size);
|
|
|
|
|
do_zero_range(offset, size);
|
|
|
|
|
break;
|
2014-04-04 17:22:29 +11:00
|
|
|
case OP_COLLAPSE_RANGE:
|
|
|
|
|
TRIM_OFF_LEN(offset, size, file_size - 1);
|
|
|
|
|
offset = offset & ~(block_size - 1);
|
|
|
|
|
size = size & ~(block_size - 1);
|
|
|
|
|
if (size == 0) {
|
|
|
|
|
log4(OP_SKIPPED, OP_COLLAPSE_RANGE, offset, size);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
do_collapse_range(offset, size);
|
|
|
|
|
break;
|
2011-07-14 15:27:01 +10:00
|
|
|
default:
|
|
|
|
|
prterr("test: unknown operation");
|
|
|
|
|
report_failure(42);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
2003-07-07 06:36:46 +00:00
|
|
|
if (sizechecks && testcalls > simulatedopcount)
|
|
|
|
|
check_size();
|
|
|
|
|
if (closeopen)
|
|
|
|
|
docloseopen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
cleanup(sig)
|
|
|
|
|
int sig;
|
|
|
|
|
{
|
|
|
|
|
if (sig)
|
|
|
|
|
prt("signal %d\n", sig);
|
|
|
|
|
prt("testcalls = %lu\n", testcalls);
|
|
|
|
|
exit(sig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
usage(void)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stdout, "usage: %s",
|
2011-03-09 10:35:19 -06:00
|
|
|
"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\
|
2003-07-07 06:36:46 +00:00
|
|
|
-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\
|
2006-08-04 13:44:58 +00:00
|
|
|
-f flush and invalidate cache after I/O\n\
|
2003-07-07 06:36:46 +00:00
|
|
|
-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\
|
|
|
|
|
-o oplen: the upper bound on operation size (default 65536)\n\
|
|
|
|
|
-p progressinterval: debug output at specified operation interval\n\
|
|
|
|
|
-q: quieter operation\n\
|
|
|
|
|
-r readbdy: 4096 would make reads page aligned (default 1)\n\
|
|
|
|
|
-s style: 1 gives smaller truncates (default 0)\n\
|
|
|
|
|
-t truncbdy: 4096 would make truncates page aligned (default 1)\n\
|
|
|
|
|
-w writebdy: 4096 would make writes page aligned (default 1)\n\
|
2006-08-04 13:44:58 +00:00
|
|
|
-x: preallocate file space before starting, XFS only (default 0)\n\
|
|
|
|
|
-y synchronize changes to a file\n"
|
|
|
|
|
|
2005-02-14 13:52:05 +00:00
|
|
|
#ifdef AIO
|
2006-08-04 13:44:58 +00:00
|
|
|
" -A: Use the AIO system calls\n"
|
2005-02-14 13:52:05 +00:00
|
|
|
#endif
|
2011-03-09 10:35:19 -06:00
|
|
|
" -D startingop: debug output starting at specified operation\n"
|
2014-03-13 15:19:52 +11:00
|
|
|
#ifdef HAVE_LINUX_FALLOC_H
|
2011-03-09 10:35:19 -06:00
|
|
|
" -F: Do not use fallocate (preallocation) calls\n"
|
|
|
|
|
#endif
|
2011-06-06 16:33:37 -07:00
|
|
|
#ifdef FALLOC_FL_PUNCH_HOLE
|
2014-03-13 15:19:58 +11:00
|
|
|
" -H: Do not use punch hole calls\n"
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef FALLOC_FL_ZERO_RANGE
|
|
|
|
|
" -z: Do not use zero range calls\n"
|
2011-06-06 16:33:37 -07:00
|
|
|
#endif
|
2014-04-04 17:22:29 +11:00
|
|
|
#ifdef FALLOC_FL_COLLAPSE_RANGE
|
|
|
|
|
" -C: Do not use collapse range calls\n"
|
|
|
|
|
#endif
|
2011-03-09 10:35:19 -06:00
|
|
|
" -L: fsxLite - no file creations & no file size changes\n\
|
2003-07-07 06:36:46 +00:00
|
|
|
-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\
|
|
|
|
|
-S seed: for random # generator (default 1) 0 gets timestamp\n\
|
|
|
|
|
-W: mapped write operations DISabled\n\
|
|
|
|
|
-R: read() system calls only (mapped reads disabled)\n\
|
2004-03-18 23:46:57 +00:00
|
|
|
-Z: O_DIRECT (use -R, -W, -r and -w too)\n\
|
2003-07-07 06:36:46 +00:00
|
|
|
fname: this filename is REQUIRED (no default)\n");
|
|
|
|
|
exit(90);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
getnum(char *s, char **e)
|
|
|
|
|
{
|
2004-10-22 14:38:06 +00:00
|
|
|
int ret;
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
*e = (char *) 0;
|
|
|
|
|
ret = strtol(s, e, 0);
|
|
|
|
|
if (*e)
|
|
|
|
|
switch (**e) {
|
|
|
|
|
case 'b':
|
|
|
|
|
case 'B':
|
|
|
|
|
ret *= 512;
|
|
|
|
|
*e = *e + 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'k':
|
|
|
|
|
case 'K':
|
|
|
|
|
ret *= 1024;
|
|
|
|
|
*e = *e + 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'm':
|
|
|
|
|
case 'M':
|
|
|
|
|
ret *= 1024*1024;
|
|
|
|
|
*e = *e + 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'w':
|
|
|
|
|
case 'W':
|
|
|
|
|
ret *= 4;
|
|
|
|
|
*e = *e + 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return (ret);
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-18 23:46:57 +00:00
|
|
|
#ifdef AIO
|
|
|
|
|
|
|
|
|
|
#define QSZ 1024
|
|
|
|
|
io_context_t io_ctx;
|
|
|
|
|
struct iocb iocb;
|
|
|
|
|
|
|
|
|
|
int aio_setup()
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
ret = io_queue_init(QSZ, &io_ctx);
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
fprintf(stderr, "aio_setup: io_queue_init failed: %s\n",
|
|
|
|
|
strerror(ret));
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
__aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
|
|
|
|
|
{
|
|
|
|
|
struct io_event event;
|
|
|
|
|
static struct timespec ts;
|
|
|
|
|
struct iocb *iocbs[] = { &iocb };
|
|
|
|
|
int ret;
|
2009-04-06 10:18:34 -05:00
|
|
|
long res;
|
2004-03-18 23:46:57 +00:00
|
|
|
|
|
|
|
|
if (rw == READ) {
|
|
|
|
|
io_prep_pread(&iocb, fd, buf, len, offset);
|
|
|
|
|
} else {
|
|
|
|
|
io_prep_pwrite(&iocb, fd, buf, len, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ts.tv_sec = 30;
|
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
|
ret = io_submit(io_ctx, 1, iocbs);
|
|
|
|
|
if (ret != 1) {
|
|
|
|
|
fprintf(stderr, "errcode=%d\n", ret);
|
|
|
|
|
fprintf(stderr, "aio_rw: io_submit failed: %s\n",
|
|
|
|
|
strerror(ret));
|
2009-04-06 10:18:34 -05:00
|
|
|
goto out_error;
|
2004-03-18 23:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = io_getevents(io_ctx, 1, 1, &event, &ts);
|
|
|
|
|
if (ret != 1) {
|
2009-04-06 10:18:34 -05:00
|
|
|
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;
|
2004-03-18 23:46:57 +00:00
|
|
|
}
|
|
|
|
|
if (len != event.res) {
|
2009-04-06 10:18:34 -05:00
|
|
|
/*
|
|
|
|
|
* 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 {
|
2010-02-12 20:49:45 +00:00
|
|
|
fprintf(stderr, "errcode=%ld\n", -res);
|
2009-04-06 10:18:34 -05:00
|
|
|
fprintf(stderr, "aio_rw: async io failed: %s\n",
|
|
|
|
|
strerror(-res));
|
|
|
|
|
ret = res;
|
|
|
|
|
goto out_error;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-18 23:46:57 +00:00
|
|
|
}
|
|
|
|
|
return event.res;
|
2009-04-06 10:18:34 -05:00
|
|
|
|
|
|
|
|
out_error:
|
|
|
|
|
/*
|
|
|
|
|
* The caller expects error return in traditional libc
|
|
|
|
|
* convention, i.e. -1 and the errno set to error.
|
|
|
|
|
*/
|
|
|
|
|
errno = -ret;
|
|
|
|
|
return -1;
|
2004-03-18 23:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (aio) {
|
|
|
|
|
ret = __aio_rw(rw, fd, buf, len, offset);
|
|
|
|
|
} else {
|
|
|
|
|
if (rw == READ)
|
|
|
|
|
ret = read(fd, buf, len);
|
|
|
|
|
else
|
|
|
|
|
ret = write(fd, buf, len);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
2003-07-07 06:36:46 +00:00
|
|
|
|
2014-03-13 15:19:58 +11:00
|
|
|
int
|
|
|
|
|
test_fallocate(int mode)
|
2011-06-06 16:33:37 -07:00
|
|
|
{
|
2014-03-13 15:19:52 +11:00
|
|
|
#ifdef HAVE_LINUX_FALLOC_H
|
2014-03-13 15:19:58 +11:00
|
|
|
int ret = 0;
|
|
|
|
|
if (!lite) {
|
|
|
|
|
if (fallocate(fd, mode, 0, 1) && errno == EOPNOTSUPP) {
|
2011-06-06 16:33:37 -07:00
|
|
|
if(!quiet)
|
2014-03-13 15:19:58 +11:00
|
|
|
warn("main: filesystem does not support "
|
|
|
|
|
"fallocate mode 0x%x, disabling!\n", mode);
|
2011-06-06 16:33:37 -07:00
|
|
|
} else {
|
2014-03-13 15:19:58 +11:00
|
|
|
ret = 1;
|
2011-06-06 16:33:37 -07:00
|
|
|
ftruncate(fd, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-13 15:19:58 +11:00
|
|
|
return ret;
|
2011-06-06 16:33:37 -07:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
int
|
|
|
|
|
main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
int i, style, ch;
|
|
|
|
|
char *endp;
|
|
|
|
|
char goodfile[1024];
|
|
|
|
|
char logfile[1024];
|
2014-04-04 17:22:29 +11:00
|
|
|
struct stat statbuf;
|
2003-07-07 06:36:46 +00:00
|
|
|
|
|
|
|
|
goodfile[0] = 0;
|
|
|
|
|
logfile[0] = 0;
|
|
|
|
|
|
2006-08-04 13:44:58 +00:00
|
|
|
page_size = getpagesize();
|
|
|
|
|
page_mask = page_size - 1;
|
|
|
|
|
mmap_mask = page_mask;
|
|
|
|
|
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */
|
|
|
|
|
|
2014-04-04 17:22:29 +11:00
|
|
|
while ((ch = getopt(argc, argv, "b:c:dfl:m:no:p:qr:s:t:w:xyAD:FHzCLN:OP:RS:WZ"))
|
2003-07-07 06:36:46 +00:00
|
|
|
!= EOF)
|
|
|
|
|
switch (ch) {
|
|
|
|
|
case 'b':
|
|
|
|
|
simulatedopcount = getnum(optarg, &endp);
|
|
|
|
|
if (!quiet)
|
|
|
|
|
fprintf(stdout, "Will begin at operation %ld\n",
|
|
|
|
|
simulatedopcount);
|
|
|
|
|
if (simulatedopcount == 0)
|
|
|
|
|
usage();
|
|
|
|
|
simulatedopcount -= 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'c':
|
|
|
|
|
closeprob = getnum(optarg, &endp);
|
|
|
|
|
if (!quiet)
|
|
|
|
|
fprintf(stdout,
|
|
|
|
|
"Chance of close/open is 1 in %d\n",
|
|
|
|
|
closeprob);
|
|
|
|
|
if (closeprob <= 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
|
|
|
|
debug = 1;
|
|
|
|
|
break;
|
2004-03-18 23:46:57 +00:00
|
|
|
case 'f':
|
2006-08-04 13:44:58 +00:00
|
|
|
flush = 1;
|
2004-03-18 23:46:57 +00:00
|
|
|
break;
|
2003-07-07 06:36:46 +00:00
|
|
|
case 'l':
|
|
|
|
|
maxfilelen = getnum(optarg, &endp);
|
|
|
|
|
if (maxfilelen <= 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 'm':
|
|
|
|
|
monitorstart = getnum(optarg, &endp);
|
|
|
|
|
if (monitorstart < 0)
|
|
|
|
|
usage();
|
|
|
|
|
if (!endp || *endp++ != ':')
|
|
|
|
|
usage();
|
|
|
|
|
monitorend = getnum(endp, &endp);
|
|
|
|
|
if (monitorend < 0)
|
|
|
|
|
usage();
|
|
|
|
|
if (monitorend == 0)
|
|
|
|
|
monitorend = -1; /* aka infinity */
|
|
|
|
|
debug = 1;
|
|
|
|
|
case 'n':
|
|
|
|
|
sizechecks = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
maxoplen = getnum(optarg, &endp);
|
|
|
|
|
if (maxoplen <= 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 'p':
|
|
|
|
|
progressinterval = getnum(optarg, &endp);
|
2004-10-22 14:38:06 +00:00
|
|
|
if (progressinterval == 0)
|
2003-07-07 06:36:46 +00:00
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 'q':
|
|
|
|
|
quiet = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
readbdy = getnum(optarg, &endp);
|
|
|
|
|
if (readbdy <= 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 's':
|
|
|
|
|
style = getnum(optarg, &endp);
|
|
|
|
|
if (style < 0 || style > 1)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 't':
|
|
|
|
|
truncbdy = getnum(optarg, &endp);
|
|
|
|
|
if (truncbdy <= 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 'w':
|
|
|
|
|
writebdy = getnum(optarg, &endp);
|
|
|
|
|
if (writebdy <= 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
2003-08-01 05:48:02 +00:00
|
|
|
case 'x':
|
|
|
|
|
prealloc = 1;
|
|
|
|
|
break;
|
2006-08-04 13:44:58 +00:00
|
|
|
case 'y':
|
|
|
|
|
do_fsync = 1;
|
|
|
|
|
break;
|
2004-03-18 23:46:57 +00:00
|
|
|
case 'A':
|
|
|
|
|
aio = 1;
|
|
|
|
|
break;
|
2003-07-07 06:36:46 +00:00
|
|
|
case 'D':
|
|
|
|
|
debugstart = getnum(optarg, &endp);
|
|
|
|
|
if (debugstart < 1)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
2011-03-09 10:35:19 -06:00
|
|
|
case 'F':
|
|
|
|
|
fallocate_calls = 0;
|
|
|
|
|
break;
|
2011-06-06 16:33:37 -07:00
|
|
|
case 'H':
|
|
|
|
|
punch_hole_calls = 0;
|
|
|
|
|
break;
|
2014-03-13 15:19:58 +11:00
|
|
|
case 'z':
|
|
|
|
|
zero_range_calls = 0;
|
|
|
|
|
break;
|
2014-04-04 17:22:29 +11:00
|
|
|
case 'C':
|
|
|
|
|
collapse_range_calls = 0;
|
|
|
|
|
break;
|
2003-07-07 06:36:46 +00:00
|
|
|
case 'L':
|
|
|
|
|
lite = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'N':
|
|
|
|
|
numops = getnum(optarg, &endp);
|
|
|
|
|
if (numops < 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 'O':
|
|
|
|
|
randomoplen = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 'P':
|
|
|
|
|
strncpy(goodfile, optarg, sizeof(goodfile));
|
|
|
|
|
strcat(goodfile, "/");
|
|
|
|
|
strncpy(logfile, optarg, sizeof(logfile));
|
|
|
|
|
strcat(logfile, "/");
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
mapped_reads = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 'S':
|
|
|
|
|
seed = getnum(optarg, &endp);
|
|
|
|
|
if (seed == 0)
|
|
|
|
|
seed = time(0) % 10000;
|
|
|
|
|
if (!quiet)
|
|
|
|
|
fprintf(stdout, "Seed set to %d\n", seed);
|
|
|
|
|
if (seed < 0)
|
|
|
|
|
usage();
|
|
|
|
|
break;
|
|
|
|
|
case 'W':
|
|
|
|
|
mapped_writes = 0;
|
|
|
|
|
if (!quiet)
|
|
|
|
|
fprintf(stdout, "mapped writes DISABLED\n");
|
|
|
|
|
break;
|
2004-03-18 23:46:57 +00:00
|
|
|
case 'Z':
|
|
|
|
|
o_direct = O_DIRECT;
|
|
|
|
|
break;
|
2003-07-07 06:36:46 +00:00
|
|
|
default:
|
|
|
|
|
usage();
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
}
|
|
|
|
|
argc -= optind;
|
|
|
|
|
argv += optind;
|
|
|
|
|
if (argc != 1)
|
|
|
|
|
usage();
|
|
|
|
|
fname = argv[0];
|
|
|
|
|
|
|
|
|
|
signal(SIGHUP, cleanup);
|
|
|
|
|
signal(SIGINT, cleanup);
|
|
|
|
|
signal(SIGPIPE, cleanup);
|
|
|
|
|
signal(SIGALRM, cleanup);
|
|
|
|
|
signal(SIGTERM, cleanup);
|
|
|
|
|
signal(SIGXCPU, cleanup);
|
|
|
|
|
signal(SIGXFSZ, cleanup);
|
|
|
|
|
signal(SIGVTALRM, cleanup);
|
|
|
|
|
signal(SIGUSR1, cleanup);
|
|
|
|
|
signal(SIGUSR2, cleanup);
|
|
|
|
|
|
|
|
|
|
initstate(seed, state, 256);
|
|
|
|
|
setstate(state);
|
2004-03-18 23:46:57 +00:00
|
|
|
fd = open(fname,
|
|
|
|
|
O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
|
prterr(fname);
|
|
|
|
|
exit(91);
|
|
|
|
|
}
|
2014-04-04 17:22:29 +11:00
|
|
|
if (fstat(fd, &statbuf)) {
|
|
|
|
|
prterr("check_size: fstat");
|
|
|
|
|
exit(91);
|
|
|
|
|
}
|
|
|
|
|
block_size = statbuf.st_blksize;
|
2004-03-18 23:46:57 +00:00
|
|
|
#ifdef XFS
|
2003-08-01 05:48:02 +00:00
|
|
|
if (prealloc) {
|
|
|
|
|
xfs_flock64_t resv = { 0 };
|
2004-06-15 07:32:36 +00:00
|
|
|
#ifdef HAVE_XFS_PLATFORM_DEFS_H
|
2003-08-01 05:48:02 +00:00
|
|
|
if (!platform_test_xfs_fd(fd)) {
|
|
|
|
|
prterr(fname);
|
|
|
|
|
fprintf(stderr, "main: cannot prealloc, non XFS\n");
|
|
|
|
|
exit(96);
|
|
|
|
|
}
|
2004-06-15 07:32:36 +00:00
|
|
|
#endif
|
2003-08-01 05:48:02 +00:00
|
|
|
resv.l_len = maxfilelen;
|
|
|
|
|
if ((xfsctl(fname, fd, XFS_IOC_RESVSP, &resv)) < 0) {
|
|
|
|
|
prterr(fname);
|
|
|
|
|
exit(97);
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-03-18 23:46:57 +00:00
|
|
|
#endif
|
2003-07-07 06:36:46 +00:00
|
|
|
strncat(goodfile, fname, 256);
|
|
|
|
|
strcat (goodfile, ".fsxgood");
|
|
|
|
|
fsxgoodfd = open(goodfile, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
|
|
|
|
if (fsxgoodfd < 0) {
|
|
|
|
|
prterr(goodfile);
|
|
|
|
|
exit(92);
|
|
|
|
|
}
|
|
|
|
|
strncat(logfile, fname, 256);
|
|
|
|
|
strcat (logfile, ".fsxlog");
|
|
|
|
|
fsxlogf = fopen(logfile, "w");
|
|
|
|
|
if (fsxlogf == NULL) {
|
|
|
|
|
prterr(logfile);
|
|
|
|
|
exit(93);
|
|
|
|
|
}
|
2004-03-18 23:46:57 +00:00
|
|
|
|
|
|
|
|
#ifdef AIO
|
|
|
|
|
if (aio)
|
|
|
|
|
aio_setup();
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
if (lite) {
|
|
|
|
|
off_t ret;
|
2009-05-13 13:31:47 -05:00
|
|
|
file_size = maxfilelen = lseek(fd, (off_t)0, SEEK_END);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (file_size == (off_t)-1) {
|
|
|
|
|
prterr(fname);
|
2004-03-18 23:46:57 +00:00
|
|
|
warn("main: lseek eof");
|
2003-07-07 06:36:46 +00:00
|
|
|
exit(94);
|
|
|
|
|
}
|
|
|
|
|
ret = lseek(fd, (off_t)0, SEEK_SET);
|
|
|
|
|
if (ret == (off_t)-1) {
|
|
|
|
|
prterr(fname);
|
2004-03-18 23:46:57 +00:00
|
|
|
warn("main: lseek 0");
|
2003-07-07 06:36:46 +00:00
|
|
|
exit(95);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
original_buf = (char *) malloc(maxfilelen);
|
|
|
|
|
for (i = 0; i < maxfilelen; i++)
|
|
|
|
|
original_buf[i] = random() % 256;
|
2004-03-18 23:46:57 +00:00
|
|
|
good_buf = (char *) malloc(maxfilelen + writebdy);
|
2011-07-26 12:12:47 +02:00
|
|
|
good_buf = round_ptr_up(good_buf, writebdy, 0);
|
2009-05-13 13:31:46 -05:00
|
|
|
memset(good_buf, '\0', maxfilelen);
|
2004-03-18 23:46:57 +00:00
|
|
|
temp_buf = (char *) malloc(maxoplen + readbdy);
|
2011-07-26 12:12:47 +02:00
|
|
|
temp_buf = round_ptr_up(temp_buf, readbdy, 0);
|
2009-05-13 13:31:46 -05:00
|
|
|
memset(temp_buf, '\0', maxoplen);
|
2003-07-07 06:36:46 +00:00
|
|
|
if (lite) { /* zero entire existing file */
|
|
|
|
|
ssize_t written;
|
|
|
|
|
|
|
|
|
|
written = write(fd, good_buf, (size_t)maxfilelen);
|
|
|
|
|
if (written != maxfilelen) {
|
|
|
|
|
if (written == -1) {
|
|
|
|
|
prterr(fname);
|
2004-03-18 23:46:57 +00:00
|
|
|
warn("main: error on write");
|
2003-07-07 06:36:46 +00:00
|
|
|
} else
|
2004-03-18 23:46:57 +00:00
|
|
|
warn("main: short write, 0x%x bytes instead "
|
|
|
|
|
"of 0x%lx\n",
|
|
|
|
|
(unsigned)written,
|
|
|
|
|
maxfilelen);
|
2003-07-07 06:36:46 +00:00
|
|
|
exit(98);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
check_trunc_hack();
|
|
|
|
|
|
2014-03-13 15:19:58 +11:00
|
|
|
if (fallocate_calls)
|
|
|
|
|
fallocate_calls = test_fallocate(0);
|
|
|
|
|
if (punch_hole_calls)
|
|
|
|
|
punch_hole_calls = test_fallocate(FALLOC_FL_PUNCH_HOLE |
|
|
|
|
|
FALLOC_FL_KEEP_SIZE);
|
|
|
|
|
if (zero_range_calls)
|
|
|
|
|
zero_range_calls = test_fallocate(FALLOC_FL_ZERO_RANGE);
|
2014-04-04 17:22:29 +11:00
|
|
|
if (collapse_range_calls)
|
|
|
|
|
collapse_range_calls = test_fallocate(FALLOC_FL_COLLAPSE_RANGE);
|
2011-03-09 10:35:19 -06:00
|
|
|
|
2003-07-07 06:36:46 +00:00
|
|
|
while (numops == -1 || numops--)
|
|
|
|
|
test();
|
|
|
|
|
|
|
|
|
|
if (close(fd)) {
|
|
|
|
|
prterr("close");
|
|
|
|
|
report_failure(99);
|
|
|
|
|
}
|
|
|
|
|
prt("All operations completed A-OK!\n");
|
|
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|