[PATCH Libvirt v2 2/3] qemu_command: Generate cmd line for discard and write-zeroes properties

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hyman Huang(黄勇) <yong.huang@xxxxxxxxxx>

Generate cmd line for virtio-blk.discard and virtio-blk.write-zeroes
properties. Also, validate that the requested feature is supported by QEMU.

Signed-off-by: Hyman Huang(黄勇) <yong.huang@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                       |  2 +
 src/qemu/qemu_validate.c                      |  9 +++
 .../disk-virtio-discard.x86_64-latest.args    | 45 ++++++++++++++
 .../qemuxml2argvdata/disk-virtio-discard.xml  | 45 ++++++++++++++
 tests/qemuxml2argvtest.c                      |  1 +
 .../disk-virtio-discard.x86_64-latest.xml     | 58 +++++++++++++++++++
 tests/qemuxml2xmltest.c                       |  1 +
 7 files changed, 161 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/disk-virtio-discard.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-virtio-discard.xml
 create mode 100644 tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-latest.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ad224571f3..6954fc5d75 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1834,6 +1834,8 @@ qemuBuildDiskDeviceProps(const virDomainDef *def,
                                   "T:scsi", scsi,
                                   "p:num-queues", disk->queues,
                                   "p:queue-size", disk->queue_size,
+                                  "T:discard", disk->virtio_discard,
+                                  "T:write-zeroes", disk->virtio_write_zeroes,
                                   NULL) < 0)
             return NULL;
     }
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 7e09e2c52f..499b49ce74 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2949,6 +2949,15 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
         }
     }
 
+    if (disk->virtio_discard || disk->virtio_write_zeroes) {
+        if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("virtio_discard and virtio_write_zeroes options are "
+                             "only valid for VIRTIO bus"));
+            return -1;
+        }
+    }
+
     switch (disk->bus) {
     case VIR_DOMAIN_DISK_BUS_SCSI:
         if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
diff --git a/tests/qemuxml2argvdata/disk-virtio-discard.x86_64-latest.args b/tests/qemuxml2argvdata/disk-virtio-discard.x86_64-latest.args
new file mode 100644
index 0000000000..ee7a7edc9c
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-virtio-discard.x86_64-latest.args
@@ -0,0 +1,45 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \
+-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=off \
+-accel tcg \
+-cpu qemu64 \
+-m size=219136k \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
+-blockdev '{"driver":"file","filename":"/tmp/data.img","node-name":"libvirt-4-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"raw","file":"libvirt-4-storage"}' \
+-device '{"driver":"virtio-blk-pci","discard":true,"write-zeroes":true,"bus":"pci.0","addr":"0x2","drive":"libvirt-4-format","id":"virtio-disk0","bootindex":1}' \
+-blockdev '{"driver":"file","filename":"/tmp/data1.img","node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"raw","file":"libvirt-3-storage"}' \
+-device '{"driver":"virtio-blk-pci","discard":true,"write-zeroes":false,"bus":"pci.0","addr":"0x3","drive":"libvirt-3-format","id":"virtio-disk1"}' \
+-blockdev '{"driver":"file","filename":"/tmp/data2.img","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw","file":"libvirt-2-storage"}' \
+-device '{"driver":"virtio-blk-pci","discard":false,"write-zeroes":true,"bus":"pci.0","addr":"0x4","drive":"libvirt-2-format","id":"virtio-disk2"}' \
+-blockdev '{"driver":"file","filename":"/tmp/data3.img","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
+-device '{"driver":"virtio-blk-pci","discard":false,"write-zeroes":false,"bus":"pci.0","addr":"0x5","drive":"libvirt-1-format","id":"virtio-disk3"}' \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x6"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/disk-virtio-discard.xml b/tests/qemuxml2argvdata/disk-virtio-discard.xml
new file mode 100644
index 0000000000..cd6ec6a51d
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-virtio-discard.xml
@@ -0,0 +1,45 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='on' virtio_write_zeroes='on'/>
+      <source file='/tmp/data.img'/>
+      <target dev='vda' bus='virtio'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='on' virtio_write_zeroes='off'/>
+      <source file='/tmp/data1.img'/>
+      <target dev='vdb' bus='virtio'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='off' virtio_write_zeroes='on'/>
+      <source file='/tmp/data2.img'/>
+      <target dev='vdc' bus='virtio'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='off' virtio_write_zeroes='off'/>
+      <source file='/tmp/data3.img'/>
+      <target dev='vdd' bus='virtio'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <audio id='1' type='none'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 534eb9e699..9c7ff63ff1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1420,6 +1420,7 @@ mymain(void)
     DO_TEST_CAPS_LATEST("net-vdpa");
     DO_TEST_CAPS_LATEST("net-vdpa-multiqueue");
     DO_TEST_CAPS_LATEST("net-virtio-rss");
+    DO_TEST_CAPS_LATEST("disk-virtio-discard");
 
     DO_TEST("hostdev-pci-multifunction",
             QEMU_CAPS_KVM,
diff --git a/tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-latest.xml
new file mode 100644
index 0000000000..9895fe13fb
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-latest.xml
@@ -0,0 +1,58 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <cpu mode='custom' match='exact' check='none'>
+    <model fallback='forbid'>qemu64</model>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='on' virtio_write_zeroes='on'/>
+      <source file='/tmp/data.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='on' virtio_write_zeroes='off'/>
+      <source file='/tmp/data1.img'/>
+      <target dev='vdb' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='off' virtio_write_zeroes='on'/>
+      <source file='/tmp/data2.img'/>
+      <target dev='vdc' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' virtio_discard='off' virtio_write_zeroes='off'/>
+      <source file='/tmp/data3.img'/>
+      <target dev='vdd' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+    </disk>
+    <controller type='usb' index='0' model='piix3-uhci'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <audio id='1' type='none'/>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index b66274beb8..aa29b89466 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -600,6 +600,7 @@ mymain(void)
     DO_TEST_CAPS_LATEST("disk-discard");
     DO_TEST_CAPS_LATEST("disk-detect-zeroes");
     DO_TEST_CAPS_LATEST("disk-discard_no_unref");
+    DO_TEST_CAPS_LATEST("disk-virtio-discard");
 
     DO_TEST_NOCAPS("disk-serial");
 
-- 
2.38.5





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux