Skip to contentSkip to conversation

Add ioctl_ficlone testing suite

PATCH Superseded Andrea Cervesato 5 participants 26 messages Jul 23, 2024 – Jul 29, 2024

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add ioctl_ficlone testing suite

This testing suite is testing ioctl() FICLONE and FICLONERANGE functionalities. In particular, file clone and error codes.

---
Changes in v2:
- add fallback definitions
- algorithm steps using '-'
- avoid assigning -1 to file descriptors after close()
- use SAFE_UNLINK() instead of remove()
- enable both xfs and btrs for all tests
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrea Cervesato (7):
Add fallback definitions for lapi/fs.h
Add ioctl_ficlone01 test
Add ioctl_ficlone02 test
Add ioctl_ficlone03 test
Add ioctl_ficlonerange01 test
Add ioctl_ficlonerange02 test
Add ioctl_ficlone04 test

 configure.ac                                       |   1 +
 include/lapi/fs.h                                  |  17 +++
 runtest/syscalls                                   |   6 +
 testcases/kernel/syscalls/ioctl/.gitignore         |   6 +
 testcases/kernel/syscalls/ioctl/ioctl_ficlone01.c  | 122 ++++++++++++++++
 testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c  |  70 +++++++++
 testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c  | 124 ++++++++++++++++
 testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c  | 108 ++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_ficlonerange01.c   | 162 +++++++++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_ficlonerange02.c   |  97 ++++++++++++
 10 files changed, 713 insertions(+)

---
base-commit: c5d95b6d34e2356bd19e6b646da06f1bce66a024
change-id: 20240529-ioctl_ficlone-95c603f71d53

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


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

PATCH v2 1/7 Add fallback definitions for lapi/fs.h

From: Andrea Cervesato <[email protected]>

This patch adds "struct file_clone_range" and FICLONERANGE fallback definitions.

---
 configure.ac      |  1 +
 include/lapi/fs.h | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
