* tests shared mount: shared mount can be replicated to as many
  mountpoints and all the replicas continue to be exactly same.

Signed-off-by: Matus Marhefka <mmarh...@redhat.com>
---
 runtest/containers                                 |   2 +
 testcases/kernel/containers/.gitignore             |   1 +
 testcases/kernel/containers/mountns/Makefile       |  23 +++
 testcases/kernel/containers/mountns/mountns01.c    | 161 +++++++++++++++++++++
 .../kernel/containers/mountns/mountns_helper.h     |  66 +++++++++
 5 files changed, 253 insertions(+)
 create mode 100644 testcases/kernel/containers/mountns/Makefile
 create mode 100644 testcases/kernel/containers/mountns/mountns01.c
 create mode 100644 testcases/kernel/containers/mountns/mountns_helper.h

diff --git a/runtest/containers b/runtest/containers
index 558d7eb..f298c7e 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -55,3 +55,5 @@ utstest_clone_2 utstest clone 2
 utstest_clone_3 utstest clone 3
 utstest_clone_4 utstest clone 4
 utstest_clone_5 utstest clone 5
+
+mountns01 mountns01
diff --git a/testcases/kernel/containers/.gitignore 
b/testcases/kernel/containers/.gitignore
index f6f5b14..254d1b9 100644
--- a/testcases/kernel/containers/.gitignore
+++ b/testcases/kernel/containers/.gitignore
@@ -1 +1,2 @@
 /check_for_unshare
+mountns/mountns01
diff --git a/testcases/kernel/containers/mountns/Makefile 
b/testcases/kernel/containers/mountns/Makefile
new file mode 100644
index 0000000..f9b6b99
--- /dev/null
+++ b/testcases/kernel/containers/mountns/Makefile
@@ -0,0 +1,23 @@
+# 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/>.
+##############################################################################
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(abs_srcdir)/../Makefile.inc
+
+LDLIBS                  := -lclone -lltp
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/containers/mountns/mountns01.c 
b/testcases/kernel/containers/mountns/mountns01.c
new file mode 100644
index 0000000..4c541ea
--- /dev/null
+++ b/testcases/kernel/containers/mountns/mountns01.c
@@ -0,0 +1,161 @@
+/* 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: mountns01.c
+ *
+ * Tests a shared mount: shared mount can be replicated to as many
+ * mountpoints and all the replicas continue to be exactly same.
+ * Description:
+ * 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 "A" shared
+ * 5. Clones a new child process with CLONE_NEWNS flag
+ * 6. There are two test cases (where X is parent namespace and Y child
+ *    namespace):
+ *    1)
+ *     X: bind mounts "B" to "A"
+ *     Y: must see "A/B"
+ *     X: umounts "A"
+ *    2)
+ *     Y: bind mounts "B" to "A"
+ *     X: must see "A/B"
+ *     Y: umounts "A"
+ ***********************************************************************/
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+#include <sys/mount.h>
+#include <stdio.h>
+#include <errno.h>
+#include "test.h"
+#include "usctest.h"
+#include "libclone.h"
+#include "safe_macros.h"
+#include "safe_file_ops.h"
+#include "mountns_helper.h"
+
+
+char *TCID     = "mountns01";
+int TST_TOTAL  = 2;
+
+
+#if defined(MS_SHARED) && defined(MS_PRIVATE) && defined(MS_REC)
+
+int child_func(void *arg)
+{
+       int ret = 0;
+
+       TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);
+
+       if (access(DIRA"/B", F_OK) == -1)
+               ret = 2;
+
+       TST_CHECKPOINT_SIGNAL_PARENT(&checkpoint1);
+       TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);
+
+       /* 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;
+       }
+
+       TST_CHECKPOINT_SIGNAL_PARENT(&checkpoint1);
+       TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);
+
+       umount(DIRA);
+       return ret;
+}
+
+static void test(void)
+{
+       int status;
+
+       /* unshares the mount ns */
+       if (unshare(CLONE_NEWNS) == -1)
+               tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
+       /* makes sure parent mounts/umounts have no effect on a real system */
+       SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL);
+
+       /* bind mounts DIRA to itself */
+       SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL);
+
+       /* makes mount DIRA shared */
+       SAFE_MOUNT(cleanup, "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");
+
+       /* bind mounts DIRB to DIRA making contents of DIRB visible
+        * in DIRA */
+       SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL);
+
+       TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2);
+       TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1);
+
+       SAFE_UMOUNT(cleanup, DIRA);
+
+       TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2);
+       TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1);
+
+       if (access(DIRA"/B", F_OK) == 0)
+               tst_resm(TPASS, "shared mount in child passed");
+       else
+               tst_resm(TFAIL, "shared mount in child failed");
+
+       TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2);
+
+
+       SAFE_WAIT(cleanup, &status);
+       if (WIFEXITED(status)) {
+               if ((WEXITSTATUS(status) == 0))
+                       tst_resm(TPASS, "shared mount in parent passed");
+               else
+                       tst_resm(TFAIL, "shared mount in parent failed");
+       }
+       if (WIFSIGNALED(status)) {
+               tst_resm(TBROK, "child was killed with signal %s",
+                        tst_strsig(WTERMSIG(status)));
+               return;
+       }
+
+       SAFE_UMOUNT(cleanup, DIRA);
+}
+
+int main(int argc, char *argv[])
+{
+       const char *msg;
+       int lc;
+
+       msg = parse_opts(argc, argv, NULL, NULL);
+       if (msg != NULL)
+               tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+       setup();
+
+       for (lc = 0; TEST_LOOPING(lc); lc++)
+               test();
+
+       cleanup();
+       tst_exit();
+}
+
+#else
+int main(void)
+{
+       tst_brkm(TCONF, NULL, "needed mountflags are not defined");
+}
+#endif
diff --git a/testcases/kernel/containers/mountns/mountns_helper.h 
b/testcases/kernel/containers/mountns/mountns_helper.h
new file mode 100644
index 0000000..cb9c16d
--- /dev/null
+++ b/testcases/kernel/containers/mountns/mountns_helper.h
@@ -0,0 +1,66 @@
+/* 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"
+struct tst_checkpoint checkpoint1;
+struct tst_checkpoint checkpoint2;
+
+
+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(NULL);
+       check_newns();
+       tst_tmpdir();
+       TST_CHECKPOINT_INIT(&checkpoint1);
+       TST_CHECKPOINT_INIT(&checkpoint2);
+       SAFE_MKDIR(cleanup, DIRA, 0777);
+       SAFE_MKDIR(cleanup, DIRB, 0777);
+       SAFE_TOUCH(cleanup, DIRA"/A", 0, NULL);
+       SAFE_TOUCH(cleanup, DIRB"/B", 0, NULL);
+}
-- 
1.8.3.1


------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to