From: yuxiating <yuxiating@xxxxxxxxxx> This patch introduces a new attribute "discard". An example of the XML: <disk type='file' device='disk'> <driver name='qemu' type='qcow2' discard_enable='4'/> The corresponding QEMU command line: -device virtio-blk-pci,scsi=off,discard=off,id=virtio-disk0 Signed-off-by: yuxiating <yuxiating@xxxxxxxxxx> --- src/qemu/qemu_command.c | 5 +++ .../qemuxml2argvdata/disk-virtio-discard.args | 29 +++++++++++++++ .../qemuxml2argvdata/disk-virtio-discard.xml | 35 +++++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ 4 files changed, 71 insertions(+) create mode 100644 tests/qemuxml2argvdata/disk-virtio-discard.args create mode 100644 tests/qemuxml2argvdata/disk-virtio-discard.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b230314f7f..cf5a4ca7cf 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1739,6 +1739,11 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, virBufferAsprintf(&opt, ",num-queues=%u", disk->queues); } + if (disk->discard_enable) { + virBufferAsprintf(&opt, ",discard=%s", + virTristateSwitchTypeToString(disk->discard_enable)); + } + qemuBuildVirtioOptionsStr(&opt, disk->virtio); if (qemuBuildDeviceAddressStr(&opt, def, &disk->info) < 0) diff --git a/tests/qemuxml2argvdata/disk-virtio-discard.args b/tests/qemuxml2argvdata/disk-virtio-discard.args new file mode 100644 index 0000000000..0e952ca81a --- /dev/null +++ b/tests/qemuxml2argvdata/disk-virtio-discard.args @@ -0,0 +1,29 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-m 214 \ +-realtime mlock=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,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-drive file=/tmp/data.img,format=raw,if=none,id=drive-virtio-disk0 \ +-device virtio-blk-pci,discard=off,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \ +-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..37450f0bfc --- /dev/null +++ b/tests/qemuxml2argvdata/disk-virtio-discard.xml @@ -0,0 +1,35 @@ +<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='i686' 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-i386</emulator> + <disk type='file' device='disk'> + <driver name='qemu' type='raw' discard_enable='off'/> + <source file='/tmp/data.img'/> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </disk> + <controller type='usb' index='0'> + <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='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 3b331d5fd4..4375b06d40 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1341,6 +1341,8 @@ mymain(void) DO_TEST("disk-order", QEMU_CAPS_VIRTIO_BLK_SCSI); DO_TEST("disk-virtio-queues", QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES); + DO_TEST("disk-virtio-discard", + QEMU_CAPS_DEVICE_DISCARD); DO_TEST_NOCAPS("disk-boot-disk"); DO_TEST_NOCAPS("disk-boot-cdrom"); DO_TEST_NOCAPS("floppy-drive-fat"); -- 2.27.0