qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] raw: Use the right host device driver for open/crea


From: Kevin Wolf
Subject: [Qemu-devel] [PATCH] raw: Use the right host device driver for open/create
Date: Mon, 30 Nov 2009 16:54:31 +0100

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 <address@hidden>
---
 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;
-- 
1.6.2.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]