]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: introduce a helper function for dir sync
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tue, 24 May 2011 13:33:04 +0000 (16:33 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 27 May 2011 12:55:07 +0000 (15:55 +0300)
Add a helper 'sync_directory()' function to synchronize directories.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
tests/fs-tests/integrity/integck.c

index 4ca93869fb16f0f305fe57a01c578f1f05feec97..045d63db5028f358afb558fd3ed8d91fd2a7e2c9 100644 (file)
@@ -2212,6 +2212,30 @@ static int operate_on_entry(struct dir_entry_info *entry)
        return ret;
 }
 
+/* Synchronize a directory */
+static int sync_directory(const char *path)
+{
+       int fd, ret;
+
+       fd = open(path, O_RDONLY);
+       if (fd == -1) {
+               pcv("cannot open directory %s", path);
+               return -1;
+       }
+
+       if (random_no(100) >= 50) {
+               ret = fsync(fd);
+               if (ret)
+                       pcv("directory fsync failed for %s", path);
+       } else {
+               ret = fdatasync(fd);
+               if (ret)
+                       pcv("directory fdatasync failed for %s", path);
+       }
+       close(fd);
+       return ret;
+}
+
 /*
  * Randomly select something to do with a directory.
  */
@@ -2253,26 +2277,9 @@ static int operate_on_dir(struct dir_info *dir)
        /* Synchronize the directory sometimes */
        if (random_no(100) >= 99) {
                char *path;
-               int fd;
 
                path = dir_path(dir->parent, dir->entry->name);
-               fd = open(path, O_RDONLY);
-               if (fd == -1) {
-                       pcv("cannot open directory %s", path);
-                       free(path);
-                       return -1;
-               }
-
-               if (random_no(100) >= 50) {
-                       ret = fsync(fd);
-                       if (ret)
-                               pcv("directory fsync failed for %s", path);
-               } else {
-                       ret = fdatasync(fd);
-                       if (ret)
-                               pcv("directory fdatasync failed for %s", path);
-               }
-               close(fd);
+               ret = sync_directory(path);
                free(path);
                if (!ret)
                        dir->clean = 1;