* [LTP] [PATCH 1/2] swapon03: Cleanup
@ 2024-02-05 2:28 Petr Vorel
2024-02-05 2:28 ` [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs Petr Vorel
0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2024-02-05 2:28 UTC (permalink / raw)
To: ltp
* There is no need to check for sprintf() return code.
* Use tst_res() instead of printf and remove bogus comments.
* Define EXPECTED_ERRNO as constant (not assigned).
* Use SAFE_*() functions.
* Fix remaining checkpack.pl warnings.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/kernel/syscalls/swapon/swapon03.c | 63 ++++++++-------------
1 file changed, 25 insertions(+), 38 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 05fe2045f..3dbcd5bfd 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -24,14 +24,15 @@
#define MNTPOINT "mntpoint"
#define TEST_FILE MNTPOINT"/testswap"
+#define EXPECTED_ERRNO EPERM
static int setup_swap(void);
static int clean_swap(void);
static int check_and_swapoff(const char *filename);
static int swapfiles;
+static int testfiles = 3;
-int testfiles = 3;
static struct swap_testfile_t {
char *filename;
} swap_testfiles[] = {
@@ -40,8 +41,6 @@ static struct swap_testfile_t {
{"thirdswapfile"}
};
-int expected_errno = EPERM;
-
static void verify_swapon(void)
{
if (setup_swap() < 0) {
@@ -51,14 +50,14 @@ static void verify_swapon(void)
TEST(tst_syscall(__NR_swapon, swap_testfiles[0].filename, 0));
- if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
+ if ((TST_RET == -1) && (TST_ERR == EXPECTED_ERRNO)) {
tst_res(TPASS, "swapon(2) got expected failure (%d),",
- expected_errno);
+ EXPECTED_ERRNO);
} else if (TST_RET < 0) {
tst_res(TFAIL | TTERRNO,
"swapon(2) failed to produce expected error "
"(%d). System reboot recommended.",
- expected_errno);
+ EXPECTED_ERRNO);
} else {
/*
* Probably the system supports MAX_SWAPFILES > 30, let's try with
@@ -78,19 +77,19 @@ static void verify_swapon(void)
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)) {
+ 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);
+ 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));
+ EXPECTED_ERRNO, strerror(TST_ERR));
}
}
}
@@ -114,30 +113,24 @@ static int setup_swap(void)
/* 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");
+ SAFE_SETEUID(0);
- /* 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");
- }
+ fd = SAFE_OPEN("/proc/swaps", O_RDONLY);
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");
- }
+
+ res = SAFE_READ(0, fd, buf, BUFSIZ);
buf[res] = '\0';
while ((p = strchr(p, '\n'))) {
p++;
swapfiles++;
}
- } while (BUFSIZ <= res);
- close(fd);
+ } while (res >= BUFSIZ);
+ SAFE_CLOSE(fd);
+
+ /* don't count the /proc/swaps header */
if (swapfiles)
- swapfiles--; /* don't count the /proc/swaps header */
+ swapfiles--;
if (swapfiles < 0)
tst_brk(TFAIL, "Failed to find existing number of swapfiles");
@@ -146,36 +139,30 @@ static int setup_swap(void)
swapfiles = MAX_SWAPFILES - swapfiles;
if (swapfiles > MAX_SWAPFILES)
swapfiles = MAX_SWAPFILES;
+
pid = SAFE_FORK();
if (pid == 0) {
/*create and turn on remaining swapfiles */
for (j = 0; j < swapfiles; j++) {
-
- /* prepare filename for the iteration */
- if (sprintf(filename, "swapfile%02d", j + 2) < 0) {
- printf("sprintf() failed to create "
- "filename");
- exit(1);
- }
-
- /* Create the swapfile */
+ sprintf(filename, "swapfile%02d", j + 2);
make_swapfile(filename, 10, 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);
+ tst_res(TINFO, "Successfully created %d swapfiles", j);
break;
- } else {
- printf("Failed to create swapfile: %s\n", filename);
- exit(1);
}
+
+ tst_res(TWARN | TERRNO, "Failed to create swapfile: %s", filename);
+ exit(1);
}
}
exit(0);
- } else
+ } else {
waitpid(pid, &status, 0);
+ }
if (WEXITSTATUS(status))
tst_brk(TFAIL, "Failed to setup swaps");
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs
2024-02-05 2:28 [LTP] [PATCH 1/2] swapon03: Cleanup Petr Vorel
@ 2024-02-05 2:28 ` Petr Vorel
2024-02-05 7:48 ` Li Wang
0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2024-02-05 2:28 UTC (permalink / raw)
To: ltp; +Cc: Dominique Leuenberger
tst_test.c:1701: TINFO: === Testing on ext4 ===
tst_test.c:1117: TINFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1131: TINFO: Mounting /dev/loop0 to /tmp/LTP_swanIztq7/mntpoint fstyp=ext4 flags=0
tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
swapon03.c:164: TWARN: Failed to create swapfile: swapfile02: EINVAL (22)
swapon03.c:175: TFAIL: Failed to setup swaps
At least on kernel 6.7.
Fixes: 009a407a0 ("swapon/off: enable all_filesystem in swap test")
Reported-by: Dominique Leuenberger <dimstar@opensuse.org>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
testcases/kernel/syscalls/swapon/swapon03.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 3dbcd5bfd..37314cc65 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -247,6 +247,9 @@ static void setup(void)
if (access("/proc/swaps", F_OK))
tst_brk(TCONF, "swap not supported by kernel");
+ if (tst_fs_type(".") == TST_TMPFS_MAGIC)
+ tst_brk(TCONF, "swap not supported on tmpfs");
+
is_swap_supported(TEST_FILE);
}
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs
2024-02-05 2:28 ` [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs Petr Vorel
@ 2024-02-05 7:48 ` Li Wang
2024-02-05 11:00 ` Petr Vorel
0 siblings, 1 reply; 7+ messages in thread
From: Li Wang @ 2024-02-05 7:48 UTC (permalink / raw)
To: Petr Vorel; +Cc: Dominique Leuenberger, ltp
On Mon, Feb 5, 2024 at 10:29 AM Petr Vorel <pvorel@suse.cz> wrote:
> tst_test.c:1701: TINFO: === Testing on ext4 ===
> tst_test.c:1117: TINFO: Formatting /dev/loop0 with ext4 opts='' extra
> opts=''
> mke2fs 1.47.0 (5-Feb-2023)
> tst_test.c:1131: TINFO: Mounting /dev/loop0 to /tmp/LTP_swanIztq7/mntpoint
> fstyp=ext4 flags=0
> tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
> swapon03.c:164: TWARN: Failed to create swapfile: swapfile02: EINVAL (22)
> swapon03.c:175: TFAIL: Failed to setup swaps
>
> At least on kernel 6.7.
>
> Fixes: 009a407a0 ("swapon/off: enable all_filesystem in swap test")
> Reported-by: Dominique Leuenberger <dimstar@opensuse.org>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> testcases/kernel/syscalls/swapon/swapon03.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon03.c
> b/testcases/kernel/syscalls/swapon/swapon03.c
> index 3dbcd5bfd..37314cc65 100644
> --- a/testcases/kernel/syscalls/swapon/swapon03.c
> +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> @@ -247,6 +247,9 @@ static void setup(void)
> if (access("/proc/swaps", F_OK))
> tst_brk(TCONF, "swap not supported by kernel");
>
> + if (tst_fs_type(".") == TST_TMPFS_MAGIC)
> + tst_brk(TCONF, "swap not supported on tmpfs");
>
I didn't catch the patch point, isn't the failure on EXT4, why here skip
tmpfs?
And, shouldn't the FS check completed in is_swap_supported()?
> +
> is_swap_supported(TEST_FILE);
> }
>
> --
> 2.43.0
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs
2024-02-05 7:48 ` Li Wang
@ 2024-02-05 11:00 ` Petr Vorel
2024-02-12 19:30 ` Petr Vorel
0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2024-02-05 11:00 UTC (permalink / raw)
To: Li Wang; +Cc: Dominique Leuenberger, ltp
> On Mon, Feb 5, 2024 at 10:29 AM Petr Vorel <pvorel@suse.cz> wrote:
> > tst_test.c:1701: TINFO: === Testing on ext4 ===
> > tst_test.c:1117: TINFO: Formatting /dev/loop0 with ext4 opts='' extra
> > opts=''
> > mke2fs 1.47.0 (5-Feb-2023)
> > tst_test.c:1131: TINFO: Mounting /dev/loop0 to /tmp/LTP_swanIztq7/mntpoint
> > fstyp=ext4 flags=0
> > tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
> > swapon03.c:164: TWARN: Failed to create swapfile: swapfile02: EINVAL (22)
> > swapon03.c:175: TFAIL: Failed to setup swaps
> > At least on kernel 6.7.
> > Fixes: 009a407a0 ("swapon/off: enable all_filesystem in swap test")
> > Reported-by: Dominique Leuenberger <dimstar@opensuse.org>
> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > testcases/kernel/syscalls/swapon/swapon03.c | 3 +++
> > 1 file changed, 3 insertions(+)
> > diff --git a/testcases/kernel/syscalls/swapon/swapon03.c
> > b/testcases/kernel/syscalls/swapon/swapon03.c
> > index 3dbcd5bfd..37314cc65 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon03.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> > @@ -247,6 +247,9 @@ static void setup(void)
> > if (access("/proc/swaps", F_OK))
> > tst_brk(TCONF, "swap not supported by kernel");
> > + if (tst_fs_type(".") == TST_TMPFS_MAGIC)
> > + tst_brk(TCONF, "swap not supported on tmpfs");
[ Cc Yang Xu, because he posted a patchset about MAX_SWAPFILES [1], maybe that
would fix the problem ]
> I didn't catch the patch point, isn't the failure on EXT4, why here skip
> tmpfs?
> And, shouldn't the FS check completed in is_swap_supported()?
I'm sorry, the problem is with TMPDIR on tmpfs (which is on Tumbleweed).
Tested on 6.8.0-rc1-2.gf4ba5db-default and 6.7 stable. Or is it a bug in
FIBMAP ioctl detection?
Kind regards,
Petr
[1] https://patchwork.ozlabs.org/project/ltp/list/?series=387814&state=*
> > +
> > is_swap_supported(TEST_FILE);
> > }
> > --
> > 2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs
2024-02-05 11:00 ` Petr Vorel
@ 2024-02-12 19:30 ` Petr Vorel
2024-02-19 10:49 ` Yang Xu (Fujitsu) via ltp
0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2024-02-12 19:30 UTC (permalink / raw)
To: Li Wang, Yang Xu; +Cc: Dominique Leuenberger, ltp
Hi Li, Yang Xu,
this is invalid, replaced by:
https://lore.kernel.org/ltp/20240212192612.636901-1-pvorel@suse.cz/
https://patchwork.ozlabs.org/project/ltp/patch/20240212192612.636901-1-pvorel@suse.cz/
Could we please merge this simple fix before Yang Xu cleanup patchset:
https://patchwork.ozlabs.org/project/ltp/list/?series=394113
https://lore.kernel.org/ltp/20240208100517.1974-1-xuyang2018.jy@fujitsu.com/
I'm sorry, that would mean to send rebased version, but IMHO better include
simple fix.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs
2024-02-12 19:30 ` Petr Vorel
@ 2024-02-19 10:49 ` Yang Xu (Fujitsu) via ltp
2024-02-19 15:21 ` Petr Vorel
0 siblings, 1 reply; 7+ messages in thread
From: Yang Xu (Fujitsu) via ltp @ 2024-02-19 10:49 UTC (permalink / raw)
To: Petr Vorel, Li Wang; +Cc: Dominique Leuenberger, ltp
Hi Petr, Li
> Hi Li, Yang Xu,
>
> this is invalid, replaced by:
>
> https://lore.kernel.org/ltp/20240212192612.636901-1-pvorel@suse.cz/
> https://patchwork.ozlabs.org/project/ltp/patch/20240212192612.636901-1-pvorel@suse.cz/
>
> Could we please merge this simple fix before Yang Xu cleanup patchset:
>
> https://patchwork.ozlabs.org/project/ltp/list/?series=394113
> https://lore.kernel.org/ltp/20240208100517.1974-1-xuyang2018.jy@fujitsu.com/
>
> I'm sorry, that would mean to send rebased version, but IMHO better include
> simple fix.
>
Now, can I send v4 patchset for maxswapfiles since Li's patch (fix
snprintf return value problem) has been merged int master?
Best Regards
Yang Xu
> Kind regards,
> Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs
2024-02-19 10:49 ` Yang Xu (Fujitsu) via ltp
@ 2024-02-19 15:21 ` Petr Vorel
0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2024-02-19 15:21 UTC (permalink / raw)
To: Yang Xu (Fujitsu); +Cc: Dominique Leuenberger, ltp
> Hi Petr, Li
> > Hi Li, Yang Xu,
> > this is invalid, replaced by:
> > https://lore.kernel.org/ltp/20240212192612.636901-1-pvorel@suse.cz/
> > https://patchwork.ozlabs.org/project/ltp/patch/20240212192612.636901-1-pvorel@suse.cz/
> > Could we please merge this simple fix before Yang Xu cleanup patchset:
> > https://patchwork.ozlabs.org/project/ltp/list/?series=394113
> > https://lore.kernel.org/ltp/20240208100517.1974-1-xuyang2018.jy@fujitsu.com/
> > I'm sorry, that would mean to send rebased version, but IMHO better include
> > simple fix.
> Now, can I send v4 patchset for maxswapfiles since Li's patch (fix
> snprintf return value problem) has been merged int master?
Yes, please.
Kind regards,
Petr
> Best Regards
> Yang Xu
> > Kind regards,
> > Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-02-19 15:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 2:28 [LTP] [PATCH 1/2] swapon03: Cleanup Petr Vorel
2024-02-05 2:28 ` [LTP] [PATCH 2/2] swapon03: Swap is not supported on TMPFS on tmpfs Petr Vorel
2024-02-05 7:48 ` Li Wang
2024-02-05 11:00 ` Petr Vorel
2024-02-12 19:30 ` Petr Vorel
2024-02-19 10:49 ` Yang Xu (Fujitsu) via ltp
2024-02-19 15:21 ` Petr Vorel
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.