[LTP] [PATCH 2/2] Add new test ioctl_getlbmd01
Andrea Cervesato
andrea.cervesato@suse.de
Wed Mar 25 15:19:11 CET 2026
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify :manpage:`ioctl(2)` with FS_IOC_GETLBMD_CAP on block devices.
- fill struct logical_block_metadata_cap with non-zero pattern, call
FS_IOC_GETLBMD_CAP on a block device without integrity support
and verify the kernel zeroed out all fields
- call FS_IOC_GETLBMD_CAP on a regular file and verify it fails
with ENOTTY
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_getlbmd01.c | 84 +++++++++++++++++++++++
3 files changed, 87 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 6ba0227a87f30e68e473c9019a6e6acc224738d9..e94a9cb58a1563dc15f26a16db480c8cac468375 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -624,6 +624,8 @@ ioctl_ficlonerange01 ioctl_ficlonerange01
ioctl_ficlonerange02 ioctl_ficlonerange02
ioctl_fiemap01 ioctl_fiemap01
+ioctl_getlbmd01 ioctl_getlbmd01
+
ioctl_pidfd01 ioctl_pidfd01
ioctl_pidfd02 ioctl_pidfd02
ioctl_pidfd03 ioctl_pidfd03
diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
index dac4583fa7c05a4cdd937e86bd8f935dd15aebc8..63765dea61a795aac01e5b6b14996e441b56d3e3 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -30,6 +30,7 @@
/ioctl_ficlonerange01
/ioctl_ficlonerange02
/ioctl_fiemap01
+/ioctl_getlbmd01
/ioctl_pidfd01
/ioctl_pidfd02
/ioctl_pidfd03
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_getlbmd01.c b/testcases/kernel/syscalls/ioctl/ioctl_getlbmd01.c
new file mode 100644
index 0000000000000000000000000000000000000000..56622977fa949e47ffaaf7403e1f266768366878
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_getlbmd01.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify :manpage:`ioctl(2)` with FS_IOC_GETLBMD_CAP on block devices.
+ *
+ * - fill struct logical_block_metadata_cap with non-zero pattern, call
+ * FS_IOC_GETLBMD_CAP on a block device without integrity support
+ * and verify the kernel zeroed out all fields
+ * - call FS_IOC_GETLBMD_CAP on a regular file and verify it fails
+ * with ENOTTY
+ */
+
+#include <sys/ioctl.h>
+#include "tst_test.h"
+#include "lapi/fs.h"
+
+static int dev_fd = -1;
+static int file_fd = -1;
+
+static struct logical_block_metadata_cap *meta_cap;
+
+static void run(void)
+{
+ memset(meta_cap, 0xff, sizeof(*meta_cap));
+
+ TST_EXP_PASS(ioctl(dev_fd, FS_IOC_GETLBMD_CAP, meta_cap),
+ "FS_IOC_GETLBMD_CAP on block device");
+
+ if (!TST_PASS)
+ return;
+
+ TST_EXP_EQ_LU(meta_cap->lbmd_flags, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_interval, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_size, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_opaque_size, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_opaque_offset, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_pi_size, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_pi_offset, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_guard_tag_type, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_app_tag_size, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_ref_tag_size, 0);
+ TST_EXP_EQ_LU(meta_cap->lbmd_storage_tag_size, 0);
+
+ TST_EXP_FAIL(ioctl(file_fd, FS_IOC_GETLBMD_CAP, meta_cap), ENOTTY,
+ "FS_IOC_GETLBMD_CAP on regular file");
+}
+
+static void setup(void)
+{
+ dev_fd = SAFE_OPEN(tst_device->dev, O_RDONLY);
+
+ SAFE_TOUCH("testfile", 0644, NULL);
+ file_fd = SAFE_OPEN("testfile", O_RDONLY);
+}
+
+static void cleanup(void)
+{
+ if (file_fd != -1)
+ SAFE_CLOSE(file_fd);
+
+ if (dev_fd != -1)
+ SAFE_CLOSE(dev_fd);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_device = 1,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .min_kver = "6.17",
+ .needs_kconfigs = (const char *[]) {
+ "CONFIG_BLK_DEV_INTEGRITY=y",
+ NULL,
+ },
+ .bufs = (struct tst_buffers[]) {
+ {&meta_cap, .size = sizeof(*meta_cap)},
+ {},
+ },
+};
--
2.51.0
More information about the ltp
mailing list