* [LTP] [PATCH 1/1] swapon01: Test on all filesystems
@ 2024-01-19 14:43 Petr Vorel
2024-01-19 15:06 ` Cyril Hrubis
2024-01-20 4:21 ` Li Wang
0 siblings, 2 replies; 15+ messages in thread
From: Petr Vorel @ 2024-01-19 14:43 UTC (permalink / raw)
To: ltp
Test on all filesystems to increase coverage.
Skip filesystems which does not support swap (currently bcachefs, btrfs
and tmpfs).
Tested on 5.10, 6.6 and 6.7.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi Li, Cyril,
feel free to postpone this after the release.
If we are for adding this, I'll retest on Monday older filesystems.
man swapon(8) mentions:
Btrfs
Swap files on Btrfs are supported since Linux 5.0 on files with nocow
attribute. See the btrfs(5) manual page for more details.
=> Can we pass "nocow" just to btrfs? Or should it be added to single
test, which uses just btrfs with nocow?
NFS
Swap over NFS may not work.
=> I guess this is not important for us, as NFS is not part of
filesystems in .all_filesystems, but maybe we should still add it to the
whitelist?
Kind regards,
Petr
testcases/kernel/syscalls/swapon/swapon01.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index e59fb20a1..ef4ebfdcf 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -8,6 +8,7 @@
* [Description]
*
* Checks that swapon() succeds with swapfile.
+ * Testing on all filesystems which support swap file.
*/
#include <unistd.h>
@@ -17,13 +18,14 @@
#include "lapi/syscalls.h"
#include "libswap.h"
-#define SWAP_FILE "swapfile01"
+#define MNTPOINT "mntpoint"
+#define SWAP_FILE MNTPOINT"/swapfile01"
static void verify_swapon(void)
{
TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
- if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
+ if (tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
tst_brk(TBROK | TERRNO,
"Failed to turn off swapfile, system reboot recommended");
}
@@ -31,13 +33,20 @@ static void verify_swapon(void)
static void setup(void)
{
- is_swap_supported(SWAP_FILE);
make_swapfile(SWAP_FILE, 0);
}
static struct tst_test test = {
- .needs_root = 1,
- .needs_tmpdir = 1,
+ .mntpoint = MNTPOINT,
+ .mount_device = 1,
+ .needs_root = 1, /* for swapon() */
+ .all_filesystems = 1,
.test_all = verify_swapon,
- .setup = setup
+ .setup = setup,
+ .skip_filesystems = (const char *[]) {
+ "bcachefs",
+ "btrfs",
+ "tmpfs",
+ NULL
+ },
};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 1/1] swapon01: Test on all filesystems
2024-01-19 14:43 [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
@ 2024-01-19 15:06 ` Cyril Hrubis
2024-01-22 6:22 ` Petr Vorel
2024-01-20 4:21 ` Li Wang
1 sibling, 1 reply; 15+ messages in thread
From: Cyril Hrubis @ 2024-01-19 15:06 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> testcases/kernel/syscalls/swapon/swapon01.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
> index e59fb20a1..ef4ebfdcf 100644
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -8,6 +8,7 @@
> * [Description]
> *
> * Checks that swapon() succeds with swapfile.
> + * Testing on all filesystems which support swap file.
> */
>
> #include <unistd.h>
> @@ -17,13 +18,14 @@
> #include "lapi/syscalls.h"
> #include "libswap.h"
>
> -#define SWAP_FILE "swapfile01"
> +#define MNTPOINT "mntpoint"
> +#define SWAP_FILE MNTPOINT"/swapfile01"
>
> static void verify_swapon(void)
> {
> TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
>
> - if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> + if (tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
I do not think that this should be removed, if the swapon() call fails
we still do not want TBROK here.
> tst_brk(TBROK | TERRNO,
> "Failed to turn off swapfile, system reboot recommended");
> }
> @@ -31,13 +33,20 @@ static void verify_swapon(void)
>
> static void setup(void)
> {
> - is_swap_supported(SWAP_FILE);
> make_swapfile(SWAP_FILE, 0);
> }
>
> static struct tst_test test = {
> - .needs_root = 1,
> - .needs_tmpdir = 1,
> + .mntpoint = MNTPOINT,
> + .mount_device = 1,
> + .needs_root = 1, /* for swapon() */
Can we please avoid comments like this?
I'ts pretty clear that if you are working with devices and setting up
swapfiles it's priviledged operation...
> + .all_filesystems = 1,
> .test_all = verify_swapon,
> - .setup = setup
> + .setup = setup,
> + .skip_filesystems = (const char *[]) {
> + "bcachefs",
> + "btrfs",
> + "tmpfs",
So the rest of the filesystems work fine? If so this change looks fine
to me.
> + NULL
> + },
> };
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 1/1] swapon01: Test on all filesystems
2024-01-19 14:43 [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
2024-01-19 15:06 ` Cyril Hrubis
@ 2024-01-20 4:21 ` Li Wang
2024-01-20 4:34 ` [LTP] [PATCH 1/2] libswap: add known swap supported fs check Li Wang
2024-01-22 6:26 ` [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
1 sibling, 2 replies; 15+ messages in thread
From: Li Wang @ 2024-01-20 4:21 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi Petr, Cyril,
On Fri, Jan 19, 2024 at 10:43 PM Petr Vorel <pvorel@suse.cz> wrote:
> Test on all filesystems to increase coverage.
> Skip filesystems which does not support swap (currently bcachefs, btrfs
> and tmpfs).
>
> Tested on 5.10, 6.6 and 6.7.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Hi Li, Cyril,
>
> feel free to postpone this after the release.
> If we are for adding this, I'll retest on Monday older filesystems.
>
> man swapon(8) mentions:
>
> Btrfs
> Swap files on Btrfs are supported since Linux 5.0 on files with
> nocow
> attribute. See the btrfs(5) manual page for more details.
>
> => Can we pass "nocow" just to btrfs? Or should it be added to single
> test, which uses just btrfs with nocow?
>
> NFS
> Swap over NFS may not work.
>
> => I guess this is not important for us, as NFS is not part of
> filesystems in .all_filesystems, but maybe we should still add it to the
> whitelist?
>
> Kind regards,
> Petr
>
> testcases/kernel/syscalls/swapon/swapon01.c | 21 +++++++++++++++------
> 1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> b/testcases/kernel/syscalls/swapon/swapon01.c
> index e59fb20a1..ef4ebfdcf 100644
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -8,6 +8,7 @@
> * [Description]
> *
> * Checks that swapon() succeds with swapfile.
> + * Testing on all filesystems which support swap file.
> */
>
> #include <unistd.h>
> @@ -17,13 +18,14 @@
> #include "lapi/syscalls.h"
> #include "libswap.h"
>
> -#define SWAP_FILE "swapfile01"
> +#define MNTPOINT "mntpoint"
> +#define SWAP_FILE MNTPOINT"/swapfile01"
>
> static void verify_swapon(void)
> {
> TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
>
> - if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> + if (tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> tst_brk(TBROK | TERRNO,
> "Failed to turn off swapfile, system
> reboot recommended");
> }
> @@ -31,13 +33,20 @@ static void verify_swapon(void)
>
> static void setup(void)
> {
> - is_swap_supported(SWAP_FILE);
> make_swapfile(SWAP_FILE, 0);
> }
>
> static struct tst_test test = {
> - .needs_root = 1,
> - .needs_tmpdir = 1,
> + .mntpoint = MNTPOINT,
> + .mount_device = 1,
> + .needs_root = 1, /* for swapon() */
> + .all_filesystems = 1,
> .test_all = verify_swapon,
> - .setup = setup
> + .setup = setup,
> + .skip_filesystems = (const char *[]) {
> + "bcachefs",
> + "btrfs",
> + "tmpfs",
> + NULL
> + },
>
IMHO, I hate to add the skip_filesystem in this test, because if we do,
then we have to add to all of the related swap tests that, it add more
tedious work to people.
So, if we decide to postpone this patch to release, we can just refactor
the is_swap_supported() function to make things easier. I will send an RFC
patch to show something in my mind, what we need to do later is just
to finalize the swap_supported_fs[] struct list.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH 1/2] libswap: add known swap supported fs check
2024-01-20 4:21 ` Li Wang
@ 2024-01-20 4:34 ` Li Wang
2024-01-20 4:34 ` [LTP] [PATCH 2/2] swapon01: Test on all filesystems Li Wang
2024-01-22 6:26 ` [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
1 sibling, 1 reply; 15+ messages in thread
From: Li Wang @ 2024-01-20 4:34 UTC (permalink / raw)
To: ltp
This introduce an enhancement to the library's is_swap_supported
function to check for filesystem compatibility before attempting
to create and enable a swap file. A list of supported filesystems
is added (ext2, ext3, ext4, xfs, vfat, exfat, ntfs), and a check
against this list is performed to ensure that the swap operations
are only attempted on known compatible filesystems.
If the make_swapfile function fails, the error handling is now
more descriptive: it distinguishes between failures due to the
filesystem not supporting swap files and other types of failures.
Similarly, when attempting to enable the swap file with swapon,
the patch ensures that clearer error messages are provided in
cases where the operation is not supported by the filesystem.
Signed-off-by: Li Wang <liwang@redhat.com>
---
libs/libltpswap/libswap.c | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index d014325e5..5f9622aca 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -12,6 +12,17 @@
#include "libswap.h"
#include "lapi/syscalls.h"
+static const char *const swap_supported_fs[] = {
+ "ext2",
+ "ext3",
+ "ext4",
+ "xfs",
+ "vfat",
+ "exfat",
+ "ntfs",
+ NULL
+};
+
/*
* Make a swap file
*/
@@ -39,23 +50,31 @@ int make_swapfile(const char *swapfile, int safe)
*/
void is_swap_supported(const char *filename)
{
+ int i, sw_support = 0;
int fibmap = tst_fibmap(filename);
long fs_type = tst_fs_type(filename);
const char *fstype = tst_fs_type_name(fs_type);
- int ret = make_swapfile(filename, 1);
- if (ret != 0) {
- if (fibmap == 1)
- tst_brk(TCONF, "mkswap on %s not supported", fstype);
- else
- tst_brk(TFAIL, "mkswap on %s failed", fstype);
+ for (i = 0; swap_supported_fs[i]; i++) {
+ if (!strcmp(fstype, swap_supported_fs[i])) {
+ sw_support = 1;
+ break;
+ }
}
+ int ret = make_swapfile(filename, 1);
+ if (ret != 0) {
+ if (fibmap == 1 && sw_support == 0)
+ tst_brk(TCONF, "mkswap on %s not supported", fstype);
+ else
+ tst_brk(TFAIL, "mkswap on %s failed", fstype);
+ }
+
TEST(tst_syscall(__NR_swapon, filename, 0));
if (TST_RET == -1) {
if (errno == EPERM)
tst_brk(TCONF, "Permission denied for swapon()");
- else if (fibmap == 1 && errno == EINVAL)
+ else if (fibmap == 1 && errno == EINVAL && sw_support == 0)
tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
else
tst_brk(TFAIL | TTERRNO, "swapon() on %s failed", fstype);
--
2.40.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH 2/2] swapon01: Test on all filesystems
2024-01-20 4:34 ` [LTP] [PATCH 1/2] libswap: add known swap supported fs check Li Wang
@ 2024-01-20 4:34 ` Li Wang
2024-01-20 6:40 ` [LTP] [PATCH] swapon01: Improving test with memory limits and swap reporting Li Wang
2024-01-20 8:27 ` [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files Li Wang
0 siblings, 2 replies; 15+ messages in thread
From: Li Wang @ 2024-01-20 4:34 UTC (permalink / raw)
To: ltp
From: Petr Vorel <pvorel@suse.cz>
Test on all filesystems to increase coverage.
Skip filesystems which does not support swap (currently bcachefs, btrfs
and tmpfs).
Tested on 5.10, 6.6 and 6.7.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Li Wang <liwang@redhat.com>
---
testcases/kernel/syscalls/swapon/swapon01.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index e59fb20a1..e1fe50459 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -8,6 +8,7 @@
* [Description]
*
* Checks that swapon() succeds with swapfile.
+ * Testing on all filesystems which support swap file.
*/
#include <unistd.h>
@@ -17,7 +18,8 @@
#include "lapi/syscalls.h"
#include "libswap.h"
-#define SWAP_FILE "swapfile01"
+#define MNTPOINT "mntpoint"
+#define SWAP_FILE MNTPOINT"/swapfile01"
static void verify_swapon(void)
{
@@ -36,8 +38,10 @@ static void setup(void)
}
static struct tst_test test = {
+ .mntpoint = MNTPOINT,
+ .mount_device = 1,
.needs_root = 1,
- .needs_tmpdir = 1,
+ .all_filesystems = 1,
.test_all = verify_swapon,
.setup = setup
};
--
2.40.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH] swapon01: Improving test with memory limits and swap reporting
2024-01-20 4:34 ` [LTP] [PATCH 2/2] swapon01: Test on all filesystems Li Wang
@ 2024-01-20 6:40 ` Li Wang
2024-01-20 6:52 ` Li Wang
2024-01-20 8:27 ` [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files Li Wang
1 sibling, 1 reply; 15+ messages in thread
From: Li Wang @ 2024-01-20 6:40 UTC (permalink / raw)
To: ltp
This is target to create a more robust and controlled environment to test
the swapon system call. By introducing memory limits through cgroups and
filling memory with a known pattern, the test can better assess swapon
behavior when the system experiences memory pressure.
Additionally, the reporting of "SwapCached" memory before turning off the
swap file provides a clearer understanding of the swap system's state in
response to the test conditions.
Signed-off-by: Li Wang <liwang@redhat.com>
---
testcases/kernel/syscalls/swapon/swapon01.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index e1fe50459..faf4a8002 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -20,6 +20,7 @@
#define MNTPOINT "mntpoint"
#define SWAP_FILE MNTPOINT"/swapfile01"
+#define TESTMEM (1UL<<30)
static void verify_swapon(void)
{
@@ -29,12 +30,19 @@ static void verify_swapon(void)
tst_brk(TBROK | TERRNO,
"Failed to turn off swapfile, system reboot recommended");
}
+
+ tst_res(TINFO, "SwapCached: %ld Kb", SAFE_READ_MEMINFO("SwapCached:"));
}
static void setup(void)
{
is_swap_supported(SWAP_FILE);
make_swapfile(SWAP_FILE, 0);
+
+ SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+ SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
+
+ tst_pollute_memory(TESTMEM, 0x41);
}
static struct tst_test test = {
@@ -42,6 +50,7 @@ static struct tst_test test = {
.mount_device = 1,
.needs_root = 1,
.all_filesystems = 1,
+ .needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
.test_all = verify_swapon,
.setup = setup
};
--
2.40.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH] swapon01: Improving test with memory limits and swap reporting
2024-01-20 6:40 ` [LTP] [PATCH] swapon01: Improving test with memory limits and swap reporting Li Wang
@ 2024-01-20 6:52 ` Li Wang
0 siblings, 0 replies; 15+ messages in thread
From: Li Wang @ 2024-01-20 6:52 UTC (permalink / raw)
To: ltp
On Sat, Jan 20, 2024 at 2:40 PM Li Wang <liwang@redhat.com> wrote:
> This is target to create a more robust and controlled environment to test
> the swapon system call. By introducing memory limits through cgroups and
> filling memory with a known pattern, the test can better assess swapon
> behavior when the system experiences memory pressure.
>
> Additionally, the reporting of "SwapCached" memory before turning off the
> swap file provides a clearer understanding of the swap system's state in
> response to the test conditions.
>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
> testcases/kernel/syscalls/swapon/swapon01.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> b/testcases/kernel/syscalls/swapon/swapon01.c
> index e1fe50459..faf4a8002 100644
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -20,6 +20,7 @@
>
> #define MNTPOINT "mntpoint"
> #define SWAP_FILE MNTPOINT"/swapfile01"
> +#define TESTMEM (1UL<<30)
>
> static void verify_swapon(void)
> {
> @@ -29,12 +30,19 @@ static void verify_swapon(void)
> tst_brk(TBROK | TERRNO,
> "Failed to turn off swapfile, system
> reboot recommended");
> }
> +
> + tst_res(TINFO, "SwapCached: %ld Kb",
> SAFE_READ_MEMINFO("SwapCached:"));
> }
>
> static void setup(void)
> {
> is_swap_supported(SWAP_FILE);
> make_swapfile(SWAP_FILE, 0);
> +
> + SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
> + SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
> +
> + tst_pollute_memory(TESTMEM, 0x41);
>
Oops, this pollute memory should move to the behind of swapon,
I forget to submit the last changes when formatting the patch.
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -26,12 +26,13 @@ static void verify_swapon(void)
{
TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
+ tst_pollute_memory(TESTMEM, 0x41);
+ tst_res(TINFO, "SwapCached: %ld Kb",
SAFE_READ_MEMINFO("SwapCached:"));
+
if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
tst_brk(TBROK | TERRNO,
"Failed to turn off swapfile, system reboot
recommended");
}
-
- tst_res(TINFO, "SwapCached: %ld Kb",
SAFE_READ_MEMINFO("SwapCached:"));
}
static void setup(void)
@@ -41,8 +42,6 @@ static void setup(void)
SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
-
- tst_pollute_memory(TESTMEM, 0x41);
}
static struct tst_test test = {
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files
2024-01-20 4:34 ` [LTP] [PATCH 2/2] swapon01: Test on all filesystems Li Wang
2024-01-20 6:40 ` [LTP] [PATCH] swapon01: Improving test with memory limits and swap reporting Li Wang
@ 2024-01-20 8:27 ` Li Wang
2024-01-22 7:13 ` Petr Vorel
1 sibling, 1 reply; 15+ messages in thread
From: Li Wang @ 2024-01-20 8:27 UTC (permalink / raw)
To: ltp
The patch aims to ensure swap files on Btrfs filesystems are created
with the appropriate FS_NOCOW_FL attribute, which is necessary to
disable CoW (Copy-on-Write) for swap files, perthe btrfs(5) manual page.
This change is gated behind a kernel version check to ensure compatibility
with the system's capabilities.
Signed-off-by: Li Wang <liwang@redhat.com>
---
Notes:
Hi Petr,
I haven't gotten a chance to test this patch on any Btrfs platform,
but only compile successfully without error on my RHEL8/9(xfs).
Can you help test and guarantee it works for you?
libs/libltpswap/libswap.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 5f9622aca..8b180f288 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -4,6 +4,7 @@
* Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
*/
+#include <linux/fs.h>
#include <errno.h>
#define TST_NO_DEFAULT_MAIN
@@ -23,11 +24,37 @@ static const char *const swap_supported_fs[] = {
NULL
};
+static void set_nocow_attr(const char *filename)
+{
+ int fd;
+ int attrs;
+
+ fd = SAFE_OPEN(filename, O_RDONLY);
+
+ if (ioctl(fd, FS_IOC_GETFLAGS, &attrs) == -1) {
+ tst_res(TFAIL | TERRNO, "Error getting attributes");
+ close(fd);
+ return;
+ }
+
+ attrs |= FS_NOCOW_FL;
+
+ if (ioctl(fd, FS_IOC_SETFLAGS, &attrs) == -1)
+ tst_res(TFAIL | TERRNO, "Error setting FS_NOCOW_FL attribute");
+ else
+ tst_res(TINFO, "FS_NOCOW_FL attribute set on %s\n", filename);
+
+ close(fd);
+}
+
/*
* Make a swap file
*/
int make_swapfile(const char *swapfile, int safe)
{
+ long fs_type = tst_fs_type(swapfile);
+ const char *fstype = tst_fs_type_name(fs_type);
+
if (!tst_fs_has_free(".", sysconf(_SC_PAGESIZE) * 10, TST_BYTES))
tst_brk(TBROK, "Insufficient disk space to create swap file");
@@ -35,6 +62,14 @@ int make_swapfile(const char *swapfile, int safe)
if (tst_fill_file(swapfile, 0, sysconf(_SC_PAGESIZE), 10) != 0)
tst_brk(TBROK, "Failed to create swapfile");
+ /* Btrfs file need set 'nocow' attribute */
+ if (strcmp(fstype, "btrfs") == 0) {
+ if (tst_kvercmp(5, 0, 0) > 0)
+ set_nocow_attr(swapfile);
+ else
+ tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
+ }
+
/* make the file swapfile */
const char *argv[2 + 1];
argv[0] = "mkswap";
--
2.40.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 1/1] swapon01: Test on all filesystems
2024-01-19 15:06 ` Cyril Hrubis
@ 2024-01-22 6:22 ` Petr Vorel
2024-01-22 7:39 ` Li Wang
0 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2024-01-22 6:22 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
> Hi!
> > testcases/kernel/syscalls/swapon/swapon01.c | 21 +++++++++++++++------
> > 1 file changed, 15 insertions(+), 6 deletions(-)
> > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
> > index e59fb20a1..ef4ebfdcf 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > @@ -8,6 +8,7 @@
> > * [Description]
> > *
> > * Checks that swapon() succeds with swapfile.
> > + * Testing on all filesystems which support swap file.
> > */
> > #include <unistd.h>
> > @@ -17,13 +18,14 @@
> > #include "lapi/syscalls.h"
> > #include "libswap.h"
> > -#define SWAP_FILE "swapfile01"
> > +#define MNTPOINT "mntpoint"
> > +#define SWAP_FILE MNTPOINT"/swapfile01"
> > static void verify_swapon(void)
> > {
> > TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
> > - if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> > + if (tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> I do not think that this should be removed, if the swapon() call fails
> we still do not want TBROK here.
+1, I did it by accident when rebasing the original patch.
> > tst_brk(TBROK | TERRNO,
> > "Failed to turn off swapfile, system reboot recommended");
> > }
> > @@ -31,13 +33,20 @@ static void verify_swapon(void)
> > static void setup(void)
> > {
> > - is_swap_supported(SWAP_FILE);
> > make_swapfile(SWAP_FILE, 0);
> > }
> > static struct tst_test test = {
> > - .needs_root = 1,
> > - .needs_tmpdir = 1,
> > + .mntpoint = MNTPOINT,
> > + .mount_device = 1,
> > + .needs_root = 1, /* for swapon() */
> Can we please avoid comments like this?
Sure (again part for the original effort).
> I'ts pretty clear that if you are working with devices and setting up
> swapfiles it's priviledged operation...
> > + .all_filesystems = 1,
> > .test_all = verify_swapon,
> > - .setup = setup
> > + .setup = setup,
> > + .skip_filesystems = (const char *[]) {
> > + "bcachefs",
> > + "btrfs",
> > + "tmpfs",
> So the rest of the filesystems work fine? If so this change looks fine
> to me.
Yes.
Going to send v2.
Kind regards,
Petr
> > + NULL
> > + },
> > };
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 1/1] swapon01: Test on all filesystems
2024-01-20 4:21 ` Li Wang
2024-01-20 4:34 ` [LTP] [PATCH 1/2] libswap: add known swap supported fs check Li Wang
@ 2024-01-22 6:26 ` Petr Vorel
2024-01-22 7:50 ` Li Wang
1 sibling, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2024-01-22 6:26 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi Li, Cyril,
> Hi Petr, Cyril,
> On Fri, Jan 19, 2024 at 10:43 PM Petr Vorel <pvorel@suse.cz> wrote:
> > Test on all filesystems to increase coverage.
> > Skip filesystems which does not support swap (currently bcachefs, btrfs
> > and tmpfs).
> > Tested on 5.10, 6.6 and 6.7.
> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > Hi Li, Cyril,
> > feel free to postpone this after the release.
> > If we are for adding this, I'll retest on Monday older filesystems.
> > man swapon(8) mentions:
> > Btrfs
> > Swap files on Btrfs are supported since Linux 5.0 on files with
> > nocow
> > attribute. See the btrfs(5) manual page for more details.
> > => Can we pass "nocow" just to btrfs? Or should it be added to single
> > test, which uses just btrfs with nocow?
> > NFS
> > Swap over NFS may not work.
> > => I guess this is not important for us, as NFS is not part of
> > filesystems in .all_filesystems, but maybe we should still add it to the
> > whitelist?
> > Kind regards,
> > Petr
> > testcases/kernel/syscalls/swapon/swapon01.c | 21 +++++++++++++++------
> > 1 file changed, 15 insertions(+), 6 deletions(-)
> > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> > b/testcases/kernel/syscalls/swapon/swapon01.c
> > index e59fb20a1..ef4ebfdcf 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > @@ -8,6 +8,7 @@
> > * [Description]
> > *
> > * Checks that swapon() succeds with swapfile.
> > + * Testing on all filesystems which support swap file.
> > */
> > #include <unistd.h>
> > @@ -17,13 +18,14 @@
> > #include "lapi/syscalls.h"
> > #include "libswap.h"
> > -#define SWAP_FILE "swapfile01"
> > +#define MNTPOINT "mntpoint"
> > +#define SWAP_FILE MNTPOINT"/swapfile01"
> > static void verify_swapon(void)
> > {
> > TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
> > - if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> > + if (tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> > tst_brk(TBROK | TERRNO,
> > "Failed to turn off swapfile, system
> > reboot recommended");
> > }
> > @@ -31,13 +33,20 @@ static void verify_swapon(void)
> > static void setup(void)
> > {
> > - is_swap_supported(SWAP_FILE);
> > make_swapfile(SWAP_FILE, 0);
> > }
> > static struct tst_test test = {
> > - .needs_root = 1,
> > - .needs_tmpdir = 1,
> > + .mntpoint = MNTPOINT,
> > + .mount_device = 1,
> > + .needs_root = 1, /* for swapon() */
> > + .all_filesystems = 1,
> > .test_all = verify_swapon,
> > - .setup = setup
> > + .setup = setup,
> > + .skip_filesystems = (const char *[]) {
> > + "bcachefs",
> > + "btrfs",
> > + "tmpfs",
> > + NULL
> > + },
> IMHO, I hate to add the skip_filesystem in this test, because if we do,
> then we have to add to all of the related swap tests that, it add more
> tedious work to people.
First I thought it'd be ok to have just single test which uses all_filesystems
(better one than none), but sure, having all of them would be better.
> So, if we decide to postpone this patch to release, we can just refactor
> the is_swap_supported() function to make things easier. I will send an RFC
> patch to show something in my mind, what we need to do later is just
> to finalize the swap_supported_fs[] struct list.
Sure, this is not critical, it can wait if you have better solution. Thanks
for spending time on it.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files
2024-01-20 8:27 ` [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files Li Wang
@ 2024-01-22 7:13 ` Petr Vorel
2024-01-22 7:28 ` Li Wang
0 siblings, 1 reply; 15+ messages in thread
From: Petr Vorel @ 2024-01-22 7:13 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi Li,
> The patch aims to ensure swap files on Btrfs filesystems are created
> with the appropriate FS_NOCOW_FL attribute, which is necessary to
> disable CoW (Copy-on-Write) for swap files, perthe btrfs(5) manual page.
> This change is gated behind a kernel version check to ensure compatibility
> with the system's capabilities.
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
> Notes:
> Hi Petr,
> I haven't gotten a chance to test this patch on any Btrfs platform,
> but only compile successfully without error on my RHEL8/9(xfs).
> Can you help test and guarantee it works for you?
I'm not able to apply this to the current master. I also got a bit confused by
number of patches for libswap / swapon01. Could you please resend all the
patches again (in a series)? Or push branch to your fork and point the location?
(whatever is easier to you)
Kind regards,
Petr
> libs/libltpswap/libswap.c | 35 +++++++++++++++++++++++++++++++++++
> 1 file changed, 35 insertions(+)
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index 5f9622aca..8b180f288 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -4,6 +4,7 @@
> * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
> */
> +#include <linux/fs.h>
> #include <errno.h>
> #define TST_NO_DEFAULT_MAIN
> @@ -23,11 +24,37 @@ static const char *const swap_supported_fs[] = {
> NULL
> };
> +static void set_nocow_attr(const char *filename)
> +{
> + int fd;
> + int attrs;
> +
> + fd = SAFE_OPEN(filename, O_RDONLY);
> +
> + if (ioctl(fd, FS_IOC_GETFLAGS, &attrs) == -1) {
> + tst_res(TFAIL | TERRNO, "Error getting attributes");
> + close(fd);
> + return;
> + }
> +
> + attrs |= FS_NOCOW_FL;
> +
> + if (ioctl(fd, FS_IOC_SETFLAGS, &attrs) == -1)
> + tst_res(TFAIL | TERRNO, "Error setting FS_NOCOW_FL attribute");
> + else
> + tst_res(TINFO, "FS_NOCOW_FL attribute set on %s\n", filename);
> +
> + close(fd);
> +}
> +
> /*
> * Make a swap file
> */
> int make_swapfile(const char *swapfile, int safe)
> {
> + long fs_type = tst_fs_type(swapfile);
> + const char *fstype = tst_fs_type_name(fs_type);
> +
> if (!tst_fs_has_free(".", sysconf(_SC_PAGESIZE) * 10, TST_BYTES))
> tst_brk(TBROK, "Insufficient disk space to create swap file");
> @@ -35,6 +62,14 @@ int make_swapfile(const char *swapfile, int safe)
> if (tst_fill_file(swapfile, 0, sysconf(_SC_PAGESIZE), 10) != 0)
> tst_brk(TBROK, "Failed to create swapfile");
> + /* Btrfs file need set 'nocow' attribute */
> + if (strcmp(fstype, "btrfs") == 0) {
> + if (tst_kvercmp(5, 0, 0) > 0)
> + set_nocow_attr(swapfile);
> + else
> + tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
> + }
> +
> /* make the file swapfile */
> const char *argv[2 + 1];
> argv[0] = "mkswap";
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files
2024-01-22 7:13 ` Petr Vorel
@ 2024-01-22 7:28 ` Li Wang
0 siblings, 0 replies; 15+ messages in thread
From: Li Wang @ 2024-01-22 7:28 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Mon, Jan 22, 2024 at 3:13 PM Petr Vorel <pvorel@suse.cz> wrote:
> Hi Li,
>
> > The patch aims to ensure swap files on Btrfs filesystems are created
> > with the appropriate FS_NOCOW_FL attribute, which is necessary to
> > disable CoW (Copy-on-Write) for swap files, perthe btrfs(5) manual page.
> > This change is gated behind a kernel version check to ensure
> compatibility
> > with the system's capabilities.
>
> > Signed-off-by: Li Wang <liwang@redhat.com>
> > ---
>
> > Notes:
> > Hi Petr,
>
> > I haven't gotten a chance to test this patch on any Btrfs platform,
> > but only compile successfully without error on my RHEL8/9(xfs).
> > Can you help test and guarantee it works for you?
>
> I'm not able to apply this to the current master. I also got a bit
> confused by
> number of patches for libswap / swapon01. Could you please resend all the
> patches again (in a series)? Or push branch to your fork and point the
> location?
> (whatever is easier to you)
>
Sure, let's format them in a set.
Sorry for the confusion, I was just developing them one by one and sent
directly.
>
> Kind regards,
> Petr
>
> > libs/libltpswap/libswap.c | 35 +++++++++++++++++++++++++++++++++++
> > 1 file changed, 35 insertions(+)
>
> > diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> > index 5f9622aca..8b180f288 100644
> > --- a/libs/libltpswap/libswap.c
> > +++ b/libs/libltpswap/libswap.c
> > @@ -4,6 +4,7 @@
> > * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
> > */
>
> > +#include <linux/fs.h>
> > #include <errno.h>
>
> > #define TST_NO_DEFAULT_MAIN
> > @@ -23,11 +24,37 @@ static const char *const swap_supported_fs[] = {
> > NULL
> > };
>
> > +static void set_nocow_attr(const char *filename)
> > +{
> > + int fd;
> > + int attrs;
> > +
> > + fd = SAFE_OPEN(filename, O_RDONLY);
> > +
> > + if (ioctl(fd, FS_IOC_GETFLAGS, &attrs) == -1) {
> > + tst_res(TFAIL | TERRNO, "Error getting attributes");
> > + close(fd);
> > + return;
> > + }
> > +
> > + attrs |= FS_NOCOW_FL;
> > +
> > + if (ioctl(fd, FS_IOC_SETFLAGS, &attrs) == -1)
> > + tst_res(TFAIL | TERRNO, "Error setting FS_NOCOW_FL
> attribute");
> > + else
> > + tst_res(TINFO, "FS_NOCOW_FL attribute set on %s\n",
> filename);
> > +
> > + close(fd);
> > +}
> > +
> > /*
> > * Make a swap file
> > */
> > int make_swapfile(const char *swapfile, int safe)
> > {
> > + long fs_type = tst_fs_type(swapfile);
> > + const char *fstype = tst_fs_type_name(fs_type);
> > +
> > if (!tst_fs_has_free(".", sysconf(_SC_PAGESIZE) * 10, TST_BYTES))
> > tst_brk(TBROK, "Insufficient disk space to create swap
> file");
>
> > @@ -35,6 +62,14 @@ int make_swapfile(const char *swapfile, int safe)
> > if (tst_fill_file(swapfile, 0, sysconf(_SC_PAGESIZE), 10) != 0)
> > tst_brk(TBROK, "Failed to create swapfile");
>
> > + /* Btrfs file need set 'nocow' attribute */
> > + if (strcmp(fstype, "btrfs") == 0) {
> > + if (tst_kvercmp(5, 0, 0) > 0)
> > + set_nocow_attr(swapfile);
> > + else
> > + tst_brk(TCONF, "Swapfile on %s not implemented",
> fstype);
> > + }
> > +
> > /* make the file swapfile */
> > const char *argv[2 + 1];
> > argv[0] = "mkswap";
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 1/1] swapon01: Test on all filesystems
2024-01-22 6:22 ` Petr Vorel
@ 2024-01-22 7:39 ` Li Wang
0 siblings, 0 replies; 15+ messages in thread
From: Li Wang @ 2024-01-22 7:39 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi Petr
On Mon, Jan 22, 2024 at 2:22 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> > So the rest of the filesystems work fine? If so this change looks fine
> > to me.
>
> Yes.
>
> Going to send v2.
>
No need, I dared to modify and combine it in the 2/4.
https://lists.linux.it/pipermail/ltp/2024-January/036806.html
Sorry for my arbitrary work, I just to test the patchset on my side easily.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 1/1] swapon01: Test on all filesystems
2024-01-22 6:26 ` [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
@ 2024-01-22 7:50 ` Li Wang
2024-01-22 8:24 ` Petr Vorel
0 siblings, 1 reply; 15+ messages in thread
From: Li Wang @ 2024-01-22 7:50 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Mon, Jan 22, 2024 at 2:27 PM Petr Vorel <pvorel@suse.cz> wrote:
> Hi Li, Cyril,
>
> > Hi Petr, Cyril,
>
> > On Fri, Jan 19, 2024 at 10:43 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> > > Test on all filesystems to increase coverage.
> > > Skip filesystems which does not support swap (currently bcachefs, btrfs
> > > and tmpfs).
>
> > > Tested on 5.10, 6.6 and 6.7.
>
> > > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > > ---
> > > Hi Li, Cyril,
>
> > > feel free to postpone this after the release.
> > > If we are for adding this, I'll retest on Monday older filesystems.
>
> > > man swapon(8) mentions:
>
> > > Btrfs
> > > Swap files on Btrfs are supported since Linux 5.0 on files with
> > > nocow
> > > attribute. See the btrfs(5) manual page for more details.
>
> > > => Can we pass "nocow" just to btrfs? Or should it be added to single
> > > test, which uses just btrfs with nocow?
>
> > > NFS
> > > Swap over NFS may not work.
>
> > > => I guess this is not important for us, as NFS is not part of
> > > filesystems in .all_filesystems, but maybe we should still add it to
> the
> > > whitelist?
>
> > > Kind regards,
> > > Petr
>
> > > testcases/kernel/syscalls/swapon/swapon01.c | 21 +++++++++++++++------
> > > 1 file changed, 15 insertions(+), 6 deletions(-)
>
> > > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> > > b/testcases/kernel/syscalls/swapon/swapon01.c
> > > index e59fb20a1..ef4ebfdcf 100644
> > > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > > @@ -8,6 +8,7 @@
> > > * [Description]
> > > *
> > > * Checks that swapon() succeds with swapfile.
> > > + * Testing on all filesystems which support swap file.
> > > */
>
> > > #include <unistd.h>
> > > @@ -17,13 +18,14 @@
> > > #include "lapi/syscalls.h"
> > > #include "libswap.h"
>
> > > -#define SWAP_FILE "swapfile01"
> > > +#define MNTPOINT "mntpoint"
> > > +#define SWAP_FILE MNTPOINT"/swapfile01"
>
> > > static void verify_swapon(void)
> > > {
> > > TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
>
> > > - if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> > > + if (tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> > > tst_brk(TBROK | TERRNO,
> > > "Failed to turn off swapfile, system
> > > reboot recommended");
> > > }
> > > @@ -31,13 +33,20 @@ static void verify_swapon(void)
>
> > > static void setup(void)
> > > {
> > > - is_swap_supported(SWAP_FILE);
> > > make_swapfile(SWAP_FILE, 0);
> > > }
>
> > > static struct tst_test test = {
> > > - .needs_root = 1,
> > > - .needs_tmpdir = 1,
> > > + .mntpoint = MNTPOINT,
> > > + .mount_device = 1,
> > > + .needs_root = 1, /* for swapon() */
> > > + .all_filesystems = 1,
> > > .test_all = verify_swapon,
> > > - .setup = setup
> > > + .setup = setup,
> > > + .skip_filesystems = (const char *[]) {
> > > + "bcachefs",
> > > + "btrfs",
> > > + "tmpfs",
> > > + NULL
> > > + },
>
>
>
> > IMHO, I hate to add the skip_filesystem in this test, because if we do,
> > then we have to add to all of the related swap tests that, it add more
> > tedious work to people.
>
> First I thought it'd be ok to have just single test which uses
> all_filesystems
> (better one than none), but sure, having all of them would be better.
>
> > So, if we decide to postpone this patch to release, we can just refactor
> > the is_swap_supported() function to make things easier. I will send an
> RFC
> > patch to show something in my mind, what we need to do later is just
> > to finalize the swap_supported_fs[] struct list.
>
> Sure, this is not critical, it can wait if you have better solution. Thanks
> for spending time on it.
>
Yes, but it is ready there 1/4 :).
https://lists.linux.it/pipermail/ltp/2024-January/036804.html
The rest work is just to finalize the swap_supported_fs list.
And, I agree that all of these can be postponed. Because
so far it won't be a critical/urgent-fix for a new release.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH 1/1] swapon01: Test on all filesystems
2024-01-22 7:50 ` Li Wang
@ 2024-01-22 8:24 ` Petr Vorel
0 siblings, 0 replies; 15+ messages in thread
From: Petr Vorel @ 2024-01-22 8:24 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi Li,
> On Mon, Jan 22, 2024 at 2:27 PM Petr Vorel <pvorel@suse.cz> wrote:
> > Hi Li, Cyril,
> > > Hi Petr, Cyril,
> > > On Fri, Jan 19, 2024 at 10:43 PM Petr Vorel <pvorel@suse.cz> wrote:
> > > > Test on all filesystems to increase coverage.
> > > > Skip filesystems which does not support swap (currently bcachefs, btrfs
> > > > and tmpfs).
> > > > Tested on 5.10, 6.6 and 6.7.
> > > > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > > > ---
> > > > Hi Li, Cyril,
> > > > feel free to postpone this after the release.
> > > > If we are for adding this, I'll retest on Monday older filesystems.
> > > > man swapon(8) mentions:
> > > > Btrfs
> > > > Swap files on Btrfs are supported since Linux 5.0 on files with
> > > > nocow
> > > > attribute. See the btrfs(5) manual page for more details.
> > > > => Can we pass "nocow" just to btrfs? Or should it be added to single
> > > > test, which uses just btrfs with nocow?
> > > > NFS
> > > > Swap over NFS may not work.
> > > > => I guess this is not important for us, as NFS is not part of
> > > > filesystems in .all_filesystems, but maybe we should still add it to
> > the
> > > > whitelist?
> > > > Kind regards,
> > > > Petr
> > > > testcases/kernel/syscalls/swapon/swapon01.c | 21 +++++++++++++++------
> > > > 1 file changed, 15 insertions(+), 6 deletions(-)
> > > > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> > > > b/testcases/kernel/syscalls/swapon/swapon01.c
> > > > index e59fb20a1..ef4ebfdcf 100644
> > > > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > > > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > > > @@ -8,6 +8,7 @@
> > > > * [Description]
> > > > *
> > > > * Checks that swapon() succeds with swapfile.
> > > > + * Testing on all filesystems which support swap file.
> > > > */
> > > > #include <unistd.h>
> > > > @@ -17,13 +18,14 @@
> > > > #include "lapi/syscalls.h"
> > > > #include "libswap.h"
> > > > -#define SWAP_FILE "swapfile01"
> > > > +#define MNTPOINT "mntpoint"
> > > > +#define SWAP_FILE MNTPOINT"/swapfile01"
> > > > static void verify_swapon(void)
> > > > {
> > > > TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
> > > > - if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> > > > + if (tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
> > > > tst_brk(TBROK | TERRNO,
> > > > "Failed to turn off swapfile, system
> > > > reboot recommended");
> > > > }
> > > > @@ -31,13 +33,20 @@ static void verify_swapon(void)
> > > > static void setup(void)
> > > > {
> > > > - is_swap_supported(SWAP_FILE);
> > > > make_swapfile(SWAP_FILE, 0);
> > > > }
> > > > static struct tst_test test = {
> > > > - .needs_root = 1,
> > > > - .needs_tmpdir = 1,
> > > > + .mntpoint = MNTPOINT,
> > > > + .mount_device = 1,
> > > > + .needs_root = 1, /* for swapon() */
> > > > + .all_filesystems = 1,
> > > > .test_all = verify_swapon,
> > > > - .setup = setup
> > > > + .setup = setup,
> > > > + .skip_filesystems = (const char *[]) {
> > > > + "bcachefs",
> > > > + "btrfs",
> > > > + "tmpfs",
> > > > + NULL
> > > > + },
> > > IMHO, I hate to add the skip_filesystem in this test, because if we do,
> > > then we have to add to all of the related swap tests that, it add more
> > > tedious work to people.
> > First I thought it'd be ok to have just single test which uses
> > all_filesystems
> > (better one than none), but sure, having all of them would be better.
> > > So, if we decide to postpone this patch to release, we can just refactor
> > > the is_swap_supported() function to make things easier. I will send an
> > RFC
> > > patch to show something in my mind, what we need to do later is just
> > > to finalize the swap_supported_fs[] struct list.
> > Sure, this is not critical, it can wait if you have better solution. Thanks
> > for spending time on it.
> Yes, but it is ready there 1/4 :).
> https://lists.linux.it/pipermail/ltp/2024-January/036804.html
> The rest work is just to finalize the swap_supported_fs list.
> And, I agree that all of these can be postponed. Because
> so far it won't be a critical/urgent-fix for a new release.
OTOH if you prepared this, I'm ok to review and test.
I already run various tests on this.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2024-01-22 8:24 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19 14:43 [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
2024-01-19 15:06 ` Cyril Hrubis
2024-01-22 6:22 ` Petr Vorel
2024-01-22 7:39 ` Li Wang
2024-01-20 4:21 ` Li Wang
2024-01-20 4:34 ` [LTP] [PATCH 1/2] libswap: add known swap supported fs check Li Wang
2024-01-20 4:34 ` [LTP] [PATCH 2/2] swapon01: Test on all filesystems Li Wang
2024-01-20 6:40 ` [LTP] [PATCH] swapon01: Improving test with memory limits and swap reporting Li Wang
2024-01-20 6:52 ` Li Wang
2024-01-20 8:27 ` [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files Li Wang
2024-01-22 7:13 ` Petr Vorel
2024-01-22 7:28 ` Li Wang
2024-01-22 6:26 ` [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
2024-01-22 7:50 ` Li Wang
2024-01-22 8:24 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox