fsstress: allow afsync on directories too
[xfstests-dev.git] / ltp / fsstress.c
index 96f48b1c27f2f047c15fc4294653c0ac4ddf1c61..3ec1914305ff2e1ad909e359f48e170a6f1b5712 100644 (file)
@@ -1,29 +1,15 @@
+// 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 "global.h"
 
-#ifdef HAVE_ATTR_XATTR_H
-#include <attr/xattr.h>
-#endif
 #ifdef HAVE_ATTR_ATTRIBUTES_H
 #include <attr/attributes.h>
 #endif
@@ -40,6 +26,7 @@
 #include <libaio.h>
 io_context_t   io_ctx;
 #endif
+#include <sys/syscall.h>
 
 #ifndef FS_IOC_GETFLAGS
 #define FS_IOC_GETFLAGS                 _IOR('f', 1, long)
@@ -68,7 +55,10 @@ typedef enum {
        OP_BULKSTAT,
        OP_BULKSTAT1,
        OP_CHOWN,
+       OP_CLONERANGE,
+       OP_COPYRANGE,
        OP_CREAT,
+       OP_DEDUPERANGE,
        OP_DREAD,
        OP_DWRITE,
        OP_FALLOCATE,
@@ -95,6 +85,7 @@ typedef enum {
        OP_RMDIR,
        OP_SETATTR,
        OP_SETXATTR,
+       OP_SPLICE,
        OP_STAT,
        OP_SYMLINK,
        OP_SYNC,
@@ -174,7 +165,10 @@ 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);
@@ -201,6 +195,7 @@ void        resvsp_f(int, long);
 void   rmdir_f(int, long);
 void   setattr_f(int, long);
 void   setxattr_f(int, long);
+void   splice_f(int, long);
 void   stat_f(int, long);
 void   symlink_f(int, long);
 void   sync_f(int, long);
@@ -221,7 +216,10 @@ opdesc_t   ops[] = {
        { 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 },
@@ -248,6 +246,7 @@ opdesc_t    ops[] = {
        { OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
        { OP_SETATTR, "setattr", setattr_f, 0, 1 },
        { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
+       { OP_SPLICE, "splice", splice_f, 1, 1 },
        { OP_STAT, "stat", stat_f, 1, 0 },
        { OP_SYMLINK, "symlink", symlink_f, 2, 1 },
        { OP_SYNC, "sync", sync_f, 1, 1 },
@@ -325,6 +324,7 @@ 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 *);
@@ -495,7 +495,7 @@ int main(int argc, char **argv)
 
        (void)mkdir(dirname, 0777);
        if (logname && logname[0] != '/') {
-               if (getcwd(rpath, sizeof(rpath)) < 0){
+               if (!getcwd(rpath, sizeof(rpath))){
                        perror("getcwd failed");
                        exit(1);
                }
@@ -507,7 +507,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");
@@ -591,7 +591,7 @@ int main(int argc, char **argv)
                                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) {
@@ -614,6 +614,9 @@ int main(int argc, char **argv)
                                return 1;
                        }
 #endif
+
+                       cleanup_flist();
+                       free(freq_table);
                        return 0;
                }
        }
@@ -640,6 +643,7 @@ int main(int argc, char **argv)
                close(fd);
        }
 
+       free(freq_table);
        unlink(buf);
        return 0;
 }
@@ -737,7 +741,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 */
        }
@@ -769,7 +773,7 @@ attr_list_path(pathname_t *name,
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = attr_list_path(&newname, buffer, buffersize, flags, cursor);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -788,7 +792,7 @@ attr_remove_path(pathname_t *name, const char *attrname, int flags)
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
                rval = attr_remove_path(&newname, attrname, flags);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -809,7 +813,7 @@ attr_set_path(pathname_t *name, const char *attrname, const char *attrvalue,
        if (chdir(buf) == 0) {
                rval = attr_set_path(&newname, attrname, attrvalue, valuelength,
                        flags);
-               chdir("..");
+               assert(chdir("..") == 0);
        }
        free_pathname(&newname);
        return rval;
@@ -823,7 +827,7 @@ 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 */
@@ -862,7 +866,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;
@@ -966,6 +970,10 @@ doproc(void)
        }
        top_ino = statbuf.st_ino;
        homedir = getcwd(NULL, 0);
+       if (!homedir) {
+               perror("getcwd failed");
+               _exit(1);
+       }
        seed += procid;
        srandom(seed);
        if (namerand)
@@ -996,10 +1004,15 @@ 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();
        }
 }
@@ -1215,7 +1228,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;
@@ -1239,7 +1252,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)
@@ -1259,7 +1272,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);
@@ -1267,7 +1280,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);
                        }
                }
        }
