Skip to contentSkip to conversation

fs-tests: integck: check files in power cut testing

PATCH New Artem Bityutskiy 1 participant 12 messages May 17, 2011 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

cover fs-tests: integck: check files in power cut testing

When we are in power cut emulation testing, check the contents of files and directories which had been synchronized before the power cut - the contents should be intact. This series implements this feature plus does few cleanups and fixes which were spotted. As usually for the tests - the series is not perfect form the patch split/quality POW.

Artem.

#1 lore raw

PATCH 1/11 fs-tests: integck: introduce the clean flag

From: Artem Bityutskiy <[email protected]>

Introduce per-file "clean" flag which tells whether the file is synchronized or not. This flag is not really used so far.

---
 tests/fs-tests/integrity/integck.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
tests/fs-tests/integrity/integck.c +5 -1
index ac72c5b..9b98ef0 100644
@@ -156,6 +156,7 @@ struct file_info /* Each file has one of these */
 	int link_count;
 	unsigned int check_run_no; /* Run number used when checking */
 	unsigned int no_space_error:1; /* File has incurred a ENOSPC error */
+	unsigned int clean:1; /* Non-zero if the file is synchronized */
 };
 
 struct symlink_info /* Each symlink has one of these */
@@ -1192,6 +1193,8 @@ static int file_write(struct file_info *file, int fd)
 {
 	int ret;
 
+	file->clean = 0;
+
 	if (!args.power_cut_mode && fsinfo.can_mmap && !full &&
 	    file->link_count && random_no(100) == 1) {
 		/*
@@ -1260,6 +1263,7 @@ static int file_write(struct file_info *file, int fd)
 				pcv("fdatasync failed for %s",
 				    file->links->name);
 		}
+		file->clean = 1;
 	}
 
 	return 0;
@@ -1295,7 +1299,7 @@ static int file_truncate(struct file_info *file, int fd)
 	int ret;
 	size_t new_length = random_no(file->length);
 
-
+	file->clean = 0;
 	ret = file_ftruncate(file, fd, new_length);
 	if (ret == -1)
 		return -1;
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 2/11 fs-tests: integck: fix segfault

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Commit 1394a46213e8180e1233ca6d4811e7c77d49b1e0 was a good idea, but it introduced a segfault - files can be unlinked and 'file->links' is NULL, it is bad idea to unconditionally dereference it with 'file->links->name'. This patch introduces a helper function which takes care of the situation with unlinked files, plus it adds few assertions.

---
 tests/fs-tests/integrity/integck.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)
tests/fs-tests/integrity/integck.c +21 -7
index 9b98ef0..1b08acc 100644
@@ -837,6 +837,8 @@ static int file_open(struct file_info *file)
 	int fd, flags = O_RDWR;
 	char *path;
 
+	assert(file->links);
+
 	path = dir_path(file->links->parent, file->links->name);
 	if (random_no(100) == 1)
 		flags |= O_SYNC;
@@ -851,6 +853,13 @@ static int file_open(struct file_info *file)
 	return 0;
 }
 
+static const char *get_file_name(struct file_info *file)
+{
+	if (file->links)
+		return file->links->name;
+	return "(unlinked file, no names)";
+}
+
 /*
  * Write random 'size' bytes of random data to offset 'offset'. Seed the random
  * gererator with 'seed'. Return amount of written data on success and -1 on
@@ -890,7 +899,7 @@ static ssize_t file_write_data(struct file_info *file, int fd, off_t offset,
 			}
 			pcv("failed to write %zu bytes to offset %llu of file %s",
 			    block, (unsigned long long)(offset + actual),
-			    file->links->name);
+			    get_file_name(file));
 			return -1;
 		}
 		remains -= written;
@@ -1089,7 +1098,8 @@ static int file_ftruncate(struct file_info *file, int fd, off_t new_length)
 			return 1;
 		} else
 			pcv("cannot truncate file %s to %llu",
-			    file->links->name, (unsigned long long)new_length);
+			    get_file_name(file),
+			    (unsigned long long)new_length);
 		return -1;
 	}
 
@@ -1139,6 +1149,7 @@ static int file_mmap_write(struct file_info *file)
 		len = 1 << 24;
 
 	/* Open it */
+	assert(file->links);
 	path = dir_path(file->links->parent, file->links->name);
 	fd = open(path, O_RDWR);
 	if (fd == -1) {
@@ -1256,12 +1267,12 @@ static int file_write(struct file_info *file, int fd)
 		if (random_no(100) >= 50) {
 			ret = fsync(fd);
 			if (ret)
-				pcv("fsync failed for %s", file->links->name);
+				pcv("fsync failed for %s", get_file_name(file));
 		} else {
 			ret = fdatasync(fd);
 			if (ret)
 				pcv("fdatasync failed for %s",
-				    file->links->name);
+				    get_file_name(file));
 		}
 		file->clean = 1;
 	}
@@ -1278,6 +1289,7 @@ static int file_write_file(struct file_info *file)
 	int fd, ret;
 	char *path;
 
+	assert(file->links);
 	path = dir_path(file->links->parent, file->links->name);
 	fd = open(path, O_RDWR);
 	if (fd == -1) {
@@ -1314,6 +1326,7 @@ static int file_truncate_file(struct file_info *file)
 	char *path;
 	int ret;
 
+	assert(file->links);
 	path = dir_path(file->links->parent, file->links->name);
 	fd = open(path, O_WRONLY);
 	if (fd == -1) {
@@ -1394,7 +1407,7 @@ static void save_file(int fd, struct file_info *file)
 
 	/* Open file to save contents to */
 	strcpy(name, "/tmp/");
-	strcat(name, file->links->name);
+	strcat(name, get_file_name(file));
 	strcat(name, ".integ.sav.read");
 	normsg("Saving %sn", name);
 	w_fd = open(name, O_CREAT | O_WRONLY, 0777);
@@ -1414,7 +1427,7 @@ static void save_file(int fd, struct file_info *file)
 
 	/* Open file to save contents to */
 	strcpy(name, "/tmp/");
-	strcat(name, file->links->name);
+	strcat(name, get_file_name(file));
 	strcat(name, ".integ.sav.written");
 	normsg("Saving %s", name);
 	w_fd = open(name, O_CREAT | O_WRONLY, 0777);
@@ -1512,7 +1525,8 @@ static void file_check(struct file_info *file, int fd)
 		open_and_close = 1;
 	if (open_and_close) {
 		/* Open file */
-		path = dir_path(file->links->parent, file->links->name);
+		assert(file->links);
+		path = dir_path(file->links->parent, get_file_name(file));
 		fd = open(path, O_RDONLY);
 		CHECK(fd != -1);
 	}
Signature · 1 line
1.7.2.3
#3 lore raw

PATCH 3/11 fs-tests: integck: check errno in pvc macro

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

All errors but write errors have corresponding CHECK(), so if something gets wrong we fail. But in case of I/O errors we do not fail if an unexpected error happens, which makes it difficult to trace issues. Inject the errno checking to the pvc macro to make sure we fail if errno is not EROFS.

---
 tests/fs-tests/integrity/integck.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
tests/fs-tests/integrity/integck.c +8 -2
index 1b08acc..b411a68 100644
@@ -69,12 +69,18 @@
 		check_failed(stringify(cond), __func__, __FILE__, __LINE__); \
 } while(0)
 
+#define CHECK_ERRNO() do {                                                   \
+	if (args.power_cut_mode)                                             \
+		CHECK(errno == EROFS);                                       \
+	else                                                                 \
+		CHECK(0);                                                    \
+} while(0)
+
 #define pcv(fmt, ...) do {                                                   \
 	if (!args.power_cut_mode || (args.power_cut_mode && args.verbose))   \
 		normsg(fmt " (line %d, error %d (%s))",                      \
 		       ##__VA_ARGS__, __LINE__, errno, strerror(errno));     \
-	if (!args.power_cut_mode)                                            \
-		CHECK(0);                                                    \
+	CHECK_ERRNO();                                                       \
 } while(0)
 
 /* The variables below are set by command line arguments */
Signature · 1 line
1.7.2.3
#4 lore raw

PATCH 4/11 fs-tests: integck: check direntries in power cut mode

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Enable directory entry checking in power cut mode. This means that with this patch integck will check that all directory entries in the file-system were created by integck.

---
 tests/fs-tests/integrity/integck.c |   40 +++++++++--------------------------
 1 files changed, 11 insertions(+), 29 deletions(-)
tests/fs-tests/integrity/integck.c +11 -29
index b411a68..1483f62 100644
@@ -1662,8 +1662,6 @@ static void dir_check(struct dir_info *dir)
 	int link_count = 2; /* Parent and dot */
 	struct stat st;
 
-	assert(!args.power_cut_mode);
-
 	/* Create an array of entries */
 	sz = sizeof(struct dir_entry_info *);
 	n = dir->number_of_entries;
@@ -1700,7 +1698,14 @@ static void dir_check(struct dir_info *dir)
 		}
 	}
 	CHECK(closedir(d) == 0);
