[CRIU] [PATCH 04/12] net: transfer ns_id structures to functions about c/r-ing netns

Andrei Vagin avagin at openvz.org
Tue Mar 21 17:28:45 PDT 2017


From: Andrei Vagin <avagin at virtuozzo.com>

It will be used to get or set netns id-s.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/include/net.h |  3 ++-
 criu/namespaces.c  |  2 +-
 criu/net.c         | 66 +++++++++++++++++++++++++++---------------------------
 3 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/criu/include/net.h b/criu/include/net.h
index 9af6f44..72275b8 100644
--- a/criu/include/net.h
+++ b/criu/include/net.h
@@ -11,7 +11,8 @@
 #endif
 
 struct cr_imgset;
-extern int dump_net_ns(int ns_id);
+struct ns_id;
+extern int dump_net_ns(struct ns_id *ns);
 extern int prepare_net_namespaces(void);
 extern void fini_net_namespaces(void);
 extern int netns_keep_nsfd(void);
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 77308cc..40362ee 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -1266,7 +1266,7 @@ static int do_dump_namespaces(struct ns_id *ns)
 	case CLONE_NEWNET:
 		pr_info("Dump NET namespace info %d via %d\n",
 				ns->id, ns->ns_pid);
-		ret = dump_net_ns(ns->id);
+		ret = dump_net_ns(ns);
 		break;
 	default:
 		pr_err("Unknown namespace flag %x\n", ns->nd->cflag);
diff --git a/criu/net.c b/criu/net.c
index daf8db5..cdd1985 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -367,7 +367,7 @@ int write_netdev_img(NetDeviceEntry *nde, struct cr_imgset *fds, struct nlattr *
 }
 
 static int dump_one_netdev(int type, struct ifinfomsg *ifi,
-		struct nlattr **tb, struct cr_imgset *fds,
+		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds,
 		int (*dump)(NetDeviceEntry *, struct cr_imgset *, struct nlattr **info))
 {
 	int ret = -1;
@@ -483,13 +483,13 @@ static char *link_kind(struct ifinfomsg *ifi, struct nlattr **tb)
 }
 
 static int dump_unknown_device(struct ifinfomsg *ifi, char *kind,
-		struct nlattr **tb, struct cr_imgset *fds)
+		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
 	int ret;
 
 	ret = run_plugins(DUMP_EXT_LINK, ifi->ifi_index, ifi->ifi_type, kind);
 	if (ret == 0)
-		return dump_one_netdev(ND_TYPE__EXTLINK, ifi, tb, fds, NULL);
+		return dump_one_netdev(ND_TYPE__EXTLINK, ifi, tb, ns, fds, NULL);
 
 	if (ret == -ENOTSUP)
 		pr_err("Unsupported link %d (type %d kind %s)\n",
@@ -564,7 +564,7 @@ static int dump_macvlan(NetDeviceEntry *nde, struct cr_imgset *imgset, struct nl
 }
 
 static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
-		struct nlattr **tb, struct cr_imgset *fds)
+		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
 	if (!strcmp(kind, "veth"))
 		/*
@@ -575,11 +575,11 @@ static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
 		 * Sigh... we have to assume, that the veth device is a
 		 * connection to the outer world and just dump this end :(
 		 */
-		return dump_one_netdev(ND_TYPE__VETH, ifi, tb, fds, NULL);
+		return dump_one_netdev(ND_TYPE__VETH, ifi, tb, ns, fds, NULL);
 	if (!strcmp(kind, "tun"))
-		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, fds, dump_tun_link);
+		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, ns, fds, dump_tun_link);
 	if (!strcmp(kind, "bridge"))
-		return dump_one_netdev(ND_TYPE__BRIDGE, ifi, tb, fds, dump_bridge);
+		return dump_one_netdev(ND_TYPE__BRIDGE, ifi, tb, ns, fds, dump_bridge);
 	if (!strcmp(kind, "gretap")) {
 		char *name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
 
@@ -596,31 +596,31 @@ static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
 		pr_warn("GRE tap device %s not supported natively\n", name);
 	}
 	if (!strcmp(kind, "macvlan"))
-		return dump_one_netdev(ND_TYPE__MACVLAN, ifi, tb, fds, dump_macvlan);
+		return dump_one_netdev(ND_TYPE__MACVLAN, ifi, tb, ns, fds, dump_macvlan);
 
-	return dump_unknown_device(ifi, kind, tb, fds);
+	return dump_unknown_device(ifi, kind, tb, ns, fds);
 }
 
 static int dump_one_gendev(struct ifinfomsg *ifi, char *kind,
-		struct nlattr **tb, struct cr_imgset *fds)
+		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
 	if (!strcmp(kind, "tun"))
-		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, fds, dump_tun_link);
+		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, ns, fds, dump_tun_link);
 
-	return dump_unknown_device(ifi, kind, tb, fds);
+	return dump_unknown_device(ifi, kind, tb, ns, fds);
 }
 
 static int dump_one_voiddev(struct ifinfomsg *ifi, char *kind,
-		struct nlattr **tb, struct cr_imgset *fds)
+		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
 	if (!strcmp(kind, "venet"))
-		return dump_one_netdev(ND_TYPE__VENET, ifi, tb, fds, NULL);
+		return dump_one_netdev(ND_TYPE__VENET, ifi, tb, ns, fds, NULL);
 
