c/r: some cleanup for sockets
Subsystems (3)
Dan,
While trying to fix a compilation warning from the socket c/r code, I ended up doing some cleanup, that isn't particuarly structured.
It compiles flawlessly for me, but I didn't give it much testing. Let me know what you think.
Thanks,
Oren.
A message that is not in the archive (sent off-list or not yet received): 1250539931-12951-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org
PATCH 1/3 c/r: cleanup sock_file_restore()/sock_file_checkpoint()
This patch was intended to fix a compilation warning regarding the sock_file_restore():
checkpoint/files.c: At top level:checkpoint/files.c:573: warning: initialization from incompatible pointer type
and evolved to some cleanup of that code, making the following changes:
* Make ckpt_hdr_socket be part of ckpt_hdr_file_socket; There is no good reason to use a separate header for it. This saves write/read of an extra structure.
* Fold do_sock_file_checkpoint() into sock_file_checkpoint(), and also do_sock_file_restore() into sock_file_restore(). This makes the code a bit simpler and more streamlined.
* Move sock_file_{checkpoint,restore} to net/checkpoint.c, which is a more proper place than net/socket.c.
* Properly define sock_file_{checkpoint,restore} in header file
* Have sock_file_restore() call restore_file_common(), which was omitted previously.
--- include/linux/checkpoint_hdr.h | 116 +++++++++++++++++++-------------------- include/linux/net.h | 2 + include/net/af_unix.h | 6 +- include/net/sock.h | 10 ++-- net/checkpoint.c | 94 ++++++++++++++++++++++++-------- net/socket.c | 84 +---------------------------- net/unix/checkpoint.c | 8 +--- 7 files changed, 138 insertions(+), 182 deletions(-)
include/linux/checkpoint_hdr.h +57 -59
@@ -94,7 +94,6 @@ enum {CKPT_HDR_SIGPENDING ,CKPT_HDR_FD_SOCKET =701 , -CKPT_HDR_SOCKET ,CKPT_HDR_SOCKET_QUEUE ,CKPT_HDR_SOCKET_BUFFER , CKPT_HDR_SOCKET_UNIX,
@@ -366,8 +365,65 @@ struct ckpt_hdr_file_pipe {__s32 pipe_objref; } __attribute__((aligned(8))); +/* socket */ +struct ckpt_hdr_socket { +struct {/* struct socket */ +__u64 flags; +__u8 state; + } socket __attribute__ ((aligned (8 ))); + +struct {/* struct sock_common */ +__u32 bound_dev_if; +__u32 reuse; +__u16 family; +__u8 state; + } sock_common __attribute__ ((aligned (8 ))); + +struct {/* struct sock */ +__s64 rcvlowat; +__u64 flags; + +__u32 err; +__u32 err_soft; +__u32 priority; +__s32 rcvbuf; +__s32 sndbuf; +__u16 type; +__s16 backlog; + +__u8 protocol; +__u8 state; +__u8 shutdown; +__u8 userlocks; +__u8 no_check; + +struct linger linger; +struct timeval rcvtimeo; +struct timeval sndtimeo; + } sock __attribute__ ((aligned (8 ))); +} __attribute__ ((aligned (8 ))); + +struct ckpt_hdr_socket_queue { +struct ckpt_hdr h; +__u32 skb_count; +__u32 total_bytes; +} __attribute__ ((aligned (8 ))); + +#define CKPT_UNIX_LINKED 1 +struct ckpt_hdr_socket_unix { +struct ckpt_hdr h; +__s32 this; +__s32 peer; +__u32 flags; +__u32 laddr_len; +__u32 raddr_len; +struct sockaddr_un laddr; +struct sockaddr_un raddr; +} __attribute__ ((aligned (8 ))); +struct ckpt_hdr_file_socket {struct ckpt_hdr_file common; +struct ckpt_hdr_socket socket; } __attribute__((aligned (8 )));struct ckpt_hdr_utsns {
@@ -576,64 +632,6 @@ struct ckpt_hdr_ipc_sem {__u32 sem_nsems; } __attribute__((aligned(8))); -#define CKPT_UNIX_LINKED 1 -struct ckpt_hdr_socket_unix { -struct ckpt_hdr h; -__s32 this; -__s32 peer; -__u32 flags; -__u32 laddr_len; -__u32 raddr_len; -struct sockaddr_un laddr; -struct sockaddr_un raddr; -} __attribute__ ((aligned (8 ))); - -struct ckpt_hdr_socket { -struct ckpt_hdr h; - -struct {/* struct socket */ -__u64 flags; -__u8 state; - } socket __attribute__ ((aligned (8 ))); - -struct {/* struct sock_common */ -__u32 bound_dev_if; -__u32 reuse; -__u16 family; -__u8 state; - } sock_common __attribute__ ((aligned (8 ))); - -struct {/* struct sock */ -__s64 rcvlowat; -__u64 flags; - -__u32 err; -__u32 err_soft; -__u32 priority; -__s32 rcvbuf; -__s32 sndbuf; -__u16 type; -__s16 backlog; - -__u8 protocol; -__u8 state; -__u8 shutdown; -__u8 userlocks; -__u8 no_check; - -struct linger linger; -struct timeval rcvtimeo; -struct timeval sndtimeo; - - } sock __attribute__ ((aligned (8 ))); - -} __attribute__ ((aligned (8 ))); - -struct ckpt_hdr_socket_queue { -struct ckpt_hdr h; -__u32 skb_count; -__u32 total_bytes; -} __attribute__ ((aligned (8 )));#define CKPT_TST_OVERFLOW_16 (a, b) \ ((sizeof(a) > sizeof(b)) && ((a) > SHORT_MAX))
include/linux/net.h +2 -0
@@ -223,6 +223,8 @@ extern int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t len);extern int sock_recvmsg (struct socket *sock,struct msghdr *msg,size_t size,int flags); +extern int sock_attach_fd (struct socket *sock,struct file *file, +int flags);extern int sock_map_fd (struct socket *sock,int flags);extern struct socket *sockfd_lookup (int fd,int *err);#define sockfd_put (sock) fput(sock->file)
include/net/af_unix.h +3 -3
@@ -70,6 +70,8 @@ static inline void unix_sysctl_unregister(struct net *net) {}#endif #ifdef CONFIG_CHECKPOINT +struct ckpt_ctx ; +struct ckpt_hdr_socket ;#ifdef CONFIG_UNIX_MODULE /* FIXME: Our current scheme won't work with CONFIG_UNIX=m */
@@ -77,9 +79,7 @@ static inline void unix_sysctl_unregister(struct net *net) {}#endif #ifdef CONFIG_UNIX -extern int sock_unix_checkpoint (struct ckpt_ctx *ctx, -struct socket *socket, -struct ckpt_hdr_socket *h); +extern int sock_unix_checkpoint (struct ckpt_ctx *ctx,struct socket *socket);extern int sock_unix_restore (struct ckpt_ctx *ctx,struct ckpt_hdr_socket *h,struct socket *socket);
include/net/sock.h +4 -6
@@ -1643,12 +1643,10 @@ extern __u32 sysctl_rmem_default;#ifdef CONFIG_CHECKPOINT /* 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); +struct ckpt_hdr_file ; +extern int sock_file_checkpoint (struct ckpt_ctx *ctx,struct file *file); +extern struct file *sock_file_restore (struct ckpt_ctx *ctx, +struct ckpt_hdr_file *h);#endif #endif /* _SOCK_H */
net/checkpoint.c +70 -24
149 lines not on this page · raw message
net/socket.c +1 -83
102 lines not on this page · raw message
net/unix/checkpoint.c +1 -7
@@ -55,9 +55,7 @@ static int sock_unix_write_cwd(struct ckpt_ctx *ctx,return ret; } -int sock_unix_checkpoint (struct ckpt_ctx *ctx, -struct socket *socket, -struct ckpt_hdr_socket *h) +int sock_unix_checkpoint (struct ckpt_ctx *ctx,struct socket *socket) {struct unix_sock *sk =unix_sk (socket->sk);struct unix_sock *pr =unix_sk (sk->peer);
@@ -98,10 +96,6 @@ int sock_unix_checkpoint(struct ckpt_ctx *ctx, goto out; } - ret =ckpt_write_obj (ctx, (struct ckpt_hdr *) h); -if (ret <0 ) - goto out; - ret =ckpt_write_obj (ctx, (struct ckpt_hdr *) un);if (ret <0 ) goto out;
Signature · 1 line
1.6.0.4
A message that is not in the archive (sent off-list or not yet received): 1250539931-12951-2-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org
Dan Smith
Acked-byRe: [PATCH 1/3] c/r: cleanup sock_file_restore()/sock_file_checkpoint()
OL> checkpoint/files.c: At top level:
OL> checkpoint/files.c:573: warning: initialization from incompatible pointer type
Yeah, I must've missed that among all the other c/r-induced warnings... :)
OL> and evolved to some cleanup of that code, making the following OL> changes:
Seems (and tests) okay to me.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
PATCH 2/3 c/r: add checkpoint/restore methods to struct proto_ops
In reply to a message not in the archiveThis patch adds checkpoint and restore methods to struct proto_ops which should allow compilation of af-unix sockets as a module. It also simplifies the code.
--- include/linux/net.h | 7 ++++++ include/net/af_unix.h | 29 ++------------------------ net/checkpoint.c | 53 +++++++++++++++++++++++------------------------- net/unix/af_unix.c | 6 +++++ net/unix/checkpoint.c | 6 ++-- 5 files changed, 44 insertions(+), 57 deletions(-)
include/linux/net.h +7 -0
@@ -147,6 +147,9 @@ struct sockaddr;struct msghdr ;struct module ; +struct ckpt_ctx ; +struct ckpt_hdr_socket ; +struct proto_ops {int family;struct module *owner;
@@ -191,6 +194,10 @@ struct proto_ops { int offset, size_t size, int flags);ssize_t (*splice_read)(struct socket *sock,loff_t *ppos,struct pipe_inode_info *pipe,size_t len,unsigned int flags); +int (*checkpoint)(struct ckpt_ctx *ctx, +struct socket *sock); +int (*restore)(struct ckpt_ctx *ctx,struct socket *sock, +struct ckpt_hdr_socket *h); };struct net_proto_family {
include/net/af_unix.h +3 -26
@@ -72,32 +72,9 @@ static inline void unix_sysctl_unregister(struct net *net) {}#ifdef CONFIG_CHECKPOINT struct ckpt_ctx ;struct ckpt_hdr_socket ; - -#ifdef CONFIG_UNIX_MODULE -/* FIXME: Our current scheme won't work with CONFIG_UNIX=m */ -#error "CONFIG_UNIX=m not currently supported by CONFIG_CHECKPOINT" -#endif - -#ifdef CONFIG_UNIX -extern int sock_unix_checkpoint (struct ckpt_ctx *ctx,struct socket *socket); -extern int sock_unix_restore (struct ckpt_ctx *ctx, -struct ckpt_hdr_socket *h, -struct socket *socket); -#else -static inline int sock_unix_checkpoint (struct ckpt_ctx *ctx, -struct socket *socket, -struct ckpt_hdr_socket *h) -{ -return -ENOSYS ; -} - -static inline int sock_unix_restore (struct ckpt_ctx *ctx, -struct ckpt_hdr_socket *h, -struct socket *socket) -{ -return -ENOSYS ; -} -#endif /* CONFIG_UNIX */ +extern int sock_unix_checkpoint (struct ckpt_ctx *ctx,struct socket *sock); +extern int sock_unix_restore (struct ckpt_ctx *ctx,struct socket *sock, +struct ckpt_hdr_socket *h);#endif /* CONFIG_CHECKPOINT */ #endif
net/checkpoint.c +25 -28
113 lines not on this page · raw message
net/unix/af_unix.c +6 -0
@@ -523,6 +523,8 @@ static const struct proto_ops unix_stream_ops = { .recvmsg = unix_stream_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, + .checkpoint = sock_unix_checkpoint, + .restore = sock_unix_restore, };static const struct proto_ops unix_dgram_ops = {
@@ -544,6 +546,8 @@ static const struct proto_ops unix_dgram_ops = { .recvmsg = unix_dgram_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, + .checkpoint = sock_unix_checkpoint, + .restore = sock_unix_restore, };static const struct proto_ops unix_seqpacket_ops = {
@@ -565,6 +569,8 @@ static const struct proto_ops unix_seqpacket_ops = { .recvmsg = unix_dgram_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, + .checkpoint = sock_unix_checkpoint, + .restore = sock_unix_restore, };static struct proto unix_proto = {
net/unix/checkpoint.c +3 -3
@@ -472,9 +472,9 @@ static int sock_unix_precheck(struct socket *socket,return 0 ; } -int sock_unix_restore (struct ckpt_ctx *ctx, -struct ckpt_hdr_socket *h, -struct socket *socket) +int sock_unix_restore (struct ckpt_ctx *ctx,struct socket *socket, +struct ckpt_hdr_socket *h) + {struct ckpt_hdr_socket_unix *un;int ret = -EINVAL ;
Signature · 1 line
1.6.0.4
A message that is not in the archive (sent off-list or not yet received): 1250539931-12951-3-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org
Re: [PATCH 2/3] c/r: add checkpoint/restore methods to struct proto_ops
OL> - if ((h->sock.type != SOCK_DGRAM) && (h->sock.type != SOCK_STREAM)) {
OL> - ckpt_debug("Socket type %i not supported", h->sock.type);
OL> + if (h->sock.type & ~SOCK_TYPE_MASK)
OL> return ERR_PTR(-EINVAL);
OL> - }
The idea here was to prevent a rewritten checkpoint stream from causing us to call sock_create() with a type that we don't support. Checking the mask may be functionally equivalent right now, but may open the door for an interesting failure later, no?
OL> static const struct proto_ops unix_seqpacket_ops = {
OL> @@ -565,6 +569,8 @@ static const struct proto_ops unix_seqpacket_ops = {
OL> .recvmsg = unix_dgram_recvmsg, OL> .mmap = sock_no_mmap, OL> .sendpage = sock_no_sendpage,
OL> + .checkpoint = sock_unix_checkpoint,
OL> + .restore = sock_unix_restore,
OL> };
Have you tested SEQPACKET? I haven't.
Other than that, it looks fine to me and fails the same set of tests that the current tree does.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
A message that is not in the archive (sent off-list or not yet received): 87r5va5g1g.fsf-FLMGYpZoEPULwtHQx/[email protected]
Re: [PATCH 2/3] c/r: add checkpoint/restore methods to struct proto_ops
Quoted 10 lines · Dan Smith
OL> - if ((
h->sock.type!=SOCK_DGRAM) && (h->sock.type!=SOCK_STREAM)) {
OL> -ckpt_debug("Socket type %i not supported", h->sock.type);
OL> + if (h->sock.type& ~SOCK_TYPE_MASK)
OL> returnERR_PTR(-EINVAL);
OL> - }The idea here was to prevent a rewritten checkpoint stream from causing us to call
sock_create()with a type that we don't support. Checking the mask may be functionally equivalent right now, but may open the door for an interesting failure later, no?
I figured that if we called a sock_create() for a type that isn't supported by checkpoint/restart, we will catch it down the code by testing sock->ops->restore. That way, I don't need to "teach" sock_file_restore() about socket types and protocols.
Quoted 11 lines
OL> static const struct
proto_opsunix_seqpacket_ops= {
OL> @@ -565,6 +569,8 @@ static const structproto_opsunix_seqpacket_ops= {OL> .recvmsg = unix_dgram_recvmsg, OL> .mmap = sock_no_mmap, OL> .sendpage = sock_no_sendpage,OL> + .checkpoint =
sock_unix_checkpoint,
OL> + .restore =sock_unix_restore,
OL> };Have you tested SEQPACKET? I haven't.
Hehe ... I guess I'm too eager :)
Do you see any reason why it should work ? The only difference (for afunix) between dgram and seqpacket is the requirement that the socket be connected - see unix_seqpacket_sendmsg().
Quoted 4 lines
Other than that, it looks fine to me and fails the same set of tests that the current tree does.
Thanks,
Oren.
Re: [PATCH 2/3] c/r: add checkpoint/restore methods to struct proto_ops
OL> I figured that if we called a sock_create() for a type that isn't OL> supported by checkpoint/restart, we will catch it down the code by OL> testing sock->ops->restore. That way, I don't need to "teach" OL> sock_file_restore() about socket types and protocols.
Okay, yeah I suppose so. In that case, why even have the check? certainly sock_create() checks that somewhere down the line, right?
OL> Do you see any reason why it should work ? The only difference OL> (for afunix) between dgram and seqpacket is the requirement that OL> the socket be connected - see unix_seqpacket_sendmsg().
Not for AF_UNIX, no. I just said I hadn't tested it :)
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]
A message that is not in the archive (sent off-list or not yet received): 874os65e6q.fsf-FLMGYpZoEPULwtHQx/[email protected]
Re: [PATCH 2/3] c/r: add checkpoint/restore methods to struct proto_ops
Quoted 7 lines · Dan Smith
OL> I figured that if we called a
sock_create()for a type that isn't OL> supported by checkpoint/restart, we will catch it down the code by OL> testingsock->ops->restore. That way, I don't need to "teach" OL>sock_file_restore()about socket types and protocols.Okay, yeah I suppose so. In that case, why even have the check? certainly
sock_create()checks that somewhere down the line, right?
Hmm... true. I was distracted by the test in socket() syscalls. Will remove the test.
Oren.
Quoted 7 lines
OL> Do you see any reason why it should work ? The only difference OL> (for afunix) between dgram and seqpacket is the requirement that OL> the socket be connected - see
unix_seqpacket_sendmsg().Not for
AF_UNIX, no. I just said I hadn't tested it :)
PATCH 3/3 c/r: cleanup - follow naming conventions
In reply to a message not in the archiveMore cleanup of the sockets c/r code. Now that we use the methods from struct proto_ops (checkpoint,restore), we no longer need the prefix "sock_unix_..." for function names in net/unix/checkpoint.c; Instead we follow the convention (e.g. in net/unix/afunix.c) "unix_...".
Speaking about code conventions, it is also customary to use 'sock' for a struct socket, and a 'sk' for struct sock. This patch also makes changes accordingly where necessary.
--- include/net/af_unix.h | 6 +- net/checkpoint.c | 91 +++++++++++++++----------------- net/unix/af_unix.c | 12 ++-- net/unix/checkpoint.c | 139 +++++++++++++++++++++++-------------------------- 4 files changed, 119 insertions(+), 129 deletions(-)
include/net/af_unix.h +3 -3
@@ -72,9 +72,9 @@ static inline void unix_sysctl_unregister(struct net *net) {}#ifdef CONFIG_CHECKPOINT struct ckpt_ctx ;struct ckpt_hdr_socket ; -extern int sock_unix_checkpoint (struct ckpt_ctx *ctx,struct socket *sock); -extern int sock_unix_restore (struct ckpt_ctx *ctx,struct socket *sock, -struct ckpt_hdr_socket *h); +extern int unix_checkpoint (struct ckpt_ctx *ctx,struct socket *sock); +extern int unix_restore (struct ckpt_ctx *ctx,struct socket *sock, +struct ckpt_hdr_socket *h);#endif /* CONFIG_CHECKPOINT */ #endif
net/checkpoint.c +44 -47
193 lines not on this page · raw message
net/unix/af_unix.c +6 -6
@@ -523,8 +523,8 @@ static const struct proto_ops unix_stream_ops = { .recvmsg = unix_stream_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, - .checkpoint = sock_unix_checkpoint, - .restore = sock_unix_restore, + .checkpoint = unix_checkpoint, + .restore = unix_restore, };static const struct proto_ops unix_dgram_ops = {
@@ -546,8 +546,8 @@ static const struct proto_ops unix_dgram_ops = { .recvmsg = unix_dgram_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, - .checkpoint = sock_unix_checkpoint, - .restore = sock_unix_restore, + .checkpoint = unix_checkpoint, + .restore = unix_restore, };static const struct proto_ops unix_seqpacket_ops = {
@@ -569,8 +569,8 @@ static const struct proto_ops unix_seqpacket_ops = { .recvmsg = unix_dgram_recvmsg, .mmap = sock_no_mmap, .sendpage = sock_no_sendpage, - .checkpoint = sock_unix_checkpoint, - .restore = sock_unix_restore, + .checkpoint = unix_checkpoint, + .restore = unix_restore, };static struct proto unix_proto = {
net/unix/checkpoint.c +66 -73
348 lines not on this page · raw message
Signature · 1 line
1.6.0.4
A message that is not in the archive (sent off-list or not yet received): 1250539931-12951-4-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org
Dan Smith
Acked-byRe: [PATCH 3/3] c/r: cleanup - follow naming conventions
OL> More cleanup of the sockets c/r code. Now that we use the methods OL> from struct proto_ops (checkpoint,restore), we no longer need the OL> prefix "sock_unix_..." for function names in
OL> net/unix/checkpoint.c; Instead we follow the convention (e.g. in OL> net/unix/afunix.c) "unix_...".
No complaints.
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: danms-r/[email protected]