From: Shahar Frank <sfrank@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel][PATCH] Qemu image over raw devices
Date: Mon, 15 Dec 2008 16:04:20 +0200 [thread overview]
Message-ID: <494663E4.3020409@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3631 bytes --]
Hi,
The following patch enables QEMU to create and use images with any
format on top of a raw device. Note that -f <format> is not enough for
bcking files support.
The patch includes the following:
1. The check for block devices is weaken so you can override it by
specifying a protocol
2. If a protocol exists but not found in the protocols list, the logic
falls back to image type probing. This means use can write
"probe:filename" or just ":filename"
Note that if regular file/device path names are used, the previous
behavior is kept.
lvcreate -L 5G -n base store
dd bs=32k if=win.qcow2 of=/dev/store/base
./qemu-img info :/dev/store/base
lvcreate -L 2G -n l2 store
./qemu-img create -b :/dev/store/base -f qcow2 /dev/store/l2
./x86_64-softmmu/qemu-system-x86_64 -hda :/dev/store/l2 -L pc-bios/
lvcreate -L 2G -n l3 store
./qemu-img create -b :/dev/store/l2 -f qcow2 /dev/store/l3
./x86_64-softmmu/qemu-system-x86_64 -hda :/dev/store/l3 -L pc-bios/
Signed-off-by: Shahar Frank <sfrank@redhat.com>
diff --git a/block.c b/block.c
index 28d63d7..cbf9968 100644
--- a/block.c
+++ b/block.c
@@ -226,6 +226,17 @@ static int is_windows_drive(const char *filename)
}
#endif
+static const char *raw_filename(const char *filename)
+{
+ char *_filename;
+
+ _filename = strchr(filename, ':');
+ if (_filename)
+ return _filename + 1;
+ else
+ return filename;
+}
+
static BlockDriver *find_protocol(const char *filename)
{
BlockDriver *drv1;
@@ -267,25 +278,28 @@ static BlockDriver *find_image_format(const char
*filename)
recognized as a host CDROM */
if (strstart(filename, "/dev/cdrom", NULL))
return &bdrv_host_device;
+ drv = find_protocol(filename);
+
+ if (drv == &bdrv_raw) {
#ifdef _WIN32
- if (is_windows_drive(filename))
- return &bdrv_host_device;
+ if (is_windows_drive(filename))
+ return &bdrv_host_device;
#else
- {
- struct stat st;
- if (stat(filename, &st) >= 0 &&
- (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
- return &bdrv_host_device;
- }
- }
+ {
+ struct stat st;
+ if (stat(filename, &st) >= 0 &&
+ (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
+ return &bdrv_host_device;
+ }
+ }
#endif
+ }
- drv = find_protocol(filename);
/* no need to test disk image formats for vvfat */
if (drv == &bdrv_vvfat)
return drv;
- ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
+ ret = bdrv_file_open(&bs, raw_filename(filename), BDRV_O_RDONLY);
if (ret < 0)
return NULL;
ret = bdrv_pread(bs, 0, buf, sizeof(buf));
@@ -335,6 +349,7 @@ int bdrv_open2(BlockDriverState *bs, const char
*filename, int flags,
int ret, open_flags;
char tmp_filename[PATH_MAX];
char backing_filename[PATH_MAX];
+ char const *_filename;
bs->read_only = 0;
bs->is_temporary = 0;
@@ -403,9 +418,12 @@ int bdrv_open2(BlockDriverState *bs, const char
*filename, int flags,
open_flags = BDRV_O_RDWR | (flags & BDRV_O_CACHE_MASK);
else
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
- ret = drv->bdrv_open(bs, filename, open_flags);
+
+ _filename = raw_filename(filename);
+
+ ret = drv->bdrv_open(bs, _filename, open_flags);
if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) {
- ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
+ ret = drv->bdrv_open(bs, _filename, open_flags & ~BDRV_O_RDWR);
bs->read_only = 1;
}
if (ret < 0) {
diff --git a/qemu-img.c b/qemu-img.c
[-- Attachment #2: qemu-image-over-raw.patch --]
[-- Type: text/plain, Size: 2591 bytes --]
diff --git a/block.c b/block.c
index 28d63d7..cbf9968 100644
--- a/block.c
+++ b/block.c
@@ -226,6 +226,17 @@ static int is_windows_drive(const char *filename)
}
#endif
+static const char *raw_filename(const char *filename)
+{
+ char *_filename;
+
+ _filename = strchr(filename, ':');
+ if (_filename)
+ return _filename + 1;
+ else
+ return filename;
+}
+
static BlockDriver *find_protocol(const char *filename)
{
BlockDriver *drv1;
@@ -267,25 +278,28 @@ static BlockDriver *find_image_format(const char *filename)
recognized as a host CDROM */
if (strstart(filename, "/dev/cdrom", NULL))
return &bdrv_host_device;
+ drv = find_protocol(filename);
+
+ if (drv == &bdrv_raw) {
#ifdef _WIN32
- if (is_windows_drive(filename))
- return &bdrv_host_device;
+ if (is_windows_drive(filename))
+ return &bdrv_host_device;
#else
- {
- struct stat st;
- if (stat(filename, &st) >= 0 &&
- (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
- return &bdrv_host_device;
- }
- }
+ {
+ struct stat st;
+ if (stat(filename, &st) >= 0 &&
+ (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
+ return &bdrv_host_device;
+ }
+ }
#endif
+ }
- drv = find_protocol(filename);
/* no need to test disk image formats for vvfat */
if (drv == &bdrv_vvfat)
return drv;
- ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
+ ret = bdrv_file_open(&bs, raw_filename(filename), BDRV_O_RDONLY);
if (ret < 0)
return NULL;
ret = bdrv_pread(bs, 0, buf, sizeof(buf));
@@ -335,6 +349,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
int ret, open_flags;
char tmp_filename[PATH_MAX];
char backing_filename[PATH_MAX];
+ char const *_filename;
bs->read_only = 0;
bs->is_temporary = 0;
@@ -403,9 +418,12 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
open_flags = BDRV_O_RDWR | (flags & BDRV_O_CACHE_MASK);
else
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
- ret = drv->bdrv_open(bs, filename, open_flags);
+
+ _filename = raw_filename(filename);
+
+ ret = drv->bdrv_open(bs, _filename, open_flags);
if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) {
- ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
+ ret = drv->bdrv_open(bs, _filename, open_flags & ~BDRV_O_RDWR);
bs->read_only = 1;
}
if (ret < 0) {
diff --git a/qemu-img.c b/qemu-img.c
next reply other threads:[~2008-12-15 14:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-15 14:04 Shahar Frank [this message]
2008-12-15 18:17 ` [Qemu-devel][PATCH] Qemu image over raw devices Kevin Wolf
2008-12-16 11:15 ` Daniel P. Berrange
[not found] <571317069.373331229413498662.JavaMail.root@zmail02.collab.prod.int.phx2.redhat.com>
2008-12-16 7:50 ` Shahar Frank
2008-12-16 9:40 ` Kevin Wolf
2008-12-16 10:21 ` Shahar Frank
2008-12-16 12:10 ` Kevin Wolf
2008-12-16 12:55 ` Shahar Frank
2008-12-17 12:57 ` Kevin Wolf
2008-12-18 17:20 ` Shahar Frank
2008-12-16 10:53 ` Daniel P. Berrange
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=494663E4.3020409@redhat.com \
--to=sfrank@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.