btrfs: add test for zone auto reclaim
[xfstests-dev.git] / ltp / fsstress.c
index 7e7cf608f5f389b8167ffdb4b12c29765f505940..e7cd0eae304d521af4cee5bf8e17497f5cdfd3c0 100644 (file)
@@ -1,39 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2002 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * 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 <stdbool.h>
 #include "global.h"
 
-#ifdef HAVE_ATTR_XATTR_H
-#include <attr/xattr.h>
-#endif
-#ifdef HAVE_ATTR_ATTRIBUTES_H
-#include <attr/attributes.h>
+#ifdef HAVE_BTRFSUTIL_H
+#include <btrfsutil.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>
+#define AIO_ENTRIES    1
+io_context_t   io_ctx;
+#endif
+#ifdef URING
+#include <liburing.h>
+#define URING_ENTRIES  1
+struct io_uring        ring;
+bool have_io_uring;                    /* to indicate runtime availability */
+#endif
+#include <sys/syscall.h>
+#include <sys/xattr.h>
 
 #ifndef FS_IOC_GETFLAGS
 #define FS_IOC_GETFLAGS                 _IOR('f', 1, long)
 #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
+
+#ifndef HAVE_RENAMEAT2
+#if !defined(SYS_renameat2) && defined(__x86_64__)
+#define SYS_renameat2 316
+#endif
+
+#if !defined(SYS_renameat2) && defined(__i386__)
+#define SYS_renameat2 353
+#endif
+
+static int renameat2(int dfd1, const char *path1,
+                    int dfd2, const char *path2,
+                    unsigned int flags)
+{
+#ifdef SYS_renameat2
+       return syscall(SYS_renameat2, dfd1, path1, dfd2, path2, flags);
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+#endif
+
+#ifndef RENAME_NOREPLACE
+#define RENAME_NOREPLACE       (1 << 0)        /* Don't overwrite target */
+#endif
+#ifndef RENAME_EXCHANGE
+#define RENAME_EXCHANGE                (1 << 1)        /* Exchange source and dest */
+#endif
+#ifndef RENAME_WHITEOUT
+#define RENAME_WHITEOUT                (1 << 2)        /* Whiteout source */
+#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_COPYRANGE,
        OP_CREAT,
+       OP_DEDUPERANGE,
        OP_DREAD,
        OP_DWRITE,
        OP_FALLOCATE,
@@ -66,27 +106,44 @@ typedef enum {
        OP_FSYNC,
        OP_GETATTR,
        OP_GETDENTS,
+       OP_GETFATTR,
        OP_LINK,
+       OP_LISTFATTR,
        OP_MKDIR,
        OP_MKNOD,
+       OP_MREAD,
+       OP_MWRITE,
        OP_PUNCH,
        OP_ZERO,
        OP_COLLAPSE,
        OP_INSERT,
        OP_READ,
        OP_READLINK,
+       OP_READV,
+       OP_REMOVEFATTR,
        OP_RENAME,
+       OP_RNOREPLACE,
+       OP_REXCHANGE,
+       OP_RWHITEOUT,
        OP_RESVSP,
        OP_RMDIR,
        OP_SETATTR,
+       OP_SETFATTR,
        OP_SETXATTR,
+       OP_SNAPSHOT,
+       OP_SPLICE,
        OP_STAT,
+       OP_SUBVOL_CREATE,
+       OP_SUBVOL_DELETE,
        OP_SYMLINK,
        OP_SYNC,
        OP_TRUNCATE,
        OP_UNLINK,
        OP_UNRESVSP,
+       OP_URING_READ,
+       OP_URING_WRITE,
        OP_WRITE,
+       OP_WRITEV,
        OP_LAST
 } opty_t;
 
@@ -102,7 +159,9 @@ typedef struct opdesc {
 
 typedef struct fent {
        int     id;
+       int     ft;
        int     parent;
+       int     xattr_counter;
 } fent_t;
 
 typedef struct flist {
@@ -128,20 +187,23 @@ struct print_string {
        int max;
 };
 
-#define        FT_DIR  0
-#define        FT_DIRm (1 << FT_DIR)
-#define        FT_REG  1
-#define        FT_REGm (1 << FT_REG)
-#define        FT_SYM  2
-#define        FT_SYMm (1 << FT_SYM)
-#define        FT_DEV  3
-#define        FT_DEVm (1 << FT_DEV)
-#define        FT_RTF  4
-#define        FT_RTFm (1 << FT_RTF)
-#define        FT_nft  5
-#define        FT_ANYm ((1 << FT_nft) - 1)
+#define        FT_DIR          0
+#define        FT_DIRm         (1 << FT_DIR)
+#define        FT_REG          1
+#define        FT_REGm         (1 << FT_REG)
+#define        FT_SYM          2
+#define        FT_SYMm         (1 << FT_SYM)
+#define        FT_DEV          3
+#define        FT_DEVm         (1 << FT_DEV)
+#define        FT_RTF          4
+#define        FT_RTFm         (1 << FT_RTF)
+#define        FT_SUBVOL       5
+#define        FT_SUBVOLm      (1 << FT_SUBVOL)
+#define        FT_nft          6
+#define        FT_ANYm         ((1 << FT_nft) - 1)
 #define        FT_REGFILE      (FT_REGm | FT_RTFm)
-#define        FT_NOTDIR       (FT_ANYm & ~FT_DIRm)
+#define        FT_NOTDIR       (FT_ANYm & (~FT_DIRm & ~FT_SUBVOLm))
+#define        FT_ANYDIR       (FT_DIRm | FT_SUBVOLm)
 
 #define        FLIST_SLOT_INCR 16
 #define        NDCACHE 64
@@ -149,13 +211,21 @@ struct print_string {
 #define        MAXFSIZE        ((1ULL << 63) - 1ULL)
 #define        MAXFSIZE32      ((1ULL << 40) - 1ULL)
 
+#define XATTR_NAME_BUF_SIZE 18
+
+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   copyrange_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);
@@ -163,39 +233,64 @@ void      fdatasync_f(int, long);
 void   fiemap_f(int, long);
 void   freesp_f(int, long);
 void   fsync_f(int, long);
+char   *gen_random_string(int);
 void   getattr_f(int, long);
 void   getdents_f(int, long);
+void   getfattr_f(int, long);
 void   link_f(int, long);
+void   listfattr_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   removefattr_f(int, long);
 void   rename_f(int, long);
+void   rnoreplace_f(int, long);
+void   rexchange_f(int, long);
+void   rwhiteout_f(int, long);
 void   resvsp_f(int, long);
 void   rmdir_f(int, long);
 void   setattr_f(int, long);
+void   setfattr_f(int, long);
 void   setxattr_f(int, long);
+void   snapshot_f(int, long);
+void   splice_f(int, long);
 void   stat_f(int, long);
+void   subvol_create_f(int, long);
+void   subvol_delete_f(int, long);
 void   symlink_f(int, long);
 void   sync_f(int, long);
 void   truncate_f(int, long);
 void   unlink_f(int, long);
 void   unresvsp_f(int, long);
+void   uring_read_f(int, long);
+void   uring_write_f(int, long);
 void   write_f(int, long);
+void   writev_f(int, long);
+char   *xattr_flag_to_string(int);
 
 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_COPYRANGE, "copyrange", copyrange_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 },
@@ -205,27 +300,50 @@ opdesc_t  ops[] = {
        { OP_FSYNC, "fsync", fsync_f, 1, 1 },
        { OP_GETATTR, "getattr", getattr_f, 1, 0 },
        { OP_GETDENTS, "getdents", getdents_f, 1, 0 },
+       /* get extended attribute */
+       { OP_GETFATTR, "getfattr", getfattr_f, 1, 0 },
        { OP_LINK, "link", link_f, 1, 1 },
+       /* list extent attributes */
+       { OP_LISTFATTR, "listfattr", listfattr_f, 1, 0 },
        { 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 },
+       /* remove (delete) extended attribute */
+       { OP_REMOVEFATTR, "removefattr", removefattr_f, 1, 1 },
        { OP_RENAME, "rename", rename_f, 2, 1 },
+       { OP_RNOREPLACE, "rnoreplace", rnoreplace_f, 2, 1 },
+       { OP_REXCHANGE, "rexchange", rexchange_f, 2, 1 },
+       { OP_RWHITEOUT, "rwhiteout", rwhiteout_f, 2, 1 },
        { OP_RESVSP, "resvsp", resvsp_f, 1, 1 },
        { OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
+       /* set attribute flag (FS_IOC_SETFLAGS ioctl) */
        { OP_SETATTR, "setattr", setattr_f, 0, 1 },
+       /* set extended attribute */
+       { OP_SETFATTR, "setfattr", setfattr_f, 2, 1 },
+       /* set project id (XFS_IOC_FSSETXATTR ioctl) */
        { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
+       { OP_SNAPSHOT, "snapshot", snapshot_f, 1, 1 },
+       { OP_SPLICE, "splice", splice_f, 1, 1 },
        { OP_STAT, "stat", stat_f, 1, 0 },
+       { OP_SUBVOL_CREATE, "subvol_create", subvol_create_f, 1, 1},
+       { OP_SUBVOL_DELETE, "subvol_delete", subvol_delete_f, 1, 1},
        { OP_SYMLINK, "symlink", symlink_f, 2, 1 },
        { 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_URING_READ, "uring_read", uring_read_f, 1, 0 },
+       { OP_URING_WRITE, "uring_write", uring_write_f, 1, 1 },
        { OP_WRITE, "write", write_f, 4, 1 },
+       { OP_WRITEV, "writev", writev_f, 4, 1 },
 }, *ops_end;
 
 flist_t        flist[FT_nft] = {
@@ -234,6 +352,7 @@ flist_t     flist[FT_nft] = {
        { 0, 0, 'l', NULL },
        { 0, 0, 'c', NULL },
        { 0, 0, 'r', NULL },
+       { 0, 0, 's', NULL },
 };
 
 int            dcache[NDCACHE];
@@ -241,7 +360,7 @@ int         errrange;
 int            errtag;
 opty_t         *freq_table;
 int            freq_table_size;
-xfs_fsop_geom_t        geom;
+struct xfs_fsop_geom   geom;
 char           *homedir;
 int            *ilist;
 int            ilistlen;
@@ -262,28 +381,32 @@ 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   add_to_flist(int, int, int, int);
 void   append_pathname(pathname_t *, char *);
-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);
+int    attr_list_path(pathname_t *, char *, const int);
+int    attr_remove_path(pathname_t *, const char *);
+int    attr_set_path(pathname_t *, const char *, const char *, const 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);
 fent_t *dcache_lookup(int);
-void   dcache_purge(int);
+void   dcache_purge(int, int);
 void   del_from_flist(int, int);
 int    dirid_to_name(char *, int);
 void   doproc(void);
-int    fent_to_name(pathname_t *, flist_t *, fent_t *);
-void   fix_parent(int, int);
+int    fent_to_name(pathname_t *, fent_t *);
+bool   fents_ancestor_check(fent_t *, fent_t *);
+void   fix_parent(int, int, bool);
 void   free_pathname(pathname_t *);
 int    generate_fname(fent_t *, int, pathname_t *, int *, int *);
+int    generate_xattr_name(int, char *, int);
 int    get_fname(int, long, pathname_t *, flist_t **, fent_t **, int *);
 void   init_pathname(pathname_t *);
 int    lchown_path(pathname_t *, uid_t, gid_t);
@@ -293,11 +416,12 @@ void      make_freq_table(void);
 int    mkdir_path(pathname_t *, mode_t);
 int    mknod_path(pathname_t *, mode_t, dev_t);
 void   namerandpad(int, char *, int);
+int    open_file_or_dir(pathname_t *, int);
 int    open_path(pathname_t *, int);
 DIR    *opendir_path(pathname_t *);
 void   process_freq(char *);
 int    readlink_path(pathname_t *, char *, size_t);
-int    rename_path(pathname_t *, pathname_t *);
+int    rename_path(pathname_t *, pathname_t *, int);
 int    rmdir_path(pathname_t *);
 void   separate_pathname(pathname_t *, char *, pathname_t *);
 void   show_ops(int, char *);
@@ -308,10 +432,30 @@ int       unlink_path(pathname_t *);
 void   usage(void);
 void   write_freq(void);
 void   zero_freq(void);
+void   non_btrfs_freq(const char *);
 
 void sg_handler(int signum)
 {
-       should_stop = 1;
+       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)
@@ -442,9 +586,10 @@ int main(int argc, char **argv)
             exit(1);
         }
 
+       non_btrfs_freq(dirname);
        (void)mkdir(dirname, 0777);
        if (logname && logname[0] != '/') {
-               if (getcwd(rpath, sizeof(rpath)) < 0){
+               if (!getcwd(rpath, sizeof(rpath))){
                        perror("getcwd failed");
                        exit(1);
                }
@@ -456,7 +601,7 @@ int main(int argc, char **argv)
                exit(1);
        }
        if (logname) {
-               char path[PATH_MAX];
+               char path[PATH_MAX + NAME_MAX + 1];
                snprintf(path, sizeof(path), "%s/%s", rpath, logname);
                if (freopen(path, "a", stdout) == NULL) {
                        perror("freopen logfile failed");
@@ -527,17 +672,20 @@ int main(int argc, char **argv)
 
        for (i = 0; i < nproc; i++) {
                if (fork() == 0) {
-                       action.sa_handler = SIG_DFL;
                        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];
+                               char path[PATH_MAX + NAME_MAX + 2 + 11];
                                snprintf(path, sizeof(path), "%s/%s.%d",
                                         rpath, logname, i);
                                if (freopen(path, "a", stdout) == NULL) {
@@ -546,8 +694,38 @@ int main(int argc, char **argv)
                                }
                        }
                        procid = i;
+#ifdef AIO
+                       if (io_setup(AIO_ENTRIES, &io_ctx) != 0) {
+                               fprintf(stderr, "io_setup failed\n");
+                               exit(1);
+                       }
+#endif
+#ifdef URING
+                       have_io_uring = true;
+                       /* If ENOSYS, just ignore uring, other errors are fatal. */
+                       if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
+                               if (errno == ENOSYS) {
+                                       have_io_uring = false;
+                               } else {
+                                       fprintf(stderr, "io_uring_queue_init failed\n");
+                                       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
+#ifdef URING
+                       if (have_io_uring)
+                               io_uring_queue_exit(&ring);
+#endif
+                       cleanup_flist();
+                       free(freq_table);
                        return 0;
                }
        }
@@ -574,6 +752,7 @@ int main(int argc, char **argv)
                close(fd);
        }
 
+       free(freq_table);
        unlink(buf);
        return 0;
 }
@@ -646,7 +825,7 @@ translate_flags(int flags, const char *delim,
 }
 
 void
-add_to_flist(int ft, int id, int parent)
+add_to_flist(int ft, int id, int parent, int xattr_counter)
 {
        fent_t  *fep;
        flist_t *ftp;
@@ -658,7 +837,9 @@ add_to_flist(int ft, int id, int parent)
        }
        fep = &ftp->fents[ftp->nfiles++];
        fep->id = id;
+       fep->ft = ft;
        fep->parent = parent;
+       fep->xattr_counter = xattr_counter;
 }
 
 void
@@ -671,7 +852,7 @@ append_pathname(pathname_t *name, char *str)
        /* attempting to append to a dir a zero length path */
        if (len && *str == '/' && name->len == 0) {
                fprintf(stderr, "fsstress: append_pathname failure\n");
-               chdir(homedir);
+               assert(chdir(homedir) == 0);
                abort();
                /* NOTREACHED */
        }
@@ -681,48 +862,56 @@ append_pathname(pathname_t *name, char *str)
        name->len += len;
 }
 
+int
+attr_list_count(char *buffer, int buffersize)
+{
+       char *p = buffer;
+       char *end = buffer + buffersize;
+       int count = 0;
+
+       while (p < end && *p != 0) {
+               count++;
+               p += strlen(p) + 1;
+       }
+
+       return count;
+}
+
 int
 attr_list_path(pathname_t *name,
               char *buffer,
-              const int buffersize,
-              int flags,
-              attrlist_cursor_t *cursor)
+              const int buffersize)
 {
        char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
-       if (flags != ATTR_DONTFOLLOW) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       rval = attr_list(name->path, buffer, buffersize, flags, cursor);
+       rval = llistxattr(name->path, buffer, buffersize);
        if (rval >= 0 || errno != ENAMETOOLONG)
                return rval;
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
-               rval = attr_list_path(&newname, buffer, buffersize, flags, cursor);
-               chdir("..");
+               rval = attr_list_path(&newname, buffer, buffersize);
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
 }
 
 int
-attr_remove_path(pathname_t *name, const char *attrname, int flags)
+attr_remove_path(pathname_t *name, const char *attrname)
 {
        char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
-       rval = attr_remove(name->path, attrname, flags);
+       rval = lremovexattr(name->path, attrname);
        if (rval >= 0 || errno != ENAMETOOLONG)
                return rval;
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
-               rval = attr_remove_path(&newname, attrname, flags);
-               chdir("..");
+               rval = attr_remove_path(&newname, attrname);
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -730,20 +919,20 @@ attr_remove_path(pathname_t *name, const char *attrname, int flags)
 
 int
 attr_set_path(pathname_t *name, const char *attrname, const char *attrvalue,
-             const int valuelength, int flags)
+             const int valuelength)
 {
        char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
-       rval = attr_set(name->path, attrname, attrvalue, valuelength, flags);
+       rval = lsetxattr(name->path, attrname, attrvalue, valuelength, 0);
        if (rval >= 0 || errno != ENAMETOOLONG)
                return rval;
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
-               rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
-                       flags);
-               chdir("..");
+               rval = attr_set_path(&newname, attrname, attrvalue,
+                                    valuelength);
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -757,13 +946,32 @@ check_cwd(void)
 
        if (stat64(".", &statbuf) == 0 && statbuf.st_ino == top_ino)
                return;
-       chdir(homedir);
+       assert(chdir(homedir) == 0);
        fprintf(stderr, "fsstress: check_cwd failure\n");
        abort();
        /* NOTREACHED */
 #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)
 {
@@ -777,7 +985,7 @@ creat_path(pathname_t *name, mode_t mode)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = creat_path(&newname, mode);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -805,18 +1013,22 @@ dcache_lookup(int dirid)
        int     i;
 
        i = dcache[dirid % NDCACHE];
-       if (i >= 0 && (fep = &flist[FT_DIR].fents[i])->id == dirid)
+       if (i >= 0 && i < flist[FT_DIR].nfiles &&
+           (fep = &flist[FT_DIR].fents[i])->id == dirid)
+               return fep;
+       if (i >= 0 && i < flist[FT_SUBVOL].nfiles &&
+           (fep = &flist[FT_SUBVOL].fents[i])->id == dirid)
                return fep;
        return NULL;
 }
 
 void
-dcache_purge(int dirid)
+dcache_purge(int dirid, int ft)
 {
        int     *dcp;
-
        dcp = &dcache[dirid % NDCACHE];
-       if (*dcp >= 0 && flist[FT_DIR].fents[*dcp].id == dirid)
+       if (*dcp >= 0 && *dcp < flist[ft].nfiles &&
+           flist[ft].fents[*dcp].id == dirid)
                *dcp = -1;
 }
 
@@ -832,32 +1044,58 @@ del_from_flist(int ft, int slot)
        flist_t *ftp;
 
        ftp = &flist[ft];
-       if (ft == FT_DIR)
-               dcache_purge(ftp->fents[slot].id);
+       if (ft == FT_DIR || ft == FT_SUBVOL)
+               dcache_purge(ftp->fents[slot].id, ft);
        if (slot != ftp->nfiles - 1) {
-               if (ft == FT_DIR)
-                       dcache_purge(ftp->fents[ftp->nfiles - 1].id);
+               if (ft == FT_DIR || ft == FT_SUBVOL)
+                       dcache_purge(ftp->fents[ftp->nfiles - 1].id, ft);
                ftp->fents[slot] = ftp->fents[--ftp->nfiles];
        } else
                ftp->nfiles--;
 }
 
+void
+delete_subvol_children(int parid)
+{
+       flist_t *flp;
+       int     i;
+again:
+       for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
+               int c;
+               for (c = 0; c < flp->nfiles; c++) {
+                       if (flp->fents[c].parent == parid) {
+                               int id = flp->fents[c].id;
+                               del_from_flist(i, c);
+                               if (i == FT_DIR || i == FT_SUBVOL)
+                                       delete_subvol_children(id);
+                               goto again;
+                       }
+               }
+       }
+}
+
 fent_t *
 dirid_to_fent(int dirid)
 {
        fent_t  *efep;
        fent_t  *fep;
        flist_t *flp;
+       int     ft = FT_DIR;
 
        if ((fep = dcache_lookup(dirid)))
                return fep;
-       flp = &flist[FT_DIR];
+again:
+       flp = &flist[ft];
        for (fep = flp->fents, efep = &fep[flp->nfiles]; fep < efep; fep++) {
                if (fep->id == dirid) {
                        dcache_enter(dirid, fep - flp->fents);
                        return fep;
                }
        }
+       if (ft == FT_DIR) {
+               ft = FT_SUBVOL;
+               goto again;
+       }
        return NULL;
 }
 
