From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc7ud-0007Uc-Th for qemu-devel@nongnu.org; Wed, 16 Sep 2015 04:17:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zc7ua-0008Dm-Oj for qemu-devel@nongnu.org; Wed, 16 Sep 2015 04:17:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zc7ua-0008DQ-Ir for qemu-devel@nongnu.org; Wed, 16 Sep 2015 04:17:52 -0400 References: <55F91755.1010704@cn.fujitsu.com> From: Paolo Bonzini Message-ID: <55F925AC.6060406@redhat.com> Date: Wed, 16 Sep 2015 10:17:48 +0200 MIME-Version: 1.0 In-Reply-To: <55F91755.1010704@cn.fujitsu.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] nbd: wait all read/write requests finished when shutdowning nbd socket List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wen Congyang , qemu-devl Cc: Li Zhijian On 16/09/2015 09:16, Wen Congyang wrote: > 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); I think a better fix is to move the whole "if" to nbd_export_put. In fact, nbd_export_close is wrong because exp can be freed by nbd_export_close's call to nbd_export_put. > @@ -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; > + } This is okay. Paolo > switch (command) { > case NBD_CMD_READ: > TRACE("Request type is READ"); >