render / rpms / libvirt

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