C/R: Network namespace and device support (v2)
Subsystems (2)
This set adds support for checkpointing network namespaces and devices, with in-kernel restart.
Basic support includes veth pair and loopback adapters and allows me to checkpoint and restart a containerized copy of sendmail with a veth bridged to a physical network. Follow-on work is detailed in the header of the last patch.
Changes in v2 only to the final patch, detailed there.
PATCH 1/3 Expose rtnl_link_ops_get()
--- include/net/rtnetlink.h | 1 + net/core/rtnetlink.c | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)
include/net/rtnetlink.h +1 -0
@@ -82,6 +82,7 @@ extern void rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops);extern int rtnl_link_register (struct rtnl_link_ops *ops);extern void rtnl_link_unregister (struct rtnl_link_ops *ops); +extern const struct rtnl_link_ops *rtnl_link_ops_get (const char *kind);extern struct net_device *rtnl_create_link (struct net *net,char *ifname,const struct rtnl_link_ops *ops,struct nlattr *tb[]);extern const struct nla_policy ifla_policy[IFLA_MAX +1 ];
net/core/rtnetlink.c +1 -1
@@ -325,7 +325,7 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops)EXPORT_SYMBOL_GPL (rtnl_link_unregister); -static const struct rtnl_link_ops *rtnl_link_ops_get (const char *kind) +const struct rtnl_link_ops *rtnl_link_ops_get (const char *kind) {const struct rtnl_link_ops *ops;
Signature · 1 line
1.6.2.5
PATCH 2/3 Add a veth_get_peer() and veth_set_peer() functions
In reply to Dan SmithThis is needed for C/R. For checkpoint, we need to be able to follow the link from one veth device to its peer. For restart, we need to be able to link two veth devices we've restored to re-establish their relationship.
--- drivers/net/veth.c | 14 ++++++++++++++ include/linux/veth.h | 5 +++++ 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/net/veth.c +14 -0
@@ -454,6 +454,20 @@ static void veth_dellink(struct net_device *dev)unregister_netdevice (peer); } +struct net_device *veth_get_peer (struct net_device *veth) +{ +struct veth_priv *priv =netdev_priv (veth); + +return priv->peer; +} + +void veth_set_peer (struct net_device *veth,struct net_device *peer) +{ +struct veth_priv *priv =netdev_priv (veth); + + priv->peer = peer; +} +static const struct nla_policy veth_policy[VETH_INFO_MAX +1 ];static struct rtnl_link_ops veth_link_ops = {
include/linux/veth.h +5 -0
@@ -9,4 +9,9 @@ enum {#define VETH_INFO_MAX (__VETH_INFO_MAX - 1) }; +#ifdef __KERNEL__ +struct net_device *veth_get_peer (struct net_device *veth); +void veth_set_peer (struct net_device *veth,struct net_device *peer); +#endif +#endif
Signature · 1 line
1.6.2.5
PATCH 3/3 C/R: Basic support for network namespaces and devices (v2)
In reply to Dan SmithWhen checkpointing a task tree with network namespaces, we hook into do_checkpoint_ns() along with the others. Any devices in a given namespace are checkpointed (including their peer, in the case of veth) sequentially. Each network device stores a list of protocol addresses, as well as other information, such as hardware address.
This patch supports veth pairs, as well as the loopback adapter. The loopback support is there to make sure that any additional addresses and state (such as up/down) is copied to the loopback adapter that we are given in the new network namespace.
On restart, we instantiate new network namespaces and veth pairs as necessary. Any device we encounter that isn't in a network namespace that was checkpointed as part of a task is left in the namespace of the restarting process. This will be the case for a veth half that exists in the init netns to provide network access to a container.
Still to do are:
1. Routes
2. Netfilter rules
3. IPv6 addresses
4. Other virtual device types (e.g. bridges)
5. Multicast
6. Device config info (ipv4_devconf)
7. Additional ipv4 address attributes
Changes in v2:
- Add CONFIG_CHECKPOINT_NETNS that is dependent on NET, NET_NS, and CHECKPOINT. Conditionally compile the checkpoint_dev code based on it.
- Updated comment on should_checkpoint_netdev()
- Updated checkpoint_netdev() to explicitly check for "veth" in name
- Changed checkpoint_netns() to use BUG() for impossible condition
- Fixed a bug on restart with all devices in the init netns
- Lock the dev_base_lock while traversing interface addresses
- Collect all addresses for an interface before writing out in one single pass
--- checkpoint/checkpoint.c | 21 ++- checkpoint/objhash.c | 48 ++++ checkpoint/restart.c | 4 + include/linux/checkpoint.h | 12 + include/linux/checkpoint_hdr.h | 49 ++++ include/linux/checkpoint_types.h | 1 + kernel/nsproxy.c | 45 +++- net/Kconfig | 4 + net/Makefile | 1 + net/checkpoint_dev.c | 533 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 711 insertions(+), 7 deletions(-) create mode 100644 net/checkpoint_dev.c
checkpoint/checkpoint.c +16 -5
@@ -180,16 +180,23 @@ static int checkpoint_write_header(struct ckpt_ctx *ctx)static int checkpoint_container (struct ckpt_ctx *ctx) {struct ckpt_hdr_container *h; +int new;int ret; h =ckpt_hdr_get_type (ctx,sizeof (*h),CKPT_HDR_CONTAINER );if (!h)return -ENOMEM ; - ret =ckpt_write_obj (ctx, &h->h); -ckpt_hdr_put (ctx, h); + ret =ckpt_obj_lookup_add (ctx, current->nsproxy->net_ns, +CKPT_OBJ_NET_NS , &new);if (ret <0 ) -return ret; + goto out; + + ctx->init_netns_ref = h->init_netns_ref = ret; + + ret =ckpt_write_obj (ctx, &h->h); +if (ret <0 ) + goto out;memset (ctx->lsm_name,0 ,CHECKPOINT_LSM_NAME_MAX +1 ); strlcpy(ctx->lsm_name, security_get_lsm_name(),
@@ -197,9 +204,13 @@ static int checkpoint_container(struct ckpt_ctx *ctx) ret =ckpt_write_buffer (ctx, ctx->lsm_name,CHECKPOINT_LSM_NAME_MAX +1 );if (ret <0 ) -return ret; + goto out; -return security_checkpoint_header (ctx); + ret =security_checkpoint_header (ctx); + out: +ckpt_hdr_put (ctx, h); + +return ret; }/* write the checkpoint trailer */
checkpoint/objhash.c +48 -0
60 lines not on this page · raw message
checkpoint/restart.c +4 -0
@@ -689,6 +689,10 @@ static int restore_container(struct ckpt_ctx *ctx)return PTR_ERR (h);ckpt_hdr_put (ctx, h); +/* Store the ref of the init netns so we know to leave its +* devices where they fall */ + ctx->init_netns_ref = h->init_netns_ref; +/* read the LSM name and info which follow ("are a part of") * the ckpt_hdr_container */ ret =restore_lsm (ctx);
include/linux/checkpoint.h +12 -0
@@ -113,6 +113,18 @@ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx,extern struct sk_buff *sock_restore_skb (struct ckpt_ctx *ctx,struct sock *sk);extern void sock_listening_list_free (struct list_head *head); +#ifdef CONFIG_CHECKPOINT_NETNS +int checkpoint_netns (struct ckpt_ctx *ctx,void *ptr); +void *restore_netns (struct ckpt_ctx *ctx); +int checkpoint_netdev (struct ckpt_ctx *ctx,void *ptr); +void *restore_netdev (struct ckpt_ctx *ctx); +#else +# define checkpoint_netns NULL +# define restore_netns NULL +# define checkpoint_netdev NULL +# define restore_netdev NULL +#endif +/* ckpt kflags */ #define ckpt_set_ctx_kflag (__ctx, __kflag) \ set_bit(__kflag##_BIT, &(__ctx)->kflags)
include/linux/checkpoint_hdr.h +49 -0
79 lines not on this page · raw message
include/linux/checkpoint_types.h +1 -0
@@ -85,6 +85,7 @@ struct ckpt_ctx {wait_queue_head_t ghostq;/* waitqueue for ghost tasks */ struct cred *realcred, *ecred;/* tmp storage for cred at restart */ struct list_head listen_sockets;/* listening parent sockets */ +int init_netns_ref;/* Objref of root net namespace */ struct ckpt_stats stats;/* statistics */
kernel/nsproxy.c +43 -2
75 lines not on this page · raw message
net/Kconfig +4 -0
@@ -276,4 +276,8 @@ source "net/wimax/Kconfig" source "net/rfkill/Kconfig" source "net/9p/Kconfig" +config CHECKPOINT_NETNS + bool + default y if NET && NET_NS && CHECKPOINT + endif # if NET
net/Makefile +1 -0
@@ -67,3 +67,4 @@ endif obj-$(CONFIG_WIMAX) += wimax/ obj-$(CONFIG_CHECKPOINT) += checkpoint.o +obj-$(CONFIG_CHECKPOINT_NETNS) += checkpoint_dev.o
net/checkpoint_dev.c new file +533 -0
533 lines not on this page · raw message
Signature · 1 line
1.6.2.5
David Miller
maintainerRe: [PATCH 3/3] C/R: Basic support for network namespaces and devices (v2)
From: Dan Smith <[email protected]>
Date: Fri, 22 Jan 2010 13:09:52 -0800
Quoted 8 lines
net/checkpoint_dev.c new file +8
-0+if (strcmp (dev->name,"sit0" ) ==0 ) { +return 0 ;/* Skip sit0 */ + }else if (dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) { + dev->ethtool_ops->get_drvinfo (dev, &drvinfo); +if (strcmp (drvinfo.driver,"veth" ) ==0 ) +return 1 ;/* vethX is okay */ + }else if (strcmp (dev->name,"lo" ) ==0 ) +return 1 ;/* lo is okay */
...
net/checkpoint_dev.c line 168
Quoted 6 lines
net/checkpoint_dev.c new file +6
-0+if (strcmp (dev->name,"lo" ) ==0 ) + h->type =CKPT_NETDEV_LO ; +else if (strncmp (dev->name,"veth" ,4 ) ==0 ) { + h->type =CKPT_NETDEV_VETH ; + peer =veth_get_peer (dev); + }else {
This is gross. You can't do things this way.
First of all, devices can get whatever name the user wants to assign to them. If they want to rename the loopback device to something other than "lo" they can.
You need another way. Is it such a stretch of ingenuity to simply add an attribute flag to struct netdev that you can test here and perhaps a callback for what you need?
Your direct calls into these drivers, like the veth bits, will not work if the driver is built modular. It's one of several reasons why doing things this way isn't going to work.
This misdesign is also why you find a need to get at the RTNL link ops too. You have no infrastructure for doing what you need to do generically, so instead you are forced to directly call into drivers and export RTNL internals needlessly.
This needs a lot of work, sorry.
A message that is not in the archive (sent off-list or not yet received): 20100123.012537.99190542.davem-fT/PcQaiUtIeIZ0/[email protected]
Re: [PATCH 3/3] C/R: Basic support for network namespaces and devices (v2)
DM> This is gross. You can't do things this way.
Okay, fair enough.
DM> This misdesign is also why you find a need to get at the RTNL link DM> ops too. You have no infrastructure for doing what you need to do DM> generically, so instead you are forced to directly call into DM> drivers and export RTNL internals needlessly.
Stepping back, RTNL itself seems like the proper generic interface. Would you agree? At first, it seemed overkill to pack the information into message buffers just to have the rest of RTNL unpack them, which is why I mis-did what I did. I think you've make it clear that that overhead is worth the reuse. Would that be more palatable?
Thanks!
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]