All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/3] renameat2 rewrite
@ 2026-06-03 11:58 Petr Vorel
  2026-06-03 11:58 ` [LTP] [PATCH 1/3] renameat201.c: Rewrite into new API, split into renameat203.c Petr Vorel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Petr Vorel @ 2026-06-03 11:58 UTC (permalink / raw)
  To: ltp

Hi,

this was triggered to get renameat2() fallback from renameat2.h to
lapi/ for fanotify13 [1]. In the end it's not needed as an alternative
solution without it got merged as 7fd307c37a [2], so at least we have 2
rewritten tests (+ 1 new).

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/CAOQ4uxhR2CAKf0aALs7X2fLYMvgN5n8Hx3ADSDqdWXXnmdezQg@mail.gmail.com/
[2] https://github.com/linux-test-project/ltp/commit/7fd307c37a6b5b2dfffb280ef7e3f9f556fdcd34

Petr Vorel (3):
  renameat201.c: Rewrite into new API, split into renameat203.c
  renameat202.c: Rewrite into new API
  lapi: Move renameat2.h into lapi/stdio.h

 include/lapi/stdio.h                          |  25 +++
 .../kernel/syscalls/renameat2/renameat2.h     |  35 ----
 .../kernel/syscalls/renameat2/renameat201.c   | 174 +++++-------------
 .../kernel/syscalls/renameat2/renameat202.c   | 161 ++++++----------
 .../kernel/syscalls/renameat2/renameat203.c   |  99 ++++++++++
 5 files changed, 230 insertions(+), 264 deletions(-)
 create mode 100644 include/lapi/stdio.h
 delete mode 100644 testcases/kernel/syscalls/renameat2/renameat2.h
 create mode 100644 testcases/kernel/syscalls/renameat2/renameat203.c

-- 
2.54.0


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 1/3] renameat201.c: Rewrite into new API, split into renameat203.c
  2026-06-03 11:58 [LTP] [PATCH 0/3] renameat2 rewrite Petr Vorel
@ 2026-06-03 11:58 ` Petr Vorel
  2026-06-03 14:44   ` [LTP] " linuxtestproject.agent
  2026-06-03 11:58 ` [LTP] [PATCH 2/3] renameat202.c: Rewrite into new API Petr Vorel
  2026-06-03 11:58 ` [LTP] [PATCH 3/3] lapi: Move renameat2.h into lapi/stdio.h Petr Vorel
  2 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2026-06-03 11:58 UTC (permalink / raw)
  To: ltp

Keep only expected errors changes in renameat201.c, move successful
cases into renameat203.c (although RENAME_EXCHANGE is somehow covered by
renameat202.c, lets keep simple RENAME_EXCHANGE test also in new
renameat203.c).

Due cdd1fedf8261c ("btrfs: add support for RENAME_EXCHANGE and
RENAME_WHITEOUT") from v4.7-rc1 which has been backported to 4.4 based
SLES 12-SP3 kernel it's not possible to use TST_EXP_PASS() (which would
further simplify the code) because we cannot raise .min_kver = "4.7".

Other options would be to use tst_kvercmp2(), which is defacto
deprecated (single test is using it).

Simplify, print a description, fix typo implemented.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 .../kernel/syscalls/renameat2/renameat201.c   | 172 +++++-------------
 .../kernel/syscalls/renameat2/renameat203.c   |  99 ++++++++++
 2 files changed, 148 insertions(+), 123 deletions(-)
 create mode 100644 testcases/kernel/syscalls/renameat2/renameat203.c

diff --git a/testcases/kernel/syscalls/renameat2/renameat201.c b/testcases/kernel/syscalls/renameat2/renameat201.c
index 01e34d6534..a7ec388ab4 100644
--- a/testcases/kernel/syscalls/renameat2/renameat201.c
+++ b/testcases/kernel/syscalls/renameat2/renameat201.c
@@ -1,163 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Copyright (c) 2026 Petr Vorel <pvorel@suse.cz>
  */
 
- /* Description:
- *   Verify that:
- *   1) renameat2(2) returns -1 and sets errno to EEXIST because newpath
- *		already exists and the flag RENAME_NOREPLACE is used.
- *   2) renameat2(2) returns 0.
- *   3) renameat2(2) returns -1 and sets errno to ENOENT because the flag
- *		RENAME_EXCHANGE is used and newpath does not exist.
- *   4) renameat2(2) returns 0 because the flag RENAME_NOREPLACE is used,
- *		both olddirfd and newdirfd are valid and oldpath exists and
- *		newpath does not exist.
- *   5) renameat2(2) returns -1 and sets errno to EINVAL because
- *		RENAME_NOREPLACE and RENAME_EXCHANGE are used together
- *   6) renameat2(2) returns -1 and sets errno to EINVAL because
- *		RENAME_WHITEOUT and RENAME_EXCHANGE are used together
+/*\
+ * Verify that :manpage:`renameat2(2)` returns -1 and sets errno to:
+ *
+ * 1. EEXIST when newpath already exists and the flag RENAME_NOREPLACE is used.
+ * 2. ENOENT when the flag RENAME_EXCHANGE is used and newpath does not exist.
+ * 3. EINVAL when RENAME_NOREPLACE and RENAME_EXCHANGE are used together
+ * 4. EINVAL when RENAME_WHITEOUT and RENAME_EXCHANGE are used together
  */
 
 #define _GNU_SOURCE
 
-#include "test.h"
-#include "tso_safe_macros.h"
 #include "lapi/fcntl.h"
+#include "tst_test.h"
 #include "renameat2.h"
 
 #define TEST_DIR "test_dir/"
 #define TEST_DIR2 "test_dir2/"
 
+#define TEST_PATH TEST_DIR TEST_FILE
+#define TEST_PATH2 TEST_DIR2 TEST_FILE2
+
 #define TEST_FILE "test_file"
 #define TEST_FILE2 "test_file2"
-#define TEST_FILE3 "test_file3"
 #define NON_EXIST "non_exist"
 
-char *TCID = "renameat201";
-
-static int olddirfd;
-static int newdirfd;
-static long fs_type;
+#define FLAGS_ERRNO_DESC(x, y) .flags = x, .exp_errno = y, .desc = "flags: " #x ", errno: " #y
 
-static struct test_case {
-	int *olddirfd;
-	const char *oldpath;
-	int *newdirfd;
+static struct tcase {
 	const char *newpath;
 	int flags;
 	int exp_errno;
-} test_cases[] = {
-	{&olddirfd, TEST_FILE, &newdirfd, TEST_FILE2, RENAME_NOREPLACE, EEXIST},
-	{&olddirfd, TEST_FILE, &newdirfd, TEST_FILE2, RENAME_EXCHANGE, 0},
-	{&olddirfd, TEST_FILE, &newdirfd, NON_EXIST, RENAME_EXCHANGE, ENOENT},
-	{&olddirfd, TEST_FILE, &newdirfd, TEST_FILE3, RENAME_NOREPLACE, 0},
-	{&olddirfd, TEST_FILE, &newdirfd, TEST_FILE2, RENAME_NOREPLACE
-				| RENAME_EXCHANGE, EINVAL},
-	{&olddirfd, TEST_FILE, &newdirfd, TEST_FILE2, RENAME_WHITEOUT
-				| RENAME_EXCHANGE, EINVAL}
+	char *desc;
+} tcases[] = {
+	{TEST_FILE2, FLAGS_ERRNO_DESC(RENAME_NOREPLACE, EEXIST)},
+	{NON_EXIST, FLAGS_ERRNO_DESC(RENAME_EXCHANGE, ENOENT)},
+	{TEST_FILE2, FLAGS_ERRNO_DESC(RENAME_NOREPLACE | RENAME_EXCHANGE, EINVAL)},
+	{TEST_FILE2, FLAGS_ERRNO_DESC(RENAME_WHITEOUT | RENAME_EXCHANGE, EINVAL)}
 };
 
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void cleanup(void);
-static void renameat2_verify(const struct test_case *test);
-
-
-int main(int ac, char **av)
-{
-	int i;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; lc < TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++)
-			renameat2_verify(&test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
+static int olddirfd;
+static int newdirfd;
+static long fs_type;
 
 static void setup(void)
 {
-	tst_tmpdir();
-
-	fs_type = tst_fs_type(cleanup, ".");
+	fs_type = tst_fs_type(".");
 
-	SAFE_MKDIR(cleanup, TEST_DIR, 0700);
-	SAFE_MKDIR(cleanup, TEST_DIR2, 0700);
+	SAFE_MKDIR(TEST_DIR, 0700);
+	SAFE_MKDIR(TEST_DIR2, 0700);
 
-	SAFE_TOUCH(cleanup, TEST_DIR TEST_FILE, 0600, NULL);
-	SAFE_TOUCH(cleanup, TEST_DIR2 TEST_FILE2, 0600, NULL);
-	SAFE_TOUCH(cleanup, TEST_DIR TEST_FILE3, 0600, NULL);
+	olddirfd = SAFE_OPEN(TEST_DIR, O_DIRECTORY);
+	newdirfd = SAFE_OPEN(TEST_DIR2, O_DIRECTORY);
 
-	olddirfd = SAFE_OPEN(cleanup, TEST_DIR, O_DIRECTORY);
-	newdirfd = SAFE_OPEN(cleanup, TEST_DIR2, O_DIRECTORY);
+	SAFE_TOUCH(TEST_PATH, 0600, NULL);
+	SAFE_TOUCH(TEST_PATH2, 0600, NULL);
 }
 
 static void cleanup(void)
 {
-	if (olddirfd > 0 && close(olddirfd) < 0)
-		tst_resm(TWARN | TERRNO, "close olddirfd failed");
-
-	if (newdirfd > 0 && close(newdirfd) < 0)
-		tst_resm(TWARN | TERRNO, "close newdirfd failed");
-
-	tst_rmdir();
+	if (olddirfd > 0)
+		SAFE_CLOSE(olddirfd);
 
+	if (newdirfd > 0)
+		SAFE_CLOSE(newdirfd);
 }
 
-static void renameat2_verify(const struct test_case *test)
+static void renameat2_verify(unsigned int i)
 {
-	TEST(renameat2(*(test->olddirfd), test->oldpath,
-			*(test->newdirfd), test->newpath, test->flags));
-
-	if ((test->flags & RENAME_EXCHANGE) && EINVAL == TEST_ERRNO
-		&& fs_type == TST_BTRFS_MAGIC) {
-		tst_resm(TCONF,
-			"RENAME_EXCHANGE flag is not implemeted on %s",
-			tst_fs_type_name(fs_type));
-		return;
-	}
-
-	if (test->exp_errno && TEST_RETURN != -1) {
-		tst_resm(TFAIL, "renameat2() succeeded unexpectedly");
-		return;
-	}
-
-	if (test->exp_errno == 0 && TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "renameat2() failed unexpectedly");
-		return;
-	}
-
-	if (test->exp_errno == TEST_ERRNO) {
-		tst_resm(TPASS | TTERRNO,
-		"renameat2() returned the expected value");
-		return;
-	}
-
-	tst_resm(TFAIL | TTERRNO,
-		"renameat2() got unexpected return value: expected: %d - %s",
-			test->exp_errno, tst_strerrno(test->exp_errno));
+	struct tcase *tc = &tcases[i];
 
+	tst_res(TINFO, "Testing flag: %s", tc->desc);
+
+	TST_EXP_FAIL(renameat2(olddirfd, TEST_FILE, newdirfd, tc->newpath,
+						   tc->flags), tc->exp_errno);
 }
+
+static struct tst_test test = {
+	.test = renameat2_verify,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/renameat2/renameat203.c b/testcases/kernel/syscalls/renameat2/renameat203.c
new file mode 100644
index 0000000000..dba12e48b3
--- /dev/null
+++ b/testcases/kernel/syscalls/renameat2/renameat203.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
+ * Copyright (c) 2026 Petr Vorel <pvorel@suse.cz>
+ */
+
+/*\
+ * Verify that :manpage:`renameat2(2)` works on these flags:
+ *
+ * 1. RENAME_EXCHANGE
+ * 2. RENAME_NOREPLACE
+ */
+
+#define _GNU_SOURCE
+
+#include "lapi/fcntl.h"
+#include "tst_test.h"
+#include "renameat2.h"
+
+#define TEST_DIR "test_dir/"
+#define TEST_DIR2 "test_dir2/"
+
+#define TEST_FILE "test_file"
+#define TEST_FILE2 "test_file2"
+
+#define TEST_PATH TEST_DIR TEST_FILE
+#define TEST_PATH2 TEST_DIR2 TEST_FILE2
+
+#define FLAGS_DESC(x) .flags = x, .desc = #x
+
+static struct tcase {
+	int flags;
+	char *desc;
+} tcases[] = {
+	{FLAGS_DESC(RENAME_EXCHANGE)},
+	{FLAGS_DESC(RENAME_NOREPLACE)},
+};
+
+static int olddirfd;
+static int newdirfd;
+static long fs_type;
+
+static void setup(void)
+{
+	// TODO
+	fs_type = tst_fs_type(".");
+
+	SAFE_MKDIR(TEST_DIR, 0700);
+	SAFE_MKDIR(TEST_DIR2, 0700);
+
+	olddirfd = SAFE_OPEN(TEST_DIR, O_DIRECTORY);
+	newdirfd = SAFE_OPEN(TEST_DIR2, O_DIRECTORY);
+}
+
+static void cleanup(void)
+{
+	if (olddirfd > 0)
+		SAFE_CLOSE(olddirfd);
+
+	if (newdirfd > 0)
+		SAFE_CLOSE(newdirfd);
+}
+
+static void renameat2_verify(unsigned int i)
+{
+	struct tcase *tc = &tcases[i];
+
+	tst_res(TINFO, "Testing flag: %s", tc->desc);
+
+	SAFE_TOUCH(TEST_PATH, 0600, NULL);
+	if (!i)
+		SAFE_TOUCH(TEST_PATH2, 0600, NULL);
+
+	TEST(renameat2(olddirfd, TEST_FILE, newdirfd, TEST_FILE2, tc->flags));
+	SAFE_UNLINK(TEST_PATH2);
+
+	if (TST_RET == -1) {
+		/*
+		 * cdd1fedf8261c ("btrfs: add support for RENAME_EXCHANGE and
+		 * RENAME_WHITEOUT") from v4.7-rc1 has been backported to 4.4
+		 * based SLES 12-SP3 kernel.
+		 */
+		if (TST_ERR == EINVAL && fs_type == TST_BTRFS_MAGIC) {
+			tst_res(TCONF, "RENAME_EXCHANGE flag is not implemented on %s",
+				tst_fs_type_name(fs_type));
+			return;
+		}
+		tst_brk(TFAIL | TTERRNO, "renameat2() failed");
+	}
+	tst_res(TPASS, "renameat2() passed");
+}
+
+static struct tst_test test = {
+	.test = renameat2_verify,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
2.54.0


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/3] renameat202.c: Rewrite into new API
  2026-06-03 11:58 [LTP] [PATCH 0/3] renameat2 rewrite Petr Vorel
  2026-06-03 11:58 ` [LTP] [PATCH 1/3] renameat201.c: Rewrite into new API, split into renameat203.c Petr Vorel
@ 2026-06-03 11:58 ` Petr Vorel
  2026-06-03 11:58 ` [LTP] [PATCH 3/3] lapi: Move renameat2.h into lapi/stdio.h Petr Vorel
  2 siblings, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2026-06-03 11:58 UTC (permalink / raw)
  To: ltp

Again, as in previous commit, Due cdd1fedf8261c ("btrfs: add support
for RENAME_EXCHANGE and RENAME_WHITEOUT") from v4.7-rc1 which has been
backported to 4.4 based SLES 12-SP3 kernel it's not possible to use
TST_EXP_PASS() (which would further simplify the code) because we cannot
raise .min_kver = "4.7".

Other options would be to use tst_kvercmp2(), which is defacto
deprecated (single test is using it).

* Replace char content[] as preprocessor macro, fix typo implemeted.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 .../kernel/syscalls/renameat2/renameat202.c   | 159 ++++++------------
 1 file changed, 55 insertions(+), 104 deletions(-)

diff --git a/testcases/kernel/syscalls/renameat2/renameat202.c b/testcases/kernel/syscalls/renameat2/renameat202.c
index a635206f7d..17acd7206e 100644
--- a/testcases/kernel/syscalls/renameat2/renameat202.c
+++ b/testcases/kernel/syscalls/renameat2/renameat202.c
@@ -1,31 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Copyright (c) 2026 Petr Vorel <pvorel@suse.cz>
  */
 
- /* Description:
- *   Calls renameat2(2) with the flag RENAME_EXCHANGE and check that
- *   the content was swapped
+/*\
+ * Verify that :manpage:`renameat2(2)` with RENAME_EXCHANGE swapps the content.
  */
 
 #define _GNU_SOURCE
 
-#include "test.h"
-#include "tso_safe_macros.h"
 #include "lapi/fcntl.h"
+#include "tst_test.h"
 #include "renameat2.h"
 
 #define TEST_DIR "test_dir/"
@@ -34,80 +20,42 @@
 #define TEST_FILE "test_file"
 #define TEST_FILE2 "test_file2"
 
-char *TCID = "renameat202";
+#define CONTENT "content"
 
 static int olddirfd;
 static int newdirfd;
 static int fd = -1;
-static int cnt;
-
-static const char content[] = "content";
 static long fs_type;
 
-
-int TST_TOTAL = 1;
-
-static void setup(void);
-static void cleanup(void);
-static void renameat2_verify(void);
-
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(renameat2(olddirfd, TEST_FILE,
-				newdirfd, TEST_FILE2, RENAME_EXCHANGE));
-
-		cnt++;
-
-		renameat2_verify();
-	}
-
-	cleanup();
-	tst_exit();
-}
+/* workaround for iterations not being exposed by lib/tst_test.c */
+static int cnt;
 
 static void setup(void)
 {
-	tst_tmpdir();
-
-	fs_type = tst_fs_type(cleanup, ".");
-
-	SAFE_MKDIR(cleanup, TEST_DIR, 0700);
-	SAFE_MKDIR(cleanup, TEST_DIR2, 0700);
+	fs_type = tst_fs_type(".");
 
-	SAFE_TOUCH(cleanup, TEST_DIR TEST_FILE, 0600, NULL);
-	SAFE_TOUCH(cleanup, TEST_DIR2 TEST_FILE2, 0600, NULL);
+	SAFE_MKDIR(TEST_DIR, 0700);
+	SAFE_MKDIR(TEST_DIR2, 0700);
 
-	olddirfd = SAFE_OPEN(cleanup, TEST_DIR, O_DIRECTORY);
-	newdirfd = SAFE_OPEN(cleanup, TEST_DIR2, O_DIRECTORY);
+	SAFE_TOUCH(TEST_DIR TEST_FILE, 0600, NULL);
+	SAFE_TOUCH(TEST_DIR2 TEST_FILE2, 0600, NULL);
 
-	SAFE_FILE_PRINTF(cleanup, TEST_DIR TEST_FILE, "%s", content);
+	olddirfd = SAFE_OPEN(TEST_DIR, O_DIRECTORY);
+	newdirfd = SAFE_OPEN(TEST_DIR2, O_DIRECTORY);
 
+	SAFE_FILE_PRINTF(TEST_DIR TEST_FILE, "%s", CONTENT);
 }
 
 static void cleanup(void)
 {
-	if (olddirfd > 0 && close(olddirfd) < 0)
-		tst_resm(TWARN | TERRNO, "close olddirfd failed");
+	if (olddirfd > 0)
+		SAFE_CLOSE(olddirfd);
 
-	if (newdirfd > 0 && close(newdirfd) < 0)
-		tst_resm(TWARN | TERRNO, "close newdirfd failed");
-
-	if (fd > 0 && close(fd) < 0)
-		tst_resm(TWARN | TERRNO, "close fd failed");
-
-	tst_rmdir();
+	if (newdirfd > 0)
+		SAFE_CLOSE(newdirfd);
 
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
 
 static void renameat2_verify(void)
@@ -116,51 +64,54 @@ static void renameat2_verify(void)
 	struct stat st;
 	char *emptyfile;
 	char *contentfile;
-	int readn, data_len;
-
-	if (TEST_ERRNO == EINVAL && TST_BTRFS_MAGIC == fs_type) {
-		tst_brkm(TCONF, cleanup,
-			"RENAME_EXCHANGE flag is not implemeted on %s",
-			tst_fs_type_name(fs_type));
-	}
 
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "renameat2() failed unexpectedly");
-		return;
+	TEST(renameat2(olddirfd, TEST_FILE, newdirfd, TEST_FILE2,
+		       RENAME_EXCHANGE));
+
+	if (TST_RET == -1) {
+		/*
+		 * cdd1fedf8261c ("btrfs: add support for RENAME_EXCHANGE and
+		 * RENAME_WHITEOUT") from v4.7-rc1 has been backported to 4.4
+		 * based SLES 12-SP3 kernel.
+		 */
+		if (TST_ERR == EINVAL && fs_type == TST_BTRFS_MAGIC) {
+			tst_brk(TCONF, "RENAME_EXCHANGE flag is not implemented on %s",
+				tst_fs_type_name(fs_type));
+		}
+		tst_brk(TFAIL | TTERRNO, "renameat2() failed");
 	}
 
