[CRIU] [PATCH 2/2] zdtm: check a case when a root of sub-mntns is read-only

Andrei Vagin avagin at openvz.org
Mon Aug 8 17:23:01 PDT 2016


From: Andrei Vagin <avagin at virtuozzo.com>

It's what we have when ReadOnlyDirectories=/ is set for systemd services.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/Makefile           |  1 +
 test/zdtm/static/mntns_ro_root.c    | 70 +++++++++++++++++++++++++++++++++++++
 test/zdtm/static/mntns_ro_root.desc |  1 +
 3 files changed, 72 insertions(+)
 create mode 100644 test/zdtm/static/mntns_ro_root.c
 create mode 100644 test/zdtm/static/mntns_ro_root.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 353b423..e5248ca 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -231,6 +231,7 @@ TST_DIR		=				\
 		mntns_open			\
 		mntns_link_remap		\
 		mntns_ghost			\
+		mntns_ro_root			\
 		mntns_link_ghost		\
 		mntns_shared_bind		\
 		mntns_shared_bind02		\
diff --git a/test/zdtm/static/mntns_ro_root.c b/test/zdtm/static/mntns_ro_root.c
new file mode 100644
index 0000000..613c25a
--- /dev/null
+++ b/test/zdtm/static/mntns_ro_root.c
@@ -0,0 +1,70 @@
+#define _GNU_SOURCE
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sched.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <sys/mount.h>
+#include <dirent.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check a case when a root is read-only for a sub-mntns";
+const char *test_author	= "Andrew Vagin <avagin at parallels.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+
+int main(int argc, char **argv)
+{
+	task_waiter_t lock;
+	pid_t pid = -1;
+	int status = 1;
+
+	task_waiter_init(&lock);
+	test_init(argc, argv);
+
+	pid = fork();
+	if (pid < 0) {
+		pr_perror("fork");
+		return 1;
+	}
+
+	if (pid == 0) {
+		if (unshare(CLONE_NEWNS)) {
+			pr_perror("unshare");
+			return 1;
+		}
+		if (mount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY | MS_BIND, NULL)) {
+			pr_perror("mount");
+			return 1;
+		}
+
+		task_waiter_complete(&lock, 1);
+		test_waitsig();
+
+		return 0;
+	}
+
+	task_waiter_wait4(&lock, 1);
+	test_daemon();
+	test_waitsig();
+
+	kill(pid, SIGTERM);
+	wait(&status);
+	if (status) {
+		fail("Test died");
+		return 1;
+	}
+	pass();
+
+	return 0;
+}
diff --git a/test/zdtm/static/mntns_ro_root.desc b/test/zdtm/static/mntns_ro_root.desc
new file mode 100644
index 0000000..a8849e0
--- /dev/null
+++ b/test/zdtm/static/mntns_ro_root.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid', 'feature': 'mnt_id'}
-- 
2.7.4



More information about the CRIU mailing list