Blame SOURCES/libvirt-qemu-domain-Reject-shared-disk-access-if-backing-format-does-not-support-it.patch

c1c534
From e335715f4f93b62641b8a3a780c8617b1db1434b Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <e335715f4f93b62641b8a3a780c8617b1db1434b@dist-git>
c1c534
From: Peter Krempa <pkrempa@redhat.com>
c1c534
Date: Thu, 23 Nov 2017 19:02:19 +0100
c1c534
Subject: [PATCH] qemu: domain: Reject shared disk access if backing format
c1c534
 does not support it
c1c534
c1c534
Disk sharing between two VMs may corrupt the images if the format driver
c1c534
does not support it. Check that the user declared use of a supported
c1c534
storage format when they want to share the disk.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1511480
c1c534
(cherry picked from commit 3b03a27cd00c2f032661d2bf8905795425752fc7)
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_domain.c                             | 27 +++++++++++++++++++++
c1c534
 .../qemuxml2argv-disk-drive-shared-qcow.xml        | 28 ++++++++++++++++++++++
c1c534
 .../qemuxml2argv-disk-drive-shared.args            |  2 +-
c1c534
 .../qemuxml2argv-disk-drive-shared.xml             |  2 +-
c1c534
 tests/qemuxml2argvtest.c                           |  1 +
c1c534
 5 files changed, 58 insertions(+), 2 deletions(-)
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-qcow.xml
c1c534
c1c534
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c1c534
index 1159be9980..2f987787cd 100644
c1c534
--- a/src/qemu/qemu_domain.c
c1c534
+++ b/src/qemu/qemu_domain.c
c1c534
@@ -25,6 +25,7 @@
c1c534
 
c1c534
 #include "qemu_domain.h"
c1c534
 #include "qemu_alias.h"
c1c534
+#include "qemu_block.h"
c1c534
 #include "qemu_cgroup.h"
c1c534
 #include "qemu_command.h"
c1c534
 #include "qemu_process.h"
c1c534
@@ -3689,6 +3690,29 @@ qemuDomainDeviceDefValidateVideo(const virDomainVideoDef *video)
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static int
c1c534
+qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk)
c1c534
+{
c1c534
+    if (disk->src->shared && !disk->src->readonly) {
c1c534
+        if (disk->src->format <= VIR_STORAGE_FILE_AUTO) {
c1c534
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
+                           _("shared access for disk '%s' requires use of "
c1c534
+                             "explicitly specified disk format"), disk->dst);
c1c534
+            return -1;
c1c534
+        }
c1c534
+
c1c534
+        if (!qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) {
c1c534
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
+                           _("shared access for disk '%s' requires use of "
c1c534
+                             "supported storage format"), disk->dst);
c1c534
+            return -1;
c1c534
+        }
c1c534
+    }
c1c534
+
c1c534
+    return 0;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 static int
c1c534
 qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
c1c534
                             const virDomainDef *def,
c1c534
@@ -3730,6 +3754,9 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
c1c534
         break;
c1c534
 
c1c534
     case VIR_DOMAIN_DEVICE_DISK:
c1c534
+        ret = qemuDomainDeviceDefValidateDisk(dev->data.disk);
c1c534
+        break;
c1c534
+
c1c534
     case VIR_DOMAIN_DEVICE_LEASE:
c1c534
     case VIR_DOMAIN_DEVICE_FS:
c1c534
     case VIR_DOMAIN_DEVICE_INPUT:
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-qcow.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-qcow.xml
c1c534
new file mode 100644
c1c534
index 0000000000..ca88a944b3
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-qcow.xml
c1c534
@@ -0,0 +1,28 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>QEMUGuest1</name>
c1c534
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c1c534
+  <memory unit='KiB'>219136</memory>
c1c534
+  <currentMemory unit='KiB'>219136</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='i686' machine='pc'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-i686</emulator>
c1c534
+    <disk type='block' device='disk'>
c1c534
+      <driver name='qemu' type='qcow2'/>
c1c534
+      <source dev='/dev/HostVG/QEMUGuest1'/>
c1c534
+      <target dev='hda' bus='ide'/>
c1c534
+      <shareable/>
c1c534
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c1c534
+    </disk>
c1c534
+    <controller type='usb' index='0'/>
c1c534
+    <controller type='ide' index='0'/>
c1c534
+    <memballoon model='virtio'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.args
c1c534
index 502157bf8c..326fde1b36 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.args
c1c534
@@ -19,7 +19,7 @@ server,nowait \
c1c534
 -no-acpi \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
--drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
c1c534
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0,\
c1c534
 serial=XYZXYZXYZYXXYZYZYXYZY,cache=none \
c1c534
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
c1c534
 -drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,media=cdrom,\
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.xml
c1c534
index 9f74723783..677c2b0b7d 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.xml
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared.xml
c1c534
@@ -15,7 +15,7 @@
c1c534
   <devices>
c1c534
     <emulator>/usr/bin/qemu-system-i686</emulator>
c1c534
     <disk type='block' device='disk'>
c1c534
-      <driver name='qemu' type='qcow2'/>
c1c534
+      <driver name='qemu' type='raw'/>
c1c534
       <source dev='/dev/HostVG/QEMUGuest1'/>
c1c534
       <target dev='hda' bus='ide'/>
c1c534
       <shareable/>
c1c534
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c1c534
index ff9c8608aa..00110cae19 100644
c1c534
--- a/tests/qemuxml2argvtest.c
c1c534
+++ b/tests/qemuxml2argvtest.c
c1c534
@@ -908,6 +908,7 @@ mymain(void)
c1c534
             QEMU_CAPS_DRIVE_BOOT);
c1c534
     DO_TEST("disk-drive-shared",
c1c534
             QEMU_CAPS_DRIVE_SERIAL);
c1c534
+    DO_TEST_PARSE_ERROR("disk-drive-shared-qcow", NONE);
c1c534
     DO_TEST("disk-drive-error-policy-stop",
c1c534
             QEMU_CAPS_MONITOR_JSON);
c1c534
     DO_TEST("disk-drive-error-policy-enospace",
c1c534
-- 
c1c534
2.15.0
c1c534