This commit adds building of `discard_granularity` disk option
for qemu commandline.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1849570
Signed-off-by: Kristina Hanicova <khanicov(a)redhat.com>
---
src/qemu/qemu_command.c | 2 +
.../disk-blockio.x86_64-latest.args | 2 +-
tests/qemuxml2argvdata/disk-blockio.xml | 2 +-
.../disk-blockio.x86_64-latest.xml | 48 +++++++++++++++++++
tests/qemuxml2xmltest.c | 1 +
5 files changed, 53 insertions(+), 2 deletions(-)
create mode 100644 tests/qemuxml2xmloutdata/disk-blockio.x86_64-latest.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6bcf2fdadd..b228820b5f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1760,6 +1760,7 @@ qemuBuildDiskDeviceProps(const virDomainDef *def,
unsigned int bootindex = 0;
unsigned int logical_block_size = disk->blockio.logical_block_size;
unsigned int physical_block_size = disk->blockio.physical_block_size;
+ unsigned int discard_granularity = disk->blockio.discard_granularity;
g_autoptr(virJSONValue) wwn = NULL;
g_autofree char *serial = NULL;
virTristateSwitch removable = VIR_TRISTATE_SWITCH_ABSENT;
@@ -1939,6 +1940,7 @@ qemuBuildDiskDeviceProps(const virDomainDef *def,
"p:bootindex", bootindex,
"p:logical_block_size", logical_block_size,
"p:physical_block_size", physical_block_size,
+ "p:discard_granularity", discard_granularity,
"A:wwn", &wwn,
"p:rotation_rate", disk->rotation_rate,
"S:vendor", disk->vendor,
diff --git a/tests/qemuxml2argvdata/disk-blockio.x86_64-latest.args
b/tests/qemuxml2argvdata/disk-blockio.x86_64-latest.args
index 7270613573..15f31ae60d 100644
--- a/tests/qemuxml2argvdata/disk-blockio.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-blockio.x86_64-latest.args
@@ -32,7 +32,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-device
'{"driver":"ide-cd","bus":"ide.0","unit":1,"drive":"libvirt-2-format","id":"ide0-0-1"}'
\
-blockdev
'{"driver":"file","filename":"/tmp/idedisk.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":"ide-hd","bus":"ide.0","unit":2,"drive":"libvirt-1-format","id":"ide0-0-2","bootindex":1,"logical_block_size":512,"physical_block_size":512}'
\
+-device
'{"driver":"ide-hd","bus":"ide.0","unit":2,"drive":"libvirt-1-format","id":"ide0-0-2","bootindex":1,"logical_block_size":512,"physical_block_size":512,"discard_granularity":4096}'
\
-audiodev
'{"id":"audio1","driver":"none"}' \
-device
'{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}'
\
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
diff --git a/tests/qemuxml2argvdata/disk-blockio.xml
b/tests/qemuxml2argvdata/disk-blockio.xml
index 170728371f..84943719d4 100644
--- a/tests/qemuxml2argvdata/disk-blockio.xml
+++ b/tests/qemuxml2argvdata/disk-blockio.xml
@@ -23,7 +23,7 @@
<source file='/tmp/idedisk.img'/>
<target dev='hdc' bus='ide'/>
<address type='drive' controller='0' bus='0'
target='0' unit='2'/>
- <blockio logical_block_size='512'
physical_block_size='512'/>
+ <blockio logical_block_size='512' physical_block_size='512'
discard_granularity='4096'/>
</disk>
<controller type='usb' index='0'/>
<controller type='ide' index='0'/>
diff --git a/tests/qemuxml2xmloutdata/disk-blockio.x86_64-latest.xml
b/tests/qemuxml2xmloutdata/disk-blockio.x86_64-latest.xml
new file mode 100644
index 0000000000..82ee552068
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/disk-blockio.x86_64-latest.xml
@@ -0,0 +1,48 @@
+<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='block' device='cdrom'>
+ <driver name='qemu' type='raw'/>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <readonly/>
+ <address type='drive' controller='0' bus='0'
target='0' unit='1'/>
+ </disk>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source file='/tmp/idedisk.img'/>
+ <blockio logical_block_size='512' physical_block_size='512'
discard_granularity='4096'/>
+ <target dev='hdc' bus='ide'/>
+ <address type='drive' controller='0' bus='0'
target='0' unit='2'/>
+ </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='0x02' function='0x0'/>
+ </memballoon>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 895e24d522..87bd6389a6 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -288,6 +288,7 @@ mymain(void)
DO_TEST_CAPS_LATEST("disk-floppy");
DO_TEST_CAPS_LATEST("disk-usb-device");
DO_TEST_CAPS_LATEST("disk-virtio");
+ DO_TEST_CAPS_LATEST("disk-blockio");
DO_TEST_CAPS_LATEST("floppy-drive-fat");
DO_TEST_CAPS_LATEST("disk-virtio-queues");
DO_TEST_CAPS_LATEST("disk-boot-disk");
--
2.41.0