]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: Refactor: split out common remount logic
authorCsókás, Bence <csokas.bence@prolan.hu>
Mon, 26 Aug 2024 11:24:59 +0000 (13:24 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 25 Sep 2024 05:51:11 +0000 (07:51 +0200)
remount_tested_fs() and recover_tested_fs() both have
almost the same code for remounting the target FS
RO then RW. Split this sequence into a new
function called remount_ro_rw().

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Link: https://lore.kernel.org/linux-mtd/5530437c-b564-461f-26af-85bde1a00cb3@huawei.com/T/#mad1d043095b3f64a1f1eddd2d87b1545e329e141
Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
tests/fs-tests/integrity/integck.c

index ad076b5ad5788a6f7f0359fb8a3982e14d277c57..4a6ef1665651fac42967a0f88d9ce82cad98da38 100644 (file)
@@ -2664,6 +2664,35 @@ static int umount_and_remount(int mounted, int reatt, int um_rorw)
        return 0;
 }
 
+/**
+ * Remount the test file-system RO first, then RW.
+ */
+static int remount_ro_rw(const char *tries)
+{
+       int ret;
+       unsigned long flags;
+
+       flags = fsinfo.mount_flags | MS_RDONLY | MS_REMOUNT;
+       ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
+                   flags, fsinfo.mount_opts);
+       if (ret) {
+               pcv("cannot remount %s R/O%s", tries, fsinfo.mount_point);
+               return -1;
+       }
+
+       flags = fsinfo.mount_flags | MS_REMOUNT;
+       flags &= ~((unsigned long)MS_RDONLY);
+       ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
+                   flags, fsinfo.mount_opts);
+       if (ret) {
+               pcv("remounted %s R/O%s, but cannot re-mount it R/W",
+                   tries, fsinfo.mount_point);
+               return -1;
+       }
+
+       return 0;
+}
+
 /**
  * Re-mount the test file-system. This function randomly select how to
  * re-mount.
@@ -2688,24 +2717,9 @@ static int remount_tested_fs(void)
                um = 1;
 
        if (rorw1) {
-               flags = fsinfo.mount_flags | MS_RDONLY | MS_REMOUNT;
-               ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
-                           flags, fsinfo.mount_opts);
-               if (ret) {
-                       pcv("cannot remount %s R/O (1)",
-                           fsinfo.mount_point);
-                       return -1;
-               }
-
-               flags = fsinfo.mount_flags | MS_REMOUNT;
-               flags &= ~((unsigned long)MS_RDONLY);
-               ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
-                           flags, fsinfo.mount_opts);
-               if (ret) {
-                       pcv("remounted %s R/O (1), but cannot re-mount it R/W",
-                           fsinfo.mount_point);
+               ret = remount_ro_rw(" (1)");
+               if (ret)
                        return -1;
-               }
        }
 
        if (um) {
@@ -2726,23 +2740,9 @@ static int remount_tested_fs(void)
        }
 
        if (rorw2) {
-               flags = fsinfo.mount_flags | MS_RDONLY | MS_REMOUNT;
-               ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
-                           flags, fsinfo.mount_opts);
-               if (ret) {
-                       pcv("cannot re-mount %s R/O (3)", fsinfo.mount_point);
-                       return -1;
-               }
-
-               flags = fsinfo.mount_flags | MS_REMOUNT;
-               flags &= ~((unsigned long)MS_RDONLY);
-               ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
-                           flags, fsinfo.mount_opts);
-               if (ret) {
-                       pcv("remounted %s R/O (3), but cannot re-mount it back R/W",
-                            fsinfo.mount_point);
+               ret = remount_ro_rw(" (3)");
+               if (ret)
                        return -1;
-               }
        }
 
        CHECK(chdir(fsinfo.mount_point) == 0);
@@ -3205,7 +3205,6 @@ static void free_fs_info(struct dir_info *dir)
 static int recover_tested_fs(void)
 {
        int ret;
-       unsigned long flags;
        unsigned int  um_rorw, rorw2;
        struct mntent *mntent;
 
@@ -3227,23 +3226,9 @@ static int recover_tested_fs(void)
                return -1;
 
        if (rorw2) {
-               flags = fsinfo.mount_flags | MS_RDONLY | MS_REMOUNT;
-               ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
-                           flags, fsinfo.mount_opts);
-               if (ret) {
-                       pcv("cannot re-mount %s R/O", fsinfo.mount_point);
-                       return -1;
-               }
-
-               flags = fsinfo.mount_flags | MS_REMOUNT;
-               flags &= ~((unsigned long)MS_RDONLY);
-               ret = mount(fsinfo.fsdev, fsinfo.mount_point, fsinfo.fstype,
-                           flags, fsinfo.mount_opts);
-               if (ret) {
-                       pcv("remounted %s R/O, but cannot re-mount it back R/W",
-                            fsinfo.mount_point);
+               ret = remount_ro_rw("");
+               if (ret)
                        return -1;
-               }
        }
 
        return 0;