Rewrite mountns testing suite
cover Rewrite mountns testing suite
mountns testing suite has been rewritten using new LTP API and libclone has been removed from dependences.
Andrea Cervesato (5):
Rewrite mountns01 test using new LTP API
Rewrite mountns02 test using new LTP API
Rewrite mountns03 test using new LTP API
Rewrite mountns04 test using new LTP API
Remove obsolete mountns_helper.h
testcases/kernel/containers/mountns/Makefile | 21 +-- testcases/kernel/containers/mountns/common.h | 53 ++++++ .../kernel/containers/mountns/mountns01.c | 148 ++++++++-------- .../kernel/containers/mountns/mountns02.c | 145 +++++++--------- .../kernel/containers/mountns/mountns03.c | 161 ++++++++---------- .../kernel/containers/mountns/mountns04.c | 98 +++++------ .../containers/mountns/mountns_helper.h | 61 ------- 7 files changed, 308 insertions(+), 379 deletions(-) create mode 100644 testcases/kernel/containers/mountns/common.h delete mode 100644 testcases/kernel/containers/mountns/mountns_helper.h
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/5 Rewrite mountns01 test using new LTP API
Removed libclone from Makefile and used LTP API to replace it. mountns01 has been adapted to use the new LTP API.
--- testcases/kernel/containers/mountns/Makefile | 21 +-- testcases/kernel/containers/mountns/common.h | 53 +++++++ .../kernel/containers/mountns/mountns01.c | 148 ++++++++---------- 3 files changed, 124 insertions(+), 98 deletions(-) create mode 100644 testcases/kernel/containers/mountns/common.h
testcases/kernel/containers/mountns/Makefile +3 -18
@@ -1,23 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2014 Red Hat, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of version 2 the GNU General Public License as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -############################################################################## +# Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> -top_srcdir ?= ../../../.. +top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(abs_srcdir)/../Makefile.inc - -LDLIBS := -lclone $(LDLIBS) - include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/containers/mountns/common.h new file +53 -0
53 lines not on this page · raw message
testcases/kernel/containers/mountns/mountns01.c +68 -80
215 lines not on this page · raw message
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v1 1/5] Rewrite mountns01 test using new LTP API
Hi Andrea,
Quoted 2 lines
Removed libclone from
Makefileand used LTP API to replace it. mountns01 has been adapted to use the new LTP API.
Thanks for this effort!
Quoted 1 line
+++ b/testcases/kernel/containers/mountns/Makefile
...
testcases/kernel/containers/mountns/Makefile line 22
Quoted 5 lines
include $(top_srcdir)/include/mk/testcases.mk
testcases/kernel/containers/mountns/Makefile +0
-4-include $(abs_srcdir)/../Makefile.inc - -LDLIBS := -lclone $(LDLIBS) -
Removing this makes this commit (and I guess all but the last commits) uncompilable. IMHO this is no-go as it breaks bisecting.
But even keeping it for all not yet rewritten tests:
include $(abs_srcdir)/../Makefile.inc
mountns02 mountns03 mountns04 mountns05: LDLIBS := -lclone $(LDLIBS)
breaks the compilation:
$ make mountns02 make -C ../libclone -f "testcases/kernel/containers/mountns/../libclone/Makefile" all make[1]: Entering directory 'testcases/kernel/containers/libclone' ../../../../include/mk/sparse.mk:6: warning: overriding recipe for target 'tools/sparse/sparse-ltp' ../../../../include/mk/sparse.mk:6: warning: ignoring old recipe for target 'tools/sparse/sparse-ltp' ../../../../include/mk/sparse.mk:9: warning: overriding recipe for target 'tools/sparse' ../../../../include/mk/sparse.mk:9: warning: ignoring old recipe for target 'tools/sparse' make[1]: Nothing to be done for 'all'. make[1]: Leaving directory 'testcases/kernel/containers/libclone' /usr/bin/ld: testcases/kernel/containers/mountns/../libclone/libclone.a(libclone.o): in function `do_unshare_tests': testcases/kernel/containers/libclone/libclone.c:59: undefined reference to `tst_brk' collect2: error: ld returned 1 exit status make: *** [../../../../include/mk/rules.mk:37: mountns02] Error 1
testcases/kernel/containers/mountns/common.h
Quoted 6 lines
include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/containers/mountns/common.h new file +0
-0
nit: maybe mountns.h would be a better name.
...
testcases/kernel/containers/mountns/common.h line 27
Quoted 6 lines
testcases/kernel/containers/mountns/common.h new file +6
-0+static void check_newns (void ) +{ +int pid, status; + +if (tst_kvercmp (2 ,4 ,19 ) <0 ) +tst_brk (TCONF ,"CLONE_NEWNS not supported" );
We can safely remove check for kernel 2.4 :).
testcases/kernel/containers/mountns/common.h line 31
Quoted 4 lines
testcases/kernel/containers/mountns/common.h new file +4
-0+ + pid =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , dummy_child,NULL ); +if (pid <0 ) +tst_brk (TCONF ,"CLONE_NEWNS not supported" );
Yes, I'd also be for keeping ltp_clone_quick() from quite obscure cloner.[hc]. SAFE_CLONE() / tst_clone() use nice clone3() interface, but that's was added quite recently (kernel 5.3). It'd be nice one day rewrite/cleanup also also cloner.[hc].
Quoted 1 line
testcases/kernel/containers/mountns/mountns01.c +0
-0
...
Quoted 1 line
#define
_GNU_SOURCE
IMHO _GNU_SOURCE is not needed. Or at least it compiles without it
Quoted 5 lines
testcases/kernel/containers/mountns/mountns01.c +1
-2+#include <sys/wait.h> #include <sys/mount.h> -#include <stdio.h> -#include <errno.h>
testcases/kernel/containers/mountns/mountns01.c line 40
Quoted 10 lines
testcases/kernel/containers/mountns/mountns01.c +2
-6-#include "mountns_helper.h" -#include "test.h" -#include "safe_macros.h" - -char *TCID ="mountns01" ; -int TST_TOTAL =2 ; +#include "common.h" +#include "tst_test.h" #if defined(MS_SHARED ) && defined(MS_PRIVATE ) && defined(MS_REC )
These were added in glibc in 2010 (glibc 2.12), we can safely remove this check.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/5 Rewrite mountns02 test using new LTP API
In reply to Andrea Cervesato--- .../kernel/containers/mountns/mountns02.c | 145 ++++++++---------- 1 file changed, 66 insertions(+), 79 deletions(-)
testcases/kernel/containers/mountns/mountns02.c +66 -79
@@ -1,22 +1,17 @@ -/* Copyright (c) 2014 Red Hat, Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of version 2 the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*********************************************************************** -* File: mountns02.c +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2014 Red Hat, Inc. +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] * * Tests a private mount: private mount does not forward or receive * propagation. -* Description: +* +* [Algorithm] +* * 1. Creates directories "A", "B" and files "A/A", "B/B" * 2. Unshares mount namespace and makes it private (so mounts/umounts * have no effect on a real system)
@@ -33,117 +28,109 @@* Y: bind mounts "B" to "A" * X: must see "A/A" and must not see "A/B" * Y: umounts A -***********************************************************************/ +*/ #define _GNU_SOURCE +#include <sys/wait.h> #include <sys/mount.h> -#include <stdio.h> -#include <errno.h> -#include "mountns_helper.h" -#include "test.h" -#include "safe_macros.h" - -char *TCID ="mountns02" ; -int TST_TOTAL =2 ; +#include "common.h" +#include "tst_test.h" #if defined(MS_SHARED ) && defined(MS_PRIVATE ) && defined(MS_REC ) -int child_func(void *arg LTP_ATTRIBUTE_UNUSED) +static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) {int ret =0 ; -TST_SAFE_CHECKPOINT_WAIT (NULL ,0 ); +TST_CHECKPOINT_WAIT (0 ); -if ((access (DIRA "/A" ,F_OK ) !=0 ) || (access (DIRA "/B" ,F_OK ) ==0 )) +if ((access (DIRA "/A" ,F_OK ) !=0 ) || (access (DIRA "/B" ,F_OK ) ==0 )) ret =2 ; -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (NULL ,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 ); -/* bind mounts DIRB to DIRA making contents of DIRB visible -* in DIRA */ -if (mount (DIRB ,DIRA ,"none" ,MS_BIND ,NULL ) ==-1 ) { -perror ("mount" ); -return 1 ; - } +/* bind mounts DIRB to DIRA making contents of DIRB visible in DIRA */ +SAFE_MOUNT (DIRB ,DIRA ,"none" ,MS_BIND ,NULL ); -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (NULL ,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 ); + +SAFE_UMOUNT (DIRA ); -umount (DIRA );return ret; } -static void test (void ) +static void run (void ) { -int status; +int status, ret;/* unshares the mount ns */ -if (unshare (CLONE_NEWNS ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"unshare failed" ); +SAFE_UNSHARE (CLONE_NEWNS ); +/* makes sure parent mounts/umounts have no effect on a real system */ -SAFE_MOUNT (cleanup,"none" ,"/" ,"none" ,MS_REC |MS_PRIVATE ,NULL ); +SAFE_MOUNT ("none" ,"/" ,"none" ,MS_REC |MS_PRIVATE ,NULL );/* bind mounts DIRA to itself */ -SAFE_MOUNT (cleanup,DIRA ,DIRA ,"none" ,MS_BIND ,NULL ); +SAFE_MOUNT (DIRA ,DIRA ,"none" ,MS_BIND ,NULL );/* makes mount DIRA private */ -SAFE_MOUNT (cleanup,"none" ,DIRA ,"none" ,MS_PRIVATE ,NULL ); +SAFE_MOUNT ("none" ,DIRA ,"none" ,MS_PRIVATE ,NULL ); -if (do_clone_tests (CLONE_NEWNS , child_func,NULL ,NULL ,NULL ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"clone failed" ); + ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , child_func,NULL ); +if (ret <0 ) +tst_brk (TBROK ,"clone failed" ); -/* bind mounts DIRB to DIRA making contents of DIRB visible -* in DIRA */ -SAFE_MOUNT (cleanup,DIRB ,DIRA ,"none" ,MS_BIND ,NULL ); +/* bind mounts DIRB to DIRA making contents of DIRB visible in DIRA */ +SAFE_MOUNT (DIRB ,DIRA ,"none" ,MS_BIND ,NULL ); -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (cleanup,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 ); -SAFE_UMOUNT (cleanup,DIRA ); +SAFE_UMOUNT (DIRA ); -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (cleanup,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 ); -if ((access (DIRA "/A" ,F_OK ) !=0 ) || (access (DIRA "/B" ,F_OK ) ==0 )) -tst_resm (TFAIL ,"private mount in child failed" ); +if ((access (DIRA "/A" ,F_OK ) !=0 ) || (access (DIRA "/B" ,F_OK ) ==0 )) +tst_res (TFAIL ,"private mount in child failed" );else -tst_resm (TPASS ,"private mount in child passed" ); +tst_res (TPASS ,"private mount in child passed" ); -TST_SAFE_CHECKPOINT_WAKE (cleanup,0 ); +TST_CHECKPOINT_WAKE (0 ); - -SAFE_WAIT (cleanup, &status); +SAFE_WAIT (&status);if (WIFEXITED (status)) {if ((WEXITSTATUS (status) ==0 )) -tst_resm (TPASS ,"private mount in parent passed" ); +tst_res (TPASS ,"private mount in parent passed" );else -tst_resm (TFAIL ,"private mount in parent failed" ); +tst_res (TFAIL ,"private mount in parent failed" ); } +if (WIFSIGNALED (status)) { -tst_resm (TBROK ,"child was killed with signal %s" , -tst_strsig (WTERMSIG (status))); -return ; +tst_brk (TBROK ,"child was killed with signal %s" , +tst_strsig (WTERMSIG (status))); } -SAFE_UMOUNT (cleanup,DIRA ); +SAFE_UMOUNT (DIRA ); } -int main (int argc,char *argv[]) +static void setup (void ) { -int lc; - -tst_parse_opts (argc, argv,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) -test (); - -cleanup (); -tst_exit (); +check_newns (); +create_folders (); } -#else -int main (void ) +static void cleanup (void ) { -tst_brkm (TCONF ,NULL ,"needed mountflags are not defined" ); +umount_folders (); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, + .needs_root =1 , + .needs_checkpoints =1 , +}; + +#else +TST_TEST_TCONF ("needed mountflags are not defined" );#endif
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/5 Rewrite mountns03 test using new LTP API
In reply to Andrea Cervesato--- .../kernel/containers/mountns/mountns03.c | 161 ++++++++---------- 1 file changed, 73 insertions(+), 88 deletions(-)
testcases/kernel/containers/mountns/mountns03.c +73 -88
@@ -1,23 +1,17 @@ -/* Copyright (c) 2014 Red Hat, Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of version 2 the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*********************************************************************** -* File: mountns03.c +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2014 Red Hat, Inc. +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] * * Tests a slave mount: slave mount is like a shared mount except that * mount and umount events only propagate towards it. * -* Description: +* [Algorithm] +* * 1. Creates directories "A", "B" and files "A/A", "B/B" * 2. Unshares mount namespace and makes it private (so mounts/umounts * have no effect on a real system)
@@ -36,131 +30,122 @@* X: must see only the "A/A" and must not see "A/B" (as slave * mount does not forward propagation) * Y: umounts "A" -***********************************************************************/ +*/ #define _GNU_SOURCE +#include <sys/wait.h> #include <sys/mount.h> -#include <stdio.h> -#include <unistd.h> -#include <errno.h> -#include "mountns_helper.h" -#include "test.h" -#include "safe_macros.h" +#include "common.h" +#include "tst_test.h" -char *TCID ="mountns03" ; -int TST_TOTAL =2 ; +#if defined(MS_SHARED ) && defined(MS_PRIVATE ) && defined(MS_REC ) \ + && defined(MS_SLAVE ) -#if defined(MS_SHARED ) && defined(MS_PRIVATE ) \ - && defined(MS_REC ) && defined(MS_SLAVE ) - -int child_func(void *arg LTP_ATTRIBUTE_UNUSED) +static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) {int ret =0 ; -/* makes mount DIRA a slave of DIRA (all slave mounts have -* a master mount which is a shared mount) */ -if (mount ("none" ,DIRA ,"none" ,MS_SLAVE ,NULL ) ==-1 ) { -perror ("mount" ); -return 1 ; - } +/* +* makes mount DIRA a slave of DIRA (all slave mounts have +* a master mount which is a shared mount) +*/ +SAFE_MOUNT ("none" ,DIRA ,"none" ,MS_SLAVE ,NULL ); -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (NULL ,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 );/* checks that shared mounts propagates to slave mount */ -if (access (DIRA "/B" ,F_OK ) ==-1 ) +if (access (DIRA "/B" ,F_OK ) <0 ) ret =2 ; -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (NULL ,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 ); -/* bind mounts DIRB to DIRA making contents of DIRB visible -* in DIRA */ -if (mount (DIRB ,DIRA ,"none" ,MS_BIND ,NULL ) ==-1 ) { -perror ("mount" ); -return 1 ; - } +/* bind mounts DIRB to DIRA making contents of DIRB visible in DIRA */ +SAFE_MOUNT (DIRB ,DIRA ,"none" ,MS_BIND ,NULL ); -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (NULL ,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 ); + +SAFE_UMOUNT (DIRA ); -umount (DIRA );return ret; } -static void test (void ) +static void run (void ) { -int status; +int status, ret;/* unshares the mount ns */ -if (unshare (CLONE_NEWNS ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"unshare failed" ); +SAFE_UNSHARE (CLONE_NEWNS ); +/* makes sure parent mounts/umounts have no effect on a real system */ -SAFE_MOUNT (cleanup,"none" ,"/" ,"none" ,MS_REC |MS_PRIVATE ,NULL ); +SAFE_MOUNT ("none" ,"/" ,"none" ,MS_REC |MS_PRIVATE ,NULL );/* bind mounts DIRA to itself */ -SAFE_MOUNT (cleanup,DIRA ,DIRA ,"none" ,MS_BIND ,NULL ); +SAFE_MOUNT (DIRA ,DIRA ,"none" ,MS_BIND ,NULL );/* makes mount DIRA shared */ -SAFE_MOUNT (cleanup,"none" ,DIRA ,"none" ,MS_SHARED ,NULL ); +SAFE_MOUNT ("none" ,DIRA ,"none" ,MS_SHARED ,NULL ); -if (do_clone_tests (CLONE_NEWNS , child_func,NULL ,NULL ,NULL ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"clone failed" ); + ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , child_func,NULL ); +if (ret <0 ) +tst_brk (TBROK ,"clone failed" );/* waits for child to make a slave mount */ -TST_SAFE_CHECKPOINT_WAIT (cleanup,0 ); +TST_CHECKPOINT_WAIT (0 ); -/* bind mounts DIRB to DIRA making contents of DIRB visible -* in DIRA */ -SAFE_MOUNT (cleanup,DIRB ,DIRA ,"none" ,MS_BIND ,NULL ); +/* bind mounts DIRB to DIRA making contents of DIRB visible in DIRA */ +SAFE_MOUNT (DIRB ,DIRA ,"none" ,MS_BIND ,NULL ); -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (cleanup,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 ); -SAFE_UMOUNT (cleanup,DIRA ); +SAFE_UMOUNT (DIRA ); -TST_SAFE_CHECKPOINT_WAKE_AND_WAIT (cleanup,0 ); +TST_CHECKPOINT_WAKE_AND_WAIT (0 );/* checks that slave mount doesn't propagate to shared mount */ -if ((access (DIRA "/A" ,F_OK ) ==0 ) && (access (DIRA "/B" ,F_OK ) ==-1 )) -tst_resm (TPASS ,"propagation from slave mount passed" ); +if ((access (DIRA "/A" ,F_OK ) ==0 ) && (access (DIRA "/B" ,F_OK ) ==-1 )) +tst_res (TPASS ,"propagation from slave mount passed" );else -tst_resm (TFAIL ,"propagation form slave mount failed" ); +tst_res (TFAIL ,"propagation form slave mount failed" ); -TST_SAFE_CHECKPOINT_WAKE (cleanup,0 ); +TST_CHECKPOINT_WAKE (0 ); +SAFE_WAIT (&status); -SAFE_WAIT (cleanup, &status);if (WIFEXITED (status)) {if (WEXITSTATUS (status) ==0 ) -tst_resm (TPASS ,"propagation to slave mount passed" ); +tst_res (TPASS ,"propagation to slave mount passed" );else -tst_resm (TFAIL ,"propagation to slave mount failed" ); +tst_res (TFAIL ,"propagation to slave mount failed" ); } +if (WIFSIGNALED (status)) { -tst_resm (TBROK ,"child was killed with signal %s" , -tst_strsig (WTERMSIG (status))); -return ; +tst_brk (TBROK ,"child was killed with signal %s" , +tst_strsig (WTERMSIG (status))); } -SAFE_UMOUNT (cleanup,DIRA ); +SAFE_UMOUNT (DIRA ); } -int main (int argc,char *argv[]) +static void setup (void ) { -int lc; - -tst_parse_opts (argc, argv,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) -test (); - -cleanup (); -tst_exit (); +check_newns (); +create_folders (); } -#else -int main (void ) +static void cleanup (void ) { -tst_brkm (TCONF ,NULL ,"needed mountflags are not defined" ); +umount_folders (); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, + .needs_root =1 , + .needs_checkpoints =1 , +}; + +#else +TST_TEST_TCONF ("needed mountflags are not defined" );#endif
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/5 Rewrite mountns04 test using new LTP API
In reply to Andrea Cervesato--- .../kernel/containers/mountns/mountns04.c | 98 +++++++++---------- 1 file changed, 45 insertions(+), 53 deletions(-)
testcases/kernel/containers/mountns/mountns04.c +45 -53
@@ -1,89 +1,81 @@ -/* Copyright (c) 2014 Red Hat, Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of version 2 the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*********************************************************************** -* File: mountns04.c +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2014 Red Hat, Inc. +* Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] * * Tests an unbindable mount: unbindable mount is an unbindable * private mount. -* Description: +* +* [Algorithm] +* * 1. Creates directories "A", "B" and files "A/A", "B/B" * 2. Unshares mount namespace and makes it private (so mounts/umounts * have no effect on a real system) * 3. Bind mounts directory "A" to "A" -* 4. Makes directory directory "A" unbindable +* 4. Makes directory "A" unbindable * 5. Tries to bind mount unbindable "A" to "B": * - if it fails, test passes * - if it passes, test fails -***********************************************************************/ +*/ #define _GNU_SOURCE +#include <sys/wait.h> #include <sys/mount.h> -#include <stdio.h> -#include <errno.h> -#include "mountns_helper.h" -#include "test.h" -#include "safe_macros.h" +#include "common.h" +#include "tst_test.h" -char *TCID ="mountns04" ; -int TST_TOTAL =1 ; +#if defined(MS_SHARED ) && defined(MS_PRIVATE ) && defined(MS_REC ) \ + && defined(MS_UNBINDABLE ) -#if defined(MS_SHARED ) && defined(MS_PRIVATE ) \ - && defined(MS_REC ) && defined(MS_UNBINDABLE ) - -static void test (void ) +static void run (void ) {/* unshares the mount ns */ -if (unshare (CLONE_NEWNS ) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"unshare failed" ); +SAFE_UNSHARE (CLONE_NEWNS ); +/* makes sure mounts/umounts have no effect on a real system */ -SAFE_MOUNT (cleanup,"none" ,"/" ,"none" ,MS_REC |MS_PRIVATE ,NULL ); +SAFE_MOUNT ("none" ,"/" ,"none" ,MS_REC |MS_PRIVATE ,NULL );/* bind mounts DIRA to itself */ -SAFE_MOUNT (cleanup,DIRA ,DIRA ,"none" ,MS_BIND ,NULL ); +SAFE_MOUNT (DIRA ,DIRA ,"none" ,MS_BIND ,NULL ); +/* makes mount DIRA unbindable */ -SAFE_MOUNT (cleanup,"none" ,DIRA ,"none" ,MS_UNBINDABLE ,NULL ); +SAFE_MOUNT ("none" ,DIRA ,"none" ,MS_UNBINDABLE ,NULL );/* tries to bind mount unbindable DIRA to DIRB which should fail */ if (mount (DIRA ,DIRB ,"none" ,MS_BIND ,NULL ) ==-1 ) { -tst_resm (TPASS ,"unbindable mount passed" ); +tst_res (TPASS ,"unbindable mount passed" ); }else { -SAFE_UMOUNT (cleanup,DIRB ); -tst_resm (TFAIL ,"unbindable mount faled" ); +SAFE_UMOUNT (DIRB ); +tst_res (TFAIL ,"unbindable mount faled" ); } -SAFE_UMOUNT (cleanup,DIRA ); +SAFE_UMOUNT (DIRA ); } -int main (int argc,char *argv[]) +static void setup (void ) { -int lc; - -tst_parse_opts (argc, argv,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) -test (); - -cleanup (); -tst_exit (); +check_newns (); +create_folders (); } -#else -int main (void ) +static void cleanup (void ) { -tst_brkm (TCONF ,NULL ,"needed mountflags are not defined" ); +umount_folders (); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, + .needs_root =1 , + .needs_checkpoints =1 , +}; + +#else +TST_TEST_TCONF ("needed mountflags are not defined" );#endif
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/5 Remove obsolete mountns_helper.h
In reply to Andrea Cervesatomountns_helper.h has been replaced by common.h file.
--- .../containers/mountns/mountns_helper.h | 61 ------------------- 1 file changed, 61 deletions(-) delete mode 100644 testcases/kernel/containers/mountns/mountns_helper.h
testcases/kernel/containers/mountns/mountns_helper.h deleted +0 -61
@@ -1,61 +0,0 @@ -/* Copyright (c) 2014 Red Hat, Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of version 2 the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "libclone.h" -#include "test.h" -#include "safe_macros.h" - -#define DIRA "A" -#define DIRB "B" - -static int dummy_child (void *v) -{ - (void ) v; -return 0 ; -} - -static int check_newns (void ) -{ -int pid, status; - -if (tst_kvercmp (2 ,4 ,19 ) <0 ) -tst_brkm (TCONF ,NULL ,"CLONE_NEWNS not supported" ); - - pid =do_clone_unshare_test (T_CLONE ,CLONE_NEWNS , dummy_child,NULL ); -if (pid ==-1 ) -tst_brkm (TCONF |TERRNO ,NULL ,"CLONE_NEWNS not supported" ); -SAFE_WAIT (NULL , &status); - -return 0 ; -} - -static void cleanup (void ) -{ -umount (DIRA ); -umount (DIRB ); -tst_rmdir (); -} - -static void setup (void ) -{ -tst_require_root (); -check_newns (); -tst_tmpdir (); -TST_CHECKPOINT_INIT (tst_rmdir); -SAFE_MKDIR (cleanup,DIRA ,0777 ); -SAFE_MKDIR (cleanup,DIRB ,0777 ); -SAFE_TOUCH (cleanup,DIRA "/A" ,0 ,NULL ); -SAFE_TOUCH (cleanup,DIRB "/B" ,0 ,NULL ); -}
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp