[PATCH 1/3] struct tst_fs: Add flag for checking filesystem mount support in kernel

Martin Doucha <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
Add flag for skipping filesystem if mount() fails with EOPNOTSUPP. This
error usually happens when special mkfs options are not supported
by the kernel.

Signed-off-by: Martin Doucha <[email protected]>
---
 include/old/tso_safe_macros.h |  2 +-
 include/safe_macros_fn.h      |  2 +-
 include/tst_safe_macros.h     |  7 ++++---
 include/tst_test.h            |  4 ++++
 lib/safe_macros.c             | 14 ++++++++++----
 lib/tst_test.c                |  3 ++-
 6 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/include/old/tso_safe_macros.h b/include/old/tso_safe_macros.h
index f3965cc68..fec31e666 100644
--- a/include/old/tso_safe_macros.h
+++ b/include/old/tso_safe_macros.h
@@ -154,7 +154,7 @@
 #define SAFE_MOUNT(cleanup_fn, source, target, filesystemtype, \
 		   mountflags, data) \
 	safe_mount(__FILE__, __LINE__, (cleanup_fn), (source), (target), \
-		   (filesystemtype), (mountflags), (data), NULL)
+		   (filesystemtype), (mountflags), (data), NULL, 0)
 
 #define SAFE_UMOUNT(cleanup_fn, target) \
 	safe_umount(__FILE__, __LINE__, (cleanup_fn), (target))
diff --git a/include/safe_macros_fn.h b/include/safe_macros_fn.h
index e8dc02539..f01378b0a 100644
--- a/include/safe_macros_fn.h
+++ b/include/safe_macros_fn.h
@@ -187,7 +187,7 @@ int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void),
 int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
 	       const char *source, const char *target,
 	       const char *filesystemtype, unsigned long mountflags,
-	       const void *data, int *is_fuse);
+	       const void *data, int *is_fuse, unsigned int check_support);
 
 int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void),
 		const char *target);
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 91a130a48..55ca2bf8b 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -245,12 +245,13 @@ int safe_getgroups(const char *file, const int lineno, int size, gid_t list[]);
 #define SAFE_MOUNT(source, target, filesystemtype, \
 		   mountflags, data) \
 	safe_mount(__FILE__, __LINE__, NULL, (source), (target), \
-		   (filesystemtype), (mountflags), (data), NULL)
+		   (filesystemtype), (mountflags), (data), NULL, 0)
 
 #define SAFE_MOUNT2(source, target, filesystemtype, \
-		    mountflags, data, is_fuse) \
+		    mountflags, data, is_fuse, check_support) \
 	safe_mount(__FILE__, __LINE__, NULL, (source), (target), \
-		   (filesystemtype), (mountflags), (data), (is_fuse))
+		   (filesystemtype), (mountflags), (data), (is_fuse), \
+		   (check_support))
 
 #define SAFE_UMOUNT(target) \
 	safe_umount(__FILE__, __LINE__, NULL, (target))
diff --git a/include/tst_test.h b/include/tst_test.h
index c69362485..d3de042db 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -280,6 +280,8 @@ struct tst_ulimit_val {
  *
  * @min_kver: A minimum kernel version supporting the filesystem which has been
  *            created with mkfs.
+ *
+ * @mount_check_support: Skip this filesystem if mount() fails with EOPNOTSUPP.
  */
 struct tst_fs {
 	const char *type;
@@ -292,6 +294,8 @@ struct tst_fs {
 	const void *mnt_data;
 
 	const char *min_kver;
+
+	unsigned int mount_check_support:1;
 };
 
 /**
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index f95c5fdc5..187550041 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -930,7 +930,7 @@ static int possibly_fuse(const char *fs_type)
 int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
 	       const char *source, const char *target,
 	       const char *filesystemtype, unsigned long mountflags,
-	       const void *data, int *is_fuse)
+	       const void *data, int *is_fuse, unsigned int check_support)
 {
 	int rval = -1;
 	char mpath[PATH_MAX];
@@ -993,9 +993,15 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
 			"mount.%s failed with %i", filesystemtype, rval);
 		return -1;
 	} else if (rval == -1) {
-		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
-			"mount(%s, %s, %s, %lu, %p) failed", source, target,
-			filesystemtype, mountflags, data);
+		if (check_support && errno == EOPNOTSUPP) {
+			tst_brkm_(file, lineno, TCONF | TERRNO, cleanup_fn,
+				"Kernel does not support required %s features",
+				filesystemtype);
+		} else {
+			tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+				"mount(%s, %s, %s, %lu, %p) failed", source,
+				target, filesystemtype, mountflags, data);
+		}
 	} else {
 		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
 			"Invalid mount(%s, %s, %s, %lu, %p) return value %d",
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 9c5f2617f..166e0f672 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1301,7 +1301,8 @@ static void prepare_device(struct tst_fs *fs)
 				buf, sizeof(buf), tdev.fs_type);
 
 		SAFE_MOUNT2(get_device_name(tdev.fs_type), tst_test->mntpoint,
-				tdev.fs_type, fs->mnt_flags, mnt_data, &tdev.is_fuse);
+				tdev.fs_type, fs->mnt_flags, mnt_data,
+				&tdev.is_fuse, fs->mount_check_support);
 		context->mntpoint_mounted = 1;
 	}
 }
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.