From: Ciro Iriarte <cyruspy@gmail.com>
To: pve-devel@lists.proxmox.com
Subject: [RFC PATCH storage/qemu-server/docs v2 0/6] offload full clone to the storage backend
Date: Thu, 26 Nov 2026 13:56:55 -0300 [thread overview]
Message-ID: <20261126.0.copyoffload-v2@cyruspy.gmail.com> (raw)
This series lets a storage plugin perform a full copy on its backend
instead of having the host read and write every byte with qemu-img or
drive-mirror. The consumer is full clone (bug #7780). v1 is at
https://lore.proxmox.com/pve-devel/20260720.0.copyoffload@cyruspy.gmail.com/
Recap
-----
A plugin advertises one of two features, copy-offload-atomic (the copy
captures a single point in time) or copy-offload-bulk (it does not), and
implements four methods:
copy_image_check() can this volume go to that target storage?
copy_image_prepare() reserve the target name, under the storage lock
copy_image_start() capture the instant; may run in a guest freeze
copy_image_status() poll until the copy is independent of its source
The split exists because a backend copy can run for hours while the
storage lock is a pmxcfs lock with a 60 second limit, and because only a
cheap call can run while a guest is frozen. 'complete' means
independent, not just readable: an RBD clone reads fine before it is
flattened, but deleting the source would destroy it.
For a running guest, qemu-server reserves every offloaded target first
and starts the copies inside the same freeze that cuts the mirrored
disks over, so all disks of the clone are captured at the same instant.
copy_images_start() passes a VM's starts to the plugin as one batch per
source/target storage pair, for backends that can capture several
volumes together.
Offload is off by default, enabled per target storage with the
copy-offload option, and only works between two storages of the same
type. The series implements it for rbd, dir (reflink), btrfs and
lvmthin.
Changes since v1
----------------
Mostly fixes from re-reviewing v1 after the rebase onto storage API 17.
Each patch lists its own changes; the main ones:
* API 17 changed parse_volname() to return 'vm-vol' instead of 'images'.
The dir, btrfs and lvmthin code compared against 'images', so after
the rebase, dir never advertised offload and btrfs and lvmthin refused
every volume in prepare. They now use vtype_matches(), and a new test
goes through the real parse_volname().
* New copy_image_check(). In v1, a pair the backend could not copy (a
different thin pool, another filesystem, a filesystem without reflink,
different Ceph monitors) made prepare die and the clone fail. The core
now checks first and falls back to the host-side copy, logging the
reason.
* qemu-server no longer uses a goto, which master had just removed.
Deferred copies record the source size in the config instead of the
placeholder's. Cutting over a final cloud-init drive starts them too,
whereas v1 froze the guest a second time. A copy from a snapshot is
not deferred. A failed guest agent freeze falls back to suspending the
guest; if that fails too, the mirrors are still cut over, as on
master, but the deferred copies are not started and the clone fails,
because their targets are only reservations. A guest that is already
paused stays paused, and a failed thaw or resume ends the task with a
warning (log_warn) instead of a plain message.
* rbd: the 'ceph rbd task' calls use the storage's connection options
and namespace, free_image() cancels a running flatten, and values read
back from rbd are untainted for pvedaemon's -T. The check falls back
when the target is on another Ceph cluster (same monhost, or else same
fsid), when the two storages use different Ceph users, and when the
user is not allowed to add manager tasks, which the flatten needs.
Each command in start has a 30 second timeout, so a hung cluster fails
the start within a bounded time instead of holding the guest frozen
indefinitely. The flatten status fix sent after v1 is folded in.
* A failed copy's target is freed in one place only. v1 freed it in
vdisk_copy_wait() and again in the caller's rollback, which could
remove a volume another task had allocated under the same name in
between. dir now keeps the name reserved after a failed start, and
btrfs free_image() removes a parked placeholder.
* The docs patch, sent separately, is now 6/6.
APIVER goes 17 -> 18 and APIAGE 8 -> 9. The base plugin declares
'copy-offload' and 'copy-offload-timeout', so under the v17 rules they
become common properties. That fits the criterion as I read it, since
core code reads them from any storage type, but it means a third-party
plugin declaring either name would stop loading. I found none.
No range-diff: the rebase onto API 17 and the clone_disk() restructuring
make it longer than the patches themselves.
qemu-server 5/6 needs a libpve-storage-perl that ships APIVER 18 (1/6);
I left the debian/control bump to you. The patches apply in order:
storage, then qemu-server, then docs.
Not covered: the edit dialogs of the in-tree storages in pve-manager are
hand-written, so copy-offload can only be set with pvesm or the API for
now. The clone bandwidth limit does not apply to an offloaded copy,
since the data does not pass through the host; the docs say so.
Open questions
--------------
1. move_disk. It already goes through clone_disk(), so moving a disk of
a stopped guest, or a detached disk, is offloaded. Moving an attached
disk of a running guest would need the bulk path, since the source
changes during the copy. Same series or later?
2. prepare() returns a volname, and a failed copy's rollback frees that
volname. The caller drops the lock between prepare and start, so each
backend has to keep the name reserved itself (btrfs swaps with
renameat2(RENAME_EXCHANGE), rbd and lvmthin park under a prefix the
lister ignores but the allocator counts). An opaque token that the
rollback verifies would move that guarantee into the core. Is that
worth an interface change now?
3. copy_offload_class() tries atomic before bulk and stops at the first
refusal. copy_image_check() does not get the class, so falling
through to bulk would require passing it in. No plugin here
advertises both; is that worth doing now?
4. run_with_guest_quiesced() changes what every full clone of a running
guest does, offloaded or not, compared with master's monitor(): a
failed guest agent freeze falls back to suspending the guest instead
of continuing unquiesced; a guest that was already paused is no
longer resumed afterwards; and a failed thaw or resume is reported
with log_warn(), so the task ends with a warning. I chose a warning
over failing the task because failing it deletes a finished clone,
and on Windows the agent's freeze is limited to about ten seconds,
after which the thaw itself reports an error; in that case the disks
may not be captured at the same instant, and the warning is the only
sign of it. Are these acceptable for all clones, or should they be
limited to clones with deferred copies?
5. copy_image_start() runs while the guest is frozen. The plugin
contract asks it to put a timeout on calls that can block on a remote
backend; rbd does, per command, while dir, btrfs and lvmthin run
local reflink, snapshot and LVM operations without one (a reflink of
a heavily fragmented file on XFS can take seconds). The core sets no
overall deadline. Given the ten second freeze limit on Windows,
should it?
6. Only the target storage's copy-offload option is consulted, as the
new volume lands there. Should the source storage be able to refuse
as well?
rbd requests clone format 2 explicitly. It worked on the test cluster,
whose require-min-compat-client is luminous; a cluster older than Mimic
was not tested.
Testing
-------
On a PVE 9.3 node (libpve-storage-perl 9.1.26, qemu-server 9.2.24,
matching the bases of this series):
* pve-storage 'make check', minus the four targets that create real
devices: all 24 targets pass, as on master. run_plugin_tests.pl runs
902 tests, all pass.
* copy_offload_functional_test.pl as root, on a loop-backed btrfs and
thin pool: 22/22. Without the vtype_matches() change it fails at the
first prepare.
* qemu-server 'make test' passes, including the new
run_guest_quiesce_tests.pl.
* Full clones of running VMs onto Ceph RBD (Tentacle, erasure coded
pool), with the patched code loaded for the qm process only: an
offloaded disk plus a mirrored one plus a final cloud-init drive; a
mirrored disk followed by an offloaded one; two offloaded disks; and
an offloaded disk of a paused guest, which stayed paused. The guests
had no agent, so this used the suspend path. In every case the RBD
snapshot was taken while the guest was quiesced, each clone was
byte-identical to its source and had no parent, the config recorded
the right size, and no snapshot was left on the source.
Not repeated from v1: the reflink runs on XFS and ZFS, and the guest
agent freeze path. The dir, btrfs and lvmthin paths were exercised by
the functional test, not through a live clone.
Ciro Iriarte (6):
storage: add asynchronous copy-offload hook for full copies
rbd: implement copy-offload via snapshot + clone + flatten
dir: implement copy-offload via reflink (FICLONE)
btrfs, lvmthin: implement copy-offload (atomic class)
use storage copy-offload for full clone
pvesm: document copy-offload and add it to the storage capability table
storage:
ApiChangeLog | 38 ++
src/PVE/Storage.pm | 268 ++++++++++-
src/PVE/Storage/BTRFSPlugin.pm | 267 +++++++++++
src/PVE/Storage/DirPlugin.pm | 193 ++++++++
src/PVE/Storage/LvmThinPlugin.pm | 202 ++++++++-
src/PVE/Storage/Plugin.pm | 180 ++++++++
src/PVE/Storage/RBDPlugin.pm | 551 ++++++++++++++++++++++-
src/test/copy_offload_check_test.pm | 208 +++++++++
src/test/copy_offload_feature_test.pm | 99 ++++
src/test/copy_offload_functional_test.pl | 296 ++++++++++++
src/test/copy_offload_naming_test.pm | 82 ++++
src/test/copy_offload_rbd_status_test.pm | 114 +++++
src/test/copy_offload_test.pm | 90 ++++
src/test/plugin_properties_test.pm | 5 +-
src/test/run_plugin_tests.pl | 5 +
15 files changed, 2588 insertions(+), 10 deletions(-)
qemu-server:
src/PVE/API2/Qemu.pm | 17 +++
src/PVE/QemuServer.pm | 225 ++++++++++++++++++++++++++--
src/PVE/QemuServer/BlockJob.pm | 119 +++++++++++----
src/test/Makefile | 5 +-
src/test/run_guest_quiesce_tests.pl | 154 +++++++++++++++++++
5 files changed, 479 insertions(+), 41 deletions(-)
docs:
pvesm.adoc | 79 ++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 62 insertions(+), 17 deletions(-)
--
Ciro Iriarte
next reply other threads:[~2026-11-26 16:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 16:56 Ciro Iriarte [this message]
2026-11-26 16:56 ` [RFC PATCH storage v2 1/6] storage: add asynchronous copy-offload hook for full copies Ciro Iriarte
2026-11-26 16:56 ` [RFC PATCH storage v2 2/6] rbd: implement copy-offload via snapshot + clone + flatten Ciro Iriarte
2026-11-26 16:57 ` [RFC PATCH storage v2 3/6] dir: implement copy-offload via reflink (FICLONE) Ciro Iriarte
2026-11-26 16:57 ` [RFC PATCH storage v2 4/6] btrfs, lvmthin: implement copy-offload (atomic class) Ciro Iriarte
2026-11-26 16:57 ` [RFC PATCH qemu-server v2 5/6] use storage copy-offload for full clone Ciro Iriarte
2026-11-26 16:57 ` [RFC PATCH docs v2 6/6] pvesm: document copy-offload and add it to the storage capability table Ciro Iriarte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126.0.copyoffload-v2@cyruspy.gmail.com \
--to=cyruspy@gmail.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.