Add _ckpt_read_hdr_type() helper
Subsystems (2)
PATCH 1/3 Add _ckpt_read_hdr_type() helper
This helper function gives us a way to read a header object and the subsequent payload from the checkpoint stream directly into our own buffer. This is used by the net/checkpoint.c code to read skb's without a memcpy().
--- checkpoint/restart.c | 36 ++++++++++++++++++++++++++++++++++-- include/linux/checkpoint.h | 4 ++++ 2 files changed, 38 insertions(+), 2 deletions(-)
checkpoint/restart.c +34 -2
@@ -177,6 +177,38 @@ int _ckpt_read_string(struct ckpt_ctx *ctx, void *ptr, int len) }/** +* _ckpt_read_hdr_type - read a header record and check the type +* @ctx: checkpoint context +* @h: provided header buffer (returned) +* @type: optional type, 0 to ignore +* +* Returns the size of the payload to follow or negative on error +*/ +int _ckpt_read_hdr_type (struct ckpt_ctx *ctx,struct ckpt_hdr *h,int type) +{ +int ret; + + ret =ckpt_kread (ctx, h,sizeof (*h)); +if (ret <0 ) +return ret; +else if (type && h->type != type) +return -EINVAL ; +else +return h->len -sizeof (*h); +} + +/** +* _ckpt_read_payload - read the payload associated with a recent header read +* @ctx: checkpoint_context +* @h: header returned from _ckpt_read_hdr_type() +* @buffer: pre-allocated buffer to store payload +*/ +int _ckpt_read_payload (struct ckpt_ctx *ctx,struct ckpt_hdr *h,void *buffer) +{ +return ckpt_kread (ctx, buffer, h->len -sizeof (*h)); +} + +/** * ckpt_read_obj - allocate and read an object (ckpt_hdr followed by payload) * @ctx: checkpoint context * @h: object descriptor
@@ -192,7 +224,7 @@ static void *ckpt_read_obj(struct ckpt_ctx *ctx, int len, int max)int ret; again: - ret =ckpt_kread (ctx, &hh,sizeof (hh)); + ret =_ckpt_read_hdr_type (ctx, &hh,0 );if (ret <0 )return ERR_PTR (ret); _ckpt_debug(CKPT_DRW, "type %d len %d(%d,%d)\n",
@@ -217,7 +249,7 @@ static void *ckpt_read_obj(struct ckpt_ctx *ctx, int len, int max) *h = hh;/* yay ! */ - ret =ckpt_kread (ctx, (h +1 ), hh.len -sizeof (struct ckpt_hdr )); + ret =_ckpt_read_payload (ctx, &hh, (h +1 ));if (ret <0 ) {ckpt_hdr_put (ctx, h); h =ERR_PTR (ret);
include/linux/checkpoint.h +4 -0
@@ -63,6 +63,10 @@ extern int ckpt_write_string(struct ckpt_ctx *ctx, char *str, int len);extern void __ckpt_write_err (struct ckpt_ctx *ctx,char *fmt, ...);extern int ckpt_write_err (struct ckpt_ctx *ctx,char *fmt, ...); +extern int _ckpt_read_payload (struct ckpt_ctx *ctx,struct ckpt_hdr *h, +void *buffer); +extern int _ckpt_read_hdr_type (struct ckpt_ctx *ctx,struct ckpt_hdr *h, +int type);extern int _ckpt_read_obj_type (struct ckpt_ctx *ctx,void *ptr,int len,int type);extern int _ckpt_read_nbuffer (struct ckpt_ctx *ctx,void *ptr,int len);
Signature · 1 line
1.6.2.2
A message that is not in the archive (sent off-list or not yet received): 1246472414-23105-1-git-send-email-danms-r/[email protected]
PATCH 2/3 c/r: Add AF_UNIX support (v4)
This patch adds basic checkpoint/restart support for AF_UNIX sockets. It has been tested with a single and multiple processes, and with data inflight at the time of checkpoint. It supports socketpair()s, path-based, and abstract sockets.
Changes in v4:
- Changed the signdness of rcvlowat, rcvtimeo, sndtimeo, and backlog to match their struct sock definitions. This should avoid issues with sign extension.
- Add a sock_cptrst_verify() function to be run at restore time to validate several of the values in the checkpoint image against limits, flag masks, etc.
- Write an error string with ctk_write_err() in the obscure cases
- Don't write socket buffers for listen sockets
- Sanity check address lengths before we agree to allocate memory
- Check the result of inserting the peer object in the objhash on restart
- Check return value of sock_cptrst() on restart
- Change logic in remote getname() phase of checkpoint to not fail for closed (et al) sockets
- Eliminate the memory copy while reading socket buffers on restart
Changes in v3:
- Move sock_file_checkpoint() above sock_file_restore()
- Change __sock_file_*() functions to do_sock_file_*()
- Adjust some of the struct cr_hdr_socket alignment
- Improve the sock_copy_buffers() algorithm to avoid locking the source queue for the entire operation
- Fix alignment in the socket header struct(s)
- Move the per-protocol structure (ckpt_hdr_socket_un) out of the common socket header and read/write it separately
- Fix missing call to sock_cptrst() in restore path
- Break out the socket joining into another function
- Fix failure to restore the socket address thus fixing getname()
- Check the state values on restart
- Fix case of state being TCP_CLOSE, which allows dgram sockets to be properly connected (if appropriate) to their peer and maintain the sockaddr for getname() operation
- Fix restoring a listening socket that has been unlink()'d
- Fix checkpointing sockets with an in-flight FD-passing SKB. Fail with EBUSY.
- Fix checkpointing listening sockets with an unaccepted connection. Fail with EBUSY.
- Changed 'un' to 'unix' in function and structure names
Changes in v2:
- Change GFP_KERNEL to GFP_ATOMIC in sock_copy_buffers() (this seems to be rather common in other uses of skb_copy())
- Move the ckpt_hdr_socket structure definition to linux/socket.h
- Fix whitespace issue
- Move sock_file_checkpoint() to net/socket.c for symmetry
--- checkpoint/files.c | 7 + checkpoint/objhash.c | 27 ++ include/linux/checkpoint_hdr.h | 13 + include/linux/socket.h | 59 +++++ include/net/sock.h | 9 + net/Makefile | 2 + net/checkpoint.c | 545 ++++++++++++++++++++++++++++++++++++++++ net/socket.c | 84 ++++++ 8 files changed, 746 insertions(+), 0 deletions(-) create mode 100644 net/checkpoint.c
checkpoint/files.c +7 -0
@@ -21,6 +21,7 @@#include <linux/syscalls.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h> +#include <net/sock.h> /**************************************************************************
@@ -519,6 +520,12 @@ static struct restore_file_ops restore_file_ops[] = { .file_type = CKPT_FILE_PIPE, .restore = pipe_file_restore, }, +/* socket */ + { + .file_name = "SOCKET", + .file_type = CKPT_FILE_SOCKET, + .restore = sock_file_restore, + }, };static struct file *do_restore_file (struct ckpt_ctx *ctx)
checkpoint/objhash.c +27 -0
@@ -20,6 +20,7 @@#include <linux/user_namespace.h> #include <linux/checkpoint.h> #include <linux/checkpoint_hdr.h> +#include <net/sock.h> struct ckpt_obj ;struct ckpt_obj_ops ;
@@ -264,6 +265,22 @@ static int obj_groupinfo_users(void *ptr)return atomic_read (&((struct group_info *) ptr)->usage); } +static int obj_sock_grab (void *ptr) +{ +sock_hold ((struct sock *) ptr); +return 0 ; +} + +static void obj_sock_drop (void *ptr) +{ +sock_put ((struct sock *) ptr); +} + +static int obj_sock_users (void *ptr) +{ +return atomic_read (&((struct sock *) ptr)->sk_refcnt); +} +static struct ckpt_obj_ops ckpt_obj_ops[] = {/* ignored object */ {
@@ -391,6 +408,16 @@ static struct ckpt_obj_ops ckpt_obj_ops[] = { .checkpoint = checkpoint_groupinfo, .restore = restore_groupinfo, }, +/* sock object */ + { + .obj_name = "SOCKET", + .obj_type = CKPT_OBJ_SOCK, + .ref_drop = obj_sock_drop, + .ref_grab = obj_sock_grab, + .ref_users = obj_sock_users, + .checkpoint = sock_file_checkpoint, + .restore = sock_file_restore, + }, };
include/linux/checkpoint_hdr.h +13 -0
@@ -88,6 +88,12 @@ enum {CKPT_HDR_SIGHAND =601 , +CKPT_HDR_FD_SOCKET =601 , +CKPT_HDR_SOCKET , +CKPT_HDR_SOCKET_BUFFERS , +CKPT_HDR_SOCKET_BUFFER , +CKPT_HDR_SOCKET_UNIX , +CKPT_HDR_TAIL =9001 , CKPT_HDR_ERROR = 9999,
@@ -121,6 +127,7 @@ enum obj_type {CKPT_OBJ_CRED ,CKPT_OBJ_USER ,CKPT_OBJ_GROUPINFO , +CKPT_OBJ_SOCK , CKPT_OBJ_MAX };
@@ -316,6 +323,7 @@ enum file_type {CKPT_FILE_IGNORE =0 ,CKPT_FILE_GENERIC ,CKPT_FILE_PIPE , +CKPT_FILE_SOCKET , CKPT_FILE_MAX };
@@ -339,6 +347,11 @@ struct ckpt_hdr_file_pipe {__s32 pipe_objref; } __attribute__((aligned(8))); +struct ckpt_hdr_file_socket { +struct ckpt_hdr_file common; +__u16 family; +} __attribute__((aligned (8 ))); +struct ckpt_hdr_file_pipe_state {struct ckpt_hdr h;__s32 pipe_len;
include/linux/socket.h +59 -0
70 lines not on this page · raw message
include/net/sock.h +9 -0
@@ -1482,4 +1482,13 @@ extern int sysctl_optmem_max;extern __u32 sysctl_wmem_default;extern __u32 sysctl_rmem_default; +/* Checkpoint/Restart Functions */ +struct ckpt_ctx ; +struct ckpt_hdr_socket ; +extern int sock_file_checkpoint (struct ckpt_ctx *,void *); +extern void *sock_file_restore (struct ckpt_ctx *); +extern struct socket *do_sock_file_restore (struct ckpt_ctx *, +struct ckpt_hdr_socket *); +extern int do_sock_file_checkpoint (struct ckpt_ctx *ctx,struct file *file); +#endif /* _SOCK_H */
net/Makefile +2 -0
@@ -65,3 +65,5 @@ ifeq ($(CONFIG_NET),y) obj-$(CONFIG_SYSCTL) += sysctl_net.o endif obj-$(CONFIG_WIMAX) += wimax/ + +obj-$(CONFIG_CHECKPOINT) += checkpoint.o
net/checkpoint.c new file +545 -0
545 lines not on this page · raw message
net/socket.c +84 -0
102 lines not on this page · raw message
Signature · 1 line
1.6.2.2
A message that is not in the archive (sent off-list or not yet received): 1246472414-23105-2-git-send-email-danms-r/[email protected]
PATCH 3/3 Add AF_INET c/r support (v2)
This patch adds AF_INET c/r support based on the framework established in my AF_UNIX patch. I've tested it by checkpointing a single app with a pair of sockets connected over loopback.
A couple points about the operation:
1. In order to properly hook up the established sockets with the matching listening parent socket, I added a new list to the ckpt_ctx and run the parent attachment in the deferqueue at the end of the restart process.
2. I don't do anything to redirect or freeze traffic flowing to or from the remote system (to prevent a RST from breaking things). I expect that userspace will bring down a veth device or freeze traffic to the remote system to handle this case.
Changes in v2:
- Check for data in the TCP out-of-order queue and fail if present
- Fix a logic issue in sock_add_parent()
- Add comment about holding a reference to sock for parent list
- Write error messages to checkpoint stream where appropriate
- Fix up checking of some return values in restart phase
- Fix up restart logic to restore socket info for all states
- Avoid running sk_proto->hash() for non-TCP sockets
- Fix calling bind() for unconnected (i.e. DGRAM) sockets
- Change 'in' to 'inet' in structure and function names
--- checkpoint/sys.c | 2 + include/linux/checkpoint_hdr.h | 1 + include/linux/checkpoint_types.h | 2 + include/linux/socket.h | 95 +++++++++++ net/checkpoint.c | 319 +++++++++++++++++++++++++++++++++++++- 5 files changed, 414 insertions(+), 5 deletions(-)
checkpoint/sys.c +2 -0
@@ -242,6 +242,8 @@ static struct ckpt_ctx *ckpt_ctx_alloc(int fd, unsigned long uflags,INIT_LIST_HEAD (&ctx->pgarr_pool);init_waitqueue_head (&ctx->waitq); +INIT_LIST_HEAD (&ctx->listen_sockets); + err = -EBADF ; ctx->file =fget (fd);if (!ctx->file)
include/linux/checkpoint_hdr.h +1 -0
@@ -93,6 +93,7 @@ enum {CKPT_HDR_SOCKET_BUFFERS ,CKPT_HDR_SOCKET_BUFFER ,CKPT_HDR_SOCKET_UNIX , +CKPT_HDR_SOCKET_INET , CKPT_HDR_TAIL = 9001,
include/linux/checkpoint_types.h +2 -0
@@ -60,6 +60,8 @@ struct ckpt_ctx {struct list_head pgarr_list;/* page array to dump VMA contents */ struct list_head pgarr_pool;/* pool of empty page arrays chain */ +struct list_head listen_sockets;/* listening parent sockets */ +/* [multi-process checkpoint] */ struct task_struct **tasks_arr;/* array of all tasks [checkpoint] */ int nr_tasks;/* size of tasks array */
include/linux/socket.h +95 -0
101 lines not on this page · raw message
net/checkpoint.c +314 -5
391 lines not on this page · raw message
Signature · 1 line
1.6.2.2
A message that is not in the archive (sent off-list or not yet received): 1246472414-23105-3-git-send-email-danms-r/[email protected]
Re: [PATCH 3/3] Add AF_INET c/r support (v2)
Quoted 3 lines · Dan Smith
This patch adds
AF_INETc/r support based on the framework established in myAF_UNIXpatch. I've tested it by checkpointing a single app with a pair of sockets connected over loopback.
You've probably already mentioned it elsewhere, but having IPv6 support before sending to netdev would probably be a good thing.
-Brian
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3] Add AF_INET c/r support (v2)
BH> You've probably already mentioned it elsewhere, but having IPv6 BH> support before sending to netdev would probably be a good thing.
Bummer :)
I'll see what I can cook up... Thanks :)
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
Re: [PATCH 2/3] c/r: Add AF_UNIX support (v4)
In reply to a message not in the archiveHi Dan,
Quoted 4 lines
include/net/sock.h +0
-0@@ -1482,4 +1482,13 @@ extern int sysctl_optmem_max;extern __u32 sysctl_wmem_default;
include/net/sock.h extern int sysctl_optmem_max; · line 1492
Quoted 10 lines
include/net/sock.h +8
-0extern __u32 sysctl_rmem_default; +/* Checkpoint/Restart Functions */ +struct ckpt_ctx ; +struct ckpt_hdr_socket ; +extern int sock_file_checkpoint (struct ckpt_ctx *,void *); +extern void *sock_file_restore (struct ckpt_ctx *); +extern struct socket *do_sock_file_restore (struct ckpt_ctx *, +struct ckpt_hdr_socket *); +extern int do_sock_file_checkpoint (struct ckpt_ctx *ctx,struct file *file);
Should this all be under #ifdef CONFIG_CHECKPOINT?
Quoted 23 lines
net/socket.c +6
-0@@ -96,6 +96,9 @@#include <net/sock.h> #include <linux/netfilter.h> +#include <linux/checkpoint.h> +#include <linux/checkpoint_hdr.h> +static int sock_no_open (struct inode *irrelevant,struct file *dontcare);static ssize_t sock_aio_read (struct kiocb *iocb,const struct iovec *iov,unsigned long nr_segs,loff_t pos);@@ -140,6 +143,9 @@ static const struct file_operations socket_file_ops = { .sendpage = sock_sendpage, .splice_write = generic_splice_sendpage, .splice_read = sock_splice_read, +#ifdef CONFIG_CHECKPOINT + .checkpoint = sock_file_checkpoint, +#endif };/*
net/socket.c int sock_map_fd(struct socket *sock, int flags) · line 428
Quoted 8 lines
net/socket.c +5
-0@@ -415,6 +421,84 @@ int sock_map_fd(struct socket *sock, int flags)return fd; } +int sock_file_checkpoint (struct ckpt_ctx *ctx,void *ptr) +{ +struct ckpt_hdr_file_socket *h; +int ret; +struct file *file = ptr;
<snip>
And the corresponding code in socket.c too, since you're only assigning .checkpoint above in that case.
-Brian
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/3] c/r: Add AF_UNIX support (v4)
BH> Should this all be under #ifdef CONFIG_CHECKPOINT?
Yeah, probably so :)
BH> And the corresponding code in socket.c too, since you're only BH> assigning .checkpoint above in that case.
Yep, okay, thanks!
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
Ack, I meant to patchbomb these with some intro text.
This set of patches includes the helper that Oren suggested to make reading in the socket buffers more efficient as well as updates to the UNIX and INET patches as suggested by Oren and Matt. There are a few things not addressed which I asked for clarification on earlier.
I think these are getting close to the point where we can solicit some "comments" from the netdev folks. I'll let these fester here for the rest of the week and then plan to post them to netdev for comments on Monday. I will plan to procure some flame-retardant clothing over the weekend.
Thanks!
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]