-	return dump_unknown_device(ifi, kind, tb, fds);
+	return dump_unknown_device(ifi, kind, tb, ns, fds);
 }
 
 static int dump_one_gre(struct ifinfomsg *ifi, char *kind,
-		struct nlattr **tb, struct cr_imgset *fds)
+		struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
 {
 	if (!strcmp(kind, "gre")) {
 		char *name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
@@ -637,7 +637,7 @@ static int dump_one_gre(struct ifinfomsg *ifi, char *kind,
 		pr_warn("GRE tunnel device %s not supported natively\n", name);
 	}
 
-	return dump_unknown_device(ifi, kind, tb, fds);
+	return dump_unknown_device(ifi, kind, tb, ns, fds);
 }
 
 static int dump_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
@@ -659,7 +659,7 @@ static int dump_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
 	pr_info("\tLD: Got link %d, type %d\n", ifi->ifi_index, ifi->ifi_type);
 
 	if (ifi->ifi_type == ARPHRD_LOOPBACK) 
-		return dump_one_netdev(ND_TYPE__LOOPBACK, ifi, tb, fds, NULL);
+		return dump_one_netdev(ND_TYPE__LOOPBACK, ifi, tb, ns, fds, NULL);
 
 	kind = link_kind(ifi, tb);
 	if (!kind)
@@ -667,20 +667,20 @@ static int dump_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
 
 	switch (ifi->ifi_type) {
 	case ARPHRD_ETHER:
-		ret = dump_one_ethernet(ifi, kind, tb, fds);
+		ret = dump_one_ethernet(ifi, kind, tb, ns, fds);
 		break;
 	case ARPHRD_NONE:
-		ret = dump_one_gendev(ifi, kind, tb, fds);
+		ret = dump_one_gendev(ifi, kind, tb, ns, fds);
 		break;
 	case ARPHRD_VOID:
-		ret = dump_one_voiddev(ifi, kind, tb, fds);
+		ret = dump_one_voiddev(ifi, kind, tb, ns, fds);
 		break;
 	case ARPHRD_IPGRE:
-		ret = dump_one_gre(ifi, kind, tb, fds);
+		ret = dump_one_gre(ifi, kind, tb, ns, fds);
 		break;
 	default:
 unk:
-		ret = dump_unknown_device(ifi, kind, tb, fds);
+		ret = dump_unknown_device(ifi, kind, tb, ns, fds);
 		break;
 	}
 
@@ -856,7 +856,7 @@ out:
 
 }
 
-static int dump_links(struct cr_imgset *fds)
+static int dump_links(struct ns_id *ns, struct cr_imgset *fds)
 {
 	int sk, ret;
 	struct {
@@ -880,7 +880,7 @@ static int dump_links(struct cr_imgset *fds)
 	req.nlh.nlmsg_seq = CR_NLMSG_SEQ;
 	req.g.rtgen_family = AF_PACKET;
 
-	ret = do_rtnl_req(sk, &req, sizeof(req), dump_one_link, NULL, NULL, fds);
+	ret = do_rtnl_req(sk, &req, sizeof(req), dump_one_link, NULL, ns, fds);
 	close(sk);
 out:
 	return ret;
@@ -1369,7 +1369,7 @@ static inline int dump_iptables(struct cr_imgset *fds)
 	return 0;
 }
 
-static int dump_netns_conf(struct cr_imgset *fds)
+static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds)
 {
 	int ret = -1;
 	int i;
@@ -1639,21 +1639,21 @@ static int mount_ns_sysfs(void)
 	return ns_sysfs_fd >= 0 ? 0 : -1;
 }
 
-int dump_net_ns(int ns_id)
+int dump_net_ns(struct ns_id *ns)
 {
 	struct cr_imgset *fds;
 	int ret;
 
-	fds = cr_imgset_open(ns_id, NETNS, O_DUMP);
+	fds = cr_imgset_open(ns->id, NETNS, O_DUMP);
 	if (fds == NULL)
 		return -1;
 
 	ret = mount_ns_sysfs();
 	if (!(opts.empty_ns & CLONE_NEWNET)) {
 		if (!ret)
-			ret = dump_netns_conf(fds);
+			ret = dump_netns_conf(ns, fds);
 		if (!ret)
-			ret = dump_links(fds);
+			ret = dump_links(ns, fds);
 		if (!ret)
 			ret = dump_ifaddr(fds);
 		if (!ret)
@@ -1675,9 +1675,9 @@ int dump_net_ns(int ns_id)
 	return ret;
 }
 
-static int prepare_net_ns(int nsid)
+static int prepare_net_ns(struct ns_id *ns)
 {
-	int ret = 0;
+	int ret = 0, nsid = ns->id;
 	NetnsEntry *netns = NULL;
 
 	if (!(opts.empty_ns & CLONE_NEWNET)) {
@@ -1731,7 +1731,7 @@ static int do_create_net_ns(struct ns_id *ns)
 		pr_perror("Unable to create a new netns");
 		return -1;
 	}
-	if (prepare_net_ns(ns->id))
+	if (prepare_net_ns(ns))
 		return -1;
 	if (open_net_ns(ns))
 		return -1;
-- 
2.7.4



More information about the CRIU mailing list