The default discard granularity is set to the logical block size or 4k by qemu, whichever is largest. The Optimal Unmap Granularity field in the block limits VPD page is impacted by it: Optimal Unmap Granularity = discard granularity / logical block size Signed-off-by: Lin Ma <lma@xxxxxxxx> --- src/qemu/qemu_command.c | 3 +++ tests/qemuxml2argvdata/disk-blockio.args | 2 +- tests/qemuxml2argvdata/disk-blockio.xml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f27246b4c6..43f3a4c2a3 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1849,6 +1849,9 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, if (disk->blockio.physical_block_size > 0) virBufferAsprintf(&opt, ",physical_block_size=%u", disk->blockio.physical_block_size); + if (disk->blockio.discard_granularity > 0) + virBufferAsprintf(&opt, ",discard_granularity=%u", + disk->blockio.discard_granularity); } if (disk->wwn) { diff --git a/tests/qemuxml2argvdata/disk-blockio.args b/tests/qemuxml2argvdata/disk-blockio.args index 72aa592fef..b02f833692 100644 --- a/tests/qemuxml2argvdata/disk-blockio.args +++ b/tests/qemuxml2argvdata/disk-blockio.args @@ -30,5 +30,5 @@ readonly=on \ -device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \ -drive file=/tmp/idedisk.img,format=raw,if=none,id=drive-ide0-0-2 \ -device ide-hd,bus=ide.0,unit=2,drive=drive-ide0-0-2,id=ide0-0-2,bootindex=1,\ -logical_block_size=512,physical_block_size=512 \ +logical_block_size=512,physical_block_size=512,discard_granularity=4096 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/disk-blockio.xml b/tests/qemuxml2argvdata/disk-blockio.xml index 1f78b38cb6..8ae53cdeb5 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'/> -- 2.26.0