<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 22, 2020 at 2:40 PM Peter Krempa <<a href="mailto:pkrempa@redhat.com">pkrempa@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Oct 22, 2020 at 10:57:05 +0800, Han Han wrote:<br>
> Hello,<br>
> I find "discard":"unmap" is defaultly enabled in  qemu cmdline(libvirt<br>
> v6.6, qemu v5.1):<br>
> XML:<br>
> <disk type="file" device="disk"><br>
>       <driver name="qemu" type="qcow2"/><br>
>       <source file="/var/lib/libvirt/images/new.qcow2" index="2"/><br>
>       <backingStore/><br>
>       <target dev="sda" bus="scsi"/><br>
>       <alias name="scsi0-0-0-0"/><br>
>       <address type="drive" controller="0" bus="0" target="0" unit="0"/><br>
<br>
[...]<br>
<br>
> QEMU cmdline:<br>
<br>
The -blockdev definition of storage splits up a storage into a protocol<br>
node, which handles storage access:<br>
<br>
In this case it's a 'file':<br>
<br>
> ... -blockdev<br>
> {"driver":"file","filename":"/var/lib/libvirt/images/new.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,<br>
> *"discard":"unmap"*}<br>
<br>
You can see, that 'discard: unmap' is enabled only here.<br>
<br>
<br>
The second layer is a 'format' node which handles the actual qcow2<br>
format:<br>
<br>
>-blockdev<br>
> {"node-name":"libvirt-2-format","read-only":false,"driver":"qcow2","file":"libvirt-2-storage","backing":null}<br>
<br>
Here you can see that there's no 'discard' setting, since you didn't<br>
configure any setting in the disk.<br>
<br>
Now the above configuration is used as we want to allow the QCOW2 driver<br>
to discard it's unused internal sectors/structures. This can happen for<br>
example when you delete an internal snapshot. All the unused sectors get<br>
unref'd and discarded. This wouldn't be possible without enabling unmap<br>
for the protocol node and the qcow2 image would not decrease size<br>
otherwise.<br>
<br>
The user setting is configured only for the 'format' node since it<br>
handles whether the guest discard gets honoured or not.<br>
<br>
The 'format' node is then installed as the disk backend:<br>
<br></blockquote><div>Thx <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> -device<br>
> scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-2-format,id=scsi0-0-0-0,bootindex=1<br>
<br>
[...]<br>
<br>
<br>
> I think it's from<br>
> <a href="https://gitlab.com/libvirt/libvirt/-/blob/master/src/qemu/qemu_block.c#L1211" rel="noreferrer" target="_blank">https://gitlab.com/libvirt/libvirt/-/blob/master/src/qemu/qemu_block.c#L1211</a><br>
> But I cannot find the reason from commit msgs or documents.<br>
> Could you please explain it?<br>
<br>
See above. I'm curious though why are you asking? You didn't mention<br>
that there's any problem with that.<br>
<br></blockquote><div>Yeah. No problems here. I was just a little surprised to find discard in qemu cmdline when no such configurations in libvirt domain XML.<br></div></div></div>