Skip to content

Commit dfee193

Browse files
committed
zdtm: Add ztatic/mnt_ext_file_bind_auto test
The test creates a file bindmount in criu mntns and binds it into test mntns, this external file bindmount is autodetected and restored via "--external mnt[]" criu option. Note: In previous patch we fix the problem on this code path where file bindmount restore fails as there is excess "/" in source path. Signed-off-by: Pavel Tikhomirov <[email protected]>
1 parent 072faba commit dfee193

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

test/zdtm/static/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ TST_FILE = \
381381
sk-unix-listen02 \
382382
sk-unix-listen03 \
383383
sk-unix-listen04 \
384+
mnt_ext_file_bind_auto \
384385

385386
TST_DIR = \
386387
cwd00 \
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#include <sys/mount.h>
2+
#include <linux/limits.h>
3+
#include <sys/stat.h>
4+
#include <sched.h>
5+
#include <fcntl.h>
6+
#include <stdlib.h>
7+
#include <string.h>
8+
9+
#include "zdtmtst.h"
10+
11+
const char *test_doc = "Check if external file mount works";
12+
const char *test_author = "Pavel Tikhomirov <[email protected]>";
13+
14+
char *filename = "mnt_ext_file_bind_auto_bind_auto.file";
15+
TEST_OPTION(filename, string, "file name", 1);
16+
17+
char *source = "mnt_ext_file_bind_auto_bind_auto.source";
18+
19+
int create_file(const char *path)
20+
{
21+
int fd;
22+
23+
fd = open(path, O_CREAT | O_RDWR, 0644);
24+
if (fd < 0) {
25+
pr_perror("open");
26+
return -1;
27+
}
28+
29+
close(fd);
30+
return 0;
31+
}
32+
33+
int main(int argc, char **argv)
34+
{
35+
char *zdtm_newns = getenv("ZDTM_NEWNS");
36+
char *tmp = "/tmp/zdtm_ext_file_bind_auto.tmp";
37+
char *sourcefile = "/tmp/zdtm_ext_file_bind_auto.file";
38+
char *root, tmpfile[PATH_MAX], testfile[PATH_MAX];
39+
40+
root = getenv("ZDTM_ROOT");
41+
if (root == NULL) {
42+
pr_perror("root");
43+
return 1;
44+
}
45+
46+
if (!zdtm_newns) {
47+
pr_perror("ZDTM_NEWNS is not set");
48+
return 1;
49+
} else if (strcmp(zdtm_newns, "1")) {
50+
goto test;
51+
}
52+
53+
/* Prepare file bindmount in criu root (source for external file bindmount) */
54+
mkdir(tmp, 0755);
55+
if (mount(source, tmp, "tmpfs", 0, NULL)) {
56+
pr_perror("mount tmpfs");
57+
return 1;
58+
}
59+
if (mount(NULL, tmp, NULL, MS_PRIVATE, NULL)) {
60+
pr_perror("make private");
61+
return 1;
62+
}
63+
64+
sprintf(tmpfile, "%s/%s", tmp, filename);
65+
if (create_file(tmpfile))
66+
return 1;
67+
68+
if (create_file(sourcefile))
69+
return 1;
70+
71+
if (mount(tmpfile, sourcefile, NULL, MS_BIND, NULL)) {
72+
pr_perror("bind");
73+
return 1;
74+
}
75+
76+
umount2(tmp, MNT_DETACH);
77+
78+
/* Prepare file in test root (mount point for external file bindmount) */
79+
sprintf(testfile, "%s/%s", root, filename);
80+
if (create_file(testfile))
81+
return 1;
82+
83+
/*
84+
* Create temporary mntns, next mounts will not show up in criu mntns
85+
* and will be inherited into test mntns
86+
*/
87+
if (unshare(CLONE_NEWNS)) {
88+
pr_perror("unshare");
89+
return 1;
90+
}
91+
92+
if (mount(sourcefile, testfile, NULL, MS_BIND, NULL)) {
93+
pr_perror("bind");
94+
return 1;
95+
}
96+
test:
97+
test_init(argc, argv);
98+
99+
test_daemon();
100+
test_waitsig();
101+
102+
pass();
103+
return 0;
104+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{ 'opts': '--external mnt[]',
2+
'feature': 'mnt_id',
3+
'flavor': 'ns uns',
4+
'flags': 'suid'}

0 commit comments

Comments
 (0)