@@ -1289,7 +1302,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;
@@ -1325,7 +1338,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;
@@ -1344,7 +1357,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;
@@ -1372,6 +1385,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)
 {
@@ -1385,7 +1414,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;
@@ -1404,7 +1433,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;
@@ -1445,7 +1474,7 @@ 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;
@@ -1469,7 +1498,7 @@ rename_path(pathname_t *name1, pathname_t *name2)
        if (strcmp(buf1, buf2) == 0) {
                if (chdir(buf1) == 0) {
                        rval = rename_path(&newname1, &newname2);
-                       chdir("..");
+                       assert(chdir("..") == 0);
                }
        } else {
                if (strcmp(buf1, "..") == 0)
@@ -1489,7 +1518,7 @@ rename_path(pathname_t *name1, pathname_t *name2)
                        append_pathname(&newname2, name2->path);
                        if (chdir(buf1) == 0) {
                                rval = rename_path(&newname1, &newname2);
-                               chdir("..");
+                               assert(chdir("..") == 0);
                        }
                } else {
                        free_pathname(&newname1);
@@ -1497,7 +1526,7 @@ rename_path(pathname_t *name1, pathname_t *name2)
                        append_pathname(&newname1, name1->path);
                        if (chdir(buf2) == 0) {
                                rval = rename_path(&newname1, &newname2);
-                               chdir("..");
+                               assert(chdir("..") == 0);
                        }
                }
        }
@@ -1519,7 +1548,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;
@@ -1602,7 +1631,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;
@@ -1626,7 +1655,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;
@@ -1645,7 +1674,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;
@@ -1664,7 +1693,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;
@@ -1745,13 +1774,13 @@ afsync_f(int opno, long r)
        struct io_event event;
 
        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: afsync - no filename\n", procid, opno);
                free_pathname(&f);
                return;
        }
-       fd = open_path(&f, O_WRONLY | O_DIRECT);
+       fd = open_file_or_dir(&f, O_WRONLY | O_DIRECT);
        e = fd < 0 ? errno : 0;
        check_cwd();
        if (fd < 0) {
@@ -1795,7 +1824,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;
@@ -1827,7 +1856,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;
@@ -1846,14 +1875,14 @@ allocsp_f(int opno, long r)
 void
 do_aio_rw(int opno, long r, int flags)
 {
-       __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;
@@ -1910,8 +1939,8 @@ do_aio_rw(int opno, long r, int flags)
        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();
        len = (random() % FILELEN_MAX) + 1;
        len -= (len % align);
        if (len <= 0)
@@ -2086,7 +2115,7 @@ bulkstat_f(int opno, long r)
        __u64           last;
        int             nent;
        xfs_bstat_t     *t;
-       __int64_t       total;
+       int64_t         total;
         xfs_fsop_bulkreq_t bsr;
 
        last = 0;
@@ -2189,6 +2218,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)
 {
@@ -2225,6 +2797,177 @@ setxattr_f(int opno, long r)
 #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));
+
+       /*
+        * 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;
+               }
+       }
+
+       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 (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
 creat_f(int opno, long r)
 {
@@ -2301,14 +3044,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;
@@ -2363,8 +3106,8 @@ dread_f(int opno, long r)
        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);
@@ -2387,14 +3130,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;
@@ -2440,8 +3183,8 @@ dwrite_f(int opno, long r)
        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);
@@ -2487,7 +3230,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;
@@ -2519,7 +3262,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));
@@ -2602,7 +3345,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;
@@ -2646,14 +3389,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)
@@ -2674,7 +3417,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;
@@ -2706,7 +3449,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;
@@ -2729,13 +3472,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) {
@@ -2949,7 +3692,7 @@ do_mmap(int opno, long r, int prot)
        pathname_t      f;
        int             fd;
        size_t          len;
-       __int64_t       lr;
+       int64_t         lr;
        off64_t         off;
        int             flags;
        struct stat64   stb;
@@ -2992,7 +3735,7 @@ do_mmap(int opno, long r, int prot)
                return;
        }
 
-       lr = ((__int64_t)random() << 32) + random();
+       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;
@@ -3094,7 +3837,7 @@ read_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;
@@ -3134,7 +3877,7 @@ read_f(int opno, long r)
                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;
@@ -3178,7 +3921,7 @@ readv_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;
@@ -3223,7 +3966,7 @@ readv_f(int opno, long r)
                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;
@@ -3325,7 +4068,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;
@@ -3357,7 +4100,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;
@@ -3509,7 +4252,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;
@@ -3532,7 +4275,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;
@@ -3579,7 +4322,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;
@@ -3611,7 +4354,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;
@@ -3634,7 +4377,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;
@@ -3666,7 +4409,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);
@@ -3690,7 +4433,7 @@ writev_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;
@@ -3727,7 +4470,7 @@ writev_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);