From patchwork Wed Sep 19 13:49:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 185064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 48AD62C00B6 for ; Thu, 20 Sep 2012 00:41:36 +1000 (EST) Received: from localhost ([::1]:52368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEKgu-0003ps-Gh for incoming@patchwork.ozlabs.org; Wed, 19 Sep 2012 09:51:48 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEKfh-0001Wv-MD for qemu-devel@nongnu.org; Wed, 19 Sep 2012 09:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TEKfb-0005fo-Ey for qemu-devel@nongnu.org; Wed, 19 Sep 2012 09:50:33 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:56240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEKfb-0005IH-8z for qemu-devel@nongnu.org; Wed, 19 Sep 2012 09:50:27 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp12so2503409pbb.4 for ; Wed, 19 Sep 2012 06:50:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=Cma5ZAjm417TjrnhKK7yZTmsodbDqvVeyE6IkmIHL54=; b=FeQBzXhEZnsJPtoU0LVCnnwLixoE3oMNA8ykI3mMg4uJ6fZ5rEPH9kZTZMH15YThHM mrCE04gFKdRKpS7N/Eg1nr9nmxp3NdZG/MHp9zVIfWVSoZuuC7qLmhRnjEA18+WWMSzW zN+mdKSmfmJZBI0sU0nFYxKUEU7lWY3KvzsuDPSBnUQgktqiAoppV02+WIvWdgAdSVVW 8qCBm+/bufTfaRvveMZ7ZSz3BcBN4HslHKrMpelKH8WSlKtl12TD3xxzrJgrb3tYtFGY Yf7Rd/6yT5fKXY3zVnQufz4Ca5Ux1VVOc+sSaCMQIL792tZralxL3xQq+fmhfBEkP0TP Ppdg== Received: by 10.66.76.135 with SMTP id k7mr7110871paw.2.1348062626868; Wed, 19 Sep 2012 06:50:26 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id jw14sm623562pbb.36.2012.09.19.06.50.24 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 19 Sep 2012 06:50:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2012 15:49:51 +0200 Message-Id: <1348062596-30446-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1348062596-30446-1-git-send-email-pbonzini@redhat.com> References: <1348062596-30446-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 07/12] nbd: track clients into NBDExport X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Track the NBDClients of each NBDExport, and use it to implement nbd_export_close. Signed-off-by: Paolo Bonzini --- nbd.c | 13 +++++++++++-- 1 file modificato, 11 inserzioni(+), 2 rimozioni(-) diff --git a/nbd.c b/nbd.c index 4922d38..c39692b 100644 --- a/nbd.c +++ b/nbd.c @@ -94,6 +94,7 @@ struct NBDExport { off_t dev_offset; off_t size; uint32_t nbdflags; + QTAILQ_HEAD(, NBDClient) clients; QSIMPLEQ_HEAD(, NBDRequest) requests; }; @@ -109,6 +110,7 @@ struct NBDClient { CoMutex send_lock; Coroutine *send_coroutine; + QTAILQ_ENTRY(NBDClient) next; int nb_requests; bool closing; }; @@ -665,6 +667,7 @@ void nbd_client_put(NBDClient *client) qemu_set_fd_handler2(client->sock, NULL, NULL, NULL, NULL); close(client->sock); client->sock = -1; + QTAILQ_REMOVE(&client->exp->clients, client, next); nbd_export_put(client->exp); g_free(client); } @@ -725,6 +728,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, NBDExport *exp = g_malloc0(sizeof(NBDExport)); QSIMPLEQ_INIT(&exp->requests); exp->refcount = 1; + QTAILQ_INIT(&exp->clients); exp->bs = bs; exp->dev_offset = dev_offset; exp->nbdflags = nbdflags; @@ -734,9 +738,13 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, void nbd_export_close(NBDExport *exp) { - assert(exp->refcount == 1); + NBDClient *client, *next; - /* stub */ + nbd_export_get(exp); + QTAILQ_FOREACH_SAFE(client, &exp->clients, next, next) { + nbd_client_close(client); + } + nbd_export_put(exp); } void nbd_export_get(NBDExport *exp) @@ -1035,6 +1043,7 @@ NBDClient *nbd_client_new(NBDExport *exp, int csock, qemu_co_mutex_init(&client->send_lock); qemu_set_fd_handler2(csock, nbd_can_read, nbd_read, NULL, client); + QTAILQ_INSERT_TAIL(&exp->clients, client, next); nbd_export_get(exp); return client; }