[LTP] [PATCH v2 3/7] Add ioctl_ficlone02 test
Andrea Cervesato
andrea.cervesato@suse.de
Tue Jul 23 09:15:03 CEST 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
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.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c | 70 +++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index f05386ba2..48fe85c97 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -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
diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
index 5404aa93f..3d25fdfb2 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -23,3 +23,4 @@
/ioctl_ns07
/ioctl_sg01
/ioctl_ficlone01
+/ioctl_ficlone02
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c b/testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c
new file mode 100644
index 000000000..f6d492026
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ficlone02.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that ioctl() FICLONE/FICLONERANGE feature correctly raises
+ * EOPNOTSUPP when an unsupported filesystem is used. In particular, filesystems
+ * which don't support copy-on-write.
+ */
+
+#include "tst_test.h"
+#include "lapi/fs.h"
+
+#define MNTPOINT "mnt"
+#define SRCPATH MNTPOINT "/file0"
+#define DSTPATH MNTPOINT "/file1"
+
+static struct file_clone_range *clone_range;
+
+static void run(void)
+{
+ int src_fd;
+ int dst_fd;
+
+ src_fd = SAFE_OPEN(SRCPATH, O_CREAT | O_RDWR, 0640);
+ dst_fd = SAFE_OPEN(DSTPATH, O_CREAT | O_RDWR, 0640);
+
+ clone_range->src_fd = src_fd;
+
+ TST_EXP_FAIL(ioctl(dst_fd, FICLONE, src_fd), EOPNOTSUPP);
+ TST_EXP_FAIL(ioctl(dst_fd, FICLONERANGE, clone_range), EOPNOTSUPP);
+
+ SAFE_CLOSE(src_fd);
+ SAFE_CLOSE(dst_fd);
+}
+
+static void setup(void)
+{
+ struct stat sb;
+
+ SAFE_STAT(MNTPOINT, &sb);
+
+ clone_range->src_offset = 0;
+ clone_range->src_length = sb.st_blksize;
+ clone_range->dest_offset = 0;
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .min_kver = "4.5",
+ .needs_root = 1,
+ .mount_device = 1,
+ .mntpoint = MNTPOINT,
+ .all_filesystems = 1,
+ .skip_filesystems = (const char *[]) {
+ "btrfs",
+ "overlayfs",
+ "nfs",
+ "xfs",
+ NULL,
+ },
+ .bufs = (struct tst_buffers []) {
+ {&clone_range, .size = sizeof(struct file_clone_range)},
+ {},
+ }
+};
--
2.43.0
More information about the ltp
mailing list