From patchwork Mon Nov 30 15:54:31 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 39812 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 67CBE1007D5 for ; Tue, 1 Dec 2009 02:59:55 +1100 (EST) Received: from localhost ([127.0.0.1]:60714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NF8fH-0004XK-HD for incoming@patchwork.ozlabs.org; Mon, 30 Nov 2009 10:59:51 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NF8bI-0003h3-0z for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NF8bC-0003eE-9Z for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:42 -0500 Received: from [199.232.76.173] (port=38956 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NF8bC-0003e4-14 for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10717) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NF8bB-000134-Nu for qemu-devel@nongnu.org; Mon, 30 Nov 2009 10:55:38 -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 nAUFtaaW016624 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 30 Nov 2009 10:55:36 -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 nAUFtZ0Z025230; Mon, 30 Nov 2009 10:55:35 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 30 Nov 2009 16:54:31 +0100 Message-Id: <1259596471-14576-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] raw: Use the right host device driver for open/create 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 Users don't expect that they need to specify host_device/cdrom/floppy when "creating" an image on a block device or converting with an device as target. Currently creating as raw leads to 'Error while formatting' whereas using as raw just works. With this patch raw is accepted for both files and host devices. For devices the block driver is transparently changed to host_*. Signed-off-by: Kevin Wolf --- block.c | 2 +- block/raw-posix.c | 16 ++++++++++++++++ block_int.h | 1 + qemu-img.c | 1 + 4 files changed, 19 insertions(+), 1 deletions(-) diff --git a/block.c b/block.c index 6fdabff..377747f 100644 --- a/block.c +++ b/block.c @@ -283,7 +283,7 @@ static BlockDriver *find_protocol(const char *filename) * Detect host devices. By convention, /dev/cdrom[N] is always * recognized as a host CDROM. */ -static BlockDriver *find_hdev_driver(const char *filename) +BlockDriver *find_hdev_driver(const char *filename) { int score_max = 0, score; BlockDriver *drv = NULL, *d; diff --git a/block/raw-posix.c b/block/raw-posix.c index 3763d0c..54b127a 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -206,6 +206,14 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags) { BDRVRawState *s = bs->opaque; int open_flags = 0; + BlockDriver *drv; + + /* If it's a block device, we want to use the right host_* driver */ + drv = find_hdev_driver(filename); + if (drv) { + bs->drv = drv; + return drv->bdrv_open(bs, filename, flags); + } s->type = FTYPE_FILE; if (flags & BDRV_O_CREAT) @@ -710,6 +718,14 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) int fd; int result = 0; int64_t total_size = 0; + BlockDriver *drv; + + /* If it's a block device, we want to use the right host_* driver */ + drv = find_hdev_driver(filename); + if (drv) { + return drv->bdrv_create(filename, options); + } + /* Read out options */ while (options && options->name) { diff --git a/block_int.h b/block_int.h index a7ac1f6..d96f182 100644 --- a/block_int.h +++ b/block_int.h @@ -185,6 +185,7 @@ struct BlockDriverAIOCB { BlockDriverAIOCB *next; }; +BlockDriver *find_hdev_driver(const char *filename); void get_tmp_filename(char *filename, int size); void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs, diff --git a/qemu-img.c b/qemu-img.c index f19c644..8284d96 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -651,6 +651,7 @@ static int img_convert(int argc, char **argv) } out_bs = bdrv_new_open(out_filename, out_fmt); + drv = out_bs->drv; bs_i = 0; bs_offset = 0;