netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: kvm@vger.kernel.org
Cc: netdev@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Matt Benjamin" <mbenjamin@redhat.com>,
	"Christoffer Dall" <christoffer.dall@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"marius vlad" <marius.vlad0@gmail.com>,
	areis@redhat.com,
	"Claudio Imbrenda" <imbrenda@linux.vnet.ibm.com>,
	"Greg Kurz" <gkurz@linux.vnet.ibm.com>,
	"Ian Campbell" <ian.campbell@docker.com>,
	ggarcia@abra.uab.cat, virtualization@lists.linux-foundation.org,
	"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: [RFC v6 2/6] VSOCK: defer sock removal to transports
Date: Thu, 28 Jul 2016 15:36:31 +0100	[thread overview]
Message-ID: <1469716595-13591-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1469716595-13591-1-git-send-email-stefanha@redhat.com>

The virtio transport will implement graceful shutdown and the related
SO_LINGER socket option.  This requires orphaning the sock but keeping
it in the table of connections after .release().

This patch adds the vsock_remove_sock() function and leaves it up to the
transport when to remove the sock.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/net/af_vsock.h         |  1 +
 net/vmw_vsock/af_vsock.c       | 16 ++++++++++------
 net/vmw_vsock/vmci_transport.c |  2 ++
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
index 23f5525..3af0b22 100644
--- a/include/net/af_vsock.h
+++ b/include/net/af_vsock.h
@@ -180,6 +180,7 @@ void vsock_remove_connected(struct vsock_sock *vsk);
 struct sock *vsock_find_bound_socket(struct sockaddr_vm *addr);
 struct sock *vsock_find_connected_socket(struct sockaddr_vm *src,
 					 struct sockaddr_vm *dst);
+void vsock_remove_sock(struct vsock_sock *vsk);
 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk));
 
 #endif /* __AF_VSOCK_H__ */
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index e34d96f..17dbbe6 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -344,6 +344,16 @@ static bool vsock_in_connected_table(struct vsock_sock *vsk)
 	return ret;
 }
 
+void vsock_remove_sock(struct vsock_sock *vsk)
+{
+	if (vsock_in_bound_table(vsk))
+		vsock_remove_bound(vsk);
+
+	if (vsock_in_connected_table(vsk))
+		vsock_remove_connected(vsk);
+}
+EXPORT_SYMBOL_GPL(vsock_remove_sock);
+
 void vsock_for_each_connected_socket(void (*fn)(struct sock *sk))
 {
 	int i;
@@ -660,12 +670,6 @@ static void __vsock_release(struct sock *sk)
 		vsk = vsock_sk(sk);
 		pending = NULL;	/* Compiler warning. */
 
-		if (vsock_in_bound_table(vsk))
-			vsock_remove_bound(vsk);
-
-		if (vsock_in_connected_table(vsk))
-			vsock_remove_connected(vsk);
-
 		transport->release(vsk);
 
 		lock_sock(sk);
diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
index 4120b7a..4be4fbb 100644
--- a/net/vmw_vsock/vmci_transport.c
+++ b/net/vmw_vsock/vmci_transport.c
@@ -1644,6 +1644,8 @@ static void vmci_transport_destruct(struct vsock_sock *vsk)
 
 static void vmci_transport_release(struct vsock_sock *vsk)
 {
+	vsock_remove_sock(vsk);
+
 	if (!vmci_handle_is_invalid(vmci_trans(vsk)->dg_handle)) {
 		vmci_datagram_destroy_handle(vmci_trans(vsk)->dg_handle);
 		vmci_trans(vsk)->dg_handle = VMCI_INVALID_HANDLE;
-- 
2.7.4


  parent reply	other threads:[~2016-07-28 14:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-28 14:36 [RFC v6 0/6] Add virtio transport for AF_VSOCK Stefan Hajnoczi
2016-07-28 14:36 ` [RFC v6 1/6] VSOCK: transport-specific vsock_transport functions Stefan Hajnoczi
2016-07-28 14:36 ` Stefan Hajnoczi [this message]
2016-07-28 14:36 ` [RFC v6 3/6] VSOCK: Introduce virtio_vsock_common.ko Stefan Hajnoczi
2016-07-28 14:36 ` [RFC v6 4/6] VSOCK: Introduce virtio_transport.ko Stefan Hajnoczi
2016-07-28 14:36 ` [RFC v6 5/6] VSOCK: Introduce vhost_vsock.ko Stefan Hajnoczi
2016-07-28 14:36 ` [RFC v6 6/6] VSOCK: Add Makefile and Kconfig Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469716595-13591-3-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=areis@redhat.com \
    --cc=christoffer.dall@linaro.org \
    --cc=ggarcia@abra.uab.cat \
    --cc=gkurz@linux.vnet.ibm.com \
    --cc=ian.campbell@docker.com \
    --cc=imbrenda@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=marius.vlad0@gmail.com \
    --cc=mbenjamin@redhat.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).