syscalls/swapon02: Do not fail on overlayfs
Subsystems (2)
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Currently swapfiles on Overlayfs are not supported.
So if we are on overlayfs and we get EINVAL from swapon() we return TCONF.
--- testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++ 1 file changed, 5 insertions(+)
testcases/kernel/syscalls/swapon/swapon02.c +5 -0
@@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)return ; } +if (fs_type ==TST_OVERLAYFS_MAGIC && errno ==EINVAL ) { +tst_resm (TCONF ,"Swapfile on overlayfs not implemeted" ); +return ; + } +tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" " %d, errno: %s and got %d." , test->exp_errno, test->exp_errval,TEST_ERRNO );
Signature · 1 line
2.21.0
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Quoted 15 lines · Murphy Zhou
Currently swapfiles on Overlayfs are not supported.
So if we are on overlayfs and we get EINVAL from
swapon()we return TCONF.Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++ 1 file changed, 5 insertions(+)testcases/kernel/syscalls/swapon/swapon02.c +0
-0
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 93
Quoted 8 lines
testcases/kernel/syscalls/swapon/swapon02.c +4
-0@@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)return ; } +if (fs_type ==TST_OVERLAYFS_MAGIC && errno ==EINVAL ) { +tst_resm (TCONF ,"Swapfile on overlayfs not implemeted" ); +return ; + }
The code looks correct.
But it already has a test skipping for BTRFS, is there any possibility to combine these filesystems check together?
Quoted 11 lines
testcases/kernel/syscalls/swapon/swapon02.c +1
-0+ tst_resm(TFAIL, "swapon(2) failed to produce expected error:" " %d, errno: %s and got %d.", test->exp_errno,test->exp_errval, TEST_ERRNO);--
2.21.0--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190430/37366418/attachment.html>
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Quoted 28 lines · Li Wang
Quoted 15 lines · Murphy Zhou
Currently swapfiles on Overlayfs are not supported.
So if we are on overlayfs and we get EINVAL from
swapon()we return TCONF.Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++ 1 file changed, 5 insertions(+)testcases/kernel/syscalls/swapon/swapon02.c +0
-0testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 93
Quoted 8 lines
testcases/kernel/syscalls/swapon/swapon02.c +4
-0@@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)return ; } +if (fs_type ==TST_OVERLAYFS_MAGIC && errno ==EINVAL ) { +tst_resm (TCONF ,"Swapfile on overlayfs not implemeted" ); +return ; + }The code looks correct.
Quoted 2 lines
But it already has a test skipping for BTRFS, is there any possibility to combine these filesystems check together?
Good idea~ Sending V2.
Thansk!
M
Quoted 18 lines
Quoted 13 lines
testcases/kernel/syscalls/swapon/swapon02.c +1
-0+ tst_resm(TFAIL, "swapon(2) failed to produce expected error:" " %d, errno: %s and got %d.", test->exp_errno,test->exp_errval, TEST_ERRNO);--
2.21.0--
Mailing list info: https://lists.linux.it/listinfo/ltpSignature · 2 lines
Regards, Li Wang
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Quoted 29 lines · Murphy Zhou
Quoted 5 lines · Li Wang
Quoted 3 lines · Murphy Zhou
Currently swapfiles on Overlayfs are not supported.
So if we are on overlayfs and we get EINVAL from
swapon()we returnTCONF.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++ 1 file changed, 5 insertions(+)testcases/kernel/syscalls/swapon/swapon02.c +0
-0@@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)return ; }Quoted 2 lines
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 90
Quoted 2 lines
testcases/kernel/syscalls/swapon/swapon02.c +2
-0+if (fs_type ==TST_OVERLAYFS_MAGIC && errno ==EINVAL ) { + tst_resm(TCONF, "Swapfile on overlayfs notimplemeted");
Quoted 4 lines
Quoted 3 lines
testcases/kernel/syscalls/swapon/swapon02.c +2
-0+return ; + }
Quoted 7 lines
Quoted 4 lines
The code looks correct.
But it already has a test skipping for BTRFS, is there any possibility to combine these filesystems check together?
Good idea~ Sending V2.
One more comment.
I just noticed that it also has an FS skipping list in setup(), do u think can we move BTRFS and OVERLAYFS to there?
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190430/40504742/attachment.html>
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Quoted 36 lines · Li Wang
Quoted 34 lines · Murphy Zhou
Quoted 5 lines · Li Wang
Quoted 3 lines · Murphy Zhou
Currently swapfiles on Overlayfs are not supported.
So if we are on overlayfs and we get EINVAL from
swapon()we returnTCONF.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++ 1 file changed, 5 insertions(+)testcases/kernel/syscalls/swapon/swapon02.c +0
-0@@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)return ; }Quoted 2 lines
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 90
Quoted 2 lines
testcases/kernel/syscalls/swapon/swapon02.c +2
-0+if (fs_type ==TST_OVERLAYFS_MAGIC && errno ==EINVAL ) { + tst_resm(TCONF, "Swapfile on overlayfs notimplemeted");
Quoted 8 lines
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test)
Quoted 3 lines
testcases/kernel/syscalls/swapon/swapon02.c +2
-0+return ; + }The code looks correct.
But it already has a test skipping for BTRFS, is there any possibility to combine these filesystems check together?
Quoted 7 lines
Quoted 2 lines
Good idea~ Sending V2.
One more comment.
I just noticed that it also has an FS skipping list in
setup(), do u think can we move BTRFS and OVERLAYFS to there?
Great! That makes perfect sense. Also I'm thinking a few other tweaks needed:
NFS now actually support swapfiles. Let's remove it from skip list; Skip all swapon/swapoff tests on TMPFS BTRFS OVERLAYFS; Add CIFS_MAGIC, then skip on it too;
Remove existing BTRFS return value tweaks.
Thanks,
M
Quoted 4 lines
Signature · 3 lines
-- Regards, Li Wang
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Quoted 19 lines · Murphy Zhou
...
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) { + tst_resm(TCONF, "Swapfile on overlayfs notimplemeted");
Quoted 7 lines
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 92
Quoted 3 lines
testcases/kernel/syscalls/swapon/swapon02.c +2
-0+return ; + }The code looks correct.
But it already has a test skipping for BTRFS, is there any
possibility to
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
combine these filesystems check together?
Good idea~ Sending V2.
One more comment.
Quoted 9 lines
Quoted 1 line
I just noticed that it also has an FS skipping list in
setup(), do uthink
Quoted 1 line
can we move BTRFS and OVERLAYFS to there?
Great! That makes perfect sense. Also I'm thinking a few other tweaks needed:
NFS now actually support swapfiles. Let's remove it from skip list;
But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee the test works fine in that situation. So, my opinion is to reserve the NFS, or do you have a better way to make test more flexible?
Quoted 4 lines
Skip all swapon/swapoff tests on TMPFS BTRFS OVERLAYFS; Add
CIFS_MAGIC, then skip on it too;
Remove existing BTRFS return value tweaks.
Agree.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190430/1dbfc940/attachment.html>
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Quoted 28 lines · Li Wang
Quoted 26 lines · Murphy Zhou
...
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) { + tst_resm(TCONF, "Swapfile on overlayfs notimplemeted");
Quoted 7 lines
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 92
Quoted 3 lines
testcases/kernel/syscalls/swapon/swapon02.c +2
-0+return ; + }The code looks correct.
But it already has a test skipping for BTRFS, is there any
possibility to
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
combine these filesystems check together?
Good idea~ Sending V2.
One more comment.
I just noticed that it also has an FS skipping list in
setup(), do uthink
Quoted 1 line
can we move BTRFS and OVERLAYFS to there?
Great! That makes perfect sense. Also I'm thinking a few other tweaks needed:
Quoted 6 lines
Quoted 2 lines
NFS now actually support swapfiles. Let's remove it from skip list;
But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee the test works fine in that situation. So, my opinion is to reserve the NFS, or do you have a better way to make test more flexible?
Fair enough. We can reserve NFS on the skip list to avoid much false alarms.
Quoted 8 lines
Quoted 6 lines
Skip all swapon/swapoff tests on TMPFS BTRFS OVERLAYFS; Add
CIFS_MAGIC, then skip on it too;
Remove existing BTRFS return value tweaks.Agree.
Thanks!
M
Quoted 4 lines
Signature · 3 lines
-- Regards, Li Wang
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
In reply to Li WangQuoted 26 lines · Li Wang
Quoted 22 lines · Murphy Zhou
...
Quoted 19 lines
Quoted 7 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) { + tst_resm(TCONF, "Swapfile on overlayfs notimplemeted");
Quoted 4 lines
Quoted 3 lines
testcases/kernel/syscalls/swapon/swapon02.c +2
-0+return ; + }Quoted 7 lines
Quoted 4 lines
The code looks correct.
But it already has a test skipping for BTRFS, is there any possibility to combine these filesystems check together?
Good idea~ Sending V2.
One more comment.
I just noticed that it also has an FS skipping list in
setup(), do u think can we move BTRFS and OVERLAYFS to there?
Quoted 7 lines
Quoted 4 lines
Great! That makes perfect sense. Also I'm thinking a few other tweaks needed:
NFS now actually support swapfiles. Let's remove it from skip list;
But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee the test works fine in that situation. So, my opinion is to reserve the NFS, or do you have a better way to make test more flexible?
Avoid whitelist.
Test for FIBMAP ioctl support.
Thanks,
Amir.
PATCH 1/1 syscalls/swapon02: Do not fail on overlayfs
Quoted 30 lines · Amir Goldstein
Quoted 29 lines · Li Wang
Quoted 25 lines · Murphy Zhou
...
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) { + tst_resm(TCONF, "Swapfile on overlayfs notimplemeted");
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ return; + }The code looks correct.
But it already has a test skipping for BTRFS, is there any possibility to combine these filesystems check together?
Quoted 7 lines
Quoted 2 lines
Good idea~ Sending V2.
One more comment.
I just noticed that it also has an FS skipping list in
setup(), do u think can we move BTRFS and OVERLAYFS to there?Great! That makes perfect sense. Also I'm thinking a few other tweaks needed:
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
NFS now actually support swapfiles. Let's remove it from skip list;
But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee the test works fine in that situation. So, my opinion is to reserve the NFS, or do you have a better way to make test more flexible?
Avoid whitelist.
Test for FIBMAP ioctl support.
Hmm.. This is better. I'll try.
Thanks!
M
Quoted 3 lines
Thanks,
Amir.
PATCH v2 1/1 syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
That means swapfile in the test filesystem is not supported.
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
--- include/tst_fs.h | 5 +++ lib/tst_ioctl.c | 41 +++++++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++---- testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ++--- testcases/kernel/syscalls/swapon/swapon01.c | 13 ++---- testcases/kernel/syscalls/swapon/swapon02.c | 16 ++------ testcases/kernel/syscalls/swapon/swapon03.c | 20 ++------- 7 files changed, 64 insertions(+), 54 deletions(-) create mode 100644 lib/tst_ioctl.c
include/tst_fs.h +5 -0
@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (void ); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {
lib/tst_ioctl.c new file +41 -0
41 lines not on this page · raw message
testcases/kernel/syscalls/swapoff/swapoff01.c +3 -10
@@ -55,11 +55,6 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); - } -tst_resm (TBROK ,"Failed to turn on the swap file" ", skipping test iteration" );return ;
@@ -86,13 +81,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) {
testcases/kernel/syscalls/swapoff/swapoff02.c +4 -6
@@ -138,13 +138,11 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; +"Cannot do FIBMAP ioctl on a file on %s filesystem" , +tst_fs_type_name (fs_type)); }if (!tst_fs_has_free (NULL ,"." ,1 ,TST_KB )) {
testcases/kernel/syscalls/swapon/swapon01.c +3 -10
@@ -39,11 +39,6 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; - }tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );
@@ -84,13 +79,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }make_swapfile (cleanup,"swapfile01" );
testcases/kernel/syscalls/swapon/swapon02.c +4 -12
@@ -81,11 +81,6 @@ static void verify_swapon(struct test_case_t *test)return ; } -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_resm (TCONF ,"Swapfile on BTRFS not implemeted" ); -return ; - } -tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" " %d, errno: %s and got %d." , test->exp_errno, test->exp_errval,TEST_ERRNO );
@@ -132,13 +127,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL );
@@ -146,8 +139,7 @@ static void setup(void)make_swapfile (cleanup,"alreadyused" );if (ltp_syscall (__NR_swapon,"alreadyused" ,0 )) { -if (fs_type !=TST_BTRFS_MAGIC || errno !=EINVAL ) -tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); +tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); }else { do_swapoff =1 ; }
testcases/kernel/syscalls/swapon/swapon03.c +4 -16
@@ -215,9 +215,6 @@ static int setup_swap(void)/* turn on the swap file */ res =ltp_syscall (__NR_swapon, filename,0 );if (res !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) -exit (2 ); -if (errno ==EPERM ) {printf ("Successfully created %d " "swapfiles\n" , j);
@@ -233,15 +230,8 @@ static int setup_swap(void) }else waitpid (pid, &status,0 ); -switch (WEXITSTATUS (status)) { -case 0 : -break ; -case 2 : -tst_brkm (TCONF , cleanup,"Swapfile on BTRFS not implemeted" ); -break ; -default : +if (WEXITSTATUS (status)) {tst_brkm (TFAIL , cleanup,"Failed to setup swaps" ); -break ; }/* Create all needed extra swapfiles for testing */
@@ -333,13 +323,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }TEST_PAUSE ;
Signature · 1 line
2.21.0
PATCH v3 1/1 syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
That means swapfile in the test filesystem is not supported.
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fix fs_type undeclared in swapoff01.c.
include/tst_fs.h | 5 +++ lib/tst_ioctl.c | 41 +++++++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++---- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++-- testcases/kernel/syscalls/swapon/swapon01.c | 13 ++---- testcases/kernel/syscalls/swapon/swapon02.c | 16 ++------ testcases/kernel/syscalls/swapon/swapon03.c | 20 ++------- 7 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 lib/tst_ioctl.c
include/tst_fs.h +5 -0
@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (void ); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {
lib/tst_ioctl.c new file +41 -0
41 lines not on this page · raw message
testcases/kernel/syscalls/swapoff/swapoff01.c +3 -10
@@ -55,11 +55,6 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); - } -tst_resm (TBROK ,"Failed to turn on the swap file" ", skipping test iteration" );return ;
@@ -86,13 +81,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) {
testcases/kernel/syscalls/swapoff/swapoff02.c +5 -6
@@ -43,6 +43,7 @@ char *TCID = "swapoff02";int TST_TOTAL =3 ;static uid_t nobody_uid; +static long fs_type; static struct test_case_t { char *err_desc;
@@ -138,13 +139,11 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; +"Cannot do FIBMAP ioctl on a file on %s filesystem" , +tst_fs_type_name (fs_type)); }if (!tst_fs_has_free (NULL ,"." ,1 ,TST_KB )) {
testcases/kernel/syscalls/swapon/swapon01.c +3 -10
@@ -39,11 +39,6 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; - }tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );
@@ -84,13 +79,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }make_swapfile (cleanup,"swapfile01" );
testcases/kernel/syscalls/swapon/swapon02.c +4 -12
@@ -81,11 +81,6 @@ static void verify_swapon(struct test_case_t *test)return ; } -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_resm (TCONF ,"Swapfile on BTRFS not implemeted" ); -return ; - } -tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" " %d, errno: %s and got %d." , test->exp_errno, test->exp_errval,TEST_ERRNO );
@@ -132,13 +127,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL );
@@ -146,8 +139,7 @@ static void setup(void)make_swapfile (cleanup,"alreadyused" );if (ltp_syscall (__NR_swapon,"alreadyused" ,0 )) { -if (fs_type !=TST_BTRFS_MAGIC || errno !=EINVAL ) -tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); +tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); }else { do_swapoff =1 ; }
testcases/kernel/syscalls/swapon/swapon03.c +4 -16
@@ -215,9 +215,6 @@ static int setup_swap(void)/* turn on the swap file */ res =ltp_syscall (__NR_swapon, filename,0 );if (res !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) -exit (2 ); -if (errno ==EPERM ) {printf ("Successfully created %d " "swapfiles\n" , j);
@@ -233,15 +230,8 @@ static int setup_swap(void) }else waitpid (pid, &status,0 ); -switch (WEXITSTATUS (status)) { -case 0 : -break ; -case 2 : -tst_brkm (TCONF , cleanup,"Swapfile on BTRFS not implemeted" ); -break ; -default : +if (WEXITSTATUS (status)) {tst_brkm (TFAIL , cleanup,"Failed to setup swaps" ); -break ; }/* Create all needed extra swapfiles for testing */
@@ -333,13 +323,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem" ,tst_fs_type_name (fs_type)); -break ; }TEST_PAUSE ;
Signature · 1 line
2.21.0
PATCH v3 1/1 syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
Hi Murphy,
Quoted 170 lines · Murphy Zhou
That means swapfile in the test filesystem is not supported. Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.include/tst_fs.h | 5 +++ lib/tst_ioctl.c | 41 +++++++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++---- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++-- testcases/kernel/syscalls/swapon/swapon01.c | 13 ++---- testcases/kernel/syscalls/swapon/swapon02.c | 16 ++------ testcases/kernel/syscalls/swapon/swapon03.c | 20 ++------- 7 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (void ); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +20
-0@@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (void ) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; +const char *tmpdir =getenv ("TMPDIR" ); +char buf[128 ]; + + tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",tmpdir);
lib/tst_ioctl.c new file +21
-0+ +sprintf (buf,"%s/tst_fibmap" , tmpdir); + + fd =open (buf,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , buf); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +close (fd); +return 1 ; + } + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +3
-10@@ -55,11 +55,6 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); - } -tst_resm (TBROK ,"Failed to turn on the swap file" ", skipping test iteration" );return ;@@ -86,13 +81,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem",tst_fs_type_name (fs_type)); -break ; }if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {testcases/kernel/syscalls/swapoff/swapoff02.c +5
-6@@ -43,6 +43,7 @@ char *TCID = "swapoff02";int TST_TOTAL =3 ;static uid_t nobody_uid; +static long fs_type; static struct test_case_t { char *err_desc;@@ -138,13 +139,11 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; +"Cannot do FIBMAP ioctl on a file on %s filesystem", +tst_fs_type_name (fs_type)); }if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {testcases/kernel/syscalls/swapon/swapon01.c +0
-5@@ -39,11 +39,6 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; - }tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );
testcases/kernel/syscalls/swapon/swapon01.c static void setup(void) · line 84
Quoted 9 lines
testcases/kernel/syscalls/swapon/swapon01.c +2
-3@@ -84,13 +79,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {
I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted on a filesystem.
If that's true, shouldn't we verify FIBMAP ioctl on the swapfile? Here you just test that in a tmp file, it probably not a correct way I guess.
IMO, maybe we can define the function API as:
tst_fibmap(const char *filename);
And calling it in behind of make_swapfile(cleanup, "swapfile01");
Beside that, there is another issue in this patch, since the getenv("TMPDIR"); depend on runltp script, so we cann't run the test independently.
# ./swapon01 tst_ioctl.c:20: INFO: Testing if FIBMAP ioctl is supported in (null) tst_ioctl.c:27: WARN: open((null)/tst_fibmap, O_RDWR | O_CREAT, 0666) failed: ENOENT swapon01 1 TCONF : swapon01.c:86: Cannot do FIBMAP ioctl on a file on XFS filesystem swapon01 2 TCONF : swapon01.c:86: Remaining cases not appropriate for configuration
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190507/9bdefaa0/attachment-0001.html>
PATCH v3 1/1 syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
Hi,
Thanks for reviewing!
Quoted 177 lines · Li Wang
Hi Murphy,
Quoted 173 lines · Murphy Zhou
That means swapfile in the test filesystem is not supported. Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.include/tst_fs.h | 5 +++ lib/tst_ioctl.c | 41 +++++++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++---- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++-- testcases/kernel/syscalls/swapon/swapon01.c | 13 ++---- testcases/kernel/syscalls/swapon/swapon02.c | 16 ++------ testcases/kernel/syscalls/swapon/swapon03.c | 20 ++------- 7 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (void ); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +20
-0@@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (void ) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; +const char *tmpdir =getenv ("TMPDIR" ); +char buf[128 ]; + + tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",tmpdir);
lib/tst_ioctl.c new file +21
-0+ +sprintf (buf,"%s/tst_fibmap" , tmpdir); + + fd =open (buf,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , buf); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +close (fd); +return 1 ; + } + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +3
-10@@ -55,11 +55,6 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); - } -tst_resm (TBROK ,"Failed to turn on the swap file" ", skipping test iteration" );return ;@@ -86,13 +81,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem",tst_fs_type_name (fs_type)); -break ; }if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {testcases/kernel/syscalls/swapoff/swapoff02.c +5
-6@@ -43,6 +43,7 @@ char *TCID = "swapoff02";int TST_TOTAL =3 ;static uid_t nobody_uid; +static long fs_type; static struct test_case_t { char *err_desc;@@ -138,13 +139,11 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; +"Cannot do FIBMAP ioctl on a file on %s filesystem", +tst_fs_type_name (fs_type)); }if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {testcases/kernel/syscalls/swapon/swapon01.c +0
-5@@ -39,11 +39,6 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; - }tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );@@ -84,13 +79,11 @@ static void setup(void)tst_tmpdir ();
Quoted 11 lines
testcases/kernel/syscalls/swapon/swapon01.c static void setup(void) · line 84
Quoted 6 lines
testcases/kernel/syscalls/swapon/swapon01.c +2
-3-switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted on a filesystem.
If that's true, shouldn't we verify FIBMAP ioctl on the swapfile? Here you just test that in a tmp file, it probably not a correct way I guess.
We don't need to test on a swapfile. If the filesystem we are testing supports FIBMAP iotcl, we can make a file in this filesystem a swapfile.
Quoted 8 lines
IMO, maybe we can define the function API as:
tst_fibmap(const char *filename);And calling it in behind of
make_swapfile(cleanup, "swapfile01");Beside that, there is another issue in this patch, since the
getenv("TMPDIR"); depend on runltp script, so we cann't run the test independently.
Good catch. I guess we can check the string returned by getenv("TMPDIR"), if it's null, set the test directory to "./".
Thanks,
M
Quoted 13 lines
# ./swapon01 tst_ioctl.c:20: INFO: Testing if FIBMAP ioctl is supported in (null) tst_ioctl.c:27: WARN: open((null)/tst_fibmap, O_RDWR | O_CREAT, 0666) failed: ENOENT swapon01 1 TCONF : swapon01.c:86: Cannot do FIBMAP ioctl on a file on XFS filesystem swapon01 2 TCONF : swapon01.c:86: Remaining cases not appropriate for configurationSignature · 2 lines
Regards, Li Wang
PATCH v3 1/1 syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
Quoted 192 lines · Murphy Zhou
Hi,
Thanks for reviewing!
Quoted 186 lines · Li Wang
Hi Murphy,
Quoted 170 lines · Murphy Zhou
That means swapfile in the test filesystem is not supported. Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.include/tst_fs.h | 5 +++ lib/tst_ioctl.c | 41 +++++++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++---- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++-- testcases/kernel/syscalls/swapon/swapon01.c | 13 ++---- testcases/kernel/syscalls/swapon/swapon02.c | 16 ++------ testcases/kernel/syscalls/swapon/swapon03.c | 20 ++------- 7 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (void ); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +20
-0@@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (void ) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; +const char *tmpdir =getenv ("TMPDIR" ); +char buf[128 ]; + + tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",tmpdir);
lib/tst_ioctl.c new file +21
-0+ +sprintf (buf,"%s/tst_fibmap" , tmpdir); + + fd =open (buf,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , buf); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +close (fd); +return 1 ; + } + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +3
-10@@ -55,11 +55,6 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); - } -tst_resm (TBROK ,"Failed to turn on the swap file" ", skipping test iteration" );return ;@@ -86,13 +81,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem",tst_fs_type_name (fs_type)); -break ; }if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {testcases/kernel/syscalls/swapoff/swapoff02.c +5
-6@@ -43,6 +43,7 @@ char *TCID = "swapoff02";int TST_TOTAL =3 ;static uid_t nobody_uid; +static long fs_type; static struct test_case_t { char *err_desc;@@ -138,13 +139,11 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; +"Cannot do FIBMAP ioctl on a file on %s filesystem", +tst_fs_type_name (fs_type)); }if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {testcases/kernel/syscalls/swapon/swapon01.c +0
-5@@ -39,11 +39,6 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; - }tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );testcases/kernel/syscalls/swapon/swapon01.c static void setup(void) · line 84
Quoted 9 lines
testcases/kernel/syscalls/swapon/swapon01.c +2
-3@@ -84,13 +79,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted on a filesystem.
Li is correct here. BTRFS and NFS on recent kernel support swapfile but not support FIBMAP ioctl, so if you want to add test coverage for NFS and BTRFS, I'm afraid they would have to be whitelisted after all, but not is setup()
because depending on kernel, they may support swapfile and may not. Worse even, BTRFS had FIBMAP support for a while and then removed, see:ed46ff3d4237 Btrfs: support swap files35054394c4b3 Btrfs: stop providing a bmap operation to avoid swapfile corruptions
Sorry I missed this before.
Quoted 6 lines
Quoted 2 lines
If that's true, shouldn't we verify FIBMAP ioctl on the swapfile? Here you just test that in a tmp file, it probably not a correct way I guess.
We don't need to test on a swapfile. If the filesystem we are testing supports FIBMAP iotcl, we can make a file in this filesystem a swapfile.
In theory, FIBMAP can work on certain files and fail on certain files (e.g. reflinked xfs/ocfs2 file), but that is unlikely the case in this test and not related to file being a swap file.
In conclusion
1. If filesystem supports FIBMAP its a very strong indication that filesystem supports swapfile, but in theory a future filesystem could fail this test (don't see a reason for that to happen).
2. If filesystem does not support FIBMAP it can support swapfile btrfs and nfs are examples in current upstream, but in future could be other filesystems as well
Suggestion: test in setup FIBMAP. If not supported don't fail immediately but do the try and fail softly with TCONF that is currently implemented for TST_BTRFS_MAGIC.
Thanks,
Amir.
PATCH v3 1/1 syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
Hi,
Quoted 194 lines · Amir Goldstein
Quoted 192 lines · Murphy Zhou
Hi,
Thanks for reviewing!
Quoted 186 lines · Li Wang
Hi Murphy,
Quoted 170 lines · Murphy Zhou
That means swapfile in the test filesystem is not supported. Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.include/tst_fs.h | 5 +++ lib/tst_ioctl.c | 41 +++++++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++---- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++-- testcases/kernel/syscalls/swapon/swapon01.c | 13 ++---- testcases/kernel/syscalls/swapon/swapon02.c | 16 ++------ testcases/kernel/syscalls/swapon/swapon03.c | 20 ++------- 7 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (void ); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +20
-0@@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (void ) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; +const char *tmpdir =getenv ("TMPDIR" ); +char buf[128 ]; + + tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",tmpdir);
lib/tst_ioctl.c new file +21
-0+ +sprintf (buf,"%s/tst_fibmap" , tmpdir); + + fd =open (buf,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , buf); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +close (fd); +return 1 ; + } + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +3
-10@@ -55,11 +55,6 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); - } -tst_resm (TBROK ,"Failed to turn on the swap file" ", skipping test iteration" );return ;@@ -86,13 +81,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , +"Cannot do FIBMAP ioctl on a file on %s filesystem",tst_fs_type_name (fs_type)); -break ; }if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {testcases/kernel/syscalls/swapoff/swapoff02.c +5
-6@@ -43,6 +43,7 @@ char *TCID = "swapoff02";int TST_TOTAL =3 ;static uid_t nobody_uid; +static long fs_type; static struct test_case_t { char *err_desc;@@ -138,13 +139,11 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; +"Cannot do FIBMAP ioctl on a file on %s filesystem", +tst_fs_type_name (fs_type)); }if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {testcases/kernel/syscalls/swapon/swapon01.c +0
-5@@ -39,11 +39,6 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; - }tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );testcases/kernel/syscalls/swapon/swapon01.c static void setup(void) · line 84
Quoted 9 lines
testcases/kernel/syscalls/swapon/swapon01.c +2
-3@@ -84,13 +79,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ()) {I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted on a filesystem.
Quoted 9 lines
Li is correct here. BTRFS and NFS on recent kernel support swapfile but not support FIBMAP ioctl, so if you want to add test coverage for NFS and BTRFS, I'm afraid they would have to be whitelisted after all, but not is
setup()
because depending on kernel, they may support swapfile and may not. Worse even, BTRFS had FIBMAP support for a while and then removed, see:ed46ff3d4237Btrfs: support swap files35054394c4b3Btrfs: stop providing a bmap operation to avoid swapfile corruptions
Great to know! Thanks for pointing that out. Much learned. :)
Quoted 2 lines
Sorry I missed this before.
It's my bad not checking carefully.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
If that's true, shouldn't we verify FIBMAP ioctl on the swapfile? Here you just test that in a tmp file, it probably not a correct way I guess.
We don't need to test on a swapfile. If the filesystem we are testing supports FIBMAP iotcl, we can make a file in this filesystem a swapfile.
In theory, FIBMAP can work on certain files and fail on certain files (e.g. reflinked xfs/ocfs2 file), but that is unlikely the case in this test and not related to file being a swap file.
Agreed. Sounds like a corner case in these corner swap rests to me :)
Quoted 5 lines
In conclusion
1. If filesystem supports FIBMAP its a very strong indication that filesystem supports swapfile, but in theory a future filesystem could fail this test (don't see a reason for that to happen).
I mainly thought about ths situation. We can let the following swap* test go to see what's happening.
Quoted 7 lines
2. If filesystem does not support FIBMAP it can support swapfile btrfs and nfs are examples in current upstream, but in future could be other filesystems as well
Suggestion: test in setup FIBMAP. If not supported don't fail immediately but do the try and fail softly with TCONF that is currently implemented for
TST_BTRFS_MAGIC.
Reasonable to me. Thanks for the suggestion. We can go wo/ whitelist.
Thanks,
M
Quoted 3 lines
Thanks,
Amir.
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
In reply to Amir GoldsteinAdd a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code. Leave swapoff02 alone because it's permission checking only in it.
---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fix fs_type undeclared in swapoff01.c.
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase.
include/tst_fs.h | 5 ++ lib/tst_ioctl.c | 39 ++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++------- testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ---- testcases/kernel/syscalls/swapon/swapon01.c | 23 ++++---- testcases/kernel/syscalls/swapon/swapon02.c | 31 ++++++----- testcases/kernel/syscalls/swapon/swapon03.c | 52 +++++++++---------- 7 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 lib/tst_ioctl.c
include/tst_fs.h +5 -0
@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename,const char *fstype); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {
lib/tst_ioctl.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename,const char *fstype) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + +tst_res (TINFO ,"Testing if FIBMAP ioctl is supported on %s" , fstype); + + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}
testcases/kernel/syscalls/swapoff/swapoff01.c +27 -19
76 lines not on this page · raw message
testcases/kernel/syscalls/swapoff/swapoff02.c +0 -10
@@ -124,7 +124,6 @@ static void cleanup01(void)static void setup (void ) { -long type;struct passwd *nobody;tst_sig (FORK ,DEF_HANDLER , cleanup);
@@ -138,15 +137,6 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; - } -if (!tst_fs_has_free (NULL ,"." ,1 ,TST_KB )) {tst_brkm (TBROK , cleanup,"Insufficient disk space to create swap file" );
testcases/kernel/syscalls/swapon/swapon01.c +10 -13
@@ -31,6 +31,7 @@ static void cleanup(void);char *TCID ="swapon01" ;int TST_TOTAL =1 ; +int fibmap =1 ;static long fs_type;
@@ -39,12 +40,11 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; +if (fibmap ==0 ) { +tst_resm (TCONF ,"Failed to turn on swapfile" ); + }else { +tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); } -tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );/*we need to turn this swap file off for -i option */
@@ -58,7 +58,6 @@ static void verify_swapon(void)int main (int ac,char **av) { -int lc;tst_parse_opts (ac, av,NULL ,NULL );
@@ -84,13 +83,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }make_swapfile (cleanup,"swapfile01" );
testcases/kernel/syscalls/swapon/swapon02.c +15 -16
@@ -44,6 +44,7 @@ static void cleanup01(void);char *TCID ="swapon02" ;int TST_TOTAL =4 ; +int fibmap =1 ;static uid_t nobody_uid;static int do_swapoff;
@@ -81,14 +82,15 @@ static void verify_swapon(struct test_case_t *test)return ; } -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_resm (TCONF ,"Swapfile on BTRFS not implemeted" ); -return ; +if (fibmap ==1 ) { +tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" +" %d, errno: %s and got %d." , test->exp_errno, + test->exp_errval,TEST_ERRNO ); + }else { +tst_resm (TCONF ,"swapon(2) failed to produce expected error:" +" %d, errno: %s and got %d." , test->exp_errno, + test->exp_errval,TEST_ERRNO ); } - -tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" -" %d, errno: %s and got %d." , test->exp_errno, - test->exp_errval,TEST_ERRNO ); }int main (int ac,char **av)
@@ -132,13 +134,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL );
@@ -146,8 +146,7 @@ static void setup(void)make_swapfile (cleanup,"alreadyused" );if (ltp_syscall (__NR_swapon,"alreadyused" ,0 )) { -if (fs_type !=TST_BTRFS_MAGIC || errno !=EINVAL ) -tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); +tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); }else { do_swapoff =1 ; }
testcases/kernel/syscalls/swapon/swapon03.c +25 -27
120 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Quoted 2 lines · Murphy Zhou
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
If you wouldn't have just done that it would have been good. But your patch also changes a lot of the logic and output messages, which is less good.
For BTRFS, with a kernel that does not support swapon/off, test logic should have stayed the same and produce more or less the same output. This would have made review much easier and less chance of breaking things.
Quoted 51 lines
Leave swapoff02 alone because it's permission checking only in it.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase.include/tst_fs.h | 5 ++ lib/tst_ioctl.c | 39 ++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++------- testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ---- testcases/kernel/syscalls/swapon/swapon01.c | 23 ++++---- testcases/kernel/syscalls/swapon/swapon02.c | 31 ++++++----- testcases/kernel/syscalls/swapon/swapon03.c | 52 +++++++++---------- 7 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename,const char *fstype); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +8
-0@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> +
lib/tst_ioctl.c line 18
Quoted 10 lines
lib/tst_ioctl.c new file +10
-0+#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename,const char *fstype) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + +tst_res (TINFO ,"Testing if FIBMAP ioctl is supported on %s" , fstype);
passing the fstype into this helper seems quite irrelevant to me. the TINFO print doesn't justify it IMO
Its not even an important info IMO, so as long as you have the print when FIBMAP not supported
Quoted 34 lines
lib/tst_ioctl.c new file +21
-0+ + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0@@ -32,6 +32,7 @@ static void verify_swapoff(void);char *TCID ="swapoff01" ;int TST_TOTAL =1 ; +int fibmap =1 ;static long fs_type;
testcases/kernel/syscalls/swapoff/swapoff01.c int main(int ac, char **av) · line 59
Quoted 7 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-3@@ -55,22 +56,26 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); +if (fibmap ==1 ) {
This changes both logic and output message.
I don't see a good reason for you to do that.
Please keep the errno == EINVAL check and the message format for TCONF case Same comment for all the other places it applies
Quoted 10 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +6
-3+tst_resm (TBROK ,"Failed to turn on the swap file" +", skipping test iteration" ); +return ; + }else { +tst_resm (TCONF ,"Failed to turn on the swap file" +", keep going for sanity check" ); } - -tst_resm (TBROK ,"Failed to turn on the swap file" -", skipping test iteration" );
testcases/kernel/syscalls/swapoff/swapoff01.c int main(int ac, char **av) · line 72
Quoted 10 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-4-return ; }TEST (ltp_syscall (__NR_swapoff,"./swapfile01" ));if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," -" system reboot after execution of LTP " -"test suite is recommended." ); +if (fibmap ==1 ) {
No reason to do that.
If filesystem was already proven to support swpaon(), swapoff() must succeed. If fs doesn't support swapon(), test should bail out and not try swapoff()
Quoted 14 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +6
-1+tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," +" system reboot after execution of LTP " +"test suite is recommended." ); + }else { +tst_resm (TCONF ,"Failed to turn off swapfile" ); + } }else {tst_resm (TPASS ,"Succeeded to turn off swapfile" ); }@@ -86,13 +91,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) {
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 97
Quoted 10 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +4
-6-case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" );
Here printing fs name would be useful IMO
Quoted 5 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0+ fibmap =0 ; }if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) {
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 113
Quoted 10 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +5
-2@@ -103,8 +106,13 @@ static void setup(void)if (tst_fill_file ("swapfile01" ,0x00 ,1024 ,65536 ))tst_brkm (TBROK , cleanup,"Failed to create file for swap" ); -if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) -tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); +if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) { +if (fibmap ==1 ) { +tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); + }else { +tst_resm (TCONF ,"Failed to make swapfile" );
You see, this message does not align with the outcome (skip). Is this really needed? does mkswap fail on tmpfs? If it does, then surely the entire test can be skipped
Quoted 46 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +2
-0+ } + } }static void cleanup (void )testcases/kernel/syscalls/swapoff/swapoff02.c +0
-10@@ -124,7 +124,6 @@ static void cleanup01(void)static void setup (void ) { -long type;struct passwd *nobody;tst_sig (FORK ,DEF_HANDLER , cleanup);@@ -138,15 +137,6 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; - } -if (!tst_fs_has_free (NULL ,"." ,1 ,TST_KB )) {tst_brkm (TBROK , cleanup,"Insufficient disk space to create swap file" );testcases/kernel/syscalls/swapon/swapon01.c +1
-0@@ -31,6 +31,7 @@ static void cleanup(void);char *TCID ="swapon01" ;int TST_TOTAL =1 ; +int fibmap =1 ;static long fs_type;
testcases/kernel/syscalls/swapon/swapon01.c static void verify_swapon(void) · line 44
Quoted 9 lines
testcases/kernel/syscalls/swapon/swapon01.c +2
-4@@ -39,12 +40,11 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; +if (fibmap ==0 ) { +tst_resm (TCONF ,"Failed to turn on swapfile" );
Please take care to not change logic.
You replcaed tst_brkm with tst_resm. Intentional?
You also change the meaning of the warning message to the worse IMO
Quoted 47 lines
testcases/kernel/syscalls/swapon/swapon01.c +7
-9+ }else { +tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); } -tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); }else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );/*we need to turn this swap file off for -i option */ @@ -58,7 +58,6 @@ static void verify_swapon(void)int main (int ac,char **av) { -int lc;tst_parse_opts (ac, av,NULL ,NULL );@@ -84,13 +83,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }make_swapfile (cleanup,"swapfile01" );testcases/kernel/syscalls/swapon/swapon02.c +1
-0@@ -44,6 +44,7 @@ static void cleanup01(void);char *TCID ="swapon02" ;int TST_TOTAL =4 ; +int fibmap =1 ;static uid_t nobody_uid;static int do_swapoff;
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 88
Quoted 10 lines
testcases/kernel/syscalls/swapon/swapon02.c +4
-3@@ -81,14 +82,15 @@ static void verify_swapon(struct test_case_t *test)return ; } -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_resm (TCONF ,"Swapfile on BTRFS not implemeted" ); -return ; +if (fibmap ==1 ) { +tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" +" %d, errno: %s and got %d." , test->exp_errno, + test->exp_errval,TEST_ERRNO );
Changes message
Quoted 32 lines
testcases/kernel/syscalls/swapon/swapon02.c +9
-11+ }else { +tst_resm (TCONF ,"swapon(2) failed to produce expected error:" +" %d, errno: %s and got %d." , test->exp_errno, + test->exp_errval,TEST_ERRNO ); } - -tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" -" %d, errno: %s and got %d." , test->exp_errno, - test->exp_errval,TEST_ERRNO ); }int main (int ac,char **av)@@ -132,13 +134,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL );
testcases/kernel/syscalls/swapon/swapon02.c static void setup(void) · line 149
Quoted 6 lines
testcases/kernel/syscalls/swapon/swapon02.c +1
-2@@ -146,8 +146,7 @@ static void setup(void)make_swapfile (cleanup,"alreadyused" );if (ltp_syscall (__NR_swapon,"alreadyused" ,0 )) { -if (fs_type !=TST_BTRFS_MAGIC || errno !=EINVAL ) -tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); +tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" );
Change of logic for fibmap == 0 case
Quoted 141 lines
testcases/kernel/syscalls/swapon/swapon02.c +0
-0}else { do_swapoff =1 ; }testcases/kernel/syscalls/swapon/swapon03.c +25
-28@@ -49,6 +49,7 @@ static int check_and_swapoff(const char *filename);char *TCID ="swapon03" ;int TST_TOTAL =1 ; +int fibmap =1 ;static int swapfiles;@@ -65,6 +66,14 @@ static struct swap_testfile_t {int expected_errno =EPERM ; +void record_failure_soft (int flag,char *s,int exp,char *err) +{ +if (fibmap !=1 ) + flag =TCONF ; + +tst_resm (flag, s, exp, err); +} +int main (int ac,char **av) {int lc;@@ -88,10 +97,10 @@ int main(int ac, char **av)tst_resm (TPASS ,"swapon(2) got expected failure (%d)," , expected_errno); }else if (TEST_RETURN <0 ) { -tst_resm (TFAIL |TTERRNO , +record_failure_soft (TFAIL |TTERRNO ,"swapon(2) failed to produce expected error " -"(%d). System reboot recommended." , - expected_errno); +"(%d), got (%s). System reboot recommended." , + expected_errno,strerror (TEST_ERRNO )); }else {/* Probably the system supports MAX_SWAPFILES > 30, * let's try with MAX_SWAPFILES == 32 */ @@ -103,8 +112,10 @@ int main(int ac, char **av)/* Check return code (now we're expecting success) */ if (TEST_RETURN <0 ) { -tst_resm (TFAIL |TTERRNO , -"swapon(2) got an unexpected failure" ); +record_failure_soft (TFAIL |TTERRNO , +"swapon(2) got an unexpected failure" +"(%d: %s)." , +TEST_RETURN ,strerror (TEST_ERRNO )); }else {/* Call swapon sys call once again for 33 * now we have to receive an error */ @@ -121,7 +132,7 @@ int main(int ac, char **av)" MAX_SWAPFILES is 32" , expected_errno); }else { -tst_resm (TFAIL , +record_failure_soft (TFAIL ,"swapon(2) failed to produce" " expected error: %d, got %s." " System reboot after execution of LTP"@@ -141,7 +152,6 @@ int main(int ac, char **av)cleanup ();tst_exit (); - }/* @@ -215,9 +225,6 @@ static int setup_swap(void)/* turn on the swap file */ res =ltp_syscall (__NR_swapon, filename,0 );if (res !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) -exit (2 ); -if (errno ==EPERM ) {printf ("Successfully created %d " "swapfiles\n" , j);@@ -225,7 +232,8 @@ static int setup_swap(void) }else {printf ("Failed to create " "swapfile: %s\n" , filename); -exit (1 ); +if (fibmap ==1 ) +exit (1 ); } } }@@ -233,15 +241,8 @@ static int setup_swap(void) }else waitpid (pid, &status,0 ); -switch (WEXITSTATUS (status)) { -case 0 : -break ; -case 2 : -tst_brkm (TCONF , cleanup,"Swapfile on BTRFS not implemeted" ); -break ; -default : +if (WEXITSTATUS (status)) {tst_brkm (TFAIL , cleanup,"Failed to setup swaps" ); -break ; }/* Create all needed extra swapfiles for testing */ @@ -249,7 +250,6 @@ static int setup_swap(void)make_swapfile (cleanup, swap_testfiles[j].filename);return 0 ; - }/* @@ -333,13 +333,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }TEST_PAUSE ; --2.21.0
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Quoted 7 lines · Amir Goldstein
Quoted 2 lines · Murphy Zhou
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
If you wouldn't have just done that it would have been good. But your patch also changes a lot of the logic and output messages, which is less good.
First of all, don't be mad if you think I'm changing too much. :) I should have written more info here in commit message like in the changelog.
If FIBMAP trial fails, don't bail out immediately, go on to the rest of tests. Than don't report fail if swap* syscall fails, just record the failure info, acting like a sanity check test.
If FIBMAP trial pass, follow the original logic.
The whitelist code removal is kinda independent. But combining with the fibmap code it looks like a lot of logic changing.
Quoted 3 lines
For BTRFS, with a kernel that does not support swapon/off, test logic should have stayed the same and produce more or less the same output. This would have made review much easier and less chance of breaking things.
I can understand the test logic part, but why the same output matters? Since we are not using golden output like fstests :)
Back to the logic, checking specific return value is precise, but it i
hard to maintain them IMO. If kernel logic changes, it's easy to forget
updating testing logic. That's why I am fan of your whitelist avoiding idea. Now if I understand correctly, you want to keep the filesystems whitelist, fibmap test is just for the info. Am I right?
For better communication, I'd like to remove whitelist code. Can we have an alter opinion here?
Quoted 59 lines
Quoted 59 lines
Leave swapoff02 alone because it's permission checking only in it.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase.include/tst_fs.h | 5 ++ lib/tst_ioctl.c | 39 ++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++------- testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ---- testcases/kernel/syscalls/swapon/swapon01.c | 23 ++++---- testcases/kernel/syscalls/swapon/swapon02.c | 31 ++++++----- testcases/kernel/syscalls/swapon/swapon03.c | 52 +++++++++---------- 7 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename,const char *fstype); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +15
-0@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename,const char *fstype) +{ +/* test if FIBMAP ioctl is supported */
Quoted 8 lines
lib/tst_ioctl.c line 18
Quoted 3 lines
lib/tst_ioctl.c new file +3
-0+int fd, block =0 ; + +tst_res (TINFO ,"Testing if FIBMAP ioctl is supported on %s" , fstype);passing the fstype into this helper seems quite irrelevant to me. the TINFO print doesn't justify it IMO
Its not even an important info IMO, so as long as you have the print when FIBMAP not supported
That's for ensure the test taking place in the right dir. We can remove this.
Quoted 34 lines
Quoted 34 lines
lib/tst_ioctl.c new file +21
-0+ + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0@@ -32,6 +32,7 @@ static void verify_swapoff(void);char *TCID ="swapoff01" ;int TST_TOTAL =1 ; +int fibmap =1 ;static long fs_type;
Quoted 13 lines
testcases/kernel/syscalls/swapoff/swapoff01.c int main(int ac, char **av) · line 59
Quoted 8 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-3@@ -55,22 +56,26 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); +if (fibmap ==1 ) {This changes both logic and output message.
I don't see a good reason for you to do that.
Please keep the errno == EINVAL check and the message format for TCONF case Same comment for all the other places it applies
Explained at the beginning.
Quoted 22 lines
Quoted 11 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +6
-3+tst_resm (TBROK ,"Failed to turn on the swap file" +", skipping test iteration" ); +return ; + }else { +tst_resm (TCONF ,"Failed to turn on the swap file" +", keep going for sanity check" ); } - -tst_resm (TBROK ,"Failed to turn on the swap file" -", skipping test iteration" );testcases/kernel/syscalls/swapoff/swapoff01.c int main(int ac, char **av) · line 72
Quoted 10 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-4-return ; }TEST (ltp_syscall (__NR_swapoff,"./swapfile01" ));if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," -" system reboot after execution of LTP " -"test suite is recommended." ); +if (fibmap ==1 ) {
Quoted 3 lines
No reason to do that.
If filesystem was already proven to supportswpaon(),swapoff()must succeed. If fs doesn't supportswapon(), test should bail out and not tryswapoff()
If swapon() fails an fibmap == 0, we could be here for a sanity check. Big chance it will fail, but hey, don't panic.
Quoted 14 lines
Quoted 14 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +6
-0+tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," +" system reboot after execution of LTP " +"test suite is recommended." ); + }else { +tst_resm (TCONF ,"Failed to turn off swapfile" ); + } }else {tst_resm (TPASS ,"Succeeded to turn off swapfile" ); }@@ -86,13 +91,11 @@ static void setup(void)tst_tmpdir ();
Quoted 13 lines
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 97
Quoted 11 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +4
-7-switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" );Here printing fs name would be useful IMO
Ya, I did it here firstly.
Quoted 9 lines
Quoted 9 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0+ fibmap =0 ; }if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) {@@ -103,8 +106,13 @@ static void setup(void)if (tst_fill_file ("swapfile01" ,0x00 ,1024 ,65536 ))tst_brkm (TBROK , cleanup,"Failed to create file for swap" );
Quoted 9 lines
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 113
Quoted 7 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +5
-2-if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) -tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); +if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) { +if (fibmap ==1 ) { +tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); + }else { +tst_resm (TCONF ,"Failed to make swapfile" );You see, this message does not align with the outcome (skip).
Sorry, you lost me here.
Quoted 2 lines
Is this really needed? does mkswap fail on tmpfs? If it does, then surely the entire test can be skipped
Or fail silently with out reporting FAIL.
Quoted 49 lines
Quoted 49 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +2
-0+ } + } }static void cleanup (void )testcases/kernel/syscalls/swapoff/swapoff02.c +0
-10@@ -124,7 +124,6 @@ static void cleanup01(void)static void setup (void ) { -long type;struct passwd *nobody;tst_sig (FORK ,DEF_HANDLER , cleanup);@@ -138,15 +137,6 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; - } -if (!tst_fs_has_free (NULL ,"." ,1 ,TST_KB )) {tst_brkm (TBROK , cleanup,"Insufficient disk space to create swap file" );testcases/kernel/syscalls/swapon/swapon01.c +1
-0@@ -31,6 +31,7 @@ static void cleanup(void);char *TCID ="swapon01" ;int TST_TOTAL =1 ; +int fibmap =1 ;static long fs_type;@@ -39,12 +40,11 @@ static void verify_swapon(void)TEST (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ));
Quoted 11 lines
testcases/kernel/syscalls/swapon/swapon01.c static void verify_swapon(void) · line 44
Quoted 7 lines
testcases/kernel/syscalls/swapon/swapon01.c +2
-4if (TEST_RETURN ==-1 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfile on BTRFS not implemeted" ); -return ; +if (fibmap ==0 ) { +tst_resm (TCONF ,"Failed to turn on swapfile" );Please take care to not change logic.
You replcaedtst_brkmwithtst_resm. Intentional?
You also change the meaning of the warning message to the worse IMO
No no no, :) Removal of BTRFS case is one part, and the change of TFAIL report is another part.
Quoted 5 lines
testcases/kernel/syscalls/swapon/swapon01.c static void verify_swapon(void) · line 47
Quoted 5 lines
testcases/kernel/syscalls/swapon/swapon01.c +2
-1+ }else { +tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" ); } -tst_resm (TFAIL |TTERRNO ,"Failed to turn on swapfile" );
^^ tst_resm and msg come from this line.
Quoted 46 lines
Quoted 46 lines
testcases/kernel/syscalls/swapon/swapon01.c +5
-8}else {tst_resm (TPASS ,"Succeeded to turn on swapfile" );/*we need to turn this swap file off for -i option */ @@ -58,7 +58,6 @@ static void verify_swapon(void)int main (int ac,char **av) { -int lc;tst_parse_opts (ac, av,NULL ,NULL );@@ -84,13 +83,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }make_swapfile (cleanup,"swapfile01" );testcases/kernel/syscalls/swapon/swapon02.c +1
-0@@ -44,6 +44,7 @@ static void cleanup01(void);char *TCID ="swapon02" ;int TST_TOTAL =4 ; +int fibmap =1 ;static uid_t nobody_uid;static int do_swapoff;@@ -81,14 +82,15 @@ static void verify_swapon(struct test_case_t *test)return ; }
Quoted 9 lines
testcases/kernel/syscalls/swapon/swapon02.c static void verify_swapon(struct test_case_t *test) · line 88
Quoted 7 lines
testcases/kernel/syscalls/swapon/swapon02.c +4
-3-if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_resm (TCONF ,"Swapfile on BTRFS not implemeted" ); -return ; +if (fibmap ==1 ) { +tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" +" %d, errno: %s and got %d." , test->exp_errno, + test->exp_errval,TEST_ERRNO );Changes message
Ditto.
Quoted 35 lines
Quoted 35 lines
testcases/kernel/syscalls/swapon/swapon02.c +9
-11+ }else { +tst_resm (TCONF ,"swapon(2) failed to produce expected error:" +" %d, errno: %s and got %d." , test->exp_errno, + test->exp_errval,TEST_ERRNO ); } - -tst_resm (TFAIL ,"swapon(2) failed to produce expected error:" -" %d, errno: %s and got %d." , test->exp_errno, - test->exp_errval,TEST_ERRNO ); }int main (int ac,char **av)@@ -132,13 +134,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL );@@ -146,8 +146,7 @@ static void setup(void)make_swapfile (cleanup,"alreadyused" );
Quoted 6 lines
testcases/kernel/syscalls/swapon/swapon02.c static void setup(void) · line 149
Quoted 4 lines
testcases/kernel/syscalls/swapon/swapon02.c +1
-2if (ltp_syscall (__NR_swapon,"alreadyused" ,0 )) { -if (fs_type !=TST_BTRFS_MAGIC || errno !=EINVAL ) -tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" ); +tst_resm (TWARN |TERRNO ,"swapon(alreadyused) failed" );Change of logic for fibmap == 0 case
It's a warning no matter what fs it is.
Thanks!
M
Quoted 142 lines
Quoted 142 lines
testcases/kernel/syscalls/swapon/swapon02.c +0
-0}else { do_swapoff =1 ; }testcases/kernel/syscalls/swapon/swapon03.c +25
-28@@ -49,6 +49,7 @@ static int check_and_swapoff(const char *filename);char *TCID ="swapon03" ;int TST_TOTAL =1 ; +int fibmap =1 ;static int swapfiles;@@ -65,6 +66,14 @@ static struct swap_testfile_t {int expected_errno =EPERM ; +void record_failure_soft (int flag,char *s,int exp,char *err) +{ +if (fibmap !=1 ) + flag =TCONF ; + +tst_resm (flag, s, exp, err); +} +int main (int ac,char **av) {int lc;@@ -88,10 +97,10 @@ int main(int ac, char **av)tst_resm (TPASS ,"swapon(2) got expected failure (%d)," , expected_errno); }else if (TEST_RETURN <0 ) { -tst_resm (TFAIL |TTERRNO , +record_failure_soft (TFAIL |TTERRNO ,"swapon(2) failed to produce expected error " -"(%d). System reboot recommended." , - expected_errno); +"(%d), got (%s). System reboot recommended." , + expected_errno,strerror (TEST_ERRNO )); }else {/* Probably the system supports MAX_SWAPFILES > 30, * let's try with MAX_SWAPFILES == 32 */ @@ -103,8 +112,10 @@ int main(int ac, char **av)/* Check return code (now we're expecting success) */ if (TEST_RETURN <0 ) { -tst_resm (TFAIL |TTERRNO , -"swapon(2) got an unexpected failure" ); +record_failure_soft (TFAIL |TTERRNO , +"swapon(2) got an unexpected failure" +"(%d: %s)." , +TEST_RETURN ,strerror (TEST_ERRNO )); }else {/* Call swapon sys call once again for 33 * now we have to receive an error */ @@ -121,7 +132,7 @@ int main(int ac, char **av)" MAX_SWAPFILES is 32" , expected_errno); }else { -tst_resm (TFAIL , +record_failure_soft (TFAIL ,"swapon(2) failed to produce" " expected error: %d, got %s." " System reboot after execution of LTP"@@ -141,7 +152,6 @@ int main(int ac, char **av)cleanup ();tst_exit (); - }/* @@ -215,9 +225,6 @@ static int setup_swap(void)/* turn on the swap file */ res =ltp_syscall (__NR_swapon, filename,0 );if (res !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) -exit (2 ); -if (errno ==EPERM ) {printf ("Successfully created %d " "swapfiles\n" , j);@@ -225,7 +232,8 @@ static int setup_swap(void) }else {printf ("Failed to create " "swapfile: %s\n" , filename); -exit (1 ); +if (fibmap ==1 ) +exit (1 ); } } }@@ -233,15 +241,8 @@ static int setup_swap(void) }else waitpid (pid, &status,0 ); -switch (WEXITSTATUS (status)) { -case 0 : -break ; -case 2 : -tst_brkm (TCONF , cleanup,"Swapfile on BTRFS not implemeted" ); -break ; -default : +if (WEXITSTATUS (status)) {tst_brkm (TFAIL , cleanup,"Failed to setup swaps" ); -break ; }/* Create all needed extra swapfiles for testing */ @@ -249,7 +250,6 @@ static int setup_swap(void)make_swapfile (cleanup, swap_testfiles[j].filename);return 0 ; - }/* @@ -333,13 +333,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" ); + fibmap =0 ; }TEST_PAUSE ; --2.21.0
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Quoted 11 lines · Murphy Zhou
Quoted 7 lines · Amir Goldstein
Quoted 2 lines · Murphy Zhou
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
If you wouldn't have just done that it would have been good. But your patch also changes a lot of the logic and output messages, which is less good.
First of all, don't be mad if you think I'm changing too much. :)
Not mad. Sorry if came off this way..
Just trying to explain why too much changes can be counter productive. And I am writing my opinion, you are not obliged to agree with it ;-)
Quoted 5 lines
I should have written more info here in commit message like in the changelog.
If FIBMAP trial fails, don't bail out immediately, go on to the rest of tests. Than don't report fail if swap* syscall fails, just record the failure info, acting like a sanity check test.
In retrospect, I think the best approach is to do all the feature support testing in setup(). As someone else wrote, testing mkswap/swapon in setup() and keeping logic simpler in tests would be better.
Testing FIBMAP and then mkwap/swpaon/swapoff will make sure that test will detect regression in swpaon with filesystems that support FIBMAP. It will not guaranty that for BTRFS/NFS, but that is the tradeoff of not whitelisting.
Quoted 6 lines
If FIBMAP trial pass, follow the original logic.
The whitelist code removal is kinda independent. But combining with the fibmap code it looks like a lot of logic changing.
Quoted 6 lines
Quoted 3 lines
For BTRFS, with a kernel that does not support swapon/off, test logic should have stayed the same and produce more or less the same output. This would have made review much easier and less chance of breaking things.
I can understand the test logic part, but why the same output matters? Since we are not using golden output like fstests :)
Same output doesn't matter, but output was good and you have not made it better you have made it worse - I will explain below.
Quoted 6 lines
Back to the logic, checking specific return value is precise, but it i
hard to maintain them IMO. If kernel logic changes, it's easy to forget
updating testing logic. That's why I am fan of your whitelist avoiding idea. Now if I understand correctly, you want to keep the filesystems whitelist, fibmap test is just for the info. Am I right?
I meant you stopped checking errno == EINVAL, which is the only expected return value for fs that do not support swapon. If for some reason btrfs has a regression and swapon returns ENOSPC test MUST fail.
Quoted 146 lines
For better communication, I'd like to remove whitelist code. Can we have an alter opinion here?
Quoted 59 lines
Quoted 59 lines
Leave swapoff02 alone because it's permission checking only in it.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase.include/tst_fs.h | 5 ++ lib/tst_ioctl.c | 39 ++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++------- testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ---- testcases/kernel/syscalls/swapon/swapon01.c | 23 ++++---- testcases/kernel/syscalls/swapon/swapon02.c | 31 ++++++----- testcases/kernel/syscalls/swapon/swapon03.c | 52 +++++++++---------- 7 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename,const char *fstype); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +15
-0@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename,const char *fstype) +{ +/* test if FIBMAP ioctl is supported */ Quoted 8 lines
lib/tst_ioctl.c line 18
Quoted 3 lines
lib/tst_ioctl.c new file +3
-0+int fd, block =0 ; + +tst_res (TINFO ,"Testing if FIBMAP ioctl is supported on %s" , fstype);passing the fstype into this helper seems quite irrelevant to me. the TINFO print doesn't justify it IMO
Its not even an important info IMO, so as long as you have the print when FIBMAP not supportedThat's for ensure the test taking place in the right dir. We can remove this.
Quoted 34 lines
Quoted 34 lines
lib/tst_ioctl.c new file +21
-0+ + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0@@ -32,6 +32,7 @@ static void verify_swapoff(void);char *TCID ="swapoff01" ;int TST_TOTAL =1 ; +int fibmap =1 ;static long fs_type;Quoted 13 lines
testcases/kernel/syscalls/swapoff/swapoff01.c int main(int ac, char **av) · line 59
Quoted 8 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-3@@ -55,22 +56,26 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); +if (fibmap ==1 ) {This changes both logic and output message.
I don't see a good reason for you to do that.
Please keep the errno == EINVAL check and the message format for TCONF case Same comment for all the other places it appliesExplained at the beginning.
Quoted 22 lines
Quoted 21 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +7
-7+tst_resm (TBROK ,"Failed to turn on the swap file" +", skipping test iteration" ); +return ; + }else { +tst_resm (TCONF ,"Failed to turn on the swap file" +", keep going for sanity check" ); } - -tst_resm (TBROK ,"Failed to turn on the swap file" -", skipping test iteration" ); -return ; }TEST (ltp_syscall (__NR_swapoff,"./swapfile01" ));if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," -" system reboot after execution of LTP " -"test suite is recommended." ); +if (fibmap ==1 ) {
Quoted 6 lines
Quoted 3 lines
No reason to do that.
If filesystem was already proven to supportswpaon(),swapoff()must succeed. If fs doesn't supportswapon(), test should bail out and not tryswapoff()If
swapon()fails an fibmap == 0, we could be here for a sanity check. Big chance it will fail, but hey, don't panic.
Of course swapoff will fail if swpaon failed.
Should abort when swapon fails.
Quoted 50 lines
Quoted 15 lines
Quoted 15 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +6
-0+tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," +" system reboot after execution of LTP " +"test suite is recommended." ); + }else { +tst_resm (TCONF ,"Failed to turn off swapfile" ); + } }else {tst_resm (TPASS ,"Succeeded to turn off swapfile" ); }@@ -86,13 +91,11 @@ static void setup(void)tst_tmpdir ();Quoted 13 lines
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 97
Quoted 11 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +4
-7-switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" );Here printing fs name would be useful IMO
Ya, I did it here firstly.
Quoted 9 lines
Quoted 9 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0+ fibmap =0 ; }if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) {@@ -103,8 +106,13 @@ static void setup(void)if (tst_fill_file ("swapfile01" ,0x00 ,1024 ,65536 ))tst_brkm (TBROK , cleanup,"Failed to create file for swap" );Quoted 9 lines
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 113
Quoted 7 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +5
-2-if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) -tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); +if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) { +if (fibmap ==1 ) { +tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); + }else { +tst_resm (TCONF ,"Failed to make swapfile" );You see, this message does not align with the outcome (skip).
Quoted 2 lines
Sorry, you lost me here.
Put your tester hat on. Imagine you do not know what swapfile is nor that filesystems may support it or not.
Which is the following messages convey the test result better:
TCONF: Failed to make swapfile
OR
TCONF: mkswap not supported on btrfs filesystem
If test setup arrives to a conclusion that filesystem doesn't support test and test should be skipped, that is what should be communicated to user.
The BTRFS_MAGIC code that your patch removes does that correctly. Your patch does not.
Even the message:
TCONF: "Will not report FAIL as FIBMAP ioctl not supported" is "too much information" IMO.
Users without proper background won't know what it means. This would have been better IMO:
TCONF: "FIBMAP ioctl not supported on XXX filesystem"
Thanks,
Amir.
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Murphy Zhou
Quoted 7 lines · Amir Goldstein
Quoted 2 lines · Murphy Zhou
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
If you wouldn't have just done that it would have been good. But your patch also changes a lot of the logic and output messages, which is less good.
Quoted 5 lines
Quoted 1 line
First of all, don't be mad if you think I'm changing too much. :)
Not mad. Sorry if came off this way..
Just trying to explain why too much changes can be counter productive. And I am writing my opinion, you are not obliged to agree with it ;-)
Start your developer engine. Actually _think_ about what your're writing. Your opinion varies every single post in this thread.
Quoted 38 lines
Quoted 6 lines
I should have written more info here in commit message like in the changelog.
If FIBMAP trial fails, don't bail out immediately, go on to the rest of tests. Than don't report fail if swap* syscall fails, just record the failure info, acting like a sanity check test.
In retrospect, I think the best approach is to do all the feature support testing in
setup(). As someone else wrote, testing mkswap/swapon insetup()and keeping logic simpler in tests would be better.
Testing FIBMAP and then mkwap/swpaon/swapoff will make sure that test will detect regression in swpaon with filesystems that support FIBMAP. It will not guaranty that for BTRFS/NFS, but that is the tradeoff of not whitelisting.Quoted 6 lines
If FIBMAP trial pass, follow the original logic.
The whitelist code removal is kinda independent. But combining with the fibmap code it looks like a lot of logic changing.
Quoted 6 lines
Quoted 3 lines
For BTRFS, with a kernel that does not support swapon/off, test logic should have stayed the same and produce more or less the same output. This would have made review much easier and less chance of breaking things.
I can understand the test logic part, but why the same output matters? Since we are not using golden output like fstests :)
Same output doesn't matter, but output was good and you have not made it better you have made it worse - I will explain below.
Quoted 6 lines
Back to the logic, checking specific return value is precise, but it i
hard to maintain them IMO. If kernel logic changes, it's easy to forget
updating testing logic. That's why I am fan of your whitelist avoiding idea. Now if I understand correctly, you want to keep the filesystems whitelist, fibmap test is just for the info. Am I right?
Quoted 4 lines
I meant you stopped checking errno == EINVAL, which is the only expected return value for fs that do not support swapon. If for some reason btrfs has a regression and swapon returns ENOSPC test MUST fail.
Ah, this is new to me.
Quoted 214 lines
Quoted 147 lines
For better communication, I'd like to remove whitelist code. Can we have an alter opinion here?
Quoted 59 lines
Quoted 59 lines
Leave swapoff02 alone because it's permission checking only in it.
Signed-off-by Murphy Zhou <[email protected]>---
v2:
Test FIBMAP instead of fstype whitelist.
v3:
Fixfs_typeundeclared inswapoff01.c.
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase.include/tst_fs.h | 5 ++ lib/tst_ioctl.c | 39 ++++++++++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++------- testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ---- testcases/kernel/syscalls/swapon/swapon01.c | 23 ++++---- testcases/kernel/syscalls/swapon/swapon02.c | 31 ++++++----- testcases/kernel/syscalls/swapon/swapon03.c | 52 +++++++++---------- 7 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename,const char *fstype); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +15
-0@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename,const char *fstype) +{ +/* test if FIBMAP ioctl is supported */ Quoted 8 lines
lib/tst_ioctl.c line 18
Quoted 3 lines
lib/tst_ioctl.c new file +3
-0+int fd, block =0 ; + +tst_res (TINFO ,"Testing if FIBMAP ioctl is supported on %s" , fstype);passing the fstype into this helper seems quite irrelevant to me. the TINFO print doesn't justify it IMO
Its not even an important info IMO, so as long as you have the print when FIBMAP not supportedThat's for ensure the test taking place in the right dir. We can remove this.
Quoted 34 lines
Quoted 34 lines
lib/tst_ioctl.c new file +21
-0+ + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0@@ -32,6 +32,7 @@ static void verify_swapoff(void);char *TCID ="swapoff01" ;int TST_TOTAL =1 ; +int fibmap =1 ;static long fs_type;Quoted 13 lines
testcases/kernel/syscalls/swapoff/swapoff01.c int main(int ac, char **av) · line 59
Quoted 8 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-3@@ -55,22 +56,26 @@ int main(int ac, char **av)static void verify_swapoff (void ) {if (ltp_syscall (__NR_swapon,"./swapfile01" ,0 ) !=0 ) { -if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { -tst_brkm (TCONF , cleanup, -"Swapfiles on BTRFS are not implemented" ); +if (fibmap ==1 ) {This changes both logic and output message.
I don't see a good reason for you to do that.
Please keep the errno == EINVAL check and the message format for TCONF case Same comment for all the other places it appliesExplained at the beginning.
Quoted 22 lines
Quoted 21 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +7
-7+tst_resm (TBROK ,"Failed to turn on the swap file" +", skipping test iteration" ); +return ; + }else { +tst_resm (TCONF ,"Failed to turn on the swap file" +", keep going for sanity check" ); } - -tst_resm (TBROK ,"Failed to turn on the swap file" -", skipping test iteration" ); -return ; }TEST (ltp_syscall (__NR_swapoff,"./swapfile01" ));if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," -" system reboot after execution of LTP " -"test suite is recommended." ); +if (fibmap ==1 ) {Quoted 6 lines
Quoted 3 lines
No reason to do that.
If filesystem was already proven to supportswpaon(),swapoff()must succeed. If fs doesn't supportswapon(), test should bail out and not tryswapoff()If
swapon()fails an fibmap == 0, we could be here for a sanity check. Big chance it will fail, but hey, don't panic.Of course swapoff will fail if swpaon failed.
Should abort when swapon fails.Quoted 50 lines
Quoted 15 lines
Quoted 15 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +6
-0+tst_resm (TFAIL |TTERRNO ,"Failed to turn off swapfile," +" system reboot after execution of LTP " +"test suite is recommended." ); + }else { +tst_resm (TCONF ,"Failed to turn off swapfile" ); + } }else {tst_resm (TPASS ,"Succeeded to turn off swapfile" ); }@@ -86,13 +91,11 @@ static void setup(void)tst_tmpdir ();Quoted 13 lines
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 97
Quoted 11 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +4
-7-switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; + fs_type =tst_fs_type (cleanup,"." ); +if (tst_fibmap ("./tst_fibmap" ,tst_fs_type_name (fs_type))) { +tst_resm (TCONF , +"Will not report FAIL as FIBMAP ioctl not supported" );Here printing fs name would be useful IMO
Ya, I did it here firstly.
Quoted 9 lines
Quoted 9 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +1
-0+ fibmap =0 ; }if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) {@@ -103,8 +106,13 @@ static void setup(void)if (tst_fill_file ("swapfile01" ,0x00 ,1024 ,65536 ))tst_brkm (TBROK , cleanup,"Failed to create file for swap" );Quoted 9 lines
testcases/kernel/syscalls/swapoff/swapoff01.c static void setup(void) · line 113
Quoted 7 lines
testcases/kernel/syscalls/swapoff/swapoff01.c +5
-2-if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) -tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); +if (system ("mkswap swapfile01 > tmpfile 2>&1" ) !=0 ) { +if (fibmap ==1 ) { +tst_brkm (TBROK , cleanup,"Failed to make swapfile" ); + }else { +tst_resm (TCONF ,"Failed to make swapfile" );You see, this message does not align with the outcome (skip).
Quoted 2 lines
Sorry, you lost me here.
Put your tester hat on. Imagine you do not know what swapfile is nor that filesystems may support it or not.
Which is the following messages convey the test result better:
Quoted 5 lines
TCONF: Failed to make swapfile
OR
TCONF: mkswap not supported on btrfs filesystem
You are ranting at wrong guy. It was not me writing this message.
Quoted 7 lines
If test setup arrives to a conclusion that filesystem doesn't support test and test should be skipped, that is what should be communicated to user.
The
BTRFS_MAGICcode that your patch removes does that correctly. Your patch does not.
Quoted 6 lines
Even the message:
TCONF: "Will not report FAIL as FIBMAP ioctl not supported" is "too much information" IMO.
Users without proper background won't know what it means. This would have been better IMO:
TCONF: "FIBMAP ioctl not supported on XXX filesystem"
I guess LTP is not a desktop app :), but yes these messages need improvement.
Thanks,
M
Quoted 3 lines
Thanks,
Amir.
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Quoted 13 lines · Murphy Zhou
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Murphy Zhou
Quoted 7 lines · Amir Goldstein
Quoted 2 lines · Murphy Zhou
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
If you wouldn't have just done that it would have been good. But your patch also changes a lot of the logic and output messages, which is less good.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
First of all, don't be mad if you think I'm changing too much. :)
Not mad. Sorry if came off this way..
Just trying to explain why too much changes can be counter productive. And I am writing my opinion, you are not obliged to agree with it ;-)Start your developer engine. Actually _think_ about what your're writing. Your opinion varies every single post in this thread.
I sense that I offended you. I did not mean to. I apologize. There might have been some miscommunication.
My option varied after incorporating feedback from Li Wang and looking closer at recent kernel changes to btrfs, which I was not aware of.
To be clear, my current opinion is:
- As Li suggested, it is best to check filesystem support in setup() using swapon()
and the rest of the test should not relax any failure
- By checking FIBMAP before swapon() in setup() you can differentiate between failing the test (for legacy fs) or TCONF (BTRFS, NFS)
- TCONF result should be accompanied with "not supported" language
- Take care not to change test logic in a way that will regress test on older kernels or some filesystem
[...]
Quoted 4 lines
Quoted 4 lines
Put your tester hat on. Imagine you do not know what swapfile is nor that filesystems may support it or not.
Which is the following messages convey the test result better:
Quoted 8 lines
Quoted 5 lines
TCONF: Failed to make swapfile
OR
TCONF: mkswap not supported on btrfs filesystem
You are ranting at wrong guy. It was not me writing this message.
Certainly. It wasn't my intention to blame you for anything. The developer that wrote this message did not expect tmpfs to reach this point, because blacklist was in place.
By changing from TBROK to TCONF, the message may need to change from a language of "Failed" to a language of "not supported".
Quoted 7 lines
Quoted 7 lines
If test setup arrives to a conclusion that filesystem doesn't support test and test should be skipped, that is what should be communicated to user.
The
BTRFS_MAGICcode that your patch removes does that correctly. Your patch does not.
Quoted 9 lines
Quoted 6 lines
Even the message:
TCONF: "Will not report FAIL as FIBMAP ioctl not supported" is "too much information" IMO.
Users without proper background won't know what it means. This would have been better IMO:
TCONF: "FIBMAP ioctl not supported on XXX filesystem"I guess LTP is not a desktop app :), but yes these messages need improvement.
Test engineers can spend a lot of time figuring out why a certain test (of a feature they
are not intimately familiar with) has started failing on a certain kernel version or after
getting latest LTP.
We should be sympathetic to our end users and try to make their lives easier if it is
in our power.
Thanks,
Amir.
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Quoted 20 lines · Amir Goldstein
Quoted 19 lines · Murphy Zhou
Quoted 16 lines · Amir Goldstein
Quoted 11 lines · Murphy Zhou
Quoted 7 lines · Amir Goldstein
Quoted 2 lines · Murphy Zhou
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
If you wouldn't have just done that it would have been good. But your patch also changes a lot of the logic and output messages, which is less good.
First of all, don't be mad if you think I'm changing too much. :)
Not mad. Sorry if came off this way..
Just trying to explain why too much changes can be counter productive. And I am writing my opinion, you are not obliged to agree with it ;-)
Quoted 6 lines
Quoted 3 lines
Start your developer engine. Actually _think_ about what your're writing. Your opinion varies every single post in this thread.
I sense that I offended you. I did not mean to. I apologize. There might have been some miscommunication.
Nevermind.
Quoted 12 lines
My option varied after incorporating feedback from Li Wang and looking closer at recent kernel changes to btrfs, which I was not aware of.
To be clear, my current opinion is:
- As Li suggested, it is best to check filesystem support insetup()usingswapon()
and the rest of the test should not relax any failure
- By checking FIBMAP beforeswapon()insetup()you can differentiate between failing the test (for legacy fs) or TCONF (BTRFS, NFS)
- TCONF result should be accompanied with "not supported" language
- Take care not to change test logic in a way that will regress test on older kernels or some filesystem
Crystal clear now and I agree.
Quoted 12 lines
[...]
Quoted 10 lines
Quoted 9 lines
Put your tester hat on. Imagine you do not know what swapfile is nor that filesystems may support it or not.
Which is the following messages convey the test result better:TCONF: Failed to make swapfile
OR
TCONF: mkswap not supported on btrfs filesystem
Quoted 8 lines
Quoted 2 lines
You are ranting at wrong guy. It was not me writing this message.
Certainly. It wasn't my intention to blame you for anything. The developer that wrote this message did not expect tmpfs to reach this point, because blacklist was in place.
By changing from TBROK to TCONF, the message may need to change from a language of "Failed" to a language of "not supported".
Fare enough.
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
If test setup arrives to a conclusion that filesystem doesn't support test and test should be skipped, that is what should be communicated to user.
The
BTRFS_MAGICcode that your patch removes does that correctly. Your patch does not.Quoted 9 lines
Quoted 6 lines
Even the message:
TCONF: "Will not report FAIL as FIBMAP ioctl not supported" is "too much information" IMO.
Users without proper background won't know what it means. This would have been better IMO:
TCONF: "FIBMAP ioctl not supported on XXX filesystem"I guess LTP is not a desktop app :), but yes these messages need improvement.
Quoted 8 lines
Test engineers can spend a lot of time figuring out why a certain test (of a feature they
are not intimately familiar with) has started failing on a certain kernel version or after
getting latest LTP.
We should be sympathetic to our end users and try to make their lives easier if it is
in our power.
Can't agree more. :)
Thanks,
M
Quoted 3 lines
Thanks,
Amir.
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Hi!
Guys what should I merge in the end?
Looking at the conversation v4 was not final patch, or was it?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
Hi,
I'm working on a new version based on Amir's comments. Will post later. Sorry for the confusion :)
Murphy
Quoted 8 lines · Cyril Hrubis
Hi!
Guys what should I merge in the end?Looking at the conversation v4 was not final patch, or was it?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v5 1/4 lib/tst_ioctl.c: add helper tst_fibmap
In reply to Cyril HrubisTo check if FIBMAP ioctl is supported on the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now.
---
v5:
Split to 4 patches
Only take one filename parameter in tst_fibmap
Add helper is_swap_supported to check swap operation support status Test fibmap/swapon and swapoff operation in the helper Keep NFS/TMPFS whitelist
Keep BTRFS EINVAL handling logic, except above 2 situation:
if swapon fails and fibmap is not supported, tst_brk with TCONF if swapon fails and fibmap is supported, tst_brk with TFAIL
If swapon test pass in the helper, test swapoff similarly Put is_swap_supported helper in libswapon, link swapoff binaries to it Mute a sprintf filaname wanrning by the way
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
Fix fs_type undeclared in swapoff01.c
v2:
Test FIBMAP instead of fstype whitelist
include/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/tst_ioctl.c
include/tst_fs.h +5 -0
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {
lib/tst_ioctl.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}
Signature · 1 line
2.21.0
PATCH v5 2/4 swapon/libswapon: add helper is_swap_supported
To check if the filesystem we are testing on supports swapon/swapoff operations. Keep NFS and TMPFS on the white list. Don't report fail if BTRFS fails with EINVAL.
--- testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++ testcases/kernel/syscalls/swapon/libswapon.h | 6 +++ 2 files changed, 62 insertions(+)
testcases/kernel/syscalls/swapon/libswapon.c +56 -0
@@ -19,6 +19,8 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h"
@@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); } + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *ops, +const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +/* whitelist legacy fs */ +switch (fs_type) { +case TST_NFS_MAGIC : +case TST_TMPFS_MAGIC : +tst_brkm (TCONF , cleanup, +"Cannot do %s on a file on %s filesystem" , + ops, fstype); +break ; + } + +make_swapfile (NULL , filename); + +TEST (ltp_syscall (__NR_swapon, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) { +tst_brkm (TCONF , cleanup, +"Swapfile on BTRFS not implemented" ); + }else { +if (fibmap ==0 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + }else { +tst_brkm (TCONF , cleanup, +"swapon on %s is not supported" , + fstype); + } + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fibmap ==0 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + }else { +tst_brkm (TCONF , cleanup, +"swapoff on %s is not supported" , fstype); + } + } +}
testcases/kernel/syscalls/swapon/libswapon.h +6 -0
@@ -31,4 +31,10 @@*/ void make_swapfile (void (cleanup )(void ),const char *swapfile); +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *ops, +const char *filename);#endif /* __LIBSWAPON_H__ */
Signature · 1 line
2.21.0
PATCH v5 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 4 lines · Murphy Zhou
To check if the filesystem we are testing on supports swapon/swapoff operations. Keep NFS and TMPFS on the white list. Don't report fail if BTRFS fails with EINVAL.
Changes look very good, but I don't think you need the whitelist anymore...
Quoted 35 lines
Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++ testcases/kernel/syscalls/swapon/libswapon.h | 6 +++ 2 files changed, 62 insertions(+)testcases/kernel/syscalls/swapon/libswapon.c +13
-0@@ -19,6 +19,8 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); } + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *ops, +const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type);
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 72
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+ +/* whitelist legacy fs */ +switch (fs_type) { +case TST_NFS_MAGIC : +case TST_TMPFS_MAGIC : +tst_brkm (TCONF , cleanup, +"Cannot do %s on a file on %s filesystem" , + ops, fstype); +break ; + }
If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case and result in tst_brkm(TCONF anyway.
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 79
Quoted 7 lines
testcases/kernel/syscalls/swapon/libswapon.c +7
-0+ +make_swapfile (NULL , filename); + +TEST (ltp_syscall (__NR_swapon, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) {
If you replace (fs_type == TST_BTRFS_MAGIC) with (fibmap != 0) then NFS swapfile support could be tested as well and you do not special case any filesystem.
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 83
Quoted 4 lines
testcases/kernel/syscalls/swapon/libswapon.c +4
-0+tst_brkm (TCONF , cleanup, +"Swapfile on BTRFS not implemented" ); + }else { +if (fibmap ==0 ) {
and then you don't need this extra test.
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + }else { +tst_brkm (TCONF , cleanup, +"swapon on %s is not supported" , + fstype); + } + } + } +
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 103
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+TEST (ltp_syscall (__NR_swapoff, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fibmap ==0 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + }else { +tst_brkm (TCONF , cleanup, +"swapoff on %s is not supported" , fstype); + }
I don't think there should be any TCONF here.
If we reached here then swapon is supported - in that case failure to swapoff is a real failure.
Thanks,
Amir.
PATCH v5 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 57 lines · Amir Goldstein
Quoted 4 lines · Murphy Zhou
To check if the filesystem we are testing on supports swapon/swapoff operations. Keep NFS and TMPFS on the white list. Don't report fail if BTRFS fails with EINVAL.
Changes look very good, but I don't think you need the whitelist anymore...
Quoted 35 lines
Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++ testcases/kernel/syscalls/swapon/libswapon.h | 6 +++ 2 files changed, 62 insertions(+)testcases/kernel/syscalls/swapon/libswapon.c +13
-0@@ -19,6 +19,8 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); } + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *ops, +const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type);testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 72
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+ +/* whitelist legacy fs */ +switch (fs_type) { +case TST_NFS_MAGIC : +case TST_TMPFS_MAGIC : +tst_brkm (TCONF , cleanup, +"Cannot do %s on a file on %s filesystem" , + ops, fstype); +break ; + }If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case and result in tst_brkm(TCONF anyway.
Quoted 11 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 79
Quoted 7 lines
testcases/kernel/syscalls/swapon/libswapon.c +7
-0+ +make_swapfile (NULL , filename); + +TEST (ltp_syscall (__NR_swapon, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) {If you replace (
fs_type==TST_BTRFS_MAGIC) with (fibmap != 0) then NFS swapfile support could be tested as well and you do not special case any filesystem.
Very good idea!
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 83
Quoted 6 lines
testcases/kernel/syscalls/swapon/libswapon.c +4
-0+tst_brkm (TCONF , cleanup, +"Swapfile on BTRFS not implemented" ); + }else { +if (fibmap ==0 ) {and then you don't need this extra test.
Yes.
Quoted 17 lines
Quoted 17 lines
testcases/kernel/syscalls/swapon/libswapon.c +16
-0+tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + }else { +tst_brkm (TCONF , cleanup, +"swapon on %s is not supported" , + fstype); + } + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fibmap ==0 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype);
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 103
Quoted 4 lines
testcases/kernel/syscalls/swapon/libswapon.c +4
-0+ }else { +tst_brkm (TCONF , cleanup, +"swapoff on %s is not supported" , fstype); + }I don't think there should be any TCONF here.
If we reached here then swapon is supported - in that case failure to swapoff is a real failure.
Hmm.. make perfect sense. I have felt this test here was a little odd..
Thanks!
I'll tests this more on different filesystems and then post again.
--
Murphy
Quoted 3 lines
Thanks,
Amir.
PATCH v5 2/4 swapon/libswapon: add helper is_swap_supported
In reply to Amir GoldsteinQuoted 57 lines · Amir Goldstein
Quoted 4 lines · Murphy Zhou
To check if the filesystem we are testing on supports swapon/swapoff operations. Keep NFS and TMPFS on the white list. Don't report fail if BTRFS fails with EINVAL.
Changes look very good, but I don't think you need the whitelist anymore...
Quoted 35 lines
Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++ testcases/kernel/syscalls/swapon/libswapon.h | 6 +++ 2 files changed, 62 insertions(+)testcases/kernel/syscalls/swapon/libswapon.c +13
-0@@ -19,6 +19,8 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); } + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *ops, +const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type);testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 72
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+ +/* whitelist legacy fs */ +switch (fs_type) { +case TST_NFS_MAGIC : +case TST_TMPFS_MAGIC : +tst_brkm (TCONF , cleanup, +"Cannot do %s on a file on %s filesystem" , + ops, fstype); +break ; + }If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case and result in tst_brkm(TCONF anyway.
Quoted 11 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 79
Quoted 7 lines
testcases/kernel/syscalls/swapon/libswapon.c +7
-0+ +make_swapfile (NULL , filename); + +TEST (ltp_syscall (__NR_swapon, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) {If you replace (
fs_type==TST_BTRFS_MAGIC) with (fibmap != 0) then NFS swapfile support could be tested as well and you do not special case any filesystem.
There is a surprise that on old kernels, 2.6.32 based, this change would TBROK whitelisted NFS TCONF while mkswap swapfiles.
TBROK on mkswap failure seems the right thing to do, but the whitelist here intended to fix this false alarm.
I remember Li suggested that un-whitelist NFS would break old distros. TMPFS is fine.
Maybe we should safely check if mkswap is doable before checking swapon? mkswap fail, fibmap fail --> tst_brk TCONF
mkswap fail, fibmap pass --> tst_brk TFAIL
Thanks,
Murphy
Quoted 36 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 83
Quoted 6 lines
testcases/kernel/syscalls/swapon/libswapon.c +4
-0+tst_brkm (TCONF , cleanup, +"Swapfile on BTRFS not implemented" ); + }else { +if (fibmap ==0 ) {and then you don't need this extra test.
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + }else { +tst_brkm (TCONF , cleanup, +"swapon on %s is not supported" , + fstype); + } + } + } +testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 103
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+TEST (ltp_syscall (__NR_swapoff, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fibmap ==0 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + }else { +tst_brkm (TCONF , cleanup, +"swapoff on %s is not supported" , fstype); + }I don't think there should be any TCONF here.
If we reached here then swapon is supported - in that case failure to swapoff is a real failure.Thanks,
Amir.
PATCH v5 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 77 lines · Murphy Zhou
Quoted 57 lines · Amir Goldstein
Quoted 4 lines · Murphy Zhou
To check if the filesystem we are testing on supports swapon/swapoff operations. Keep NFS and TMPFS on the white list. Don't report fail if BTRFS fails with EINVAL.
Changes look very good, but I don't think you need the whitelist anymore...
Quoted 35 lines
Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++ testcases/kernel/syscalls/swapon/libswapon.h | 6 +++ 2 files changed, 62 insertions(+)testcases/kernel/syscalls/swapon/libswapon.c +13
-0@@ -19,6 +19,8 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); } + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *ops, +const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type);testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 72
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+ +/* whitelist legacy fs */ +switch (fs_type) { +case TST_NFS_MAGIC : +case TST_TMPFS_MAGIC : +tst_brkm (TCONF , cleanup, +"Cannot do %s on a file on %s filesystem" , + ops, fstype); +break ; + }If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case and result in tst_brkm(TCONF anyway.
Quoted 11 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 79
Quoted 7 lines
testcases/kernel/syscalls/swapon/libswapon.c +7
-0+ +make_swapfile (NULL , filename); + +TEST (ltp_syscall (__NR_swapon, filename,0 )); + +if (TEST_RETURN ==-1 ) { +if (fs_type ==TST_BTRFS_MAGIC && errno ==EINVAL ) {If you replace (
fs_type==TST_BTRFS_MAGIC) with (fibmap != 0) then NFS swapfile support could be tested as well and you do not special case any filesystem.There is a surprise that on old kernels, 2.6.32 based, this change would TBROK whitelisted NFS TCONF while mkswap swapfiles.
TBROK on mkswap failure seems the right thing to do, but the whitelist here intended to fix this false alarm.
Quoted 7 lines
I remember Li suggested that un-whitelist NFS would break old distros. TMPFS is fine.
Maybe we should safely check if mkswap is doable before checking swapon? mkswap fail, fibmap fail -->
tst_brkTCONF
mkswap fail, fibmap pass -->tst_brkTFAIL
Makes sense to me.
Thanks,
Amir.
PATCH v6 1/4 lib/tst_ioctl.c: add helper tst_fibmap
To check if FIBMAP ioctl is supported on the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now.
---
v6:
Modify make_swapfile() to check mkswap support status safely Remove whitelist
Remove BTRFS EINVAL check
Check mkswap status before testing swapon in helper
If swapon pass, following swapoff failure will fail the whole test and break Also modify swapoff02 to remove whitelist completely
v5:
Split to 4 patches
Only take one filename parameter in tst_fibmap
Add helper is_swap_supported to check swap operation support status Test fibmap/swapon and swapoff operation in the helper
Keep NFS/TMPFS whitelist
Keep BTRFS EINVAL handling logic, except above 2 situation:
if swapon fails and fibmap is not supported, tst_brk with TCONF if swapon fails and fibmap is supported, tst_brk with TFAIL
If swapon test pass in the helper, test swapoff similarly
Put is_swap_supported helper in libswapon, link swapoff binaries to it Mute a sprintf filaname wanrning by the way
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
Fix fs_type undeclared in swapoff01.c
v2:
Test FIBMAP instead of fstype whitelist
include/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/tst_ioctl.c
include/tst_fs.h +5 -0
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {
lib/tst_ioctl.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}
Signature · 1 line
2.21.0
PATCH v6 1/4 lib/tst_ioctl.c: add helper tst_fibmap
Ping on this one.
Thanks~
Quoted 99 lines · Murphy Zhou
To check if FIBMAP ioctl is supported on the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now.
Signed-off-by Murphy Zhou <[email protected]>---
v6:
Modifymake_swapfile()to check mkswap support status safely Remove whitelist
Remove BTRFS EINVAL check
Check mkswap status before testing swapon in helper
If swapon pass, following swapoff failure will fail the whole test and break Also modify swapoff02 to remove whitelist completely
v5:
Split to 4 patches
Only take one filename parameter intst_fibmap
Add helperis_swap_supportedto check swap operation support status Test fibmap/swapon and swapoff operation in the helper
Keep NFS/TMPFS whitelist
Keep BTRFS EINVAL handling logic, except above 2 situation:
if swapon fails and fibmap is not supported,tst_brkwith TCONF if swapon fails and fibmap is supported,tst_brkwith TFAIL
If swapon test pass in the helper, test swapoff similarly
Putis_swap_supportedhelper in libswapon, link swapoff binaries to it Mute a sprintf filaname wanrning by the way
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
Fixfs_typeundeclared inswapoff01.c
v2:
Test FIBMAP instead of fstype whitelistinclude/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +37
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return 1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ; + } +return 0 ; +}Signature · 1 line
2.21.0
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
In reply to Murphy ZhouTo check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations.
Modify make_swapfile function to test mkswap support status safely.
--- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/swapon/libswapon.c +43 -2
@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" /* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe) {if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {
@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); +return tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" , safe); +} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 ); +if (ret !=0 ) { +if (fibmap !=0 ) { +tst_brkm (TCONF , cleanup, +"mkswap on %s not supported" , fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap !=0 && errno ==EINVAL ) { +tst_brkm (TCONF , cleanup, +"Swapfile on %s not implemented" , fstype); + }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }
testcases/kernel/syscalls/swapon/libswapon.h +6 -1
@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe); +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */
Signature · 1 line
2.21.0
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 6 lines · Murphy Zhou
To check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations.
Modifymake_swapfilefunction to test mkswap support status safely.Signed-off-by Murphy Zhou <[email protected]>
Looks ok to me
Quoted 92 lines
--- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)testcases/kernel/syscalls/swapon/libswapon.c +43
-2@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" /* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe) {if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); +return tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" , safe); +} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 ); +if (ret !=0 ) { +if (fibmap !=0 ) { +tst_brkm (TCONF , cleanup, +"mkswap on %s not supported" , fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap !=0 && errno ==EINVAL ) { +tst_brkm (TCONF , cleanup, +"Swapfile on %s not implemented" , fstype); + }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }testcases/kernel/syscalls/swapon/libswapon.h +6
-2@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe); +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */ --2.21.0
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
In reply to Murphy ZhouQuoted 45 lines · Murphy Zhou
To check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations.
Modifymake_swapfilefunction to test mkswap support status safely.Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)testcases/kernel/syscalls/swapon/libswapon.c +9
-2@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" /* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe) {if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); +return tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" , safe); +} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on.
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char · line 66
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 ); +if (ret !=0 ) { +if (fibmap !=0 ) {
As I replied in patch 1/4, how do we know that means FIBMAP not support if just verify fibmap != 0?
So I would suggest to make the return value of tst_fibmap() is more precise and do if (fibmap == 1) check here.
+ tst_brkm(TCONF, cleanup,
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 78
Quoted 13 lines
testcases/kernel/syscalls/swapon/libswapon.c +12
-0+ "mkswap on %s not supported", fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap !=0 && errno ==EINVAL ) { +tst_brkm (TCONF , cleanup, +"Swapfile on %s not implemented" , fstype);
Maybe there is unnecessary to check fibmap value again? Since if the fibmap is 1, it has already broken in make_swapfile() error handler and never coming here?
Quoted 37 lines
testcases/kernel/syscalls/swapon/libswapon.c +11
-0+ }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }testcases/kernel/syscalls/swapon/libswapon.h +6
-2@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe); +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */ --2.21.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/a95a5d46/attachment.html>
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 56 lines · Li Wang
Quoted 52 lines · Murphy Zhou
To check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations.
Modifymake_swapfilefunction to test mkswap support status safely.Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)testcases/kernel/syscalls/swapon/libswapon.c +17
-2@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" /* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe) {if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); +return tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" , safe); +} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 );
Quoted 9 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 65
Quoted 3 lines
testcases/kernel/syscalls/swapon/libswapon.c +2
-0+if (ret !=0 ) { +if (fibmap !=0 ) {As I replied in patch 1/4, how do we know that means FIBMAP not support if just verify fibmap != 0?
So I would suggest to make the return value oftst_fibmap()is more precise and do if (fibmap == 1) check here.
And also, imagine that if swapon01 test failed on BRTFS or NFS(support swapfile but not
support FIBMAP ioctl), then here will report the new bug as a TCONF to LTP.
Quoted 64 lines
+ tst_brkm(TCONF, cleanup,
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 78
Quoted 13 lines
testcases/kernel/syscalls/swapon/libswapon.c +12
-0+ "mkswap on %s not supported", fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap !=0 && errno ==EINVAL ) { +tst_brkm (TCONF , cleanup, +"Swapfile on %s not implemented" , fstype);Maybe there is unnecessary to check fibmap value again? Since if the fibmap is 1, it has already broken in
make_swapfile()error handler and never coming here?Quoted 34 lines
testcases/kernel/syscalls/swapon/libswapon.c +11
-0+ }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }testcases/kernel/syscalls/swapon/libswapon.h +6
-2@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe); +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */ --2.21.0
Quoted 3 lines
--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Regards,
Li Wang
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/0d333ce9/attachment.html>
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 58 lines · Li Wang
Quoted 56 lines · Li Wang
Quoted 52 lines · Murphy Zhou
To check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations.
Modifymake_swapfilefunction to test mkswap support status safely.Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)testcases/kernel/syscalls/swapon/libswapon.c +17
-2@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" /* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe) {if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); +return tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" , safe); +} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 );
Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 65
Quoted 3 lines
testcases/kernel/syscalls/swapon/libswapon.c +2
-0+if (ret !=0 ) { +if (fibmap !=0 ) {As I replied in patch 1/4, how do we know that means FIBMAP not support if just verify fibmap != 0?
So I would suggest to make the return value oftst_fibmap()is more precise and do if (fibmap == 1) check here.
Very good catch. The return value should be more precise. Thanks!
Quoted 5 lines
Quoted 1 line
And also, imagine that if swapon01 test failed on BRTFS or NFS(support swapfile but not
support FIBMAP ioctl), then here will report the new bug as a TCONF to LTP.
Here is testing mkswap for swapon test preparation. If mkswap fail, and FIBMAP not supported, it's reasonable to me that we should not go on to test swapon.
But yes, if a regression causes mkswap fail without FIBMAP supported, we could miss the bug here like you described. This situation should be covered by tcase for mkswap IMO.
I'm going to dig more on fibmap/mkswap/swapon/swapoff support status of varies filesystems.
Quoted 17 lines
Quoted 17 lines
+ tst_brkm(TCONF, cleanup,
Quoted 13 lines
testcases/kernel/syscalls/swapon/libswapon.c +12
-0+ "mkswap on %s not supported", fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap !=0 && errno ==EINVAL ) { +tst_brkm (TCONF , cleanup, +"Swapfile on %s not implemented" , fstype);
Quoted 3 lines
Quoted 3 lines
Maybe there is unnecessary to check fibmap value again? Since if the fibmap is 1, it has already broken in
make_swapfile()error handler and never coming here?
If mkswap succeeds, we are coming here.
Thanks for reviewing!
Murphy
Quoted 51 lines
Quoted 46 lines
Quoted 37 lines
testcases/kernel/syscalls/swapon/libswapon.c +11
-0+ }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }testcases/kernel/syscalls/swapon/libswapon.h +6
-2@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe); +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */ --2.21.0
Quoted 3 lines
--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Regards,
Li WangSignature · 2 lines
Regards, Li Wang
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 81 lines · Murphy Zhou
Quoted 6 lines · Li Wang
Quoted 4 lines · Li Wang
On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
To check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations.
Modifymake_swapfilefunction to test mkswap support status safely.Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 45+++++++++++++++++++-
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)testcases/kernel/syscalls/swapon/libswapon.c +2
-0@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/swapon/libswapon.c
Quoted 5 lines
testcases/kernel/syscalls/swapon/libswapon.c +1
-1/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile(void (cleanup)(void), const char *swapfile, intsafe)
Quoted 10 lines
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char · line 51
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +1
-1{if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); + return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null",safe);
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename);Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 65
Quoted 6 lines
testcases/kernel/syscalls/swapon/libswapon.c +5
-0+const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 ); +if (ret !=0 ) { +if (fibmap !=0 ) {As I replied in patch 1/4, how do we know that means FIBMAP not
support if
Quoted 3 lines
Quoted 3 lines
just verify fibmap != 0?
So I would suggest to make the return value oftst_fibmap()is more precise and do if (fibmap == 1) check here.Very good catch. The return value should be more precise. Thanks!
Quoted 5 lines
Quoted 1 line
And also, imagine that if swapon01 test failed on BRTFS or NFS(support swapfile but not
support FIBMAP ioctl), then here will report the new bug as a TCONF toLTP.
Quoted 8 lines
Here is testing mkswap for swapon test preparation. If mkswap fail, and FIBMAP not supported, it's reasonable to me that we should not go on to test swapon.
But yes, if a regression causes mkswap fail without FIBMAP supported, we could miss the bug here like you described. This situation should be covered by tcase for mkswap IMO.
I'm thinking maybe we cann't avoid adding a whilelist in the test, at least for known filesystem without FIBMAP supported.
FYI: what do you think if change the is_swap_supported(...) like this?
void is_swap_supported(void (cleanup)(void), const char *filename)
{
int fibmap = tst_fibmap(filename);
if (fibmap == 1) {
int ret;
long fs_type = tst_fs_type(cleanup, filename);
const char *fstype = tst_fs_type_name(fs_type);
ret = make_swapfile(NULL, filename, 1);
if (ret != 0) {
if (fs_type == TST_NFS_MAGIC ||
fs_type == TST_TMPFS_MAGIC ||
fs_type == TST_BRTFS_MAGIC) {
tst_brkm(TFAIL, cleanup,
"mkswap on %s failed", fstype);
} else {
tst_brkm(TCONF, cleanup,
"mkswap on %s not supported",
fstype);
}
}
TEST(ltp_syscall(__NR_swapon, filename, 0));
if (TEST_RETURN == -1) {
if (errno == EINVAL) {
tst_brkm(TCONF, cleanup,
"Swapfile on %s not implemented",
fstype);
} else {
tst_brkm(TFAIL | TERRNO, cleanup,
"swapon on %s failed", fstype);
}
}
TEST(ltp_syscall(__NR_swapoff, filename, 0));
if (TEST_RETURN == -1) {
tst_brkm(TFAIL | TERRNO, cleanup,
"swapoff on %s failed", fstype);
}
}
}Quoted 19 lines
I'm going to dig more on fibmap/mkswap/swapon/swapoff support status of varies filesystems.
Quoted 15 lines
Quoted 15 lines
+ tst_brkm(TCONF, cleanup,
Quoted 12 lines
testcases/kernel/syscalls/swapon/libswapon.c +12
-0+ "mkswap on %s not supported", fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap !=0 && errno ==EINVAL ) { + tst_brkm(TCONF, cleanup, + "Swapfile on %s not implemented",
Quoted 9 lines
fstype);
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Maybe there is unnecessary to check fibmap value again? Since if the fibmap is 1, it has already broken in
make_swapfile()error handler and never coming here?If mkswap succeeds, we are coming here.
Ah yes. I missed that situation.
Quoted 57 lines
Thanks for reviewing!
MurphyQuoted 18 lines
Quoted 18 lines
Quoted 18 lines
testcases/kernel/syscalls/swapon/libswapon.c +11
-0+ }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }testcases/kernel/syscalls/swapon/libswapon.h +0
-0Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.h line 32
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.h +1
-1@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile(void (cleanup)(void), const char *swapfile, intsafe);
Quoted 25 lines
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/swapon/libswapon.h +5
-1+/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */ --2.21.0
Quoted 9 lines
Quoted 3 lines
--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Regards,
Li Wang--
Regards,
Li Wang
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/d5d20df0/attachment-0001.html>
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 87 lines · Li Wang
Quoted 85 lines · Murphy Zhou
Quoted 6 lines · Li Wang
Quoted 4 lines · Li Wang
On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
To check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations.
Modifymake_swapfilefunction to test mkswap support status safely.Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 45+++++++++++++++++++-
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)testcases/kernel/syscalls/swapon/libswapon.c +2
-0@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/swapon/libswapon.c
Quoted 5 lines
testcases/kernel/syscalls/swapon/libswapon.c +1
-1/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile(void (cleanup)(void), const char *swapfile, intsafe)
Quoted 10 lines
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char · line 51
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +1
-1{if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); + return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null",safe);
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
testcases/kernel/syscalls/swapon/libswapon.c +10
-0+} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename);Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 65
Quoted 6 lines
testcases/kernel/syscalls/swapon/libswapon.c +5
-0+const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 ); +if (ret !=0 ) { +if (fibmap !=0 ) {As I replied in patch 1/4, how do we know that means FIBMAP not
support if
Quoted 3 lines
Quoted 3 lines
just verify fibmap != 0?
So I would suggest to make the return value oftst_fibmap()is more precise and do if (fibmap == 1) check here.Very good catch. The return value should be more precise. Thanks!
Quoted 5 lines
Quoted 1 line
And also, imagine that if swapon01 test failed on BRTFS or NFS(support swapfile but not
support FIBMAP ioctl), then here will report the new bug as a TCONF toLTP.
Here is testing mkswap for swapon test preparation. If mkswap fail, and FIBMAP not supported, it's reasonable to me that we should not go on to test swapon.
Quoted 7 lines
Quoted 4 lines
But yes, if a regression causes mkswap fail without FIBMAP supported, we could miss the bug here like you described. This situation should be covered by tcase for mkswap IMO.
I'm thinking maybe we cann't avoid adding a whilelist in the test, at least for known filesystem without FIBMAP supported.
No, I think we don't need a whilelist here. Amir and I discussed long way to here, you can check that. We are not using fibmap test as a verdict for swapfile is supported or not. Doing a mkswap/swapon/swapoff test before real tests to detect the support situation. tst_fibmap result helps us to decide how to report. If the underneath filesystem can survive these test, it should be supporting swapfiles and swapon/swapoff tests should run.
The whitelisted nfs and tmpfs are well covered by these pre-tests. More, NFS should not be skipped as if we turn on kernle configs for NFS_SWAP, these tests can run on NFS.
Whitelist could skip more tests and bugs.
I tested some fibmap/mkswap/swapon/swapoff tests for your reference:
1 means positive, 0 means negative.
-------- On 5.3-rc3+ kernel, NFS_SWAP=y SUNRPC_SWAP=y -------
fibamp mkswap swapon swapoff
xfs 1 1 1 1
ext4 1 1 1 1
btrfs 0 1 0 0
tmpfs 0 1 0 0
ovl 1 1 1 1
cifs
v3.11 0 1 0 0
v1 0 1 0 0
v2 0 1 0 0
nfs
v4.2 0 1 1* 1
v4.1 0 1 1 1
v4.0 0 1 1* 1
v3 0 1 1 1
* hang sometimes
--------- On 3.10.0 based kernel ----------------
fibamp mkswap swapon swapoff
xfs 1 1 1 1
ext4 1 1 1 1
btrfs 0 1 0 0
tmpfs 0 1 0 0
ovl 1 1 1 1
cifs
v3.0 0 1 0 0
nfs
v4.2 0 1 0 0
---------- On 2.6.32 based kernel ---------------
fibamp mkswap swapon swapoff
tmpfs 0 1 0 0
xfs 1 1 1 1
ext4 1 1 1 1
cifs 0 0 0 0
nfs 0 0 0 0
Quoted 8 lines
FYI: what do you think if change the
is_swap_supported(...)like this?void
is_swap_supported(void (cleanup)(void), const char *filename){ int fibmap = tst_fibmap(filename); if (fibmap == 1) {
fibmap == 0 does not mean swapfile is supported. We need to make sure that survivors of this function are supporting swapfiles.
Thanks,
Murphy
Quoted 131 lines
int ret; long fs_type = tst_fs_type(cleanup, filename); const char *fstype = tst_fs_type_name(fs_type); ret = make_swapfile(NULL, filename, 1); if (ret != 0) { if (fs_type == TST_NFS_MAGIC || fs_type == TST_TMPFS_MAGIC || fs_type == TST_BRTFS_MAGIC) { tst_brkm(TFAIL, cleanup, "mkswap on %s failed", fstype); } else { tst_brkm(TCONF, cleanup, "mkswap on %s not supported", fstype); } } TEST(ltp_syscall(__NR_swapon, filename, 0)); if (TEST_RETURN == -1) { if (errno == EINVAL) { tst_brkm(TCONF, cleanup, "Swapfile on %s not implemented", fstype); } else { tst_brkm(TFAIL | TERRNO, cleanup, "swapon on %s failed", fstype); } } TEST(ltp_syscall(__NR_swapoff, filename, 0)); if (TEST_RETURN == -1) { tst_brkm(TFAIL | TERRNO, cleanup, "swapoff on %s failed", fstype); } } }Quoted 19 lines
I'm going to dig more on fibmap/mkswap/swapon/swapoff support status of varies filesystems.
Quoted 15 lines
Quoted 15 lines
+ tst_brkm(TCONF, cleanup,
Quoted 12 lines
testcases/kernel/syscalls/swapon/libswapon.c +12
-0+ "mkswap on %s not supported", fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap !=0 && errno ==EINVAL ) { + tst_brkm(TCONF, cleanup, + "Swapfile on %s not implemented",Quoted 9 lines
fstype);
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Maybe there is unnecessary to check fibmap value again? Since if the fibmap is 1, it has already broken in
make_swapfile()error handler and never coming here?If mkswap succeeds, we are coming here.
Ah yes. I missed that situation.
Quoted 57 lines
Thanks for reviewing!
MurphyQuoted 18 lines
Quoted 18 lines
Quoted 18 lines
testcases/kernel/syscalls/swapon/libswapon.c +11
-0+ }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }testcases/kernel/syscalls/swapon/libswapon.h +0
-0Quoted 8 lines
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.h line 32
Quoted 8 lines
testcases/kernel/syscalls/swapon/libswapon.h +1
-1@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile(void (cleanup)(void), const char *swapfile, intsafe);
Quoted 25 lines
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/swapon/libswapon.h +5
-1+/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */ --2.21.0
Quoted 9 lines
Quoted 3 lines
--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Regards,
Li Wang--
Regards,
Li WangSignature · 2 lines
Regards, Li Wang
PATCH v6 2/4 swapon/libswapon: add helper is_swap_supported
Quoted 116 lines · Murphy Zhou
Quoted 8 lines · Li Wang
Quoted 6 lines · Murphy Zhou
Quoted 5 lines · Li Wang
Quoted 3 lines · Li Wang
On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <[email protected]>
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
To check if the filesystem we are testing on supports FIBMAP,
mkswap,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
swapon and swapoff operations.
Modifymake_swapfilefunction to test mkswap support statussafely.
Quoted 22 lines
Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Signed-off-by Murphy Zhou <[email protected]>--- testcases/kernel/syscalls/swapon/libswapon.c | 45+++++++++++++++++++-
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)testcases/kernel/syscalls/swapon/libswapon.c +2
-0@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/swapon/libswapon.c
Quoted 5 lines
testcases/kernel/syscalls/swapon/libswapon.c +1
-1/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile(void (cleanup)(void), const char *swapfile, intsafe)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
testcases/kernel/syscalls/swapon/libswapon.c +0
-0{ if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) *10,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const
Quoted 2 lines
testcases/kernel/syscalls/swapon/libswapon.c +0
-0TST_BYTES)) {@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), constchar
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile)
Quoted 6 lines
testcases/kernel/syscalls/swapon/libswapon.c +1
-1*swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); + return tst_run_cmd(cleanup, argv, "/dev/null","
/dev/null",Quoted 8 lines
Quoted 8 lines
safe);
Quoted 7 lines
Quoted 7 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile)
Quoted 7 lines
testcases/kernel/syscalls/swapon/libswapon.c +7
-0+} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported(void (cleanup)(void), const char*filename)
Quoted 16 lines
Quoted 16 lines
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/swapon/libswapon.c void make_swapfile(void (cleanup)(void), const char *swapfile) · line 65
Quoted 9 lines
testcases/kernel/syscalls/swapon/libswapon.c +8
-0+{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 ); +if (ret !=0 ) { +if (fibmap !=0 ) {As I replied in patch 1/4, how do we know that means FIBMAP not
support if
Quoted 3 lines
Quoted 3 lines
just verify fibmap != 0?
So I would suggest to make the return value oftst_fibmap()is more precise and do if (fibmap == 1) check here.Quoted 5 lines
Quoted 5 lines
Very good catch. The return value should be more precise. Thanks!
Quoted 3 lines
Quoted 1 line
And also, imagine that if swapon01 test failed on BRTFS or
NFS(support
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
swapfile but not
support FIBMAP ioctl), then here will report the new bug as a TCONFto
Quoted 7 lines
Quoted 7 lines
LTP.
Here is testing mkswap for swapon test preparation. If mkswap fail, and FIBMAP not supported, it's reasonable to me that we should not go on to test swapon.
But yes, if a regression causes mkswap fail without FIBMAP supported,
we
Quoted 5 lines
Quoted 3 lines
could miss the bug here like you described. This situation should be covered by tcase for mkswap IMO.
I'm thinking maybe we cann't avoid adding a whilelist in the test, at
least
Quoted 1 line
for known filesystem without FIBMAP supported.
No, I think we don't need a whilelist here. Amir and I discussed long way to here, you can check that. We are not using fibmap test as a verdict for swapfile is supported or not. Doing a mkswap/swapon/swapoff test before real tests to detect the support situation.
tst_fibmapresult helps us to decide how to report. If the underneath filesystem can survive these test, it should be supporting swapfiles and swapon/swapoff tests should run.
Quoted 8 lines
The whitelisted nfs and tmpfs are well covered by these pre-tests. More, NFS should not be skipped as if we turn on kernle configs for
NFS_SWAP, these tests can run on NFS.Whitelist could skip more tests and bugs.
I tested some fibmap/mkswap/swapon/swapoff tests for your reference:
Thanks a lot for the test report, good to know these details.
Quoted 54 lines
1 means positive, 0 means negative.
-------- On 5.3-rc3+ kernel, NFS_SWAP=y SUNRPC_SWAP=y -------
fibamp mkswap swapon swapoff xfs 1 1 1 1 ext4 1 1 1 1btrfs 0 1 0 0 tmpfs 0 1 0 0ovl 1 1 1 1
cifs
v3.11 0 1 0 0 v1 0 1 0 0 v2 0 1 0 0nfs
v4.2 0 1 1* 1 v4.1 0 1 1 1 v4.0 0 1 1* 1 v3 0 1 1 1* hang sometimes
--------- On 3.10.0 based kernel ----------------
fibamp mkswap swapon swapoff xfs 1 1 1 1 ext4 1 1 1 1btrfs 0 1 0 0 tmpfs 0 1 0 0ovl 1 1 1 1
cifs
v3.0 0 1 0 0nfs
v4.2 0 1 0 0---------- On 2.6.32 based kernel ---------------
fibamp mkswap swapon swapoff tmpfs 0 1 0 0 xfs 1 1 1 1 ext4 1 1 1 1 cifs 0 0 0 0 nfs 0 0 0 0Quoted 3 lines
FYI: what do you think if change the
is_swap_supported(...)like this?
Quoted 9 lines
Quoted 5 lines
void
is_swap_supported(void (cleanup)(void), const char *filename){ int fibmap = tst_fibmap(filename); if (fibmap == 1) {fibmap == 0 does not mean swapfile is supported. We need to make sure that survivors of this function are supporting swapfiles.
Yes, it sounds quite reasonable. So besides that return value of tst_fibmap() is not precise, patch V6 LGTM. Feel free to add my review in patch v7:
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190610/9d6e1b32/attachment.html>
PATCH v7 1/4 lib/tst_ioctl.c: add helper tst_fibmap
To check if FIBMAP ioctl is supported by the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now.
---
v7:
Make tst_fibmap return value more accurate
Print errno if fibmap ioctl does not succeed
Make swapoff02 use new helper
Mute some build warnnings
cc linux-fsdevel list
Overall diff stat:
include/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ testcases/kernel/syscalls/swapoff/Makefile | 3 ++- testcases/kernel/syscalls/swapoff/Makefile.inc | 6 ++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 10 ++-------- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 ++--------- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++++++- testcases/kernel/syscalls/swapon/swapon01.c | 11 ++--------- testcases/kernel/syscalls/swapon/swapon02.c | 13 +++---------- testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++----------- 11 files changed, 112 insertions(+), 51 deletions(-)
v6:
Modify make_swapfile() to check mkswap support status safely Remove whitelist
Remove BTRFS EINVAL check
Check mkswap status before testing swapon in helper
If swapon pass, following swapoff failure will fail the whole test and break Also modify swapoff02 to remove whitelist completely
v5:
Split to 4 patches
Only take one filename parameter in tst_fibmap
Add helper is_swap_supported to check swap operation support status Test fibmap/swapon and swapoff operation in the helper
Keep NFS/TMPFS whitelist
Keep BTRFS EINVAL handling logic, except above 2 situation:
if swapon fails and fibmap is not supported, tst_brk with TCONF if swapon fails and fibmap is supported, tst_brk with TFAIL
If swapon test pass in the helper, test swapoff similarly
Put is_swap_supported helper in libswapon, link swapoff binaries to it Mute a sprintf filaname wanrning by the way
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
Fix fs_type undeclared in swapoff01.c
v2:
Test FIBMAP instead of fstype whitelist
include/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/tst_ioctl.c
include/tst_fs.h +5 -0
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {
lib/tst_ioctl.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return -1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO |TERRNO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return -1 ; + } +return 0 ; +}
Signature · 1 line
2.21.0
PATCH v7 1/4 lib/tst_ioctl.c: add helper tst_fibmap
Ping ?
Quoted 121 lines · Murphy Zhou
To check if FIBMAP ioctl is supported by the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now.
Reviewed-by Li Wang <[email protected]>Signed-off-by Murphy Zhou <[email protected]>---
v7:
Maketst_fibmapreturn value more accurate
Print errno if fibmap ioctl does not succeed
Make swapoff02 use new helper
Mute some build warnnings
cc linux-fsdevel list
Overall diff stat:include/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ testcases/kernel/syscalls/swapoff/Makefile | 3 ++- testcases/kernel/syscalls/swapoff/Makefile.inc | 6 ++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 10 ++-------- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 ++--------- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++++++- testcases/kernel/syscalls/swapon/swapon01.c | 11 ++--------- testcases/kernel/syscalls/swapon/swapon02.c | 13 +++---------- testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++----------- 11 files changed, 112 insertions(+), 51 deletions(-)v6:
Modifymake_swapfile()to check mkswap support status safely Remove whitelist
Remove BTRFS EINVAL check
Check mkswap status before testing swapon in helper
If swapon pass, following swapoff failure will fail the whole test and break Also modify swapoff02 to remove whitelist completely
v5:
Split to 4 patches
Only take one filename parameter intst_fibmap
Add helperis_swap_supportedto check swap operation support status Test fibmap/swapon and swapoff operation in the helper
Keep NFS/TMPFS whitelist
Keep BTRFS EINVAL handling logic, except above 2 situation:
if swapon fails and fibmap is not supported,tst_brkwith TCONF if swapon fails and fibmap is supported,tst_brkwith TFAIL
If swapon test pass in the helper, test swapoff similarly
Putis_swap_supportedhelper in libswapon, link swapoff binaries to it Mute a sprintf filaname wanrning by the way
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
Fixfs_typeundeclared inswapoff01.c
v2:
Test FIBMAP instead of fstype whitelistinclude/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +37
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { +tst_res (TWARN |TERRNO , +"open(%s, O_RDWR | O_CREAT, 0666) failed" , filename); +return -1 ; + } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO |TERRNO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return -1 ; + } +return 0 ; +}Signature · 1 line
2.21.0
PATCH v7 2/4 swapon/libswapon: add helper is_swap_supported
In reply to Murphy ZhouTo check if the filesystem we are testing on supports FIBMAP, mkswap, swapon and swapoff operations. Survivor of this function should support swapfile function well, like swapon and swapoff.
Modify make_swapfile function to test mkswap support status safely.
--- testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++- testcases/kernel/syscalls/swapon/libswapon.h | 7 ++- 2 files changed, 49 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/swapon/libswapon.c +43 -2
@@ -19,13 +19,15 @@* */ +#include <errno.h> +#include "lapi/syscalls.h" #include "test.h" #include "libswapon.h" /* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile) +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe) {if (!tst_fs_has_free (NULL ,"." ,sysconf (_SC_PAGESIZE) *10 ,TST_BYTES )) {
@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile) argv[1 ] = swapfile; argv[2 ] =NULL ; -tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" ,0 ); +return tst_run_cmd (cleanup, argv,"/dev/null" ,"/dev/null" , safe); +} + +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename) +{ +int fibmap =tst_fibmap (filename); +long fs_type =tst_fs_type (cleanup, filename); +const char *fstype =tst_fs_type_name (fs_type); + +int ret =make_swapfile (NULL , filename,1 ); +if (ret !=0 ) { +if (fibmap ==1 ) { +tst_brkm (TCONF , cleanup, +"mkswap on %s not supported" , fstype); + }else { +tst_brkm (TFAIL , cleanup, +"mkswap on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapon, filename,0 )); +if (TEST_RETURN ==-1 ) { +if (fibmap ==1 && errno ==EINVAL ) { +tst_brkm (TCONF , cleanup, +"Swapfile on %s not implemented" , fstype); + }else { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapon on %s failed" , fstype); + } + } + +TEST (ltp_syscall (__NR_swapoff, filename,0 )); +if (TEST_RETURN ==-1 ) { +tst_brkm (TFAIL |TERRNO , cleanup, +"swapoff on %s failed" , fstype); + } }
testcases/kernel/syscalls/swapon/libswapon.h +6 -1
@@ -29,6 +29,11 @@/* * Make a swap file */ -void make_swapfile (void (cleanup )(void ),const char *swapfile); +int make_swapfile (void (cleanup )(void ),const char *swapfile,int safe); +/* +* Check swapon/swapoff support status of filesystems or files +* we are testing on. +*/ +void is_swap_supported (void (cleanup )(void ),const char *filename);#endif /* __LIBSWAPON_H__ */
Signature · 1 line
2.21.0
PATCH v7 3/4 syscalls/swapon/swapon0{1..3}: use helpers to check support status
In reply to Murphy ZhouOf swap operations.
--- testcases/kernel/syscalls/swapon/swapon01.c | 11 ++--------- testcases/kernel/syscalls/swapon/swapon02.c | 13 +++---------- testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++----------- 3 files changed, 9 insertions(+), 30 deletions(-)
testcases/kernel/syscalls/swapon/swapon01.c +2 -9
@@ -84,16 +84,9 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" ); -make_swapfile (cleanup,"swapfile01" ); +make_swapfile (cleanup,"swapfile01" ,0 ); }static void cleanup (void )
testcases/kernel/syscalls/swapon/swapon02.c +3 -10
@@ -132,18 +132,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL ); -make_swapfile (cleanup,"swapfile01" ); -make_swapfile (cleanup,"alreadyused" ); +make_swapfile (cleanup,"swapfile01" ,0 ); +make_swapfile (cleanup,"alreadyused" ,0 );if (ltp_syscall (__NR_swapon,"alreadyused" ,0 )) {if (fs_type !=TST_BTRFS_MAGIC || errno !=EINVAL )
testcases/kernel/syscalls/swapon/swapon03.c +4 -11
@@ -153,7 +153,7 @@ static int setup_swap(void)int j, fd;int status;int res =0 ; -char filename[15 ]; +char filename[FILENAME_MAX ];char buf[BUFSIZ +1 ];/* Find out how many swapfiles (1 line per entry) already exist */
@@ -210,7 +210,7 @@ static int setup_swap(void) }/* Create the swapfile */ -make_swapfile (cleanup, filename); +make_swapfile (cleanup, filename,0 );/* turn on the swap file */ res =ltp_syscall (__NR_swapon, filename,0 );
@@ -246,7 +246,7 @@ static int setup_swap(void)/* Create all needed extra swapfiles for testing */ for (j =0 ; j < testfiles; j++) -make_swapfile (cleanup, swap_testfiles[j].filename); +make_swapfile (cleanup, swap_testfiles[j].filename,0 );return 0 ;
@@ -333,14 +333,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );TEST_PAUSE ; }
Signature · 1 line
2.21.0
PATCH v7 4/4 syscalls/swapoff/swapoff0{1,2}: use helpers to check support status
In reply to Murphy ZhouOf swap operations. Change Makefile to use functions from ../swapon/libswapon.c
--- testcases/kernel/syscalls/swapoff/Makefile | 3 ++- testcases/kernel/syscalls/swapoff/Makefile.inc | 6 ++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 10 ++-------- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 ++--------- 4 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 testcases/kernel/syscalls/swapoff/Makefile.inc
testcases/kernel/syscalls/swapoff/Makefile +2 -1
@@ -19,5 +19,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk - +include $(abs_srcdir)/./Makefile.inc include $(top_srcdir)/include/mk/generic_leaf_target.mk +$(MAKE_TARGETS): %: %.o ../swapon/libswapon.o
testcases/kernel/syscalls/swapoff/Makefile.inc new file +6 -0
@@ -0,0 +1,6 @@ +LIBDIR += ../swapon/ +LIBSWAPON := $(LIBDIR)/libswapon.o +$(LIBSWAPON): + $(MAKE) -C $(LIBDIR) +CPPFLAGS += -I$(abs_srcdir)/$(LIBDIR) +LDFLAGS += -L$(abs_builddir)/$(LIBDIR)
testcases/kernel/syscalls/swapoff/swapoff01.c +2 -8
@@ -25,6 +25,7 @@#include <stdlib.h> #include "config.h" #include "lapi/syscalls.h" +#include "../swapon/libswapon.h" static void setup (void );static void cleanup (void );
@@ -86,14 +87,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) { tst_brkm(TBROK, cleanup,
testcases/kernel/syscalls/swapoff/swapoff02.c +2 -9
@@ -33,6 +33,7 @@#include "test.h" #include "lapi/syscalls.h" #include "safe_macros.h" +#include "../swapon/libswapon.h" static void setup (void );static void cleanup (void );
@@ -124,7 +125,6 @@ static void cleanup01(void)static void setup (void ) { -long type;struct passwd *nobody;tst_sig (FORK ,DEF_HANDLER , cleanup);
@@ -138,14 +138,7 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );if (!tst_fs_has_free (NULL ,"." ,1 ,TST_KB )) { tst_brkm(TBROK, cleanup,
Signature · 1 line
2.21.0
PATCH v7 1/4 lib/tst_ioctl.c: add helper tst_fibmap
In reply to Murphy ZhouQuoted 7 lines · Murphy Zhou
To check if FIBMAP ioctl is supported by the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now.
Reviewed-by Li Wang <[email protected]>Signed-off-by Murphy Zhou <[email protected]>
Patch set pushed, thanks.
I also added Amir's reviewed by.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190716/f00a03c3/attachment.htm>
PATCH v6 3/4 syscalls/swapon/swapon0{1..3}: use helper to check support status
In reply to Murphy ZhouOf swap operations.
--- testcases/kernel/syscalls/swapon/swapon01.c | 11 ++--------- testcases/kernel/syscalls/swapon/swapon02.c | 13 +++---------- testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++----------- 3 files changed, 9 insertions(+), 30 deletions(-)
testcases/kernel/syscalls/swapon/swapon01.c +2 -9
@@ -84,16 +84,9 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" ); -make_swapfile (cleanup,"swapfile01" ); +make_swapfile (cleanup,"swapfile01" ,0 ); }static void cleanup (void )
testcases/kernel/syscalls/swapon/swapon02.c +3 -10
@@ -132,18 +132,11 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL ); -make_swapfile (cleanup,"swapfile01" ); -make_swapfile (cleanup,"alreadyused" ); +make_swapfile (cleanup,"swapfile01" ,0 ); +make_swapfile (cleanup,"alreadyused" ,0 );if (ltp_syscall (__NR_swapon,"alreadyused" ,0 )) {if (fs_type !=TST_BTRFS_MAGIC || errno !=EINVAL )
testcases/kernel/syscalls/swapon/swapon03.c +4 -11
@@ -153,7 +153,7 @@ static int setup_swap(void)int j, fd;int status;int res =0 ; -char filename[15 ]; +char filename[FILENAME_MAX ];char buf[BUFSIZ +1 ];/* Find out how many swapfiles (1 line per entry) already exist */
@@ -210,7 +210,7 @@ static int setup_swap(void) }/* Create the swapfile */ -make_swapfile (cleanup, filename); +make_swapfile (cleanup, filename,0 );/* turn on the swap file */ res =ltp_syscall (__NR_swapon, filename,0 );
@@ -246,7 +246,7 @@ static int setup_swap(void)/* Create all needed extra swapfiles for testing */ for (j =0 ; j < testfiles; j++) -make_swapfile (cleanup, swap_testfiles[j].filename); +make_swapfile (cleanup, swap_testfiles[j].filename,0 );return 0 ;
@@ -333,14 +333,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );TEST_PAUSE ; }
Signature · 1 line
2.21.0
PATCH v6 4/4 syscalls/swapoff/swapoff0{1, 2}: use helper to check support status
In reply to Murphy ZhouOf swap operations. Change Makefile to use functions from ../swapon/libswapon.c
--- testcases/kernel/syscalls/swapoff/Makefile | 3 ++- testcases/kernel/syscalls/swapoff/Makefile.inc | 6 ++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 10 ++-------- testcases/kernel/syscalls/swapoff/swapoff02.c | 9 +-------- 4 files changed, 11 insertions(+), 17 deletions(-) create mode 100644 testcases/kernel/syscalls/swapoff/Makefile.inc
testcases/kernel/syscalls/swapoff/Makefile +2 -1
@@ -19,5 +19,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk - +include $(abs_srcdir)/./Makefile.inc include $(top_srcdir)/include/mk/generic_leaf_target.mk +$(MAKE_TARGETS): %: %.o ../swapon/libswapon.o
testcases/kernel/syscalls/swapoff/Makefile.inc new file +6 -0
@@ -0,0 +1,6 @@ +LIBDIR += ../swapon/ +LIBSWAPON := $(LIBDIR)/libswapon.o +$(LIBSWAPON): + $(MAKE) -C $(LIBDIR) +CPPFLAGS += -I$(abs_srcdir)/$(LIBDIR) +LDFLAGS += -L$(abs_builddir)/$(LIBDIR)
testcases/kernel/syscalls/swapoff/swapoff01.c +2 -8
@@ -25,6 +25,7 @@#include <stdlib.h> #include "config.h" #include "lapi/syscalls.h" +#include "../swapon/libswapon.h" static void setup (void );static void cleanup (void );
@@ -86,14 +87,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) { tst_brkm(TBROK, cleanup,
testcases/kernel/syscalls/swapoff/swapoff02.c +1 -8
@@ -138,14 +138,7 @@ static void setup(void)tst_tmpdir (); -switch ((type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (type)); -break ; - } +is_swap_supported (cleanup,"./tstswap" );if (!tst_fs_has_free (NULL ,"." ,1 ,TST_KB )) { tst_brkm(TBROK, cleanup,
Signature · 1 line
2.21.0
PATCH v6 1/4 lib/tst_ioctl.c: add helper tst_fibmap
In reply to Murphy ZhouQuoted 81 lines · Murphy Zhou
To check if FIBMAP ioctl is supported on the filesystem we are testing on. It also can check the support status of specific files, but that may not needed for now.
Signed-off-by Murphy Zhou <[email protected]>---
v6:
Modifymake_swapfile()to check mkswap support status safely Remove whitelist
Remove BTRFS EINVAL check
Check mkswap status before testing swapon in helper
If swapon pass, following swapoff failure will fail the whole test and
break
Also modify swapoff02 to remove whitelist completely
v5:
Split to 4 patches
Only take one filename parameter intst_fibmap
Add helperis_swap_supportedto check swap operation support status Test fibmap/swapon and swapoff operation in the helper Keep NFS/TMPFS whitelist
Keep BTRFS EINVAL handling logic, except above 2 situation:
if swapon fails and fibmap is not supported,tst_brkwith TCONF if swapon fails and fibmap is supported,tst_brkwith TFAIL
If swapon test pass in the helper, test swapoff similarly Putis_swap_supportedhelper in libswapon, link swapoff binaries to it Mute a sprintf filaname wanrning by the way
v4:
Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
Fixfs_typeundeclared inswapoff01.c
v2:
Test FIBMAP instead of fstype whitelistinclude/tst_fs.h | 5 +++++ lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 lib/tst_ioctl.cinclude/tst_fs.h +5
-0@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);*/ void tst_fill_fs (const char *path,int verbose); +/* +* test if FIBMAP ioctl is supported +*/ +int tst_fibmap (const char *filename); +#ifdef TST_TEST_H__ static inline long tst_fs_type (const char *path) {lib/tst_ioctl.c new file +21
-0@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <linux/fs.h> + +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" + +int tst_fibmap (const char *filename) +{ +/* test if FIBMAP ioctl is supported */ +int fd, block =0 ; + + fd =open (filename,O_RDWR |O_CREAT ,0666 ); +if (fd <0 ) { + tst_res(TWARN | TERRNO, + "open(%s, O_RDWR | O_CREAT, 0666) failed",
Quoted 3 lines
filename);
+ return 1;
what about return -1 here? Calling this tst_fibmap() in otherplace, we don't know that
the reruened 1 means a open/close() fail or FIBMAP ioctl is NOT supported.
lib/tst_ioctl.c line 34
Quoted 13 lines
lib/tst_ioctl.c new file +12
-0+ } + +if (ioctl (fd,FIBMAP , &block)) { +tst_res (TINFO ,"FIBMAP ioctl is NOT supported" ); +close (fd); +return 1 ; + } +tst_res (TINFO ,"FIBMAP ioctl is supported" ); + +if (close (fd)) { +tst_res (TWARN |TERRNO ,"close(fd) failed" ); +return 1 ;
return -1;
Quoted 10 lines
lib/tst_ioctl.c new file +3
-1+ } +return 0 ; +} --2.21.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/f14123bf/attachment.html>
PATCH v5 3/4 syscalls/swapon/swapon0{1..3}: use helper to check support status
In reply to Murphy ZhouOf swap operations.
--- testcases/kernel/syscalls/swapon/swapon01.c | 9 +-------- testcases/kernel/syscalls/swapon/swapon02.c | 9 +-------- testcases/kernel/syscalls/swapon/swapon03.c | 11 ++--------- 3 files changed, 4 insertions(+), 25 deletions(-)
testcases/kernel/syscalls/swapon/swapon01.c +1 -8
@@ -84,14 +84,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"swapon" ,"./tstswap" );make_swapfile (cleanup,"swapfile01" ); }
testcases/kernel/syscalls/swapon/swapon02.c +1 -8
@@ -132,14 +132,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"swapon" ,"./tstswap" );SAFE_TOUCH (cleanup,"notswap" ,0777 ,NULL );make_swapfile (cleanup,"swapfile01" );
testcases/kernel/syscalls/swapon/swapon03.c +2 -9
@@ -153,7 +153,7 @@ static int setup_swap(void)int j, fd;int status;int res =0 ; -char filename[15 ]; +char filename[FILENAME_MAX ];char buf[BUFSIZ +1 ];/* Find out how many swapfiles (1 line per entry) already exist */
@@ -333,14 +333,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapon on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"swapon" ,"./tstswap" );TEST_PAUSE ; }
Signature · 1 line
2.21.0
PATCH v5 4/4 syscalls/swapoff/swapoff01: use helper to check support status
In reply to Murphy ZhouOf swap operations. Change Makefile to use functions from ../swapon/libswapon.c
--- testcases/kernel/syscalls/swapoff/Makefile | 3 ++- testcases/kernel/syscalls/swapoff/Makefile.inc | 6 ++++++ testcases/kernel/syscalls/swapoff/swapoff01.c | 10 ++-------- 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 testcases/kernel/syscalls/swapoff/Makefile.inc
testcases/kernel/syscalls/swapoff/Makefile +2 -1
@@ -19,5 +19,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk - +include $(abs_srcdir)/./Makefile.inc include $(top_srcdir)/include/mk/generic_leaf_target.mk +$(MAKE_TARGETS): %: %.o ../swapon/libswapon.o
testcases/kernel/syscalls/swapoff/Makefile.inc new file +6 -0
@@ -0,0 +1,6 @@ +LIBDIR += ../swapon/ +LIBSWAPON := $(LIBDIR)/libswapon.o +$(LIBSWAPON): + $(MAKE) -C $(LIBDIR) +CPPFLAGS += -I$(abs_srcdir)/$(LIBDIR) +LDFLAGS += -L$(abs_builddir)/$(LIBDIR)
testcases/kernel/syscalls/swapoff/swapoff01.c +2 -8
@@ -25,6 +25,7 @@#include <stdlib.h> #include "config.h" #include "lapi/syscalls.h" +#include "../swapon/libswapon.h" static void setup (void );static void cleanup (void );
@@ -86,14 +87,7 @@ static void setup(void)tst_tmpdir (); -switch ((fs_type =tst_fs_type (cleanup,"." ))) { -case TST_NFS_MAGIC : -case TST_TMPFS_MAGIC : -tst_brkm (TCONF , cleanup, -"Cannot do swapoff on a file on %s filesystem" , -tst_fs_type_name (fs_type)); -break ; - } +is_swap_supported (cleanup,"swapoff" ,"./tstswap" );if (!tst_fs_has_free (NULL ,"." ,64 ,TST_MB )) { tst_brkm(TBROK, cleanup,
Signature · 1 line
2.21.0