Fix potential restart failure on uninitialized sockets
Subsystems (2)
PATCH 1/1 Fix potential restart failure on uninitialized sockets
The logic used to determine whether or not we should checkpoint or restore a socket's buffers was not unified and thus differed in a couple of places. This caused a restart failure in the ipv4 code when the checkpoint decided to write buffers of an unbound socket and ipv4 restart didn't read them.
This adds a should-we-do-it function to checkpoint.h and makes the unified checkpoint code use it, as well as unix and ipv4.
--- include/linux/checkpoint.h | 5 +++++ net/checkpoint.c | 2 +- net/ipv4/checkpoint.c | 6 +++--- net/unix/checkpoint.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-)
include/linux/checkpoint.h +5 -0
@@ -38,6 +38,7 @@#include <linux/err.h> #include <linux/inetdevice.h> #include <net/sock.h> +#include <net/tcp_states.h> /* sycall helpers */ extern long do_sys_checkpoint(pid_t pid, int fd,
@@ -125,6 +126,10 @@ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx, struct sockaddr *rem, unsigned *rem_len);extern struct sk_buff *sock_restore_skb (struct ckpt_ctx *ctx,struct sock *sk);extern void sock_listening_list_free (struct list_head *head); +static inline int sock_should_do_buffers (struct sock *sk) +{ +return (sk->sk_state !=TCP_LISTEN ) && !sock_flag (sk,SOCK_DEAD ); +}#ifdef CONFIG_NETNS_CHECKPOINT extern int checkpoint_netns (struct ckpt_ctx *ctx,void *ptr);
net/checkpoint.c +1 -1
@@ -776,7 +776,7 @@ static int __do_sock_checkpoint(struct ckpt_ctx *ctx, struct sock *sk) goto out;/* part III: socket buffers */ -if ((sk->sk_state !=TCP_LISTEN ) && (!sock_flag (sk,SOCK_DEAD ))) +if (sock_should_do_buffers (sk)) ret =sock_defer_write_buffers (ctx, sk); out:ckpt_hdr_put (ctx, h);
net/ipv4/checkpoint.c +3 -3
@@ -537,10 +537,10 @@ int inet_restore(struct ckpt_ctx *ctx,*/ ret =sock_defer_hash (ctx, sock->sk); } - -if (!sock_flag (sock->sk,SOCK_DEAD )) - ret =inet_defer_restore_buffers (ctx, sock->sk); } + +if (sock_should_do_buffers (sock->sk)) + ret =inet_defer_restore_buffers (ctx, sock->sk); out:ckpt_hdr_put (ctx, in);
net/unix/checkpoint.c +1 -1
@@ -443,7 +443,7 @@ static int unix_restore_connected(struct ckpt_ctx *ctx,ckpt_debug ("unix_defer_join: %i\n" , ret); } -if (!dead && !ret) +if (sock_should_do_buffers (sock->sk) && !ret) ret =unix_defer_restore_buffers (ctx, un->this);return ret;
Signature · 1 line
1.7.1.1
A message that is not in the archive (sent off-list or not yet received): 1279134384-3856-1-git-send-email-danms-r/[email protected]
Dan,
This looks fine.
Only one comment: please rename sock_should_do_buffers() since it's exclusive for c/r and exported in checkpoint.h, e.g. ckpt_sock_need_buffers(). No need to resend - I can do it while pulling.
Oren.
Quoted 84 lines · Dan Smith
The logic used to determine whether or not we should checkpoint or restore a socket's buffers was not unified and thus differed in a couple of places. This caused a restart failure in the ipv4 code when the checkpoint decided to write buffers of an unbound socket and ipv4 restart didn't read them.
This adds a should-we-do-it function to
checkpoint.hand makes the unified checkpoint code use it, as well as unix and ipv4.Signed-off-by Dan Smith <danms-r/[email protected]>--- include/linux/checkpoint.h | 5 +++++ net/checkpoint.c | 2 +- net/ipv4/checkpoint.c | 6 +++--- net/unix/checkpoint.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-)include/linux/checkpoint.h +5
-0@@ -38,6 +38,7 @@#include <linux/err.h> #include <linux/inetdevice.h> #include <net/sock.h> +#include <net/tcp_states.h> /* sycall helpers */ extern long do_sys_checkpoint(pid_t pid, int fd,@@ -125,6 +126,10 @@ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx, struct sockaddr *rem, unsigned *rem_len);extern struct sk_buff *sock_restore_skb (struct ckpt_ctx *ctx,struct sock *sk);extern void sock_listening_list_free (struct list_head *head); +static inline int sock_should_do_buffers (struct sock *sk) +{ +return (sk->sk_state !=TCP_LISTEN ) && !sock_flag (sk,SOCK_DEAD ); +}#ifdef CONFIG_NETNS_CHECKPOINT extern int checkpoint_netns (struct ckpt_ctx *ctx,void *ptr);net/checkpoint.c +1
-1@@ -776,7 +776,7 @@ static int __do_sock_checkpoint(struct ckpt_ctx *ctx, struct sock *sk) goto out;/* part III: socket buffers */ -if ((sk->sk_state !=TCP_LISTEN ) && (!sock_flag (sk,SOCK_DEAD ))) +if (sock_should_do_buffers (sk)) ret =sock_defer_write_buffers (ctx, sk); out:ckpt_hdr_put (ctx, h);net/ipv4/checkpoint.c +3
-3@@ -537,10 +537,10 @@ int inet_restore(struct ckpt_ctx *ctx,*/ ret =sock_defer_hash (ctx, sock->sk); } - -if (!sock_flag (sock->sk,SOCK_DEAD )) - ret =inet_defer_restore_buffers (ctx, sock->sk); } + +if (sock_should_do_buffers (sock->sk)) + ret =inet_defer_restore_buffers (ctx, sock->sk); out:ckpt_hdr_put (ctx, in);net/unix/checkpoint.c +1
-1@@ -443,7 +443,7 @@ static int unix_restore_connected(struct ckpt_ctx *ctx,ckpt_debug ("unix_defer_join: %i\n" , ret); } -if (!dead && !ret) +if (sock_should_do_buffers (sock->sk) && !ret) ret =unix_defer_restore_buffers (ctx, un->this);return ret;
A message that is not in the archive (sent off-list or not yet received): [email protected]
OL> Only one comment: please rename sock_should_do_buffers() since OL> it's exclusive for c/r and exported in checkpoint.h, OL> e.g. ckpt_sock_need_buffers(). No need to resend - I can do it OL> while pulling.
Oh sure, sorry about that.
Thanks!
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): 87pqyiclj0.fsf-FLMGYpZoEPULwtHQx/[email protected]
Ok, pulled into ckpt-v22-dev.
Oren.
Quoted 9 lines · Dan Smith
OL> Only one comment: please rename
sock_should_do_buffers()since OL> it's exclusive for c/r and exported incheckpoint.h, OL> e.g.ckpt_sock_need_buffers(). No need to resend - I can do it OL> while pulling.Oh sure, sorry about that.
Thanks!