ltp/fsx: drop caches if we're doing closeopen
[xfstests-dev.git] / ltp / fsstress.c
index 45325a674649ef6530a9a9d1031b7710e51ba8af..709fdeec7f0d19acbd6b863c8a04c0988afe593c 100644 (file)
@@ -8,6 +8,7 @@
 #include <setjmp.h>
 #include <sys/uio.h>
 #include <stddef.h>
+#include <stdbool.h>
 #include "global.h"
 
 #ifdef HAVE_BTRFSUTIL_H
@@ -128,6 +129,7 @@ typedef enum {
        OP_SETATTR,
        OP_SETFATTR,
        OP_SETXATTR,
+       OP_SNAPSHOT,
        OP_SPLICE,
        OP_STAT,
        OP_SUBVOL_CREATE,
@@ -198,6 +200,7 @@ struct print_string {
 #define        FT_ANYm         ((1 << FT_nft) - 1)
 #define        FT_REGFILE      (FT_REGm | FT_RTFm)
 #define        FT_NOTDIR       (FT_ANYm & (~FT_DIRm & ~FT_SUBVOLm))
+#define        FT_ANYDIR       (FT_DIRm | FT_SUBVOLm)
 
 #define        FLIST_SLOT_INCR 16
 #define        NDCACHE 64
@@ -254,6 +257,7 @@ 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);
@@ -321,6 +325,7 @@ opdesc_t    ops[] = {
        { 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},
@@ -1902,6 +1907,7 @@ zero_freq(void)
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
 opty_t btrfs_ops[] = {
+       OP_SNAPSHOT,
        OP_SUBVOL_CREATE,
        OP_SUBVOL_DELETE,
 };
@@ -3160,7 +3166,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;
@@ -3724,7 +3730,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();
@@ -3756,7 +3762,7 @@ getfattr_f(int opno, long r)
        int             xattr_num;
 
        init_pathname(&f);
-       if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) {
+       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;
@@ -3875,7 +3881,7 @@ listfattr_f(int opno, long r)
        int             buffer_len;
 
        init_pathname(&f);
-       if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) {
+       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;
@@ -3925,7 +3931,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;
@@ -3963,7 +3969,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;
@@ -4321,7 +4327,7 @@ removefattr_f(int opno, long r)
        int             xattr_num;
 
        init_pathname(&f);
-       if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) {
+       if (!get_fname(FT_REGFILE | FT_ANYDIR, r, &f, NULL, &fep, &v)) {
                if (v)
                        printf("%d/%d: removefattr - no filename\n", procid, opno);
                goto out;
@@ -4641,7 +4647,7 @@ setfattr_f(int opno, long r)
        int             xattr_num;
 
        init_pathname(&f);
-       if (!get_fname(FT_REGFILE | FT_DIRm, r, &f, NULL, &fep, &v)) {
+       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;
@@ -4702,6 +4708,55 @@ out:
        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)
 {
@@ -4738,7 +4793,7 @@ subvol_create_f(int opno, long r)
        int                     err;
 
        init_pathname(&f);
-       if (!get_fname(FT_DIRm | FT_SUBVOLm, r, NULL, NULL, &fep, &v))
+       if (!get_fname(FT_ANYDIR, r, NULL, NULL, &fep, &v))
                parid = -1;
        else
                parid = fep->id;
@@ -4818,7 +4873,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;