Proprely handle snapshot creation and reversion for 'dir' pool backed disks
Software environment
- Operating system: Fedora 40
- Architecture: x86-64
- kernel version: 6.8.7-300.fc40.x86_64
- libvirt version: 10.1.0-1.fc40.x86_64
- Hypervisor and version: qemu 8.2.2-1.fc40.x86_64
Description of problem
virsh snapshot-create-as
refuses to make external snapshots when a machine has a disk in a pool. The error message is quite indirect and suggests a fix (using --diskspec file=) that will indeed cause snapshot-create-as to successfully create a snapshot. However, that snapshot can not be deleted and not be reverted to.
Steps to reproduce
- Have a VM with a disk in a pool
# virsh list --all
Id Name State
-----------------------
- foo shut off
# virsh domblklist foo --details
Type Device Target Source
---------------------------------------------------------------
file disk vda /var/lib/libvirt/images/foo.qcow2
volume disk vdb volume
# virsh vol-dumpxml volume default
<volume type='file'>
<name>volume</name>
<key>/var/lib/libvirt/images/volume</key>
<capacity unit='bytes'>1073741824</capacity>
<allocation unit='bytes'>200704</allocation>
<physical unit='bytes'>196624</physical>
<target>
<path>/var/lib/libvirt/images/volume</path>
<format type='qcow2'/>
<permissions>
<mode>0600</mode>
<owner>0</owner>
<group>0</group>
<label>system_u:object_r:virt_image_t:s0</label>
</permissions>
<timestamps>
<atime>1715340923.079153581</atime>
<mtime>1715340923.053153410</mtime>
<ctime>1715340923.056153430</ctime>
<btime>0</btime>
</timestamps>
<clusterSize unit='B'>65536</clusterSize>
</target>
</volume>
- Try to take a external snapshot
# virsh snapshot-create-as foo snap --disk-only
error: unsupported configuration: cannot generate external snapshot name for disk 'vdb' without source
- Fine, add a source file.
# virsh snapshot-create-as foo snap --disk-only --diskspec vdb,file=/var/lib/libvirt/images/volume.snap
Domain snapshot snap created
- Try to delete the snapshot
# virsh snapshot-delete foo snap
error: Failed to delete snapshot snap
error: operation failed: snapshot VM disk source and parent disk source are not the same
- Try to revert to the snapshot
# virsh snapshot-revert foo snap
error: Failed to revert snapshot snap
error: unsupported configuration: cannot generate external snapshot name for disk 'vdb' without source
I think libvirt has to learn how to generate names when turning pool volumes into files. This seems to be required when reverting a snapshot (to create the overlay file that will be attached to the VM).
And doesn't the same issue exist for disks backed by block devices? The man page explicitly tells people to use --diskspec ...,file=...
to handle these, but during reversion, don't you run into the same problem of having to generate filenames for the new overlay?
Maybe the revert operation can use the snapshot disk sources as a template. In the example above, it would use /var/lib/libvirt/images/volume.snap
as the basis to create the /var/lib/libvirt/images/volume.327867514
name for the new overlay instead of looking at the volume and giving up.
Please don't add a --diskspec
parameter to virsh snapshot-revert ...
:-)
I have no idea what's going on with virsh snapshot-delete
, hopefully it is just a book keeping bug.