Skip to contentSkip to conversation

refluxfs: Check kernel reflink support before mount

PATCH In review Martin Doucha 4 participants 11 messages Aug 12 – Aug 13 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 refluxfs: Check kernel reflink support before mount

On some systems, mkfs.xfs can format XFS partition with reflink support but the kernel then cannot mount it. Check for kernel reflink support in setup() before mount.

---
 testcases/cve/refluxfs.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
testcases/cve/refluxfs.c +16 -2
index e41f35c53..277d56bb7 100644
@@ -38,6 +38,7 @@
  */
 
 #include <pwd.h>
+#include <sys/mount.h>
 
 #include "tst_test.h"
 #include "tst_safe_prw.h"
@@ -94,6 +95,15 @@ static void setup(void)
 	int probe_fd, probe_dio_fd;
 	struct stat sb;
 
+	SAFE_MKDIR(MNTPOINT, 0755);
+	TEST(mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL));
+
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
+		tst_brk(TCONF, "Kernel does not support XFS reflinks");
+
+	if (TST_RET)
+		tst_brk(TBROK | TTERRNO, "Mount failed");
+
 	SAFE_STAT(MNTPOINT, &sb);
 	blksize = sb.st_blksize;
 
@@ -197,6 +207,11 @@ static void cleanup(void)
 	free(tbuf);
 	free(wbuf);
 	free(rbuf);
+
+	SAFE_SETEUID(0);
+
+	if (tst_is_mounted(MNTPOINT))
+		SAFE_UMOUNT(MNTPOINT);
 }
 
 static struct tst_test test = {
@@ -205,8 +220,7 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.runtime = 180,
 	.needs_root = 1,
-	.mount_device = 1,
-	.mntpoint = MNTPOINT,
+	.format_device = 1,
 	.filesystems = (struct tst_fs []) {
 		{
 			.type = "xfs",
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

testcases/cve/refluxfs.c static void setup(void) · line 102

Quoted 2 lines
testcases/cve/refluxfs.c +2 -0
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
+		tst_brk(TCONF, "Kernel does not support XFS reflinks");

Wouldn't it make more sense to add the check for EOPNOTSUPP into the tst_test.c library?

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Cyril,

Quoted 5 lines

testcases/cve/refluxfs.c static void setup(void) · line 102

Quoted 2 lines
testcases/cve/refluxfs.c +2 -0
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
+		tst_brk(TCONF, "Kernel does not support XFS reflinks");

Wouldn't it make more sense to add the check for EOPNOTSUPP into the tst_test.c library?

I don't know if we really need to add something in the LTP library, since we have this check only in file_attr02

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 8 lines
Quoted 5 lines

testcases/cve/refluxfs.c static void setup(void) · line 102

Quoted 2 lines
testcases/cve/refluxfs.c +2 -0
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
+		tst_brk(TCONF, "Kernel does not support XFS reflinks");

Wouldn't it make more sense to add the check for EOPNOTSUPP into the tst_test.c library?

I don't know if we really need to add something in the LTP library, since we have this check only in file_attr02

I mean that we should rather than hacking around it in the tests handle EOPNOTSUPP properly in the test libray when mounting filesystems. We do enough magick in safe_mount() to support FUSE and handle other corner cases, checking for EOPNOTSUPP (possibly with non-standard mount flags) does sound like a reasonable extension.

The main point of handling the filesystems in the test library is that cleanup (umounting) is handled properly even if the test crashes. If we move the code back to the tests like this we lose that.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi Cyril,

Quoted 16 lines

Hi!

Quoted 8 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
+		tst_brk(TCONF, "Kernel does not support XFS reflinks");

Wouldn't it make more sense to add the check for EOPNOTSUPP into the tst_test.c library?

I don't know if we really need to add something in the LTP library, since we have this check only in file_attr02

I mean that we should rather than hacking around it in the tests handle EOPNOTSUPP properly in the test libray when mounting filesystems. We do enough magick in safe_mount() to support FUSE and handle other corner cases, checking for EOPNOTSUPP (possibly with non-standard mount flags) does sound like a reasonable extension.

Quoted 7 lines

The main point of handling the filesystems in the test library is that cleanup (umounting) is handled properly even if the test crashes. If we move the code back to the tests like this we lose that.

Signature · 2 lines
Cyril Hrubis
[email protected]

Something like this?

lib/safe_macros.c +9 -3
index f95c5fdc5..34430d018 100644
@@ -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 (errno == EOPNOTSUPP) {
+			tst_brkm_(file, lineno, TCONF | TERRNO, cleanup_fn,
+				"mount(%s, %s, %s, %lu, %p) failed with EOPNOTSUPP", source, target,
+				filesystemtype, mountflags, data);
+		} 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",
testcases/kernel/syscalls/file_attr/file_attr02.c +1 -7
index f6625985a..28c1c7ca6 100644
@@ -45,13 +45,7 @@ static void setup(void)
 	struct stat statbuf;
 
 	SAFE_MKDIR(MNTPOINT, 0755);
-	TEST(mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL));
-
-	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
-		tst_brk(TCONF, "Kernel does not support XFS reflinks");
-
-	if (TST_RET)
-		tst_brk(TBROK | TTERRNO, "Mount failed");
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
 
 	SAFE_STAT(MNTPOINT, &statbuf);
 

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Hi!

Quoted 33 lines

Something like this?

lib/safe_macros.c +9 -3
index f95c5fdc5..34430d018 100644
@@ -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 (errno == EOPNOTSUPP) {
+			tst_brkm_(file, lineno, TCONF | TERRNO, cleanup_fn,
+				"mount(%s, %s, %s, %lu, %p) failed with EOPNOTSUPP", source, target,
+				filesystemtype, mountflags, data);
+		} 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",
testcases/kernel/syscalls/file_attr/file_attr02.c +0 -0
index f6625985a..28c1c7ca6 100644
@@ -45,13 +45,7 @@ static void setup(void)
 	struct stat statbuf;
 
 	SAFE_MKDIR(MNTPOINT, 0755);

testcases/kernel/syscalls/file_attr/file_attr02.c static void setup(void) · line 50

Quoted 10 lines
testcases/kernel/syscalls/file_attr/file_attr02.c +1 -7
-	TEST(mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL));
-
-	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
-		tst_brk(TCONF, "Kernel does not support XFS reflinks");
-
-	if (TST_RET)
-		tst_brk(TBROK | TTERRNO, "Mount failed");
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
 
 	SAFE_STAT(MNTPOINT, &statbuf);

Yes. If we do not do this we are going to open code the check over and over.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
In reply to Andrea Cervesato via ltp
Quoted 17 lines · Andrea Cervesato

Hi Cyril,

Something like this?

lib/safe_macros.c +2 -3
index f95c5fdc5..34430d018 100644
@@ -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 (errno == EOPNOTSUPP) {
+			tst_brkm_(file, lineno, TCONF | TERRNO, cleanup_fn,

lib/safe_macros.c int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void), · line 1007

Quoted 10 lines
lib/safe_macros.c +7 -0
+				"mount(%s, %s, %s, %lu, %p) failed with EOPNOTSUPP", source, target,
+				filesystemtype, mountflags, data);
+		} 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",

Hi,
yes, but I think it'd be better to add a setting to struct tst_test to enable this TCONF check only for specific tests. By default, EOPNOTSUPP should still trigger TBROK.

Something like:
.mount_check_support = 1

Signature · 10 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi!

Quoted 25 lines
Quoted 9 lines
lib/safe_macros.c +2 -3
@@ -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 (errno == EOPNOTSUPP) {
+			tst_brkm_(file, lineno, TCONF | TERRNO, cleanup_fn,

lib/safe_macros.c int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void), · line 1007

Quoted 10 lines
lib/safe_macros.c +7 -0
+				"mount(%s, %s, %s, %lu, %p) failed with EOPNOTSUPP", source, target,
+				filesystemtype, mountflags, data);
+		} 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",

Hi,
yes, but I think it'd be better to add a setting to struct tst_test to enable this TCONF check only for specific tests. By default, EOPNOTSUPP should still trigger TBROK.

Quoted 2 lines

Something like:
.mount_check_support = 1

Shoudn't that be per filesystem and live in tst_fs structure?

Either way we will need a flag to the safe_mount() added first...

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw
Quoted 11 lines · Cyril Hrubis
Quoted 7 lines

Hi,
yes, but I think it'd be better to add a setting to struct tst_test to enable this TCONF check only for specific tests. By default, EOPNOTSUPP should still trigger TBROK.

Something like:
.mount_check_support = 1

Shoudn't that be per filesystem and live in tst_fs structure?

Either way we will need a flag to the safe_mount() added first...

That's a good point. I'll prepare a patch.

Signature · 10 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw
In reply to Martin Doucha

Hi Martin,

Quoted 1 line · Martin Doucha

refluxfs: Check kernel reflink support before mount

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp