All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/3] Increase coverage for swapon syscall
@ 2026-08-27 11:54 Andrea Cervesato
  2026-08-27 11:54 ` [LTP] [PATCH 1/3] lapi: fallback definitions " Andrea Cervesato
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Andrea Cervesato @ 2026-08-27 11:54 UTC (permalink / raw)
  To: Linux Test Project

Complete the EINVAL coverage on invalid input data and create a new test
to verify discarding pages functionalities.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Andrea Cervesato (3):
      lapi: fallback definitions for swapon syscall
      swapon04: Add test for discard flags
      swapon02: Add test cases for invalid swapflags

 include/tse_swap.h                          |  16 +++
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/swapon/.gitignore |   1 +
 testcases/kernel/syscalls/swapon/swapon02.c |  58 +++++---
 testcases/kernel/syscalls/swapon/swapon04.c | 197 ++++++++++++++++++++++++++++
 5 files changed, 257 insertions(+), 16 deletions(-)
---
base-commit: 9118a480cc68700f27944aab817e0202e9e6136c
change-id: 20260827-swapon_discard_coverage-34861d63fc55

Best regards,
--  
Andrea Cervesato <andrea.cervesato@suse.com>


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

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

* [LTP] [PATCH 1/3] lapi: fallback definitions for swapon syscall
  2026-08-27 11:54 [LTP] [PATCH 0/3] Increase coverage for swapon syscall Andrea Cervesato
@ 2026-08-27 11:54 ` Andrea Cervesato
  2026-08-27 13:58   ` [LTP] " linuxtestproject.agent
  2026-08-28  7:54   ` [LTP] [PATCH 1/3] " Li Wang
  2026-08-27 11:54 ` [LTP] [PATCH 2/3] swapon04: Add test for discard flags Andrea Cervesato
  2026-08-27 11:54 ` [LTP] [PATCH 3/3] swapon02: Add test cases for invalid swapflags Andrea Cervesato
  2 siblings, 2 replies; 17+ messages in thread
From: Andrea Cervesato @ 2026-08-27 11:54 UTC (permalink / raw)
  To: Linux Test Project

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

Introduce fallback definition inside lapi for:

- SWAP_FLAG_PREFER
- SWAP_FLAG_PRIO_MASK
- SWAP_FLAG_DISCARD
- SWAP_FLAG_DISCARD_ONCE
- SWAP_FLAG_DISCARD_PAGES

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 include/tse_swap.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/tse_swap.h b/include/tse_swap.h
index c4979b3e5..25fe4ad77 100644
--- a/include/tse_swap.h
+++ b/include/tse_swap.h
@@ -14,6 +14,22 @@
 #ifndef TSE_SWAP_H__
 #define TSE_SWAP_H__
 
+#ifndef SWAP_FLAG_PREFER
+# define SWAP_FLAG_PREFER	0x8000
+#endif
+#ifndef SWAP_FLAG_PRIO_MASK
+# define SWAP_FLAG_PRIO_MASK	0x7fff
+#endif
+#ifndef SWAP_FLAG_DISCARD
+# define SWAP_FLAG_DISCARD	0x10000
+#endif
+#ifndef SWAP_FLAG_DISCARD_ONCE
+# define SWAP_FLAG_DISCARD_ONCE	0x20000
+#endif
+#ifndef SWAP_FLAG_DISCARD_PAGES
+# define SWAP_FLAG_DISCARD_PAGES 0x40000
+#endif
+
 enum swapfile_method {
     SWAPFILE_BY_SIZE,
     SWAPFILE_BY_BLKS

-- 
2.51.0


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

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

* [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-27 11:54 [LTP] [PATCH 0/3] Increase coverage for swapon syscall Andrea Cervesato
  2026-08-27 11:54 ` [LTP] [PATCH 1/3] lapi: fallback definitions " Andrea Cervesato
@ 2026-08-27 11:54 ` Andrea Cervesato
  2026-08-28  3:57   ` Li Wang
  2026-08-27 11:54 ` [LTP] [PATCH 3/3] swapon02: Add test cases for invalid swapflags Andrea Cervesato
  2 siblings, 1 reply; 17+ messages in thread
From: Andrea Cervesato @ 2026-08-27 11:54 UTC (permalink / raw)
  To: Linux Test Project

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

Verify that swapon(2) discard flags (SWAP_FLAG_DISCARD,
SWAP_FLAG_DISCARD_ONCE, SWAP_FLAG_DISCARD_PAGES) correctly control
swapon-time area discard on block devices supporting discard operations.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/swapon/.gitignore |   1 +
 testcases/kernel/syscalls/swapon/swapon04.c | 197 ++++++++++++++++++++++++++++
 3 files changed, 199 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 737c63e31..ca190dd97 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1676,6 +1676,7 @@ swapoff02 swapoff02
 swapon01 swapon01
 swapon02 swapon02
 swapon03 swapon03
+swapon04 swapon04
 
 #Exclusive syscall() for POWER6 machines only
 switch01 endian_switch01
diff --git a/testcases/kernel/syscalls/swapon/.gitignore b/testcases/kernel/syscalls/swapon/.gitignore
index 729226b11..db03b81ea 100644
--- a/testcases/kernel/syscalls/swapon/.gitignore
+++ b/testcases/kernel/syscalls/swapon/.gitignore
@@ -1,3 +1,4 @@
 /swapon01
 /swapon02
 /swapon03
+/swapon04
diff --git a/testcases/kernel/syscalls/swapon/swapon04.c b/testcases/kernel/syscalls/swapon/swapon04.c
new file mode 100644
index 000000000..cf527586b
--- /dev/null
+++ b/testcases/kernel/syscalls/swapon/swapon04.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2026
+ */
+
+/*\
+ * Check that :manpage:`swapon(2)` discard flags control swapon-time area discard:
+ *
+ * - With 0 (no flags), the swap area is not discarded at swapon.
+ * - With SWAP_FLAG_DISCARD, the swap area is discarded at swapon.
+ * - With SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE, the swap area is discarded at swapon.
+ * - With SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_PAGES, swapon-time area discard
+ *   is disabled (page-cluster discard only).
+ * - With SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | SWAP_FLAG_DISCARD_PAGES,
+ *   SWAP_FLAG_DISCARD_ONCE takes precedence and discards the swap area at swapon.
+ * - With SWAP_FLAG_DISCARD_ONCE or SWAP_FLAG_DISCARD_PAGES alone (without the
+ *   SWAP_FLAG_DISCARD master enable bit), discard is not enabled.
+ *
+ * [Algorithm]
+ *
+ * - Create a backing file on the test filesystem and fill it completely.
+ * - Attach the backing file to a loop device supporting discard.
+ * - For each test case, populate the backing file and format it with mkswap.
+ * - Record the allocated block count before swapon().
+ * - Call swapon() with the test case flags.
+ * - Verify whether the allocated block count dropped (discarded) or remained.
+ * - Call swapoff() to reset the swap device state.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "tst_test.h"
+#include "tse_swap.h"
+#include "lapi/syscalls.h"
+#include "lapi/fallocate.h"
+
+#define MNTPOINT "mntpoint"
+#define BACKING_FILE MNTPOINT "/swap_backing_file"
+#define SWAP_SIZE_MB 16
+
+static char loop_dev[PATH_MAX];
+static int loop_dev_id = -1;
+static int loop_attached;
+static int swap_active;
+static size_t max_header_blocks;
+
+static struct tcase {
+	int flags;
+	int exp_discard;
+	const char *desc;
+} tcases[] = {
+	{
+		.desc = "0 (no flags)",
+	},
+	{
+		.flags = SWAP_FLAG_DISCARD,
+		.exp_discard = 1,
+		.desc = "SWAP_FLAG_DISCARD",
+	},
+	{
+		.flags = SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE,
+		.exp_discard = 1,
+		.desc = "SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE",
+	},
+	{
+		.flags = SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_PAGES,
+		.desc = "SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_PAGES",
+	},
+	{
+		.flags = SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | SWAP_FLAG_DISCARD_PAGES,
+		.exp_discard = 1,
+		.desc = "SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | SWAP_FLAG_DISCARD_PAGES",
+	},
+	{
+		.flags = SWAP_FLAG_DISCARD_ONCE,
+		.desc = "SWAP_FLAG_DISCARD_ONCE (alone without master flag)",
+	},
+	{
+		.flags = SWAP_FLAG_DISCARD_PAGES,
+		.desc = "SWAP_FLAG_DISCARD_PAGES (alone without master flag)",
+	},
+};
+
+static void setup(void)
+{
+	char discard_path[PATH_MAX];
+	unsigned long discard_max_bytes = 0;
+	size_t page_size, blk_size, alloc_units;
+	struct stat st;
+	int fd;
+
+	if (access("/proc/swaps", F_OK))
+		tst_brk(TCONF, "swap is not supported by kernel");
+
+	fd = SAFE_OPEN(BACKING_FILE, O_RDWR | O_CREAT | O_TRUNC, 0600);
+	TEST(fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 4096));
+
+	if (TST_RET != 0) {
+		SAFE_CLOSE(fd);
+
+		if (TST_ERR == EOPNOTSUPP || TST_ERR == ENOSYS) {
+			tst_brk(TCONF, "Filesystem %s does not support FALLOC_FL_PUNCH_HOLE",
+				tst_device->fs_type);
+		}
+
+		tst_brk(TBROK | TERRNO, "fallocate() error");
+	}
+
+	SAFE_FTRUNCATE(fd, SWAP_SIZE_MB * TST_MB);
+	SAFE_CLOSE(fd);
+
+	loop_dev_id = tst_find_free_loopdev(loop_dev, sizeof(loop_dev));
+	if (loop_dev_id < 0)
+		tst_brk(TBROK, "No free loop device found");
+
+	if (tst_attach_device(loop_dev, BACKING_FILE))
+		tst_brk(TBROK, "Failed to attach %s to %s", loop_dev, BACKING_FILE);
+	loop_attached = 1;
+
+	snprintf(discard_path, sizeof(discard_path),
+		 "/sys/block/loop%d/queue/discard_max_bytes", loop_dev_id);
+	if (FILE_SCANF(discard_path, "%lu", &discard_max_bytes) != 0 || discard_max_bytes == 0) {
+		tst_brk(TCONF, "Loop device %s does not support discard on %s",
+			loop_dev, tst_device->fs_type);
+	}
+
+	SAFE_STAT(BACKING_FILE, &st);
+
+	page_size = getpagesize();
+	blk_size = st.st_blksize;
+	alloc_units = page_size > blk_size ? page_size : blk_size;
+
+	/* Minimum 512-byte blocks for 1 page + small tolerance for filesystem metadata */
+	max_header_blocks = (alloc_units / 512) * 2;
+}
+
+static void verify_swapon(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	struct stat st;
+	blkcnt_t blocks_before, blocks_after;
+	const char *const mkswap_argv[] = {"mkswap", loop_dev, NULL};
+
+	tst_fill_file(BACKING_FILE, 'A', TST_MB, SWAP_SIZE_MB);
+
+	tst_cmd(mkswap_argv, "/dev/null", "/dev/null", TST_CMD_TCONF_ON_MISSING);
+
+	SAFE_STAT(BACKING_FILE, &st);
+	blocks_before = st.st_blocks;
+
+	if (!blocks_before)
+		tst_brk(TBROK, "Backing file has 0 allocated blocks");
+
+	TEST(tst_syscall(__NR_swapon, loop_dev, tc->flags));
+	if (TST_RET != 0) {
+		tst_res(TFAIL | TTERRNO, "swapon(%s, %s)", loop_dev, tc->desc);
+		return;
+	}
+	swap_active = 1;
+
+	SAFE_STAT(BACKING_FILE, &st);
+	blocks_after = st.st_blocks;
+
+	if (tc->exp_discard)
+		TST_EXP_LE_LU(blocks_after, max_header_blocks);
+	else
+		TST_EXP_EQ_LI(blocks_after, blocks_before);
+
+	if (tst_syscall(__NR_swapoff, loop_dev) != 0)
+		tst_brk(TBROK | TTERRNO, "swapoff(%s) failed", loop_dev);
+	swap_active = 0;
+}
+
+static void cleanup(void)
+{
+	if (swap_active && tst_syscall(__NR_swapoff, loop_dev) != 0)
+		tst_res(TWARN | TTERRNO, "swapoff(%s) failed", loop_dev);
+	swap_active = 0;
+
+	if (loop_attached)
+		tst_detach_device(loop_dev);
+	loop_attached = 0;
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_swapon,
+	.tcnt = ARRAY_SIZE(tcases),
+};

-- 
2.51.0


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

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

* [LTP] [PATCH 3/3] swapon02: Add test cases for invalid swapflags
  2026-08-27 11:54 [LTP] [PATCH 0/3] Increase coverage for swapon syscall Andrea Cervesato
  2026-08-27 11:54 ` [LTP] [PATCH 1/3] lapi: fallback definitions " Andrea Cervesato
  2026-08-27 11:54 ` [LTP] [PATCH 2/3] swapon04: Add test for discard flags Andrea Cervesato
@ 2026-08-27 11:54 ` Andrea Cervesato
  2026-08-28  7:59   ` Li Wang
  2 siblings, 1 reply; 17+ messages in thread
From: Andrea Cervesato @ 2026-08-27 11:54 UTC (permalink / raw)
  To: Linux Test Project

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

Add test cases verifying that swapon(2) returns EINVAL when swapflags
contains undefined or invalid flag bits.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/syscalls/swapon/swapon02.c | 58 +++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 16 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index d3e528c94..9d30f8527 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -5,10 +5,11 @@
  */
 
 /*\
- * This test case checks whether swapon(2) system call returns:
+ * This test case checks whether :manpage:`swapon(2)` system call returns:
  *
  * - ENOENT when the path does not exist
  * - EINVAL when the path exists but is invalid
+ * - EINVAL when swapflags contains invalid or undefined flag bits
  * - EPERM when user is not a superuser
  * - EBUSY when the specified path is already being used as a swap area
  */
@@ -20,10 +21,10 @@
 #include "tse_swap.h"
 
 #define MNTPOINT	"mntpoint"
-#define TEST_FILE	MNTPOINT"/testswap"
-#define NOTSWAP_FILE	MNTPOINT"/notswap"
-#define SWAP_FILE	MNTPOINT"/swapfile"
-#define USED_FILE	MNTPOINT"/alreadyused"
+#define TEST_FILE	MNTPOINT "/testswap"
+#define NOTSWAP_FILE	MNTPOINT "/notswap"
+#define SWAP_FILE	MNTPOINT "/swapfile"
+#define USED_FILE	MNTPOINT "/alreadyused"
 
 static uid_t nobody_uid;
 static int do_swapoff;
@@ -32,11 +33,40 @@ static struct tcase {
 	char *err_desc;
 	int exp_errno;
 	char *path;
+	int flags;
 } tcases[] = {
-	{"Path does not exist", ENOENT, "./doesnotexist"},
-	{"Invalid path", EINVAL, NOTSWAP_FILE},
-	{"Permission denied", EPERM, SWAP_FILE},
-	{"File already used", EBUSY, USED_FILE},
+	{
+		.err_desc = "Path does not exist",
+		.exp_errno = ENOENT,
+		.path = "./doesnotexist",
+	},
+	{
+		.err_desc = "Invalid path",
+		.exp_errno = EINVAL,
+		.path = NOTSWAP_FILE,
+	},
+	{
+		.err_desc = "Permission denied",
+		.exp_errno = EPERM,
+		.path = SWAP_FILE,
+	},
+	{
+		.err_desc = "File already used",
+		.exp_errno = EBUSY,
+		.path = USED_FILE,
+	},
+	{
+		.err_desc = "Invalid swapflags (undefined flag bits)",
+		.exp_errno = EINVAL,
+		.path = SWAP_FILE,
+		.flags = 0x80000,
+	},
+	{
+		.err_desc = "Invalid swapflags (high bits set)",
+		.exp_errno = EINVAL,
+		.path = SWAP_FILE,
+		.flags = ~0,
+	},
 };
 
 static void setup(void)
@@ -66,20 +96,16 @@ static void cleanup(void)
 
 static void verify_swapon(unsigned int i)
 {
-	struct tcase *tc = tcases + i;
+	struct tcase *tc = &tcases[i];
+
 	if (tc->exp_errno == EPERM)
 		SAFE_SETEUID(nobody_uid);
 
-	TST_EXP_FAIL(tst_syscall(__NR_swapon, tc->path, 0), tc->exp_errno,
+	TST_EXP_FAIL(tst_syscall(__NR_swapon, tc->path, tc->flags), tc->exp_errno,
 		     "swapon(2) fail with %s", tc->err_desc);
 
 	if (tc->exp_errno == EPERM)
 		SAFE_SETEUID(0);
-
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "swapon(2) failed unexpectedly, expected: %s",
-			tst_strerrno(tc->exp_errno));
-	}
 }
 
 static struct tst_test test = {

-- 
2.51.0


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

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

* Re: [LTP] lapi: fallback definitions for swapon syscall
  2026-08-27 11:54 ` [LTP] [PATCH 1/3] lapi: fallback definitions " Andrea Cervesato
@ 2026-08-27 13:58   ` linuxtestproject.agent
  2026-08-28  7:54   ` [LTP] [PATCH 1/3] " Li Wang
  1 sibling, 0 replies; 17+ messages in thread
From: linuxtestproject.agent @ 2026-08-27 13:58 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi Andrea,

On Aug 27, 2026, Andrea Cervesato wrote:
> lapi: fallback definitions for swapon syscall

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-27 11:54 ` [LTP] [PATCH 2/3] swapon04: Add test for discard flags Andrea Cervesato
@ 2026-08-28  3:57   ` Li Wang
  2026-08-28  8:30     ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 17+ messages in thread
From: Li Wang @ 2026-08-28  3:57 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Linux Test Project

On Thu, Aug 27, 2026 at 01:54:05PM +0200, Andrea Cervesato wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
> 
> Verify that swapon(2) discard flags (SWAP_FLAG_DISCARD,
> SWAP_FLAG_DISCARD_ONCE, SWAP_FLAG_DISCARD_PAGES) correctly control
> swapon-time area discard on block devices supporting discard operations.
> 
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  runtest/syscalls                            |   1 +
>  testcases/kernel/syscalls/swapon/.gitignore |   1 +
>  testcases/kernel/syscalls/swapon/swapon04.c | 197 ++++++++++++++++++++++++++++
>  3 files changed, 199 insertions(+)
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 737c63e31..ca190dd97 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1676,6 +1676,7 @@ swapoff02 swapoff02
>  swapon01 swapon01
>  swapon02 swapon02
>  swapon03 swapon03
> +swapon04 swapon04
>  
>  #Exclusive syscall() for POWER6 machines only
>  switch01 endian_switch01
> diff --git a/testcases/kernel/syscalls/swapon/.gitignore b/testcases/kernel/syscalls/swapon/.gitignore
> index 729226b11..db03b81ea 100644
> --- a/testcases/kernel/syscalls/swapon/.gitignore
> +++ b/testcases/kernel/syscalls/swapon/.gitignore
> @@ -1,3 +1,4 @@
>  /swapon01
>  /swapon02
>  /swapon03
> +/swapon04
> diff --git a/testcases/kernel/syscalls/swapon/swapon04.c b/testcases/kernel/syscalls/swapon/swapon04.c
> new file mode 100644
> index 000000000..cf527586b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/swapon/swapon04.c
> @@ -0,0 +1,197 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) Linux Test Project, 2026
> + */
> +
> +/*\
> + * Check that :manpage:`swapon(2)` discard flags control swapon-time area discard:
> + *
> + * - With 0 (no flags), the swap area is not discarded at swapon.
> + * - With SWAP_FLAG_DISCARD, the swap area is discarded at swapon.
> + * - With SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE, the swap area is discarded at swapon.
> + * - With SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_PAGES, swapon-time area discard
> + *   is disabled (page-cluster discard only).
> + * - With SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | SWAP_FLAG_DISCARD_PAGES,
> + *   SWAP_FLAG_DISCARD_ONCE takes precedence and discards the swap area at swapon.
> + * - With SWAP_FLAG_DISCARD_ONCE or SWAP_FLAG_DISCARD_PAGES alone (without the
> + *   SWAP_FLAG_DISCARD master enable bit), discard is not enabled.
> + *
> + * [Algorithm]
> + *
> + * - Create a backing file on the test filesystem and fill it completely.
> + * - Attach the backing file to a loop device supporting discard.
> + * - For each test case, populate the backing file and format it with mkswap.
> + * - Record the allocated block count before swapon().
> + * - Call swapon() with the test case flags.
> + * - Verify whether the allocated block count dropped (discarded) or remained.
> + * - Call swapoff() to reset the swap device state.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <sys/stat.h>
> +#include <unistd.h>
> +
> +#include "tst_test.h"
> +#include "tse_swap.h"
> +#include "lapi/syscalls.h"
> +#include "lapi/fallocate.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define BACKING_FILE MNTPOINT "/swap_backing_file"
> +#define SWAP_SIZE_MB 16
> +
> +static char loop_dev[PATH_MAX];
> +static int loop_dev_id = -1;
> +static int loop_attached;
> +static int swap_active;
> +static size_t max_header_blocks;
> +
> +static struct tcase {
> +	int flags;
> +	int exp_discard;
> +	const char *desc;
> +} tcases[] = {
> +	{
> +		.desc = "0 (no flags)",
> +	},
> +	{
> +		.flags = SWAP_FLAG_DISCARD,
> +		.exp_discard = 1,
> +		.desc = "SWAP_FLAG_DISCARD",
> +	},
> +	{
> +		.flags = SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE,
> +		.exp_discard = 1,
> +		.desc = "SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE",
> +	},

I encountered an intermittent failure on my x86_64 platform running kernel 6.6.
This needs further investigation.

tst_test.c:1986: TINFO: === Testing on xfs ===
tst_test.c:1291: TINFO: Formatting /dev/loop0 with xfs opts='' extra opts=''
tst_test.c:1303: TINFO: Mounting /dev/loop0 to /tmp/LTP_swa4Dz6aP/mntpoint fstyp=xfs flags=0
tst_device.c:103: TINFO: Found free device 1 '/dev/loop1'
swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
swapon04.c:168: TPASS: blocks_after <= max_header_blocks (8 <= 16)
swapon04.c:168: TFAIL: blocks_after (32648) > max_header_blocks (16)
swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
swapon04.c:168: TPASS: blocks_after <= max_header_blocks (8 <= 16)
swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
swapon04.c:170: TPASS: blocks_after == blocks_before (32768)

> +	{
> +		.flags = SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_PAGES,
> +		.desc = "SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_PAGES",
> +	},
> +	{
> +		.flags = SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | SWAP_FLAG_DISCARD_PAGES,
> +		.exp_discard = 1,
> +		.desc = "SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | SWAP_FLAG_DISCARD_PAGES",
> +	},
> +	{
> +		.flags = SWAP_FLAG_DISCARD_ONCE,
> +		.desc = "SWAP_FLAG_DISCARD_ONCE (alone without master flag)",
> +	},
> +	{
> +		.flags = SWAP_FLAG_DISCARD_PAGES,
> +		.desc = "SWAP_FLAG_DISCARD_PAGES (alone without master flag)",
> +	},
> +};
> +
> +static void setup(void)
> +{
> +	char discard_path[PATH_MAX];
> +	unsigned long discard_max_bytes = 0;
> +	size_t page_size, blk_size, alloc_units;
> +	struct stat st;
> +	int fd;
> +
> +	if (access("/proc/swaps", F_OK))
> +		tst_brk(TCONF, "swap is not supported by kernel");
> +
> +	fd = SAFE_OPEN(BACKING_FILE, O_RDWR | O_CREAT | O_TRUNC, 0600);
> +	TEST(fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 4096));
> +
> +	if (TST_RET != 0) {
> +		SAFE_CLOSE(fd);
> +
> +		if (TST_ERR == EOPNOTSUPP || TST_ERR == ENOSYS) {
> +			tst_brk(TCONF, "Filesystem %s does not support FALLOC_FL_PUNCH_HOLE",
> +				tst_device->fs_type);
> +		}
> +
> +		tst_brk(TBROK | TERRNO, "fallocate() error");
> +	}
> +
> +	SAFE_FTRUNCATE(fd, SWAP_SIZE_MB * TST_MB);
> +	SAFE_CLOSE(fd);
> +
> +	loop_dev_id = tst_find_free_loopdev(loop_dev, sizeof(loop_dev));
> +	if (loop_dev_id < 0)
> +		tst_brk(TBROK, "No free loop device found");
> +
> +	if (tst_attach_device(loop_dev, BACKING_FILE))
> +		tst_brk(TBROK, "Failed to attach %s to %s", loop_dev, BACKING_FILE);
> +	loop_attached = 1;
> +
> +	snprintf(discard_path, sizeof(discard_path),
> +		 "/sys/block/loop%d/queue/discard_max_bytes", loop_dev_id);
> +	if (FILE_SCANF(discard_path, "%lu", &discard_max_bytes) != 0 || discard_max_bytes == 0) {
> +		tst_brk(TCONF, "Loop device %s does not support discard on %s",
> +			loop_dev, tst_device->fs_type);
> +	}
> +
> +	SAFE_STAT(BACKING_FILE, &st);
> +
> +	page_size = getpagesize();
> +	blk_size = st.st_blksize;
> +	alloc_units = page_size > blk_size ? page_size : blk_size;
> +
> +	/* Minimum 512-byte blocks for 1 page + small tolerance for filesystem metadata */
> +	max_header_blocks = (alloc_units / 512) * 2;
> +}
> +
> +static void verify_swapon(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +	struct stat st;
> +	blkcnt_t blocks_before, blocks_after;
> +	const char *const mkswap_argv[] = {"mkswap", loop_dev, NULL};
> +
> +	tst_fill_file(BACKING_FILE, 'A', TST_MB, SWAP_SIZE_MB);
> +
> +	tst_cmd(mkswap_argv, "/dev/null", "/dev/null", TST_CMD_TCONF_ON_MISSING);
> +
> +	SAFE_STAT(BACKING_FILE, &st);
> +	blocks_before = st.st_blocks;
> +
> +	if (!blocks_before)
> +		tst_brk(TBROK, "Backing file has 0 allocated blocks");
> +
> +	TEST(tst_syscall(__NR_swapon, loop_dev, tc->flags));
> +	if (TST_RET != 0) {
> +		tst_res(TFAIL | TTERRNO, "swapon(%s, %s)", loop_dev, tc->desc);
> +		return;
> +	}
> +	swap_active = 1;
> +
> +	SAFE_STAT(BACKING_FILE, &st);
> +	blocks_after = st.st_blocks;
> +
> +	if (tc->exp_discard)
> +		TST_EXP_LE_LU(blocks_after, max_header_blocks);
> +	else
> +		TST_EXP_EQ_LI(blocks_after, blocks_before);
> +
> +	if (tst_syscall(__NR_swapoff, loop_dev) != 0)
> +		tst_brk(TBROK | TTERRNO, "swapoff(%s) failed", loop_dev);
> +	swap_active = 0;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (swap_active && tst_syscall(__NR_swapoff, loop_dev) != 0)
> +		tst_res(TWARN | TTERRNO, "swapoff(%s) failed", loop_dev);
> +	swap_active = 0;
> +
> +	if (loop_attached)
> +		tst_detach_device(loop_dev);
> +	loop_attached = 0;
> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.mount_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test = verify_swapon,
> +	.tcnt = ARRAY_SIZE(tcases),
> +};
> 
> -- 
> 2.51.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Regards,
Li Wang

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

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

* Re: [LTP] [PATCH 1/3] lapi: fallback definitions for swapon syscall
  2026-08-27 11:54 ` [LTP] [PATCH 1/3] lapi: fallback definitions " Andrea Cervesato
  2026-08-27 13:58   ` [LTP] " linuxtestproject.agent
@ 2026-08-28  7:54   ` Li Wang
  1 sibling, 0 replies; 17+ messages in thread
From: Li Wang @ 2026-08-28  7:54 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Linux Test Project

Reviewed-by: Li Wang <li.wang@linux.dev>

-- 
Regards,
Li Wang

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

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

* Re: [LTP] [PATCH 3/3] swapon02: Add test cases for invalid swapflags
  2026-08-27 11:54 ` [LTP] [PATCH 3/3] swapon02: Add test cases for invalid swapflags Andrea Cervesato
@ 2026-08-28  7:59   ` Li Wang
  0 siblings, 0 replies; 17+ messages in thread
From: Li Wang @ 2026-08-28  7:59 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Linux Test Project

Reviewed-by: Li Wang <li.wang@linux.dev>

-- 
Regards,
Li Wang

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-28  3:57   ` Li Wang
@ 2026-08-28  8:30     ` Andrea Cervesato via ltp
  2026-08-28  8:47       ` Li Wang
  2026-08-28  8:47       ` Andrea Cervesato via ltp
  0 siblings, 2 replies; 17+ messages in thread
From: Andrea Cervesato via ltp @ 2026-08-28  8:30 UTC (permalink / raw)
  To: Li Wang; +Cc: Linux Test Project

Hi Li,

> I encountered an intermittent failure on my x86_64 platform running kernel 6.6.
> This needs further investigation.
> 
> tst_test.c:1986: TINFO: === Testing on xfs ===
> tst_test.c:1291: TINFO: Formatting /dev/loop0 with xfs opts='' extra opts=''
> tst_test.c:1303: TINFO: Mounting /dev/loop0 to /tmp/LTP_swa4Dz6aP/mntpoint fstyp=xfs flags=0
> tst_device.c:103: TINFO: Found free device 1 '/dev/loop1'
> swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
> swapon04.c:168: TPASS: blocks_after <= max_header_blocks (8 <= 16)
> swapon04.c:168: TFAIL: blocks_after (32648) > max_header_blocks (16)
> swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
> swapon04.c:168: TPASS: blocks_after <= max_header_blocks (8 <= 16)
> swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
> swapon04.c:170: TPASS: blocks_after == blocks_before (32768)

this is interesting. Also I notice how it's hard to read the logs, so
I need a TINFO before the checks. But technically, this could be a kernel
bug: can you please add a sync() before stat() while we are getting the
blocks_after? We might need to flush the cache before reading the blocks.

	fd = SAFE_OPEN(BACKING_FILE, O_RDONLY);
	SAFE_FSYNC(fd);
	SAFE_CLOSE(fd);

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-28  8:30     ` Andrea Cervesato via ltp
@ 2026-08-28  8:47       ` Li Wang
  2026-08-28  9:02         ` Andrea Cervesato via ltp
  2026-08-28  8:47       ` Andrea Cervesato via ltp
  1 sibling, 1 reply; 17+ messages in thread
From: Li Wang @ 2026-08-28  8:47 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Linux Test Project

Hi Andrea,

> > I encountered an intermittent failure on my x86_64 platform running kernel 6.6.
> > This needs further investigation.
> > 
> > tst_test.c:1986: TINFO: === Testing on xfs ===
> > tst_test.c:1291: TINFO: Formatting /dev/loop0 with xfs opts='' extra opts=''
> > tst_test.c:1303: TINFO: Mounting /dev/loop0 to /tmp/LTP_swa4Dz6aP/mntpoint fstyp=xfs flags=0
> > tst_device.c:103: TINFO: Found free device 1 '/dev/loop1'
> > swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
> > swapon04.c:168: TPASS: blocks_after <= max_header_blocks (8 <= 16)
> > swapon04.c:168: TFAIL: blocks_after (32648) > max_header_blocks (16)
> > swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
> > swapon04.c:168: TPASS: blocks_after <= max_header_blocks (8 <= 16)
> > swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
> > swapon04.c:170: TPASS: blocks_after == blocks_before (32768)
> 

> this is interesting. Also I notice how it's hard to read the logs, so
> I need a TINFO before the checks. But technically, this could be a kernel
> bug: can you please add a sync() before stat() while we are getting the
> blocks_after? We might need to flush the cache before reading the blocks.
> 
> 	fd = SAFE_OPEN(BACKING_FILE, O_RDONLY);
> 	SAFE_FSYNC(fd);
> 	SAFE_CLOSE(fd);
> 

It doesn't work — even with the fsync() added above, the problem is
still reproducible. I agree it's likely a kernel bug, because I tried
on c10s (6.12) and c9s (5.14) and couldn't reproduce the issue there.

Only on kernel-v6.6-* fail:

# LTP_SINGLE_FS_TYPE=xfs ./swapon04 -i 100

swapon04.c:174: TPASS: blocks_after == blocks_before (32768)
swapon04.c:172: TPASS: blocks_after <= max_header_blocks (8 <= 16)
swapon04.c:174: TPASS: blocks_after == blocks_before (32768)
swapon04.c:174: TPASS: blocks_after == blocks_before (32768)
swapon04.c:174: TFAIL: blocks_after (32768) != blocks_before (65408)
swapon04.c:172: TFAIL: blocks_after (32648) > max_header_blocks (16)
...

swapon04.c:174: TPASS: blocks_after == blocks_before (32768)
swapon04.c:174: TPASS: blocks_after == blocks_before (32768)

Summary:
passed   670
failed   30
broken   0
skipped  0
warnings 0

-- 
Regards,
Li Wang

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-28  8:30     ` Andrea Cervesato via ltp
  2026-08-28  8:47       ` Li Wang
@ 2026-08-28  8:47       ` Andrea Cervesato via ltp
  2026-08-28  9:01         ` Li Wang
  1 sibling, 1 reply; 17+ messages in thread
From: Andrea Cervesato via ltp @ 2026-08-28  8:47 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Linux Test Project

> this is interesting. Also I notice how it's hard to read the logs, so
> I need a TINFO before the checks. But technically, this could be a kernel
> bug: can you please add a sync() before stat() while we are getting the
> blocks_after? We might need to flush the cache before reading the blocks.
> 
> 	fd = SAFE_OPEN(BACKING_FILE, O_RDONLY);
> 	SAFE_FSYNC(fd);
> 	SAFE_CLOSE(fd);

sorry, this should stay after the tst_fill_file()

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-28  8:47       ` Andrea Cervesato via ltp
@ 2026-08-28  9:01         ` Li Wang
  2026-08-28  9:02           ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 17+ messages in thread
From: Li Wang @ 2026-08-28  9:01 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Linux Test Project

> > this is interesting. Also I notice how it's hard to read the logs, so
> > I need a TINFO before the checks. But technically, this could be a kernel
> > bug: can you please add a sync() before stat() while we are getting the
> > blocks_after? We might need to flush the cache before reading the blocks.
> > 
> > 	fd = SAFE_OPEN(BACKING_FILE, O_RDONLY);
> > 	SAFE_FSYNC(fd);
> > 	SAFE_CLOSE(fd);
> 
> sorry, this should stay after the tst_fill_file()

Great, this works!

I think the fsync after tst_fill_file() ensures all allocated blocks are
flushed to disk, so stat() reflects the real block count.

Feel free to add my RBT with this change applied:

Reviewed-by: Li Wang <li.wang@linux.dev>

-- 
Regards,
Li Wang

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-28  8:47       ` Li Wang
@ 2026-08-28  9:02         ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 17+ messages in thread
From: Andrea Cervesato via ltp @ 2026-08-28  9:02 UTC (permalink / raw)
  To: Li Wang; +Cc: Linux Test Project

> > this is interesting. Also I notice how it's hard to read the logs, so
> > I need a TINFO before the checks. But technically, this could be a kernel
> > bug: can you please add a sync() before stat() while we are getting the
> > blocks_after? We might need to flush the cache before reading the blocks.
> > 
> > 	fd = SAFE_OPEN(BACKING_FILE, O_RDONLY);
> > 	SAFE_FSYNC(fd);
> > 	SAFE_CLOSE(fd);
> > 
> 
> It doesn't work — even with the fsync() added above, the problem is
> still reproducible. I agree it's likely a kernel bug, because I tried
> on c10s (6.12) and c9s (5.14) and couldn't reproduce the issue there.
> 
> Only on kernel-v6.6-* fail:
> 
> # LTP_SINGLE_FS_TYPE=xfs ./swapon04 -i 100
> 
> swapon04.c:174: TPASS: blocks_after == blocks_before (32768)
> swapon04.c:172: TPASS: blocks_after <= max_header_blocks (8 <= 16)
> swapon04.c:174: TPASS: blocks_after == blocks_before (32768)
> swapon04.c:174: TPASS: blocks_after == blocks_before (32768)
> swapon04.c:174: TFAIL: blocks_after (32768) != blocks_before (65408)
> swapon04.c:172: TFAIL: blocks_after (32648) > max_header_blocks (16)

did you move fsync() after filling the file and it's still failing?
then most likely it's a kernel bug.

I will send a new version with the fsync() as well, and a TINFO
message to show what test case we are running in.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-28  9:01         ` Li Wang
@ 2026-08-28  9:02           ` Andrea Cervesato via ltp
  2026-08-28  9:12             ` Li Wang
  0 siblings, 1 reply; 17+ messages in thread
From: Andrea Cervesato via ltp @ 2026-08-28  9:02 UTC (permalink / raw)
  To: Li Wang; +Cc: Linux Test Project

> Great, this works!
> 
> I think the fsync after tst_fill_file() ensures all allocated blocks are
> flushed to disk, so stat() reflects the real block count.
> 
> Feel free to add my RBT with this change applied:
> 
> Reviewed-by: Li Wang <li.wang@linux.dev>

there we are :-) will send a new version with the R-B tags

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

* Re: [LTP] [PATCH 2/3] swapon04: Add test for discard flags
  2026-08-28  9:02           ` Andrea Cervesato via ltp
@ 2026-08-28  9:12             ` Li Wang
  0 siblings, 0 replies; 17+ messages in thread
From: Li Wang @ 2026-08-28  9:12 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Linux Test Project

On Fri, Aug 28, 2026 at 09:02:43AM +0000, Andrea Cervesato wrote:
> > Great, this works!
> > 
> > I think the fsync after tst_fill_file() ensures all allocated blocks are
> > flushed to disk, so stat() reflects the real block count.
> > 
> > Feel free to add my RBT with this change applied:
> > 
> > Reviewed-by: Li Wang <li.wang@linux.dev>
> 
> there we are :-) will send a new version with the R-B tags

Hmm, I thought about it again. Perhaps we don't need this change.

Comparing the results on 6.12 and 5.14 kernels, only 6.6 needs the sync().

If the swap file contains delalloc blocks, the kernel should flush
them to disk first, then perform the discard.

If the kernel instead discards "nonexistent blocks" directly — making
the discard ineffective — that could be considered a minor bug, though
the impact is limited.

-- 
Regards,
Li Wang

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

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

* Re: [LTP] lapi: fallback definitions for swapon syscall
  2026-08-28  9:05 [LTP] [PATCH v2 1/3] lapi: fallback definitions for swapon syscall Andrea Cervesato
@ 2026-08-28  9:46 ` linuxtestproject.agent
  2026-08-28 11:07   ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 17+ messages in thread
From: linuxtestproject.agent @ 2026-08-28  9:46 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp

Hi Andrea,

On Aug 28, 2026, Andrea Cervesato wrote:
> lapi: fallback definitions for swapon syscall

--- [PATCH 1/3] ---

> lapi: fallback definitions for swapon syscall
>
> Introduce fallback definition inside lapi for:

Could the subject and body name include/tse_swap.h rather than lapi? The
fallback definitions are not added under include/lapi/, so the current
component and location do not match the patch.

--- [PATCH 3/3] ---

> +	TST_EXP_FAIL(tst_syscall(__NR_swapon, tc->path, tc->flags), tc->exp_errno,
>  		     "swapon(2) fail with %s", tc->err_desc);
>
>  static void cleanup(void)
>  {
>  	if (do_swapoff && tst_syscall(__NR_swapoff, USED_FILE))
>  		tst_res(TWARN | TERRNO, "swapoff(alreadyused) failed");
>  }

Could an unexpected successful swapon() of SWAP_FILE be tracked and undone?
This is the failure mode these new cases are intended to detect, but
TST_EXP_FAIL() only reports TFAIL. The swap area remains active, the next
case gets EBUSY, and cleanup only disables USED_FILE, so the test filesystem
cannot be unmounted.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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

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

* Re: [LTP] lapi: fallback definitions for swapon syscall
  2026-08-28  9:46 ` [LTP] " linuxtestproject.agent
@ 2026-08-28 11:07   ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 17+ messages in thread
From: Andrea Cervesato via ltp @ 2026-08-28 11:07 UTC (permalink / raw)
  To: linuxtestproject.agent; +Cc: ltp

> --- [PATCH 1/3] ---
> 
> > lapi: fallback definitions for swapon syscall
> >
> > Introduce fallback definition inside lapi for:
> 
> Could the subject and body name include/tse_swap.h rather than lapi? The
> fallback definitions are not added under include/lapi/, so the current
> component and location do not match the patch.
> 
> --- [PATCH 3/3] ---
> 
> > +	TST_EXP_FAIL(tst_syscall(__NR_swapon, tc->path, tc->flags), tc->exp_errno,
> >  		     "swapon(2) fail with %s", tc->err_desc);
> >
> >  static void cleanup(void)
> >  {
> >  	if (do_swapoff && tst_syscall(__NR_swapoff, USED_FILE))
> >  		tst_res(TWARN | TERRNO, "swapoff(alreadyused) failed");
> >  }
> 
> Could an unexpected successful swapon() of SWAP_FILE be tracked and undone?
> This is the failure mode these new cases are intended to detect, but
> TST_EXP_FAIL() only reports TFAIL. The swap area remains active, the next
> case gets EBUSY, and cleanup only disables USED_FILE, so the test filesystem
> cannot be unmounted.

