[CRIU] [PATCH] net: Move node's net fd reference into service fd

Andrew Vagin avagin at virtuozzo.com
Tue Nov 17 05:57:13 PST 2015


On Tue, Nov 17, 2015 at 04:44:51PM +0300, Cyrill Gorcunov wrote:
> So we keep it and dont close inside close_old_fds()
> helper but pass into veth creation so the kernel
> can fetch the net namespace of the veth peer.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  include/servicefd.h |  1 +
>  net.c               | 12 ++++++++++--
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/include/servicefd.h b/include/servicefd.h
> index 3c6e08a7472e..a9e35a223420 100644
> --- a/include/servicefd.h
> +++ b/include/servicefd.h
> @@ -18,6 +18,7 @@ enum sfd_type {
>  	ROOT_FD_OFF,	/* Root of the namespace we dump/restore */
>  	CGROUP_YARD,
>  	USERNSD_SK,	/* Socket for usernsd */
> +	NS_FD_OFF,	/* Node's net namespace fd */
>  
>  	SERVICE_FD_MAX
>  };
> diff --git a/net.c b/net.c
> index cca5ef884a1c..b1d58984623b 100644
> --- a/net.c
> +++ b/net.c
> @@ -28,7 +28,6 @@
>  #include "protobuf.h"
>  #include "protobuf/netdev.pb-c.h"
>  
> -static int ns_fd = -1;
>  static int ns_sysfs_fd = -1;
>  
>  int read_ns_sys_file(char *path, char *buf, int len)
> @@ -461,6 +460,7 @@ enum {
>  
>  static int veth_link_info(NetDeviceEntry *nde, struct newlink_req *req)
>  {
> +	int ns_fd = get_service_fd(NS_FD_OFF);
>  	struct rtattr *veth_data, *peer_data;
>  	struct ifinfomsg ifm;
>  	struct veth_pair *n;
> @@ -489,6 +489,7 @@ static int veth_link_info(NetDeviceEntry *nde, struct newlink_req *req)
>  
>  static int venet_link_info(NetDeviceEntry *nde, struct newlink_req *req)
>  {
> +	int ns_fd = get_service_fd(NS_FD_OFF);
>  	struct rtattr *venet_data;
>  
>  	BUG_ON(ns_fd < 0);
> @@ -906,13 +907,15 @@ int prepare_net_ns(int pid)
>  	if (!ret)
>  		ret = restore_iptables(pid);
>  
> -	close(ns_fd);
> +	close_service_fd(NS_FD_OFF);
>  
>  	return ret;
>  }
>  
>  int netns_keep_nsfd(void)
>  {
> +	int ns_fd;
> +
>  	if (!(root_ns_mask & CLONE_NEWNET))
>  		return 0;
>  
> @@ -928,6 +931,11 @@ int netns_keep_nsfd(void)
>  		return -1;
>  	}
>  
> +	if (install_service_fd(NS_FD_OFF, ns_fd) < 0) {
> +		pr_err("Can't install ns net reference\n");
> +		return -1;
> +	}

	close(ns_fd);

> +
>  	pr_info("Saved netns fd for links restore\n");
>  	return 0;
>  }
> -- 
> 2.5.0
> 


More information about the CRIU mailing list