qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@gmail.com
Subject: [Qemu-devel] [RFC PATCH 04/13] nbd: close all clients on deleting export
Date: Mon, 27 Aug 2012 17:00:17 +0200	[thread overview]
Message-ID: <1346079626-16386-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1346079626-16386-1-git-send-email-pbonzini@redhat.com>

Clients have a pointer to the NBDExport that they serve.  Do not
let a dangling pointer escape.  Also flush all pending I/O so that
coroutines are forced to exit.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 nbd.c | 14 ++++++++++++++
 1 file modificato, 14 inserzioni(+)

diff --git a/nbd.c b/nbd.c
index cb4e8fe..f6eaea3 100644
--- a/nbd.c
+++ b/nbd.c
@@ -93,6 +93,7 @@ struct NBDExport {
     off_t dev_offset;
     off_t size;
     uint32_t nbdflags;
+    QTAILQ_HEAD(, NBDClient) clients;
     QSIMPLEQ_HEAD(, NBDRequest) requests;
 };
 
@@ -108,6 +109,7 @@ struct NBDClient {
     CoMutex send_lock;
     Coroutine *send_coroutine;
 
+    QTAILQ_ENTRY(NBDClient) next;
     int nb_requests;
 };
 
@@ -658,6 +660,9 @@ static void nbd_client_put(NBDClient *client)
 {
     if (--client->refcount == 0) {
         qemu_set_fd_handler2(client->sock, NULL, NULL, NULL, NULL);
+        if (client->exp) {
+            QTAILQ_REMOVE(&client->exp->clients, client, next);
+        }
         close(client->sock);
         client->sock = -1;
         if (client->close) {
@@ -711,6 +716,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
 {
     NBDExport *exp = g_malloc0(sizeof(NBDExport));
     QSIMPLEQ_INIT(&exp->requests);
+    QTAILQ_INIT(&exp->clients);
     exp->bs = bs;
     exp->dev_offset = dev_offset;
     exp->nbdflags = nbdflags;
@@ -720,6 +726,11 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset,
 
 void nbd_export_close(NBDExport *exp)
 {
+    while (!QTAILQ_EMPTY(&exp->clients)) {
+        NBDClient *client = QTAILQ_FIRST(&exp->clients);
+        nbd_client_close(client);
+    }
+
     while (!QSIMPLEQ_EMPTY(&exp->requests)) {
         NBDRequest *first = QSIMPLEQ_FIRST(&exp->requests);
         QSIMPLEQ_REMOVE_HEAD(&exp->requests, entry);
@@ -995,6 +1006,9 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock,
         return NULL;
     }
     client->close = close;
+    if (exp) {
+        QTAILQ_INSERT_TAIL(&exp->clients, client, next);
+    }
     qemu_co_mutex_init(&client->send_lock);
     qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client);
     return client;
-- 
1.7.11.2

  parent reply	other threads:[~2012-08-27 15:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-27 15:00 [Qemu-devel] [RFC PATCH 00/13] Embedded NBD server Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 01/13] nbd: add more constants Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 02/13] nbd: pass NBDClient to nbd_send_negotiate Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 03/13] nbd: do not leak nbd_trip coroutines when a connection is torn down Paolo Bonzini
2012-08-27 15:00 ` Paolo Bonzini [this message]
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 05/13] nbd: register named exports Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 06/13] nbd: negotiate with " Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 07/13] nbd: do not close BlockDriverState in nbd_export_close Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 08/13] qemu-sockets: publish dummy_opts Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 09/13] qmp: add NBD server commands Paolo Bonzini
2012-09-18 20:11   ` Luiz Capitulino
2012-09-19  8:16     ` Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 10/13] qemu-sockets: make inet_parse public Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 11/13] hmp: add NBD server commands Paolo Bonzini
2012-09-18 20:22   ` Luiz Capitulino
2012-09-19  8:00     ` Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 12/13] block: add close notifiers Paolo Bonzini
2012-08-27 15:00 ` [Qemu-devel] [RFC PATCH 13/13] nbd: add notifier to close exports when the image is closed Paolo Bonzini
2012-09-07 15:50 ` [Qemu-devel] ping Re: [RFC PATCH 00/13] Embedded NBD server Paolo Bonzini
2012-09-07 16:11   ` Kevin Wolf
2012-09-17 16:43     ` Paolo Bonzini
2012-09-18  8:45       ` Kevin Wolf
2012-09-18  9:09         ` Paolo Bonzini
2012-09-18  9:40           ` Kevin Wolf
2012-09-18  9:48             ` Paolo Bonzini
2012-09-18  9:55               ` Kevin Wolf
2012-09-19 10:16 ` [Qemu-devel] " Daniel P. Berrange
2012-09-19 10:22   ` Paolo Bonzini

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=1346079626-16386-5-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /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).