Commit 4a15f013 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: Check that files from alien mnt ns are handled (v2)

Check that files opened before switching to new mount namespace
remain in it after restore. Right now this is not so :( Andrey is
fixing the issue.

Christopher, can you check whether the ns_child's call to system()
works in your minimal set-ups (it launches cat and awk). If not,
then I should rewrite this routine in pure C.

The first version was written by Pavel (xemul@).

v2: don't use test_init_ns
    don't call awk and cat
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 6903cc96
...@@ -174,6 +174,7 @@ static/netns ...@@ -174,6 +174,7 @@ static/netns
static/cgroup00 static/cgroup00
static/cgroup01 static/cgroup01
ns/static/clean_mntns ns/static/clean_mntns
ns/static/mntns_open
" "
TEST_CR_KERNEL=" TEST_CR_KERNEL="
...@@ -207,6 +208,7 @@ cgroup00 ...@@ -207,6 +208,7 @@ cgroup00
cgroup01 cgroup01
clean_mntns clean_mntns
deleted_dev deleted_dev
mntns_open
" "
source $(readlink -f `dirname $0`/env.sh) || exit 1 source $(readlink -f `dirname $0`/env.sh) || exit 1
...@@ -389,7 +391,7 @@ start_test() ...@@ -389,7 +391,7 @@ start_test()
mkdir -p dump mkdir -p dump
ZDTM_ROOT=`mktemp -d /tmp/criu-root.XXXXXX` ZDTM_ROOT=`mktemp -d /tmp/criu-root.XXXXXX`
ZDTM_ROOT=`readlink -f $ZDTM_ROOT` ZDTM_ROOT=`readlink -f $ZDTM_ROOT`
mount --bind . $ZDTM_ROOT || return 1 mount --make-private --bind . $ZDTM_ROOT || return 1
fi fi
construct_root $ZDTM_ROOT $tdir/$tname || return 1 construct_root $ZDTM_ROOT $tdir/$tname || return 1
export ZDTM_NEWNS=1 export ZDTM_NEWNS=1
......
...@@ -164,6 +164,7 @@ TST_DIR = \ ...@@ -164,6 +164,7 @@ TST_DIR = \
cgroup00 \ cgroup00 \
rmdir_open \ rmdir_open \
cgroup01 \ cgroup01 \
mntns_open \
TST_DIR_FILE = \ TST_DIR_FILE = \
chroot \ chroot \
......
#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 "zdtmtst.h"
#ifndef CLONE_NEWNS
#define CLONE_NEWNS 0x00020000
#endif
const char *test_doc = "Check that mnt_id is repsected";
const char *test_author = "Pavel Emelianov <xemul@parallels.com>";
#define MPTS_FILE "F"
char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);
char fpath[PATH_MAX];
#define NS_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
struct ns_exec_args {
char stack[NS_STACK_SIZE];
char stack_ptr[0];
int fd;
};
#define AWK_OK 13
#define AWK_FAIL 42
static int get_mntid(int fd)
{
char str[256];
int mnt_id = -1;
FILE *f;
snprintf(str, sizeof(str), "/proc/self/fdinfo/%d", fd);
f = fopen(str, "r");
if (!f) {
err("Can't open %s to parse", str);
return -1;
}
while (fgets(str, sizeof(str), f)) {
if (sscanf(str, "mnt_id: %d", &mnt_id) == 1)
break;
}
fclose(f);
return mnt_id;
}
int ns_child(void *_arg)
{
struct ns_exec_args *args = _arg;
int fd2;
int id1, id2;
fd2 = open(fpath, O_RDWR);
test_waitsig();
id1 = get_mntid(args->fd);
id2 = get_mntid(fd2);
test_msg("%d %d", id1, id2);
if (id1 <0 || id2 < 0)
exit(1);
if (id1 > 0 && id1 != id2)
exit(AWK_OK);
else
exit(AWK_FAIL);
}
int main(int argc, char **argv)
{
struct ns_exec_args args;
pid_t pid = -1;
test_init(argc, argv);
snprintf(fpath, sizeof(fpath), "%s/%s", dirname, MPTS_FILE);
if (mkdir(dirname, 0600) < 0) {
fail("Can't make zdtm_sys");
return 1;
}
if (getenv("ZDTM_NOSUBNS") == NULL) {
args.fd = open(fpath, O_CREAT | O_RDWR, 0600);
if (args.fd < 0) {
fail("Can't open file");
return 1;
}
pid = clone(ns_child, args.stack_ptr, CLONE_NEWNS | SIGCHLD, &args);
if (pid < 0) {
err("Unable to fork child");
return 1;
}
close(args.fd);
}
test_daemon();
test_waitsig();
if (pid > 0) {
kill(pid, SIGTERM);
int status = 1;
wait(&status);
if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == AWK_OK)
pass();
else if (WEXITSTATUS(status) == AWK_FAIL)
fail("Mount ID not restored");
else
fail("Failed to check mount IDs (%d)", WEXITSTATUS(status));
} else
fail("Test died");
}
unlink(fpath);
rmdir(dirname);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment