public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 2/2] mount_setattr01: add open_tree_attr variant
Date: Tue, 02 Sep 2025 10:29:37 +0200	[thread overview]
Message-ID: <20250902-open_tree_attr-v2-2-b23d2585986d@suse.com> (raw)
In-Reply-To: <20250902-open_tree_attr-v2-0-b23d2585986d@suse.com>

From: Andrea Cervesato <andrea.cervesato@suse.com>

This patch simply introduces a new variant to the mount_setattr01
test, in order to verify that open_tree_attr() works correctly.
The open_tree_attr() syscall has been introduced in the kernel v6.15 by
commit "c4a16820d901 - fs: add open_tree_attr()".

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 .../syscalls/mount_setattr/mount_setattr01.c       | 68 ++++++++++++++++------
 1 file changed, 51 insertions(+), 17 deletions(-)

diff --git a/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c b/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
index eb32cd91a7fcb4cb303e184dd40d5e10a280874c..2e3fee5cdda905858f89b12a2b3b65255d46297d 100644
--- a/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
+++ b/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
@@ -3,10 +3,11 @@
  * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
  * Author: Dai Shili <daisl.fnst@fujitsu.com>
  * Author: Chen Hanxiao <chenhx.fnst@fujitsu.com>
+ * Copyright (C) 2025 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
 /*\
- * Basic mount_setattr() test.
+ * Basic mount_setattr()/open_tree_attr() test.
  * Test whether the basic mount attributes are set correctly.
  *
  * Verify some MOUNT_SETATTR(2) attributes:
@@ -22,7 +23,8 @@
  * - MOUNT_ATTR_NODIRATIME - prevents updating access time for
  *   directories on this mount
  *
- * The functionality was added in v5.12.
+ * The mount_setattr functionality was added in v5.12, while the open_tree_attr
+ * functionality was added in v6.15.
  */
 
 #define _GNU_SOURCE
@@ -41,6 +43,7 @@
 	}
 
 static int mount_flag, otfd = -1;
+struct mount_attr *attr;
 
 static struct tcase {
 	char *name;
@@ -66,35 +69,61 @@ static void cleanup(void)
 static void setup(void)
 {
 	fsopen_supported_by_kernel();
-	struct stat st = {0};
 
-	if (stat(OT_MNTPOINT, &st) == -1)
+	if (access(OT_MNTPOINT, F_OK) != 0)
 		SAFE_MKDIR(OT_MNTPOINT, 0777);
 }
 
+static int open_tree_variant1(struct mount_attr *attr)
+{
+	tst_res(TINFO, "Variant using open_tree() + mount_setattr()");
+
+	otfd = TST_EXP_FD_SILENT(open_tree(AT_FDCWD, MNTPOINT,
+			AT_EMPTY_PATH | OPEN_TREE_CLONE));
+	if (otfd == -1)
+		return -1;
+
+	TST_EXP_PASS(mount_setattr(otfd, "", AT_EMPTY_PATH,
+			attr, sizeof(*attr)));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(otfd);
+		return -1;
+	}
+
+	return otfd;
+}
+
+static int open_tree_variant2(struct mount_attr *attr)
+{
+	tst_res(TINFO, "Variant using open_tree_attr()");
+
+	otfd = TST_EXP_FD(open_tree_attr(AT_FDCWD, MNTPOINT,
+			AT_EMPTY_PATH | OPEN_TREE_CLONE,
+			attr, sizeof(*attr)));
+
+	return otfd;
+}
+
 static void run(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
-	struct mount_attr attr = {
-		.attr_set = tc->mount_attrs,
-	};
 	struct statvfs buf;
 
-	TST_EXP_FD_SILENT(open_tree(AT_FDCWD, MNTPOINT, AT_EMPTY_PATH |
-		AT_SYMLINK_NOFOLLOW | OPEN_TREE_CLOEXEC | OPEN_TREE_CLONE));
-	if (!TST_PASS)
-		return;
+	memset(attr, 0, sizeof(*attr));
+	attr->attr_set = tc->mount_attrs;
 
-	otfd = (int)TST_RET;
+	if (tst_variant)
+		otfd = open_tree_variant1(attr);
+	else
+		otfd = open_tree_variant2(attr);
 
-	TST_EXP_PASS_SILENT(mount_setattr(otfd, "", AT_EMPTY_PATH, &attr, sizeof(attr)),
-		"%s set", tc->name);
-	if (!TST_PASS)
-		goto out1;
+	if (otfd == -1)
+		goto out2;
 
 	TST_EXP_PASS_SILENT(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
 	if (!TST_PASS)
 		goto out1;
+
 	mount_flag = 1;
 	SAFE_CLOSE(otfd);
 
@@ -123,9 +152,14 @@ static struct tst_test test = {
 	.test = run,
 	.setup = setup,
 	.cleanup = cleanup,
+	.test_variants = 2,
 	.needs_root = 1,
 	.mount_device = 1,
 	.mntpoint = MNTPOINT,
 	.all_filesystems = 1,
-	.skip_filesystems = (const char *const []){"fuse", NULL},
+	.skip_filesystems = (const char *const []) {"fuse", NULL},
+	.bufs = (struct tst_buffers []) {
+		{&attr, .size = sizeof(struct mount_attr)},
+		{}
+	}
 };

-- 
2.51.0


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

  parent reply	other threads:[~2025-09-02  8:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02  8:29 [LTP] [PATCH v2 0/2] open_tree_attr syscall coverage Andrea Cervesato
2025-09-02  8:29 ` [LTP] [PATCH v2 1/2] Add open_tree_attr fallback Andrea Cervesato
2025-09-17 12:02   ` Petr Vorel
2025-09-02  8:29 ` Andrea Cervesato [this message]
2025-09-17 12:22   ` [LTP] [PATCH v2 2/2] mount_setattr01: add open_tree_attr variant Petr Vorel
2025-09-17 12:41     ` Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250902-open_tree_attr-v2-2-b23d2585986d@suse.com \
    --to=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox