Skip to contentSkip to conversation

NetNS and Netdev follow-up patches

PATCH New Dan Smith 2 participants 8 messages Mar 22, 2010 – Mar 30, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Dan Smith

author
#0 lore raw

These patches fix a couple of post-ack issues that Oren brought up, as well as perform some cleanups to some of the more sticky error paths.

It also fixes compiling without NETNS support, and adds a flag to make checkpoint ignore netns/netdev details.

A message that is not in the archive (sent off-list or not yet received): 1269286415-24851-1-git-send-email-danms-r/[email protected]

author
#2 lore raw

PATCH 1/6 C/R: Netdev and NetNS fixes

These are fixes to the netdev/netns code to address things that Oren pointed out after the initial review of that code. Included are:

- Netdev restore function dispatching from a table
- Added a comment about the controverial determination of "initial netns"
- Simplify the E2BIG error handling
- Remove a redundant check for checkpoint support per-device

---
 include/linux/checkpoint_hdr.h |    1 +
 net/checkpoint_dev.c           |  102 +++++++++++++++++++---------------------
 2 files changed, 49 insertions(+), 54 deletions(-)
include/linux/checkpoint_hdr.h +1 -0
index 061d1d5..01553b4 100644
@@ -779,6 +779,7 @@ enum ckpt_netdev_types {
 	CKPT_NETDEV_VETH,
 	CKPT_NETDEV_SIT,
 	CKPT_NETDEV_MACVLAN,
+	CKPT_NETDEV_MAX,
 };
 
 struct ckpt_hdr_netdev {
net/checkpoint_dev.c +48 -54

231 lines not on this page · raw message

Signature · 1 line
1.6.2.5
author
#3 lore raw

PATCH 2/6 Unbreak compiling with CONFIG_CHECKPOINT=n or CONFIG_NET_NS=n

In reply to a message not in the archive

This just changes the code to use CONFIG_CHECKPOINT_NETNS instead of CONFIG_CHECKPOINT, as it shoud have been in the first place.

---
 drivers/net/loopback.c |    4 ++--
 drivers/net/macvlan.c  |    4 ++++
 drivers/net/veth.c     |    4 ++--
 net/ipv6/sit.c         |    4 ++++
 4 files changed, 12 insertions(+), 4 deletions(-)
drivers/net/loopback.c +2 -2
index 77023a7..68120b3 100644
@@ -155,7 +155,7 @@ static void loopback_dev_free(struct net_device *dev)
 	free_netdev(dev);
 }
 
-#ifdef CONFIG_CHECKPOINT
+#ifdef CONFIG_CHECKPOINT_NETNS
 static int loopback_checkpoint(struct ckpt_ctx *ctx, struct net_device *dev)
 {
 	struct ckpt_hdr_netdev *h;
@@ -192,7 +192,7 @@ static const struct net_device_ops loopback_ops = {
 	.ndo_init       = loopback_dev_init,
 	.ndo_start_xmit = loopback_xmit,
 	.ndo_get_stats  = loopback_get_stats,
-#ifdef CONFIG_CHECKPOINT
+#ifdef CONFIG_CHECKPOINT_NETNS
 	.ndo_checkpoint = loopback_checkpoint,
 #endif
 };
drivers/net/macvlan.c +4 -0
index 4d99501..2600514 100644
@@ -495,6 +495,7 @@ static struct net_device_stats *macvlan_dev_get_stats(struct net_device *dev)
 	return stats;
 }
 
+#ifdef CONFIG_CHECKPOINT_NETNS
 static int macvlan_checkpoint(struct ckpt_ctx *ctx, struct net_device *dev)
 {
 	struct macvlan_dev *vlan = netdev_priv(dev);
@@ -535,6 +536,7 @@ static int macvlan_checkpoint(struct ckpt_ctx *ctx, struct net_device *dev)
 
 	return ret;
 }
+#endif
 
 static void macvlan_ethtool_get_drvinfo(struct net_device *dev,
 					struct ethtool_drvinfo *drvinfo)
@@ -582,7 +584,9 @@ static const struct net_device_ops macvlan_netdev_ops = {
 	.ndo_set_multicast_list	= macvlan_set_multicast_list,
 	.ndo_get_stats		= macvlan_dev_get_stats,
 	.ndo_validate_addr	= eth_validate_addr,
+#ifdef CONFIG_CHECKPOINT_NETNS
 	.ndo_checkpoint		= macvlan_checkpoint,
+#endif
 };
 
 static void macvlan_setup(struct net_device *dev)
drivers/net/veth.c +2 -2
index db92de8..da55546 100644
@@ -287,7 +287,7 @@ static void veth_dev_free(struct net_device *dev)
 	free_netdev(dev);
 }
 
-#ifdef CONFIG_CHECKPOINT
+#ifdef CONFIG_CHECKPOINT_NETNS
 static int veth_checkpoint(struct ckpt_ctx *ctx, struct net_device *dev)
 {
 	struct ckpt_hdr_netdev *h;
@@ -365,7 +365,7 @@ static const struct net_device_ops veth_netdev_ops = {
 	.ndo_change_mtu      = veth_change_mtu,
 	.ndo_get_stats       = veth_get_stats,
 	.ndo_set_mac_address = eth_mac_addr,
-#ifdef CONFIG_CHECKPOINT
+#ifdef CONFIG_CHECKPOINT_NETNS
 	.ndo_checkpoint      = veth_checkpoint,
 #endif
 };
net/ipv6/sit.c +4 -0
index a9fc331..fe2dd49 100644
@@ -1087,6 +1087,7 @@ static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu)
 	return 0;
 }
 
+#ifdef CONFIG_CHECKPOINT_NETNS
 static int ipip6_checkpoint(struct ckpt_ctx *ctx, struct net_device *dev)
 {
 	struct ckpt_hdr_netdev *h;
@@ -1113,13 +1114,16 @@ static int ipip6_checkpoint(struct ckpt_ctx *ctx, struct net_device *dev)
 
 	return ret;
 }
+#endif
 
 static const struct net_device_ops ipip6_netdev_ops = {
 	.ndo_uninit	= ipip6_tunnel_uninit,
 	.ndo_start_xmit	= ipip6_tunnel_xmit,
 	.ndo_do_ioctl	= ipip6_tunnel_ioctl,
 	.ndo_change_mtu	= ipip6_tunnel_change_mtu,
+#ifdef CONFIG_CHECKPOINT_NETNS
 	.ndo_checkpoint	= ipip6_checkpoint,
+#endif
 };
 
 static void ipip6_tunnel_setup(struct net_device *dev)
Signature · 1 line
1.6.2.5
author
#4 lore raw

PATCH 3/6 Add CHECKPOINT_NONETNS flag

In reply to a message not in the archive

This flag allows you to checkpoint a process without its network namespace, ignoring all the devices within. The restart will then depend on either:

1. Userspace recreating the interfaces necessary to rebind sockets
2. The only open sockets are those listening on 0.0.0.0

With this patch, I can checkpoint a network application with this flag enabled and restart it on a kernel without CONFIG_CHECKPOINT_NETNS support.

---
 include/linux/checkpoint.h |    3 ++-
 kernel/nsproxy.c           |    8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
include/linux/checkpoint.h +2 -1
index 0fb647b..1e7f8d3 100644
@@ -14,6 +14,7 @@
 
 /* checkpoint user flags */
 #define CHECKPOINT_SUBTREE	0x1
+#define CHECKPOINT_NONETNS	0x2
 
 /* restart user flags */
 #define RESTART_TASKSELF	0x1
@@ -56,7 +57,7 @@ extern long do_sys_restart(pid_t pid, int fd,
 #define CKPT_CTX_ERROR		(1 << CKPT_CTX_ERROR_BIT)
 
 /* ckpt_ctx: uflags */
-#define CHECKPOINT_USER_FLAGS		CHECKPOINT_SUBTREE
+#define CHECKPOINT_USER_FLAGS	(CHECKPOINT_SUBTREE | CHECKPOINT_NONETNS)
 #define RESTART_USER_FLAGS  \
 	(RESTART_TASKSELF | \
 	 RESTART_FROZEN | \
kernel/nsproxy.c +6 -2
index b0e67ff..e6a748b 100644
@@ -249,7 +249,8 @@ int ckpt_collect_ns(struct ckpt_ctx *ctx, struct task_struct *t)
 	if (ret < 0)
 		goto out;
 #ifdef CONFIG_CHECKPOINT_NETNS
-	ret = ckpt_obj_collect(ctx, nsproxy->net_ns, CKPT_OBJ_NET_NS);
+	if (!(ctx->uflags & CHECKPOINT_NONETNS))
+		ret = ckpt_obj_collect(ctx, nsproxy->net_ns, CKPT_OBJ_NET_NS);
 	if (ret < 0)
 		goto out;
 #endif
@@ -294,7 +295,10 @@ static int do_checkpoint_ns(struct ckpt_ctx *ctx, struct nsproxy *nsproxy)
 		goto out;
 	h->ipc_objref = ret;
 #ifdef CONFIG_CHECKPOINT_NETNS
-	ret = checkpoint_obj(ctx, nsproxy->net_ns, CKPT_OBJ_NET_NS);
+	if (!(ctx->uflags & CHECKPOINT_NONETNS))
+		ret = checkpoint_obj(ctx, nsproxy->net_ns, CKPT_OBJ_NET_NS);
+	else
+		ret = 0;
 	if (ret < 0)
 		goto out;
 	h->net_objref = ret;
Signature · 1 line
1.6.2.5
author
#5 lore raw

PATCH 4/6 Add ckpt_obj_del() to objhash for handling error conditions

In reply to a message not in the archive

This is not something that I would expect to be used in normal situations, but it makes the error path of codependent network interfaces much smoother.

---
 checkpoint/objhash.c       |   30 ++++++++++++++++++++++++++++++
 include/linux/checkpoint.h |    1 +
 2 files changed, 31 insertions(+), 0 deletions(-)
checkpoint/objhash.c +30 -0
index 5ae2e64..306f1b6 100644
@@ -739,6 +739,14 @@ static struct ckpt_obj *obj_new(struct ckpt_ctx *ctx, void *ptr,
 	return obj;
 }
 
+static void obj_del(struct ckpt_ctx *ctx, struct ckpt_obj *obj)
+{
+	hlist_del(&obj->hash);
+	hlist_del(&obj->next);
+	obj->ops->ref_drop(obj->ptr, 1);
+	kfree(obj);
+}
+
 /**************************************************************************
  * Checkpoint
  */
@@ -1175,6 +1183,28 @@ int ckpt_obj_insert(struct ckpt_ctx *ctx, void *ptr,
 EXPORT_SYMBOL(ckpt_obj_insert);
 
 /**
+ * ckpt_obj_del - delete object (by pointer) in objhash
+ * @ctx: checkpoint context
+ * @ref: object reference
+ * @type: object type
+ *
+ * Return: nonzero on failure
+ */
+int ckpt_obj_del(struct ckpt_ctx *ctx, int objref, enum obj_type type)
+{
+	struct ckpt_obj *obj;
+
+	obj = obj_find_by_objref(ctx, objref);
+	BUG_ON(obj && obj->ops->obj_type != type);
+	if (obj) {
+		ckpt_debug("%s deleted from hash\n", obj->ops->obj_name);
+		obj_del(ctx, obj);
+	}
+
+	return obj ? 0 : -ESRCH;
+}
+
+/**
  * ckpt_obj_try_fetch - fetch an object by its identifier
  * @ctx: checkpoint context
  * @objref: object id
include/linux/checkpoint.h +1 -0
index 1e7f8d3..efbc049 100644
@@ -193,6 +193,7 @@ extern void *ckpt_obj_fetch(struct ckpt_ctx *ctx, int objref,
 extern int ckpt_obj_insert(struct ckpt_ctx *ctx, void *ptr, int objref,
 			   enum obj_type type);
 extern int ckpt_obj_reserve(struct ckpt_ctx *ctx);
+extern int ckpt_obj_del(struct ckpt_ctx *ctx, int objref, enum obj_type type);
 
 extern struct ckpt_ctx *ckpt_ctx_get(struct ckpt_ctx *ctx);
 extern void ckpt_ctx_put(struct ckpt_ctx *ctx);
Signature · 1 line
1.6.2.5
author
#6 lore raw

PATCH 5/6 Add rtnl_dellink() helper

In reply to a message not in the archive

This is the kernel equivalent of "ip link del $name" and matches the existing rtnl_newlink() equivalent of "ip link add $name". It factors out the message creation and dispatch code a little further into rtnl_do() before adding the new function.

---
 net/checkpoint_dev.c |   86 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 72 insertions(+), 14 deletions(-)
net/checkpoint_dev.c +72 -14
index 24186c5..0091eb9 100644
@@ -465,22 +465,49 @@ static struct sk_buff *new_link_msg(new_link_fn fn, void *data, char *name)
 	return skb;
 }
 
-static struct net_device *rtnl_newlink(new_link_fn fn, void *data, char *name)
+static struct sk_buff *del_link_msg(char *name)
+{
+	int ret = -ENOMEM;
+	int flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
+	struct nlmsghdr *nlh;
+	struct sk_buff *skb;
+	struct ifinfomsg *ifm;
+
+	skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!skb)
+		return ERR_PTR(-ENOMEM);
+
+	nlh = nlmsg_put(skb, 0, 0, RTM_DELLINK, sizeof(*ifm), flags);
+	if (!nlh)
+		goto out;
+
+	ifm = nlmsg_data(nlh);
+	memset(ifm, 0, sizeof(*ifm));
+
+	ret = nla_put_string(skb, IFLA_IFNAME, name);
+	if (ret)
+		goto out;
+
+	nlmsg_end(skb, nlh);
+
+ out:
+	if (ret < 0) {
+		kfree_skb(skb);
+		skb = ERR_PTR(ret);
+	}
+
+	return skb;
+}
+
+static int rtnl_do(struct sk_buff *skb)
 {
 	int ret = -ENOMEM;
 	struct socket *rtnl = NULL;
-	struct sk_buff *skb = NULL;
+	struct sk_buff *rskb = NULL;
 	struct nlmsghdr *nlh;
 	struct msghdr msg;
 	struct kvec kvec;
 
-	skb = new_link_msg(fn, data, name);
-	if (IS_ERR(skb)) {
-		ckpt_debug("failed to create new link message: %li\n",
-			   PTR_ERR(skb));
-		return ERR_PTR(PTR_ERR(skb));
-	}
-
 	memset(&msg, 0, sizeof(msg));
 	kvec.iov_len = skb->len;
 	kvec.iov_base = skb->head;
@@ -500,25 +527,56 @@ static struct net_device *rtnl_newlink(new_link_fn fn, void *data, char *name)
 		goto out;
 	}
 
-	/* Free the send skb to make room for the receive skb */
-	kfree_skb(skb);
-
-	nlh = rtnl_get_response(rtnl, &skb);
+	nlh = rtnl_get_response(rtnl, &rskb);
 	if (IS_ERR(nlh)) {
 		ret = PTR_ERR(nlh);
 		ckpt_debug("RTNETLINK said: %i\n", ret);
 	}
  out:
 	rtnl_close(rtnl);
+	kfree_skb(rskb);
  out_noclose:
-	kfree_skb(skb);
+	return ret;
+}
 
+static struct net_device *rtnl_newlink(new_link_fn fn, void *data, char *name)
+{
+	struct sk_buff *skb;
+	int ret;
+
+	skb = new_link_msg(fn, data, name);
+	if (IS_ERR(skb)) {
+		ckpt_debug("failed to create new link message: %li\n",
+			   PTR_ERR(skb));
+		return ERR_PTR(PTR_ERR(skb));
+	}
+
+	ret = rtnl_do(skb);
+	kfree_skb(skb);
 	if (ret < 0)
 		return ERR_PTR(ret);
 	else
 		return dev_get_by_name(current->nsproxy->net_ns, name);
 }
 
+static int rtnl_dellink(char *name)
+{
+	struct sk_buff *skb;
+	int ret;
+
+	skb = del_link_msg(name);
+	if (IS_ERR(skb)) {
+		ckpt_debug("failed to create del link message: %li\n",
+			   PTR_ERR(skb));
+		return PTR_ERR(skb);
+	}
+
+	ret = rtnl_do(skb);
+	kfree_skb(skb);
+
+	return ret;
+}
+
 static int netdev_noop(void *data)
 {
 	return 0;
Signature · 1 line
1.6.2.5
author
#7 lore raw

PATCH 6/6 Clean up the error path in restore_veth()

In reply to a message not in the archive

This uses the previously-added rtnl_dellink() helper to tear down the pair all at once by specifying one of the halves by name (which is how userspace does it and how RTNL expects it to be done). It also uses the ckpt_obj_del() function to pull the devices out of the hash and drop the references before it makes the call to destroy. The result is a unified and much cleaner error path for the entire function.

All the "goto err" paths have been checked by injecting errors. They all cleanup the interfaces properly and cleanly.

---
 net/checkpoint_dev.c |   87 +++++++++++++++++--------------------------------
 1 files changed, 30 insertions(+), 57 deletions(-)
net/checkpoint_dev.c +30 -57
index 0091eb9..2bb3d4d 100644
@@ -21,11 +21,6 @@
 #include <net/net_namespace.h>
 #include <net/sch_generic.h>
 
-struct dq_netdev {
-	struct net_device *dev;
-	struct ckpt_ctx *ctx;
-};
-
 struct veth_newlink {
 	char *peer;
 };
@@ -577,25 +572,6 @@ static int rtnl_dellink(char *name)
 	return ret;
 }
 
-static int netdev_noop(void *data)
-{
-	return 0;
-}
-
-static int netdev_cleanup(void *data)
-{
-	struct dq_netdev *dq = data;
-
-	dev_put(dq->dev);
-
-	if (dq->ctx->errno) {
-		ckpt_debug("Unregistering netdev %s\n", dq->dev->name);
-		unregister_netdev(dq->dev);
-	}
-
-	return 0;
-}
-
 static struct net_device *restore_veth(struct ckpt_ctx *ctx,
 				       struct ckpt_hdr_netdev *h,
 				       struct net *net)
@@ -606,9 +582,6 @@ static struct net_device *restore_veth(struct ckpt_ctx *ctx,
 	struct net_device *dev;
 	struct net_device *peer;
 	struct ifreq req;
-	struct dq_netdev dq;
-
-	dq.ctx = ctx;
 
 	ret = _ckpt_read_buffer(ctx, this_name, IFNAMSIZ);
 	if (ret < 0)
@@ -630,37 +603,31 @@ static struct net_device *restore_veth(struct ckpt_ctx *ctx,
 		if (IS_ERR(dev))
 			return dev;
 
+		ret = ckpt_obj_insert(ctx, dev, h->veth.this_ref,
+				      CKPT_OBJ_NETDEV);
+		dev_put(dev);
+		if (ret < 0)
+			goto err;
+
 		peer = dev_get_by_name(current->nsproxy->net_ns, peer_name);
 		if (!peer) {
 			ret = -EINVAL;
-			goto err_dev;
+			goto err;
 		}
 
-		dq.dev = peer;
-		ret = deferqueue_add(ctx->deferqueue, &dq, sizeof(dq),
-				     netdev_noop, netdev_cleanup);
-		if (ret)
-			goto err_peer;
-
 		ret = ckpt_obj_insert(ctx, peer, h->veth.peer_ref,
 				      CKPT_OBJ_NETDEV);
-		if (ret < 0)
-			/* Can't recall peer dq, so let it cleanup peer */
-			goto err_dev;
 		dev_put(peer);
-
-		dq.dev = dev;
-		ret = deferqueue_add(ctx->deferqueue, &dq, sizeof(dq),
-				     netdev_noop, netdev_cleanup);
-		if (ret)
-			/* Can't recall peer dq, so let it cleanup peer */
-			goto err_dev;
+		if (ret < 0)
+			goto err;
 
 	} else {
 		/* We're second: get our dev from the hash */
 		dev = ckpt_obj_fetch(ctx, h->veth.this_ref, CKPT_OBJ_NETDEV);
-		if (IS_ERR(dev))
-			return dev;
+		if (IS_ERR(dev)) {
+			ret = PTR_ERR(dev);
+			goto err;
+		}
 	}
 
 	/* Move to our new netns */
@@ -668,25 +635,31 @@ static struct net_device *restore_veth(struct ckpt_ctx *ctx,
 	ret = dev_change_net_namespace(dev, net, dev->name);
 	rtnl_unlock();
 	if (ret < 0)
-		goto out;
+		goto err;
 
 	/* Restore MAC address */
 	memcpy(req.ifr_name, dev->name, IFNAMSIZ);
 	memcpy(req.ifr_hwaddr.sa_data, h->hwaddr, sizeof(h->hwaddr));
 	req.ifr_hwaddr.sa_family = ARPHRD_ETHER;
 	ret = __kern_dev_ioctl(net, SIOCSIFHWADDR, &req);
- out:
-	if (ret)
-		dev = ERR_PTR(ret);
+	if (ret < 0)
+		goto err;
 
 	return dev;
-
- err_peer:
-	dev_put(peer);
-	unregister_netdev(peer);
- err_dev:
-	dev_put(dev);
-	unregister_netdev(dev);
+ err:
+	/* Delete from hash to drop reference */
+	ckpt_obj_del(ctx, h->veth.this_ref, CKPT_OBJ_NETDEV);
+	ckpt_obj_del(ctx, h->veth.peer_ref, CKPT_OBJ_NETDEV);
+
+	/* This will fail to delete the interface if we get here
+	 * because of a failed attempt at setting the hardware
+	 * address, since the device has been moved to another netns.
+	 * This is not a problem, however, because the death of that
+	 * netns will take the device (and its peer) down with it
+	 * cleanly.
+	 */
+	if (rtnl_dellink(this_name) < 0)
+		ckpt_debug("failed to delete interfaces on error\n");
 
 	return ERR_PTR(ret);
 }
Signature · 1 line
1.6.2.5
#8 lore raw
In reply to a message not in the archive

Looks fine to me, and haven't seen any negative (or other) comments. Applied for ckpt-v21.

Quoted 12 lines · Dan Smith

These patches fix a couple of post-ack issues that Oren brought up, as well as perform some cleanups to some of the more sticky error paths.

It also fixes compiling without NETNS support, and adds a flag to make checkpoint ignore netns/netdev details.

_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers