From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFm8j-0005jr-7C for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:03:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFm8i-0005B7-El for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:03:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54852) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFm8i-0005Ay-30 for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:03:48 -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 t0QG3lQ0015156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 26 Jan 2015 11:03:47 -0500 From: Max Reitz Date: Mon, 26 Jan 2015 11:02:54 -0500 Message-Id: <1422288204-29271-21-git-send-email-mreitz@redhat.com> In-Reply-To: <1422288204-29271-1-git-send-email-mreitz@redhat.com> References: <1422288204-29271-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 20/50] blockdev: Check blk_is_available() in sn-del-int-sync 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@redhat.com Check whether the BlockBackend is actually available at the start of snapshot-delete-internal-sync. Signed-off-by: Max Reitz --- blockdev.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index ae1137f..858d181 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1096,18 +1096,23 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, const char *name, Error **errp) { - BlockDriverState *bs = bdrv_find(device); + BlockBackend *blk; + BlockDriverState *bs; AioContext *aio_context; QEMUSnapshotInfo sn; Error *local_err = NULL; SnapshotInfo *info = NULL; int ret; - if (!bs) { + blk = blk_by_name(device); + if (!blk) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return NULL; } + aio_context = blk_get_aio_context(blk); + aio_context_acquire(aio_context); + if (!has_id) { id = NULL; } @@ -1118,11 +1123,14 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, if (!id && !name) { error_setg(errp, "Name or id must be provided"); - return NULL; + goto out_aio_context; } - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); + if (!blk_is_available(blk)) { + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + goto out_aio_context; + } + bs = blk_bs(blk); if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE, errp)) { goto out_aio_context; -- 2.1.0