From patchwork Thu Dec 10 15:30:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 40828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AAB76B6EDD for ; Fri, 11 Dec 2009 02:44:25 +1100 (EST) Received: from localhost ([127.0.0.1]:52076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIlBm-00030v-Vl for incoming@patchwork.ozlabs.org; Thu, 10 Dec 2009 10:44:23 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NIkzw-0006c7-MK for qemu-devel@nongnu.org; Thu, 10 Dec 2009 10:32:08 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NIkzs-0006Wu-TO for qemu-devel@nongnu.org; Thu, 10 Dec 2009 10:32:08 -0500 Received: from [199.232.76.173] (port=49964 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIkzs-0006WV-Ni for qemu-devel@nongnu.org; Thu, 10 Dec 2009 10:32:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3835) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NIkzs-0001p5-Mu for qemu-devel@nongnu.org; Thu, 10 Dec 2009 10:32:04 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBAFW3pt010128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 10 Dec 2009 10:32:03 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBAFW0dS011236; Thu, 10 Dec 2009 10:32:02 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Thu, 10 Dec 2009 16:30:54 +0100 Message-Id: <1260459056-20520-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1260459056-20520-1-git-send-email-kwolf@redhat.com> References: <1260459056-20520-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH 1/3] block: Introduce BDRV_O_NO_BACKING X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If an image references a backing file that doesn't exist, qemu-img info fails to open this image. Exactly in this case the info would be valuable, though: the user might want to find out which file is missing. This patch introduces a BDRV_O_NO_BACKING flag to ignore the backing file when opening the image. qemu-img info is the first user and provides info now even if the backing file is invalid. Signed-off-by: Kevin Wolf --- block.c | 4 ++-- block.h | 1 + qemu-img.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 853f025..a794875 100644 --- a/block.c +++ b/block.c @@ -476,7 +476,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, unlink(filename); } #endif - if (bs->backing_file[0] != '\0') { + if ((flags & BDRV_O_NO_BACKING) == 0 && bs->backing_file[0] != '\0') { /* if there is a backing file, use it */ BlockDriver *back_drv = NULL; bs->backing_hd = bdrv_new(""); @@ -1209,7 +1209,7 @@ const char *bdrv_get_encrypted_filename(BlockDriverState *bs) void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size) { - if (!bs->backing_hd) { + if (!bs->backing_file) { pstrcpy(filename, filename_size, ""); } else { pstrcpy(filename, filename_size, bs->backing_file); diff --git a/block.h b/block.h index 4a8b628..880d450 100644 --- a/block.h +++ b/block.h @@ -38,6 +38,7 @@ typedef struct QEMUSnapshotInfo { #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */ #define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */ #define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the thread pool */ +#define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */ #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB) diff --git a/qemu-img.c b/qemu-img.c index 1d97f2e..5ad88bf 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -884,7 +884,7 @@ static int img_info(int argc, char **argv) } else { drv = NULL; } - if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) { + if (bdrv_open2(bs, filename, BRDV_O_FLAGS | BDRV_O_NO_BACKING, drv) < 0) { error("Could not open '%s'", filename); } bdrv_get_format(bs, fmt_name, sizeof(fmt_name));