From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zoxax-0005Br-8Z for qemu-devel@nongnu.org; Wed, 21 Oct 2015 13:54:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zoxas-0006SR-2M for qemu-devel@nongnu.org; Wed, 21 Oct 2015 13:54:38 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:34496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zoxar-0006SC-R4 for qemu-devel@nongnu.org; Wed, 21 Oct 2015 13:54:34 -0400 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Oct 2015 11:54:33 -0600 From: Michael Roth Date: Wed, 21 Oct 2015 12:51:52 -0500 Message-Id: <1445449930-23525-23-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1445449930-23525-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1445449930-23525-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 22/40] nbd: release exp->blk after all clients are closed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-stable@nongnu.org, Michael Roth From: Wen Congyang If the socket fd is shutdown, there may be some data which is received before shutdown. We will read the data and do read/write in nbd_trip(). But the exp's blk is NULL, and it will cause qemu crashed. Reported-by: Li Zhijian Signed-off-by: Wen Congyang Message-Id: <55F929E2.1020501@cn.fujitsu.com> Signed-off-by: Paolo Bonzini (cherry picked from commit d6268348493f32ecc096caa637620757472a1196) Signed-off-by: Michael Roth --- nbd.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/nbd.c b/nbd.c index 06b501b..07240bd 100644 --- a/nbd.c +++ b/nbd.c @@ -1131,12 +1131,6 @@ void nbd_export_close(NBDExport *exp) } nbd_export_set_name(exp, NULL); nbd_export_put(exp); - if (exp->blk) { - blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, - blk_aio_detach, exp); - blk_unref(exp->blk); - exp->blk = NULL; - } } void nbd_export_get(NBDExport *exp) @@ -1159,6 +1153,13 @@ void nbd_export_put(NBDExport *exp) exp->close(exp); } + if (exp->blk) { + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, + blk_aio_detach, exp); + blk_unref(exp->blk); + exp->blk = NULL; + } + g_free(exp); } } @@ -1305,6 +1306,14 @@ static void nbd_trip(void *opaque) goto invalid_request; } + if (client->closing) { + /* + * The client may be closed when we are blocked in + * nbd_co_receive_request() + */ + goto done; + } + switch (command) { case NBD_CMD_READ: TRACE("Request type is READ"); -- 1.9.1