-	CHECK(checked == dir->number_of_entries);
+
+	/*
+	 * In power cut mode the file-system may miss some directory entries
+	 * because it is possible that they have not reached the media by the
+	 * time of the emulated power cut.
+	 */
+	if (!args.power_cut_mode)
+		CHECK(checked == dir->number_of_entries);
 
 	/* Now check each entry */
 	entry = dir->first;
@@ -2577,32 +2582,9 @@ static int remount_tested_fs(void)
 
 static void check_tested_fs(void)
 {
-	/*
-	 * when we are in power cut mode we can only test files which have not
-	 * been modified since the last successful 'fsync()'. this is not
-	 * implemented yet.
-	 *
-	 * note, even if we have not encounter any error during the test, we
-	 * cannot test the file-system. indeed, consider the situation when we
-	 * have written data to file a. a lot of the data is currently cached
-	 * and is waiting for write-back. when write-back happens, an emulated
-	 * power cut may also happen and cause write-back to drop the errored
-	 * pages. and if we start checking the file a after this, we'll fail as
-	 * well.
-	 *
-	 * and even re-mounting will not help, because re-mounting will cause
-	 * full sync which may fail and data pages will be dropped, but
-	 * 'unmount()' will nevertheless succeed, and if we check the
-	 * file-system after this - the check will fail.
-	 *
-	 * and 'sync()' will not help as well since it does not return an
-	 * error.
-	 */
-	if (!args.power_cut_mode) {
-		check_run_no += 1;
-		dir_check(top_dir);
-		check_deleted_files();
-	}
+	check_run_no += 1;
+	dir_check(top_dir);
+	check_deleted_files();
 }
 
 /*
Signature · 1 line
1.7.2.3
#5 lore raw

PATCH 5/11 fs-tests: integck: make -v work -e

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Make the verify option -v work with power cut emulation option -e. We can verify all operations except of writing to the file, because of write-back. Indeed, even if we write successfully, the pages may still be in the page-cache and if an emulated power cut happens they will be dropped, and our verification will fail.

I am not 100% sure it is save to verify non-write operation in other FSes, but only UBIFS has power cut emulation mode now, so we do not really care about other FSes at this point.

---
 tests/fs-tests/integrity/integck.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)
tests/fs-tests/integrity/integck.c +13 -13
index 1483f62..944ff3c 100644
@@ -552,7 +552,7 @@ static int dir_new(struct dir_info *parent, const char *name)
 		return -1;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		struct stat st;
 
 		CHECK(lstat(path, &st) == 0);
@@ -598,7 +598,7 @@ static int dir_remove(struct dir_info *dir)
 		return -1;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		struct stat st;
 
 		CHECK(lstat(path, &st) == -1);
@@ -635,7 +635,7 @@ static int file_new(struct dir_info *parent, const char *name)
 		return -1;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		struct stat st;
 
 		CHECK(lstat(path, &st) == 0);
@@ -663,7 +663,7 @@ static int link_new(struct dir_info *parent, const char *name,
 	path = dir_path(parent, name);
 	target = dir_path(entry->parent, entry->name);
 
-	if (args.verify_ops && !args.power_cut_mode)
+	if (args.verify_ops)
 		CHECK(lstat(target, &st1) == 0);
 
 	ret = link(target, path);
@@ -679,7 +679,7 @@ static int link_new(struct dir_info *parent, const char *name,
 		return ret;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		CHECK(lstat(path, &st2) == 0);
 		CHECK(S_ISREG(st2.st_mode));
 		CHECK(st1.st_ino == st2.st_ino);
@@ -725,7 +725,7 @@ static int file_unlink(struct dir_entry_info *entry)
 		return -1;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		struct stat st;
 
 		CHECK(lstat(path, &st) == -1);
@@ -1109,7 +1109,7 @@ static int file_ftruncate(struct file_info *file, int fd, off_t new_length)
 		return -1;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode)
+	if (args.verify_ops)
 		CHECK(lseek(fd, 0, SEEK_END) == new_length);
 
 	return 0;
@@ -1914,7 +1914,7 @@ static int rename_entry(struct dir_entry_info *entry)
 	if (!path)
 		return 0;
 
-	if (args.verify_ops && !args.power_cut_mode)
+	if (args.verify_ops)
 		CHECK(lstat(path, &st1) == 0);
 
 	ret = rename(path, to);
@@ -1932,7 +1932,7 @@ static int rename_entry(struct dir_entry_info *entry)
 		return ret;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		CHECK(lstat(to, &st2) == 0);
 		CHECK(st1.st_ino == st2.st_ino);
 	}
@@ -2074,7 +2074,7 @@ static int symlink_new(struct dir_info *dir, const char *nm)
 		return ret;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode)
+	if (args.verify_ops)
 		verify_symlink(target, path);
 
 	s = add_dir_entry(dir, 's', name, NULL);
@@ -2096,7 +2096,7 @@ static int symlink_remove(struct symlink_info *symlink)
 		return -1;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		struct stat st;
 
 		CHECK(lstat(path, &st) == -1);
@@ -2434,7 +2434,7 @@ static int rm_minus_rf_dir(const char *dir_name)
 	CHECK(chdir(buf) == 0);
 	CHECK(closedir(dir) == 0);
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		dir = opendir(dir_name);
 		CHECK(dir != NULL);
 		do {
@@ -2454,7 +2454,7 @@ static int rm_minus_rf_dir(const char *dir_name)
 		return -1;
 	}
 
-	if (args.verify_ops && !args.power_cut_mode) {
+	if (args.verify_ops) {
 		struct stat st;
 
 		CHECK(lstat(dir_name, &st) == -1);
Signature · 1 line
1.7.2.3
#6 lore raw

PATCH 6/11 fs-tests: integck: verify clean files

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Allow verification for clean files, i.e. the files which had been fsync()'ed before the emulated power cut happened.

---
 tests/fs-tests/integrity/integck.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
tests/fs-tests/integrity/integck.c +7 -2
index 944ff3c..221bd49 100644
@@ -1481,7 +1481,8 @@ static void file_check_data(struct file_info *file, int fd,
 	char buf[IO_BUFFER_SIZE];
 	unsigned int seed = w->random_seed;
 
-	assert(!args.power_cut_mode);
+	if (args.power_cut_mode && !file->clean)
+		return;
 
 	for (r = 0; r < w->random_offset; ++r)
 		rand_r(&seed);
@@ -1517,7 +1518,11 @@ static void file_check(struct file_info *file, int fd)
 	struct dir_entry_info *entry;
 	struct stat st;
 
-	if (args.power_cut_mode)
+	/*
+	 * In case of power cut emulation testing check only clean files, i.e.
+	 * the files which have not been modified since last 'fsync()'.
+	 */
+	if (args.power_cut_mode && !file->clean)
 		return;
 
 	/* Do not check files that have errored */
