qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel][PATCH] Qemu image over raw devices
@ 2008-12-15 14:04 Shahar Frank
  2008-12-15 18:17 ` Kevin Wolf
  2008-12-16 11:15 ` Daniel P. Berrange
  0 siblings, 2 replies; 11+ messages in thread
From: Shahar Frank @ 2008-12-15 14:04 UTC (permalink / raw)
  To: qemu-devel

[-- 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

^ permalink raw reply related	[flat|nested] 11+ messages in thread
[parent not found: <571317069.373331229413498662.JavaMail.root@zmail02.collab.prod.int.phx2.redhat.com>]

end of thread, other threads:[~2008-12-18 17:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-15 14:04 [Qemu-devel][PATCH] Qemu image over raw devices Shahar Frank
2008-12-15 18:17 ` 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

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).