* [LTP] [PATCH 1/3] swapon03: Cleanup
2025-11-05 15:47 [LTP] [PATCH 0/3] swapon03: Try to swapon() as many files until it fails Petr Vorel
@ 2025-11-05 15:47 ` Petr Vorel
2025-11-05 15:47 ` [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails Petr Vorel
2025-11-05 15:47 ` [LTP] [PATCH 3/3] libswap: Remove now unused tst_max_swapfiles() Petr Vorel
2 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2025-11-05 15:47 UTC (permalink / raw)
To: ltp
- Remove unused return code in check_and_swapoff() and setup_swap(). The
purpose was to run cleanup() in the end of the setup() if creating
swap fails, but return code is always 0. Also cleanup() should be run
when test exits with tst_brk() anyway.
- Change return code from TFAIL to TBROK.
- Add missing brackets.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/kernel/syscalls/swapon/swapon03.c | 23 +++++++--------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index d6445d5fc4..b89d853188 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -25,7 +25,7 @@
static int swapfiles;
-static int setup_swap(void)
+static void setup_swap(void)
{
pid_t pid;
int status;
@@ -54,34 +54,28 @@ static int setup_swap(void)
TST_EXP_PASS_SILENT(swapon(filename, 0));
}
exit(0);
- } else
+ } else {
waitpid(pid, &status, 0);
+ }
if (WEXITSTATUS(status))
- tst_brk(TFAIL, "Failed to setup swap files");
+ tst_brk(TBROK, "Failed to setup swap files");
tst_res(TINFO, "Successfully created %d swap files", swapfiles);
MAKE_SMALL_SWAPFILE(TEST_FILE);
-
- return 0;
}
/*
* Check if the file is at /proc/swaps and remove it giving swapoff
*/
-static int check_and_swapoff(const char *filename)
+static void check_and_swapoff(const char *filename)
{
char cmd_buffer[256];
- int rc = -1;
snprintf(cmd_buffer, sizeof(cmd_buffer), "grep -q '%s.*file' /proc/swaps", filename);
- if (system(cmd_buffer) == 0 && swapoff(filename) != 0) {
+ if (system(cmd_buffer) == 0 && swapoff(filename) != 0)
tst_res(TWARN, "Failed to swapoff %s", filename);
- rc = -1;
- }
-
- return rc;
}
/*
@@ -111,10 +105,7 @@ static void setup(void)
tst_brk(TCONF, "swap not supported by kernel");
is_swap_supported(TEST_FILE);
- if (setup_swap() < 0) {
- clean_swap();
- tst_brk(TBROK, "Setup failed, quitting the test");
- }
+ setup_swap();
}
static void cleanup(void)
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread* [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails
2025-11-05 15:47 [LTP] [PATCH 0/3] swapon03: Try to swapon() as many files until it fails Petr Vorel
2025-11-05 15:47 ` [LTP] [PATCH 1/3] swapon03: Cleanup Petr Vorel
@ 2025-11-05 15:47 ` Petr Vorel
2025-11-06 3:46 ` Li Wang via ltp
2025-11-06 10:11 ` Avinesh Kumar
2025-11-05 15:47 ` [LTP] [PATCH 3/3] libswap: Remove now unused tst_max_swapfiles() Petr Vorel
2 siblings, 2 replies; 9+ messages in thread
From: Petr Vorel @ 2025-11-05 15:47 UTC (permalink / raw)
To: ltp; +Cc: Michal Hocko
Previously tst_max_swapfiles() had fine tuning for a specific kernel
version which was fragile due various backports in enterprise kernels.
Let's try to create and use as many swap files until swapon() fails.
Then check for expected EPERM.
Suggested-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/kernel/syscalls/swapon/swapon03.c | 63 +++++++++++++--------
1 file changed, 40 insertions(+), 23 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index b89d853188..0027f874be 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -1,14 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
+ * Copyright (c) Linux Test Project, 2009-2025
* Copyright (c) International Business Machines Corp., 2007
* Created by <rsalveti@linux.vnet.ibm.com>
- *
*/
/*\
- * This test case checks whether swapon(2) system call returns:
+ * Test checks whether :man2:`swapon` system call returns EPERM when the maximum
+ * number of swap files are already in use.
*
- * - EPERM when there are more than MAX_SWAPFILES already in use.
+ * NOTE: test does not try to calculate MAX_SWAPFILES from the internal
+ * kernel implementation (which is currently <23, 29> depending on kernel
+ * configuration). Instead test exptect that at least 15 swap files minus
+ * currently used swap can be created.
*/
#include <stdio.h>
@@ -20,49 +24,54 @@
#include "lapi/syscalls.h"
#include "libswap.h"
+#define NUM_SWAP_FILES 15
#define MNTPOINT "mntpoint"
#define TEST_FILE MNTPOINT"/testswap"
-static int swapfiles;
+static int *swapfiles;
static void setup_swap(void)
{
pid_t pid;
- int status;
- int j, max_swapfiles, used_swapfiles;
+ int status, used_swapfiles, expected_swapfiles;
char filename[FILENAME_MAX];
SAFE_SETEUID(0);
- /* Determine how many more files are to be created */
- max_swapfiles = tst_max_swapfiles();
used_swapfiles = tst_count_swaps();
- swapfiles = max_swapfiles - used_swapfiles;
- if (swapfiles > max_swapfiles)
- swapfiles = max_swapfiles;
+ expected_swapfiles = NUM_SWAP_FILES - used_swapfiles;
+
+ if (expected_swapfiles < 0) {
+ tst_brk(TCONF, "Warning: too many used swap files (%d)",
+ expected_swapfiles);
+ }
pid = SAFE_FORK();
if (pid == 0) {
- /*create and turn on remaining swapfiles */
- for (j = 0; j < swapfiles; j++) {
-
+ while (true) {
/* Create the swapfile */
- snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
+ snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, *swapfiles);
MAKE_SMALL_SWAPFILE(filename);
- /* turn on the swap file */
- TST_EXP_PASS_SILENT(swapon(filename, 0));
+ /* Quit on a first swap file over max */
+ if (swapon(filename, 0) == -1)
+ break;
+ (*swapfiles)++;
}
exit(0);
} else {
waitpid(pid, &status, 0);
}
- if (WEXITSTATUS(status))
+ if (WEXITSTATUS(status) || *swapfiles == 0)
tst_brk(TBROK, "Failed to setup swap files");
- tst_res(TINFO, "Successfully created %d swap files", swapfiles);
- MAKE_SMALL_SWAPFILE(TEST_FILE);
+ if (*swapfiles < expected_swapfiles) {
+ tst_res(TWARN, "Successfully created only %d swap files (>= %d expected)",
+ *swapfiles, expected_swapfiles);
+ } else {
+ tst_res(TINFO, "Successfully created %d swap files", *swapfiles);
+ }
}
/*
@@ -86,8 +95,8 @@ static void clean_swap(void)
int j;
char filename[FILENAME_MAX];
- for (j = 0; j < swapfiles; j++) {
- snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
+ for (j = 0; j < *swapfiles; j++) {
+ snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j);
check_and_swapoff(filename);
}
@@ -105,12 +114,20 @@ static void setup(void)
tst_brk(TCONF, "swap not supported by kernel");
is_swap_supported(TEST_FILE);
+
+ swapfiles = SAFE_MMAP(NULL, sizeof(*swapfiles), PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ *swapfiles = 0;
+
setup_swap();
}
static void cleanup(void)
{
- clean_swap();
+ if (swapfiles) {
+ clean_swap();
+ SAFE_MUNMAP(swapfiles, sizeof(*swapfiles));
+ }
}
static struct tst_test test = {
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails
2025-11-05 15:47 ` [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails Petr Vorel
@ 2025-11-06 3:46 ` Li Wang via ltp
2025-11-06 9:07 ` Petr Vorel
2025-11-06 10:11 ` Avinesh Kumar
1 sibling, 1 reply; 9+ messages in thread
From: Li Wang via ltp @ 2025-11-06 3:46 UTC (permalink / raw)
To: Petr Vorel; +Cc: Michal Hocko, ltp
On Wed, Nov 5, 2025 at 11:48 PM Petr Vorel <pvorel@suse.cz> wrote:
> Previously tst_max_swapfiles() had fine tuning for a specific kernel
> version which was fragile due various backports in enterprise kernels.
>
> Let's try to create and use as many swap files until swapon() fails.
> Then check for expected EPERM.
>
> Suggested-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> testcases/kernel/syscalls/swapon/swapon03.c | 63 +++++++++++++--------
> 1 file changed, 40 insertions(+), 23 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon03.c
> b/testcases/kernel/syscalls/swapon/swapon03.c
> index b89d853188..0027f874be 100644
> --- a/testcases/kernel/syscalls/swapon/swapon03.c
> +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> @@ -1,14 +1,18 @@
> // SPDX-License-Identifier: GPL-2.0-or-later
> /*
> + * Copyright (c) Linux Test Project, 2009-2025
> * Copyright (c) International Business Machines Corp., 2007
> * Created by <rsalveti@linux.vnet.ibm.com>
> - *
> */
>
> /*\
> - * This test case checks whether swapon(2) system call returns:
> + * Test checks whether :man2:`swapon` system call returns EPERM when the
> maximum
> + * number of swap files are already in use.
> *
> - * - EPERM when there are more than MAX_SWAPFILES already in use.
> + * NOTE: test does not try to calculate MAX_SWAPFILES from the internal
> + * kernel implementation (which is currently <23, 29> depending on kernel
> + * configuration). Instead test exptect that at least 15 swap files minus
> + * currently used swap can be created.
> */
>
> #include <stdio.h>
> @@ -20,49 +24,54 @@
> #include "lapi/syscalls.h"
> #include "libswap.h"
>
> +#define NUM_SWAP_FILES 15
>
Does the number 15 have a specific meaning?
Anyway, the whole patch set looks good to me:
Reviewed-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails
2025-11-06 3:46 ` Li Wang via ltp
@ 2025-11-06 9:07 ` Petr Vorel
0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2025-11-06 9:07 UTC (permalink / raw)
To: Li Wang; +Cc: Michal Hocko, ltp
Hi Li,
...
> > /*\
> > - * This test case checks whether swapon(2) system call returns:
> > + * Test checks whether :man2:`swapon` system call returns EPERM when the
> > maximum
> > + * number of swap files are already in use.
> > *
> > - * - EPERM when there are more than MAX_SWAPFILES already in use.
> > + * NOTE: test does not try to calculate MAX_SWAPFILES from the internal
> > + * kernel implementation (which is currently <23, 29> depending on kernel
> > + * configuration). Instead test exptect that at least 15 swap files minus
> > + * currently used swap can be created.
> > */
> > #include <stdio.h>
> > @@ -20,49 +24,54 @@
> > #include "lapi/syscalls.h"
> > #include "libswap.h"
> > +#define NUM_SWAP_FILES 15
> Does the number 15 have a specific meaning?
No. I wanted something high enough but reasonably smaller than the current
minimum 23, because it can get even smaller in the future.
Should I move/add some of the docs from docparse doc (the note) to this
definition?
> Anyway, the whole patch set looks good to me:
> Reviewed-by: Li Wang <liwang@redhat.com>
Thanks!
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails
2025-11-05 15:47 ` [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails Petr Vorel
2025-11-06 3:46 ` Li Wang via ltp
@ 2025-11-06 10:11 ` Avinesh Kumar
2025-11-06 12:03 ` Petr Vorel
1 sibling, 1 reply; 9+ messages in thread
From: Avinesh Kumar @ 2025-11-06 10:11 UTC (permalink / raw)
To: ltp; +Cc: Michal Hocko
Hi Petr,
some comments inline
On Wednesday, November 5, 2025 4:47:15 PM CET Petr Vorel wrote:
> Previously tst_max_swapfiles() had fine tuning for a specific kernel
> version which was fragile due various backports in enterprise kernels.
>
> Let's try to create and use as many swap files until swapon() fails.
> Then check for expected EPERM.
>
> Suggested-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> testcases/kernel/syscalls/swapon/swapon03.c | 63 +++++++++++++--------
> 1 file changed, 40 insertions(+), 23 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
> index b89d853188..0027f874be 100644
> --- a/testcases/kernel/syscalls/swapon/swapon03.c
> +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> @@ -1,14 +1,18 @@
> // SPDX-License-Identifier: GPL-2.0-or-later
> /*
> + * Copyright (c) Linux Test Project, 2009-2025
> * Copyright (c) International Business Machines Corp., 2007
> * Created by <rsalveti@linux.vnet.ibm.com>
> - *
> */
>
> /*\
> - * This test case checks whether swapon(2) system call returns:
> + * Test checks whether :man2:`swapon` system call returns EPERM when the maximum
> + * number of swap files are already in use.
> *
> - * - EPERM when there are more than MAX_SWAPFILES already in use.
> + * NOTE: test does not try to calculate MAX_SWAPFILES from the internal
> + * kernel implementation (which is currently <23, 29> depending on kernel
> + * configuration). Instead test exptect that at least 15 swap files minus
> + * currently used swap can be created.
> */
>
> #include <stdio.h>
> @@ -20,49 +24,54 @@
> #include "lapi/syscalls.h"
> #include "libswap.h"
>
> +#define NUM_SWAP_FILES 15
> #define MNTPOINT "mntpoint"
> #define TEST_FILE MNTPOINT"/testswap"
>
> -static int swapfiles;
> +static int *swapfiles;
>
> static void setup_swap(void)
> {
> pid_t pid;
> - int status;
> - int j, max_swapfiles, used_swapfiles;
> + int status, used_swapfiles, expected_swapfiles;
> char filename[FILENAME_MAX];
>
> SAFE_SETEUID(0);
>
> - /* Determine how many more files are to be created */
> - max_swapfiles = tst_max_swapfiles();
> used_swapfiles = tst_count_swaps();
> - swapfiles = max_swapfiles - used_swapfiles;
> - if (swapfiles > max_swapfiles)
> - swapfiles = max_swapfiles;
> + expected_swapfiles = NUM_SWAP_FILES - used_swapfiles;
> +
> + if (expected_swapfiles < 0) {
do we want to proceed when expected_swapfiles is 0 here?
> + tst_brk(TCONF, "Warning: too many used swap files (%d)",
> + expected_swapfiles);
I think this should be used_swapfiles ?
> + }
>
> pid = SAFE_FORK();
> if (pid == 0) {
> - /*create and turn on remaining swapfiles */
> - for (j = 0; j < swapfiles; j++) {
> -
> + while (true) {
> /* Create the swapfile */
> - snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
> + snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, *swapfiles);
> MAKE_SMALL_SWAPFILE(filename);
>
> - /* turn on the swap file */
> - TST_EXP_PASS_SILENT(swapon(filename, 0));
> + /* Quit on a first swap file over max */
> + if (swapon(filename, 0) == -1)
so now first swapon() fail is here and then we check for errno==EPERM by
making another swapon() call in verify_swapon function.
Is it possible to combine setup_swap() and verify_swapon() and check for
EPERM on first swapon() fail itself?
> + break;
> + (*swapfiles)++;
> }
> exit(0);
> } else {
> waitpid(pid, &status, 0);
> }
>
> - if (WEXITSTATUS(status))
> + if (WEXITSTATUS(status) || *swapfiles == 0)
> tst_brk(TBROK, "Failed to setup swap files");
>
> - tst_res(TINFO, "Successfully created %d swap files", swapfiles);
> - MAKE_SMALL_SWAPFILE(TEST_FILE);
> + if (*swapfiles < expected_swapfiles) {
> + tst_res(TWARN, "Successfully created only %d swap files (>= %d expected)",
> + *swapfiles, expected_swapfiles);
> + } else {
> + tst_res(TINFO, "Successfully created %d swap files", *swapfiles);
> + }
> }
>
> /*
> @@ -86,8 +95,8 @@ static void clean_swap(void)
> int j;
> char filename[FILENAME_MAX];
>
> - for (j = 0; j < swapfiles; j++) {
> - snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
> + for (j = 0; j < *swapfiles; j++) {
> + snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j);
> check_and_swapoff(filename);
> }
>
> @@ -105,12 +114,20 @@ static void setup(void)
> tst_brk(TCONF, "swap not supported by kernel");
>
> is_swap_supported(TEST_FILE);
> +
> + swapfiles = SAFE_MMAP(NULL, sizeof(*swapfiles), PROT_READ | PROT_WRITE,
> + MAP_SHARED | MAP_ANONYMOUS, -1, 0);
> + *swapfiles = 0;
> +
> setup_swap();
> }
>
> static void cleanup(void)
> {
> - clean_swap();
> + if (swapfiles) {
> + clean_swap();
> + SAFE_MUNMAP(swapfiles, sizeof(*swapfiles));
> + }
> }
>
> static struct tst_test test = {
>
Regards,
Avinesh
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails
2025-11-06 10:11 ` Avinesh Kumar
@ 2025-11-06 12:03 ` Petr Vorel
2025-11-06 13:31 ` Avinesh Kumar
0 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2025-11-06 12:03 UTC (permalink / raw)
To: Avinesh Kumar; +Cc: Michal Hocko, ltp
> Hi Petr,
> some comments inline
+1
...
> > - /* Determine how many more files are to be created */
> > - max_swapfiles = tst_max_swapfiles();
> > used_swapfiles = tst_count_swaps();
> > - swapfiles = max_swapfiles - used_swapfiles;
> > - if (swapfiles > max_swapfiles)
> > - swapfiles = max_swapfiles;
> > + expected_swapfiles = NUM_SWAP_FILES - used_swapfiles;
> > +
> > + if (expected_swapfiles < 0) {
> do we want to proceed when expected_swapfiles is 0 here?
Yes, because NUM_SWAP_FILES is 15, which is safe for the changes.
I.e. on my Tumbleweed VM it can be 23 swaps. One is used as filesystem
partition, therefore it would work on even 22.
> > + tst_brk(TCONF, "Warning: too many used swap files (%d)",
> > + expected_swapfiles);
> I think this should be used_swapfiles ?
+1.
Also I should remove "Warning: " (left over from previous not-yet-sent
version which used tst_res(TWARN)).
I'd also prefer either to improve grep or replace it with C based search
(better as it does not require grep).
> > + }
> > pid = SAFE_FORK();
> > if (pid == 0) {
> > - /*create and turn on remaining swapfiles */
> > - for (j = 0; j < swapfiles; j++) {
> > -
> > + while (true) {
> > /* Create the swapfile */
> > - snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
> > + snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, *swapfiles);
> > MAKE_SMALL_SWAPFILE(filename);
> > - /* turn on the swap file */
> > - TST_EXP_PASS_SILENT(swapon(filename, 0));
> > + /* Quit on a first swap file over max */
> > + if (swapon(filename, 0) == -1)
> so now first swapon() fail is here and then we check for errno==EPERM by
> making another swapon() call in verify_swapon function.
> Is it possible to combine setup_swap() and verify_swapon() and check for
> EPERM on first swapon() fail itself?
I was thinking about it as well. To support -i, we still need to have setup run
only once. Moving code from setup to test function would require to run "setup"
part only once (guard with static variable).
Other option would be to keep setup, but test errno also here (i.e. test it twice).
I'm not sure which one is less awkward.
Kind regards,
Petr
> > + break;
> > + (*swapfiles)++;
> > }
> > exit(0);
> > } else {
> > waitpid(pid, &status, 0);
> > }
> > - if (WEXITSTATUS(status))
> > + if (WEXITSTATUS(status) || *swapfiles == 0)
> > tst_brk(TBROK, "Failed to setup swap files");
...
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails
2025-11-06 12:03 ` Petr Vorel
@ 2025-11-06 13:31 ` Avinesh Kumar
0 siblings, 0 replies; 9+ messages in thread
From: Avinesh Kumar @ 2025-11-06 13:31 UTC (permalink / raw)
To: Petr Vorel; +Cc: Michal Hocko, ltp
> > > +
> > > + if (expected_swapfiles < 0) {
> > do we want to proceed when expected_swapfiles is 0 here?
>
> Yes, because NUM_SWAP_FILES is 15, which is safe for the changes.
> I.e. on my Tumbleweed VM it can be 23 swaps. One is used as filesystem
> partition, therefore it would work on even 22.
Understood, thanks!
> > > - /* turn on the swap file */
> > > - TST_EXP_PASS_SILENT(swapon(filename, 0));
> > > + /* Quit on a first swap file over max */
> > > + if (swapon(filename, 0) == -1)
> > so now first swapon() fail is here and then we check for errno==EPERM by
> > making another swapon() call in verify_swapon function.
> > Is it possible to combine setup_swap() and verify_swapon() and check for
> > EPERM on first swapon() fail itself?
>
> I was thinking about it as well. To support -i, we still need to have setup run
> only once. Moving code from setup to test function would require to run "setup"
> part only once (guard with static variable).
>
> Other option would be to keep setup, but test errno also here (i.e. test it twice).
> I'm not sure which one is less awkward.
ok, I forgot about more iterations scenario.
Reviewed-by: Avinesh Kumar <akumar@suse.de>
(for all patches in the series)
Regards,
Avinesh
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 9+ messages in thread
* [LTP] [PATCH 3/3] libswap: Remove now unused tst_max_swapfiles()
2025-11-05 15:47 [LTP] [PATCH 0/3] swapon03: Try to swapon() as many files until it fails Petr Vorel
2025-11-05 15:47 ` [LTP] [PATCH 1/3] swapon03: Cleanup Petr Vorel
2025-11-05 15:47 ` [LTP] [PATCH 2/3] swapon03: Try to swapon() as many files until it fails Petr Vorel
@ 2025-11-05 15:47 ` Petr Vorel
2 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2025-11-05 15:47 UTC (permalink / raw)
To: ltp
The only use in swapon03 was removed in the previous commit.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
I can squash this to previous commit if you like.
include/libswap.h | 7 -----
libs/swap/libswap.c | 64 ---------------------------------------------
2 files changed, 71 deletions(-)
diff --git a/include/libswap.h b/include/libswap.h
index 6904e8f45b..b22b992eeb 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -109,13 +109,6 @@ int make_swapfile(const char *file, const int lineno,
*/
bool is_swap_supported(const char *filename);
-/**
- * tst_max_swapfiles() - Get kernel constant MAX_SWAPFILES value.
- *
- * Return: MAX_SWAPFILES value.
- */
-int tst_max_swapfiles(void);
-
/**
* tst_count_swaps() - Get the used swapfiles number.
*
diff --git a/libs/swap/libswap.c b/libs/swap/libswap.c
index 734cd2612d..3eb589cdd7 100644
--- a/libs/swap/libswap.c
+++ b/libs/swap/libswap.c
@@ -239,70 +239,6 @@ bool is_swap_supported(const char *filename)
return true;
}
-int tst_max_swapfiles(void)
-{
- unsigned int swp_migration_num = 0, swp_hwpoison_num = 0,
- swp_device_num = 0, swp_pte_marker_num = 0,
- swp_swapin_error_num = 0;
- struct tst_kconfig_var migration = TST_KCONFIG_INIT("CONFIG_MIGRATION");
- struct tst_kconfig_var memory = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
- struct tst_kconfig_var device = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
- struct tst_kconfig_var marker = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
- struct tst_kern_exv kvers_marker_migration[] = {
- /* RHEL9 kernel has patch 6c287605f and 679d10331 since 5.14.0-179 */
- { "RHEL9", "5.14.0-179" },
- { NULL, NULL},
- };
-
- struct tst_kern_exv kvers_marker_migration2[] = {
- /* RHEL9 kernel has patch ca92ea3dc5a since 5.14.0-441 */
- { "RHEL9", "5.14.0-441" },
- { NULL, NULL},
- };
-
- struct tst_kern_exv kvers_device[] = {
- /* SLES12-SP4 has patch 5042db43cc26 since 4.12.14-5.5 */
- { "SLES", "4.12.14-5.5" },
- { NULL, NULL},
- };
-
- tst_kconfig_read(&migration, 1);
- tst_kconfig_read(&memory, 1);
- tst_kconfig_read(&device, 1);
- tst_kconfig_read(&marker, 1);
-
- if (migration.choice == 'y') {
- if (tst_kvercmp2(5, 19, 0, kvers_marker_migration) < 0)
- swp_migration_num = 2;
- else
- swp_migration_num = 3;
- }
-
- if (memory.choice == 'y')
- swp_hwpoison_num = 1;
-
- if (device.choice == 'y') {
- if (tst_kvercmp2(4, 14, 0, kvers_device) >= 0)
- swp_device_num = 2;
- if (tst_kvercmp(5, 14, 0) >= 0)
- swp_device_num = 4;
- if (tst_kvercmp(6, 15, 0) >= 0)
- swp_device_num = 3;
- }
-
- if ((marker.choice == 'y' &&
- tst_kvercmp2(5, 19, 0, kvers_marker_migration) >= 0)
- || tst_kvercmp2(6, 2, 0, kvers_marker_migration2) >= 0) {
- swp_pte_marker_num = 1;
- }
-
- if ((tst_kvercmp(5, 19, 0) >= 0) && (tst_kvercmp(6, 2, 0) < 0))
- swp_swapin_error_num = 1;
-
- return DEFAULT_MAX_SWAPFILE - swp_migration_num - swp_hwpoison_num
- - swp_device_num - swp_pte_marker_num - swp_swapin_error_num;
-}
-
int tst_count_swaps(void)
{
FILE *fp;
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread