From patchwork Thu Dec 17 14:40:20 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 41319 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 E3D09B6F2B for ; Fri, 18 Dec 2009 01:52:17 +1100 (EST) Received: from localhost ([127.0.0.1]:53363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLHiB-00013n-1D for incoming@patchwork.ozlabs.org; Thu, 17 Dec 2009 09:52:15 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLHXu-0004yi-Fv for qemu-devel@nongnu.org; Thu, 17 Dec 2009 09:41:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLHXp-0004sR-BO for qemu-devel@nongnu.org; Thu, 17 Dec 2009 09:41:37 -0500 Received: from [199.232.76.173] (port=59876 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLHXo-0004sJ-GX for qemu-devel@nongnu.org; Thu, 17 Dec 2009 09:41:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38287) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NLHXn-0004kW-CM for qemu-devel@nongnu.org; Thu, 17 Dec 2009 09:41:31 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBHEfTQO032475 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 17 Dec 2009 09:41:29 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBHEfRwK002820; Thu, 17 Dec 2009 09:41:28 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Thu, 17 Dec 2009 15:40:20 +0100 Message-Id: <1261060822-23219-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1261060822-23219-1-git-send-email-kwolf@redhat.com> References: <1261060822-23219-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH v3 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 3f3496e..20a0de2 100644 --- a/block.c +++ b/block.c @@ -477,7 +477,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(""); @@ -1352,7 +1352,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 fa51ddf..f660d5f 100644 --- a/block.h +++ b/block.h @@ -39,6 +39,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));