From patchwork Mon Jan 26 16:03:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 432918 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 A6989140192 for ; Tue, 27 Jan 2015 03:27:56 +1100 (AEDT) Received: from localhost ([::1]:42698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFmW2-0008Ek-IK for incoming@patchwork.ozlabs.org; Mon, 26 Jan 2015 11:27:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFm90-0006Ga-Ms for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:04:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFm8s-0005Es-P9 for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:04:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFm8s-0005Ei-Gh for qemu-devel@nongnu.org; Mon, 26 Jan 2015 11:03:58 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0QG3vad015489 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 26 Jan 2015 11:03:58 -0500 Received: from localhost ([10.18.17.71]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0QG3uoJ020423 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 26 Jan 2015 11:03:57 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Mon, 26 Jan 2015 11:03:04 -0500 Message-Id: <1422288204-29271-31-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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Fam Zheng , Jeff Cody , Markus Armbruster , Max Reitz , Stefan Hajnoczi , john@redhat.com Subject: [Qemu-devel] [PATCH 30/50] blockdev: Check BB validity in change-backing-file 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 Call blk_is_available() before using blk_bs() to obtain the root BlockDriverState behind the BlockBackend. Signed-off-by: Max Reitz --- blockdev.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/blockdev.c b/blockdev.c index 4bd52b8..7f4470f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2821,7 +2821,8 @@ void qmp_change_backing_file(const char *device, const char *backing_file, Error **errp) { - BlockDriverState *bs = NULL; + BlockBackend *blk; + BlockDriverState *bs; AioContext *aio_context; BlockDriverState *image_bs = NULL; Error *local_err = NULL; @@ -2830,15 +2831,21 @@ void qmp_change_backing_file(const char *device, int ret; /* find the top layer BDS of the chain */ - 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); + image_bs = bdrv_lookup_bs(NULL, image_node_name, &local_err); if (local_err) { error_propagate(errp, local_err);