@@ -880,7 +1118,11 @@ 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)
@@ -911,10 +1153,16 @@ doproc(void)
                }
        }
 errout:
-       chdir("..");
+       assert(chdir("..") == 0);
+       free(homedir);
        if (cleanup) {
+               int ret;
+
                sprintf(cmd, "rm -rf %s", buf);
-               system(cmd);
+               ret = system(cmd);
+               if (ret != 0)
+                       perror("cleaning up");
+               cleanup_flist();
        }
 }
 
@@ -924,8 +1172,9 @@ errout:
  * Return 0 on error, 1 on success;
  */
 int
-fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
+fent_to_name(pathname_t *name, fent_t *fep)
 {
+       flist_t *flp = &flist[fep->ft];
        char    buf[NAME_MAX + 1];
        int     i;
        fent_t  *pfep;
@@ -945,7 +1194,7 @@ fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
 #endif
                if (pfep == NULL)
                        return 0;
-               e = fent_to_name(name, &flist[FT_DIR], pfep);
+               e = fent_to_name(name, pfep);
                if (!e)
                        return 0;
                append_pathname(name, "/");
@@ -957,8 +1206,22 @@ fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
        return 1;
 }
 
+bool
+fents_ancestor_check(fent_t *fep, fent_t *dfep)
+{
+       fent_t  *tmpfep;
+
+       for (tmpfep = fep; tmpfep->parent != -1;
+            tmpfep = dirid_to_fent(tmpfep->parent)) {
+               if (tmpfep->parent == dfep->id)
+                       return true;
+       }
+
+       return false;
+}
+
 void
-fix_parent(int oldid, int newid)
+fix_parent(int oldid, int newid, bool swap)
 {
        fent_t  *fep;
        flist_t *flp;
@@ -969,6 +1232,8 @@ fix_parent(int oldid, int newid)
                for (j = 0, fep = flp->fents; j < flp->nfiles; j++, fep++) {
                        if (fep->parent == oldid)
                                fep->parent = newid;
+                       else if (swap && fep->parent == newid)
+                               fep->parent = oldid;
                }
        }
 }
@@ -1005,7 +1270,7 @@ generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
 
        /* prepend fep parent dir-name to it */
        if (fep) {
-               e = fent_to_name(name, &flist[FT_DIR], fep);
+               e = fent_to_name(name, fep);
                if (!e)
                        return 0;
                append_pathname(name, "/");
@@ -1023,6 +1288,18 @@ generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
        return 1;
 }
 
+int generate_xattr_name(int xattr_num, char *buffer, int buflen)
+{
+       int ret;
+
+       ret = snprintf(buffer, buflen, "user.x%d", xattr_num);
+       if (ret < 0)
+               return ret;
+       if (ret < buflen)
+               return 0;
+       return -EOVERFLOW;
+}
+
 /*
  * Get file 
  * Input: "which" to choose the file-types eg. non-directory
@@ -1075,7 +1352,7 @@ get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
 
                                /* fill-in what we were asked for */
                                if (name) {
-                                       e = fent_to_name(name, flp, fep);
+                                       e = fent_to_name(name, fep);
 #ifdef DEBUG
                                        if (!e) {
                                                fprintf(stderr, "%d: failed to get path for entry:"
@@ -1129,7 +1406,7 @@ lchown_path(pathname_t *name, uid_t owner, gid_t group)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = lchown_path(&newname, owner, group);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1153,7 +1430,7 @@ link_path(pathname_t *name1, pathname_t *name2)
        if (strcmp(buf1, buf2) == 0) {
                if (chdir(buf1) == 0) {
                        rval = link_path(&newname1, &newname2);
-                       chdir("..");
+                       assert(chdir("..") == 0);
                }
        } else {
                if (strcmp(buf1, "..") == 0)
@@ -1173,7 +1450,7 @@ link_path(pathname_t *name1, pathname_t *name2)
                        append_pathname(&newname2, name2->path);
                        if (chdir(buf1) == 0) {
                                rval = link_path(&newname1, &newname2);
-                               chdir("..");
+                               assert(chdir("..") == 0);
                        }
                } else {
                        free_pathname(&newname1);
@@ -1181,7 +1458,7 @@ link_path(pathname_t *name1, pathname_t *name2)
                        append_pathname(&newname1, name1->path);
                        if (chdir(buf2) == 0) {
                                rval = link_path(&newname1, &newname2);
-                               chdir("..");
+                               assert(chdir("..") == 0);
                        }
                }
        }
@@ -1203,7 +1480,7 @@ lstat64_path(pathname_t *name, struct stat64 *sbuf)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = lstat64_path(&newname, sbuf);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1239,7 +1516,7 @@ mkdir_path(pathname_t *name, mode_t mode)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = mkdir_path(&newname, mode);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1258,7 +1535,7 @@ mknod_path(pathname_t *name, mode_t mode, dev_t dev)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = mknod_path(&newname, mode, dev);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1286,6 +1563,22 @@ namerandpad(int id, char *buf, int i)
        }
 }
 
+int
+open_file_or_dir(pathname_t *name, int flags)
+{
+       int fd;
+
+       fd = open_path(name, flags);
+       if (fd != -1)
+               return fd;
+       if (fd == -1 && errno != EISDIR)
+               return fd;
+       /* Directories can not be opened in write mode nor direct mode. */
+       flags &= ~(O_WRONLY | O_DIRECT);
+       flags |= O_RDONLY | O_DIRECTORY;
+       return open_path(name, flags);
+}
+
 int
 open_path(pathname_t *name, int oflag)
 {
@@ -1299,7 +1592,7 @@ open_path(pathname_t *name, int oflag)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = open_path(&newname, oflag);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1318,7 +1611,7 @@ opendir_path(pathname_t *name)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = opendir_path(&newname);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1359,14 +1652,14 @@ readlink_path(pathname_t *name, char *lbuf, size_t lbufsiz)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = readlink_path(&newname, lbuf, lbufsiz);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
 }
 
 int
-rename_path(pathname_t *name1, pathname_t *name2)
+rename_path(pathname_t *name1, pathname_t *name2, int mode)
 {
        char            buf1[NAME_MAX + 1];
        char            buf2[NAME_MAX + 1];
@@ -1375,15 +1668,19 @@ rename_path(pathname_t *name1, pathname_t *name2)
        pathname_t      newname2;
        int             rval;
 
-       rval = rename(name1->path, name2->path);
+       if (mode == 0)
+               rval = rename(name1->path, name2->path);
+       else
+               rval = renameat2(AT_FDCWD, name1->path,
+                                AT_FDCWD, name2->path, mode);
        if (rval >= 0 || errno != ENAMETOOLONG)
                return rval;
        separate_pathname(name1, buf1, &newname1);
        separate_pathname(name2, buf2, &newname2);
        if (strcmp(buf1, buf2) == 0) {
                if (chdir(buf1) == 0) {
-                       rval = rename_path(&newname1, &newname2);
-                       chdir("..");
+                       rval = rename_path(&newname1, &newname2, mode);
+                       assert(chdir("..") == 0);
                }
        } else {
                if (strcmp(buf1, "..") == 0)
@@ -1402,16 +1699,16 @@ rename_path(pathname_t *name1, pathname_t *name2)
                        append_pathname(&newname2, "../");
                        append_pathname(&newname2, name2->path);
                        if (chdir(buf1) == 0) {
-                               rval = rename_path(&newname1, &newname2);
-                               chdir("..");
+                               rval = rename_path(&newname1, &newname2, mode);
+                               assert(chdir("..") == 0);
                        }
                } else {
                        free_pathname(&newname1);
                        append_pathname(&newname1, "../");
                        append_pathname(&newname1, name1->path);
                        if (chdir(buf2) == 0) {
-                               rval = rename_path(&newname1, &newname2);
-                               chdir("..");
+                               rval = rename_path(&newname1, &newname2, mode);
+                               assert(chdir("..") == 0);
                        }
                }
        }
@@ -1433,7 +1730,7 @@ rmdir_path(pathname_t *name)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = rmdir_path(&newname);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1516,7 +1813,7 @@ stat64_path(pathname_t *name, struct stat64 *sbuf)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = stat64_path(&newname, sbuf);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1540,7 +1837,7 @@ symlink_path(const char *name1, pathname_t *name)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = symlink_path(name1, &newname);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1559,7 +1856,7 @@ truncate64_path(pathname_t *name, off64_t length)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = truncate64_path(&newname, length);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1578,7 +1875,7 @@ unlink_path(pathname_t *name)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = unlink_path(&newname);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -1637,6 +1934,36 @@ zero_freq(void)
                p->freq = 0;
 }
 
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+opty_t btrfs_ops[] = {
+       OP_SNAPSHOT,
+       OP_SUBVOL_CREATE,
+       OP_SUBVOL_DELETE,
+};
+
+void
+non_btrfs_freq(const char *path)
+{
+       opdesc_t                *p;
+#ifdef HAVE_BTRFSUTIL_H
+       enum btrfs_util_error   e;
+
+       e = btrfs_util_is_subvolume(path);
+       if (e != BTRFS_UTIL_ERROR_NOT_BTRFS)
+               return;
+#endif
+       for (p = ops; p < ops_end; p++) {
+               int i;
+               for (i = 0; i < ARRAY_SIZE(btrfs_ops); i++) {
+                       if (p->op == btrfs_ops[i]) {
+                               p->freq = 0;
+                               break;
+                       }
+               }
+       }
+}
+
 void inode_info(char *str, size_t sz, struct stat64 *s, int verbose)
 {
        if (verbose)
@@ -1646,6 +1973,62 @@ void inode_info(char *str, size_t sz, struct stat64 *s, int verbose)
                         (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 | FT_DIRm, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: afsync - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_file_or_dir(&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)
 {
@@ -1653,7 +2036,7 @@ allocsp_f(int opno, long r)
        pathname_t      f;
        int             fd;
        struct xfs_flock64      fl;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -1685,7 +2068,7 @@ allocsp_f(int opno, long r)
                return;
        }
        inode_info(st, sizeof(st), &stb, v);
-       lr = ((__int64_t)random() << 32) + random();
+       lr = ((int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        fl.l_whence = SEEK_SET;
@@ -1700,108 +2083,336 @@ allocsp_f(int opno, long r)
        close(fd);
 }
 
+#ifdef AIO
 void
-attr_remove_f(int opno, long r)
+do_aio_rw(int opno, long r, int flags)
 {
-       attrlist_ent_t          *aep;
-       attrlist_t              *alist;
-       char                    *aname;
-       char                    buf[4096];
-       attrlist_cursor_t       cursor;
-       int                     e;
-       int                     ent;
-       pathname_t              f;
-       int                     total;
-       int                     v;
-       int                     which;
+       int64_t         align;
+       char            *buf = NULL;
+       struct dioattr  diob;
+       int             e;
+       pathname_t      f;
+       int             fd = -1;
+       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_ANYm, r, &f, NULL, NULL, &v))
-               append_pathname(&f, ".");
-       total = 0;
-       bzero(&cursor, sizeof(cursor));
-       do {
-               bzero(buf, sizeof(buf));
-               e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
-               check_cwd();
-               if (e)
-                       break;
-               alist = (attrlist_t *)buf;
-               total += alist->al_count;
-       } while (alist->al_more);
-       if (total == 0) {
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
                if (v)
-                       printf("%d/%d: attr_remove - no attrs for %s\n",
-                               procid, opno, f.path);
-               free_pathname(&f);
-               return;
+                       printf("%d/%d: do_aio_rw - no filename\n", procid, opno);
+               goto aio_out;
        }
-       which = (int)(random() % total);
-       bzero(&cursor, sizeof(cursor));
-       ent = 0;
-       aname = NULL;
-       do {
-               bzero(buf, sizeof(buf));
-               e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
-               check_cwd();
-               if (e)
-                       break;
-               alist = (attrlist_t *)buf;
-               if (which < ent + alist->al_count) {
-                       aep = (attrlist_ent_t *)
-                               &buf[alist->al_offset[which - ent]];
-                       aname = aep->a_name;
-                       break;
-               }
-               ent += alist->al_count;
-       } while (alist->al_more);
-       if (aname == NULL) {
+       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);
+               goto aio_out;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: do_aio_rw - fstat64 %s failed %d\n",
+                              procid, opno, f.path, errno);
+               goto aio_out;
+       }
+       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);
+               goto aio_out;
+       }
+       if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
                if (v)
                        printf(
-                       "%d/%d: attr_remove - name %d not found at %s\n",
-                               procid, opno, which, f.path);
-               free_pathname(&f);
-               return;
+                       "%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);
        }
-       e = attr_remove_path(&f, aname, ATTR_DONTFOLLOW) < 0 ? errno : 0;
-       check_cwd();
+       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 (!buf) {
+               if (v)
+                       printf("%d/%d: do_aio_rw - memalign failed\n",
+                              procid, opno);
+               goto aio_out;
+       }
+
+       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);
+               goto aio_out;
+       }
+       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);
+               goto aio_out;
+       }
+
+       e = event.res != len ? event.res2 : 0;
        if (v)
-               printf("%d/%d: attr_remove %s %s %d\n",
-                       procid, opno, f.path, aname, 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);
+ aio_out:
+       if (buf)
+               free(buf);
+       if (fd != -1)
+               close(fd);
        free_pathname(&f);
 }
+#endif
 
+#ifdef URING
 void
-attr_set_f(int opno, long r)
+do_uring_rw(int opno, long r, int flags)
 {
-       char            aname[10];
-       char            *aval;
+       char            *buf = NULL;
        int             e;
        pathname_t      f;
-       int             len;
-       static int      lengths[] = { 10, 100, 1000, 10000 };
-       int             li;
+       int             fd = -1;
+       size_t          len;
+       int64_t         lr;
+       off64_t         off;
+       struct stat64   stb;
        int             v;
+       char            st[1024];
+       struct io_uring_sqe     *sqe;
+       struct io_uring_cqe     *cqe;
+       struct iovec    iovec;
+       int             iswrite = (flags & (O_WRONLY | O_RDWR)) ? 1 : 0;
+
+       if (!have_io_uring)
+               return;
 
        init_pathname(&f);
-       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
-               append_pathname(&f, ".");
-       sprintf(aname, "a%x", nameseq++);
-       li = (int)(random() % (sizeof(lengths) / sizeof(lengths[0])));
-       len = (int)(random() % lengths[li]);
-       if (len == 0)
-               len = 1;
-       aval = malloc(len);
-       memset(aval, nameseq & 0xff, len);
-       e = attr_set_path(&f, aname, aval, len, ATTR_DONTFOLLOW) < 0 ?
-               errno : 0;
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - no filename\n", procid, opno);
+               goto uring_out;
+       }
+       fd = open_path(&f, flags);
+       e = fd < 0 ? errno : 0;
        check_cwd();
-       free(aval);
-       if (v)
-               printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
-                       aname, e);
-       free_pathname(&f);
-}
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - open %s failed %d\n",
+                              procid, opno, f.path, e);
+               goto uring_out;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - fstat64 %s failed %d\n",
+                              procid, opno, f.path, errno);
+               goto uring_out;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       if (!iswrite && stb.st_size == 0) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - %s%s zero size\n", procid, opno,
+                              f.path, st);
+               goto uring_out;
+       }
+       sqe = io_uring_get_sqe(&ring);
+       if (!sqe) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - io_uring_get_sqe failed\n",
+                              procid, opno);
+               goto uring_out;
+       }
+       lr = ((int64_t)random() << 32) + random();
+       len = (random() % FILELEN_MAX) + 1;
+       buf = malloc(len);
+       if (!buf) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - malloc failed\n",
+                              procid, opno);
+               goto uring_out;
+       }
+       iovec.iov_base = buf;
+       iovec.iov_len = len;
+       if (iswrite) {
+               off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+               off %= maxfsize;
+               memset(buf, nameseq & 0xff, len);
+               io_uring_prep_writev(sqe, fd, &iovec, 1, off);
+       } else {
+               off = (off64_t)(lr % stb.st_size);
+               io_uring_prep_readv(sqe, fd, &iovec, 1, off);
+       }
+
+       if ((e = io_uring_submit_and_wait(&ring, 1)) != 1) {
+               if (v)
+                       printf("%d/%d: %s - io_uring_submit failed %d\n", procid, opno,
+                              iswrite ? "uring_write" : "uring_read", e);
+               goto uring_out;
+       }
+       if ((e = io_uring_wait_cqe(&ring, &cqe)) < 0) {
+               if (v)
+                       printf("%d/%d: %s - io_uring_wait_cqe failed %d\n", procid, opno,
+                              iswrite ? "uring_write" : "uring_read", e);
+               goto uring_out;
+       }
+       if (v)
+               printf("%d/%d: %s %s%s [%lld, %d(res=%d)] %d\n",
+                      procid, opno, iswrite ? "uring_write" : "uring_read",
+                      f.path, st, (long long)off, (int)len, cqe->res, e);
+       io_uring_cqe_seen(&ring, cqe);
+
+ uring_out:
+       if (buf)
+               free(buf);
+       if (fd != -1)
+               close(fd);
+       free_pathname(&f);
+}
+#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)
+{
+       char                    *bufname;
+       char                    *bufend;
+       char                    *aname = NULL;
+       char                    buf[XATTR_LIST_MAX];
+       int                     e;
+       int                     ent;
+       pathname_t              f;
+       int                     total = 0;
+       int                     v;
+       int                     which;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       e = attr_list_path(&f, buf, sizeof(buf));
+       check_cwd();
+       if (e > 0)
+               total = attr_list_count(buf, e);
+       if (total == 0) {
+               if (v)
+                       printf("%d/%d: attr_remove - no attrs for %s\n",
+                               procid, opno, f.path);
+               free_pathname(&f);
+               return;
+       }
+
+       which = (int)(random() % total);
+       bufname = buf;
+       bufend = buf + e;
+       ent = 0;
+       while (bufname < bufend) {
+               if (which < ent) {
+                       aname = bufname;
+                       break;
+               }
+               ent++;
+               bufname += strlen(bufname) + 1;
+       }
+       if (aname == NULL) {
+               if (v)
+                       printf(
+                       "%d/%d: attr_remove - name %d not found at %s\n",
+                               procid, opno, which, f.path);
+               free_pathname(&f);
+               return;
+       }
+       if (attr_remove_path(&f, aname) < 0)
+               e = errno;
+       else
+               e = 0;
+       check_cwd();
+       if (v)
+               printf("%d/%d: attr_remove %s %s %d\n",
+                       procid, opno, f.path, aname, e);
+       free_pathname(&f);
+}
+
+void
+attr_set_f(int opno, long r)
+{
+       char            aname[10];
+       char            *aval;
+       int             e;
+       pathname_t      f;
+       int             len;
+       static int      lengths[] = { 10, 100, 1000, 10000 };
+       int             li;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       sprintf(aname, "a%x", nameseq++);
+       li = (int)(random() % (sizeof(lengths) / sizeof(lengths[0])));
+       len = (int)(random() % lengths[li]);
+       if (len == 0)
+               len = 1;
+       aval = malloc(len);
+       memset(aval, nameseq & 0xff, len);
+       if (attr_set_path(&f, aname, aval, len) < 0)
+               e = errno;
+       else
+               e = 0;
+       check_cwd();
+       free(aval);
+       if (v)
+               printf("%d/%d: attr_set %s %s %d\n", procid, opno, f.path,
+                       aname, e);
+       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)
@@ -1810,9 +2421,9 @@ bulkstat_f(int opno, long r)
        int             fd;
        __u64           last;
        int             nent;
-       xfs_bstat_t     *t;
-       __int64_t       total;
-        xfs_fsop_bulkreq_t bsr;
+       struct xfs_bstat        *t;
+       int64_t         total;
+       struct xfs_fsop_bulkreq bsr;
 
        last = 0;
        nent = (r % 999) + 2;
@@ -1843,9 +2454,9 @@ bulkstat1_f(int opno, long r)
        int             good;
        __u64           ino;
        struct stat64   s;
-       xfs_bstat_t     t;
+       struct xfs_bstat        t;
        int             v;
-        xfs_fsop_bulkreq_t bsr;
+       struct xfs_fsop_bulkreq bsr;
         
 
        good = random() & 1;
@@ -1914,6 +2525,549 @@ chown_f(int opno, long r)
        free_pathname(&f);
 }
 
+/* reflink some arbitrary range of f1 to f2. */
+void
+clonerange_f(
+       int                     opno,
+       long                    r)
+{
+#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;
+       off64_t                 max_off2;
+       size_t                  len;
+       int                     v1;
+       int                     v2;
+       int                     fd1;
+       int                     fd2;
+       int                     ret;
+       int                     e;
+
+       /* 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;
+       }
+
+       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;
+       }
+
+       /* 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;
+       }
+       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.
+        */
+       max_off2 = MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE);
+       do {
+               lr = ((int64_t)random() << 32) + random();
+               off2 = (off64_t)(lr % max_off2);
+               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
+}
+
+/* copy some arbitrary range of f1 to f2. */
+void
+copyrange_f(
+       int                     opno,
+       long                    r)
+{
+#ifdef HAVE_COPY_FILE_RANGE
+       struct pathname         fpath1;
+       struct pathname         fpath2;
+       struct stat64           stat1;
+       struct stat64           stat2;
+       char                    inoinfo1[1024];
+       char                    inoinfo2[1024];
+       loff_t                  lr;
+       loff_t                  off1;
+       loff_t                  off2;
+       loff_t                  offset1;
+       loff_t                  offset2;
+       loff_t                  max_off2;
+       size_t                  len;
+       size_t                  length;
+       int                     tries = 0;
+       int                     v1;
+       int                     v2;
+       int                     fd1;
+       int                     fd2;
+       size_t                  ret = 0;
+       int                     e;
+
+       /* Load paths */
+       init_pathname(&fpath1);
+       if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
+               if (v1)
+                       printf("%d/%d: copyrange 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: copyrange 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: copyrange read - open %s failed %d\n",
+                               procid, opno, fpath1.path, e);
+               goto out_fpath2;
+       }
+
+       fd2 = open_path(&fpath2, O_WRONLY);
+       e = fd2 < 0 ? errno : 0;
+       check_cwd();
+       if (fd2 < 0) {
+               if (v2)
+                       printf("%d/%d: copyrange write - open %s failed %d\n",
+                               procid, opno, fpath2.path, e);
+               goto out_fd1;
+       }
+
+       /* Get file stats */
+       if (fstat64(fd1, &stat1) < 0) {
+               if (v1)
+                       printf("%d/%d: copyrange read - fstat64 %s failed %d\n",
+                               procid, opno, fpath1.path, errno);
+               goto out_fd2;
+       }
+       inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
+
+       if (fstat64(fd2, &stat2) < 0) {
+               if (v2)
+                       printf("%d/%d: copyrange 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;
+       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;
+
+       /*
+        * If srcfile == destfile, randomly generate destination ranges
+        * until we find one that doesn't overlap the source range.
+        */
+       max_off2 = MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE);
+       do {
+               lr = ((int64_t)random() << 32) + random();
+               off2 = (off64_t)(lr % max_off2);
+               off2 %= maxfsize;
+       } while (stat1.st_ino == stat2.st_ino && llabs(off2 - off1) < len);
+
+       /*
+        * Since len, off1 and off2 will be changed later, preserve their
+        * original values.
+        */
+       length = len;
+       offset1 = off1;
+       offset2 = off2;
+
+       while (len > 0) {
+               ret = syscall(__NR_copy_file_range, fd1, &off1, fd2, &off2,
+                             len, 0);
+               if (ret < 0) {
+                       if (errno != EAGAIN || tries++ >= 300)
+                               break;
+               } else if (ret > len || ret == 0)
+                       break;
+               else if (ret > 0)
+                       len -= ret;
+       }
+       e = ret < 0 ? errno : 0;
+       if (v1 || v2) {
+               printf("%d/%d: copyrange %s%s [%lld,%lld] -> %s%s [%lld,%lld]",
+                       procid, opno,
+                       fpath1.path, inoinfo1,
+                       (long long)offset1, (long long)length,
+                       fpath2.path, inoinfo2,
+                       (long long)offset2, (long long)length);
+
+               if (ret < 0)
+                       printf(" error %d", e);
+               else if (len && ret > len)
+                       printf(" asked for %lld, copied %lld??\n",
+                               (long long)len, (long long)ret);
+               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)
 {
@@ -1926,28 +3080,199 @@ setxattr_f(int opno, long r)
        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();
+       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);
+#endif
+}
+
+void
+splice_f(int opno, long r)
+{
+       struct pathname         fpath1;
+       struct pathname         fpath2;
+       struct stat64           stat1;
+       struct stat64           stat2;
+       char                    inoinfo1[1024];
+       char                    inoinfo2[1024];
+       loff_t                  lr;
+       loff_t                  off1, off2;
+       size_t                  len;
+       loff_t                  offset1, offset2;
+       size_t                  length;
+       size_t                  total;
+       int                     v1;
+       int                     v2;
+       int                     fd1;
+       int                     fd2;
+       ssize_t                 ret1 = 0, ret2 = 0;
+       size_t                  bytes;
+       int                     e;
+       int                     filedes[2];
+
+       /* Load paths */
+       init_pathname(&fpath1);
+       if (!get_fname(FT_REGm, r, &fpath1, NULL, NULL, &v1)) {
+               if (v1)
+                       printf("%d/%d: splice 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: splice 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: splice read - open %s failed %d\n",
+                               procid, opno, fpath1.path, e);
+               goto out_fpath2;
+       }
+
+       fd2 = open_path(&fpath2, O_WRONLY);
+       e = fd2 < 0 ? errno : 0;
+       check_cwd();
+       if (fd2 < 0) {
+               if (v2)
+                       printf("%d/%d: splice write - open %s failed %d\n",
+                               procid, opno, fpath2.path, e);
+               goto out_fd1;
+       }
+
+       /* Get file stats */
+       if (fstat64(fd1, &stat1) < 0) {
+               if (v1)
+                       printf("%d/%d: splice read - fstat64 %s failed %d\n",
+                               procid, opno, fpath1.path, errno);
+               goto out_fd2;
+       }
+       inode_info(inoinfo1, sizeof(inoinfo1), &stat1, v1);
+
+       if (fstat64(fd2, &stat2) < 0) {
+               if (v2)
+                       printf("%d/%d: splice 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;
+       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;
+
+       /*
+        * splice can overlap write, so the offset of the target file can be
+        * any number. But to avoid too large offset, add a clamp of 1024 blocks
+        * past the current dest file EOF
+        */
+       lr = ((int64_t)random() << 32) + random();
+       off2 = (off64_t)(lr % MIN(stat2.st_size + (1024ULL * stat2.st_blksize), MAXFSIZE));
 
-       /* project ID */
-       p = (uint)random();
-       e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
-       nbits = (int)(random() % e);
-       p &= (1 << nbits) - 1;
+       /*
+        * Since len, off1 and off2 will be changed later, preserve their
+        * original values.
+        */
+       length = len;
+       offset1 = off1;
+       offset2 = off2;
+
+       /* Pipe initialize */
+       if (pipe(filedes) < 0) {
+               if (v1 || v2) {
+                       printf("%d/%d: splice - pipe failed %d\n",
+                               procid, opno, errno);
+                       goto out_fd2;
+               }
+       }
 
-       if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
-               fsx.fsx_projid = p;
-               e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
+       bytes = 0;
+       total = 0;
+       while (len > 0) {
+               /* move to pipe buffer */
+               ret1 = splice(fd1, &off1, filedes[1], NULL, len, 0);
+               if (ret1 <= 0) {
+                       break;
+               }
+               bytes = ret1;
+
+               /* move from pipe buffer to dst file */
+               while (bytes > 0) {
+                       ret2 = splice(filedes[0], NULL, fd2, &off2, bytes, 0);
+                       if (ret2 < 0) {
+                               break;
+                       }
+                       bytes -= ret2;
+               }
+               if (ret2 < 0)
+                       break;
+
+               len -= ret1;
+               total += ret1;
        }
-       if (v)
-               printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e);
-       free_pathname(&f);
-       close(fd);
-#endif
+
+       if (ret1 < 0 || ret2 < 0)
+               e = errno;
+       else
+               e = 0;
+       if (v1 || v2) {
+               printf("%d/%d: splice %s%s [%lld,%lld] -> %s%s [%lld,%lld] %d",
+                       procid, opno,
+                       fpath1.path, inoinfo1, (long long)offset1, (long long)length,
+                       fpath2.path, inoinfo2, (long long)offset2, (long long)length, e);
+
+               if (length && length > total)
+                       printf(" asked for %lld, spliced %lld??\n",
+                               (long long)length, (long long)total);
+               printf("\n");
+       }
+
+       close(filedes[0]);
+       close(filedes[1]);
+out_fd2:
+       close(fd2);
+out_fd1:
+       close(fd1);
+out_fpath2:
+       free_pathname(&fpath2);
+out_fpath1:
+       free_pathname(&fpath1);
 }
 
 void
@@ -1966,7 +3291,7 @@ creat_f(int opno, long r)
        int             v;
        int             v1;
 
-       if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v1))
+       if (!get_fname(FT_ANYDIR, r, NULL, NULL, &fep, &v1))
                parid = -1;
        else
                parid = fep->id;
@@ -1985,7 +3310,7 @@ creat_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, fep);
                        printf("%d/%d: creat - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -2012,7 +3337,7 @@ creat_f(int opno, long r)
                        if (xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &a) < 0)
                                e1 = errno;
                }
-               add_to_flist(type, id, parid);
+               add_to_flist(type, id, parid, 0);
                close(fd);
        }
        if (v) {
@@ -2026,14 +3351,14 @@ creat_f(int opno, long r)
 void
 dread_f(int opno, long r)
 {
-       __int64_t       align;
+       int64_t         align;
        char            *buf;
        struct dioattr  diob;
        int             e;
        pathname_t      f;
        int             fd;
        size_t          len;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -2077,19 +3402,19 @@ 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%s failed %d\n",
+                       "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s%s return %d,"
+                       " fallback to stat()\n",
                                procid, opno, f.path, st, errno);
-               free_pathname(&f);
-               close(fd);
-               return;
+               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();
+       align = (int64_t)diob.d_miniosz;
+       lr = ((int64_t)random() << 32) + random();
        off = (off64_t)(lr % stb.st_size);
        off -= (off % align);
        lseek64(fd, off, SEEK_SET);
@@ -2112,14 +3437,14 @@ dread_f(int opno, long r)
 void
 dwrite_f(int opno, long r)
 {
-       __int64_t       align;
+       int64_t         align;
        char            *buf;
        struct dioattr  diob;
        int             e;
        pathname_t      f;
        int             fd;
        size_t          len;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -2155,19 +3480,18 @@ dwrite_f(int opno, long r)
        if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
                if (v)
                        printf("%d/%d: dwrite - xfsctl(XFS_IOC_DIOINFO)"
-                               " %s%s failed %d\n",
+                               " %s%s return %d, fallback to stat()\n",
                               procid, opno, f.path, st, errno);
-               free_pathname(&f);
-               close(fd);
-               return;
+               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();
+       align = (int64_t)diob.d_miniosz;
+       lr = ((int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off -= (off % align);
        lseek64(fd, off, SEEK_SET);
@@ -2213,7 +3537,7 @@ do_fallocate(int opno, long r, int mode)
        int             e;
        pathname_t      f;
        int             fd;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        off64_t         len;
        struct stat64   stb;
@@ -2245,7 +3569,7 @@ do_fallocate(int opno, long r, int mode)
                return;
        }
        inode_info(st, sizeof(st), &stb, v);
-       lr = ((__int64_t)random() << 32) + random();
+       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));
@@ -2328,7 +3652,7 @@ fiemap_f(int opno, long r)
        int             e;
        pathname_t      f;
        int             fd;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -2372,14 +3696,14 @@ fiemap_f(int opno, long r)
                close(fd);
                return;
        }
-       lr = ((__int64_t)random() << 32) + random();
+       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();
+       fiemap->fm_length = ((int64_t)random() << 32) + random();
 
        e = ioctl(fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
        if (v)
@@ -2400,7 +3724,7 @@ freesp_f(int opno, long r)
        pathname_t      f;
        int             fd;
        struct xfs_flock64      fl;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -2432,7 +3756,7 @@ freesp_f(int opno, long r)
                return;
        }
        inode_info(st, sizeof(st), &stb, v);
-       lr = ((__int64_t)random() << 32) + random();
+       lr = ((int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        fl.l_whence = SEEK_SET;
@@ -2455,13 +3779,13 @@ fsync_f(int opno, long r)
        int             v;
 
        init_pathname(&f);
-       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+       if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, NULL, &v)) {
                if (v)
                        printf("%d/%d: fsync - no filename\n", procid, opno);
                free_pathname(&f);
                return;
        }
-       fd = open_path(&f, O_WRONLY);
+       fd = open_file_or_dir(&f, O_WRONLY);
        e = fd < 0 ? errno : 0;
        check_cwd();
        if (fd < 0) {
@@ -2478,6 +3802,28 @@ fsync_f(int opno, long r)
        close(fd);
 }
 
+char *
+gen_random_string(int len)
+{
+       static const char charset[] = "0123456789"
+               "abcdefghijklmnopqrstuvwxyz"
+               "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+       int i;
+       char *s;
+
+       if (len == 0)
+               return NULL;
+
+       s = malloc(len);
+       if (!s)
+               return NULL;
+
+       for (i = 0; i < len; i++)
+               s[i] = charset[random() % sizeof(charset)];
+
+       return s;
+}
+
 void
 getattr_f(int opno, long r)
 {
@@ -2509,7 +3855,7 @@ getdents_f(int opno, long r)
        int             v;
 
        init_pathname(&f);
-       if (!get_fname(FT_DIRm, r, &f, NULL, NULL, &v))
+       if (!get_fname(FT_ANYDIR, r, &f, NULL, NULL, &v))
                append_pathname(&f, ".");
        dir = opendir_path(&f);
        check_cwd();
@@ -2528,12 +3874,82 @@ getdents_f(int opno, long r)
        closedir(dir);
 }
 
+void
+getfattr_f(int opno, long r)
+{
+       fent_t          *fep;
+       int             e;
+       pathname_t      f;
+       int             v;
+       char            name[XATTR_NAME_BUF_SIZE];
+       char            *value = NULL;
+       int             value_len;
+       int             xattr_num;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE | FT_ANYDIR, r, &f, NULL, &fep, &v)) {
+               if (v)
+                       printf("%d/%d: getfattr - no filename\n", procid, opno);
+               goto out;
+       }
+       check_cwd();
+
+       /*
+        * If the file/dir has xattrs, pick one randomly, otherwise attempt
+        * to read a xattr that doesn't exist (fgetxattr should fail with
+        * errno set to ENOATTR (61) in this case).
+        */
+       if (fep->xattr_counter > 0)
+               xattr_num = (random() % fep->xattr_counter) + 1;
+       else
+               xattr_num = 0;
+
+       e = generate_xattr_name(xattr_num, name, sizeof(name));
+       if (e < 0) {
+               printf("%d/%d: getfattr - file %s failed to generate xattr name: %d\n",
+                      procid, opno, f.path, e);
+               goto out;
+       }
+
+       value_len = getxattr(f.path, name, NULL, 0);
+       if (value_len < 0) {
+               if (v)
+                       printf("%d/%d: getfattr file %s name %s failed %d\n",
+                              procid, opno, f.path, name, errno);
+               goto out;
+       }
+
+       /* A xattr without value.*/
+       if (value_len == 0) {
+               e = 0;
+               goto out_log;
+       }
+
+       value = malloc(value_len);
+       if (!value) {
+               if (v)
+                       printf("%d/%d: getfattr file %s failed to allocate buffer with %d bytes\n",
+                              procid, opno, f.path, value_len);
+               goto out;
+       }
+
+       e = getxattr(f.path, name, value, value_len) < 0 ? errno : 0;
+out_log:
+       if (v)
+               printf("%d/%d: getfattr file %s name %s value length %d %d\n",
+                      procid, opno, f.path, name, value_len, e);
+out:
+       free(value);
+       free_pathname(&f);
+}
+
 void
 link_f(int opno, long r)
 {
        int             e;
        pathname_t      f;
        fent_t          *fep;
+       fent_t          *fep_src;
        flist_t         *flp;
        int             id;
        pathname_t      l;
@@ -2542,7 +3958,7 @@ link_f(int opno, long r)
        int             v1;
 
        init_pathname(&f);
-       if (!get_fname(FT_NOTDIR, r, &f, &flp, NULL, &v1)) {
+       if (!get_fname(FT_NOTDIR, r, &f, &flp, &fep_src, &v1)) {
                if (v1)
                        printf("%d/%d: link - no file\n", procid, opno);
                free_pathname(&f);
@@ -2558,7 +3974,7 @@ link_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       (void)fent_to_name(&l, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&l, fep);
                        printf("%d/%d: link - no filename from %s\n",
                                procid, opno, l.path);
                }
@@ -2569,7 +3985,7 @@ link_f(int opno, long r)
        e = link_path(&f, &l) < 0 ? errno : 0;
        check_cwd();
        if (e == 0)
-               add_to_flist(flp - flist, id, parid);
+               add_to_flist(flp - flist, id, parid, fep_src->xattr_counter);
        if (v) {
                printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
                        e);
@@ -2579,6 +3995,56 @@ link_f(int opno, long r)
        free_pathname(&f);
 }
 
+void
+listfattr_f(int opno, long r)
+{
+       fent_t          *fep;
+       int             e;
+       pathname_t      f;
+       int             v;
+       char            *buffer = NULL;
+       int             buffer_len;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE | FT_ANYDIR, r, &f, NULL, &fep, &v)) {
+               if (v)
+                       printf("%d/%d: listfattr - no filename\n", procid, opno);
+               goto out;
+       }
+       check_cwd();
+
+       e = listxattr(f.path, NULL, 0);
+       if (e < 0) {
+               if (v)
+                       printf("%d/%d: listfattr %s failed %d\n",
+                              procid, opno, f.path, errno);
+               goto out;
+       }
+       buffer_len = e;
+       if (buffer_len == 0) {
+               if (v)
+                       printf("%d/%d: listfattr %s - has no extended attributes\n",
+                              procid, opno, f.path);
+               goto out;
+       }
+
+       buffer = malloc(buffer_len);
+       if (!buffer) {
+               if (v)
+                       printf("%d/%d: listfattr %s failed to allocate buffer with %d bytes\n",
+                              procid, opno, f.path, buffer_len);
+               goto out;
+       }
+
+       e = listxattr(f.path, buffer, buffer_len) < 0 ? errno : 0;
+       if (v)
+               printf("%d/%d: listfattr %s buffer length %d %d\n",
+                      procid, opno, f.path, buffer_len, e);
+out:
+       free(buffer);
+       free_pathname(&f);
+}
+
 void
 mkdir_f(int opno, long r)
 {
@@ -2590,7 +4056,7 @@ mkdir_f(int opno, long r)
        int             v;
        int             v1;
 
-       if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
+       if (!get_fname(FT_ANYDIR, r, NULL, NULL, &fep, &v))
                parid = -1;
        else
                parid = fep->id;
@@ -2599,7 +4065,7 @@ mkdir_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, fep);
                        printf("%d/%d: mkdir - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -2609,7 +4075,7 @@ mkdir_f(int opno, long r)
        e = mkdir_path(&f, 0777) < 0 ? errno : 0;
        check_cwd();
        if (e == 0)
-               add_to_flist(FT_DIR, id, parid);
+               add_to_flist(FT_DIR, id, parid, 0);
        if (v) {
                printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
                printf("%d/%d: mkdir add id=%d,parent=%d\n", procid, opno, id, parid);
@@ -2628,7 +4094,7 @@ mknod_f(int opno, long r)
        int             v;
        int             v1;
 
-       if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
+       if (!get_fname(FT_ANYDIR, r, NULL, NULL, &fep, &v))
                parid = -1;
        else
                parid = fep->id;
@@ -2637,7 +4103,7 @@ mknod_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, fep);
                        printf("%d/%d: mknod - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -2647,7 +4113,7 @@ mknod_f(int opno, long r)
        e = mknod_path(&f, S_IFCHR|0444, 0) < 0 ? errno : 0;
        check_cwd();
        if (e == 0)
-               add_to_flist(FT_DEV, id, parid);
+               add_to_flist(FT_DEV, id, parid, 0);
        if (v) {
                printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
                printf("%d/%d: mknod add id=%d,parent=%d\n", procid, opno, id, parid);
@@ -2655,6 +4121,131 @@ 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)
 {
@@ -2688,23 +4279,112 @@ insert_f(int opno, long r)
 }
 
 void
-read_f(int opno, long r)
+read_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];
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: read - 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: read - open %s failed %d\n",
+                               procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: read - 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: read - %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);
+       e = read(fd, buf, len) < 0 ? errno : 0;
+       free(buf);
+       if (v)
+               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);
+}
+
+void
+readlink_f(int opno, long r)
+{
+       char            buf[PATH_MAX];
+       int             e;
+       pathname_t      f;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: readlink - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
+       check_cwd();
+       if (v)
+               printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
+       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;
+       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: read - no filename\n", procid, opno);
+                       printf("%d/%d: readv - no filename\n", procid, opno);
                free_pathname(&f);
                return;
        }
@@ -2713,14 +4393,14 @@ read_f(int opno, long r)
        check_cwd();
        if (fd < 0) {
                if (v)
-                       printf("%d/%d: read - open %s failed %d\n",
+                       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: read - fstat64 %s failed %d\n",
+                       printf("%d/%d: readv - fstat64 %s failed %d\n",
                                procid, opno, f.path, errno);
                free_pathname(&f);
                close(fd);
@@ -2729,50 +4409,93 @@ read_f(int opno, long r)
        inode_info(st, sizeof(st), &stb, v);
        if (stb.st_size == 0) {
                if (v)
-                       printf("%d/%d: read - %s%s zero size\n", procid, opno,
+                       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();
+       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);
-       e = read(fd, buf, len) < 0 ? errno : 0;
+
+       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: read %s%s [%lld,%d] %d\n",
-                      procid, opno, f.path, st, (long long)off, (int)len, e);
+               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
-readlink_f(int opno, long r)
+removefattr_f(int opno, long r)
 {
-       char            buf[PATH_MAX];
+       fent_t          *fep;
        int             e;
        pathname_t      f;
        int             v;
+       char            name[XATTR_NAME_BUF_SIZE];
+       int             xattr_num;
 
        init_pathname(&f);
-       if (!get_fname(FT_SYMm, r, &f, NULL, NULL, &v)) {
+       if (!get_fname(FT_REGFILE | FT_ANYDIR, r, &f, NULL, &fep, &v)) {
                if (v)
-                       printf("%d/%d: readlink - no filename\n", procid, opno);
-               free_pathname(&f);
-               return;
+                       printf("%d/%d: removefattr - no filename\n", procid, opno);
+               goto out;
        }
-       e = readlink_path(&f, buf, PATH_MAX) < 0 ? errno : 0;
        check_cwd();
+
+       /*
+        * If the file/dir has xattrs, pick one randomly, otherwise attempt to
+        * remove a xattr that doesn't exist (fremovexattr should fail with
+        * errno set to ENOATTR (61) in this case).
+        */
+       if (fep->xattr_counter > 0)
+               xattr_num = (random() % fep->xattr_counter) + 1;
+       else
+               xattr_num = 0;
+
+       e = generate_xattr_name(xattr_num, name, sizeof(name));
+       if (e < 0) {
+               printf("%d/%d: removefattr - file %s failed to generate xattr name: %d\n",
+                      procid, opno, f.path, e);
+               goto out;
+       }
+
+       e = removexattr(f.path, name) < 0 ? errno : 0;
        if (v)
-               printf("%d/%d: readlink %s %d\n", procid, opno, f.path, e);
+               printf("%d/%d: removefattr file %s name %s %d\n",
+                      procid, opno, f.path, name, e);
+out:
        free_pathname(&f);
 }
 
+struct print_flags renameat2_flags [] = {
+       { RENAME_NOREPLACE, "NOREPLACE"},
+       { RENAME_EXCHANGE, "EXCHANGE"},
+       { RENAME_WHITEOUT, "WHITEOUT"},
+       { -1, NULL}
+};
+
+#define translate_renameat2_flags(mode)        \
+       ({translate_flags(mode, "|", renameat2_flags);})
+
 void
-rename_f(int opno, long r)
+do_renameat2(int opno, long r, int mode)
 {
        fent_t          *dfep;
        int             e;
@@ -2783,56 +4506,116 @@ rename_f(int opno, long r)
        pathname_t      newf;
        int             oldid;
        int             parid;
+       int             oldparid;
+       int             which;
        int             v;
        int             v1;
 
        /* get an existing path for the source of the rename */
        init_pathname(&f);
-       if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
+       which = (mode == RENAME_WHITEOUT) ? FT_DEVm : FT_ANYm;
+       if (!get_fname(which, r, &f, &flp, &fep, &v1)) {
                if (v1)
-                       printf("%d/%d: rename - no filename\n", procid, opno);
+                       printf("%d/%d: rename - no source filename\n",
+                               procid, opno);
                free_pathname(&f);
                return;
        }
 
-       /* get an existing directory for the destination parent directory name */
-       if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
-               parid = -1;
-       else
-               parid = dfep->id;
-       v |= v1;
+       /*
+        * Both pathnames must exist for the RENAME_EXCHANGE, and in
+        * order to maintain filelist/filename integrity, we should
+        * restrict exchange operation to files of the same type.
+        */
+       if (mode == RENAME_EXCHANGE) {
+               which = 1 << (flp - flist);
+               init_pathname(&newf);
+               if (!get_fname(which, random(), &newf, NULL, &dfep, &v)) {
+                       if (v)
+                               printf("%d/%d: rename - no target filename\n",
+                                       procid, opno);
+                       free_pathname(&newf);
+                       free_pathname(&f);
+                       return;
+               }
+               if (which == FT_DIRm && (fents_ancestor_check(fep, dfep) ||
+                   fents_ancestor_check(dfep, fep))) {
+                       if (v)
+                               printf("%d/%d: rename(REXCHANGE) %s and %s "
+                                       "have ancestor-descendant relationship\n",
+                                       procid, opno, f.path, newf.path);
+                       free_pathname(&newf);
+                       free_pathname(&f);
+                       return;
+               }
+               v |= v1;
+               id = dfep->id;
+               parid = dfep->parent;
+       } else {
+               /*
+                * Get an existing directory for the destination parent
+                * directory name.
+                */
+               if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
+                       parid = -1;
+               else
+                       parid = dfep->id;
+               v |= v1;
 
-       /* generate a new path using an existing parent directory in name */
-       init_pathname(&newf);
-       e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
-       v |= v1;
-       if (!e) {
-               if (v) {
-                       (void)fent_to_name(&f, &flist[FT_DIR], dfep);
-                       printf("%d/%d: rename - no filename from %s\n",
-                               procid, opno, f.path);
+               /*
+                * Generate a new path using an existing parent directory
+                * in name.
+                */
+               init_pathname(&newf);
+               e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
+               v |= v1;
+               if (!e) {
+                       if (v) {
+                               (void)fent_to_name(&f, dfep);
+                               printf("%d/%d: rename - no filename from %s\n",
+                                       procid, opno, f.path);
+                       }
+                       free_pathname(&newf);
+                       free_pathname(&f);
+                       return;
                }
-               free_pathname(&newf);
-               free_pathname(&f);
-               return;
        }
-       e = rename_path(&f, &newf) < 0 ? errno : 0;
+       e = rename_path(&f, &newf, mode) < 0 ? errno : 0;
        check_cwd();
        if (e == 0) {
-               if (flp - flist == FT_DIR) {
-                       oldid = fep->id;
-                       fix_parent(oldid, id);
+               int xattr_counter = fep->xattr_counter;
+               bool swap = (mode == RENAME_EXCHANGE) ? true : false;
+               int ft = flp - flist;
+
+               oldid = fep->id;
+               oldparid = fep->parent;
+
+               /*
+                * Swap the parent ids for RENAME_EXCHANGE, and replace the
+                * old parent id for the others.
+                */
+               if (ft == FT_DIR || ft == FT_SUBVOL)
+                       fix_parent(oldid, id, swap);
+
+               if (mode == RENAME_WHITEOUT) {
+                       fep->xattr_counter = 0;
+                       add_to_flist(flp - flist, id, parid, xattr_counter);
+               } else if (mode == RENAME_EXCHANGE) {
+                       fep->xattr_counter = dfep->xattr_counter;
+                       dfep->xattr_counter = xattr_counter;
+               } else {
+                       del_from_flist(flp - flist, fep - flp->fents);
+                       add_to_flist(flp - flist, id, parid, xattr_counter);
                }
-               del_from_flist(flp - flist, fep - flp->fents);
-               add_to_flist(flp - flist, id, parid);
        }
        if (v) {
-               printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
+               printf("%d/%d: rename(%s) %s to %s %d\n", procid,
+                       opno, translate_renameat2_flags(mode), f.path,
                        newf.path, e);
                if (e == 0) {
-                       printf("%d/%d: rename del entry: id=%d,parent=%d\n",
-                               procid, opno, fep->id, fep->parent);
-                       printf("%d/%d: rename add entry: id=%d,parent=%d\n",
+                       printf("%d/%d: rename source entry: id=%d,parent=%d\n",
+                               procid, opno, oldid, oldparid);
+                       printf("%d/%d: rename target entry: id=%d,parent=%d\n",
                                procid, opno, id, parid);
                }
        }
@@ -2840,6 +4623,30 @@ rename_f(int opno, long r)
        free_pathname(&f);
 }
 
+void
+rename_f(int opno, long r)
+{
+       do_renameat2(opno, r, 0);
+}
+
+void
+rnoreplace_f(int opno, long r)
+{
+       do_renameat2(opno, r, RENAME_NOREPLACE);
+}
+
+void
+rexchange_f(int opno, long r)
+{
+       do_renameat2(opno, r, RENAME_EXCHANGE);
+}
+
+void
+rwhiteout_f(int opno, long r)
+{
+       do_renameat2(opno, r, RENAME_WHITEOUT);
+}
+
 void
 resvsp_f(int opno, long r)
 {
@@ -2847,7 +4654,7 @@ resvsp_f(int opno, long r)
        pathname_t      f;
        int             fd;
        struct xfs_flock64      fl;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -2879,7 +4686,7 @@ resvsp_f(int opno, long r)
                return;
        }
        inode_info(st, sizeof(st), &stb, v);
-       lr = ((__int64_t)random() << 32) + random();
+       lr = ((int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        fl.l_whence = SEEK_SET;
@@ -2900,6 +4707,8 @@ rmdir_f(int opno, long r)
        int             e;
        pathname_t      f;
        fent_t          *fep;
+       int             oldid;
+       int             oldparid;
        int             v;
 
        init_pathname(&f);
@@ -2911,13 +4720,16 @@ rmdir_f(int opno, long r)
        }
        e = rmdir_path(&f) < 0 ? errno : 0;
        check_cwd();
-       if (e == 0)
+       if (e == 0) {
+               oldid = fep->id;
+               oldparid = fep->parent;
                del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
+       }
        if (v) {
                printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
                if (e == 0)
                        printf("%d/%d: rmdir del entry: id=%d,parent=%d\n",
-                               procid, opno, fep->id, fep->parent);
+                               procid, opno, oldid, oldparid);
        }
        free_pathname(&f);
 }
@@ -2946,6 +4758,130 @@ setattr_f(int opno, long r)
        close(fd);
 }
 
+void
+setfattr_f(int opno, long r)
+{
+       int             e;
+       pathname_t      f;
+       fent_t          *fep;
+       int             v;
+       int             value_len;
+       char            name[XATTR_NAME_BUF_SIZE];
+       char            *value = NULL;
+       int             flag = 0;
+       int             xattr_num;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE | FT_ANYDIR, r, &f, NULL, &fep, &v)) {
+               if (v)
+                       printf("%d/%d: setfattr - no filename\n", procid, opno);
+               goto out;
+       }
+       check_cwd();
+
+       if ((fep->xattr_counter > 0) && (random() % 2)) {
+               /*
+                * Use an existing xattr name for replacing its value or
+                * create again a xattr that was previously deleted.
+                */
+               xattr_num = (random() % fep->xattr_counter) + 1;
+               if (random() % 2)
+                       flag = XATTR_REPLACE;
+       } else {
+               /* Use a new xattr name. */
+               xattr_num = fep->xattr_counter + 1;
+               /*
+                * Don't always use the create flag because even if our xattr
+                * counter is 0, we may still have xattrs associated to this
+                * file (this happens when xattrs are added to a file through
+                * one of its other hard links), so we can end up updating an
+                * existing xattr too.
+                */
+               if (random() % 2)
+                       flag = XATTR_CREATE;
+       }
+
+       /*
+        * The maximum supported value size depends on the filesystem
+        * implementation, but 100 bytes is a safe value for most filesystems
+        * at least.
+        */
+       value_len = random() % 101;
+       value = gen_random_string(value_len);
+       if (!value && value_len > 0) {
+               if (v)
+                       printf("%d/%d: setfattr - file %s failed to allocate value with %d bytes\n",
+                              procid, opno, f.path, value_len);
+               goto out;
+       }
+       e = generate_xattr_name(xattr_num, name, sizeof(name));
+       if (e < 0) {
+               printf("%d/%d: setfattr - file %s failed to generate xattr name: %d\n",
+                      procid, opno, f.path, e);
+               goto out;
+       }
+
+       e = setxattr(f.path, name, value, value_len, flag) < 0 ? errno : 0;
+       if (e == 0)
+               fep->xattr_counter++;
+       if (v)
+               printf("%d/%d: setfattr file %s name %s flag %s value length %d: %d\n",
+                      procid, opno, f.path, name, xattr_flag_to_string(flag),
+                      value_len, e);
+out:
+       free(value);
+       free_pathname(&f);
+}
+
+void
+snapshot_f(int opno, long r)
+{
+#ifdef HAVE_BTRFSUTIL_H
+       enum btrfs_util_error   e;
+       pathname_t              f;
+       pathname_t              newf;
+       fent_t                  *fep;
+       int                     id;
+       int                     parid;
+       int                     v;
+       int                     v1;
+       int                     err;
+
+       init_pathname(&f);
+       if (!get_fname(FT_SUBVOLm, r, &f, NULL, &fep, &v)) {
+               if (v)
+                       printf("%d/%d: snapshot - no subvolume\n", procid,
+                              opno);
+               free_pathname(&f);
+               return;
+       }
+       init_pathname(&newf);
+       parid = fep->id;
+       err = generate_fname(fep, FT_SUBVOL, &newf, &id, &v1);
+       v |= v1;
+       if (!err) {
+               if (v) {
+                       (void)fent_to_name(&f, fep);
+                       printf("%d/%d: snapshot - no filename from %s\n",
+                              procid, opno, f.path);
+               }
+               free_pathname(&f);
+               return;
+       }
+       e = btrfs_util_create_snapshot(f.path, newf.path, 0, NULL, NULL);
+       if (e == BTRFS_UTIL_OK)
+               add_to_flist(FT_SUBVOL, id, parid, 0);
+       if (v) {
+               printf("%d/%d: snapshot %s->%s %d(%s)\n", procid, opno,
+                      f.path, newf.path, e, btrfs_util_strerror(e));
+               printf("%d/%d: snapshot add id=%d,parent=%d\n", procid, opno,
+                      id, parid);
+       }
+       free_pathname(&newf);
+       free_pathname(&f);
+#endif
+}
+
 void
 stat_f(int opno, long r)
 {
@@ -2968,6 +4904,86 @@ stat_f(int opno, long r)
        free_pathname(&f);
 }
 
+void
+subvol_create_f(int opno, long r)
+{
+#ifdef HAVE_BTRFSUTIL_H
+       enum btrfs_util_error   e;
+       pathname_t              f;
+       fent_t                  *fep;
+       int                     id;
+       int                     parid;
+       int                     v;
+       int                     v1;
+       int                     err;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYDIR, r, NULL, NULL, &fep, &v))
+               parid = -1;
+       else
+               parid = fep->id;
+       err = generate_fname(fep, FT_SUBVOL, &f, &id, &v1);
+       v |= v1;
+       if (!err) {
+               if (v) {
+                       (void)fent_to_name(&f, fep);
+                       printf("%d/%d: subvol_create - no filename from %s\n",
+                              procid, opno, f.path);
+               }
+               free_pathname(&f);
+               return;
+       }
+       e = btrfs_util_create_subvolume(f.path, 0, NULL, NULL);
+       if (e == BTRFS_UTIL_OK)
+               add_to_flist(FT_SUBVOL, id, parid, 0);
+       if (v) {
+               printf("%d/%d: subvol_create %s %d(%s)\n", procid, opno,
+                      f.path, e, btrfs_util_strerror(e));
+               printf("%d/%d: subvol_create add id=%d,parent=%d\n", procid,
+                      opno, id, parid);
+       }
+       free_pathname(&f);
+#endif
+}
+
+void
+subvol_delete_f(int opno, long r)
+{
+#ifdef HAVE_BTRFSUTIL_H
+       enum btrfs_util_error   e;
+       pathname_t              f;
+       fent_t                  *fep;
+       int                     v;
+       int                     oldid;
+       int                     oldparid;
+
+       init_pathname(&f);
+       if (!get_fname(FT_SUBVOLm, r, &f, NULL, &fep, &v)) {
+               if (v)
+                       printf("%d:%d: subvol_delete - no subvolume\n", procid,
+                              opno);
+               free_pathname(&f);
+               return;
+       }
+       e = btrfs_util_delete_subvolume(f.path, 0);
+       check_cwd();
+       if (e == BTRFS_UTIL_OK) {
+               oldid = fep->id;
+               oldparid = fep->parent;
+               delete_subvol_children(oldid);
+               del_from_flist(FT_SUBVOL, fep - flist[FT_SUBVOL].fents);
+       }
+       if (v) {
+               printf("%d/%d: subvol_delete %s %d(%s)\n", procid, opno, f.path,
+                      e, btrfs_util_strerror(e));
+               if (e == BTRFS_UTIL_OK)
+                       printf("%d/%d: subvol_delete del entry: id=%d,parent=%d\n",
+                              procid, opno, oldid, oldparid);
+       }
+       free_pathname(&f);
+#endif
+}
+
 void
 symlink_f(int opno, long r)
 {
@@ -2982,7 +4998,7 @@ symlink_f(int opno, long r)
        int             v1;
        char            *val;
 
-       if (!get_fname(FT_DIRm, r, NULL, NULL, &fep, &v))
+       if (!get_fname(FT_ANYDIR, r, NULL, NULL, &fep, &v))
                parid = -1;
        else
                parid = fep->id;
@@ -2991,7 +5007,7 @@ symlink_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, fep);
                        printf("%d/%d: symlink - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -3008,7 +5024,7 @@ symlink_f(int opno, long r)
        e = symlink_path(val, &f) < 0 ? errno : 0;
        check_cwd();
        if (e == 0)
-               add_to_flist(FT_SYM, id, parid);
+               add_to_flist(FT_SYM, id, parid, 0);
        free(val);
        if (v) {
                printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
@@ -3031,7 +5047,7 @@ truncate_f(int opno, long r)
 {
        int             e;
        pathname_t      f;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -3054,7 +5070,7 @@ truncate_f(int opno, long r)
                return;
        }
        inode_info(st, sizeof(st), &stb, v);
-       lr = ((__int64_t)random() << 32) + random();
+       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;
@@ -3072,6 +5088,8 @@ unlink_f(int opno, long r)
        pathname_t      f;
        fent_t          *fep;
        flist_t         *flp;
+       int             oldid;
+       int             oldparid;
        int             v;
 
        init_pathname(&f);
@@ -3083,13 +5101,16 @@ unlink_f(int opno, long r)
        }
        e = unlink_path(&f) < 0 ? errno : 0;
        check_cwd();
-       if (e == 0)
+       if (e == 0) {
+               oldid = fep->id;
+               oldparid = fep->parent;
                del_from_flist(flp - flist, fep - flp->fents);
+       }
        if (v) {
                printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
                if (e == 0)
                        printf("%d/%d: unlink del entry: id=%d,parent=%d\n",
-                               procid, opno, fep->id, fep->parent);
+                               procid, opno, oldid, oldparid);
        }
        free_pathname(&f);
 }
@@ -3101,7 +5122,7 @@ unresvsp_f(int opno, long r)
        pathname_t      f;
        int             fd;
        struct xfs_flock64      fl;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -3133,7 +5154,7 @@ unresvsp_f(int opno, long r)
                return;
        }
        inode_info(st, sizeof(st), &stb, v);
-       lr = ((__int64_t)random() << 32) + random();
+       lr = ((int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        fl.l_whence = SEEK_SET;
@@ -3148,6 +5169,22 @@ unresvsp_f(int opno, long r)
        close(fd);
 }
 
+void
+uring_read_f(int opno, long r)
+{
+#ifdef URING
+       do_uring_rw(opno, r, O_RDONLY);
+#endif
+}
+
+void
+uring_write_f(int opno, long r)
+{
+#ifdef URING
+       do_uring_rw(opno, r, O_WRONLY);
+#endif
+}
+
 void
 write_f(int opno, long r)
 {
@@ -3156,7 +5193,7 @@ write_f(int opno, long r)
        pathname_t      f;
        int             fd;
        size_t          len;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
@@ -3188,7 +5225,7 @@ write_f(int opno, long r)
                return;
        }
        inode_info(st, sizeof(st), &stb, v);
-       lr = ((__int64_t)random() << 32) + random();
+       lr = ((int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        lseek64(fd, off, SEEK_SET);
@@ -3203,3 +5240,87 @@ write_f(int opno, long r)
        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);
+}
+
+char *
+xattr_flag_to_string(int flag)
+{
+       if (flag == XATTR_CREATE)
+               return "create";
+       if (flag == XATTR_REPLACE)
+               return "replace";
+       return "none";
+}