[CRIU] [PATCH 2/5] zdtm: add a new test to check ghost files in a non-root mntns
Andrey Vagin
avagin at openvz.org
Wed May 11 13:37:04 PDT 2016
From: Andrew Vagin <avagin at virtuozzo.com>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
test/zdtm/static/Makefile | 1 +
test/zdtm/static/mntns_ghost.c | 116 ++++++++++++++++++++++++++++++++++++++
test/zdtm/static/mntns_ghost.desc | 1 +
3 files changed, 118 insertions(+)
create mode 100644 test/zdtm/static/mntns_ghost.c
create mode 100644 test/zdtm/static/mntns_ghost.desc
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 7045734..c84a409 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -222,6 +222,7 @@ TST_DIR = \
unlink_fstat04 \
mntns_open \
mntns_link_remap \
+ mntns_ghost \
mntns_link_ghost \
mntns_shared_bind \
mntns_shared_bind02 \
diff --git a/test/zdtm/static/mntns_ghost.c b/test/zdtm/static/mntns_ghost.c
new file mode 100644
index 0000000..4635e77
--- /dev/null
+++ b/test/zdtm/static/mntns_ghost.c
@@ -0,0 +1,116 @@
+#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 ghost and link-remap files in a few 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) {
+ int fd;
+ DIR *d;
+ struct dirent *de;
+
+ if (unshare(CLONE_NEWNS)) {
+ pr_perror("unshare");
+ return 1;
+ }
+ if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ if (mkdir(dirname, 0600) < 0) {
+ pr_perror("mkdir");
+ return 1;
+ }
+
+ if (mount(dirname, dirname, NULL, MS_BIND, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+ if (chdir(dirname))
+ return 1;
+
+ fd = open("test.ghost", O_CREAT | O_WRONLY, 0600);
+ if (fd < 0) {
+ pr_perror("open");
+ return 1;
+ }
+
+ if (unlink("test.ghost")) {
+ pr_perror("unlink");
+ return 1;
+ }
+
+ task_waiter_complete(&lock, 1);
+ test_waitsig();
+
+ if (close(fd)) {
+ pr_perror("close");
+ return 1;
+ }
+ d = opendir(".");
+ if (d == NULL) {
+ pr_perror("opendir");
+ return 1;
+ }
+ while ((de = readdir(d)) != NULL) {
+ if (!strcmp(de->d_name, "."))
+ continue;
+ if (!strcmp(de->d_name, ".."))
+ continue;
+ pr_err("%s\n", de->d_name);
+ }
+ closedir(d);
+
+ 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_ghost.desc b/test/zdtm/static/mntns_ghost.desc
new file mode 100644
index 0000000..a84aba3
--- /dev/null
+++ b/test/zdtm/static/mntns_ghost.desc
@@ -0,0 +1 @@
+{'flavor': 'ns', 'flags': 'suid', 'feature': 'mnt_id', 'opts': '--link-remap'}
--
2.7.4
More information about the CRIU
mailing list