2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 13:58:34 +00:00

zdtm: test multiple ext bindmounts with no common root and same master

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov
2022-05-20 12:11:49 +03:00
committed by Andrei Vagin
parent 229c5df5ce
commit 4cc8a18f3b
3 changed files with 124 additions and 0 deletions

View File

@@ -406,6 +406,7 @@ TST_DIR = \
mntns_pivot_root \
mntns_pivot_root_ro \
mnt_ext_sharing \
mnt_ext_multiple \
mount_complex_sharing \
mnt_tracefs \
mntns_deleted \

View File

@@ -0,0 +1,118 @@
#include <sched.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Check multiple non-common root external mounts with same external master";
const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>";
char *dirname = "mnt_ext_multiple.test";
char *source = "zdtm_ext_multiple";
char *ext_source = "zdtm_ext_multiple.ext";
TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv)
{
char *root, testdir[PATH_MAX];
char dst_a[PATH_MAX], dst_b[PATH_MAX];
char src[PATH_MAX], src_a[PATH_MAX], src_b[PATH_MAX];
char nsdst_a[PATH_MAX], nsdst_b[PATH_MAX];
char *tmp = "/tmp/zdtm_ext_multiple.tmp";
char *zdtm_newns = getenv("ZDTM_NEWNS");
root = getenv("ZDTM_ROOT");
if (root == NULL) {
pr_perror("root");
return 1;
}
if (!zdtm_newns) {
pr_perror("ZDTM_NEWNS is not set");
return 1;
} else if (strcmp(zdtm_newns, "1")) {
goto test;
}
/* Prepare directories in test root */
sprintf(testdir, "%s/%s", root, dirname);
mkdir(testdir, 0755);
sprintf(dst_a, "%s/%s/dst_a", root, dirname);
mkdir(dst_a, 0755);
sprintf(dst_b, "%s/%s/dst_b", root, dirname);
mkdir(dst_b, 0755);
/* Prepare directories in criu root */
mkdir(tmp, 0755);
if (mount(source, tmp, "tmpfs", 0, NULL)) {
pr_perror("mount tmpfs");
return 1;
}
if (mount(NULL, tmp, NULL, MS_PRIVATE, NULL)) {
pr_perror("make private");
return 1;
}
sprintf(src, "%s/src", tmp);
mkdir(src, 0755);
/* Create a shared mount in criu mntns */
if (mount(ext_source, src, "tmpfs", 0, NULL)) {
pr_perror("mount tmpfs");
return 1;
}
if (mount(NULL, src, NULL, MS_PRIVATE, NULL)) {
pr_perror("make private");
return 1;
}
if (mount(NULL, src, NULL, MS_SHARED, NULL)) {
pr_perror("make shared");
return 1;
}
/*
* Create temporary mntns, next mounts will not show up in criu mntns
*/
if (unshare(CLONE_NEWNS)) {
pr_perror("unshare");
return 1;
}
/*
* Populate to the tests root subdirectories of the src mount
*/
sprintf(src_a, "%s/src/a", tmp);
mkdir(src_a, 0755);
if (mount(src_a, dst_a, NULL, MS_BIND, NULL)) {
pr_perror("bind");
return 1;
}
sprintf(src_b, "%s/src/b", tmp);
mkdir(src_b, 0755);
if (mount(src_b, dst_b, NULL, MS_BIND, NULL)) {
pr_perror("bind");
return 1;
}
test:
test_init(argc, argv);
/* Make "external" mounts to have external master */
sprintf(nsdst_a, "/%s/dst_a", dirname);
if (mount(NULL, nsdst_a, NULL, MS_SLAVE, NULL)) {
pr_perror("make slave");
return 1;
}
sprintf(nsdst_b, "/%s/dst_b", dirname);
if (mount(NULL, nsdst_b, NULL, MS_SLAVE, NULL)) {
pr_perror("make slave");
return 1;
}
test_daemon();
test_waitsig();
pass();
return 0;
}

View File

@@ -0,0 +1,5 @@
{ 'dopts': '--external mnt[/mnt_ext_multiple.test/dst_a]:MNT_A --external mnt[/mnt_ext_multiple.test/dst_b]:MNT_B',
'feature': 'mnt_id move_mount_set_group',
'flavor': 'ns uns',
'flags': 'suid',
'ropts': '--external mnt[MNT_A]:/tmp/zdtm_ext_multiple.tmp/src/a --external mnt[MNT_B]:/tmp/zdtm_ext_multiple.tmp/src/b --no-mntns-compat-mode'}