From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC6O-0006wP-5p for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGC6L-0002Bq-5M for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48596) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC6K-0002Bf-UB for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:05 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0RJl3RK011457 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 14:47:04 -0500 From: Max Reitz Date: Tue, 27 Jan 2015 14:46:02 -0500 Message-Id: <1422387983-32153-30-git-send-email-mreitz@redhat.com> In-Reply-To: <1422387983-32153-1-git-send-email-mreitz@redhat.com> References: <1422387983-32153-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH RESEND 29/50] blockdev: Check BB validity in find_block_job() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Jeff Cody , Markus Armbruster , Max Reitz , Stefan Hajnoczi , John Snow Call blk_is_available() before using blk_bs() to obtain the root BlockDriverState behind the BlockBackend. Signed-off-by: Max Reitz --- blockdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index 4e12061..4bd52b8 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2698,25 +2698,35 @@ out: /* Get the block job for a given device name and acquire its AioContext */ static BlockJob *find_block_job(const char *device, AioContext **aio_context) { + BlockBackend *blk; BlockDriverState *bs; - bs = bdrv_find(device); - if (!bs) { + *aio_context = NULL; + + blk = blk_by_name(device); + if (!blk) { goto notfound; } - *aio_context = bdrv_get_aio_context(bs); + *aio_context = blk_get_aio_context(blk); aio_context_acquire(*aio_context); + if (!blk_is_available(blk)) { + goto notfound; + } + bs = blk_bs(blk); + if (!bs->job) { - aio_context_release(*aio_context); goto notfound; } return bs->job; notfound: - *aio_context = NULL; + if (*aio_context) { + aio_context_release(*aio_context); + *aio_context = NULL; + } return NULL; } -- 2.1.0