From: Cyril Hrubis <chrubis@suse.cz>
To: Yang Xu <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/3] libltpswap: Add get_maxswapfiles api
Date: Wed, 3 Jan 2024 15:53:49 +0100 [thread overview]
Message-ID: <ZZV0_fSR7l3JD53t@yuki> (raw)
In-Reply-To: <20231205061639.68656-1-xuyang2018.jy@fujitsu.com>
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
prev parent reply other threads:[~2024-01-03 14:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZZV0_fSR7l3JD53t@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=xuyang2018.jy@fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.