From patchwork Wed Sep 16 07:16:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 518275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CFD4014016A for ; Wed, 16 Sep 2015 17:17:41 +1000 (AEST) Received: from localhost ([::1]:47990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc6yK-0003ct-2i for incoming@patchwork.ozlabs.org; Wed, 16 Sep 2015 03:17:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc6y0-0003JY-CH for qemu-devel@nongnu.org; Wed, 16 Sep 2015 03:17:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zc6xw-0005Ht-BJ for qemu-devel@nongnu.org; Wed, 16 Sep 2015 03:17:20 -0400 Received: from [59.151.112.132] (port=5917 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc6xv-0005H1-Uf for qemu-devel@nongnu.org; Wed, 16 Sep 2015 03:17:16 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100771671" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Sep 2015 15:20:03 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8G7GtpC023714; Wed, 16 Sep 2015 15:16:55 +0800 Received: from [10.167.226.52] (10.167.226.52) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Wed, 16 Sep 2015 15:17:10 +0800 To: qemu-devl , Paolo Bonzini From: Wen Congyang Message-ID: <55F91755.1010704@cn.fujitsu.com> Date: Wed, 16 Sep 2015 15:16:37 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Li Zhijian Subject: [Qemu-devel] [PATCH] nbd: wait all read/write requests finished when shutdowning nbd socket 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 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 --- nbd.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nbd.c b/nbd.c index 06b501b..d8586a1 100644 --- a/nbd.c +++ b/nbd.c @@ -1132,6 +1132,7 @@ void nbd_export_close(NBDExport *exp) nbd_export_set_name(exp, NULL); nbd_export_put(exp); if (exp->blk) { + bdrv_drain(blk_bs(exp->blk)); blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach, exp); blk_unref(exp->blk); @@ -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");