From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH] raw: Use the right host device driver for open/create
Date: Mon, 30 Nov 2009 16:54:31 +0100 [thread overview]
Message-ID: <1259596471-14576-1-git-send-email-kwolf@redhat.com> (raw)
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 <kwolf@redhat.com>
---
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
next reply other threads:[~2009-11-30 15:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-30 15:54 Kevin Wolf [this message]
2009-11-30 20:51 ` [Qemu-devel] [PATCH] raw: Use the right host device driver for open/create Christoph Hellwig
2009-12-03 17:43 ` Anthony Liguori
2009-12-04 8:39 ` Kevin Wolf
2009-12-11 9:04 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1259596471-14576-1-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).