virt-clone: only attempt --reflink for raw images

--reflink only works with raw images, since copying anything else
will hit the qemu-img code path in libvirt storage driver.
This can pop up more nowadays since UEFI support is using qcow2 as
well.

Let's only attempt --reflink for raw disk images. It's basically
an optimization anyways

https://bugzilla.redhat.com/show_bug.cgi?id=2256285

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2024-11-15 14:11:36 -05:00 committed by Pavel Hrdina
parent a22ac0932e
commit 276aa4a72e
3 changed files with 9 additions and 6 deletions

View File

@ -127,9 +127,9 @@ storage options via -file.
``--reflink``
When --reflink is specified, perform a lightweight copy. This is much faster
if source images and destination images are all on the same btrfs filesystem.
If COW copy is not possible, then virt-clone fails.
Perform a lightweight copy. This is much faster if source images and destination
images are all on the same btrfs filesystem. This only works for raw format disk
images, any non-raw images will not attempt to use refink
``-m``, ``--mac`` MAC

View File

@ -1614,7 +1614,7 @@ c.add_invalid(_CLONE_UNMANAGED + " --auto-clone", grep="does not exist") # Auto
c = vclon.add_category("misc", "")
c.add_compare("--connect %(URI-KVM-X86)s -o test-clone --auto-clone", "clone-auto1")
c.add_compare("--connect %(URI-TEST-FULL)s -o test-clone-simple --name newvm --auto-clone", "clone-auto2")
c.add_compare("--connect %(URI-TEST-FULL)s -o test-clone-simple --name newvm --auto-clone --reflink", "clone-auto2")
c.add_compare("--connect %(URI-KVM-X86)s " + _CLONE_NVRAM + " --auto-clone", "clone-nvram") # hits a particular nvram code path
c.add_compare("--connect %(URI-KVM-X86)s " + _CLONE_NVRAM + " --auto-clone --nvram /nvram/my-custom-path", "clone-nvram-path") # hits a particular nvram code path
c.add_compare("--connect %(URI-KVM-X86)s " + _CLONE_NVRAM_NEWPOOL + " --auto-clone", "nvram-newpool") # hits a particular nvram code path

View File

@ -670,8 +670,11 @@ class StorageVolume(_StorageObject):
cloneflags |= libvirt.VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA
if self.reflink:
cloneflags |= getattr(libvirt,
"VIR_STORAGE_VOL_CREATE_REFLINK", 1)
if self.format != "raw":
log.warning("skipping reflink for non-raw vol=%s", self.name)
else:
cloneflags |= getattr(libvirt,
"VIR_STORAGE_VOL_CREATE_REFLINK", 1)
event = threading.Event()
meter = progress.ensure_meter(meter)