render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c1c534
From 378887595f3cbb937f6c3e88ed3828e5f6698e33 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <378887595f3cbb937f6c3e88ed3828e5f6698e33@dist-git>
c1c534
From: Peter Krempa <pkrempa@redhat.com>
c1c534
Date: Thu, 23 Nov 2017 19:02:23 +0100
c1c534
Subject: [PATCH] qemu: command: Mark <shared/> disks as such in qemu
c1c534
c1c534
Qemu has now an internal mechanism for locking images to fix specific
c1c534
cases of disk corruption. This requires libvirt to mark the image as
c1c534
shared so that qemu lifts certain restrictions.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1378242
c1c534
(cherry picked from commit 28907b0043fbf71085a798372ab9c816ba043b93)
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_command.c                            |  4 +++
c1c534
 .../qemuxml2argv-disk-drive-shared-locking.args    | 32 +++++++++++++++++
c1c534
 .../qemuxml2argv-disk-drive-shared-locking.xml     | 42 ++++++++++++++++++++++
c1c534
 tests/qemuxml2argvtest.c                           |  2 ++
c1c534
 4 files changed, 80 insertions(+)
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.xml
c1c534
c1c534
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c1c534
index dfacff4b12..fc7f54e81e 100644
c1c534
--- a/src/qemu/qemu_command.c
c1c534
+++ b/src/qemu/qemu_command.c
c1c534
@@ -2182,6 +2182,10 @@ qemuBuildDriveDevStr(const virDomainDef *def,
c1c534
         goto error;
c1c534
     }
c1c534
 
c1c534
+    if (disk->src->shared &&
c1c534
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_DISK_SHARE_RW))
c1c534
+        virBufferAddLit(&opt, ",share-rw=on");
c1c534
+
c1c534
     if (!(drivealias = qemuAliasFromDisk(disk)))
c1c534
         goto error;
c1c534
     virBufferAsprintf(&opt, ",drive=%s,id=%s", drivealias, disk->info.alias);
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.args
c1c534
new file mode 100644
c1c534
index 0000000000..cdf17f26d1
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.args
c1c534
@@ -0,0 +1,32 @@
c1c534
+LC_ALL=C \
c1c534
+PATH=/bin \
c1c534
+HOME=/home/test \
c1c534
+USER=test \
c1c534
+LOGNAME=test \
c1c534
+QEMU_AUDIO_DRV=none \
c1c534
+/usr/bin/qemu-system-i686 \
c1c534
+-name QEMUGuest1 \
c1c534
+-S \
c1c534
+-M pc \
c1c534
+-m 214 \
c1c534
+-smp 1,sockets=1,cores=1,threads=1 \
c1c534
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
c1c534
+-nographic \
c1c534
+-nodefaults \
c1c534
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
c1c534
+server,nowait \
c1c534
+-mon chardev=charmonitor,id=monitor,mode=readline \
c1c534
+-no-acpi \
c1c534
+-boot c \
c1c534
+-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3 \
c1c534
+-usb \
c1c534
+-drive file=/dev/ide,format=raw,if=none,id=drive-ide0-0-0,cache=none \
c1c534
+-device ide-drive,bus=ide.0,unit=0,share-rw=on,drive=drive-ide0-0-0,\
c1c534
+id=ide0-0-0 \
c1c534
+-drive file=/dev/scsi,format=raw,if=none,id=drive-scsi0-0-0-0,cache=none \
c1c534
+-device scsi-disk,bus=scsi0.0,channel=0,scsi-id=0,lun=0,share-rw=on,\
c1c534
+drive=drive-scsi0-0-0-0,id=scsi0-0-0-0 \
c1c534
+-drive file=/dev/virtio,format=raw,if=none,id=drive-virtio-disk0,cache=none \
c1c534
+-device virtio-blk-pci,bus=pci.0,addr=0x4,share-rw=on,drive=drive-virtio-disk0,\
c1c534
+id=virtio-disk0 \
c1c534
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.xml
c1c534
new file mode 100644
c1c534
index 0000000000..dd48857a30
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-shared-locking.xml
c1c534
@@ -0,0 +1,42 @@
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='raw'/>
c1c534
+      <source dev='/dev/ide'/>
c1c534
+      <target dev='hda' bus='ide'/>
c1c534
+      <shareable/>
c1c534
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c1c534
+    </disk>
c1c534
+    <disk type='block' device='disk'>
c1c534
+      <driver name='qemu' type='raw'/>
c1c534
+      <source dev='/dev/scsi'/>
c1c534
+      <target dev='sda' bus='scsi'/>
c1c534
+      <shareable/>
c1c534
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c1c534
+    </disk>
c1c534
+    <disk type='block' device='disk'>
c1c534
+      <driver name='qemu' type='raw'/>
c1c534
+      <source dev='/dev/virtio'/>
c1c534
+      <target dev='vda' bus='virtio'/>
c1c534
+      <shareable/>
c1c534
+    </disk>
c1c534
+    <controller type='usb' index='0'/>
c1c534
+    <controller type='ide' index='0'/>
c1c534
+    <controller type='scsi' index='0' model='virtio-scsi'/>
c1c534
+    <memballoon model='virtio'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c1c534
index 00110cae19..4e981c9fab 100644
c1c534
--- a/tests/qemuxml2argvtest.c
c1c534
+++ b/tests/qemuxml2argvtest.c
c1c534
@@ -909,6 +909,8 @@ mymain(void)
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-shared-locking",
c1c534
+            QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_DISK_SHARE_RW);
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