diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-05-24 16:33:04 +0300 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2011-05-27 15:55:07 +0300 |
commit | d1921953032bfd8dc2750fbba7951abb25badd2c (patch) | |
tree | a4447085e512deed6cb1a02f083179c61b91e9df /tests | |
parent | ec5c7808c1f920d10f4a6a3c495679b7a7213df9 (diff) |
fs-tests: integck: introduce a helper function for dir sync
Add a helper 'sync_directory()' function to synchronize directories.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fs-tests/integrity/integck.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c index 4ca9386..045d63d 100644 --- a/tests/fs-tests/integrity/integck.c +++ b/tests/fs-tests/integrity/integck.c @@ -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; |