From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGGxY-0000GC-Ar for qemu-devel@nongnu.org; Tue, 27 Jan 2015 19:58:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGGxV-0007mz-5n for qemu-devel@nongnu.org; Tue, 27 Jan 2015 19:58:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGGme-0004N3-3y for qemu-devel@nongnu.org; Tue, 27 Jan 2015 19:47:04 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0S0l2lu023772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 19:47:03 -0500 From: Max Reitz Date: Tue, 27 Jan 2015 14:45:57 -0500 Message-Id: <1422387983-32153-25-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 24/50] blockdev: Check BB validity in block-stream 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 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9801a7e..74d26a6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2142,6 +2142,7 @@ void qmp_block_stream(const char *device, bool has_on_error, BlockdevOnError on_error, Error **errp) { + BlockBackend *blk; BlockDriverState *bs; BlockDriverState *base_bs = NULL; AioContext *aio_context; @@ -2152,15 +2153,21 @@ void qmp_block_stream(const char *device, on_error = BLOCKDEV_ON_ERROR_REPORT; } - bs = bdrv_find(device); - if (!bs) { + blk = blk_by_name(device); + if (!blk) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } - aio_context = bdrv_get_aio_context(bs); + aio_context = blk_get_aio_context(blk); aio_context_acquire(aio_context); + if (!blk_is_available(blk)) { + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + goto out; + } + bs = blk_bs(blk); + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_STREAM, errp)) { goto out; } -- 2.1.0