summaryrefslogtreecommitdiff
path: root/tests/fs-tests/integrity
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-04-21 08:13:21 +0300
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-04-22 14:29:53 +0300
commit22bfdee79b65253fe2d5656303d2a00da934b00a (patch)
treef25268eb3546770d63d79d8c8086489d94e583e2 /tests/fs-tests/integrity
parentef4b2ceb552b5e32fa2defe7a48f1aec86b82333 (diff)
fs-tests: integck: do not assume the FS is mounted after failure
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>
Diffstat (limited to 'tests/fs-tests/integrity')
-rw-r--r--tests/fs-tests/integrity/integck.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 1816461..8703355 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -2493,14 +2493,37 @@ static void parse_mount_options(const char *mount_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.
*/
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,