configure.ac +1 -0
index 1f8796c87..4d466f052 100644
@@ -177,6 +177,7 @@ AC_CHECK_TYPES([struct acct_v3],,,[#include <sys/acct.h>])
 AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include <linux/if_alg.h>])
 AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_error,
 		struct fanotify_event_info_header, struct fanotify_event_info_pidfd],,,[#include <sys/fanotify.h>])
+AC_CHECK_TYPES([struct file_clone_range],,,[#include <linux/fs.h>])
 AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>])
 
 AC_CHECK_TYPES([struct file_handle],,,[
include/lapi/fs.h +17 -0
index 635979b02..0e8d646d8 100644
@@ -20,6 +20,15 @@
 #include <limits.h>
 #include "lapi/abisize.h"
 
+#ifndef HAVE_FILE_CLONE_RANGE
+struct file_clone_range {
+	int64_t src_fd;
+	uint64_t src_offset;
+	uint64_t src_length;
+	uint64_t dest_offset;
+};
+#endif
+
 #ifndef FS_IOC_GETFLAGS
 # define	FS_IOC_GETFLAGS	_IOR('f', 1, long)
 #endif
@@ -48,6 +57,14 @@
 # define FS_VERITY_FL	   0x00100000 /* Verity protected inode */
 #endif
 
+#ifndef FICLONE
+# define FICLONE		_IOW(0x94, 9, int)
+#endif
+
+#ifndef FICLONERANGE
+# define FICLONERANGE		_IOW(0x94, 13, struct file_clone_range)
+#endif
+
 /*
  * Helper function to get MAX_LFS_FILESIZE.
  * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE.
Signature · 5 lines
2.43.0


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

Re: [LTP] [PATCH v2 1/7] Add fallback definitions for lapi/fs.h

Hi!

Quoted 1 line

#include <limits.h>

I've added #include <stdint.h> here to make sure that the *int*_t are defined and pushed, thanks.

Quoted 10 lines

#include "lapi/abisize.h"

include/lapi/fs.h +8 -0
+#ifndef HAVE_FILE_CLONE_RANGE
+struct file_clone_range {
+	int64_t src_fd;
+	uint64_t src_offset;
+	uint64_t src_length;
+	uint64_t dest_offset;
+};
+#endif
Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 1/7] Add fallback definitions for lapi/fs.h

In reply to Andrea Cervesato

Hi!

Quoted 18 lines
configure.ac +1 -0
index 1f8796c87..4d466f052 100644
@@ -177,6 +177,7 @@ AC_CHECK_TYPES([struct acct_v3],,,[#include <sys/acct.h>])
 AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include <linux/if_alg.h>])
 AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_error,
 		struct fanotify_event_info_header, struct fanotify_event_info_pidfd],,,[#include <sys/fanotify.h>])
+AC_CHECK_TYPES([struct file_clone_range],,,[#include <linux/fs.h>])
 AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>])
 
 AC_CHECK_TYPES([struct file_handle],,,[
include/lapi/fs.h +0 -0
index 635979b02..0e8d646d8 100644
@@ -20,6 +20,15 @@
 #include <limits.h>

include/lapi/fs.h line 30

Quoted 10 lines
include/lapi/fs.h +8 -0
 #include "lapi/abisize.h"
 
+#ifndef HAVE_FILE_CLONE_RANGE
+struct file_clone_range {
+	int64_t src_fd;
+	uint64_t src_offset;
+	uint64_t src_length;
+	uint64_t dest_offset;
+};
+#endif

Sigh, this is still horribly broken even when I fixed the macro to HAVE_STRUCT_FILE_CLONE_RANGE that is because:

commit b857f8723f30a4b9554bf6b0ff8fa52fd07e8b60

Author: Li Wang <[email protected]>
Date:   Fri Aug 5 14:34:01 2022 +0800

lapi/fsmount: resolve conflict in different header files

However the CI seems to work fine if I remove the HAVE_MOUNT_SETATTR check with:

#define LAPI_FS_H__

#include "config.h"
-#ifndef HAVE_MOUNT_SETATTR
-# ifdef HAVE_LINUX_FS_H
-# include <linux/fs.h>
-# endif
+
+#ifdef HAVE_LINUX_FS_H
+# include <linux/fs.h>
#endif

#include <sys/user.h>

@Li do we still need that ifdef or can we get rid of it?

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 1/7] Add fallback definitions for lapi/fs.h

Quoted 62 lines · Cyril Hrubis

Hi!

configure.ac AC_CHECK_TYPES([struct acct_v3],,,[#include

Quoted 5 lines
configure.ac +0 -0
index 1f8796c87..4d466f052 100644
@@ -177,6 +177,7 @@ AC_CHECK_TYPES([struct acct_v3],,,[#include

<sys/acct.h>])

configure.ac AC_CHECK_TYPES([struct acct_v3],,,[#include · line 177

Quoted 1 line
configure.ac +0 -0
 AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include

<linux/if_alg.h>])

configure.ac AC_CHECK_TYPES([struct acct_v3],,,[#include · line 178

Quoted 1 line
configure.ac +0 -0
 AC_CHECK_TYPES([struct fanotify_event_info_fid, struct

fanotify_event_info_error,

configure.ac AC_CHECK_TYPES([struct acct_v3],,,[#include · line 179

Quoted 1 line
configure.ac +0 -0
              struct fanotify_event_info_header, struct

fanotify_event_info_pidfd],,,[#include <sys/fanotify.h>])

Quoted 10 lines
configure.ac +1 -0
+AC_CHECK_TYPES([struct file_clone_range],,,[#include <linux/fs.h>])
 AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>])
 
 AC_CHECK_TYPES([struct file_handle],,,[
include/lapi/fs.h +0 -0
index 635979b02..0e8d646d8 100644
@@ -20,6 +20,15 @@
 #include <limits.h>

include/lapi/fs.h line 30

Quoted 10 lines
include/lapi/fs.h +8 -0
 #include "lapi/abisize.h"
 
+#ifndef HAVE_FILE_CLONE_RANGE
+struct file_clone_range {
+     int64_t src_fd;
+     uint64_t src_offset;
+     uint64_t src_length;
+     uint64_t dest_offset;
+};
+#endif

Sigh, this is still horribly broken even when I fixed the macro to HAVE_STRUCT_FILE_CLONE_RANGE that is because:

commit b857f8723f30a4b9554bf6b0ff8fa52fd07e8b60

Author: Li Wang <[email protected]>
Date:   Fri Aug 5 14:34:01 2022 +0800

lapi/fsmount: resolve conflict in different header files

However the CI seems to work fine if I remove the HAVE_MOUNT_SETATTR check with:

#define LAPI_FS_H__

#include "config.h"

(quoted diff) +3 -4
-#ifndef HAVE_MOUNT_SETATTR
-# ifdef HAVE_LINUX_FS_H
-#  include <linux/fs.h>
-# endif
+
+#ifdef HAVE_LINUX_FS_H
+# include <linux/fs.h>
 #endif
 
 #include <sys/user.h>
Quoted 2 lines

@Li do we still need that ifdef or can we get rid of it?

Theoretically, we can remove it because that problem is addressed in Glibc-2.37 by:

https://github.com/kraj/glibc/commit/774058d72942249f71d74e7f2b639f77184160a6

It is essentially a glibc bug we don't need to fix that in LTP.

We ever discussed in
https://lists.linux.it/pipermail/ltp/2023-March/033138.html

However, if we want LTP could be built with all the middle glibc versions (2.22 < glibc < 2.36)
this might be thinking over. Because we announce support the minimal glibc-version is 2.22.

Signature · 5 lines
Regards,
Li Wang

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

Re: [LTP] [PATCH v2 1/7] Add fallback definitions for lapi/fs.h

Hi!

Quoted 8 lines

Theoretically, we can remove it because that problem is addressed in Glibc-2.37 by:

https://github.com/kraj/glibc/commit/774058d72942249f71d74e7f2b639f77184160a6

It is essentially a glibc bug we don't need to fix that in LTP.

Quoted 7 lines

We ever discussed in
https://lists.linux.it/pipermail/ltp/2023-March/033138.html

However, if we want LTP could be built with all the middle glibc versions (2.22 < glibc < 2.36)
this might be thinking over. Because we announce support the minimal glibc-version is 2.22.

That does sound like we will need the workaround for quite some time.

Or maybe give up on including linux/fs.h and stick to the libc headers.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 1/7] Add fallback definitions for lapi/fs.h

In reply to Li Wang

Hi all,

...

Quoted 24 lines
Quoted 13 lines

#include "config.h"

(quoted diff) +3 -4
-#ifndef HAVE_MOUNT_SETATTR
-# ifdef HAVE_LINUX_FS_H
-#  include <linux/fs.h>
-# endif
+
+#ifdef HAVE_LINUX_FS_H
+# include <linux/fs.h>
 #endif
 
 #include <sys/user.h>
Quoted 1 line

@Li do we still need that ifdef or can we get rid of it?

Theoretically, we can remove it because that problem is addressed in Glibc-2.37 by:

https://github.com/kraj/glibc/commit/774058d72942249f71d74e7f2b639f77184160a6

It is essentially a glibc bug we don't need to fix that in LTP.

Quoted 7 lines

We ever discussed in
https://lists.linux.it/pipermail/ltp/2023-March/033138.html

However, if we want LTP could be built with all the middle glibc versions (2.22 < glibc < 2.36)
this might be thinking over. Because we announce support the minimal glibc-version is 2.22.

Hm, it makes sense to keep it. But nobody will remember once we raise the support.

Also, removing HAVE_LINUX_FS_H [1] works in the CI [2], including distros with glibc 2.36 (minimal build [3] or all cross-compile builds, e.g. [4]).

I wonder how realistic is that somebody is still affected by this issue.

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/commit/4bc155448559bc2ff75381c0e04662d585677bc4
[2] https://github.com/pevik/ltp/actions/runs/10093238273
[3] https://github.com/pevik/ltp/actions/runs/10093238273/job/27908521308
[4] https://github.com/pevik/ltp/actions/runs/10093238273/job/27908520925

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

Re: [LTP] [PATCH v2 1/7] Add fallback definitions for lapi/fs.h

Hi!

Quoted 7 lines
Quoted 4 lines

However, if we want LTP could be built with all the middle glibc versions (2.22 < glibc < 2.36)
this might be thinking over. Because we announce support the minimal glibc-version is 2.22.

Hm, it makes sense to keep it. But nobody will remember once we raise the support.

Maybe we should at least add a comment glibc-2.22 workaround or something that could be found with grep.

Quoted 4 lines

Also, removing HAVE_LINUX_FS_H [1] works in the CI [2], including distros with glibc 2.36 (minimal build [3] or all cross-compile builds, e.g. [4]).

I wonder how realistic is that somebody is still affected by this issue.

That's a good question but I'm afraid the only way to find out is to remove the workaround and wait for people complain that the next LTP release is broken...

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 1/7] Add fallback definitions for lapi/fs.h

Quoted 7 lines · Cyril Hrubis

Hi!

Quoted 1 line
Quoted 1 line

However, if we want LTP could be built with all the middle glibc

versions

Quoted 4 lines
Quoted 3 lines

(2.22 < glibc < 2.36)
this might be thinking over. Because we announce support the minimal glibc-version is 2.22.

Quoted 6 lines
Quoted 2 lines

Hm, it makes sense to keep it. But nobody will remember once we raise the support.

Maybe we should at least add a comment glibc-2.22 workaround or something that could be found with grep.

Sounds good.

Quoted 10 lines
Quoted 1 line

Also, removing HAVE_LINUX_FS_H [1] works in the CI [2], including

distros with

Quoted 3 lines

glibc 2.36 (minimal build [3] or all cross-compile builds, e.g. [4]).

I wonder how realistic is that somebody is still affected by this issue.

That's a good question but I'm afraid the only way to find out is to remove the workaround and wait for people complain that the next LTP release is broken...

I remember the broken was found by our CI automation tests on Fedora-rawhide at that moment. That is a tentative version and fixed imitatively by my patch, so yes, we can remove that to see if it impacts other users.

Signature · 5 lines
Regards,
Li Wang

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

PATCH v2 2/7 Add ioctl_ficlone01 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies that ioctl() FICLONE feature clones file content from one file to an another.

---
 runtest/syscalls                                  |   2 +
 testcases/kernel/syscalls/ioctl/.gitignore        |   1 +
 testcases/kernel/syscalls/ioctl/ioctl_ficlone01.c | 122 ++++++++++++++++++++++
 3 files changed, 125 insertions(+)
runtest/syscalls +2 -0
index 27eb9a86b..f05386ba2 100644
@@ -592,6 +592,8 @@ ioctl_ns07 ioctl_ns07
 
 ioctl_sg01 ioctl_sg01
 
+ioctl_ficlone01 ioctl_ficlone01
+
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
 
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 5fff7a61d..5404aa93f 100644
@@ -22,3 +22,4 @@
 /ioctl_ns06
 /ioctl_ns07
 /ioctl_sg01
+/ioctl_ficlone01
testcases/kernel/syscalls/ioctl/ioctl_ficlone01.c new file +122 -0

122 lines not on this page · raw message

Signature · 5 lines
2.43.0


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

PATCH v2 3/7 Add ioctl_ficlone02 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies that ioctl() FICLONE/FICLONERANGE feature correctly raises EOPNOTSUPP when unsupported filesystem is used. In particular, filesystems which don't support copy-on-write.

---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore        |  1 +
 testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c | 70 +++++++++++++++++++++++
 3 files changed, 72 insertions(+)
runtest/syscalls +1 -0
index f05386ba2..48fe85c97 100644
@@ -593,6 +593,7 @@ ioctl_ns07 ioctl_ns07
 ioctl_sg01 ioctl_sg01
 
 ioctl_ficlone01 ioctl_ficlone01
+ioctl_ficlone02 ioctl_ficlone02
 
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 5404aa93f..3d25fdfb2 100644
@@ -23,3 +23,4 @@
 /ioctl_ns07
 /ioctl_sg01
 /ioctl_ficlone01
+/ioctl_ficlone02
testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c new file +70 -0

70 lines not on this page · raw message

Signature · 5 lines
2.43.0


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

Re: [LTP] [PATCH v2 3/7] Add ioctl_ficlone02 test

Hi all,

Quoted 3 lines

This test verifies that ioctl() FICLONE/FICLONERANGE feature correctly raises EOPNOTSUPP when unsupported filesystem is used. In particular, filesystems which don't support copy-on-write.

This test, merged as [1] fails on bcachefs:

$ cd testcases/kernel/syscalls/ioctl/
# # LTP_SINGLE_FS_TYPE=bcachefs ./ioctl_ficlone02
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_iocu1xhKp as tmpdir (tmpfs filesystem)
tst_device.c:96: TINFO: Found free device 0 '/dev/loop0'
tst_test.c:1806: TINFO: LTP version: 20240524-131-gdfb293ee0
tst_test.c:1650: TINFO: Timeout per run is 0h 00m 30s
tst_supported_fs_types.c:161: TINFO: WARNING: testing only bcachefs
tst_supported_fs_types.c:97: TINFO: Kernel supports bcachefs
tst_supported_fs_types.c:62: TINFO: mkfs.bcachefs does exist
tst_test.c:1746: TINFO: === Testing on bcachefs ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with bcachefs opts='' extra opts=''
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /tmp/LTP_iocu1xhKp/mnt fstyp=bcachefs flags=0
ioctl_ficlone02.c:33: TFAIL: ioctl(dst_fd, FICLONE, src_fd) succeeded
ioctl_ficlone02.c:34: TFAIL: ioctl(dst_fd, FICLONERANGE, clone_range) expected EOPNOTSUPP: EINVAL (22)

I tested only kernel 6.10 and 6.9, fails on both. Maybe it's just a different errno set...

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/commit/d70bfb185c9aa52aeab9b9893055eec7fc969a4f

#12 lore raw

Re: [LTP] [PATCH v2 3/7] Add ioctl_ficlone02 test

Hi!

Quoted 17 lines

This test, merged as [1] fails on bcachefs:

$ cd testcases/kernel/syscalls/ioctl/
# # LTP_SINGLE_FS_TYPE=bcachefs ./ioctl_ficlone02
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_iocu1xhKp as tmpdir (tmpfs filesystem)
tst_device.c:96: TINFO: Found free device 0 '/dev/loop0'
tst_test.c:1806: TINFO: LTP version: 20240524-131-gdfb293ee0
tst_test.c:1650: TINFO: Timeout per run is 0h 00m 30s
tst_supported_fs_types.c:161: TINFO: WARNING: testing only bcachefs
tst_supported_fs_types.c:97: TINFO: Kernel supports bcachefs
tst_supported_fs_types.c:62: TINFO: mkfs.bcachefs does exist
tst_test.c:1746: TINFO: === Testing on bcachefs ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with bcachefs opts='' extra opts=''
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /tmp/LTP_iocu1xhKp/mnt fstyp=bcachefs flags=0
ioctl_ficlone02.c:33: TFAIL: ioctl(dst_fd, FICLONE, src_fd) succeeded
ioctl_ficlone02.c:34: TFAIL: ioctl(dst_fd, FICLONERANGE, clone_range) expected EOPNOTSUPP: EINVAL (22)

This looks that FIOCLONE is supported on bcachefs and bcachefs should be skipped in this test as well. And I suppose that we should enable bcachefs in the rest of the FICLONE tests too.

BTW, the EINVAL in the second subtest is caused by the fact that we attempt to clone a range that does not exist, this can be fixed by:

testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c +2 -0
index be3b01c29..17452a1a3 100644
@@ -43,6 +43,8 @@ static void setup(void)
 
        SAFE_STAT(MNTPOINT, &sb);
 
+       tst_fill_file(SRCPATH, 0x00, sb.st_blksize, 1);
+
        clone_range->src_offset = 0;
        clone_range->src_length = sb.st_blksize;
        clone_range->dest_offset = 0;
Signature · 2 lines
Cyril Hrubis
[email protected]
#13 lore raw

Re: [LTP] [PATCH v2 3/7] Add ioctl_ficlone02 test

Hi Cyril, all,

Quoted 19 lines

Hi!

Quoted 17 lines

This test, merged as [1] fails on bcachefs:

$ cd testcases/kernel/syscalls/ioctl/
# # LTP_SINGLE_FS_TYPE=bcachefs ./ioctl_ficlone02
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_tmpdir.c:316: TINFO: Using /tmp/LTP_iocu1xhKp as tmpdir (tmpfs filesystem)
tst_device.c:96: TINFO: Found free device 0 '/dev/loop0'
tst_test.c:1806: TINFO: LTP version: 20240524-131-gdfb293ee0
tst_test.c:1650: TINFO: Timeout per run is 0h 00m 30s
tst_supported_fs_types.c:161: TINFO: WARNING: testing only bcachefs
tst_supported_fs_types.c:97: TINFO: Kernel supports bcachefs
tst_supported_fs_types.c:62: TINFO: mkfs.bcachefs does exist
tst_test.c:1746: TINFO: === Testing on bcachefs ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with bcachefs opts='' extra opts=''
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /tmp/LTP_iocu1xhKp/mnt fstyp=bcachefs flags=0
ioctl_ficlone02.c:33: TFAIL: ioctl(dst_fd, FICLONE, src_fd) succeeded
ioctl_ficlone02.c:34: TFAIL: ioctl(dst_fd, FICLONERANGE, clone_range) expected EOPNOTSUPP: EINVAL (22)
Quoted 3 lines

This looks that FIOCLONE is supported on bcachefs and bcachefs should be skipped in this test as well. And I suppose that we should enable bcachefs in the rest of the FICLONE tests too.

Thanks! (I should have read the test description).
I dared to enable it + skip on ioctl_ficlone02.c and merge with your SBT

https://github.com/linux-test-project/ltp/commit/b3d9561793657239548269378d02f65580917e7c

Quoted 8 lines

BTW, the EINVAL in the second subtest is caused by the fact that we attempt to clone a range that does not exist, this can be fixed by:

testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c +0 -0
index be3b01c29..17452a1a3 100644

testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c static void setup(void) · line 50

Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c +2 -0
@@ -43,6 +43,8 @@ static void setup(void)
 
        SAFE_STAT(MNTPOINT, &sb);
 
+       tst_fill_file(SRCPATH, 0x00, sb.st_blksize, 1);
+
        clone_range->src_offset = 0;
        clone_range->src_length = sb.st_blksize;
        clone_range->dest_offset = 0;

Thanks, again! This is less confusing. I again dared to merge with your SBT:
https://github.com/linux-test-project/ltp/commit/9c6390812831f5c36e531be5a25bd8d7862e79fb

Kind regards,
Petr

#14 lore raw

PATCH v2 4/7 Add ioctl_ficlone03 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies that ioctl() FICLONE/FICLONERANGE feature correctly raises exceptions when it's supposed to.

---
 runtest/syscalls                                  |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore        |   1 +
 testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c | 124 ++++++++++++++++++++++
 3 files changed, 126 insertions(+)
runtest/syscalls +1 -0
index 48fe85c97..5aef2b97e 100644
@@ -594,6 +594,7 @@ ioctl_sg01 ioctl_sg01
 
 ioctl_ficlone01 ioctl_ficlone01
 ioctl_ficlone02 ioctl_ficlone02
+ioctl_ficlone03 ioctl_ficlone03
 
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 3d25fdfb2..d0b470714 100644
@@ -24,3 +24,4 @@
 /ioctl_sg01
 /ioctl_ficlone01
 /ioctl_ficlone02
+/ioctl_ficlone03
testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c new file +124 -0

124 lines not on this page · raw message

Signature · 5 lines
2.43.0


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

Re: [LTP] [PATCH v2 4/7] Add ioctl_ficlone03 test

Hi!
Pushed with a small fix, thanks.

The immutable file has to be on the MNTPOINT as well as th source for the immutable file, otherwise we get EOPNOTSUPP instead of EPERM since the check for supported filesystems kicks in first:

testcases/kernel/syscalls/ioctl/ioctl_ficlone03.c +2 -2
index be069836a..406b64cca 100644
@@ -37,7 +37,7 @@ static struct tcase {
        {&wo_file, &rw_file, EBADF, "write-only source"},
        {&rw_file, &dir_fd, EISDIR, "source is a directory"},
        {&dir_fd, &rw_file, EISDIR, "destination is a directory"},
-       {&rw_file, &immut_fd, EPERM, "destination is immutable"},
+       {&mnt_file, &immut_fd, EPERM, "destination is immutable"},
        {&rw_file, &mnt_file, EXDEV, "destination is on a different mount"},
        {&mnt_file, &rw_file, EXDEV, "source is on a different mount"},
 };
@@ -72,7 +72,7 @@ static void setup(void)
        dir_fd = SAFE_OPEN("mydir", O_DIRECTORY, 0640);
 
        attr = FS_IMMUTABLE_FL;
-       immut_fd = SAFE_OPEN("immutable", O_CREAT | O_RDWR, 0640);
+       immut_fd = SAFE_OPEN(MNTPOINT"/immutable", O_CREAT | O_RDWR, 0640);
        SAFE_IOCTL(immut_fd, FS_IOC_SETFLAGS, &attr);
 
        mnt_file = SAFE_OPEN(MNTPOINT"/file", O_CREAT | O_RDWR, 0640);
Signature · 5 lines
Cyril Hrubis
[email protected]

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

PATCH v2 5/7 Add ioctl_ficlonerange01 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies that ioctl() FICLONERANGE feature clones file content from one file to an another.

---
 runtest/syscalls                                   |   1 +
 testcases/kernel/syscalls/ioctl/.gitignore         |   1 +
 .../kernel/syscalls/ioctl/ioctl_ficlonerange01.c   | 162 +++++++++++++++++++++
 3 files changed, 164 insertions(+)
runtest/syscalls +1 -0
index 5aef2b97e..1f050c5f5 100644
@@ -595,6 +595,7 @@ ioctl_sg01 ioctl_sg01
 ioctl_ficlone01 ioctl_ficlone01
 ioctl_ficlone02 ioctl_ficlone02
 ioctl_ficlone03 ioctl_ficlone03
+ioctl_ficlonerange01 ioctl_ficlonerange01
 
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index d0b470714..08c015928 100644
@@ -25,3 +25,4 @@
 /ioctl_ficlone01
 /ioctl_ficlone02
 /ioctl_ficlone03
+/ioctl_ficlonerange01
testcases/kernel/syscalls/ioctl/ioctl_ficlonerange01.c new file +162 -0

162 lines not on this page · raw message

Signature · 5 lines
2.43.0


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

Re: [LTP] [PATCH v2 5/7] Add ioctl_ficlonerange01 test

Hi!
Pushed with a minor change, thanks.

testcases/kernel/syscalls/ioctl/ioctl_ficlonerange01.c line 133

Quoted 7 lines
testcases/kernel/syscalls/ioctl/ioctl_ficlonerange01.c new file +7 -0
+static void cleanup(void)
+{
+	if (buff)
+		free(buff);
+
+	if (data)
+		free(data);

free(NULL) is no-op so I've removed the two ifs here.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 5/7] Add ioctl_ficlonerange01 test

Hi!
And also please avoid casting pointers from malloc(), that is something you do in C++.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

PATCH v2 6/7 Add ioctl_ficlonerange02 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies that ioctl() FICLONERANGE feature correctly raises EINVAL when:
- filesystem does not support overlapping reflink ranges in the same file
- filesystem does not support reflinking on bad blocks alignment

---
 runtest/syscalls                                   |  1 +
 testcases/kernel/syscalls/ioctl/.gitignore         |  1 +
 .../kernel/syscalls/ioctl/ioctl_ficlonerange02.c   | 97 ++++++++++++++++++++++
 3 files changed, 99 insertions(+)
runtest/syscalls +1 -0
index 1f050c5f5..4a73852e8 100644
@@ -596,6 +596,7 @@ ioctl_ficlone01 ioctl_ficlone01
 ioctl_ficlone02 ioctl_ficlone02
 ioctl_ficlone03 ioctl_ficlone03
 ioctl_ficlonerange01 ioctl_ficlonerange01
+ioctl_ficlonerange02 ioctl_ficlonerange02
 
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 08c015928..9f995b1ad 100644
@@ -26,3 +26,4 @@
 /ioctl_ficlone02
 /ioctl_ficlone03
 /ioctl_ficlonerange01
+/ioctl_ficlonerange02
testcases/kernel/syscalls/ioctl/ioctl_ficlonerange02.c new file +97 -0

97 lines not on this page · raw message

Signature · 5 lines
2.43.0


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

Re: [LTP] [PATCH v2 6/7] Add ioctl_ficlonerange02 test

Hi!
Pushed with the same minor fixes as the previous patch.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

PATCH v2 7/7 Add ioctl_ficlone04 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies that ioctl() FICLONE/FICLONERANGE feature raises the right error according with bad file descriptors.

---
 testcases/kernel/syscalls/ioctl/.gitignore        |   1 +
 testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c | 108 ++++++++++++++++++++++
 2 files changed, 109 insertions(+)
testcases/kernel/syscalls/ioctl/.gitignore +1 -0
index 9f995b1ad..1f099ff95 100644
@@ -25,5 +25,6 @@
 /ioctl_ficlone01
 /ioctl_ficlone02
 /ioctl_ficlone03
+/ioctl_ficlone04
 /ioctl_ficlonerange01
 /ioctl_ficlonerange02
testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c new file +108 -0

108 lines not on this page · raw message

Signature · 5 lines
2.43.0


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

Re: [LTP] [PATCH v2 7/7] Add ioctl_ficlone04 test

Hi!

Quoted 17 lines
testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c new file +17 -0
+	switch (fd_src->type) {
+	case TST_FD_DEV_ZERO:
+	case TST_FD_PROC_MAPS:
+	case TST_FD_PIPE_READ:
+	case TST_FD_PIPE_WRITE:
+	case TST_FD_UNIX_SOCK:
+	case TST_FD_INET_SOCK:
+	case TST_FD_EPOLL:
+	case TST_FD_EVENTFD:
+	case TST_FD_SIGNALFD:
+	case TST_FD_TIMERFD:
+	case TST_FD_PIDFD:
+	case TST_FD_FANOTIFY:
+	case TST_FD_INOTIFY:
+	case TST_FD_USERFAULTFD:
+	case TST_FD_PERF_EVENT:
+	case TST_FD_IO_URING:

testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c line 49

Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c new file +10 -0
+	case TST_FD_BPF_MAP:
+	case TST_FD_FSOPEN:
+	case TST_FD_FSPICK:
+	case TST_FD_OPEN_TREE:
+	case TST_FD_MEMFD:
+	case TST_FD_MEMFD_SECRET:
+		return;
+	default:
+		break;
+	}

Why do we skip all these cases?

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 7/7] Add ioctl_ficlone04 test

Quoted 21 lines · Cyril Hrubis

Hi!

Quoted 20 lines
testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c new file +20 -0
+	switch (fd_src->type) {
+	case TST_FD_DEV_ZERO:
+	case TST_FD_PROC_MAPS:
+	case TST_FD_PIPE_READ:
+	case TST_FD_PIPE_WRITE:
+	case TST_FD_UNIX_SOCK:
+	case TST_FD_INET_SOCK:
+	case TST_FD_EPOLL:
+	case TST_FD_EVENTFD:
+	case TST_FD_SIGNALFD:
+	case TST_FD_TIMERFD:
+	case TST_FD_PIDFD:
+	case TST_FD_FANOTIFY:
+	case TST_FD_INOTIFY:
+	case TST_FD_USERFAULTFD:
+	case TST_FD_PERF_EVENT:
+	case TST_FD_IO_URING:
+	case TST_FD_BPF_MAP:
+	case TST_FD_FSOPEN:
+	case TST_FD_FSPICK:
Quoted 9 lines

testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c line 49

Quoted 7 lines
testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c new file +7 -0
+	case TST_FD_OPEN_TREE:
+	case TST_FD_MEMFD:
+	case TST_FD_MEMFD_SECRET:
+		return;
+	default:
+		break;
+	}

Why do we skip all these cases?

I can't understand what's the best way to test all the combinations. As you can see there are many flags, which means the amount of permutations is big.
Most of those flags are handled (indeed) in the wrong way, since most of their permutations return EXDEV. The point is that the syscall has many error codes, so it's complex to write a code that covers all possible results.

My idea would be to have an array of errors to give to TST_EXP_FAIL2_ARR() and to avoid any statement around fd_src/fd_dst, because the amount of if/switch-case might explode with the number of permutations.

Andrea

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

Re: [LTP] [PATCH v2 7/7] Add ioctl_ficlone04 test

Hi!

Quoted 8 lines

I can't understand what's the best way to test all the combinations. As you can see there are many flags, which means the amount of permutations is big.
Most of those flags are handled (indeed) in the wrong way, since most of their permutations return EXDEV. The point is that the syscall has many error codes, so it's complex to write a code that covers all possible results.

Quoted 4 lines

My idea would be to have an array of errors to give to TST_EXP_FAIL2_ARR() and to avoid any statement around fd_src/fd_dst, because the amount of if/switch-case might explode with the number of permutations.

The purpose of the tst_fd iterator is mainly to hammer syscalls with different kinds of file descriptors and trigger code paths in the kernel that are not excercies under normal circumstances. So it's fine to have a single array with a few sensible errno codes and pass that in all the cases.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 7/7] Add ioctl_ficlone04 test

Hi!

Quoted 13 lines · Cyril Hrubis

Hi!

Quoted 8 lines

I can't understand what's the best way to test all the combinations. As you can see there are many flags, which means the amount of permutations is big.
Most of those flags are handled (indeed) in the wrong way, since most of their permutations return EXDEV. The point is that the syscall has many error codes, so it's complex to write a code that covers all possible results.

Quoted 4 lines

My idea would be to have an array of errors to give to TST_EXP_FAIL2_ARR() and to avoid any statement around fd_src/fd_dst, because the amount of if/switch-case might explode with the number of permutations.

Quoted 6 lines

The purpose of the tst_fd iterator is mainly to hammer syscalls with different kinds of file descriptors and trigger code paths in the kernel that are not excercies under normal circumstances. So it's fine to have a single array with a few sensible errno codes and pass that in all the cases.

Sent v4 that does exactly this.

Andrea

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