[CRIU] [PATCH 1/2] test: check non-root shared mounts

Pavel Emelyanov xemul at virtuozzo.com
Wed Nov 23 00:09:32 PST 2016


On 11/22/2016 08:36 AM, Andrei Vagin wrote:
> From: Andrei Vagin <avagin at virtuozzo.com>
> 
> Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
> ---
>  test/zdtm/static/Makefile                 |   1 +
>  test/zdtm/static/mntns_shared_bind03.c    | 124 ++++++++++++++++++++++++++++++
>  test/zdtm/static/mntns_shared_bind03.desc |   1 +
>  3 files changed, 126 insertions(+)
>  create mode 100644 test/zdtm/static/mntns_shared_bind03.c
>  create mode 100644 test/zdtm/static/mntns_shared_bind03.desc
> 
> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
> index 6d8cd75..8c1fd65 100644
> --- a/test/zdtm/static/Makefile
> +++ b/test/zdtm/static/Makefile
> @@ -244,6 +244,7 @@ TST_DIR		=				\
>  		mntns_link_ghost		\
>  		mntns_shared_bind		\
>  		mntns_shared_bind02		\
> +		mntns_shared_bind03		\
>  		mntns_root_bind			\
>  		mntns_root_bind02		\
>  		mntns_overmount			\
> diff --git a/test/zdtm/static/mntns_shared_bind03.c b/test/zdtm/static/mntns_shared_bind03.c
> new file mode 100644
> index 0000000..0d6d320
> --- /dev/null
> +++ b/test/zdtm/static/mntns_shared_bind03.c
> @@ -0,0 +1,124 @@
> +#define _GNU_SOURCE
> +#include <stdbool.h>
> +#include <string.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <sys/stat.h>
> +#include <sched.h>
> +#include <sys/wait.h>
> +#include <stdlib.h>
> +#include <limits.h>
> +
> +#include "zdtmtst.h"
> +
> +#ifndef CLONE_NEWNS
> +#define CLONE_NEWNS     0x00020000
> +#endif
> +
> +const char *test_doc	= "Check shared non-root bind-mounts";

There's already a test with such description in suite and a patch with
the same name in log. It would be nice to have some description of
what the new problem is.

> +const char *test_author	= "Andrew Vagin <avagin at gmail.com>";
> +
> +char *dirname;
> +TEST_OPTION(dirname, string, "directory name", 1);
> +
> +
> +int main(int argc, char **argv)
> +{
> +	test_init(argc, argv);
> +
> +	if (mkdir(dirname, 0700)) {
> +		pr_perror("mkdir");
> +		return 1;
> +	}
> +
> +	if (chdir(dirname))
> +		return 1;
> +
> +	if (mkdir("1", 0700) || mkdir("2", 0700) || mkdir("3", 0700)) {
> +		pr_perror("mkdir");
> +		return 1;
> +	}
> +
> +	if (mkdir("A", 0700)) {
> +		pr_perror("mkdir");
> +		return 1;
> +	}
> +
> +	if (mkdir("B", 0700)) {
> +		pr_perror("mkdir");
> +		return 1;
> +	}
> +
> +	if (mount("1", "1", NULL, MS_BIND, NULL) ||
> +	    mount(NULL, "1", NULL, MS_PRIVATE, NULL) ||
> +	    mount(NULL, "1", NULL, MS_SHARED, NULL)) {
> +		pr_perror("mount");
> +		return 1;
> +	}
> +
> +	if (mount("1", "A", NULL, MS_BIND, NULL) ||
> +	    mount(NULL, "A", NULL, MS_PRIVATE, NULL) ||
> +	    mount(NULL, "A", NULL, MS_SHARED, NULL)) {
> +		pr_perror("mount");
> +		return 1;
> +	}
> +
> +	if (mount("1", "B", NULL, MS_BIND, NULL) ||
> +	    mount(NULL, "B", NULL, MS_SLAVE, NULL)) {
> +		pr_perror("mount");
> +		return 1;
> +	}
> +
> +	if (mkdir("1/D", 0700)) {
> +		pr_perror("mkdir");
> +		return 1;
> +	}
> +
> +	if (mount("1/D", "2", NULL, MS_BIND, NULL)) {
> +		pr_perror("mount");
> +		return 1;
> +	}
> +
> +	if (mount("1", "3", NULL, MS_BIND, NULL)) {
> +		pr_perror("mount");
> +		return 1;
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	if (mkdir("1/D/test", 0700)) {
> +		pr_perror("mkdir");
> +		return 1;
> +	}
> +
> +	if (mount("zdtm_shared", "1/D/test", "tmpfs", 0, NULL)) {
> +		pr_perror("mount");
> +		return 1;
> +	}
> +
> +	if (mount(NULL, "3", NULL, MS_PRIVATE, NULL)) {
> +		pr_perror("mount");
> +		return 1;
> +	}
> +
> +	if (umount("B/D/test")) {
> +		pr_perror("umount");
> +		return 1;
> +	}
> +	if (umount("2/test")) {
> +		pr_perror("umount");
> +		return 1;
> +	}
> +	if (umount("3/D/test")) {
> +		pr_perror("umount");
> +		return 1;
> +	}
> +
> +	pass();
> +
> +	return 0;
> +}
> diff --git a/test/zdtm/static/mntns_shared_bind03.desc b/test/zdtm/static/mntns_shared_bind03.desc
> new file mode 100644
> index 0000000..a8849e0
> --- /dev/null
> +++ b/test/zdtm/static/mntns_shared_bind03.desc
> @@ -0,0 +1 @@
> +{'flavor': 'ns uns', 'flags': 'suid', 'feature': 'mnt_id'}
> 



More information about the CRIU mailing list