diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index a22a0540f..bf7462756 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -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 diff --git a/test/zdtm/static/mntns_pivot_root.c b/test/zdtm/static/mntns_pivot_root.c index 987b0da3b..9826efde4 100644 --- a/test/zdtm/static/mntns_pivot_root.c +++ b/test/zdtm/static/mntns_pivot_root.c @@ -8,6 +8,7 @@ #include #include #include +#include #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: diff --git a/test/zdtm/static/mntns_pivot_root_ro.c b/test/zdtm/static/mntns_pivot_root_ro.c new file mode 120000 index 000000000..d352a6369 --- /dev/null +++ b/test/zdtm/static/mntns_pivot_root_ro.c @@ -0,0 +1 @@ +mntns_pivot_root.c \ No newline at end of file diff --git a/test/zdtm/static/mntns_pivot_root_ro.desc b/test/zdtm/static/mntns_pivot_root_ro.desc new file mode 120000 index 000000000..8708421ed --- /dev/null +++ b/test/zdtm/static/mntns_pivot_root_ro.desc @@ -0,0 +1 @@ +mntns_pivot_root.desc \ No newline at end of file