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

Cyrill Gorcunov gorcunov at gmail.com
Thu Nov 19 04:31:59 PST 2015


On Thu, Nov 19, 2015 at 03:16:25PM +0300, Pavel Emelyanov wrote:
> 
> >> @@ -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);
> 
i> Would you re-submit the patch?

Sure. Sorry for delay
-------------- next part --------------
>From 5ed62330fd59c7c6a1add4b20d9f30f2823365fa Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Tue, 17 Nov 2015 11:46:11 +0300
Subject: [PATCH v2] net: Move node's net fd reference into service fd

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.

v2 (by avagin@):
 - don't forget to close opened descriptor

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/servicefd.h |  1 +
 net.c               | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 4 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..bde517790d31 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, ret;
+
 	if (!(root_ns_mask & CLONE_NEWNET))
 		return 0;
 
@@ -928,8 +931,14 @@ int netns_keep_nsfd(void)
 		return -1;
 	}
 
-	pr_info("Saved netns fd for links restore\n");
-	return 0;
+	ret = install_service_fd(NS_FD_OFF, ns_fd);
+	if (ret < 0)
+		pr_err("Can't install ns net reference\n");
+	else
+		pr_info("Saved netns fd for links restore\n");
+	close(ns_fd);
+
+	return ret >= 0 ? 0 : -1;
 }
 
 int network_lock(void)
-- 
2.5.0



More information about the CRIU mailing list