* [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api
@ 2023-12-05 6:16 Yang Xu
2023-12-05 6:16 ` [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code Yang Xu
` (3 more replies)
0 siblings, 4 replies; 22+ messages in thread
From: Yang Xu @ 2023-12-05 6:16 UTC (permalink / raw)
To: ltp
Current, the kernel constant MAX_SWAPFILES value is calculated as below
------------------------------------
//#ifdef CONFIG_DEVICE_PRIVATE
//#define SWP_DEVICE_NUM 4
//#else
//#define SWP_DEVICE_NUM 0
//#endif
//#ifdef CONFIG_MIGRATION
//#define SWP_MIGRATION_NUM 3
//#else
//#define SWP_MIGRATION_NUM 0
//#ifdef CONFIG_MEMORY_FAILURE
//#define SWP_HWPOISON_NUM 1
//#else
//#define SWP_HWPOISON_NUM 0
//#endif
//#define SWP_PTE_MARKER_NUM 1
//#define MAX_SWAPFILES_SHIFT 5
//#define MAX_SWAPFILES \
// ((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
// SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
// SWP_PTE_MARKER_NUM)
------------------------------------
Also, man-pages missed something after 5.14 kernel. I have sent two patches to
add it.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/libswap.h | 6 ++++++
libs/libltpswap/libswap.c | 41 +++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/include/libswap.h b/include/libswap.h
index d4b5301a5..2cab1047d 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -21,4 +21,10 @@ int make_swapfile(const char *swapfile, int safe);
* we are testing on.
*/
void is_swap_supported(const char *filename);
+
+/*
+ * Get kernel constant MAX_SWAPFILES value
+ */
+unsigned int get_maxswapfiles(void);
+
#endif /* __LIBSWAP_H__ */
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index a4427736f..54317c627 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -11,6 +11,7 @@
#include "tst_test.h"
#include "libswap.h"
#include "lapi/syscalls.h"
+#include "tst_kconfig.h"
/*
* Make a swap file
@@ -63,3 +64,43 @@ void is_swap_supported(const char *filename)
if (TST_RET == -1)
tst_brk(TFAIL | TTERRNO, "swapoff on %s failed", fstype);
}
+
+/*
+ * Get kernel constant MAX_SWAPFILES value
+ */
+unsigned int get_maxswapfiles(void)
+{
+ unsigned int max_swapfile = 32;
+ unsigned int swp_migration_num = 0, swp_hwpoison_num = 0, swp_device_num = 0, swp_pte_marker_num = 0;
+ struct tst_kconfig_var migration_kconfig = TST_KCONFIG_INIT("CONFIG_MIGRATION");
+ struct tst_kconfig_var memory_kconfig = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
+ struct tst_kconfig_var device_kconfig = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
+ struct tst_kconfig_var marker_kconfig = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
+
+ tst_kconfig_read(&migration_kconfig, 1);
+ tst_kconfig_read(&memory_kconfig, 1);
+ tst_kconfig_read(&device_kconfig, 1);
+ tst_kconfig_read(&marker_kconfig, 1);
+
+ if (migration_kconfig.choice == 'y') {
+ if (tst_kvercmp(5, 19, 0) < 0)
+ swp_migration_num = 2;
+ else
+ swp_migration_num = 3;
+ }
+
+ if (memory_kconfig.choice == 'y')
+ swp_hwpoison_num = 1;
+
+ if (device_kconfig.choice == 'y') {
+ if (tst_kvercmp(5, 14, 0) >= 0)
+ swp_device_num = 4;
+ }
+
+ if (marker_kconfig.choice == 'y') {
+ if (tst_kvercmp(5, 19, 0) < 0)
+ swp_pte_marker_num = 1;
+ }
+
+ return max_swapfile - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
+}
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code
2023-12-05 6:16 [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api Yang Xu
@ 2023-12-05 6:16 ` Yang Xu
2023-12-22 1:39 ` Yang Xu (Fujitsu)
2023-12-05 6:16 ` [LTP] [PATCH 3/3] swaponoff.h: Remove useless header Yang Xu
` (2 subsequent siblings)
3 siblings, 1 reply; 22+ messages in thread
From: Yang Xu @ 2023-12-05 6:16 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/swapon/swapon03.c | 47 +++------------------
1 file changed, 6 insertions(+), 41 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index dc633ebc6..744fca3d1 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -19,14 +19,12 @@
#include "tst_test.h"
#include "lapi/syscalls.h"
-#include "swaponoff.h"
#include "libswap.h"
static int setup_swap(void);
static int clean_swap(void);
static int check_and_swapoff(const char *filename);
-
-static int swapfiles;
+static int swapfiles, max_swapfiles;
int testfiles = 3;
static struct swap_testfile_t {
@@ -57,47 +55,13 @@ static void verify_swapon(void)
"(%d). System reboot recommended.",
expected_errno);
} else {
- /* Probably the system supports MAX_SWAPFILES > 30,
- * let's try with MAX_SWAPFILES == 32 */
-
- /* Call swapon sys call once again for 32
- * now we can't receive an error */
- TEST(tst_syscall(__NR_swapon, swap_testfiles[1].filename, 0));
-
- /* Check return code (now we're expecting success) */
- if (TST_RET < 0) {
- tst_res(TFAIL | TTERRNO,
- "swapon(2) got an unexpected failure");
- } else {
- /* Call swapon sys call once again for 33
- * now we have to receive an error */
- TEST(tst_syscall(__NR_swapon, swap_testfiles[2].filename, 0));
-
- /* Check return code (should be an error) */
- if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
- tst_res(TPASS,
- "swapon(2) got expected failure;"
- " Got errno = %d, probably your"
- " MAX_SWAPFILES is 32",
- expected_errno);
- } else {
- tst_res(TFAIL,
- "swapon(2) failed to produce"
- " expected error: %d, got %s."
- " System reboot after execution of LTP"
- " test suite is recommended.",
- expected_errno, strerror(TST_ERR));
- }
- }
+ tst_res(TFAIL, "swapon(2) succeeded unexpectedly");
}
if (clean_swap() < 0)
tst_brk(TBROK, "Cleanup failed, quitting the test");
}
-/*
- * Create 33 and activate 30 swapfiles.
- */
static int setup_swap(void)
{
pid_t pid;
@@ -139,9 +103,10 @@ static int setup_swap(void)
tst_brk(TFAIL, "Failed to find existing number of swapfiles");
/* Determine how many more files are to be created */
- swapfiles = MAX_SWAPFILES - swapfiles;
- if (swapfiles > MAX_SWAPFILES)
- swapfiles = MAX_SWAPFILES;
+ max_swapfiles = (int)get_maxswapfiles();
+ swapfiles = max_swapfiles - swapfiles;
+ if (swapfiles > max_swapfiles)
+ swapfiles = max_swapfiles;
pid = SAFE_FORK();
if (pid == 0) {
/*create and turn on remaining swapfiles */
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH 3/3] swaponoff.h: Remove useless header
2023-12-05 6:16 [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api Yang Xu
2023-12-05 6:16 ` [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code Yang Xu
@ 2023-12-05 6:16 ` Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
2023-12-15 6:04 ` [LTP] [PATCH 1/3] " Yang Xu (Fujitsu)
2024-01-03 14:53 ` Cyril Hrubis
3 siblings, 1 reply; 22+ messages in thread
From: Yang Xu @ 2023-12-05 6:16 UTC (permalink / raw)
To: ltp
Since we have use get_maxswapfiles() api in swapon03.c, so this header
is useless and can be removed safely.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/swapon/swaponoff.h | 8 --------
1 file changed, 8 deletions(-)
delete mode 100644 testcases/kernel/syscalls/swapon/swaponoff.h
diff --git a/testcases/kernel/syscalls/swapon/swaponoff.h b/testcases/kernel/syscalls/swapon/swaponoff.h
deleted file mode 100644
index 900761bda..000000000
--- a/testcases/kernel/syscalls/swapon/swaponoff.h
+++ /dev/null
@@ -1,8 +0,0 @@
-
-#ifndef __SWAP_ON_OFF_H_
-#define __SWAP_ON_OFF_H_
-
-#include <linux/version.h>
-#define MAX_SWAPFILES 30
-
-#endif
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api
2023-12-05 6:16 [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api Yang Xu
2023-12-05 6:16 ` [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code Yang Xu
2023-12-05 6:16 ` [LTP] [PATCH 3/3] swaponoff.h: Remove useless header Yang Xu
@ 2023-12-15 6:04 ` Yang Xu (Fujitsu)
2024-01-03 14:53 ` Cyril Hrubis
3 siblings, 0 replies; 22+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-12-15 6:04 UTC (permalink / raw)
To: ltp@lists.linux.it
Hi all,
Ping
Best Regards
Yang Xu
> Current, the kernel constant MAX_SWAPFILES value is calculated as below
> ------------------------------------
> //#ifdef CONFIG_DEVICE_PRIVATE
> //#define SWP_DEVICE_NUM 4
> //#else
> //#define SWP_DEVICE_NUM 0
> //#endif
>
> //#ifdef CONFIG_MIGRATION
> //#define SWP_MIGRATION_NUM 3
> //#else
> //#define SWP_MIGRATION_NUM 0
>
> //#ifdef CONFIG_MEMORY_FAILURE
> //#define SWP_HWPOISON_NUM 1
> //#else
> //#define SWP_HWPOISON_NUM 0
> //#endif
>
> //#define SWP_PTE_MARKER_NUM 1
> //#define MAX_SWAPFILES_SHIFT 5
>
> //#define MAX_SWAPFILES \
> // ((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
> // SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
> // SWP_PTE_MARKER_NUM)
> ------------------------------------
>
> Also, man-pages missed something after 5.14 kernel. I have sent two patches to
> add it.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> include/libswap.h | 6 ++++++
> libs/libltpswap/libswap.c | 41 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 47 insertions(+)
>
> diff --git a/include/libswap.h b/include/libswap.h
> index d4b5301a5..2cab1047d 100644
> --- a/include/libswap.h
> +++ b/include/libswap.h
> @@ -21,4 +21,10 @@ int make_swapfile(const char *swapfile, int safe);
> * we are testing on.
> */
> void is_swap_supported(const char *filename);
> +
> +/*
> + * Get kernel constant MAX_SWAPFILES value
> + */
> +unsigned int get_maxswapfiles(void);
> +
> #endif /* __LIBSWAP_H__ */
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index a4427736f..54317c627 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -11,6 +11,7 @@
> #include "tst_test.h"
> #include "libswap.h"
> #include "lapi/syscalls.h"
> +#include "tst_kconfig.h"
>
> /*
> * Make a swap file
> @@ -63,3 +64,43 @@ void is_swap_supported(const char *filename)
> if (TST_RET == -1)
> tst_brk(TFAIL | TTERRNO, "swapoff on %s failed", fstype);
> }
> +
> +/*
> + * Get kernel constant MAX_SWAPFILES value
> + */
> +unsigned int get_maxswapfiles(void)
> +{
> + unsigned int max_swapfile = 32;
> + unsigned int swp_migration_num = 0, swp_hwpoison_num = 0, swp_device_num = 0, swp_pte_marker_num = 0;
> + struct tst_kconfig_var migration_kconfig = TST_KCONFIG_INIT("CONFIG_MIGRATION");
> + struct tst_kconfig_var memory_kconfig = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
> + struct tst_kconfig_var device_kconfig = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
> + struct tst_kconfig_var marker_kconfig = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
> +
> + tst_kconfig_read(&migration_kconfig, 1);
> + tst_kconfig_read(&memory_kconfig, 1);
> + tst_kconfig_read(&device_kconfig, 1);
> + tst_kconfig_read(&marker_kconfig, 1);
> +
> + if (migration_kconfig.choice == 'y') {
> + if (tst_kvercmp(5, 19, 0) < 0)
> + swp_migration_num = 2;
> + else
> + swp_migration_num = 3;
> + }
> +
> + if (memory_kconfig.choice == 'y')
> + swp_hwpoison_num = 1;
> +
> + if (device_kconfig.choice == 'y') {
> + if (tst_kvercmp(5, 14, 0) >= 0)
> + swp_device_num = 4;
> + }
> +
> + if (marker_kconfig.choice == 'y') {
> + if (tst_kvercmp(5, 19, 0) < 0)
> + swp_pte_marker_num = 1;
> + }
> +
> + return max_swapfile - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
> +}
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code
2023-12-05 6:16 ` [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code Yang Xu
@ 2023-12-22 1:39 ` Yang Xu (Fujitsu)
2023-12-22 11:42 ` Petr Vorel
0 siblings, 1 reply; 22+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-12-22 1:39 UTC (permalink / raw)
To: pvorel@suse.cz, liwang@redhat.com; +Cc: ltp@lists.linux.it
Hi Li, Petr
I am writting v2 patch that introduce another libltpswap api named
as get_used_swapfiles like we did in ipc library.
But I found libltpswap and swapon/swapoff cases all use swapon/swapff
syscall directly instead of glibc wrapper. IMO, on old glibc/other libc
doesn't support this wrapper so it use syscall directly. Can I replace
them by glibc wrapper directly?
Best Regards
Yang Xu
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> testcases/kernel/syscalls/swapon/swapon03.c | 47 +++------------------
> 1 file changed, 6 insertions(+), 41 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
> index dc633ebc6..744fca3d1 100644
> --- a/testcases/kernel/syscalls/swapon/swapon03.c
> +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> @@ -19,14 +19,12 @@
>
> #include "tst_test.h"
> #include "lapi/syscalls.h"
> -#include "swaponoff.h"
> #include "libswap.h"
>
> static int setup_swap(void);
> static int clean_swap(void);
> static int check_and_swapoff(const char *filename);
> -
> -static int swapfiles;
> +static int swapfiles, max_swapfiles;
>
> int testfiles = 3;
> static struct swap_testfile_t {
> @@ -57,47 +55,13 @@ static void verify_swapon(void)
> "(%d). System reboot recommended.",
> expected_errno);
> } else {
> - /* Probably the system supports MAX_SWAPFILES > 30,
> - * let's try with MAX_SWAPFILES == 32 */
> -
> - /* Call swapon sys call once again for 32
> - * now we can't receive an error */
> - TEST(tst_syscall(__NR_swapon, swap_testfiles[1].filename, 0));
> -
> - /* Check return code (now we're expecting success) */
> - if (TST_RET < 0) {
> - tst_res(TFAIL | TTERRNO,
> - "swapon(2) got an unexpected failure");
> - } else {
> - /* Call swapon sys call once again for 33
> - * now we have to receive an error */
> - TEST(tst_syscall(__NR_swapon, swap_testfiles[2].filename, 0));
> -
> - /* Check return code (should be an error) */
> - if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
> - tst_res(TPASS,
> - "swapon(2) got expected failure;"
> - " Got errno = %d, probably your"
> - " MAX_SWAPFILES is 32",
> - expected_errno);
> - } else {
> - tst_res(TFAIL,
> - "swapon(2) failed to produce"
> - " expected error: %d, got %s."
> - " System reboot after execution of LTP"
> - " test suite is recommended.",
> - expected_errno, strerror(TST_ERR));
> - }
> - }
> + tst_res(TFAIL, "swapon(2) succeeded unexpectedly");
> }
>
> if (clean_swap() < 0)
> tst_brk(TBROK, "Cleanup failed, quitting the test");
> }
>
> -/*
> - * Create 33 and activate 30 swapfiles.
> - */
> static int setup_swap(void)
> {
> pid_t pid;
> @@ -139,9 +103,10 @@ static int setup_swap(void)
> tst_brk(TFAIL, "Failed to find existing number of swapfiles");
>
> /* Determine how many more files are to be created */
> - swapfiles = MAX_SWAPFILES - swapfiles;
> - if (swapfiles > MAX_SWAPFILES)
> - swapfiles = MAX_SWAPFILES;
> + max_swapfiles = (int)get_maxswapfiles();
> + swapfiles = max_swapfiles - swapfiles;
> + if (swapfiles > max_swapfiles)
> + swapfiles = max_swapfiles;
> pid = SAFE_FORK();
> if (pid == 0) {
> /*create and turn on remaining swapfiles */
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api
2023-12-05 6:16 ` [LTP] [PATCH 3/3] swaponoff.h: Remove useless header Yang Xu
@ 2023-12-22 5:00 ` Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 2/7] libltpswap: alter get_used_swapfiles api Yang Xu
` (8 more replies)
0 siblings, 9 replies; 22+ messages in thread
From: Yang Xu @ 2023-12-22 5:00 UTC (permalink / raw)
To: ltp
Current, the kernel constant MAX_SWAPFILES value is calculated as below
------------------------------------
//#ifdef CONFIG_DEVICE_PRIVATE
//#define SWP_DEVICE_NUM 4
//#else
//#define SWP_DEVICE_NUM 0
//#endif
//#ifdef CONFIG_MIGRATION
//#define SWP_MIGRATION_NUM 3
//#else
//#define SWP_MIGRATION_NUM 0
//#ifdef CONFIG_MEMORY_FAILURE
//#define SWP_HWPOISON_NUM 1
//#else
//#define SWP_HWPOISON_NUM 0
//#endif
//#define SWP_PTE_MARKER_NUM 1
//#define MAX_SWAPFILES_SHIFT 5
//#define MAX_SWAPFILES \
// ((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
// SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
// SWP_PTE_MARKER_NUM)
------------------------------------
Also, man-pages missed something after 5.14 kernel. I have sent two patches[1][2] to
add it. The kernel patches modify this kernel constant in[3][4][5][6].
[1]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=26f3ec74e
[2]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=6bf3937fc
[3]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=5042db43cc
[4]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=b756a3b5e
[5]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=679d10331
[6]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=6c287605f
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/libswap.h | 6 ++++++
libs/libltpswap/libswap.c | 44 +++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/include/libswap.h b/include/libswap.h
index d4b5301a5..2cab1047d 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -21,4 +21,10 @@ int make_swapfile(const char *swapfile, int safe);
* we are testing on.
*/
void is_swap_supported(const char *filename);
+
+/*
+ * Get kernel constant MAX_SWAPFILES value
+ */
+unsigned int get_maxswapfiles(void);
+
#endif /* __LIBSWAP_H__ */
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index d014325e5..658ecede7 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -11,6 +11,8 @@
#include "tst_test.h"
#include "libswap.h"
#include "lapi/syscalls.h"
+#include "tst_kconfig.h"
+#include "tst_safe_stdio.h"
/*
* Make a swap file
@@ -65,3 +67,45 @@ void is_swap_supported(const char *filename)
if (TST_RET == -1)
tst_brk(TFAIL | TTERRNO, "swapoff on %s failed", fstype);
}
+
+/*
+ * Get kernel constant MAX_SWAPFILES value
+ */
+unsigned int get_maxswapfiles(void)
+{
+ unsigned int max_swapfile = 32;
+ unsigned int swp_migration_num = 0, swp_hwpoison_num = 0, swp_device_num = 0, swp_pte_marker_num = 0;
+ struct tst_kconfig_var migration_kconfig = TST_KCONFIG_INIT("CONFIG_MIGRATION");
+ struct tst_kconfig_var memory_kconfig = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
+ struct tst_kconfig_var device_kconfig = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
+ struct tst_kconfig_var marker_kconfig = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
+
+ tst_kconfig_read(&migration_kconfig, 1);
+ tst_kconfig_read(&memory_kconfig, 1);
+ tst_kconfig_read(&device_kconfig, 1);
+ tst_kconfig_read(&marker_kconfig, 1);
+
+ if (migration_kconfig.choice == 'y') {
+ if (tst_kvercmp(5, 19, 0) < 0)
+ swp_migration_num = 2;
+ else
+ swp_migration_num = 3;
+ }
+
+ if (memory_kconfig.choice == 'y')
+ swp_hwpoison_num = 1;
+
+ if (device_kconfig.choice == 'y') {
+ if (tst_kvercmp(4, 14, 0) >= 0)
+ swp_device_num = 2;
+ if (tst_kvercmp(5, 14, 0) >= 0)
+ swp_device_num = 4;
+ }
+
+ if (marker_kconfig.choice == 'y') {
+ if (tst_kvercmp(5, 19, 0) >= 0)
+ swp_pte_marker_num = 1;
+ }
+
+ return max_swapfile - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
+}
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2 2/7] libltpswap: alter get_used_swapfiles api
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
@ 2023-12-22 5:00 ` Yang Xu
2024-01-03 15:30 ` Cyril Hrubis
2023-12-22 5:00 ` [LTP] [PATCH v2 3/7] syscalls/swapon03: use get_maxswapfiles() and GET_USED_SWAPFILES() api Yang Xu
` (7 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Yang Xu @ 2023-12-22 5:00 UTC (permalink / raw)
To: ltp
Like we count the ipc resouce total, we can also add a similar api
for swapfiles, so we can use it for swapon03 case.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/libswap.h | 7 +++++++
libs/libltpswap/libswap.c | 26 ++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/libswap.h b/include/libswap.h
index 2cab1047d..7f8df1032 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -27,4 +27,11 @@ void is_swap_supported(const char *filename);
*/
unsigned int get_maxswapfiles(void);
+/*
+ * Get the used swapfiles number
+ */
+int get_used_swapfiles(const char *file, const int lineno);
+#define GET_USED_SWAPFILES() \
+ get_used_swapfiles(__FILE__, __LINE__)
+
#endif /* __LIBSWAP_H__ */
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 658ecede7..e10a6f5b2 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -14,6 +14,8 @@
#include "tst_kconfig.h"
#include "tst_safe_stdio.h"
+#define BUFSIZE 1024
+
/*
* Make a swap file
*/
@@ -109,3 +111,27 @@ unsigned int get_maxswapfiles(void)
return max_swapfile - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
}
+
+/*
+ * Get the used swapfiles number
+ */
+int get_used_swapfiles(const char *file, const int lineno)
+{
+ FILE *fp;
+ int used = -1;
+ char buf[BUFSIZE];
+
+ fp = safe_fopen(file, lineno, NULL, "/proc/swaps", "r");
+
+ while (fgets(buf, BUFSIZE, fp) != NULL)
+ used++;
+
+ fclose(fp);
+
+ if (used < 0) {
+ tst_brk(TBROK, "can't read /proc/swaps to get used swapfiles resource total "
+ "at %s:%d", file, lineno);
+ }
+
+ return used;
+}
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2 3/7] syscalls/swapon03: use get_maxswapfiles() and GET_USED_SWAPFILES() api
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 2/7] libltpswap: alter get_used_swapfiles api Yang Xu
@ 2023-12-22 5:00 ` Yang Xu
2024-01-03 15:34 ` Cyril Hrubis
2023-12-22 5:00 ` [LTP] [PATCH v2 4/7] swaponoff.h: Remove useless header Yang Xu
` (6 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Yang Xu @ 2023-12-22 5:00 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/swapon/swapon03.c | 40 ++++-----------------
1 file changed, 6 insertions(+), 34 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index dc633ebc6..a553dd485 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -19,7 +19,6 @@
#include "tst_test.h"
#include "lapi/syscalls.h"
-#include "swaponoff.h"
#include "libswap.h"
static int setup_swap(void);
@@ -101,47 +100,20 @@ static void verify_swapon(void)
static int setup_swap(void)
{
pid_t pid;
- int j, fd;
+ int j, max_swapfiles, used_swapfiles;
int status;
int res = 0;
char filename[FILENAME_MAX];
- char buf[BUFSIZ + 1];
-
- /* Find out how many swapfiles (1 line per entry) already exist */
- swapfiles = 0;
if (seteuid(0) < 0)
tst_brk(TFAIL | TERRNO, "Failed to call seteuid");
- /* This includes the first (header) line */
- if ((fd = open("/proc/swaps", O_RDONLY)) == -1) {
- tst_brk(TFAIL | TERRNO,
- "Failed to find out existing number of swap files");
- }
- do {
- char *p = buf;
- res = read(fd, buf, BUFSIZ);
- if (res < 0) {
- tst_brk(TFAIL | TERRNO,
- "Failed to find out existing number of swap files");
- }
- buf[res] = '\0';
- while ((p = strchr(p, '\n'))) {
- p++;
- swapfiles++;
- }
- } while (BUFSIZ <= res);
- close(fd);
- if (swapfiles)
- swapfiles--; /* don't count the /proc/swaps header */
-
- if (swapfiles < 0)
- tst_brk(TFAIL, "Failed to find existing number of swapfiles");
-
/* Determine how many more files are to be created */
- swapfiles = MAX_SWAPFILES - swapfiles;
- if (swapfiles > MAX_SWAPFILES)
- swapfiles = MAX_SWAPFILES;
+ max_swapfiles = (int)get_maxswapfiles();
+ used_swapfiles = GET_USED_SWAPFILES();
+ swapfiles = max_swapfiles - used_swapfiles;
+ if (swapfiles > max_swapfiles)
+ swapfiles = max_swapfiles;
pid = SAFE_FORK();
if (pid == 0) {
/*create and turn on remaining swapfiles */
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2 4/7] swaponoff.h: Remove useless header
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 2/7] libltpswap: alter get_used_swapfiles api Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 3/7] syscalls/swapon03: use get_maxswapfiles() and GET_USED_SWAPFILES() api Yang Xu
@ 2023-12-22 5:00 ` Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu
` (5 subsequent siblings)
8 siblings, 0 replies; 22+ messages in thread
From: Yang Xu @ 2023-12-22 5:00 UTC (permalink / raw)
To: ltp
Since we have use get_maxswapfiles() api in swapon03.c, so this header
is useless and can be removed safely.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/swapon/swaponoff.h | 8 --------
1 file changed, 8 deletions(-)
delete mode 100644 testcases/kernel/syscalls/swapon/swaponoff.h
diff --git a/testcases/kernel/syscalls/swapon/swaponoff.h b/testcases/kernel/syscalls/swapon/swaponoff.h
deleted file mode 100644
index 900761bda..000000000
--- a/testcases/kernel/syscalls/swapon/swaponoff.h
+++ /dev/null
@@ -1,8 +0,0 @@
-
-#ifndef __SWAP_ON_OFF_H_
-#define __SWAP_ON_OFF_H_
-
-#include <linux/version.h>
-#define MAX_SWAPFILES 30
-
-#endif
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
` (2 preceding siblings ...)
2023-12-22 5:00 ` [LTP] [PATCH v2 4/7] swaponoff.h: Remove useless header Yang Xu
@ 2023-12-22 5:00 ` Yang Xu
2024-01-03 15:40 ` Cyril Hrubis
2023-12-22 5:00 ` [LTP] [PATCH v2 6/7] syscalls/swapon03: Simply this case Yang Xu
` (4 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Yang Xu @ 2023-12-22 5:00 UTC (permalink / raw)
To: ltp
It seems this section doesn't affect anything, btw it is useless,
so remove it.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/swapon/Makefile | 5 -----
1 file changed, 5 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/Makefile b/testcases/kernel/syscalls/swapon/Makefile
index 53c795090..6954112a8 100644
--- a/testcases/kernel/syscalls/swapon/Makefile
+++ b/testcases/kernel/syscalls/swapon/Makefile
@@ -1,11 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) International Business Machines Corp., 2001
-NEEDSPECIAL := $(shell echo MAX_SWAPFILES | $(CC) -E -xc -include linux/swap.h 2>/dev/null - | tail -n 1 | grep 32; echo $?)
-ifneq ($(strip $(NEEDSPECIAL)),)
-export CFLAGS += -DOLDER_DISTRO_RELEASE
-endif
-
top_srcdir ?= ../../../..
LTPLIBS = ltpswap
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2 6/7] syscalls/swapon03: Simply this case
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
` (3 preceding siblings ...)
2023-12-22 5:00 ` [LTP] [PATCH v2 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu
@ 2023-12-22 5:00 ` Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 7/7] Add fallback for RHEL9 Yang Xu
` (3 subsequent siblings)
8 siblings, 0 replies; 22+ messages in thread
From: Yang Xu @ 2023-12-22 5:00 UTC (permalink / raw)
To: ltp
By moving swapfile create stage from verify_swaopon and
test EPERM error more accurate. Also use glibc wrapper by
using swapon/swapoff instead of call syscall number directly
because glibc/musl/binoic also support them since long time ago.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/swapon/swapon03.c | 111 +++-----------------
1 file changed, 16 insertions(+), 95 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index a553dd485..3f3fa7a54 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -16,93 +16,27 @@
#include <errno.h>
#include <stdlib.h>
#include <sys/wait.h>
-
+#include <sys/swap.h>
#include "tst_test.h"
-#include "lapi/syscalls.h"
#include "libswap.h"
+#define TESTFILE "testfile"
+
static int setup_swap(void);
static int clean_swap(void);
static int check_and_swapoff(const char *filename);
-
static int swapfiles;
-int testfiles = 3;
-static struct swap_testfile_t {
- char *filename;
-} swap_testfiles[] = {
- {"firstswapfile"},
- {"secondswapfile"},
- {"thirdswapfile"}
-};
-
-int expected_errno = EPERM;
-
static void verify_swapon(void)
{
- if (setup_swap() < 0) {
- clean_swap();
- tst_brk(TBROK, "Setup failed, quitting the test");
- }
-
- TEST(tst_syscall(__NR_swapon, swap_testfiles[0].filename, 0));
-
- if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
- tst_res(TPASS, "swapon(2) got expected failure (%d),",
- expected_errno);
- } else if (TST_RET < 0) {
- tst_res(TFAIL | TTERRNO,
- "swapon(2) failed to produce expected error "
- "(%d). System reboot recommended.",
- expected_errno);
- } else {
- /* Probably the system supports MAX_SWAPFILES > 30,
- * let's try with MAX_SWAPFILES == 32 */
-
- /* Call swapon sys call once again for 32
- * now we can't receive an error */
- TEST(tst_syscall(__NR_swapon, swap_testfiles[1].filename, 0));
-
- /* Check return code (now we're expecting success) */
- if (TST_RET < 0) {
- tst_res(TFAIL | TTERRNO,
- "swapon(2) got an unexpected failure");
- } else {
- /* Call swapon sys call once again for 33
- * now we have to receive an error */
- TEST(tst_syscall(__NR_swapon, swap_testfiles[2].filename, 0));
-
- /* Check return code (should be an error) */
- if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
- tst_res(TPASS,
- "swapon(2) got expected failure;"
- " Got errno = %d, probably your"
- " MAX_SWAPFILES is 32",
- expected_errno);
- } else {
- tst_res(TFAIL,
- "swapon(2) failed to produce"
- " expected error: %d, got %s."
- " System reboot after execution of LTP"
- " test suite is recommended.",
- expected_errno, strerror(TST_ERR));
- }
- }
- }
-
- if (clean_swap() < 0)
- tst_brk(TBROK, "Cleanup failed, quitting the test");
+ TST_EXP_FAIL(swapon(TESTFILE, 0), EPERM, "swapon(%s, 0)", TESTFILE);
}
-/*
- * Create 33 and activate 30 swapfiles.
- */
static int setup_swap(void)
{
pid_t pid;
int j, max_swapfiles, used_swapfiles;
int status;
- int res = 0;
char filename[FILENAME_MAX];
if (seteuid(0) < 0)
@@ -130,16 +64,7 @@ static int setup_swap(void)
make_swapfile(filename, 0);
/* turn on the swap file */
- res = tst_syscall(__NR_swapon, filename, 0);
- if (res != 0) {
- if (errno == EPERM) {
- printf("Successfully created %d swapfiles\n", j);
- break;
- } else {
- printf("Failed to create swapfile: %s\n", filename);
- exit(1);
- }
- }
+ TST_EXP_PASS_SILENT(swapon(filename, 0));
}
exit(0);
} else
@@ -148,9 +73,8 @@ static int setup_swap(void)
if (WEXITSTATUS(status))
tst_brk(TFAIL, "Failed to setup swaps");
- /* Create all needed extra swapfiles for testing */
- for (j = 0; j < testfiles; j++)
- make_swapfile(swap_testfiles[j].filename, 0);
+ tst_res(TINFO, "Successfully created %d swapfiles", swapfiles);
+ make_swapfile(TESTFILE, 0);
return 0;
}
@@ -178,12 +102,9 @@ static int clean_swap(void)
}
}
- for (j = 0; j < testfiles; j++) {
- if (check_and_swapoff(swap_testfiles[j].filename) != 0) {
- tst_res(TWARN, "Failed to turn off swap file %s.",
- swap_testfiles[j].filename);
- return -1;
- }
+ if (check_and_swapoff("testfile") != 0) {
+ tst_res(TWARN, "Failed to turn off swap file testfile");
+ return -1;
}
return 0;
@@ -201,20 +122,15 @@ static int check_and_swapoff(const char *filename)
"grep -q '%s.*file' /proc/swaps", filename) < 0) {
tst_res(TWARN, "sprintf() failed to create the command string");
} else {
-
rc = 0;
-
if (system(cmd_buffer) == 0) {
-
/* now we need to swapoff the file */
- if (tst_syscall(__NR_swapoff, filename) != 0) {
-
+ if (swapoff(filename) != 0) {
tst_res(TWARN, "Failed to turn off swap "
"file. system reboot after "
"execution of LTP test suite "
"is recommended");
rc = -1;
-
}
}
@@ -229,6 +145,11 @@ static void setup(void)
tst_brk(TCONF, "swap not supported by kernel");
is_swap_supported("./tstswap");
+
+ if (setup_swap() < 0) {
+ clean_swap();
+ tst_brk(TBROK, "Setup failed, quitting the test");
+ }
}
static void cleanup(void)
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [LTP] [PATCH v2 7/7] Add fallback for RHEL9
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
` (4 preceding siblings ...)
2023-12-22 5:00 ` [LTP] [PATCH v2 6/7] syscalls/swapon03: Simply this case Yang Xu
@ 2023-12-22 5:00 ` Yang Xu
2024-02-05 18:37 ` Petr Vorel
2024-01-02 2:07 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu (Fujitsu)
` (2 subsequent siblings)
8 siblings, 1 reply; 22+ messages in thread
From: Yang Xu @ 2023-12-22 5:00 UTC (permalink / raw)
To: ltp
Since device number patch and pte number patch have been backported into
RHEL9, we should add fallback for this distro.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
libs/libltpswap/libswap.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index e10a6f5b2..8c7729b8b 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -12,6 +12,7 @@
#include "libswap.h"
#include "lapi/syscalls.h"
#include "tst_kconfig.h"
+#include "tst_kvercmp.h"
#include "tst_safe_stdio.h"
#define BUFSIZE 1024
@@ -81,6 +82,11 @@ unsigned int get_maxswapfiles(void)
struct tst_kconfig_var memory_kconfig = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
struct tst_kconfig_var device_kconfig = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
struct tst_kconfig_var marker_kconfig = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
+ struct tst_kern_exv kvers[] = {
+ /* RHEL9 kernel has patch 6c287605f and 679d10331 since 5.14.0-179 */
+ { "RHEL9", "5.14.0-179" },
+ { NULL, NULL},
+ };
tst_kconfig_read(&migration_kconfig, 1);
tst_kconfig_read(&memory_kconfig, 1);
@@ -88,7 +94,7 @@ unsigned int get_maxswapfiles(void)
tst_kconfig_read(&marker_kconfig, 1);
if (migration_kconfig.choice == 'y') {
- if (tst_kvercmp(5, 19, 0) < 0)
+ if (tst_kvercmp2(5, 19, 0, kvers) < 0)
swp_migration_num = 2;
else
swp_migration_num = 3;
@@ -105,7 +111,7 @@ unsigned int get_maxswapfiles(void)
}
if (marker_kconfig.choice == 'y') {
- if (tst_kvercmp(5, 19, 0) >= 0)
+ if (tst_kvercmp2(5, 19, 0, kvers) >= 0)
swp_pte_marker_num = 1;
}
--
2.27.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code
2023-12-22 1:39 ` Yang Xu (Fujitsu)
@ 2023-12-22 11:42 ` Petr Vorel
0 siblings, 0 replies; 22+ messages in thread
From: Petr Vorel @ 2023-12-22 11:42 UTC (permalink / raw)
To: Yang Xu (Fujitsu); +Cc: ltp@lists.linux.it
Hi Xu,
> Hi Li, Petr
> I am writting v2 patch that introduce another libltpswap api named
> as get_used_swapfiles like we did in ipc library.
> But I found libltpswap and swapon/swapoff cases all use swapon/swapff
> syscall directly instead of glibc wrapper. IMO, on old glibc/other libc
> doesn't support this wrapper so it use syscall directly. Can I replace
> them by glibc wrapper directly?
how about use both libc wrapper and raw syscall via .test_variants?
Kind regards,
Petr
> Best Regards
> Yang Xu
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
` (5 preceding siblings ...)
2023-12-22 5:00 ` [LTP] [PATCH v2 7/7] Add fallback for RHEL9 Yang Xu
@ 2024-01-02 2:07 ` Yang Xu (Fujitsu)
2024-01-03 15:35 ` Cyril Hrubis
2024-02-05 18:43 ` Petr Vorel
8 siblings, 0 replies; 22+ messages in thread
From: Yang Xu (Fujitsu) @ 2024-01-02 2:07 UTC (permalink / raw)
To: ltp@lists.linux.it
Hi all,
Ping
Best Regards,
Yang Xu
> Current, the kernel constant MAX_SWAPFILES value is calculated as below
> ------------------------------------
> //#ifdef CONFIG_DEVICE_PRIVATE
> //#define SWP_DEVICE_NUM 4
> //#else
> //#define SWP_DEVICE_NUM 0
> //#endif
>
> //#ifdef CONFIG_MIGRATION
> //#define SWP_MIGRATION_NUM 3
> //#else
> //#define SWP_MIGRATION_NUM 0
>
> //#ifdef CONFIG_MEMORY_FAILURE
> //#define SWP_HWPOISON_NUM 1
> //#else
> //#define SWP_HWPOISON_NUM 0
> //#endif
>
> //#define SWP_PTE_MARKER_NUM 1
> //#define MAX_SWAPFILES_SHIFT 5
>
> //#define MAX_SWAPFILES \
> // ((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
> // SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
> // SWP_PTE_MARKER_NUM)
> ------------------------------------
>
> Also, man-pages missed something after 5.14 kernel. I have sent two patches[1][2] to
> add it. The kernel patches modify this kernel constant in[3][4][5][6].
>
> [1]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=26f3ec74e
> [2]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=6bf3937fc
> [3]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=5042db43cc
> [4]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=b756a3b5e
> [5]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=679d10331
> [6]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=6c287605f
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> include/libswap.h | 6 ++++++
> libs/libltpswap/libswap.c | 44 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 50 insertions(+)
>
> diff --git a/include/libswap.h b/include/libswap.h
> index d4b5301a5..2cab1047d 100644
> --- a/include/libswap.h
> +++ b/include/libswap.h
> @@ -21,4 +21,10 @@ int make_swapfile(const char *swapfile, int safe);
> * we are testing on.
> */
> void is_swap_supported(const char *filename);
> +
> +/*
> + * Get kernel constant MAX_SWAPFILES value
> + */
> +unsigned int get_maxswapfiles(void);
> +
> #endif /* __LIBSWAP_H__ */
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index d014325e5..658ecede7 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -11,6 +11,8 @@
> #include "tst_test.h"
> #include "libswap.h"
> #include "lapi/syscalls.h"
> +#include "tst_kconfig.h"
> +#include "tst_safe_stdio.h"
>
> /*
> * Make a swap file
> @@ -65,3 +67,45 @@ void is_swap_supported(const char *filename)
> if (TST_RET == -1)
> tst_brk(TFAIL | TTERRNO, "swapoff on %s failed", fstype);
> }
> +
> +/*
> + * Get kernel constant MAX_SWAPFILES value
> + */
> +unsigned int get_maxswapfiles(void)
> +{
> + unsigned int max_swapfile = 32;
> + unsigned int swp_migration_num = 0, swp_hwpoison_num = 0, swp_device_num = 0, swp_pte_marker_num = 0;
> + struct tst_kconfig_var migration_kconfig = TST_KCONFIG_INIT("CONFIG_MIGRATION");
> + struct tst_kconfig_var memory_kconfig = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
> + struct tst_kconfig_var device_kconfig = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
> + struct tst_kconfig_var marker_kconfig = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
> +
> + tst_kconfig_read(&migration_kconfig, 1);
> + tst_kconfig_read(&memory_kconfig, 1);
> + tst_kconfig_read(&device_kconfig, 1);
> + tst_kconfig_read(&marker_kconfig, 1);
> +
> + if (migration_kconfig.choice == 'y') {
> + if (tst_kvercmp(5, 19, 0) < 0)
> + swp_migration_num = 2;
> + else
> + swp_migration_num = 3;
> + }
> +
> + if (memory_kconfig.choice == 'y')
> + swp_hwpoison_num = 1;
> +
> + if (device_kconfig.choice == 'y') {
> + if (tst_kvercmp(4, 14, 0) >= 0)
> + swp_device_num = 2;
> + if (tst_kvercmp(5, 14, 0) >= 0)
> + swp_device_num = 4;
> + }
> +
> + if (marker_kconfig.choice == 'y') {
> + if (tst_kvercmp(5, 19, 0) >= 0)
> + swp_pte_marker_num = 1;
> + }
> +
> + return max_swapfile - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
> +}
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api
2023-12-05 6:16 [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api Yang Xu
` (2 preceding siblings ...)
2023-12-15 6:04 ` [LTP] [PATCH 1/3] " Yang Xu (Fujitsu)
@ 2024-01-03 14:53 ` Cyril Hrubis
3 siblings, 0 replies; 22+ messages in thread
From: Cyril Hrubis @ 2024-01-03 14:53 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> +unsigned int get_maxswapfiles(void)
> +{
> + unsigned int max_swapfile = 32;
> + unsigned int swp_migration_num = 0, swp_hwpoison_num = 0, swp_device_num = 0, swp_pte_marker_num = 0;
> + struct tst_kconfig_var migration_kconfig = TST_KCONFIG_INIT("CONFIG_MIGRATION");
> + struct tst_kconfig_var memory_kconfig = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
> + struct tst_kconfig_var device_kconfig = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
> + struct tst_kconfig_var marker_kconfig = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
> +
> + tst_kconfig_read(&migration_kconfig, 1);
> + tst_kconfig_read(&memory_kconfig, 1);
> + tst_kconfig_read(&device_kconfig, 1);
> + tst_kconfig_read(&marker_kconfig, 1);
This API is designed so that we can pass an array and parse all values
in a single call. So this should be done as:
struct tst_kconfig_var kconfig[] = {
TST_KCONFIG_INIT("CONFIG_MIGRATION"),
TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE"),
...
};
tst_kconfig_read(kconfig, ARRAY_SIZE(kconfigs));
If you want to have a nice indexes into that array, you can create an
enum as:
enum cfg_idx {
CFG_MIGRATION,
CFG_MEMORY_FAILURE,
...
};
Then use them in the array initialization to make sure they match:
struct tst_kconfig_var kconfig[] = {
[CFG_MIGRATION] = TST_KCONFIG_INIT("CONFIG_MIGRATION"),
...
};
And finally we can use these as:
if (kconfig[CFG_MIGRATION].choice == 'y')
I guess that this is quite cumbersome to use, maybe we need optional
pointer in the tst_kconfig_var structure so we can pass a pointer to a
char that would be set to the value of choice then we could do:
char migration_choice;
struct tst_kconfig_var kconfig[] = {
TST_KCONFIG_INIT2("CONFIG_MIGRATION", &migration_choice),
...
};
if (migration_choice == 'y')
...
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 2/7] libltpswap: alter get_used_swapfiles api
2023-12-22 5:00 ` [LTP] [PATCH v2 2/7] libltpswap: alter get_used_swapfiles api Yang Xu
@ 2024-01-03 15:30 ` Cyril Hrubis
0 siblings, 0 replies; 22+ messages in thread
From: Cyril Hrubis @ 2024-01-03 15:30 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> +/*
> + * Get the used swapfiles number
> + */
> +int get_used_swapfiles(const char *file, const int lineno);
> +#define GET_USED_SWAPFILES() \
> + get_used_swapfiles(__FILE__, __LINE__)
This has to be prefixed with tst_
Also I wouldn't bother withg the macro and passing down FILE and LINE,
it's going to be called just once in the test setup anyways.
So I would just add:
int tst_count_swaps(void);
> #endif /* __LIBSWAP_H__ */
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index 658ecede7..e10a6f5b2 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -14,6 +14,8 @@
> #include "tst_kconfig.h"
> #include "tst_safe_stdio.h"
>
> +#define BUFSIZE 1024
> +
> /*
> * Make a swap file
> */
> @@ -109,3 +111,27 @@ unsigned int get_maxswapfiles(void)
>
> return max_swapfile - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
> }
> +
> +/*
> + * Get the used swapfiles number
> + */
> +int get_used_swapfiles(const char *file, const int lineno)
> +{
> + FILE *fp;
> + int used = -1;
> + char buf[BUFSIZE];
> +
> + fp = safe_fopen(file, lineno, NULL, "/proc/swaps", "r");
I suppose that that we may want to check if the file exists and return 0
if it does not, otherwise we will possibly TBROK here if CONFIG_SWAP is
not set. Or do all the tests that call this function have CONFIG_SWAP in
.needs_kconfig?
> + while (fgets(buf, BUFSIZE, fp) != NULL)
> + used++;
We can do this even simpler:
int c;
while ((c = fgetc(f)) != EOF) {
if (c == '\n')
used++;
}
> + fclose(fp);
> +
> + if (used < 0) {
> + tst_brk(TBROK, "can't read /proc/swaps to get used swapfiles resource total "
> + "at %s:%d", file, lineno);
> + }
> +
> + return used;
> +}
> --
> 2.27.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 3/7] syscalls/swapon03: use get_maxswapfiles() and GET_USED_SWAPFILES() api
2023-12-22 5:00 ` [LTP] [PATCH v2 3/7] syscalls/swapon03: use get_maxswapfiles() and GET_USED_SWAPFILES() api Yang Xu
@ 2024-01-03 15:34 ` Cyril Hrubis
0 siblings, 0 replies; 22+ messages in thread
From: Cyril Hrubis @ 2024-01-03 15:34 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> + max_swapfiles = (int)get_maxswapfiles();
We may as well declare the get_maxswapfiles() to return int instead,
it's not going to overflow signed int anytime soon...
> + used_swapfiles = GET_USED_SWAPFILES();
> + swapfiles = max_swapfiles - used_swapfiles;
> + if (swapfiles > max_swapfiles)
> + swapfiles = max_swapfiles;
> pid = SAFE_FORK();
> if (pid == 0) {
> /*create and turn on remaining swapfiles */
> --
> 2.27.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
` (6 preceding siblings ...)
2024-01-02 2:07 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu (Fujitsu)
@ 2024-01-03 15:35 ` Cyril Hrubis
2024-02-05 18:43 ` Petr Vorel
8 siblings, 0 replies; 22+ messages in thread
From: Cyril Hrubis @ 2024-01-03 15:35 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> +
> +/*
> + * Get kernel constant MAX_SWAPFILES value
> + */
> +unsigned int get_maxswapfiles(void);
Also this has to be with tst_ as well, I would name it simply
tst_max_swapfiles().
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES
2023-12-22 5:00 ` [LTP] [PATCH v2 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu
@ 2024-01-03 15:40 ` Cyril Hrubis
0 siblings, 0 replies; 22+ messages in thread
From: Cyril Hrubis @ 2024-01-03 15:40 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
Good catch, looks like the code that used this has been removed back in
2009 in 96db7a4982e.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 7/7] Add fallback for RHEL9
2023-12-22 5:00 ` [LTP] [PATCH v2 7/7] Add fallback for RHEL9 Yang Xu
@ 2024-02-05 18:37 ` Petr Vorel
0 siblings, 0 replies; 22+ messages in thread
From: Petr Vorel @ 2024-02-05 18:37 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi Yang Xu, all,
> Since device number patch and pte number patch have been backported into
> RHEL9, we should add fallback for this distro.
I guess this is for Li and Jan, thus Cc them.
BTW this is the only patch not set Superseded:
https://patchwork.ozlabs.org/project/ltp/list/?series=387814&state=*
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
` (7 preceding siblings ...)
2024-01-03 15:35 ` Cyril Hrubis
@ 2024-02-05 18:43 ` Petr Vorel
2024-02-06 8:55 ` Yang Xu (Fujitsu) via ltp
8 siblings, 1 reply; 22+ messages in thread
From: Petr Vorel @ 2024-02-05 18:43 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi Yang Xu,
I'm sorry, this is not applicable due my checkpatch cleanup,
but it's Superseded anyway.
@Yang Xu FYI I touched the same test swapon03.c [1]:
The cleanup is not that much important (I'll rebase it after your changes),
the second commit [2] is more important - failure on swapon03 on TMPDIR on
tmpfs. I wonder if your MAX_SWAPFILES fixes will improve it.
Kind regards,
Petr
[1] https://patchwork.ozlabs.org/project/ltp/list/?series=393561
[2] https://patchwork.ozlabs.org/project/ltp/patch/20240205022857.191692-2-pvorel@suse.cz/
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api
2024-02-05 18:43 ` Petr Vorel
@ 2024-02-06 8:55 ` Yang Xu (Fujitsu) via ltp
0 siblings, 0 replies; 22+ messages in thread
From: Yang Xu (Fujitsu) via ltp @ 2024-02-06 8:55 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp@lists.linux.it
Hi Petr,
> Hi Yang Xu,
>
> I'm sorry, this is not applicable due my checkpatch cleanup,
> but it's Superseded anyway.
>
> @Yang Xu FYI I touched the same test swapon03.c [1]:
>
> The cleanup is not that much important (I'll rebase it after your changes),
> the second commit [2] is more important - failure on swapon03 on TMPDIR on
> tmpfs. I wonder if your MAX_SWAPFILES fixes will improve it.
>
I will fix it in my v3 max_swapfiles patchset.
Best Regards,
Yang Xu
> Kind regards,
> Petr
>
> [1] https://patchwork.ozlabs.org/project/ltp/list/?series=393561
> [2] https://patchwork.ozlabs.org/project/ltp/patch/20240205022857.191692-2-pvorel@suse.cz/
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2024-02-06 8:55 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-05 6:16 [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api Yang Xu
2023-12-05 6:16 ` [LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code Yang Xu
2023-12-22 1:39 ` Yang Xu (Fujitsu)
2023-12-22 11:42 ` Petr Vorel
2023-12-05 6:16 ` [LTP] [PATCH 3/3] swaponoff.h: Remove useless header Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 2/7] libltpswap: alter get_used_swapfiles api Yang Xu
2024-01-03 15:30 ` Cyril Hrubis
2023-12-22 5:00 ` [LTP] [PATCH v2 3/7] syscalls/swapon03: use get_maxswapfiles() and GET_USED_SWAPFILES() api Yang Xu
2024-01-03 15:34 ` Cyril Hrubis
2023-12-22 5:00 ` [LTP] [PATCH v2 4/7] swaponoff.h: Remove useless header Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu
2024-01-03 15:40 ` Cyril Hrubis
2023-12-22 5:00 ` [LTP] [PATCH v2 6/7] syscalls/swapon03: Simply this case Yang Xu
2023-12-22 5:00 ` [LTP] [PATCH v2 7/7] Add fallback for RHEL9 Yang Xu
2024-02-05 18:37 ` Petr Vorel
2024-01-02 2:07 ` [LTP] [PATCH v2 1/7] libltpswap: Add get_maxswapfiles api Yang Xu (Fujitsu)
2024-01-03 15:35 ` Cyril Hrubis
2024-02-05 18:43 ` Petr Vorel
2024-02-06 8:55 ` Yang Xu (Fujitsu) via ltp
2023-12-15 6:04 ` [LTP] [PATCH 1/3] " Yang Xu (Fujitsu)
2024-01-03 14:53 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox