fsstress: Include stddef.h for ptrdiff_t
[xfstests-dev.git] / ltp / fsstress.c
index c37cddf754847c49e978946cb32a27a86b71f56a..63c2eb4b17267fa221bb252dc929368f56898710 100644 (file)
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <linux/fs.h>
+#include <setjmp.h>
+#include <sys/uio.h>
+#include <stddef.h>
 #include "global.h"
 
 #ifdef HAVE_ATTR_XATTR_H
 #ifdef HAVE_ATTR_ATTRIBUTES_H
 #include <attr/attributes.h>
 #endif
-
+#ifdef HAVE_LINUX_FIEMAP_H
+#include <linux/fiemap.h>
+#endif
 #ifndef HAVE_ATTR_LIST
 #define attr_list(path, buf, size, flags, cursor) (errno = -ENOSYS, -1)
 #endif
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+#ifdef AIO
+#include <libaio.h>
+io_context_t   io_ctx;
+#endif
+
+#ifndef FS_IOC_GETFLAGS
+#define FS_IOC_GETFLAGS                 _IOR('f', 1, long)
+#endif
+#ifndef FS_IOC_SETFLAGS
+#define FS_IOC_SETFLAGS                 _IOW('f', 2, long)
+#endif
 
 #include <math.h>
 #define XFS_ERRTAG_MAX         17
 #define XFS_IDMODULO_MAX       31      /* user/group IDs (1 << x)  */
 #define XFS_PROJIDMODULO_MAX   16      /* project IDs (1 << x)     */
+#ifndef IOV_MAX
+#define IOV_MAX 1024
+#endif
 
 #define FILELEN_MAX            (32*4096)
 
 typedef enum {
+       OP_AFSYNC,
        OP_ALLOCSP,
+       OP_AREAD,
        OP_ATTR_REMOVE,
        OP_ATTR_SET,
+       OP_AWRITE,
        OP_BULKSTAT,
        OP_BULKSTAT1,
        OP_CHOWN,
+       OP_CLONERANGE,
        OP_CREAT,
+       OP_DEDUPERANGE,
        OP_DREAD,
        OP_DWRITE,
+       OP_FALLOCATE,
        OP_FDATASYNC,
+       OP_FIEMAP,
        OP_FREESP,
        OP_FSYNC,
+       OP_GETATTR,
        OP_GETDENTS,
        OP_LINK,
        OP_MKDIR,
        OP_MKNOD,
+       OP_MREAD,
+       OP_MWRITE,
+       OP_PUNCH,
+       OP_ZERO,
+       OP_COLLAPSE,
+       OP_INSERT,
        OP_READ,
        OP_READLINK,
+       OP_READV,
        OP_RENAME,
        OP_RESVSP,
        OP_RMDIR,
+       OP_SETATTR,
        OP_SETXATTR,
        OP_STAT,
        OP_SYMLINK,
@@ -66,6 +105,7 @@ typedef enum {
        OP_UNLINK,
        OP_UNRESVSP,
        OP_WRITE,
+       OP_WRITEV,
        OP_LAST
 } opty_t;
 
@@ -96,6 +136,17 @@ typedef struct pathname {
        char    *path;
 } pathname_t;
 
+struct print_flags {
+       unsigned long mask;
+       const char *name;
+};
+
+struct print_string {
+       char *buffer;
+       int len;
+       int max;
+};
+
 #define        FT_DIR  0
 #define        FT_DIRm (1 << FT_DIR)
 #define        FT_REG  1
@@ -117,27 +168,43 @@ typedef struct pathname {
 #define        MAXFSIZE        ((1ULL << 63) - 1ULL)
 #define        MAXFSIZE32      ((1ULL << 40) - 1ULL)
 
+void   afsync_f(int, long);
 void   allocsp_f(int, long);
+void   aread_f(int, long);
 void   attr_remove_f(int, long);
 void   attr_set_f(int, long);
+void   awrite_f(int, long);
 void   bulkstat_f(int, long);
 void   bulkstat1_f(int, long);
 void   chown_f(int, long);
+void   clonerange_f(int, long);
 void   creat_f(int, long);
+void   deduperange_f(int, long);
 void   dread_f(int, long);
 void   dwrite_f(int, long);
+void   fallocate_f(int, long);
 void   fdatasync_f(int, long);
+void   fiemap_f(int, long);
 void   freesp_f(int, long);
 void   fsync_f(int, long);
+void   getattr_f(int, long);
 void   getdents_f(int, long);
 void   link_f(int, long);
 void   mkdir_f(int, long);
 void   mknod_f(int, long);
+void   mread_f(int, long);
+void   mwrite_f(int, long);
+void   punch_f(int, long);
+void   zero_f(int, long);
+void   collapse_f(int, long);
+void   insert_f(int, long);
 void   read_f(int, long);
 void   readlink_f(int, long);
+void   readv_f(int, long);
 void   rename_f(int, long);
 void   resvsp_f(int, long);
 void   rmdir_f(int, long);
+void   setattr_f(int, long);
 void   setxattr_f(int, long);
 void   stat_f(int, long);
 void   symlink_f(int, long);
@@ -146,37 +213,56 @@ void      truncate_f(int, long);
 void   unlink_f(int, long);
 void   unresvsp_f(int, long);
 void   write_f(int, long);
+void   writev_f(int, long);
 
 opdesc_t       ops[] = {
+     /* { OP_ENUM, "name", function, freq, iswrite }, */
+       { OP_AFSYNC, "afsync", afsync_f, 0, 1 },
        { OP_ALLOCSP, "allocsp", allocsp_f, 1, 1 },
+       { OP_AREAD, "aread", aread_f, 1, 0 },
        { OP_ATTR_REMOVE, "attr_remove", attr_remove_f, /* 1 */ 0, 1 },
        { OP_ATTR_SET, "attr_set", attr_set_f, /* 2 */ 0, 1 },
+       { OP_AWRITE, "awrite", awrite_f, 1, 1 },
        { OP_BULKSTAT, "bulkstat", bulkstat_f, 1, 0 },
        { OP_BULKSTAT1, "bulkstat1", bulkstat1_f, 1, 0 },
        { OP_CHOWN, "chown", chown_f, 3, 1 },
+       { OP_CLONERANGE, "clonerange", clonerange_f, 4, 1 },
        { OP_CREAT, "creat", creat_f, 4, 1 },
+       { OP_DEDUPERANGE, "deduperange", deduperange_f, 4, 1},
        { OP_DREAD, "dread", dread_f, 4, 0 },
        { OP_DWRITE, "dwrite", dwrite_f, 4, 1 },
+       { OP_FALLOCATE, "fallocate", fallocate_f, 1, 1 },
        { OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1 },
+       { OP_FIEMAP, "fiemap", fiemap_f, 1, 1 },
        { OP_FREESP, "freesp", freesp_f, 1, 1 },
        { OP_FSYNC, "fsync", fsync_f, 1, 1 },
+       { OP_GETATTR, "getattr", getattr_f, 1, 0 },
        { OP_GETDENTS, "getdents", getdents_f, 1, 0 },
        { OP_LINK, "link", link_f, 1, 1 },
        { OP_MKDIR, "mkdir", mkdir_f, 2, 1 },
        { OP_MKNOD, "mknod", mknod_f, 2, 1 },
+       { OP_MREAD, "mread", mread_f, 2, 0 },
+       { OP_MWRITE, "mwrite", mwrite_f, 2, 1 },
+       { OP_PUNCH, "punch", punch_f, 1, 1 },
+       { OP_ZERO, "zero", zero_f, 1, 1 },
+       { OP_COLLAPSE, "collapse", collapse_f, 1, 1 },
+       { OP_INSERT, "insert", insert_f, 1, 1 },
        { OP_READ, "read", read_f, 1, 0 },
        { OP_READLINK, "readlink", readlink_f, 1, 0 },
+       { OP_READV, "readv", readv_f, 1, 0 },
        { OP_RENAME, "rename", rename_f, 2, 1 },
        { OP_RESVSP, "resvsp", resvsp_f, 1, 1 },
        { OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
+       { OP_SETATTR, "setattr", setattr_f, 0, 1 },
        { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
        { OP_STAT, "stat", stat_f, 1, 0 },
        { OP_SYMLINK, "symlink", symlink_f, 2, 1 },
-       { OP_SYNC, "sync", sync_f, 1, 0 },
+       { OP_SYNC, "sync", sync_f, 1, 1 },
        { OP_TRUNCATE, "truncate", truncate_f, 2, 1 },
        { OP_UNLINK, "unlink", unlink_f, 1, 1 },
        { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 },
        { OP_WRITE, "write", write_f, 4, 1 },
+       { OP_WRITEV, "writev", writev_f, 4, 1 },
 }, *ops_end;
 
 flist_t        flist[FT_nft] = {
@@ -204,11 +290,19 @@ int               nops;
 int            nproc = 1;
 int            operations = 1;
 unsigned int   idmodulo = XFS_IDMODULO_MAX;
+unsigned int   attr_mask = ~0;
 int            procid;
 int            rtpct;
 unsigned long  seed = 0;
 ino_t          top_ino;
+int            cleanup = 0;
 int            verbose = 0;
+int            verifiable_log = 0;
+sig_atomic_t   should_stop = 0;
+sigjmp_buf     *sigbus_jmp = NULL;
+char           *execute_cmd = NULL;
+int            execute_freq = 1;
+struct print_string    flag_str = {0};
 
 void   add_to_flist(int, int, int);
 void   append_pathname(pathname_t *, char *);
@@ -216,6 +310,7 @@ int attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
 int    attr_remove_path(pathname_t *, const char *, int);
 int    attr_set_path(pathname_t *, const char *, const char *, const int, int);
 void   check_cwd(void);
+void   cleanup_flist(void);
 int    creat_path(pathname_t *, mode_t);
 void   dcache_enter(int, int);
 void   dcache_init(void);
@@ -253,11 +348,37 @@ void      usage(void);
 void   write_freq(void);
 void   zero_freq(void);
 
+void sg_handler(int signum)
+{
+       switch (signum) {
+       case SIGTERM:
+               should_stop = 1;
+               break;
+       case SIGBUS:
+               /*
+                * Only handle SIGBUS when mmap write to a hole and no
+                * block can be allocated due to ENOSPC, abort otherwise.
+                */
+               if (sigbus_jmp) {
+                       siglongjmp(*sigbus_jmp, -1);
+               } else {
+                       printf("Unknown SIGBUS is caught, Abort!\n");
+                       abort();
+               }
+               /* should not reach here */
+               break;
+       default:
+               break;
+       }
+}
+
 int main(int argc, char **argv)
 {
        char            buf[10];
        int             c;
        char            *dirname = NULL;
+       char            *logname = NULL;
+       char            rpath[PATH_MAX];
        int             fd;
        int             i;
        int             j;
@@ -267,14 +388,20 @@ int main(int argc, char **argv)
        ptrdiff_t       srval;
        int             nousage = 0;
        xfs_error_injection_t           err_inj;
+       struct sigaction action;
+       int             loops = 1;
+       const char      *allopts = "cd:e:f:i:l:m:M:n:o:p:rs:S:vVwx:X:zH";
 
        errrange = errtag = 0;
        umask(0);
        nops = sizeof(ops) / sizeof(ops[0]);
        ops_end = &ops[nops];
        myprog = argv[0];
-       while ((c = getopt(argc, argv, "d:e:f:i:m:n:p:rs:vwzHS")) != -1) {
+       while ((c = getopt(argc, argv, allopts)) != -1) {
                switch (c) {
+               case 'c':
+                       cleanup = 1;
+                       break;
                case 'd':
                        dirname = optarg;
                        break;
@@ -308,9 +435,16 @@ int main(int argc, char **argv)
                                exit(1);
                        }
                        break;
+               case 'l':
+                       loops = atoi(optarg);
+                       break;
                case 'n':
                        operations = atoi(optarg);
                        break;
+               case 'o':
+                       logname = optarg;
+                       break;
+
                case 'p':
                        nproc = atoi(optarg);
                        break;
@@ -326,14 +460,30 @@ int main(int argc, char **argv)
                case 'w':
                        write_freq();
                        break;
+               case 'x':
+                       execute_cmd = optarg;
+                       break;
                case 'z':
                        zero_freq();
                        break;
+               case 'M':
+                       attr_mask = strtoul(optarg, NULL, 0);
+                       break;
                case 'S':
-                       show_ops(0, NULL);
+                       i = 0;
+                       if (optarg[0] == 'c')
+                               i = 1;
+                       show_ops(i, NULL);
                        printf("\n");
                         nousage=1;
                        break;
+               case 'V':
+                       verifiable_log = 1;
+                       break;
+
+               case 'X':
+                       execute_freq = strtoul(optarg, NULL, 0);
+                       break;
                case '?':
                        fprintf(stderr, "%s - invalid parameters\n",
                                myprog);
@@ -351,10 +501,26 @@ int main(int argc, char **argv)
         }
 
        (void)mkdir(dirname, 0777);
+       if (logname && logname[0] != '/') {
+               if (!getcwd(rpath, sizeof(rpath))){
+                       perror("getcwd failed");
+                       exit(1);
+               }
+       } else {
+               rpath[0] = '\0';
+       }
        if (chdir(dirname) < 0) {
                perror(dirname);
                exit(1);
        }
+       if (logname) {
+               char path[PATH_MAX];
+               snprintf(path, sizeof(path), "%s/%s", rpath, logname);
+               if (freopen(path, "a", stdout) == NULL) {
+                       perror("freopen logfile failed");
+                       exit(1);
+               }
+       }
        sprintf(buf, "fss%x", (unsigned int)getpid());
        fd = creat(buf, 0666);
        if (lseek64(fd, (off64_t)(MAXFSIZE32 + 1ULL), SEEK_SET) < 0)
@@ -407,15 +573,69 @@ int main(int argc, char **argv)
                }
        } else
                close(fd);
+
+       setpgid(0, 0);
+       action.sa_handler = sg_handler;
+       sigemptyset(&action.sa_mask);
+       action.sa_flags = 0;
+       if (sigaction(SIGTERM, &action, 0)) {
+               perror("sigaction failed");
+               exit(1);
+       }
+
        for (i = 0; i < nproc; i++) {
                if (fork() == 0) {
+                       sigemptyset(&action.sa_mask);
+                       action.sa_handler = SIG_DFL;
+                       if (sigaction(SIGTERM, &action, 0))
+                               return 1;
+                       action.sa_handler = sg_handler;
+                       if (sigaction(SIGBUS, &action, 0))
+                               return 1;
+#ifdef HAVE_SYS_PRCTL_H
+                       prctl(PR_SET_PDEATHSIG, SIGKILL);
+                       if (getppid() == 1) /* parent died already? */
+                               return 0;
+#endif
+                       if (logname) {
+                               char path[PATH_MAX];
+                               snprintf(path, sizeof(path), "%s/%s.%d",
+                                        rpath, logname, i);
+                               if (freopen(path, "a", stdout) == NULL) {
+                                       perror("freopen logfile failed");
+                                       exit(1);
+                               }
+                       }
                        procid = i;
-                       doproc();
+#ifdef AIO
+                       if (io_setup(128, &io_ctx) != 0) {
+                               fprintf(stderr, "io_setup failed");
+                               exit(1);
+                       }
+#endif
+                       for (i = 0; !loops || (i < loops); i++)
+                               doproc();
+#ifdef AIO
+                       if(io_destroy(io_ctx) != 0) {
+                               fprintf(stderr, "io_destroy failed");
+                               return 1;
+                       }
+#endif
+
+                       cleanup_flist();
+                       free(freq_table);
                        return 0;
                }
        }
+       while (wait(&stat) > 0 && !should_stop) {
+               continue;
+       }
+       action.sa_flags = SA_RESTART;
+       sigaction(SIGTERM, &action, 0);
+       kill(-getpid(), SIGTERM);
        while (wait(&stat) > 0)
                continue;
+
        if (errtag != 0) {
                err_inj.errtag = 0;
                err_inj.fd = fd;
@@ -430,10 +650,78 @@ int main(int argc, char **argv)
                close(fd);
        }
 
+       free(freq_table);
        unlink(buf);
        return 0;
 }
 
+int
+add_string(struct print_string *str, const char *add)
+{
+       int len = strlen(add);
+
+       if (len <= 0)
+               return 0;
+
+       if (len > (str->max - 1) - str->len) {
+               str->len = str->max - 1;
+               return 0;
+       }
+
+       memcpy(str->buffer + str->len, add, len);
+       str->len += len;
+       str->buffer[str->len] = '\0';
+
+       return len;
+}
+
+char *
+translate_flags(int flags, const char *delim,
+               const struct print_flags *flag_array)
+{
+       int i, mask, first = 1;
+       const char *add;
+
+       if (!flag_str.buffer) {
+               flag_str.buffer = malloc(4096);
+               flag_str.max = 4096;
+               flag_str.len = 0;
+       }
+       if (!flag_str.buffer)
+               return NULL;
+       flag_str.len = 0;
+       flag_str.buffer[0] = '\0';
+
+       for (i = 0;  flag_array[i].name && flags; i++) {
+               mask = flag_array[i].mask;
+               if ((flags & mask) != mask)
+                       continue;
+
+               add = flag_array[i].name;
+               flags &= ~mask;
+               if (!first && delim)
+                       add_string(&flag_str, delim);
+               else
+                       first = 0;
+               add_string(&flag_str, add);
+       }
+
+       /* Check whether there are any leftover flags. */
+       if (flags) {
+               int ret;
+               char number[11];
+
+               if (!first && delim)
+                       add_string(&flag_str, delim);
+
+               ret = snprintf(number, 11, "0x%x", flags) > 0;
+               if (ret > 0 && ret <= 11)
+                       add_string(&flag_str, number);
+       }
+
+       return flag_str.buffer;
+}
+
 void
 add_to_flist(int ft, int id, int parent)
 {
@@ -553,6 +841,25 @@ check_cwd(void)
 #endif
 }
 
+/*
+ * go thru flist and release all entries
+ *
+ * NOTE: this function shouldn't be called until the end of a process
+ */
+void
+cleanup_flist(void)
+{
+       flist_t *flp;
+       int     i;
+
+       for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
+               flp->nslots = 0;
+               flp->nfiles = 0;
+               free(flp->fents);
+               flp->fents = NULL;
+       }
+}
+
 int
 creat_path(pathname_t *name, mode_t mode)
 {
@@ -655,10 +962,13 @@ doproc(void)
 {
        struct stat64   statbuf;
        char            buf[10];
+       char            cmd[64];
        int             opno;
        int             rval;
        opdesc_t        *p;
+       int             dividend;
 
+       dividend = (operations + execute_freq) / (execute_freq + 1);
        sprintf(buf, "p%x", procid);
        (void)mkdir(buf, 0777);
        if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
@@ -666,12 +976,25 @@ doproc(void)
                _exit(1);
        }
        top_ino = statbuf.st_ino;
-       homedir = getcwd(NULL, -1);
+       homedir = getcwd(NULL, 0);
+       if (!homedir) {
+               perror("getcwd failed");
+               _exit(1);
+       }
        seed += procid;
        srandom(seed);
        if (namerand)
                namerand = random();
        for (opno = 0; opno < operations; opno++) {
+               if (execute_cmd && opno && opno % dividend == 0) {
+                       if (verbose)
+                               printf("%d: execute command %s\n", opno,
+                                       execute_cmd);
+                       rval = system(execute_cmd);
+                       if (rval)
+                               fprintf(stderr, "execute command failed with "
+                                       "%d\n", rval);
+               }
                p = &ops[freq_table[random() % freq_table_size]];
                p->func(opno, random());
                /*
@@ -683,10 +1006,18 @@ doproc(void)
                        rval = stat64(".", &statbuf);
                        if (rval == EIO)  {
                                fprintf(stderr, "Detected EIO\n");
-                               return;
+                               goto errout;
                        }
                }
        }
+errout:
+       chdir("..");
+       free(homedir);
+       if (cleanup) {
+               sprintf(cmd, "rm -rf %s", buf);
+               system(cmd);
+               cleanup_flist();
+       }
 }
 
 /*
@@ -1244,7 +1575,8 @@ show_ops(int flag, char *lead_str)
                         x+=printf("%s ", p->name);
                 }
                 printf("\n");
-        } else {
+        } else if (flag == 0) {
+               /* Table view style */
                int             f;
                for (f = 0, p = ops; p < ops_end; p++)
                        f += p->freq;
@@ -1261,6 +1593,15 @@ show_ops(int flag, char *lead_str)
                                (p->iswrite == 0) ? " " : "write op");
                        }
                 }
+       } else {
+               /* Command line style */
+               if (lead_str != NULL)
+                       printf("%s", lead_str);
+               printf ("-z -s %ld -m %d -n %d -p %d \\\n", seed, idmodulo,
+                       operations, nproc);
+               for (p = ops; p < ops_end; p++)
+                       if (p->freq > 0)
+                               printf("-f %s=%d \\\n",p->name, p->freq);
        }
 }
 
@@ -1349,25 +1690,32 @@ void
 usage(void)
 {
        printf("Usage: %s -H   or\n", myprog);
-       printf("       %s [-d dir][-e errtg][-f op_name=freq][-n nops]\n",
+       printf("       %s [-c][-d dir][-e errtg][-f op_name=freq][-l loops][-n nops]\n",
                myprog);
-       printf("          [-p nproc][-r len][-s seed][-v][-w][-z][-S]\n");
+       printf("          [-p nproc][-r len][-s seed][-v][-w][-x cmd][-z][-S][-X ncmd]\n");
        printf("where\n");
+       printf("   -c               clean up the test directory after each run\n");
        printf("   -d dir           specifies the base directory for operations\n");
        printf("   -e errtg         specifies error injection stuff\n");
        printf("   -f op_name=freq  changes the frequency of option name to freq\n");
        printf("                    the valid operation names are:\n");
-       printf("   -i filenum       get verbose output for this nth file object\n");
        show_ops(-1, "                        ");
+       printf("   -i filenum       get verbose output for this nth file object\n");
+       printf("   -l loops         specifies the no. of times the testrun should loop.\n");
+       printf("                     *use 0 for infinite (default 1)\n");
        printf("   -m modulo        uid/gid modulo for chown/chgrp (default 32)\n");
        printf("   -n nops          specifies the no. of operations per process (default 1)\n");
+       printf("   -o logfile       specifies logfile name\n");
        printf("   -p nproc         specifies the no. of processes (default 1)\n");
        printf("   -r               specifies random name padding\n");
        printf("   -s seed          specifies the seed for the random generator (default random)\n");
        printf("   -v               specifies verbose mode\n");
        printf("   -w               zeros frequencies of non-write operations\n");
+       printf("   -x cmd           execute command in the middle of operations\n");
        printf("   -z               zeros frequencies of all operations\n");
-       printf("   -S               prints the table of operations (omitting zero frequency)\n");
+       printf("   -S [c,t]         prints the list of operations (omitting zero frequency) in command line or table style\n");
+       printf("   -V               specifies verifiable logging mode (omitting inode numbers)\n");
+       printf("   -X ncmd          number of calls to the -x command (default 1)\n");
        printf("   -H               prints usage and exits\n");
 }
 
@@ -1391,6 +1739,71 @@ zero_freq(void)
                p->freq = 0;
 }
 
+void inode_info(char *str, size_t sz, struct stat64 *s, int verbose)
+{
+       if (verbose)
+               snprintf(str, sz, "[%ld %ld %d %d %lld %lld]",
+                        verifiable_log ? -1: (long)s->st_ino,
+                        (long)s->st_nlink,  s->st_uid, s->st_gid,
+                        (long long) s->st_blocks, (long long) s->st_size);
+}
+
+void
+afsync_f(int opno, long r)
+{
+#ifdef AIO
+       int             e;
+       pathname_t      f;
+       int             fd;
+       int             v;
+       struct iocb     iocb;
+       struct iocb     *iocbs[] = { &iocb };
+       struct io_event event;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: afsync - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_WRONLY | O_DIRECT);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: afsync - open %s failed %d\n",
+                              procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+
+       io_prep_fsync(&iocb, fd);
+       if ((e = io_submit(io_ctx, 1, iocbs)) != 1) {
+               if (v)
+                       printf("%d/%d: afsync - io_submit %s %d\n",
+                              procid, opno, f.path, e);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) {
+               if (v)
+                       printf("%d/%d: afsync - io_getevents failed %d\n",
+                              procid, opno, e);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+
+       e = event.res2;
+       if (v)
+               printf("%d/%d: afsync %s %d\n", procid, opno, f.path, e);
+       free_pathname(&f);
+       close(fd);
+#endif
+}
+
 void
 allocsp_f(int opno, long r)
 {
@@ -1402,6 +1815,7 @@ allocsp_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1428,6 +1842,7 @@ allocsp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -1435,12 +1850,138 @@ allocsp_f(int opno, long r)
        fl.l_start = off;
        fl.l_len = 0;
        e = xfsctl(f.path, fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
+       if (v) {
+               printf("%d/%d: xfsctl(XFS_IOC_ALLOCSP64) %s%s %lld 0 %d\n",
+                      procid, opno, f.path, st, (long long)off, e);
+       }
+       free_pathname(&f);
+       close(fd);
+}
+
+#ifdef AIO
+void
+do_aio_rw(int opno, long r, int flags)
+{
+       __int64_t       align;
+       char            *buf;
+       struct dioattr  diob;
+       int             e;
+       pathname_t      f;
+       int             fd;
+       size_t          len;
+       __int64_t       lr;
+       off64_t         off;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+       char            *dio_env;
+       struct iocb     iocb;
+       struct io_event event;
+       struct iocb     *iocbs[] = { &iocb };
+       int             iswrite = (flags & (O_WRONLY | O_RDWR)) ? 1 : 0;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: do_aio_rw - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, flags|O_DIRECT);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: do_aio_rw - open %s failed %d\n",
+                              procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: do_aio_rw - fstat64 %s failed %d\n",
+                              procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       if (!iswrite && stb.st_size == 0) {
+               if (v)
+                       printf("%d/%d: do_aio_rw - %s%s zero size\n", procid, opno,
+                              f.path, st);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
+               if (v)
+                       printf(
+                       "%d/%d: do_aio_rw - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
+                       " fallback to stat()\n",
+                               procid, opno, f.path, st, errno);
+               diob.d_mem = diob.d_miniosz = stb.st_blksize;
+               diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
+       }
+       dio_env = getenv("XFS_DIO_MIN");
+       if (dio_env)
+               diob.d_mem = diob.d_miniosz = atoi(dio_env);
+       align = (__int64_t)diob.d_miniosz;
+       lr = ((__int64_t)random() << 32) + random();
+       len = (random() % FILELEN_MAX) + 1;
+       len -= (len % align);
+       if (len <= 0)
+               len = align;
+       else if (len > diob.d_maxiosz)
+               len = diob.d_maxiosz;
+       buf = memalign(diob.d_mem, len);
+
+       if (iswrite) {
+               off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+               off -= (off % align);
+               off %= maxfsize;
+               memset(buf, nameseq & 0xff, len);
+               io_prep_pwrite(&iocb, fd, buf, len, off);
+       } else {
+               off = (off64_t)(lr % stb.st_size);
+               off -= (off % align);
+               io_prep_pread(&iocb, fd, buf, len, off);
+       }
+       if ((e = io_submit(io_ctx, 1, iocbs)) != 1) {
+               if (v)
+                       printf("%d/%d: %s - io_submit failed %d\n",
+                              procid, opno, iswrite ? "awrite" : "aread", e);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) {
+               if (v)
+                       printf("%d/%d: %s - io_getevents failed %d\n",
+                              procid, opno, iswrite ? "awrite" : "aread", e);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+
+       e = event.res != len ? event.res2 : 0;
+       free(buf);
        if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_ALLOCSP64) %s %lld 0 %d\n",
-                       procid, opno, f.path, (long long)off, e);
+               printf("%d/%d: %s %s%s [%lld,%d] %d\n",
+                      procid, opno, iswrite ? "awrite" : "aread",
+                      f.path, st, (long long)off, (int)len, e);
        free_pathname(&f);
        close(fd);
 }
+#endif
+
+void
+aread_f(int opno, long r)
+{
+#ifdef AIO
+       do_aio_rw(opno, r, O_RDONLY);
+#endif
+}
 
 void
 attr_remove_f(int opno, long r)
@@ -1545,6 +2086,14 @@ attr_set_f(int opno, long r)
        free_pathname(&f);
 }
 
+void
+awrite_f(int opno, long r)
+{
+#ifdef AIO
+       do_aio_rw(opno, r, O_WRONLY);
+#endif
+}
+
 void
 bulkstat_f(int opno, long r)
 {
@@ -1623,11 +2172,11 @@ bulkstat1_f(int opno, long r)
         bsr.icount=1;
         bsr.ubuffer=&t;
         bsr.ocount=NULL;
-        
        e = xfsctl(".", fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
        if (v)
                printf("%d/%d: bulkstat1 %s ino %lld %d\n", 
-                    procid, opno, good?"real":"random", (long long)ino, e);
+                      procid, opno, good?"real":"random",
+                      verifiable_log ? -1LL : (long long)ino, e);
        close(fd);
 }
 
@@ -1656,36 +2205,421 @@ chown_f(int opno, long r)
        free_pathname(&f);
 }
 
+/* reflink some arbitrary range of f1 to f2. */
 void
-setxattr_f(int opno, long r)
+clonerange_f(
+       int                     opno,
+       long                    r)
 {
-#ifdef XFS_XFLAG_EXTSIZE
-       struct fsxattr  fsx;
-       int             fd;
-       int             e;
-       pathname_t      f;
-       int             nbits;
-       uint            p;
-       int             v;
+#ifdef FICLONERANGE
+       struct file_clone_range fcr;
+       struct pathname         fpath1;
+       struct pathname         fpath2;
+       struct stat64           stat1;
+       struct stat64           stat2;
+       char                    inoinfo1[1024];
+       char                    inoinfo2[1024];
+       off64_t                 lr;
+       off64_t                 off1;
+       off64_t                 off2;
+       size_t                  len;
+       int                     v1;
+       int                     v2;
+       int                     fd1;
+       int                     fd2;
+       int                     ret;
+       int                     e;
 
-       init_pathname(&f);
-       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
-               append_pathname(&f, ".");
-       fd = open_path(&f, O_RDWR);
-       e = fd < 0 ? errno : 0;
+       /* Load paths */
+       init_pathname(&fpath1);
+       if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
+               if (v1)
+                       printf("%d/%d: clonerange read - no filename\n",
+                               procid, opno);
+               goto out_fpath1;
+       }
+
+       init_pathname(&fpath2);
+       if (!get_fname(FT_REGm, random(), &fpath2, NULL, NULL, &v2)) {
+               if (v2)
+                       printf("%d/%d: clonerange write - no filename\n",
+                               procid, opno);
+               goto out_fpath2;
+       }
+
+       /* Open files */
+       fd1 = open_path(&fpath1, O_RDONLY);
+       e = fd1 < 0 ? errno : 0;
        check_cwd();
+       if (fd1 < 0) {
+               if (v1)
+                       printf("%d/%d: clonerange read - open %s failed %d\n",
+                               procid, opno, fpath1.path, e);
+               goto out_fpath2;
+       }
 
-       /* project ID */
-       p = (uint)random();
-       e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
-       nbits = (int)(random() % e);
-       p &= (1 << nbits) - 1;
+       fd2 = open_path(&fpath2, O_WRONLY);
+       e = fd2 < 0 ? errno : 0;
+       check_cwd();
+       if (fd2 < 0) {
+               if (v2)
+                       printf("%d/%d: clonerange write - open %s failed %d\n",
+                               procid, opno, fpath2.path, e);
+               goto out_fd1;
+       }
 
-       if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
-               fsx.fsx_projid = p;
-               e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
+       /* Get file stats */
+       if (fstat64(fd1, &stat1) < 0) {
+               if (v1)
+                       printf("%d/%d: clonerange read - fstat64 %s failed %d\n",
+                               procid, opno, fpath1.path, errno);
+               goto out_fd2;
        }
-       if (v)
+       inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
+
+       if (fstat64(fd2, &stat2) < 0) {
+               if (v2)
+                       printf("%d/%d: clonerange write - fstat64 %s failed %d\n",
+                               procid, opno, fpath2.path, errno);
+               goto out_fd2;
+       }
+       inode_info(inoinfo2, sizeof(inoinfo2), &stat2, v2);
+
+       /* Calculate offsets */
+       len = (random() % FILELEN_MAX) + 1;
+       len &= ~(stat1.st_blksize - 1);
+       if (len == 0)
+               len = stat1.st_blksize;
+       if (len > stat1.st_size)
+               len = stat1.st_size;
+
+       lr = ((__int64_t)random() << 32) + random();
+       if (stat1.st_size == len)
+               off1 = 0;
+       else
+               off1 = (off64_t)(lr % MIN(stat1.st_size - len, MAXFSIZE));
+       off1 %= maxfsize;
+       off1 &= ~(stat1.st_blksize - 1);
+
+       /*
+        * If srcfile == destfile, randomly generate destination ranges
+        * until we find one that doesn't overlap the source range.
+        */
+       do {
+               lr = ((__int64_t)random() << 32) + random();
+               off2 = (off64_t)(lr % MIN(stat2.st_size + (1024 * 1024), MAXFSIZE));
+               off2 %= maxfsize;
+               off2 &= ~(stat2.st_blksize - 1);
+       } while (stat1.st_ino == stat2.st_ino && llabs(off2 - off1) < len);
+
+       /* Clone data blocks */
+       fcr.src_fd = fd1;
+       fcr.src_offset = off1;
+       fcr.src_length = len;
+       fcr.dest_offset = off2;
+
+       ret = ioctl(fd2, FICLONERANGE, &fcr);
+       e = ret < 0 ? errno : 0;
+       if (v1 || v2) {
+               printf("%d/%d: clonerange %s%s [%lld,%lld] -> %s%s [%lld,%lld]",
+                       procid, opno,
+                       fpath1.path, inoinfo1, (long long)off1, (long long)len,
+                       fpath2.path, inoinfo2, (long long)off2, (long long)len);
+
+               if (ret < 0)
+                       printf(" error %d", e);
+               printf("\n");
+       }
+
+out_fd2:
+       close(fd2);
+out_fd1:
+       close(fd1);
+out_fpath2:
+       free_pathname(&fpath2);
+out_fpath1:
+       free_pathname(&fpath1);
+#endif
+}
+
+/* dedupe some arbitrary range of f1 to f2...fn. */
+void
+deduperange_f(
+       int                     opno,
+       long                    r)
+{
+#ifdef FIDEDUPERANGE
+#define INFO_SZ                        1024
+       struct file_dedupe_range *fdr;
+       struct pathname         *fpath;
+       struct stat64           *stat;
+       char                    *info;
+       off64_t                 *off;
+       int                     *v;
+       int                     *fd;
+       int                     nr;
+       off64_t                 lr;
+       size_t                  len;
+       int                     ret;
+       int                     i;
+       int                     e;
+
+       if (flist[FT_REG].nfiles < 2)
+               return;
+
+       /* Pick somewhere between 2 and 128 files. */
+       do {
+               nr = random() % (flist[FT_REG].nfiles + 1);
+       } while (nr < 2 || nr > 128);
+
+       /* Alloc memory */
+       fdr = malloc(nr * sizeof(struct file_dedupe_range_info) +
+                    sizeof(struct file_dedupe_range));
+       if (!fdr) {
+               printf("%d/%d: line %d error %d\n",
+                       procid, opno, __LINE__, errno);
+               return;
+       }
+       memset(fdr, 0, (nr * sizeof(struct file_dedupe_range_info) +
+                       sizeof(struct file_dedupe_range)));
+
+       fpath = calloc(nr, sizeof(struct pathname));
+       if (!fpath) {
+               printf("%d/%d: line %d error %d\n",
+                       procid, opno, __LINE__, errno);
+               goto out_fdr;
+       }
+
+       stat = calloc(nr, sizeof(struct stat64));
+       if (!stat) {
+               printf("%d/%d: line %d error %d\n",
+                       procid, opno, __LINE__, errno);
+               goto out_paths;
+       }
+
+       info = calloc(nr, INFO_SZ);
+       if (!info) {
+               printf("%d/%d: line %d error %d\n",
+                       procid, opno, __LINE__, errno);
+               goto out_stats;
+       }
+
+       off = calloc(nr, sizeof(off64_t));
+       if (!off) {
+               printf("%d/%d: line %d error %d\n",
+                       procid, opno, __LINE__, errno);
+               goto out_info;
+       }
+
+       v = calloc(nr, sizeof(int));
+       if (!v) {
+               printf("%d/%d: line %d error %d\n",
+                       procid, opno, __LINE__, errno);
+               goto out_offsets;
+       }
+       fd = calloc(nr, sizeof(int));
+       if (!fd) {
+               printf("%d/%d: line %d error %d\n",
+                       procid, opno, __LINE__, errno);
+               goto out_v;
+       }
+       memset(fd, 0xFF, nr * sizeof(int));
+
+       /* Get paths for all files */
+       for (i = 0; i < nr; i++)
+               init_pathname(&fpath[i]);
+
+       if (!get_fname(FT_REGm, r, &fpath[0], NULL, NULL, &v[0])) {
+               if (v[0])
+                       printf("%d/%d: deduperange read - no filename\n",
+                               procid, opno);
+               goto out_pathnames;
+       }
+
+       for (i = 1; i < nr; i++) {
+               if (!get_fname(FT_REGm, random(), &fpath[i], NULL, NULL, &v[i])) {
+                       if (v[i])
+                               printf("%d/%d: deduperange write - no filename\n",
+                                       procid, opno);
+                       goto out_pathnames;
+               }
+       }
+
+       /* Open files */
+       fd[0] = open_path(&fpath[0], O_RDONLY);
+       e = fd[0] < 0 ? errno : 0;
+       check_cwd();
+       if (fd[0] < 0) {
+               if (v[0])
+                       printf("%d/%d: deduperange read - open %s failed %d\n",
+                               procid, opno, fpath[0].path, e);
+               goto out_pathnames;
+       }
+
+       for (i = 1; i < nr; i++) {
+               fd[i] = open_path(&fpath[i], O_WRONLY);
+               e = fd[i] < 0 ? errno : 0;
+               check_cwd();
+               if (fd[i] < 0) {
+                       if (v[i])
+                               printf("%d/%d: deduperange write - open %s failed %d\n",
+                                       procid, opno, fpath[i].path, e);
+                       goto out_fds;
+               }
+       }
+
+       /* Get file stats */
+       if (fstat64(fd[0], &stat[0]) < 0) {
+               if (v[0])
+                       printf("%d/%d: deduperange read - fstat64 %s failed %d\n",
+                               procid, opno, fpath[0].path, errno);
+               goto out_fds;
+       }
+
+       inode_info(&info[0], INFO_SZ, &stat[0], v[0]);
+
+       for (i = 1; i < nr; i++) {
+               if (fstat64(fd[i], &stat[i]) < 0) {
+                       if (v[i])
+                               printf("%d/%d: deduperange write - fstat64 %s failed %d\n",
+                                       procid, opno, fpath[i].path, errno);
+                       goto out_fds;
+               }
+               inode_info(&info[i * INFO_SZ], INFO_SZ, &stat[i], v[i]);
+       }
+
+       /* Never try to dedupe more than half of the src file. */
+       len = (random() % FILELEN_MAX) + 1;
+       len &= ~(stat[0].st_blksize - 1);
+       if (len == 0)
+               len = stat[0].st_blksize / 2;
+       if (len > stat[0].st_size / 2)
+               len = stat[0].st_size / 2;
+
+       /* Calculate offsets */
+       lr = ((__int64_t)random() << 32) + random();
+       if (stat[0].st_size == len)
+               off[0] = 0;
+       else
+               off[0] = (off64_t)(lr % MIN(stat[0].st_size - len, MAXFSIZE));
+       off[0] %= maxfsize;
+       off[0] &= ~(stat[0].st_blksize - 1);
+
+       /*
+        * If srcfile == destfile[i], randomly generate destination ranges
+        * until we find one that doesn't overlap the source range.
+        */
+       for (i = 1; i < nr; i++) {
+               int     tries = 0;
+
+               do {
+                       lr = ((__int64_t)random() << 32) + random();
+                       if (stat[i].st_size <= len)
+                               off[i] = 0;
+                       else
+                               off[i] = (off64_t)(lr % MIN(stat[i].st_size - len, MAXFSIZE));
+                       off[i] %= maxfsize;
+                       off[i] &= ~(stat[i].st_blksize - 1);
+               } while (stat[0].st_ino == stat[i].st_ino &&
+                        llabs(off[i] - off[0]) < len &&
+                        tries++ < 10);
+       }
+
+       /* Clone data blocks */
+       fdr->src_offset = off[0];
+       fdr->src_length = len;
+       fdr->dest_count = nr - 1;
+       for (i = 1; i < nr; i++) {
+               fdr->info[i - 1].dest_fd = fd[i];
+               fdr->info[i - 1].dest_offset = off[i];
+       }
+
+       ret = ioctl(fd[0], FIDEDUPERANGE, fdr);
+       e = ret < 0 ? errno : 0;
+       if (v[0]) {
+               printf("%d/%d: deduperange from %s%s [%lld,%lld]",
+                       procid, opno,
+                       fpath[0].path, &info[0], (long long)off[0],
+                       (long long)len);
+               if (ret < 0)
+                       printf(" error %d", e);
+               printf("\n");
+       }
+       if (ret < 0)
+               goto out_fds;
+
+       for (i = 1; i < nr; i++) {
+               e = fdr->info[i - 1].status < 0 ? fdr->info[i - 1].status : 0;
+               if (v[i]) {
+                       printf("%d/%d: ...to %s%s [%lld,%lld]",
+                               procid, opno,
+                               fpath[i].path, &info[i * INFO_SZ],
+                               (long long)off[i], (long long)len);
+                       if (fdr->info[i - 1].status < 0)
+                               printf(" error %d", e);
+                       if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_SAME)
+                               printf(" %llu bytes deduplicated",
+                                       fdr->info[i - 1].bytes_deduped);
+                       if (fdr->info[i - 1].status == FILE_DEDUPE_RANGE_DIFFERS)
+                               printf(" differed");
+                       printf("\n");
+               }
+       }
+
+out_fds:
+       for (i = 0; i < nr; i++)
+               if (fd[i] >= 0)
+                       close(fd[i]);
+out_pathnames:
+       for (i = 0; i < nr; i++)
+               free_pathname(&fpath[i]);
+
+       free(fd);
+out_v:
+       free(v);
+out_offsets:
+       free(off);
+out_info:
+       free(info);
+out_stats:
+       free(stat);
+out_paths:
+       free(fpath);
+out_fdr:
+       free(fdr);
+#endif
+}
+
+void
+setxattr_f(int opno, long r)
+{
+#ifdef XFS_XFLAG_EXTSIZE
+       struct fsxattr  fsx;
+       int             fd;
+       int             e;
+       pathname_t      f;
+       int             nbits;
+       uint            p;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+
+       /* project ID */
+       p = (uint)random();
+       e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
+       nbits = (int)(random() % e);
+       p &= (1 << nbits) - 1;
+
+       if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
+               fsx.fsx_projid = p;
+               e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
+       }
+       if (v)
                printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e);
        free_pathname(&f);
        close(fd);
@@ -1779,6 +2713,8 @@ dread_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
+       char            *dio_env;
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1800,15 +2736,16 @@ dread_f(int opno, long r)
        if (fstat64(fd, &stb) < 0) {
                if (v)
                        printf("%d/%d: dread - fstat64 %s failed %d\n",
-                               procid, opno, f.path, errno);
+                              procid, opno, f.path, errno);
                free_pathname(&f);
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        if (stb.st_size == 0) {
                if (v)
-                       printf("%d/%d: dread - %s zero size\n", procid, opno,
-                               f.path);
+                       printf("%d/%d: dread - %s%s zero size\n", procid, opno,
+                              f.path, st);
                free_pathname(&f);
                close(fd);
                return;
@@ -1816,12 +2753,17 @@ dread_f(int opno, long r)
        if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
                if (v)
                        printf(
-                       "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s failed %d\n",
-                               procid, opno, f.path, errno);
-               free_pathname(&f);
-               close(fd);
-               return;
+                       "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
+                       " fallback to stat()\n",
+                               procid, opno, f.path, st, errno);
+               diob.d_mem = diob.d_miniosz = stb.st_blksize;
+               diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
        }
+
+       dio_env = getenv("XFS_DIO_MIN");
+       if (dio_env)
+               diob.d_mem = diob.d_miniosz = atoi(dio_env);
+
        align = (__int64_t)diob.d_miniosz;
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % stb.st_size);
@@ -1837,8 +2779,8 @@ dread_f(int opno, long r)
        e = read(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: dread %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: dread %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
        free_pathname(&f);
        close(fd);
 }
@@ -1857,6 +2799,8 @@ dwrite_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
+       char            *dio_env;
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1883,15 +2827,20 @@ dwrite_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
                if (v)
                        printf("%d/%d: dwrite - xfsctl(XFS_IOC_DIOINFO)"
-                               " %s failed %d\n",
-                               procid, opno, f.path, errno);
-               free_pathname(&f);
-               close(fd);
-               return;
+                               " %s%s return %d, fallback to stat()\n",
+                              procid, opno, f.path, st, errno);
+               diob.d_mem = diob.d_miniosz = stb.st_blksize;
+               diob.d_maxiosz = INT_MAX & ~(diob.d_miniosz - 1);
        }
+
+       dio_env = getenv("XFS_DIO_MIN");
+       if (dio_env)
+               diob.d_mem = diob.d_miniosz = atoi(dio_env);
+
        align = (__int64_t)diob.d_miniosz;
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
@@ -1910,10 +2859,97 @@ dwrite_f(int opno, long r)
        e = write(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: dwrite %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: dwrite %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
+       free_pathname(&f);
+       close(fd);
+}
+
+
+#ifdef HAVE_LINUX_FALLOC_H
+struct print_flags falloc_flags [] = {
+       { FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"},
+       { FALLOC_FL_PUNCH_HOLE, "PUNCH_HOLE"},
+       { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"},
+       { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
+       { FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
+       { FALLOC_FL_INSERT_RANGE, "INSERT_RANGE"},
+       { -1, NULL}
+};
+
+#define translate_falloc_flags(mode)   \
+       ({translate_flags(mode, "|", falloc_flags);})
+#endif
+
+void
+do_fallocate(int opno, long r, int mode)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       int             e;
+       pathname_t      f;
+       int             fd;
+       __int64_t       lr;
+       off64_t         off;
+       off64_t         len;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: do_fallocate - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_RDWR);
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: do_fallocate - open %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               return;
+       }
+       check_cwd();
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: do_fallocate - fstat64 %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       lr = ((__int64_t)random() << 32) + random();
+       off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+       off %= maxfsize;
+       len = (off64_t)(random() % (1024 * 1024));
+       /*
+        * Collapse/insert range requires off and len to be block aligned,
+        * make it more likely to be the case.
+        */
+       if ((mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)) &&
+               (opno % 2)) {
+               off = ((off + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
+               len = ((len + stb.st_blksize - 1) & ~(stb.st_blksize - 1));
+       }
+       mode |= FALLOC_FL_KEEP_SIZE & random();
+       e = fallocate(fd, mode, (loff_t)off, (loff_t)len) < 0 ? errno : 0;
+       if (v)
+               printf("%d/%d: fallocate(%s) %s %st %lld %lld %d\n",
+                      procid, opno, translate_falloc_flags(mode),
+                      f.path, st, (long long)off, (long long)len, e);
        free_pathname(&f);
        close(fd);
+#endif
+}
+
+void
+fallocate_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, 0);
+#endif
 }
 
 void
@@ -1949,6 +2985,89 @@ fdatasync_f(int opno, long r)
        close(fd);
 }
 
+#ifdef HAVE_LINUX_FIEMAP_H
+struct print_flags fiemap_flags[] = {
+       { FIEMAP_FLAG_SYNC, "SYNC"},
+       { FIEMAP_FLAG_XATTR, "XATTR"},
+       { -1, NULL}
+};
+
+#define translate_fiemap_flags(mode)   \
+       ({translate_flags(mode, "|", fiemap_flags);})
+#endif
+
+void
+fiemap_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FIEMAP_H
+       int             e;
+       pathname_t      f;
+       int             fd;
+       __int64_t       lr;
+       off64_t         off;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+       int blocks_to_map;
+       struct fiemap *fiemap;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: fiemap - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: fiemap - open %s failed %d\n",
+                               procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: fiemap - fstat64 %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       blocks_to_map = random() & 0xffff;
+       fiemap = (struct fiemap *)malloc(sizeof(struct fiemap) +
+                       (blocks_to_map * sizeof(struct fiemap_extent)));
+       if (!fiemap) {
+               if (v)
+                       printf("%d/%d: malloc failed \n", procid, opno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       lr = ((__int64_t)random() << 32) + random();
+       off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+       off %= maxfsize;
+       fiemap->fm_flags = random() & (FIEMAP_FLAGS_COMPAT | 0x10000);
+       fiemap->fm_extent_count = blocks_to_map;
+       fiemap->fm_mapped_extents = random() & 0xffff;
+       fiemap->fm_start = off;
+       fiemap->fm_length = ((__int64_t)random() << 32) + random();
+
+       e = ioctl(fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
+       if (v)
+               printf("%d/%d: ioctl(FIEMAP) %s%s %lld %lld (%s) %d\n",
+                      procid, opno, f.path, st, (long long)fiemap->fm_start,
+                      (long long) fiemap->fm_length,
+                      translate_fiemap_flags(fiemap->fm_flags), e);
+       free(fiemap);
+       free_pathname(&f);
+       close(fd);
+#endif
+}
+
 void
 freesp_f(int opno, long r)
 {
@@ -1960,6 +3079,7 @@ freesp_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1986,6 +3106,7 @@ freesp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -1994,8 +3115,8 @@ freesp_f(int opno, long r)
        fl.l_len = 0;
        e = xfsctl(f.path, fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
        if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_FREESP64) %s %lld 0 %d\n",
-                       procid, opno, f.path, (long long)off, e);
+               printf("%d/%d: xfsctl(XFS_IOC_FREESP64) %s%s %lld 0 %d\n",
+                      procid, opno, f.path, st, (long long)off, e);
        free_pathname(&f);
        close(fd);
 }
@@ -2032,6 +3153,29 @@ fsync_f(int opno, long r)
        close(fd);
 }
 
+void
+getattr_f(int opno, long r)
+{
+       int             fd;
+       int             e;
+       pathname_t      f;
+       uint            fl;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+
+       e = ioctl(fd, FS_IOC_GETFLAGS, &fl);
+       if (v)
+               printf("%d/%d: getattr %s %u %d\n", procid, opno, f.path, fl, e);
+       free_pathname(&f);
+       close(fd);
+}
+
 void
 getdents_f(int opno, long r)
 {
@@ -2186,6 +3330,163 @@ mknod_f(int opno, long r)
        free_pathname(&f);
 }
 
