Skip to contentSkip to conversation

AF_UNIX fixes (v2)

PATCH New Dan Smith 2 participants 4 messages Jul 30, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Dan Smith

author
#0 lore raw

This is a re-send of the AF_UNIX fix set with the "need buffers" function moved to net/checkpoint.c since it's only used in one place now.

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

author
#2 lore raw

PATCH 1/2 Fix net buffer logic (v2)

The previous change to the buffer save/restore logic caused us to incorrectly attempt to restore buffers on a socket in a few instances where flags may not be restored yet or we are in a temporarily altered state.

So, keep the same logic, but save a flag to indicate whether buffers were checkpointed to avoid the ambiguity at restore time.

Also, move the UNIX buffer restore point to the main function to avoid potentially ignoring the flag on a socket we assume wouldn't have saved buffers.

Changes in v2:
- Move ckpt_sock_need_buffers() back into net/checkpoint.c, since it is now the only user

---
 include/linux/checkpoint.h     |    4 ----
 include/linux/checkpoint_hdr.h |    2 ++
 net/checkpoint.c               |    9 ++++++++-
 net/ipv4/checkpoint.c          |    2 +-
 net/unix/checkpoint.c          |    9 ++++++---
 5 files changed, 17 insertions(+), 9 deletions(-)
include/linux/checkpoint.h +0 -4
index 0437de2..4e25042 100644
@@ -126,10 +126,6 @@ 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 ckpt_sock_need_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);
include/linux/checkpoint_hdr.h +2 -0
index 9e8d518..f4f9577 100644
@@ -596,6 +596,8 @@ struct ckpt_hdr_file_eventfd {
 struct ckpt_hdr_socket {
 	struct ckpt_hdr h;
 
+	__u8 has_buffers;
+
 	struct { /* struct socket */
 		__u64 flags;
 		__u8 state;
net/checkpoint.c +8 -1
index 0d90af2..be2693c 100644
@@ -31,6 +31,11 @@ struct dq_buffers {
 	struct sock *sk;
 };
 
+static int ckpt_sock_need_buffers(struct sock *sk)
+{
+	return (sk->sk_state != TCP_LISTEN) && !sock_flag(sk, SOCK_DEAD);
+}
+
 static int sock_copy_buffers(struct sk_buff_head *from,
 			     struct sk_buff_head *to,
 			     uint32_t *total_bytes)
@@ -761,6 +766,8 @@ static int __do_sock_checkpoint(struct ckpt_ctx *ctx, struct sock *sk)
 	if (!h)
 		return -ENOMEM;
 
+	h->has_buffers = ckpt_sock_need_buffers(sk);
+
 	/* part I: common to all sockets */
 	ret = sock_cptrst(ctx, sk, h, CKPT_CPT);
 	if (ret < 0)
@@ -776,7 +783,7 @@ static int __do_sock_checkpoint(struct ckpt_ctx *ctx, struct sock *sk)
 		goto out;
 
 	/* part III: socket buffers */
-	if (ckpt_sock_need_buffers(sk))
+	if (h->has_buffers)
 		ret = sock_defer_write_buffers(ctx, sk);
  out:
 	ckpt_hdr_put(ctx, h);
net/ipv4/checkpoint.c +1 -1
index eb02175..ec42e57 100644
@@ -539,7 +539,7 @@ int inet_restore(struct ckpt_ctx *ctx,
 		}
 	}
 
-	if (ckpt_sock_need_buffers(sock->sk))
+	if (h->has_buffers)
 		ret = inet_defer_restore_buffers(ctx, sock->sk);
  out:
 	ckpt_hdr_put(ctx, in);
net/unix/checkpoint.c +6 -3
index 1fa3d7e..47d38e2 100644
@@ -443,9 +443,6 @@ static int unix_restore_connected(struct ckpt_ctx *ctx,
 		ckpt_debug("unix_defer_join: %i\n", ret);
 	}
 
-	if (ckpt_sock_need_buffers(sock->sk) && !ret)
-		ret = unix_defer_restore_buffers(ctx, un->this);
-
 	return ret;
 }
 
@@ -639,6 +636,12 @@ int unix_restore(struct ckpt_ctx *ctx, struct socket *sock,
 	else
 		ckpt_err(ctx, ret, "bad af_unix state %i\n", h->sock.state);
 
+	if (ret < 0)
+		goto out;
+
+	if (h->has_buffers)
+		ret = unix_defer_restore_buffers(ctx, un->this);
+
  out:
 	ckpt_hdr_put(ctx, un);
 	kfree(cwd);
Signature · 1 line
1.7.1.1
author
#3 lore raw

PATCH 2/2 Fix restoring unlinked UNIX sockets

In reply to a message not in the archive

We already support the concept, but the logic controlling whether or not we restore the CWD path didn't follow. This patch adds a check of the "unlinked" flag we've already set before saving or restoring the CWD string.

This fixes an issue with a real-world workload that I have which utilizes AF_UNIX sockets.

---
 net/unix/checkpoint.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
net/unix/checkpoint.c +5 -2
index 47d38e2..9522c3a 100644
@@ -165,7 +165,8 @@ int unix_checkpoint(struct ckpt_ctx *ctx, struct socket *sock)
 	if (ret < 0)
 		goto out;
 
-	if (unix_need_cwd(&un->laddr, un->laddr_len))
+	if (unix_need_cwd(&un->laddr, un->laddr_len) &&
+	    (un->flags & CKPT_UNIX_LINKED))
 		ret = unix_write_cwd(ctx, sock->sk, un->laddr.sun_path);
  out:
 	ckpt_hdr_put(ctx, un);
@@ -614,10 +615,12 @@ int unix_restore(struct ckpt_ctx *ctx, struct socket *sock,
 	if (un->peer < 0)
 		goto out;
 
-	if (unix_need_cwd(&un->laddr, un->laddr_len)) {
+	if (unix_need_cwd(&un->laddr, un->laddr_len) &&
+	    (un->flags & CKPT_UNIX_LINKED)) {
 		cwd = ckpt_read_string(ctx, PATH_MAX);
 		if (IS_ERR(cwd)) {
 			ret = PTR_ERR(cwd);
+			cwd = NULL;
 			goto out;
 		}
 	}
Signature · 1 line
1.7.1.1