Skip to contentSkip to conversation

block: Probe file for specified format

PATCH In review Stefan Weil 1 participant 2 messages Dec 15, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Probe file for specified format

Probe for the file format if the file format was specified explicitly and a probe function is available.

example: -drive file=myfile,format=qcow2

Then myfile is probed and must be in qcow2 format.

This fixes those bugs:

https://bugzilla.redhat.com/show_bug.cgi?id=556482
https://bugs.launchpad.net/qemu/+bug/1090600

---

This patch can also be used for the latest stable version of QEMU.

 blockdev.c |    7 +++++++
 1 file changed, 7 insertions(+)
blockdev.c +7 -0
index 9a05e57..5a4cd56 100644
@@ -411,6 +411,13 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
             error_report("'%s' invalid format", buf);
             return NULL;
         }
+        if (file && drv->bdrv_probe) {
+            uint8_t data[2048];
+            if (drv->bdrv_probe(data, sizeof(data), file) == 0) {
+                error_report("file '%s' not in '%s' format", file, buf);
+                return NULL;
+            }
+        }
     }
 
     /* disk I/O throttling */
Signature · 1 line
1.7.10.4
#1 lore raw

Am 15.12.2012 12:35, schrieb Stefan Weil:

Quoted 28 lines

Probe for the file format if the file format was specified explicitly and a probe function is available.

example: -drive file=myfile,format=qcow2

Then myfile is probed and must be in qcow2 format.

This fixes those bugs:

https://bugzilla.redhat.com/show_bug.cgi?id=556482
https://bugs.launchpad.net/qemu/+bug/1090600

---

This patch can also be used for the latest stable version of QEMU.

  blockdev.c |    7 +++++++
  1 file changed, 7 insertions(+)
blockdev.c +0 -0
index 9a05e57..5a4cd56 100644
@@ -411,6 +411,13 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type)
              error_report("'%s' invalid format", buf);
              return NULL;
          }

blockdev.c DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type) · line 423

Quoted 10 lines
blockdev.c +7 -0
+        if (file && drv->bdrv_probe) {
+            uint8_t data[2048];
+            if (drv->bdrv_probe(data, sizeof(data), file) == 0) {
+                error_report("file '%s' not in '%s' format", file, buf);
+                return NULL;
+            }
+        }
      }
 
      /* disk I/O throttling */

Sorry, this patch was not tested enough. I'll send a v2.

- Stefan Weil