[PATCH 1/2] qemu: Forbid non-raw images for disk type='lun' with vitio-blk frontend

Peter Krempa pkrempa at redhat.com
Thu May 7 10:09:48 UTC 2020


Historically the virtio-blk frontend by default enabled SCSI emulation
and tried to do SCSI command passthrough. As this was enabled by default
there's a fallback mechanism in place in cases when the backend doesn't
support SCSI for any reason.

This is not the case when disk type=lun is used with 'scsi-block' via
'virtio-scsi'.

We did not restrict configurations when the user picks 'qcow2' or any
other format as format of the disk, in which case the emulation is
disabled as such configuration doesn't make sense.

This patch unifies the approach so that 'raw' is required both when used
via 'virtio-blk' and 'virtio-scsi' so that the user is presented with
the expected configuration. Note that use of <disk type='lun'> is
already very restrictive as it requires a block device or iSCSI storage.

Additionally the scsi emulation is now deprecated by qemu with
virtio-blk as it conflicts with virtio-1 and the alternative is to use
'virtio-scsi' which performs better and is along for a very long time.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---

I'm aware that this will be perceived as regression. In my opinion disk
type=lun should not have existed in the first place, we do have the
<hostdev for it now. Also qemu deprecated the feature, so even if we
don't restrict this now, any user depending on the broken functionality
will have to switch to 'virtio-scsi' where we already forbid non-raw
images once upstream drops the feature fully.

 src/qemu/qemu_domain.c                  | 6 ++++++
 src/qemu/qemu_validate.c                | 8 --------
 tests/qemuxml2argvdata/virtio-lun.args  | 4 ++--
 tests/qemuxml2argvdata/virtio-lun.xml   | 4 ++--
 tests/qemuxml2xmloutdata/virtio-lun.xml | 4 ++--
 5 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0c122f300d..c4ca93722f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10485,6 +10485,12 @@ qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
         return -1;
     }

+    if (src->format != VIR_STORAGE_FILE_RAW) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("disk device 'lun' must use 'raw' format"));
+        return -1;
+    }
+
     return 0;
 }

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 2cde678ca0..f789ed075a 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1997,14 +1997,6 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
             return -1;
         }

-        if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI &&
-            disk->src->format != VIR_STORAGE_FILE_RAW) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("disk device 'lun' using target 'scsi' must use "
-                             "'raw' format"));
-            return -1;
-        }
-
         if (qemuDomainDefValidateDiskLunSource(disk->src) < 0)
             return -1;

diff --git a/tests/qemuxml2argvdata/virtio-lun.args b/tests/qemuxml2argvdata/virtio-lun.args
index 7df1512b9b..850501142a 100644
--- a/tests/qemuxml2argvdata/virtio-lun.args
+++ b/tests/qemuxml2argvdata/virtio-lun.args
@@ -27,10 +27,10 @@ server,nowait \
 -boot menu=on \
 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x6 \
 -usb \
--drive file=/dev/sdfake,format=qcow2,if=none,id=drive-virtio-disk0 \
+-drive file=/dev/sdfake,format=raw,if=none,id=drive-virtio-disk0 \
 -device virtio-blk-pci,scsi=on,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\
 id=virtio-disk0,bootindex=2 \
--drive file=/dev/sdfake2,format=qcow2,if=none,id=drive-virtio-disk1 \
+-drive file=/dev/sdfake2,format=raw,if=none,id=drive-virtio-disk1 \
 -device virtio-blk-pci,scsi=on,bus=pci.0,addr=0x5,drive=drive-virtio-disk1,\
 id=virtio-disk1 \
 -netdev user,id=hostnet0 \
diff --git a/tests/qemuxml2argvdata/virtio-lun.xml b/tests/qemuxml2argvdata/virtio-lun.xml
index 303131fb61..c802da1838 100644
--- a/tests/qemuxml2argvdata/virtio-lun.xml
+++ b/tests/qemuxml2argvdata/virtio-lun.xml
@@ -17,13 +17,13 @@
   <devices>
     <emulator>/usr/bin/qemu-system-x86_64</emulator>
     <disk type='block' device='lun' rawio='yes'>
-      <driver name='qemu' type='qcow2'/>
+      <driver name='qemu' type='raw'/>
       <source dev='/dev/sdfake'/>
       <target dev='vda' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </disk>
     <disk type='block' device='lun'>
-      <driver name='qemu' type='qcow2'/>
+      <driver name='qemu' type='raw'/>
       <source dev='/dev/sdfake2'/>
       <target dev='vdb' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
diff --git a/tests/qemuxml2xmloutdata/virtio-lun.xml b/tests/qemuxml2xmloutdata/virtio-lun.xml
index dbedd4edc0..23052cd519 100644
--- a/tests/qemuxml2xmloutdata/virtio-lun.xml
+++ b/tests/qemuxml2xmloutdata/virtio-lun.xml
@@ -17,13 +17,13 @@
   <devices>
     <emulator>/usr/bin/qemu-system-x86_64</emulator>
     <disk type='block' device='lun' rawio='yes'>
-      <driver name='qemu' type='qcow2'/>
+      <driver name='qemu' type='raw'/>
       <source dev='/dev/sdfake'/>
       <target dev='vda' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </disk>
     <disk type='block' device='lun'>
-      <driver name='qemu' type='qcow2'/>
+      <driver name='qemu' type='raw'/>
       <source dev='/dev/sdfake2'/>
       <target dev='vdb' bus='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
-- 
2.26.2




More information about the libvir-list mailing list