-	if (cnt % 2 == 1) {
+	if (cnt % 2 == 0) {
 		emptyfile = TEST_DIR TEST_FILE;
 		contentfile = TEST_DIR2 TEST_FILE2;
 	} else {
 		emptyfile = TEST_DIR2 TEST_FILE2;
 		contentfile = TEST_DIR TEST_FILE;
 	}
+	cnt++;
 
-	fd = SAFE_OPEN(cleanup, contentfile, O_RDONLY);
-
-	SAFE_STAT(cleanup, emptyfile, &st);
+	fd = SAFE_OPEN(contentfile, O_RDONLY);
 
-	readn = SAFE_READ(cleanup, 0, fd, str, BUFSIZ);
+	SAFE_STAT(emptyfile, &st);
 
-	if (close(fd) < 0)
-		tst_brkm(TERRNO | TFAIL, cleanup, "close fd failed");
-	fd = 0;
+	SAFE_READ(SAFE_READ_ANY_EAGAIN, fd, str, BUFSIZ);
+	SAFE_CLOSE(fd);
 
-	data_len = sizeof(content) - 1;
-	if (readn != data_len) {
-		tst_resm(TFAIL, "Wrong number of bytes read after renameat2(). "
-				"Expect %d, got %d", data_len, readn);
-		return;
-	}
-	if (strncmp(content, str, data_len)) {
-		tst_resm(TFAIL, "File content changed after renameat2(). "
-				"Expect '%s', got '%s'", content, str);
+	TST_EXP_EQ_STRN(CONTENT, str, sizeof(CONTENT) - 1);
+	if (!TST_PASS)
 		return;
-	}
+
 	if (st.st_size) {
-		tst_resm(TFAIL, "emptyfile has non-zero file size");
+		tst_res(TFAIL, "emptyfile has non-zero file size");
 		return;
 	}
-	tst_resm(TPASS, "renameat2() test passed");
+
+	tst_res(TPASS, "renameat2() test passed");
 }
