[CRIU] [PATCH 4/4] test: add a test for vanilla unshare()
Andrew Vagin
avagin at odin.com
Thu May 7 01:10:41 PDT 2015
On Wed, May 06, 2015 at 08:07:54AM -0600, Tycho Andersen wrote:
> This test currently fails, but replicates (in a slightly hacky way viz. the
> unshare in zdtm.sh) the case where criu is too greedy matching external mounts.
>
> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
> ---
> test/zdtm.sh | 6 +-
> test/zdtm/.gitignore | 1 +
> test/zdtm/live/static/Makefile | 1 +
> test/zdtm/live/static/mnt_ext_vanilla.c | 94 ++++++++++++++++++++++++++++++
> test/zdtm/live/static/mnt_ext_vanilla.opts | 1 +
> 5 files changed, 102 insertions(+), 1 deletion(-)
> create mode 100644 test/zdtm/live/static/mnt_ext_vanilla.c
> create mode 100644 test/zdtm/live/static/mnt_ext_vanilla.opts
>
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index 3dee9d6..1478a9c 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -546,7 +546,11 @@ start_test()
> (
> # Here is no way to set FD_CLOEXEC on 3
> exec 3>&-
> - make -C $tdir $tname.pid
> + if [ "$tname" = "mnt_ext_vanilla" ]; then
> + unshare -m make -C $tdir $tname.pid
Can we call ushared from the test source code?
> + else
> + make -C $tdir $tname.pid
> + fi
> )
>
> if [ $? -ne 0 ]; then
> diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
> index 860cf41..8cda656 100644
> --- a/test/zdtm/.gitignore
> +++ b/test/zdtm/.gitignore
> @@ -62,6 +62,7 @@
> /live/static/mmx00
> /live/static/mnt_ext_auto
> /live/static/mnt_ext_master
> +/live/static/mnt_ext_vanilla
> /live/static/mntns_link_ghost
> /live/static/mntns_link_remap
> /live/static/mntns_open
> diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
> index 6e5ffb3..23b8976 100644
> --- a/test/zdtm/live/static/Makefile
> +++ b/test/zdtm/live/static/Makefile
> @@ -122,6 +122,7 @@ TST_NOFILE = \
> remap_dead_pid \
> aio00 \
> fd \
> + mnt_ext_vanilla \
> # jobctl00 \
>
> TST_FILE = \
> diff --git a/test/zdtm/live/static/mnt_ext_vanilla.c b/test/zdtm/live/static/mnt_ext_vanilla.c
> new file mode 100644
> index 0000000..ef9db3a
> --- /dev/null
> +++ b/test/zdtm/live/static/mnt_ext_vanilla.c
> @@ -0,0 +1,94 @@
> +#define _GNU_SOURCE
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <sched.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <sys/mount.h>
> +#include <sys/stat.h>
> +#include <linux/limits.h>
> +
> +#include "zdtmtst.h"
> +
> +#ifndef CLONE_NEWNS
> +#define CLONE_NEWNS 0x00020000
> +#endif
> +
> +const char *test_doc = "Test a not-really-external external mount";
> +const char *test_author = "Tycho Andersen <tycho.andersen at canonical.com>";
> +
> +int main(int argc, char ** argv)
> +{
> + /*
> + * The magic here happens in zdtm.sh, which unshares before it invokes
> + * the test so that criu incorrectly matches external mounts.
> + */
> + test_init(argc, argv);
> +
> + test_daemon();
> + test_waitsig();
> +
> + pass();
> +
> + return 0;
> +
> + /*
> + char src[PATH_MAX], *root;
> + int status;
> + pid_t pid;
> +
> + root = getenv("ZDTM_ROOT");
> + if (root == NULL) {
> + err("root");
> + return 1;
> + }
> +
> + if (strcmp(getenv("ZDTM_NEWNS"), "1"))
> + goto test;
> +
> + sprintf(src, "%s/src", root);
> +
> + mkdir(src, 0700);
> +
> + if (mount(NULL, src, "tmpfs", 0, NULL)) {
> + err("mount");
> + return 1;
> + }
> +
> + pid = fork();
> + if (pid < 0)
> + return 1;
> + if (pid == 0) {
> + pid_t pid2;
> + test_ext_init(argc, argv);
> + pid2 = fork();
> + if (pid2 < 0) {
> + err("fork2");
> + return 1;
> + }
> +
> + if (pid2 == 0) {
> + unshare(CLONE_NEWNS);
> + return 1;
> + }
> +
> + wait(NULL);
> +
> + return 0;
> + }
> +
> + wait(&status);
> + if (status != 0)
> + return 1;
> +
> +test:
> + test_init(argc, argv);
> +
> + test_daemon();
> + test_waitsig();
> +
> + pass();
> +
> + return 0;
> + */
> +}
> diff --git a/test/zdtm/live/static/mnt_ext_vanilla.opts b/test/zdtm/live/static/mnt_ext_vanilla.opts
> new file mode 100644
> index 0000000..b8a0c84
> --- /dev/null
> +++ b/test/zdtm/live/static/mnt_ext_vanilla.opts
> @@ -0,0 +1 @@
> +--ext-mount-map auto --enable-external-sharing --enable-external-masters
> --
> 2.1.4
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list