zdtm: add mntns_pivot_root_ro test

This checks that superblock readonly flag is applied to nested mntns
roots on restore.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov 2022-01-13 10:46:44 +03:00 committed by Andrei Vagin
parent 2a3d2bc284
commit a379d4d945
4 changed files with 35 additions and 0 deletions

View file

@ -402,6 +402,7 @@ TST_DIR = \
mnt_ext_root \
mnt_ext_collision \
mntns_pivot_root \
mntns_pivot_root_ro \
mnt_tracefs \
mntns_deleted \
unlink_regular00 \
@ -580,6 +581,7 @@ socket-tcp-closed-last-ack: CFLAGS += -D ZDTM_TCP_LAST_ACK
socket-tcp-skip-in-flight: CFLAGS += -D ZDTM_IPV4V6
tun_ns: CFLAGS += -DTUN_NS
mnt_ext_manual: CFLAGS += -D ZDTM_EXTMAP_MANUAL
mntns_pivot_root_ro: CFLAGS += -DMNTNS_PIVOT_ROOT_RO
sigpending: LDLIBS += -lrt
vdso01: LDLIBS += -lrt
scm01: CFLAGS += -DKEEP_SENT_FD

View file

@ -8,6 +8,7 @@
#include <linux/limits.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <errno.h>
#include "zdtmtst.h"
#include "lock.h"
@ -86,6 +87,21 @@ static int child(void)
}
close(fd);
#ifdef MNTNS_PIVOT_ROOT_RO
/*
* Hack to make cr_pivot_root work on readonly mntns root,
* normally nested containers have /tmp directory
*/
mkdir("tmp", 0755);
/*
* Make superblock readonly
*/
if (mount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL)) {
pr_perror("remount_ro");
goto err;
}
#endif
futex_set_and_wake(futex, TEST_CHILD);
futex_wait_while_lt(futex, TEST_CHECK);
@ -94,6 +110,21 @@ static int child(void)
goto err;
}
#ifdef MNTNS_PIVOT_ROOT_RO
/*
* Check superblock readonly
*/
fd = open(testfile, O_WRONLY);
if (fd >= 0) {
pr_err("Open on readonly superblock should fail\n");
close(fd);
goto err;
} else if (errno != EROFS) {
pr_perror("open write");
goto err;
}
#endif
futex_set_and_wake(futex, TEST_EXIT);
return 0;
err:

View file

@ -0,0 +1 @@
mntns_pivot_root.c

View file

@ -0,0 +1 @@
mntns_pivot_root.desc