From patchwork Fri Apr 23 15:30:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 50830 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 A705CB7D25 for ; Sat, 24 Apr 2010 01:57:31 +1000 (EST) Received: from localhost ([127.0.0.1]:60882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5LBm-0005rX-9E for incoming@patchwork.ozlabs.org; Fri, 23 Apr 2010 11:53:10 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O5KrP-0007Wo-L9 for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:32:07 -0400 Received: from [140.186.70.92] (port=50390 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5KrL-0007Ti-VO for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:32:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O5KrD-0005t2-Nq for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:32:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57391) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5KrD-0005sj-FT for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:31:55 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3NFVrXc004022 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Apr 2010 11:31:53 -0400 Received: from localhost.localdomain (vpn2-9-155.ams2.redhat.com [10.36.9.155]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3NFVOCF020467; Fri, 23 Apr 2010 11:31:51 -0400 From: Kevin Wolf To: aliguori@linux.vnet.ibm.com Date: Fri, 23 Apr 2010 17:30:42 +0200 Message-Id: <1272036658-26776-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1272036658-26776-1-git-send-email-kwolf@redhat.com> References: <1272036658-26776-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 10/26] block: get rid of the BDRV_O_FILE flag 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 From: Christoph Hellwig BDRV_O_FILE is only used to communicate between bdrv_file_open and bdrv_open. It affects two things: first bdrv_open only searches for protocols using find_protocol instead of all image formats and host drivers. We can easily move that to the caller and pass the found driver to bdrv_open. Second it is used to not force a read-write open of a snapshot file. But we never use bdrv_file_open to open snapshots and this behaviour doesn't make sense to start with. qemu-io abused the BDRV_O_FILE for it's growable option, switch it to using bdrv_file_open to make sure we only open files as growable were we can actually support that. This patch requires Kevin's "[PATCH] Replace calls of old bdrv_open" to be applied first. Signed-off-by: Christoph Hellwig Signed-off-by: Kevin Wolf --- block.c | 19 +++++++++++-------- block.h | 4 ---- qemu-io.c | 28 ++++++++++++++-------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/block.c b/block.c index e74264d..ed4c819 100644 --- a/block.c +++ b/block.c @@ -335,10 +335,16 @@ static BlockDriver *find_image_format(const char *filename) int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags) { BlockDriverState *bs; + BlockDriver *drv; int ret; + drv = find_protocol(filename); + if (!drv) { + return -ENOENT; + } + bs = bdrv_new(""); - ret = bdrv_open(bs, filename, flags | BDRV_O_FILE, NULL); + ret = bdrv_open(bs, filename, flags, drv); if (ret < 0) { bdrv_delete(bs); return ret; @@ -416,9 +422,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, } pstrcpy(bs->filename, sizeof(bs->filename), filename); - if (flags & BDRV_O_FILE) { - drv = find_protocol(filename); - } else if (!drv) { + + if (!drv) { drv = find_hdev_driver(filename); if (!drv) { drv = find_image_format(filename); @@ -450,14 +455,12 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, * Clear flags that are internal to the block layer before opening the * image. */ - open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); + open_flags = flags & ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); /* * Snapshots should be writeable. - * - * XXX(hch): and what is the point of a snapshot during a read-only open? */ - if (!(flags & BDRV_O_FILE) && bs->is_temporary) { + if (bs->is_temporary) { open_flags |= BDRV_O_RDWR; } diff --git a/block.h b/block.h index c5900c8..4a57dd5 100644 --- a/block.h +++ b/block.h @@ -29,10 +29,6 @@ typedef struct QEMUSnapshotInfo { #define BDRV_O_RDWR 0x0002 #define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */ -#define BDRV_O_FILE 0x0010 /* open as a raw file (do not try to - use a disk image format on top of - it (default for - bdrv_file_open()) */ #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 */ diff --git a/qemu-io.c b/qemu-io.c index ffb5817..8517b90 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -1276,23 +1276,23 @@ static int openfile(char *name, int flags, int growable) return 1; } - bs = bdrv_new("hda"); - if (!bs) - return 1; - if (growable) { - flags |= BDRV_O_FILE; - } - - if (bdrv_open(bs, name, flags, NULL) < 0) { - fprintf(stderr, "%s: can't open device %s\n", progname, name); - bs = NULL; - return 1; + if (bdrv_file_open(&bs, name, flags)) { + fprintf(stderr, "%s: can't open device %s\n", progname, name); + return 1; + } + } else { + bs = bdrv_new("hda"); + if (!bs) + return 1; + + if (bdrv_open(bs, name, flags, NULL) < 0) { + fprintf(stderr, "%s: can't open device %s\n", progname, name); + bs = NULL; + return 1; + } } - if (growable) { - bs->growable = 1; - } return 0; }