+
+static struct tst_test test = {
+	.test_all = renameat2_verify,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
2.54.0


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 3/3] lapi: Move renameat2.h into lapi/stdio.h
  2026-06-03 11:58 [LTP] [PATCH 0/3] renameat2 rewrite Petr Vorel
  2026-06-03 11:58 ` [LTP] [PATCH 1/3] renameat201.c: Rewrite into new API, split into renameat203.c Petr Vorel
  2026-06-03 11:58 ` [LTP] [PATCH 2/3] renameat202.c: Rewrite into new API Petr Vorel
@ 2026-06-03 11:58 ` Petr Vorel
  2 siblings, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2026-06-03 11:58 UTC (permalink / raw)
  To: ltp

Fallback definition for renameat2() is currently needed at least for
Musl < v1.2.6 (in current Alpine in CI) and openSUSE Leap 42.2
(still being supported due the same SLES version being tested).

testcases/kernel/syscalls/renameat2/renameat2.h was a test specific
header which contains only fallback for renameat2(). Move it into
include/lapi/stdio.h with minor cleanup. That will help to use it in
other tests.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Originally triggered by fanotify13.c fix, see the cover letter.

 include/lapi/stdio.h                          | 25 +++++++++++++
 .../kernel/syscalls/renameat2/renameat2.h     | 35 -------------------
 .../kernel/syscalls/renameat2/renameat201.c   |  4 +--
 .../kernel/syscalls/renameat2/renameat202.c   |  2 +-
 .../kernel/syscalls/renameat2/renameat203.c   |  4 +--
 5 files changed, 30 insertions(+), 40 deletions(-)
 create mode 100644 include/lapi/stdio.h
 delete mode 100644 testcases/kernel/syscalls/renameat2/renameat2.h

diff --git a/include/lapi/stdio.h b/include/lapi/stdio.h
new file mode 100644
index 0000000000..cdcb3e2062
--- /dev/null
+++ b/include/lapi/stdio.h
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
+ * Copyright (c) 2026 Petr Vorel <pvorel@suse.cz>
+ */
+
+#ifndef LAPI_STDIO_H__
+#define LAPI_STDIO_H__
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#ifndef HAVE_RENAMEAT2
+int renameat2(int olddirfd, const char *oldpath, int newdirfd,
+				const char *newpath, unsigned int flags)
+{
+	return tst_syscall(__NR_renameat2, olddirfd, oldpath, newdirfd,
+						newpath, flags);
+}
+#endif
+
+#endif /* LAPI_STDIO_H__ */
diff --git a/testcases/kernel/syscalls/renameat2/renameat2.h b/testcases/kernel/syscalls/renameat2/renameat2.h
deleted file mode 100644
index c4688ed535..0000000000
--- a/testcases/kernel/syscalls/renameat2/renameat2.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef RENAMEAT2_H
-#define RENAMEAT2_H
-
-#include <sys/types.h>
-#include "config.h"
-#include "lapi/syscalls.h"
-
-#if !defined(HAVE_RENAMEAT2)
-int renameat2(int olddirfd, const char *oldpath, int newdirfd,
-				const char *newpath, unsigned int flags)
-{
-	return tst_syscall(__NR_renameat2, olddirfd, oldpath, newdirfd,
-						newpath, flags);
-}
-#endif
-
-#endif /* RENAMEAT2_H */
diff --git a/testcases/kernel/syscalls/renameat2/renameat201.c b/testcases/kernel/syscalls/renameat2/renameat201.c
index a7ec388ab4..0ffb147af1 100644
--- a/testcases/kernel/syscalls/renameat2/renameat201.c
+++ b/testcases/kernel/syscalls/renameat2/renameat201.c
@@ -15,9 +15,9 @@
 
 #define _GNU_SOURCE
 
-#include "lapi/fcntl.h"
 #include "tst_test.h"
-#include "renameat2.h"
+#include "lapi/fcntl.h"
+#include "lapi/stdio.h"
 
 #define TEST_DIR "test_dir/"
 #define TEST_DIR2 "test_dir2/"
diff --git a/testcases/kernel/syscalls/renameat2/renameat202.c b/testcases/kernel/syscalls/renameat2/renameat202.c
index 17acd7206e..79c2abaea9 100644
--- a/testcases/kernel/syscalls/renameat2/renameat202.c
+++ b/testcases/kernel/syscalls/renameat2/renameat202.c
@@ -12,7 +12,7 @@
 
 #include "lapi/fcntl.h"
 #include "tst_test.h"
-#include "renameat2.h"
+#include "lapi/stdio.h"
 
 #define TEST_DIR "test_dir/"
 #define TEST_DIR2 "test_dir2/"
diff --git a/testcases/kernel/syscalls/renameat2/renameat203.c b/testcases/kernel/syscalls/renameat2/renameat203.c
index dba12e48b3..262c871983 100644
--- a/testcases/kernel/syscalls/renameat2/renameat203.c
+++ b/testcases/kernel/syscalls/renameat2/renameat203.c
@@ -13,9 +13,9 @@
 
 #define _GNU_SOURCE
 
-#include "lapi/fcntl.h"
 #include "tst_test.h"
-#include "renameat2.h"
+#include "lapi/fcntl.h"
+#include "lapi/stdio.h"
 
 #define TEST_DIR "test_dir/"
 #define TEST_DIR2 "test_dir2/"
-- 
2.54.0


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] renameat201.c: Rewrite into new API, split into renameat203.c
  2026-06-03 11:58 ` [LTP] [PATCH 1/3] renameat201.c: Rewrite into new API, split into renameat203.c Petr Vorel
@ 2026-06-03 14:44   ` linuxtestproject.agent
  0 siblings, 0 replies; 5+ messages in thread
From: linuxtestproject.agent @ 2026-06-03 14:44 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi Petr,

thanks for working on the renameat2 conversion/cleanup. The direction looks good, but I don't think this series is ready yet. There are a few must-fix issues here:

- patch 1 adds renameat203.c but does not register it in runtest/syscalls, so the new test never runs;
- patch 1 also drops the old btrfs-specific RENAME_EXCHANGE handling for the ENOENT case, which will regress on the kernels mentioned in the commit message;
- patch 3 moves the fallback into a misleading lapi/stdio.h name and puts a non-static function definition into a public header.

Please see inline comments below.

---
[PATCH 1/3] renameat201.c: Rewrite into new API, split into renameat203.c

BUG: renameat203 is built but never added to runtest/syscalls, so the new test will not be executed by the harness.

> runtest/syscalls
> renameat201 renameat201
> renameat202 renameat202 -i 10

Please add:

> renameat203 renameat203

Without that, the split is incomplete.

BUG: this patch removes the old btrfs-specific handling for RENAME_EXCHANGE, but one of the remaining cases still depends on it.

> +	{NON_EXIST, FLAGS_ERRNO_DESC(RENAME_EXCHANGE, ENOENT)},
> ...
> +	TST_EXP_FAIL(renameat2(olddirfd, TEST_FILE, newdirfd, tc->newpath,
> +			   tc->flags), tc->exp_errno);

On older btrfs kernels, RENAME_EXCHANGE returns EINVAL because the flag is not supported, regardless of whether newpath exists. The old code handled this with a TCONF path:

> if ((test->flags & RENAME_EXCHANGE) && EINVAL == TEST_ERRNO
>     && fs_type == TST_BTRFS_MAGIC)

That exception needs to be restored for the RENAME_EXCHANGE case, otherwise this will fail on the backported kernels mentioned in the commit message.

BUG: fs_type became dead code in renameat201.c.

> +static long fs_type;
> ...
> +	fs_type = tst_fs_type(".");

After removing the btrfs check from renameat2_verify(), fs_type is no longer used. Either restore the compatibility check above or drop fs_type entirely.

BUG: renameat203.c is left with an unfinished TODO in submitted code.

> +static void setup(void)
> +{
> +	// TODO
> +	fs_type = tst_fs_type(".");

Please do not leave a bare TODO in the final patch. Either finish whatever is missing or remove the comment.

minor: desc points to string literals, so this should be const char *.

> +struct tcase {
> +	const char *newpath;
> +	int flags;
> +	int exp_errno;
> +	char *desc;

minor: the macro ordering is a bit confusing here:

> +#define TEST_PATH TEST_DIR TEST_FILE
> +#define TEST_PATH2 TEST_DIR2 TEST_FILE2
> +
> +#define TEST_FILE "test_file"
> +#define TEST_FILE2 "test_file2"

This works because macro expansion is lazy, but it reads backwards. Please define TEST_FILE/TEST_FILE2 before the TEST_PATH helpers.

nit: LTP subjects usually omit the .c suffix, so I would expect:

> renameat201: Rewrite into new API, split into renameat203

Commit message nits:
- "lets keep" -> "let's keep"
- "Due cdd1fedf8261c" -> "Due to cdd1fedf8261c"
- "defacto" -> "de facto"
- "somehow covered" is vague; "also covered" would read better

---
[PATCH 2/3] renameat202.c: Rewrite into new API

nit: typo in the test description.

>  * Verify that :manpage:`renameat2(2)` with RENAME_EXCHANGE swapps the content.

"swapps" -> "swaps"

nit: same subject style comment as patch 1; I'd drop the .c suffix:

> renameat202: Rewrite into new API

Commit message nits:
- "Due cdd1fedf8261c" -> "Due to cdd1fedf8261c"
- "defacto" -> "de facto"
- "Again, as in previous commit," is weak context; I'd restate the actual constraint directly instead of referring back to the previous patch

---
[PATCH 3/3] lapi: Move renameat2.h into lapi/stdio.h

NACK: lapi/stdio.h is the wrong name for this fallback.

> +++ b/include/lapi/stdio.h

stdio.h means standard I/O. renameat2() is a rename syscall, not a stdio interface. Other lapi headers are named after the API they provide (execveat.h, close_range.h, fallocate.h, ...), so this really should be something like lapi/renameat2.h (or, less preferably, lapi/rename.h).

BUG: the fallback definition in a public header must be static inline.

> +#ifndef HAVE_RENAMEAT2
> +int renameat2(int olddirfd, const char *oldpath, int newdirfd,
> +				const char *newpath, unsigned int flags)
> +{
> +	return tst_syscall(__NR_renameat2, olddirfd, oldpath, newdirfd,
> +						newpath, flags);
> +}
> +#endif

All other lapi fallback wrappers use static inline. Without that, including this header in multiple translation units can produce multiple-definition linker failures. For a shared lapi header, that is a real bug and must be fixed before merge.

minor: these includes are not needed for the renameat2() fallback:

> +#include <stdio.h>
> +#include <stdint.h>

The old test-local header only needed config.h, lapi/syscalls.h and sys/types.h, and that is enough here too.

minor: once the header is renamed, the subject should probably be adjusted as well, since the patch does more than just "move renameat2.h"; it also updates the tests to include the new header.

---
So overall this is a NACK for now.

The must-fix items are:
1. add renameat203 to runtest/syscalls;
2. restore the btrfs/RENAME_EXCHANGE compatibility handling in renameat201;
3. rename lapi/stdio.h to something API-appropriate;
4. make the fallback wrapper static inline.

The rest are minor cleanups, but I would also fix them in the respin.

Thanks.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-03 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03 11:58 [LTP] [PATCH 0/3] renameat2 rewrite Petr Vorel
2026-06-03 11:58 ` [LTP] [PATCH 1/3] renameat201.c: Rewrite into new API, split into renameat203.c Petr Vorel
2026-06-03 14:44   ` [LTP] " linuxtestproject.agent
2026-06-03 11:58 ` [LTP] [PATCH 2/3] renameat202.c: Rewrite into new API Petr Vorel
2026-06-03 11:58 ` [LTP] [PATCH 3/3] lapi: Move renameat2.h into lapi/stdio.h Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.