[CRIU] [PATCHv3 2/2] zdtm: sysctl net.unix.max_dgram_qlen value preservation test

Andrei Vagin avagin at gmail.com
Sun Nov 3 19:59:38 MSK 2019


On Fri, Nov 01, 2019 at 12:00:21PM +0000, Alexander Mikhalitsyn wrote:
> Test checks that if the /proc/sys/net/unix/max_dgram_qlen value has
> been changed in process net namespace, then it is saved after c/r.
> 
> Based-on-patch-by: Cyrill Gorcunov <gorcunov at gmail.com>
> Signed-off-by: Alexander Mikhalitsyn <alexander at mihalicyn.com>
> Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
> ---
>  test/zdtm/lib/Makefile                 |  2 +-
>  test/zdtm/lib/sysctl.c                 | 56 ++++++++++++++++++++++++++
>  test/zdtm/lib/sysctl.h                 |  7 ++++
>  test/zdtm/static/Makefile              |  1 +
>  test/zdtm/static/netns_sub_sysctl.c    | 51 +++++++++++++++++++++++
>  test/zdtm/static/netns_sub_sysctl.desc |  4 ++
>  6 files changed, 120 insertions(+), 1 deletion(-)
>  create mode 100644 test/zdtm/lib/sysctl.c
>  create mode 100644 test/zdtm/lib/sysctl.h
>  create mode 100644 test/zdtm/static/netns_sub_sysctl.c
>  create mode 100644 test/zdtm/static/netns_sub_sysctl.desc
> 
> diff --git a/test/zdtm/lib/Makefile b/test/zdtm/lib/Makefile
> index d2d9f1cc..b87f36e8 100644
> --- a/test/zdtm/lib/Makefile
> +++ b/test/zdtm/lib/Makefile
> @@ -4,7 +4,7 @@ CFLAGS	+= $(USERCFLAGS)
>  
>  LIB	:= libzdtmtst.a
>  
> -LIBSRC	:= datagen.c msg.c parseargs.c test.c streamutil.c lock.c ns.c tcp.c fs.c
> +LIBSRC	:= datagen.c msg.c parseargs.c test.c streamutil.c lock.c ns.c tcp.c fs.c sysctl.c
>  LIBOBJ	:= $(LIBSRC:%.c=%.o)
>  
>  BIN	:= groups
> diff --git a/test/zdtm/lib/sysctl.c b/test/zdtm/lib/sysctl.c
> new file mode 100644
> index 00000000..47dcccb4
> --- /dev/null
> +++ b/test/zdtm/lib/sysctl.c
> @@ -0,0 +1,56 @@
> +#include <fcntl.h>
> +
> +#include "zdtmtst.h"
> +#include "sysctl.h"
> +
> +int sysctl_read_int(const char *name, int *data)
> +{
> +	int fd;
> +	int ret;
> +	char buf[32];
> +
> +	fd = open(name, O_RDONLY);
> +	if (fd < 0) {
> +		pr_perror("Can't open %s", name);
> +		return fd;
> +	}
> +
> +	ret = read(fd, buf, sizeof(buf) - 1);
> +	if (ret < 0) {
> +		pr_perror("Can't read %s", name);
> +		ret = -errno;
> +		goto err;
> +	}
> +
> +	buf[ret] = '\0';
> +
> +	*data = (int)strtoul(buf, NULL, 10);
> +	ret = 0;
> +err:
> +	close(fd);
> +	return ret;
> +}
> +
> +int sysctl_write_int(const char *name, int val)
> +{
> +	int fd;
> +	int ret;
> +	char buf[32];
> +
> +	fd = open(name, O_WRONLY);
> +	if (fd < 0) {
> +		pr_perror("Can't open %s", name);
> +		return fd;
> +	}
> +
> +	sprintf(buf, "%d\n", val);
> +
> +	ret = write(fd, buf, strlen(buf));
> +	if (ret < 0) {
> +		pr_perror("Can't write %d into %s", val, name);
> +		return -errno;
> +	}
> +
> +	close(fd);
> +	return 0;
> +}
> diff --git a/test/zdtm/lib/sysctl.h b/test/zdtm/lib/sysctl.h
> new file mode 100644
> index 00000000..67129102
> --- /dev/null
> +++ b/test/zdtm/lib/sysctl.h
> @@ -0,0 +1,7 @@
> +#ifndef __ZDTM_SYSCTL__
> +#define __ZDTM_SYSCTL__
> +
> +extern int sysctl_read_int(const char *name, int *data);
> +extern int sysctl_write_int(const char *name, int val);
> +
> +#endif
> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
> index a38482f4..887bf4ac 100644
> --- a/test/zdtm/static/Makefile
> +++ b/test/zdtm/static/Makefile
> @@ -207,6 +207,7 @@ TST_NOFILE	:=				\
>  		pipe03				\
>  		netns_sub			\
>  		netns_sub_veth			\
> +		netns_sub_sysctl	\
>  		unlink_multiple_largefiles	\
>  		config_inotify_irmap		\
>  		thp_disable			\
> diff --git a/test/zdtm/static/netns_sub_sysctl.c b/test/zdtm/static/netns_sub_sysctl.c
> new file mode 100644
> index 00000000..893d1804
> --- /dev/null
> +++ b/test/zdtm/static/netns_sub_sysctl.c
> @@ -0,0 +1,51 @@
> +#include <sched.h>
> +
> +#include "zdtmtst.h"
> +#include "sysctl.h"
> +
> +const char *test_doc	= "Check dump and restore a net.unix.max_dgram_qlen sysctl parameter in subns";
> +
> +typedef struct {
> +	const char *path;
> +	int old;
> +	int new;
> +} sysctl_opt_t;
> +
> +#define CONF_UNIX_BASE	"/proc/sys/net/unix"
> +
> +static sysctl_opt_t net_unix_params[] = {
> +	{CONF_UNIX_BASE"/max_dgram_qlen", 0, 0},
> +	{NULL, 0, 0}
> +};
> +
> +int main(int argc, char **argv)
> +{
> +	test_init(argc, argv);
> +
> +	if (unshare(CLONE_NEWNET)) {
> +		perror("unshare");
> +		return 1;
> +	}

test_init creates a new network namespace. Why do we need one more? Do
you want to add the "h" flavor?

> +
> +	for (sysctl_opt_t *p = net_unix_params; p->path != NULL; p++) {
> +		p->old = (((unsigned)lrand48()) % 1023) + 1;
> +		if (sysctl_write_int(p->path, p->old)) {
> +			pr_perror("Can't change %s", p->path);
> +			return -1;
> +		}
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	for (sysctl_opt_t *p = net_unix_params; p->path != NULL; p++) {
> +		sysctl_read_int(p->path, &p->new);
> +		if (p->old != p->new) {
> +			fail();

need to write an error message which will show old and new values
 
> +			return 1;
> +		}
> +	}
> +
> +	pass();
> +	return 0;
> +}
> diff --git a/test/zdtm/static/netns_sub_sysctl.desc b/test/zdtm/static/netns_sub_sysctl.desc
> new file mode 100644
> index 00000000..53584266
> --- /dev/null
> +++ b/test/zdtm/static/netns_sub_sysctl.desc
> @@ -0,0 +1,4 @@
> +{
> +    'flavor': 'ns',

uns?

> +    'flags': 'suid'
> +}
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list