[CRIU] [PATCH v3 4/7] save net device confs bunched with criu sysctl API

Pavel Emelyanov xemul at parallels.com
Tue Oct 7 04:56:00 PDT 2014


On 10/01/2014 02:42 PM, Pavel Tikhomirov wrote:
> Signed-off-by: Pavel Tikhomirov <ptikhomirov at parallels.com>
> ---
>  net.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 54 insertions(+), 1 deletion(-)
> 
> diff --git a/net.c b/net.c
> index def4fdc..05616cf 100644
> --- a/net.c
> +++ b/net.c
> @@ -18,6 +18,7 @@
>  #include "tun.h"
>  #include "util-pie.h"
>  #include "plugin.h"
> +#include "sysctl.h"
>  
>  #include "protobuf.h"
>  #include "protobuf/netdev.pb-c.h"
> @@ -79,6 +80,41 @@ char *devconfs[] = {
>  
>  #define NET_DEV_CONF_SIZE 27
>  
> +static int ipv4_conf_op(char *dir, int *conf, int op)

Make the routine accept the char *tgt which can be one of
"default", "all" or $device_name and form the path itself.
This would eliminate the PATH_MAX array in dump_one_netdev.

> +{
> +	int ret;
> +	int i, j;
> +	struct sysctl_req req[NET_DEV_CONF_SIZE + 1];
> +	int sdir = strlen(dir);
> +
> +	for (i = 0; devconfs[i]; i++) {
> +		char *path;
> +		int size = sdir + strlen(devconfs[i]) + 2;
> +
> +		path = xmalloc(size);
> +		if (!path) {
> +			ret = -1;
> +			goto free;
> +		}
> +		snprintf(path, size, "%s/%s", dir, devconfs[i]);
> +
> +		req[i].name = path;
> +		req[i].arg = &conf[i];
> +		req[i].type = CTL_32;
> +	}
> +	req[i].name = NULL;
> +
> +	ret = sysctl_op(req, op);
> +	if (ret < 0)
> +		pr_err("Failed to read %s/<confs>\n", dir);
> +free:
> +	for (j = 0; j < i; j++)
> +		xfree(req[j].name);
> +	if (ret < 0)
> +		return -1;
> +	return 0;
> +}
> +
>  int write_netdev_img(NetDeviceEntry *nde, struct cr_fdset *fds)
>  {
>  	return pb_write_one(fdset_fd(fds, CR_FD_NETDEV), nde, PB_NETDEV);



More information about the CRIU mailing list