[LTP] [PATCH] tst_supported_fs: Implement checking paths against skiplist

Martin Doucha
2022-09-21T15:50:20Z

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Implement tst_supported_fs feature suggested by pvorel in his patch:
tst_test.sh: Fix filesystem support detection

Although the tst_fs_type_name() functions could use some improvements,
e.g. ext4 must be specified in skiplist as "ext2/ext3/ext4" to get properly
skipped and vfat is missing from the list of known filesystems.

testcases/lib/tst_supported_fs.c | 49 ++++++++++++++++++++++++++------
1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/testcases/lib/tst_supported_fs.c b/testcases/lib/tst_supported_fs.c
index 70d4d38c7..5873d0ba1 100644
--- a/testcases/lib/tst_supported_fs.c
+++ b/testcases/lib/tst_supported_fs.c
@@ -32,9 +32,13 @@ static void usage(void)
fprintf(stderr, "tst_supported_fs -s skip_list fs_type\n");
fprintf(stderr, " if fs_type is in skip_list, return 1 otherwise return 0\n\n");

+ fprintf(stderr, "tst_supported_fs -s skip_list -d path\n");
+ fprintf(stderr, " if filesystem mounted on path is in skip_list, return 1 otherwise return 0\n\n");
+
fprintf(stderr, "fs_type - a specified filesystem type\n");
fprintf(stderr, "skip_list - filesystems to skip, delimiter: '%c'\n",
SKIP_DELIMITER);
+ fprintf(stderr, "path - any valid file or directory\n");
}

static char **parse_skiplist(char *fs)
@@ -62,10 +66,11 @@ static char **parse_skiplist(char *fs)
int main(int argc, char *argv[])
{
const char *const *filesystems;
+ const char *fsname = NULL;
int i, ret;
char **skiplist = NULL;

- while ((ret = getopt(argc, argv, "hs:"))) {
+ while ((ret = getopt(argc, argv, "hs:d:"))) {
if (ret < 0)
break;

@@ -83,9 +88,26 @@ int main(int argc, char *argv[])
if (!skiplist)
return 1;
break;
+
+ case 'd':
+ if (fsname) {
+ fprintf(stderr,
+ "Can't specify multiple paths\n");
+ usage();
+ return 2;
+ }
+
+ fsname = tst_fs_type_name(tst_fs_type(optarg));
+ break;
}
}

+ if (fsname && !skiplist) {
+ fprintf(stderr, "Parameter -d requires skiplist\n");
+ usage();
+ return 2;
+ }
+
if (argc - optind > 1) {
fprintf(stderr, "Can't specify multiple fs_type\n");
usage();
@@ -94,22 +116,33 @@ int main(int argc, char *argv[])

/* fs_type */
if (optind < argc) {
- if (argv[optind][0] == '\0')
+ if (fsname) {
+ fprintf(stderr, "Can't specify fs_type and -d together\n");
+ usage();
+ return 2;
+
+ }
+
+ fsname = argv[optind];
+ }
+
+ if (fsname) {
+ if (fsname[0] == '\0')
tst_brk(TCONF, "fs_type is empty");

if (skiplist) {
- if (tst_fs_in_skiplist(argv[optind], (const char * const*)skiplist))
- tst_brk(TCONF, "%s is skipped", argv[optind]);
+ if (tst_fs_in_skiplist(fsname, (const char * const*)skiplist))
+ tst_brk(TCONF, "%s is skipped", fsname);
else
- tst_res(TINFO, "%s is not skipped", argv[optind]);
+ tst_res(TINFO, "%s is not skipped", fsname);

return 0;
}

- if (tst_fs_is_supported(argv[optind]) == TST_FS_UNSUPPORTED)
- tst_brk(TCONF, "%s is not supported", argv[optind]);
+ if (tst_fs_is_supported(fsname) == TST_FS_UNSUPPORTED)
+ tst_brk(TCONF, "%s is not supported", fsname);
else
- tst_res(TINFO, "%s is supported", argv[optind]);
+ tst_res(TINFO, "%s is supported", fsname);

return 0;
}
--
2.37.3