+#ifdef HAVE_SYS_MMAN_H
+struct print_flags mmap_flags[] = {
+       { MAP_SHARED, "SHARED"},
+       { MAP_PRIVATE, "PRIVATE"},
+       { -1, NULL}
+};
+
+#define translate_mmap_flags(flags)      \
+       ({translate_flags(flags, "|", mmap_flags);})
+#endif
+
+void
+do_mmap(int opno, long r, int prot)
+{
+#ifdef HAVE_SYS_MMAN_H
+       char            *addr;
+       int             e;
+       pathname_t      f;
+       int             fd;
+       size_t          len;
+       __int64_t       lr;
+       off64_t         off;
+       int             flags;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+       sigjmp_buf      sigbus_jmpbuf;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: do_mmap - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: do_mmap - open %s failed %d\n",
+                              procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: do_mmap - fstat64 %s failed %d\n",
+                              procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       if (stb.st_size == 0) {
+               if (v)
+                       printf("%d/%d: do_mmap - %s%s zero size\n", procid, opno,
+                              f.path, st);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+
+       lr = ((__int64_t)random() << 32) + random();
+       off = (off64_t)(lr % stb.st_size);
+       off &= (off64_t)(~(sysconf(_SC_PAGE_SIZE) - 1));
+       len = (size_t)(random() % MIN(stb.st_size - off, FILELEN_MAX)) + 1;
+
+       flags = (random() % 2) ? MAP_SHARED : MAP_PRIVATE;
+       addr = mmap(NULL, len, prot, flags, fd, off);
+       e = (addr == MAP_FAILED) ? errno : 0;
+       if (e) {
+               if (v)
+                       printf("%d/%d: do_mmap - mmap failed %s%s [%lld,%d,%s] %d\n",
+                              procid, opno, f.path, st, (long long)off,
+                              (int)len, translate_mmap_flags(flags), e);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+
+       if (prot & PROT_WRITE) {
+               if ((e = sigsetjmp(sigbus_jmpbuf, 1)) == 0) {
+                       sigbus_jmp = &sigbus_jmpbuf;
+                       memset(addr, nameseq & 0xff, len);
+               }
+       } else {
+               char *buf;
+               if ((buf = malloc(len)) != NULL) {
+                       memcpy(buf, addr, len);
+                       free(buf);
+               }
+       }
+       munmap(addr, len);
+       /* set NULL to stop other functions from doing siglongjmp */
+       sigbus_jmp = NULL;
+
+       if (v)
+               printf("%d/%d: %s %s%s [%lld,%d,%s] %s\n",
+                      procid, opno, (prot & PROT_WRITE) ? "mwrite" : "mread",
+                      f.path, st, (long long)off, (int)len,
+                      translate_mmap_flags(flags),
+                      (e == 0) ? "0" : "Bus error");
+
+       free_pathname(&f);
+       close(fd);
+#endif
+}
+
+void
+mread_f(int opno, long r)
+{
+#ifdef HAVE_SYS_MMAN_H
+       do_mmap(opno, r, PROT_READ);
+#endif
+}
+
+void
+mwrite_f(int opno, long r)
+{
+#ifdef HAVE_SYS_MMAN_H
+       do_mmap(opno, r, PROT_WRITE);
+#endif
+}
+
+void
+punch_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, FALLOC_FL_PUNCH_HOLE);
+#endif
+}
+
+void
+zero_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, FALLOC_FL_ZERO_RANGE);
+#endif
+}
+
+void
+collapse_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, FALLOC_FL_COLLAPSE_RANGE);
+#endif
+}
+
+void
+insert_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, FALLOC_FL_INSERT_RANGE);
+#endif
+}
+
 void
 read_f(int opno, long r)
 {
@@ -2198,6 +3499,7 @@ read_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2224,10 +3526,11 @@ read_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        if (stb.st_size == 0) {
                if (v)
-                       printf("%d/%d: read - %s zero size\n", procid, opno,
-                               f.path);
+                       printf("%d/%d: read - %s%s zero size\n", procid, opno,
+                              f.path, st);
                free_pathname(&f);
                close(fd);
                return;
@@ -2240,8 +3543,8 @@ read_f(int opno, long r)
        e = read(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: read %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: read %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
        free_pathname(&f);
        close(fd);
 }
@@ -2268,6 +3571,85 @@ readlink_f(int opno, long r)
        free_pathname(&f);
 }
 
+void
+readv_f(int opno, long r)
+{
+       char            *buf;
+       int             e;
+       pathname_t      f;
+       int             fd;
+       size_t          len;
+       __int64_t       lr;
+       off64_t         off;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+       struct iovec    *iov = NULL;
+       int             iovcnt;
+       size_t          iovb;
+       size_t          iovl;
+       int             i;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: readv - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_RDONLY);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: readv - open %s failed %d\n",
+                               procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: readv - fstat64 %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       if (stb.st_size == 0) {
+               if (v)
+                       printf("%d/%d: readv - %s%s zero size\n", procid, opno,
+                              f.path, st);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       lr = ((__int64_t)random() << 32) + random();
+       off = (off64_t)(lr % stb.st_size);
+       lseek64(fd, off, SEEK_SET);
+       len = (random() % FILELEN_MAX) + 1;
+       buf = malloc(len);
+
+       iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
+       iov = calloc(iovcnt, sizeof(struct iovec));
+       iovl = len / iovcnt;
+       iovb = 0;
+       for (i=0; i<iovcnt; i++) {
+               (iov + i)->iov_base = (buf + iovb);
+               (iov + i)->iov_len  = iovl;
+               iovb += iovl;
+       }
+
+       e = readv(fd, iov, iovcnt) < 0 ? errno : 0;
+       free(buf);
+       if (v)
+               printf("%d/%d: readv %s%s [%lld,%d,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)iovl,
+                      iovcnt, e);
+       free_pathname(&f);
+       close(fd);
+}
+
 void
 rename_f(int opno, long r)
 {
@@ -2348,6 +3730,7 @@ resvsp_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2374,6 +3757,7 @@ resvsp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -2382,8 +3766,8 @@ resvsp_f(int opno, long r)
        fl.l_len = (off64_t)(random() % (1024 * 1024));
        e = xfsctl(f.path, fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
        if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_RESVSP64) %s %lld %lld %d\n",
-                       procid, opno, f.path,
+               printf("%d/%d: xfsctl(XFS_IOC_RESVSP64) %s%s %lld %lld %d\n",
+                      procid, opno, f.path, st,
                        (long long)off, (long long)fl.l_len, e);
        free_pathname(&f);
        close(fd);
@@ -2417,6 +3801,30 @@ rmdir_f(int opno, long r)
        free_pathname(&f);
 }
 
+void
+setattr_f(int opno, long r)
+{
+       int             fd;
+       int             e;
+       pathname_t      f;
+       uint            fl;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+
+       fl = attr_mask & (uint)random();
+       e = ioctl(fd, FS_IOC_SETFLAGS, &fl);
+       if (v)
+               printf("%d/%d: setattr %s %x %d\n", procid, opno, f.path, fl, e);
+       free_pathname(&f);
+       close(fd);
+}
+
 void
 stat_f(int opno, long r)
 {
@@ -2506,6 +3914,7 @@ truncate_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2523,14 +3932,15 @@ truncate_f(int opno, long r)
                free_pathname(&f);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        e = truncate64_path(&f, off) < 0 ? errno : 0;
        check_cwd();
        if (v)
-               printf("%d/%d: truncate %s %lld %d\n", procid, opno, f.path,
-                       (long long)off, e);
+               printf("%d/%d: truncate %s%s %lld %d\n", procid, opno, f.path,
+                      st, (long long)off, e);
        free_pathname(&f);
 }
 
@@ -2574,6 +3984,7 @@ unresvsp_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2600,6 +4011,7 @@ unresvsp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -2608,8 +4020,8 @@ unresvsp_f(int opno, long r)
        fl.l_len = (off64_t)(random() % (1 << 20));
        e = xfsctl(f.path, fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
        if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_UNRESVSP64) %s %lld %lld %d\n",
-                       procid, opno, f.path,
+               printf("%d/%d: xfsctl(XFS_IOC_UNRESVSP64) %s%s %lld %lld %d\n",
+                      procid, opno, f.path, st,
                        (long long)off, (long long)fl.l_len, e);
        free_pathname(&f);
        close(fd);
@@ -2627,6 +4039,7 @@ write_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
@@ -2653,6 +4066,7 @@ write_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -2663,8 +4077,82 @@ write_f(int opno, long r)
        e = write(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: write %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: write %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
+       free_pathname(&f);
+       close(fd);
+}
+
+void
+writev_f(int opno, long r)
+{
+       char            *buf;
+       int             e;
+       pathname_t      f;
+       int             fd;
+       size_t          len;
+       __int64_t       lr;
+       off64_t         off;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+       struct iovec    *iov = NULL;
+       int             iovcnt;
+       size_t          iovb;
+       size_t          iovl;
+       int             i;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: writev - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_WRONLY);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: writev - open %s failed %d\n",
+                               procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: writev - fstat64 %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       lr = ((__int64_t)random() << 32) + random();
+       off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+       off %= maxfsize;
+       lseek64(fd, off, SEEK_SET);
+       len = (random() % FILELEN_MAX) + 1;
+       buf = malloc(len);
+       memset(buf, nameseq & 0xff, len);
+
+       iovcnt = (random() % MIN(len, IOV_MAX)) + 1;
+       iov = calloc(iovcnt, sizeof(struct iovec));
+       iovl = len / iovcnt;
+       iovb = 0;
+       for (i=0; i<iovcnt; i++) {
+               (iov + i)->iov_base = (buf + iovb);
+               (iov + i)->iov_len  = iovl;
+               iovb += iovl;
+       }
+
+       e = writev(fd, iov, iovcnt) < 0 ? errno : 0;
+       free(buf);
+       free(iov);
+       if (v)
+               printf("%d/%d: writev %s%s [%lld,%d,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)iovl,
+                      iovcnt, e);
        free_pathname(&f);
        close(fd);
 }