Signature · 1 line
1.7.2.3
#7 lore raw

PATCH 7/11 fs-tests: integck: fsync more often

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Currently integck calls 'fsync()' very rarely - with 0.1% probability. Make this happen more often - with 1% probability.

---
 tests/fs-tests/integrity/integck.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tests/fs-tests/integrity/integck.c +1 -1
index 221bd49..81d384f 100644
@@ -1269,7 +1269,7 @@ static int file_write(struct file_info *file, int fd)
 	}
 
 	/* Sync sometimes */
-	if (random_no(1000) >= 999) {
+	if (random_no(100) >= 99) {
 		if (random_no(100) >= 50) {
 			ret = fsync(fd);
 			if (ret)
Signature · 1 line
1.7.2.3
#8 lore raw

PATCH 8/11 fs-tests: integck: return error if fsync fails

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

If 'fsync()' or 'fdatasync()' fail we have to return an error, but we by mistake were returning 0 (success).

---
 tests/fs-tests/integrity/integck.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tests/fs-tests/integrity/integck.c +2 -0
index 81d384f..83706f8 100644
@@ -1280,6 +1280,8 @@ static int file_write(struct file_info *file, int fd)
 				pcv("fdatasync failed for %s",
 				    get_file_name(file));
 		}
+		if (ret)
+			return -1;
 		file->clean = 1;
 	}
 
Signature · 1 line
1.7.2.3
#9 lore raw

PATCH 9/11 fs-tests: integck: fsync directories as well

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Call 'fsync()' for directories sometimes as well, and check synchronized directories after re-mount - cound of directory entries has to be correct.

---
 tests/fs-tests/integrity/integck.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)
tests/fs-tests/integrity/integck.c +35 -1
index 83706f8..84e3bef 100644
@@ -178,6 +178,7 @@ struct dir_info /* Each directory has one of these */
 	unsigned int number_of_entries;
 	struct dir_entry_info *first;
 	struct dir_entry_info *entry; /* Dir entry of this dir */
+	unsigned int clean:1; /* Non-zero if the directory is synchronized */
 };
 
 struct dir_entry_info /* Each entry in a directory has one of these */
@@ -452,6 +453,7 @@ static void *add_dir_entry(struct dir_info *parent, char type, const char *name,
 		parent->first->prev = entry;
 	parent->first = entry;
 	parent->number_of_entries += 1;
+	parent->clean = 0;
 
 	if (entry->type == 'f') {
 		struct file_info *file = target;
@@ -488,6 +490,7 @@ static void *add_dir_entry(struct dir_info *parent, char type, const char *name,
 
 static void remove_dir_entry(struct dir_entry_info *entry, int free_target)
 {
+	entry->parent->clean = 0;
 	entry->parent->number_of_entries -= 1;
 	if (entry->parent->first == entry)
 		entry->parent->first = entry->next;
@@ -1711,7 +1714,7 @@ static void dir_check(struct dir_info *dir)
 	 * because it is possible that they have not reached the media by the
 	 * time of the emulated power cut.
 	 */
-	if (!args.power_cut_mode)
+	if (!args.power_cut_mode || dir->clean)
 		CHECK(checked == dir->number_of_entries);
 
 	/* Now check each entry */
@@ -2232,6 +2235,37 @@ static int operate_on_dir(struct dir_info *dir)
 			ret = operate_on_entry(entry);
 	}
 
+	if (ret)
+		return ret;
+
+	/* 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);
+		free(path);
+		if (!ret)
+			dir->clean = 1;
+	}
+
 	return ret;
 }
 
Signature · 1 line
1.7.2.3
#10 lore raw

PATCH 10/11 fs-tests: integck: verify truncation only if -v option was given

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

Currently we always verify holes when truncating, but we have -v switch for this and should do this only if -v was given.

---
 tests/fs-tests/integrity/integck.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
tests/fs-tests/integrity/integck.c +2 -1
index 84e3bef..2140a1b 100644
@@ -1082,7 +1082,8 @@ static void file_truncate_info(struct file_info *file, int fd,
 	w->random_seed = MAX_RANDOM_SEED + 1;
 	file->raw_writes = w;
 
-	if (new_length > file->length)
+	if (args.verify_ops && !args.power_cut_mode &&
+	    new_length > file->length)
 		file_check_hole(file, fd, file->length,
 				new_length - file->length);
 
Signature · 1 line
1.7.2.3
#11 lore raw

PATCH 11/11 fs-tests: integck: read all files in power cut mode

In reply to Artem Bityutskiy

From: Artem Bityutskiy <[email protected]>

When we are in power cut mode read all files after re-mounting. This will check that FS recovery worked well and all files are readable after recovery.

---
 tests/fs-tests/integrity/integck.c |   76 +++++++++++++++++++++++++++++++++--
 1 files changed, 71 insertions(+), 5 deletions(-)
tests/fs-tests/integrity/integck.c +71 -5
index 2140a1b..c2bf964 100644
@@ -1538,10 +1538,9 @@ static void file_check(struct file_info *file, int fd)
 	if (file->check_run_no == check_run_no)
 		return;
 	file->check_run_no = check_run_no;
-	if (fd == -1)
-		open_and_close = 1;
-	if (open_and_close) {
+	if (fd == -1) {
 		/* Open file */
+		open_and_close = 1;
 		assert(file->links);
 		path = dir_path(file->links->parent, get_file_name(file));
 		fd = open(path, O_RDONLY);
@@ -2630,6 +2629,73 @@ static void check_tested_fs(void)
 }
 
 /*
+ * This is a helper function which just reads whole file. We do this in case of
+ * emulated power cuts testing to make sure that unclean files can be at least
+ * read.
+ */
+static void read_whole_file(const char *name)
+{
+	size_t rd;
+	char buf[IO_BUFFER_SIZE];
+	int fd;
+
+	fd = open(name, O_RDONLY);
+	CHECK(fd != -1);
+
+	do {
+		rd = read(fd, buf, IO_BUFFER_SIZE);
+		CHECK(rd != -1);
+	} while (rd);
+
+	close(fd);
+}
+
+/*
+ * Recursively walk whole tested file-system and make sure we can read
+ * everything. This is done in case of power cuts emulation testing to ensure
+ * that everything in the file-system is readable.
+ */
+static void read_all(const char *dir_name)
+{
+	DIR *dir;
+	struct dirent *dent;
+	char buf[PATH_MAX];
+
+	assert(args.power_cut_mode);
+
+	dir = opendir(dir_name);
+	CHECK(dir != NULL);
+	CHECK(getcwd(buf, PATH_MAX) != NULL);
+	CHECK(chdir(dir_name) == 0);
+
+	for (;;) {
+		errno = 0;
+		dent = readdir(dir);
+		if (!dent) {
+			CHECK(errno == 0);
+			break;
+		}
+
+		if (!strcmp(dent->d_name, ".") ||
+		    !strcmp(dent->d_name, ".."))
+			continue;
+
+		if (dent->d_type == DT_DIR)
+			read_all(dent->d_name);
+		else if (dent->d_type == DT_REG)
+			read_whole_file(dent->d_name);
+		else if (dent->d_type == DT_LNK) {
+			char b[IO_BUFFER_SIZE];
+
+			CHECK(readlink(dent->d_name, b, IO_BUFFER_SIZE) != -1);
+		}
+	}
+
+	CHECK(chdir(buf) == 0);
+	CHECK(closedir(dir) == 0);
+}
+
+/*
  * Perform the test. Returns zero on success and -1 on failure.
  */
 static int integck(void)
@@ -2641,8 +2707,9 @@ static int integck(void)
 
 	/* Create our top directory */
 	if (chdir(fsinfo.test_dir) == 0) {
-		/* Remove it if it is already there */
 		CHECK(chdir("..") == 0);
+		if (args.power_cut_mode)
+			read_all(fsinfo.test_dir);
 		ret = rm_minus_rf_dir(fsinfo.test_dir);
 		if (ret)
 			return -1;
@@ -2974,7 +3041,6 @@ static void free_fs_info(struct dir_info *dir)
 			assert(0);
 	}
 }
-
 /**
  * Recover the tested file-system from an emulated power cut failure by
  * unmounting it and mounting it again.
Signature · 1 line
1.7.2.3