]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: do not assume the FS is mounted after failure
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Thu, 21 Apr 2011 05:13:21 +0000 (08:13 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 22 Apr 2011 11:29:53 +0000 (14:29 +0300)
If a power cut emulation error happens and we are trying to re-mount
the file-system, do not assume it is mounted because the failure could
have happened after it had had been unmounted but before it was
successfully mounted.

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

index 18164611489e9460fc8ab935fa3718190235c827..8703355dafd7b92bc89da95c1e80a2a8056b7714 100644 (file)
@@ -2492,6 +2492,31 @@ static void parse_mount_options(const char *mount_opts)
        fsinfo.mount_opts = opts;
 }
 
+/*
+ * This is a helper function which searches for the tested file-system mount
+ * description.
+ */
+static struct mntent *get_tested_fs_mntent(void)
+{
+       const char *mp;
+       struct mntent *mntent;
+        FILE *f;
+
+       mp = "/proc/mounts";
+        f = fopen(mp, "rb");
+        if (!f) {
+               mp = "/etc/mtab";
+                f = fopen(mp, "rb");
+       }
+       CHECK(f != NULL);
+
+        while ((mntent = getmntent(f)) != NULL)
+               if (!strcmp(mntent->mnt_dir, fsinfo.mount_point))
+                       break;
+        fclose(f);
+       return mntent;
+}
+
 /*
  * Fill 'fsinfo' with information about the tested file-system.
  */
@@ -2499,8 +2524,6 @@ static void get_tested_fs_info(void)
 {
        struct statfs fs_info;
        struct mntent *mntent;
-       const char *mp;
-        FILE *f;
        uint64_t z;
        char *p;
        unsigned int pid;
@@ -2516,25 +2539,11 @@ static void get_tested_fs_info(void)
        CHECK(statfs(fsinfo.mount_point, &fs_info) == 0);
        fsinfo.max_name_len = fs_info.f_namelen;
 
-       mp = "/proc/mounts";
-        f = fopen(mp, "rb");
-        if (!f) {
-               mp = "/etc/mtab";
-                f = fopen(mp, "rb");
+       mntent = get_tested_fs_mntent();
+       if (!mntent) {
+               errmsg("cannot find file-system info");
+               CHECK(0);
        }
-       CHECK(f != NULL);
-
-        while (1) {
-               mntent = getmntent(f);
-                if (!mntent) {
-                       errmsg("cannot find file-system info");
-                       CHECK(0);
-               }
-
-               if (!strcmp(mntent->mnt_dir, fsinfo.mount_point))
-                       break;
-        }
-        fclose(f);
 
        fsinfo.fstype = dup_string(mntent->mnt_type);
        fsinfo.fsdev = dup_string(mntent->mnt_fsname);
@@ -2701,6 +2710,7 @@ static int recover_tested_fs(void)
        int ret;
        unsigned long flags;
        unsigned int  um_rorw, rorw2;
+       struct mntent *mntent;
 
        /* Save current working directory */
        wd_save = malloc(PATH_MAX + 1);
@@ -2714,7 +2724,14 @@ static int recover_tested_fs(void)
        um_rorw = rand() & 1;
        rorw2 = rand() & 1;
 
-       CHECK(umount(fsinfo.mount_point) != -1);
+       /*
+        * At this point we do not know for sure whether the tested FS is
+        * mounted, because the emulated power cut error could have happened
+        * while mounting in 'remount_tested_fs()'.
+        */
+       mntent = get_tested_fs_mntent();
+       if (mntent)
+               CHECK(umount(fsinfo.mount_point) != -1);
 
        if (!um_rorw) {
                ret = mount(fsinfo.fsdev, fsinfo.mount_point,