These are both correct, I will fix them in the next version.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

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

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

end of thread, other threads:[~2026-08-28 11:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-27 11:54 [LTP] [PATCH 0/3] Increase coverage for swapon syscall Andrea Cervesato
2026-08-27 11:54 ` [LTP] [PATCH 1/3] lapi: fallback definitions " Andrea Cervesato
2026-08-27 13:58   ` [LTP] " linuxtestproject.agent
2026-08-28  7:54   ` [LTP] [PATCH 1/3] " Li Wang
2026-08-27 11:54 ` [LTP] [PATCH 2/3] swapon04: Add test for discard flags Andrea Cervesato
2026-08-28  3:57   ` Li Wang
2026-08-28  8:30     ` Andrea Cervesato via ltp
2026-08-28  8:47       ` Li Wang
2026-08-28  9:02         ` Andrea Cervesato via ltp
2026-08-28  8:47       ` Andrea Cervesato via ltp
2026-08-28  9:01         ` Li Wang
2026-08-28  9:02           ` Andrea Cervesato via ltp
2026-08-28  9:12             ` Li Wang
2026-08-27 11:54 ` [LTP] [PATCH 3/3] swapon02: Add test cases for invalid swapflags Andrea Cervesato
2026-08-28  7:59   ` Li Wang
  -- strict thread matches above, loose matches on Subject: below --
2026-08-28  9:05 [LTP] [PATCH v2 1/3] lapi: fallback definitions for swapon syscall Andrea Cervesato
2026-08-28  9:46 ` [LTP] " linuxtestproject.agent
2026-08-28 11:07   ` Andrea Cervesato via ltp

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.