fsstress: allow fsync on directories too
authorFilipe Manana <fdmanana@suse.com>
Thu, 4 Apr 2019 16:29:52 +0000 (17:29 +0100)
committerEryu Guan <guaneryu@gmail.com>
Fri, 19 Apr 2019 07:25:01 +0000 (15:25 +0800)
Currently the fsync function can only be performed against regular files.
Allow it to operate on directories too, to increase test coverage and
allow for chances of finding bugs in a filesystem's implementation of
fsync against directories.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
ltp/fsstress.c

index 41a0155e1067ab10effbf210cff827404a726958..72c574daa619c6a9af8984470df5da7dffa0ee00 100644 (file)
@@ -324,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    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    open_path(pathname_t *, int);
 DIR    *opendir_path(pathname_t *);
 void   process_freq(char *);
@@ -1384,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. */
+       flags &= ~O_WRONLY;
+       flags |= O_RDONLY | O_DIRECTORY;
+       return open_path(name, flags);
+}
+
 int
 open_path(pathname_t *name, int oflag)
 {
 int
 open_path(pathname_t *name, int oflag)
 {
@@ -3455,13 +3472,13 @@ fsync_f(int opno, long r)
        int             v;
 
        init_pathname(&f);
        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;
        }
                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) {
        e = fd < 0 ? errno : 0;
        check_cwd();
        if (fd < 0) {