]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: read all files in power cut mode
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tue, 17 May 2011 07:28:00 +0000 (10:28 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 20 May 2011 09:48:42 +0000 (12:48 +0300)
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.

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

index 2140a1ba0ea18ebf2911dc58541bcc0850b31315..c2bf964a4e2abd7b964698d8560d7ec8339be415 100644 (file)
@@ -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);
@@ -2629,6 +2628,73 @@ static void check_tested_fs(void)
        check_deleted_files();
 }
 
+/*
+ * 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.
  */
@@ -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.