Skip to contentSkip to conversation

file_attr02: Enable reflinks and fix blocksize detection

PATCH In review Martin Doucha 2 participants 6 messages Sep 23, 2025 – Sep 26, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 file_attr02: Enable reflinks and fix blocksize detection

Copy on write XFS features require reflink support. Enable it in mkfs options for older systems which don't enable it by default and mount the filesystem explicitly with checks for feature support.

Also use the correct (filesystem) blocksize instead of block device blocksize.

---
 .../kernel/syscalls/file_attr/file_attr02.c   | 30 ++++++++++++++-----
 1 file changed, 23 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/file_attr/file_attr02.c +23 -7
index 4e0d87f0f..d565a2687 100644
@@ -41,9 +41,18 @@ static void run(void)
 
 static void setup(void)
 {
-	int block_size;
+	struct stat statbuf;
 
-	block_size = tst_dev_block_size(MNTPOINT);
+	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, &statbuf);
 
 	dfd = SAFE_OPEN(MNTPOINT, O_RDONLY);
 	fd = SAFE_CREAT(MNTPOINT "/" FILENAME, 0777);
@@ -52,8 +61,8 @@ static void setup(void)
 
 	xattr.fsx_xflags |= FS_XFLAG_EXTSIZE;
 	xattr.fsx_xflags |= FS_XFLAG_COWEXTSIZE;
-	xattr.fsx_extsize = BLOCKS * block_size;
-	xattr.fsx_cowextsize = BLOCKS * block_size;
+	xattr.fsx_extsize = BLOCKS * statbuf.st_blksize;
+	xattr.fsx_cowextsize = BLOCKS * statbuf.st_blksize;
 	xattr.fsx_projid = PROJID;
 
 	SAFE_IOCTL(fd, FS_IOC_FSSETXATTR, &xattr);
@@ -72,17 +81,24 @@ static void cleanup(void)
 
 	if (dfd != -1)
 		SAFE_CLOSE(dfd);
+
+	if (tst_is_mounted(MNTPOINT))
+		SAFE_UMOUNT(MNTPOINT);
 }
 
 static struct tst_test test = {
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
-	.mntpoint = MNTPOINT,
 	.needs_root = 1,
-	.mount_device = 1,
+	.format_device = 1,
 	.filesystems = (struct tst_fs []) {
-		{.type = "xfs"},
+		{
+			.type = "xfs",
+			.mkfs_opts = (const char *const[]){
+				"-m", "reflink=1", NULL
+			},
+		},
 		{}
 	},
 	.bufs = (struct tst_buffers []) {
Signature · 5 lines
2.51.0


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

Hi!
And it looks like our CI builds fail because of implicit defintion of the mount() function. I guess that we need to add #include <sys/mount.h> before applying.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Hi!
And it looks like our CI builds fail because of implicit defintion of the mount() function. I guess that we need to add #include <sys/mount.h> before applying.

Yes, please add it during merge. Or should I submit v2?

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
#4 lore raw

Hi!

Quoted 5 lines
Quoted 3 lines

And it looks like our CI builds fail because of implicit defintion of the mount() function. I guess that we need to add #include <sys/mount.h> before applying.

Yes, please add it during merge. Or should I submit v2?

I will fix that during the merge.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp