The default max_unmap_size is set to 1GB by qemu. The Maximum unmap LBA count field in the block limits VPD page is impacted by it: Maximum unmap LBA count = max unmap size / logical block size Signed-off-by: Lin Ma <lma@xxxxxxxx> --- src/qemu/qemu_command.c | 10 ++++++ .../disk-scsi-disk-max_unmap_size.args | 32 +++++++++++++++++++ .../disk-scsi-disk-max_unmap_size.xml | 28 ++++++++++++++++ tests/qemuxml2argvtest.c | 4 +++ 4 files changed, 74 insertions(+) create mode 100644 tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.args create mode 100644 tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 43f3a4c2a3..78f856766e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1852,6 +1852,16 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, if (disk->blockio.discard_granularity > 0) virBufferAsprintf(&opt, ",discard_granularity=%u", disk->blockio.discard_granularity); + if (disk->blockio.max_unmap_size > 0) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_DISK_MAX_UNMAP_SIZE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("max_unmap_size property isn't supported by " + "this QEMU binary")); + return NULL; + } + virBufferAsprintf(&opt, ",max_unmap_size=%u", + disk->blockio.max_unmap_size); + } } if (disk->wwn) { diff --git a/tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.args b/tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.args new file mode 100644 index 0000000000..1d399ca451 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.args @@ -0,0 +1,32 @@ +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 QEMUGuest1 \ +-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,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x3 \ +-usb \ +-drive file=/var/lib/libvirt/images/guest.raw,format=raw,if=none,id=drive-scsi0-0-0-0 \ +-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,\ +id=scsi0-0-0-0,bootindex=1,max_unmap_size=1073741824 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4 diff --git a/tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.xml b/tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.xml new file mode 100644 index 0000000000..06c20e3431 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-scsi-disk-max_unmap_size.xml @@ -0,0 +1,28 @@ +<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'/> + <source file='/var/lib/libvirt/images/guest.raw'/> + <target dev='sda' bus='scsi'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + <blockio max_unmap_size='1073741824'/> + </disk> + <controller type='usb' index='0'/> + <controller type='scsi' index='0' model='virtio-scsi'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 02f8846e57..632dcd1ad8 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1262,6 +1262,10 @@ mymain(void) QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI); DO_TEST("disk-serial", QEMU_CAPS_KVM); + DO_TEST("disk-scsi-disk-max_unmap_size", + QEMU_CAPS_BLOCKIO, + QEMU_CAPS_VIRTIO_SCSI, + QEMU_CAPS_SCSI_DISK_MAX_UNMAP_SIZE); DO_TEST_PARSE_ERROR("disk-fdc-incompatible-address", NONE); DO_TEST_PARSE_ERROR("disk-ide-incompatible-address", -- 2.26.0