Repository navigation
Linstor add support for incremental nasbackup - #14194
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14194 +/- ##
============================================
+ Coverage 18.01% 18.13% +0.11%
- Complexity 16265 16412 +147
============================================
Files 5936 5937 +1
Lines 536395 537271 +876
Branches 65701 65857 +156
============================================
+ Hits 96658 97419 +761
- Misses 428710 428742 +32
- Partials 11027 11110 +83
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@rp- are the changes here relavant for 4.22 branch? if so, please re-target to 4.22. |
thanks, missed the wrong base branch |
|
@blueorangutan package |
|
@rp- a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 19402 |
|
@blueorangutan package |
|
@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19405 |
|
@blueorangutan test |
|
@weizhouapache a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
Also pinging for this here @sureshanaparti to be included in 4.22.2 |
|
[SF] Trillian test result (tid-17075)
|
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
1 similar comment
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
The RBD path overloaded ChainDecision.mode with rbd-full and rbd-incremental, the same way the content-based path upstream overloaded it with content-full and content-incremental. Split the two concerns as that path already did: mode stays full or incremental, and a new method field says how the backup is taken -- qcow2 (push mode with dirty bitmaps) or rbd (Ceph-native, anchored on an rbd snapshot and exported with rbd export-diff). TakeBackupCommand gets a method field and nasbackup.sh a --method option. Both default to qcow2 when absent, so a management server that does not send a method keeps working against an upgraded agent. legacy-full is unchanged: rewriting it as full plus a "none" method would break incremental-disabled backups on agents that have not been upgraded yet. CHAIN_FORMAT stays as it is. The method says how a backup is taken and lives only for the duration of the request; the chain format is persisted and says what is on the repository, which is what restore and delete read later. The two coincide for the rbd method today but answer different questions. This mirrors c144d09 from apache#14194, which introduced the method for the content path and named an RBD diff as the next one to adopt it. Kept as close to that commit as the branch allows so the two merge cleanly: this branch carries the RBD path but not the content one, so the METHOD_CONTENT token is defined without a user here.
The RBD path overloaded ChainDecision.mode with rbd-full and rbd-incremental, the same way the content-based path upstream overloaded it with content-full and content-incremental. Split the two concerns as that path already did: mode stays full or incremental, and a new method field says how the backup is taken -- qcow2 (push mode with dirty bitmaps) or rbd (Ceph-native, anchored on an rbd snapshot and exported with rbd export-diff). TakeBackupCommand gets a method field and nasbackup.sh a --method option. Both default to qcow2 when absent, so a management server that does not send a method keeps working against an upgraded agent. legacy-full is unchanged: rewriting it as full plus a "none" method would break incremental-disabled backups on agents that have not been upgraded yet. CHAIN_FORMAT stays as it is. The method says how a backup is taken and lives only for the duration of the request; the chain format is persisted and says what is on the repository, which is what restore and delete read later. The two coincide for the rbd method today but answer different questions. This mirrors c144d09 from apache#14194, which introduced the method for the content path and named an RBD diff as the next one to adopt it. Kept as close to that commit as the branch allows so the two merge cleanly: this branch carries the RBD path but not the content one, so the METHOD_CONTENT token is defined without a user here.
The RBD path overloaded ChainDecision.mode with rbd-full and rbd-incremental, the same way the content-based path upstream overloaded it with content-full and content-incremental. Split the two concerns as that path already did: mode stays full or incremental, and a new method field says how the backup is taken -- qcow2 (push mode with dirty bitmaps) or rbd (Ceph-native, anchored on an rbd snapshot and exported with rbd export-diff). TakeBackupCommand gets a method field and nasbackup.sh a --method option. Both default to qcow2 when absent, so a management server that does not send a method keeps working against an upgraded agent. legacy-full is unchanged: rewriting it as full plus a "none" method would break incremental-disabled backups on agents that have not been upgraded yet. CHAIN_FORMAT stays as it is. The method says how a backup is taken and lives only for the duration of the request; the chain format is persisted and says what is on the repository, which is what restore and delete read later. The two coincide for the rbd method today but answer different questions. This mirrors c144d09 from apache#14194, which introduced the method for the content path and named an RBD diff as the next one to adopt it. Kept as close to that commit as the branch allows so the two merge cleanly: this branch carries the RBD path but not the content one, so the METHOD_CONTENT token is defined without a user here.
|
@abh1sar |
abh1sar
left a comment
There was a problem hiding this comment.
I have pointed some performance concerns
I am ok with the PR being merged as it is now since the feature is opt-in, but the issues should be contemplated and addressed in a follow up PR or mentioned clearly in documentation.
Test results
|
…e agent log backup_stopped_vm redirected qemu-img convert's stdout with ">" into $logFile, which is the agent's own agent.log, so every backup of a stopped VM truncated the agent log, taking along whatever the agent had logged about the backup until then. Append instead, as every other qemu-img call in the script already does. When the convert failed, the script ran cleanup -- removing the backup directory and unmounting the share -- but then carried on with the next disk. Its convert and the second cleanup failed in turn, so the backup ended with "Backup cleanup failed" (exit 20) and was left in Error state although nothing needed cleaning up. Exit after the cleanup, as the other failure paths do.
createPhysicalDisk and connectPhysicalDisk return as soon as LINSTOR has made the resource available on this node, but udev creates its /dev/drbd/by-res link a little later. A caller that opens the device right away fails with "Could not open '/dev/drbd/by-res/cs-<uuid>/0': No such file or directory". Restoring a backup onto LINSTOR runs qemu-img convert onto the volume immediately: creating an instance from a backup hit this on every new volume, an in-place restore whenever the host had no replica of the volume. Look up the resource's device on this node after making it available and wait up to 10 seconds for it to appear.
A stopped VM is backed up by qemu-img convert straight from its volume devices, on the VM's last host. A LINSTOR volume only has a device on hosts that hold a resource of it, and when the VM stops CloudStack removes the diskless resource it ran on. Unless that host also holds a replica, the convert fails with "Could not open '/dev/drbd/by-res/cs-<uuid>/0': No such file or directory" -- on a hyperconverged setup sometimes, on one with separate compute and storage nodes always. Before running the script, make every LINSTOR volume whose device does not exist on this host available -- connecting returns once its device exists -- and disconnect it again once the backup is done, failed or not. Volumes that already have a device -- those of a running VM, or ones this host holds a replica of -- are left alone, so a running VM's disks are never touched.
Copy-before-write kept the guest data a pull-mode backup had not read yet in fleecing files under a host-local directory (/var/tmp by default). Their growth is bounded only by the guest's writes during the backup, so the script refused to start unless that filesystem had a configurable share of the VM's disk size free; if it filled up anyway the guest's writes failed and QEMU paused the VM. Concurrent backups shared the same filesystem unchecked. Instead, the agent now creates one LINSTOR resource per backup, with one volume per disk, sized for the whole disk plus qcow2 metadata, and passes the devices to nasbackup.sh with --scratch-devs. libvirt formats them as the block scratch of each disk (<scratch dev=.../>), so a scratch device can no longer fill up. The agent deletes the resource once the backup has ended. - The resource definition is created in the pool's resource group, so the group's properties and storage pool selection apply. It is placed on a storage pool of the VM's host as a plain STORAGE resource if there is one; otherwise, e.g. on a compute node without storage, it is a single DRBD replica elsewhere that the host attaches diskless. - KVMStoragePool gets createBackupScratch()/deleteBackupScratch(); pools that cannot provide scratch space fail the pull-mode backup. There is no fallback to host-local files. - The management server now also sends the volume pools for content-method backups of running VMs, so the agent knows where to take the scratch from. - A resource left behind by a crashed agent has to be deleted manually; its Aux/cs-backup-vm property names the VM. The agent.properties options nas.backup.pull.scratch.dir and nas.backup.pull.scratch.min.free.percent, the free-space check and the -S and --scratch-min-free-percent script options are removed. The NBD socket and the backup XML stay in a small work directory under /var/tmp.
The agent deletes the LINSTOR scratch resource of a pull-mode backup once the backup has ended, also when the backup fails or the agent is stopped normally. If the agent dies or the host goes down during the backup, the resource stays behind and keeps its storage allocated. When the agent registers the first pool of a LINSTOR controller, delete every cs-bkscratch-* resource definition that has a resource on this node: a scratch always has one on the node whose agent created it, diskless if its data lives elsewhere. Pools are registered again on every reconnect to the management server, while backups may still be running, so this happens only once per controller and agent process, before any backup can use the pool. Failures are only logged and never keep the pool from being registered. After a hard crash the VM's pull-mode backup job can outlive the agent and still hold the scratch devices, so LINSTOR refuses the delete. The warning then says to end the job with virsh domjobabort and delete the resource definition manually.
abh1sar
left a comment
There was a problem hiding this comment.
LGTM. reviewed and tested
|
@blueorangutan package |
|
@abh1sar a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✖️ suse15. SL-JID 19641 |
|
@blueorangutan test |
|
@abh1sar a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-17196)
|
|
Awesome work, congrats on your first merged pull request! |
|
Merged based on the reviews and test results. |
* test: support Ceph/RBD primary storage in NAS backup smoke test test_backup_recovery_nas.py only allowed NFS primary storage, since it reused the primary storage pool's own path as the NAS backup repository address, and always required incremental-backup semantics that only qcow2/NFS storage can provide. Neither holds on Ceph/RBD. - setUpClass now accepts RBD alongside NFS as the primary storage pool type, picking a pool that's actually Up rather than list()[0] -- environments that added Ceph/RBD after the zone's original NFS primary storage keep that old pool around in Disabled state, and it still sorts first, silently exercising its path as if it were the storage VMs actually deploy on. - The NAS backup repository's NFS export address is resolved independently of the primary storage: when the primary pool isn't NFS, reuse the nfs test data entry (services[nfs][url]) -- the same temporary NFS mount point test_primary_storage.py uses for its temporary NFS primary storage pool, and something every marvin environment already has configured. An explicit nas_backup_repository_address test data entry or NAS_BACKUP_REPO_ADDRESS environment variable, if set, takes precedence. - The external offering imported in setUpClass is matched to the repository just created by externalid (== the repository's own id for the nas provider) rather than blindly taking index 0 -- a stray repository left over from an earlier interrupted run, whose backups didn't get cleaned up so its own teardown couldn't remove it either, sorts alongside the new one with no guarantee of which comes first. - Incremental NAS backups require QEMU dirty bitmaps / libvirt checkpoints, which only exist on file-based qcow2 storage (NASBackupProvider.allVolumesOnCheckpointCapableStorage). The six incremental-chain tests now skip on RBD/Ceph, where the provider always falls back to full-only backups server-side, rather than failing on assertions that storage type can never satisfy. - Added test_restore_volume_and_attach_to_vm, which exercises restoreVolumeFromBackupAndAttachToVM end-to-end (restoring a backed-up ROOT and DATADISK volume onto a second, stopped Instance) -- the API that drives the restore-and-attach code fixed by the previous commit (#14007). The target Instance is stopped with forced=True: a graceful ACPI stop was observed to time out (~2 minutes) before falling back to a hard destroy anyway, and once forced to a hard destroy the domain drops out of libvirt entirely, so the periodic ping-based PowerState sync the restore call depends on falls back to a much slower heuristic well past any reasonable wait. A forced stop destroys the domain immediately and deterministically. * KVM: support incremental NAS backups of RBD volumes Incremental NAS backups so far relied on QEMU dirty bitmaps / libvirt checkpoints, which only exist on file-based qcow2 storage. RBD images are raw and have nowhere to persist a bitmap, so any VM with a volume on Ceph was forced onto the full-only path and re-uploaded the whole image on every cycle. Ceph provides the equivalent natively, and this adds a second chain format that uses it: an `rbd snap` per cycle as the anchor plus `rbd export-diff --from-snap`, which computes the changed extents inside Ceph from the image object-map. NASBackupProvider now selects the mechanism per VM via getIncrementalFlavor() - QCOW2 for checkpoint-capable pools, RBD for Ceph, UNSUPPORTED (legacy full-only) for mixed or other storage, since the two formats cannot be mixed inside one backup. Everything else - chain identity, the nas.backup.full.every cadence, delete/tombstone semantics and resource accounting - is shared unchanged. Restore differs because an export-diff stream carries no pointer to the diff before it, unlike a rebased qcow2. The provider therefore sends the whole chain from its full anchor up to the backup being restored, and the agent recreates the image and replays each diff with `rbd import-diff` in order. The image has to be recreated: a full diff only carries the extents that were allocated when it was taken, so any block still allocated in the target would otherwise show through as stale data. That also drops RBD snapshots the volume carried, which is inherent to rewinding a volume wholesale. Two behaviours follow from the anchor living in Ceph rather than in the QEMU process: a stopped VM keeps its incremental cadence (no live QEMU needed), and a chain survives a VM restart or host migration. Only the newest anchor is kept per image; a full additionally sweeps every older snapshot carrying the csbackup- prefix, so a deleted chain, an unassigned offering or a restore cannot leak snapshots. The feature stays behind the existing nas.backup.incremental.enabled zone setting, which still defaults to false. Note: the agent drives the `rbd` CLI, so KVM hosts backing up Ceph volumes need ceph-common installed. Verified on a Ceph Reef 18.2.8 cluster with KVM hosts on Ceph Quincy 17.2.7 clients: FULL 1.86 GB followed by incrementals of 71 KB - 2.6 MB, restores replaying 2- and 3-diff chains across two RBD pools including through a tombstoned ancestor. test_backup_recovery_nas.py: the blanket RBD skip is replaced by an _is_rbd_storage() predicate, so the five chain tests now run on Ceph. test_stopped_vm_falls_back_to_full keeps a targeted skip because RBD has the opposite behaviour by design, and a new test_stopped_rbd_vm_keeps_incremental_cadence asserts that other side. * test: run the NAS backup smoke test on a cloud-init template The suite registered the legacy CentOS 5.5 tiny template via get_template(). Its kernel/udev does not reliably enumerate hot-attached virtio disks and it ships no mkfs.ext4, so the chain tests needed guest-side workarounds to reach the data they back up and restore. Register the Ubuntu 24.04 cloud-init template instead, which enumerates hot-attached disks, carries the usual filesystem tools and grows its root filesystem on first boot by itself. The cloud image disables SSH password authentication outright (60-cloudimg-settings.conf), so guest access moves to an SSH keypair and the stock "ubuntu" user. That user lands unprivileged, so commands touching /root or a raw block device now go through a _sudo() helper which wraps the whole command in `sh -c` under sudo, keeping redirects and ';'-separated commands root-privileged rather than just the first word. Cleanup ordering changes with it: a template cannot be deleted while a VM still uses it, so it is appended to _cleanup after the account that owns the VM, since cleanup_resources() deletes in list order. The in-place multi-disk restore regression test that accompanied this change upstream is left out: it asserts the uuid-based volume mapping in LibvirtRestoreBackupCommandWrapper, which this branch does not carry. * test: validate a whole backup chain, including across a mid-chain delete The existing chain tests each check one property of one backup: the full/incremental cadence, a restore from the tip, a delete that repairs or defers. None of them walks the chain as a whole, and none asserts on backup size. Add a test that builds FULL + 3 INCREMENTALs with a marker file per backup, restores from every backup and creates a VM from every backup, then deletes the 2nd incremental and repeats both sweeps over what survives. The mid-chain delete is what earns the runtime on RBD. An `rbd export-diff` stream carries no pointer to the diff before it, so a restore replays the whole sequence from the full anchor, and a diff whose descendant still needs it cannot be dropped when it is deleted, only hidden. Restoring the tip across that gap is what breaks if the provider ever sends a chain with a hole in it, and nothing else covered it. Sizes are asserted throughout: an incremental must be a small fraction of the full. That is what distinguishes a real export-diff delta from the whole image being re-exported every cycle, and no other test in this file looks at size at all, so a provider that silently fell back to full-every-time still passed. Each restore also asserts that markers written after that backup are gone. Checking only that the expected markers are present would pass even if the restore had quietly done nothing. VMs built from backups are expunged as the test goes rather than through _cleanup: seven of them are created, and holding them all to the end risks exhausting the environment's capacity partway through a run. * test: verify the guest of a VM created from a backup, not just that it boots The chain test checked an Instance created from a backup only for reaching Running. That proves the image boots; it says nothing about whether the diff chain was replayed into the new volume correctly, so a create-from-backup that produced a stale or empty image would still have passed. Check the guest the same way an in-place restore is checked: the markers taken up to that backup must be present, and markers written after it must be absent. The absent half matters as much as the present half -- without it, a VM that somehow came up with the source Instance's current disk would pass. Access uses the pattern already proven by test_incremental_after_vm_restart: the backup carries the source Instance's authorized_keys, so the new VM accepts the same keypair and the stock cloud-image "ubuntu" user. * nasbackup: carry the backup method separately from the mode The RBD path overloaded ChainDecision.mode with rbd-full and rbd-incremental, the same way the content-based path upstream overloaded it with content-full and content-incremental. Split the two concerns as that path already did: mode stays full or incremental, and a new method field says how the backup is taken -- qcow2 (push mode with dirty bitmaps) or rbd (Ceph-native, anchored on an rbd snapshot and exported with rbd export-diff). TakeBackupCommand gets a method field and nasbackup.sh a --method option. Both default to qcow2 when absent, so a management server that does not send a method keeps working against an upgraded agent. legacy-full is unchanged: rewriting it as full plus a "none" method would break incremental-disabled backups on agents that have not been upgraded yet. CHAIN_FORMAT stays as it is. The method says how a backup is taken and lives only for the duration of the request; the chain format is persisted and says what is on the repository, which is what restore and delete read later. The two coincide for the rbd method today but answer different questions. This mirrors c144d09 from #14194, which introduced the method for the content path and named an RBD diff as the next one to adopt it. Kept as close to that commit as the branch allows so the two merge cleanly: this branch carries the RBD path but not the content one, so the METHOD_CONTENT token is defined without a user here. * utils: add RbdUtils for the Ceph monitors of an RBD pool Everything that talks to Ceph needs the pool's monitors as a list the client can parse, and the rules are the same wherever that list is built: give each monitor the pool's port unless it names one already, and put a bare IPv6 address in square brackets so its own colons stay distinguishable from the separator before the port. The mon_host option of a disk's rbd: string wants the same list again, with ':' and ';' escaped, because those two separate the options of that string and its monitors. None of it depends on a storage pool, so collect it in RbdUtils as static methods with their unit tests, rather than leaving each caller to grow a copy that is right in a different set of cases. * kvm: build the Ceph monitors of the restore backup command with RbdUtils The monitors with a port, and the IPv6 monitors, are not valid arguments of rbd -m when the brackets are removed and the port is added to each monitor. * backup: name the rbd method in the TakeBackupCommand comment The field listed qcow2 and content but not rbd, the method this branch adds, so the one method a reader of this command is most likely to be chasing was the one the comment left out. * Add package dependencies * Add ceph-common as dependencies * kvm: refuse an RBD restore that would destroy a snapshot we did not take A restore rewinds the volume wholesale: the image is removed and rebuilt from its diff chain, so every snapshot it carried goes with it. The chain anchors this path takes are its own to drop, but a CloudStack volume snapshot kept on primary storage, or anything else taken outside this path, is content someone asked to keep, and destroying it quietly is not a trade the operator was offered. Ask what the image carries before touching it. A snapshot that is not one of ours refuses the restore, naming the ones in the way so they can be deleted or the backup restored into a new volume. Anything else is purged as before, except that an image which carries nothing is no longer handed a purge with nothing to do; when the listing itself fails we cannot tell, so it is purged as it always was. The failure to remove the image goes back to saying only that. Explaining it by a snapshot with clones made sense while a restore purged whatever it found, but the snapshot those clones belong to is now refused earlier, so a removal that still fails is failing for some other reason. The test that replays a whole chain stubbed every piped rbd call with the output of `rbd info`, whose "name" field would now read as a snapshot; tell the two commands apart there, and cover the refusal. * kvm: drop the cephx key file from a trap in nasbackup.sh The key the script hands the rbd CLI lives in a temporary file for the length of a call. cleanup() removes it, but only the failure paths call cleanup, so an exit that does not reach it left the key behind. Leave its removal to the shell as well, which covers every exit it still gets to run code on. * utils: test the escaped colons of an IPv6 Ceph monitor without a port composeOptionForMonHosts escapes every ':' of a monitor, because the colons separate the options of the rbd: string. That includes the colons of an IPv6 address, also when the pool has no port to add. Test that case, and make addPortToRbdMonitor, which is only used by RbdUtils itself, protected. * kvm: remove the backup anchor once the chain it anchors is gone An RBD chain is exported from a snapshot of every volume, the anchor, named csbackup-<id>. Each backup drops the previous anchor once its delta has been exported, so one anchor per volume is kept: the one the next incremental reads from. Nothing removed the last one. When the last backup of a chain was deleted, or the Instance was taken out of its backup offering, the anchor stayed on the image for as long as the volume lived, and with it the data it references: the next backup is a full one either way, so nothing ever read it again. Remove the anchors of an Instance's volumes wherever the chain ends, next to where the Instance's active checkpoint is already cleared. nasbackup.sh takes a removeanchors operation, which sweeps every snapshot carrying the backup prefix off the volumes it is given: only the snapshots this tool creates carry it, so a user or volume snapshot is never touched. The removal is best effort. The chain is gone either way, and a host that cannot be reached must not fail the delete of a backup or the removal of an offering, so a failure is logged rather than thrown. An Instance with no volume on an RBD pool carries no anchor and is left alone. * nas: decide a chain from its flavour rather than from an rbd flag decideChain carried a boolean telling the RBD flavour apart from the QCOW2 one, and every branch that differs between the two read it: the prefix of the anchor it names, the on-NAS format it requires of the parent, the decision it returns, and whether a stopped Instance can continue the chain at all. A third flavour would have to be threaded through each of them separately. Ask the flavour instead. anchorPrefixOf, flavorToFormat and flavorSupportsIncrementalWhileStopped answer the three questions the branches were asking, incrementalDecision builds the next link of a chain as fullDecision already built the first one, and both take the flavour. The prefix of a QCOW2 anchor is named alongside the RBD one rather than written in place. Behaviour is unchanged: a stopped Instance only reaches the full it took before when its flavour cannot continue a chain while stopped, which is every flavour but RBD, so the decision it returns is the same one. Also rename applyBackupFormat to applyBackupFormatToRestoreCommand, which says what it applies the format to. * packaging: suggest ceph-common instead of requiring it The agent only needs the rbd command line tools for RBD backups and migrations; python3-rados and python3-rbd stay required. * nas: address review of the RBD incremental backups - restore: check every target volume (RBD storage, no foreign snapshots) before removing any image, so a later volume cannot fail after an earlier one was already rewound - restore: replay each rbd import-diff with the restore timeout instead of the one hour default - backup: pause a running multi-disk VM around the RBD snapshots when the filesystems were not frozen, so the set is crash consistent - drop em-dashes from log and exception messages * nas: run RBD backups on a host that has the rbd command ceph-common is only suggested by the agent package, so not every KVM host has the rbd command. The agent now reports whether it does (host.rbd.cli) and an RBD backup runs on a host that has it: the Instance's own host, or for a stopped Instance any other Up host of its cluster. When there is none, a plain full backup is taken instead of failing on the missing command. * nas: restore RBD backups on a host that has the rbd command Restoring an RBD chain recreates the image and replays the diffs with the rbd command, which a host may lack as ceph-common is only suggested. Restore on the Instance's host when it has the command, otherwise on another host of its cluster that has it. A volume restore that attaches to a running Instance has to stay on that Instance's host. When no usable host has the command, fail with a message that says so. * import com.cloud.utils.exception.CloudRuntimeException * nasbackup.sh: bring back the quiesce fixes of #14305 dropped by the merges The merges of main into this branch lost most of #14305 in nasbackup.sh: - --quiesce-timeout was no longer parsed, so a quiesced backup, for which the agent passes it by default, failed with an invalid option on every storage - abort_backup_job() was gone, though the pull mode path of the Linstor backup still calls it, so a failed pull job kept the scratch devices busy - the push mode path lost the freeze timeout, the thaw after every freeze attempt, the thaw retries, the abort of the job in cleanup() and the retry of the domjobinfo query The script is main's again, plus what the rbd method adds. The rbd path now freezes and thaws the guest with the same helpers, resuming a paused Instance before it thaws. * nas: tell the user why a restore of an Instance from a backup failed When the host refuses or fails the restore, the NAS provider returned only false and the backup manager answered with the generic error, so the reason the host gave, such as an RBD image carrying snapshots the backup path did not take, never reached the user. Throw a BackupProviderException with the details of the answer, which the backup manager hands to the user as it is. * nas: check for volume snapshots on RBD before restoring an Instance from a backup Restoring an RBD volume from a backup rewinds the image wholesale, which removes every snapshot it carries, so the host refuses it when the image carries a snapshot the backup path did not take. Check the volume snapshots kept on primary storage in the management server first, and refuse before anything is sent to the host with the names of the volume and of its snapshots. The host still checks the image, which also catches snapshots CloudStack does not know about. * nas: remove a duplicate import of DataStoreRole in the test NASBackupProviderTest imported com.cloud.storage.DataStoreRole twice, which the checkstyle check of the build refuses. * test: release the public IP of each Instance the NAS backup tests create Marvin gives every Instance created by VirtualMachine.create or Backup.createVMFromBackup its own public IP, with a port forwarding rule for SSH, and destroying the Instance does not release that IP. The class only got them back when its account was removed, so the tests which create Instances from backups ran out of the 13 free addresses of the public range and failed with "Insufficient address capacity", after which Marvin silently left ssh_ip unset. Add release_publicIP() to marvin.lib.common, which releases a public IP unless it is the source NAT address of the network, and call it for the Instances of each test in tearDown, for the target Instance of test_restore_volume_and_attach_to_vm, and for each Instance which test_full_chain_restore_and_create_vm_survive_mid_chain_delete destroys as it goes. The Instance shared by the class keeps its IP until the class ends. * kvm: build every Ceph monitor list with RbdUtils The agent assembled the monitor list in several places, each with its own idea of the rules. Opening a RADOS connection, or writing a ceph.conf for one, appended the pool's port to the host string as a whole, so with several monitors only the last was given it and a monitor that already named its port was handed a second. The rbd: option string of a disk escaped the colons of an IPv6 address only when it was bracketed already, which left a bare one reading as though it carried options of its own. Use the shared helpers for all of them. Two inputs therefore come out differently, both previously wrong: a monitor that names its port keeps just that one, and a bare IPv6 address is bracketed before anything is appended to it or escaped in it. The iscsiadm portals in IscsiAdmStorageAdaptor read the same way but are not monitor lists, so they keep their own formatting. * nas: address the second review of the RBD incremental backups - restore: fail closed when the snapshots of an RBD image can not be listed, so a restore never removes snapshots it could not see; a missing image (exit code 2) has none. - removing the offering sends the anchor cleanup to a host which has the rbd command, and sends none when no host has it. - build the Ceph monitor list of an RBD disk string with RbdUtils, so a bare IPv6 monitor is bracketed, carries its port and survives nasbackup.sh's parser. - RBD backup: bound the freeze, pause and snapshot steps with timeouts and keep a state file in /run/csbackup while the guest is held. The guest is released by a TERM/HUP/INT trap of the script, by the take-backup wrapper when the script failed or was killed, and by the agent for every state file left when it starts (RbdBackupGuestReleaser), which covers SIGKILL, a crash and a restart of the agent. - nasbackup.sh holds a per-VM flock during the RBD backup, so two backups of a VM can not freeze the guest and share the state file at once. A refused backup exits with 21 and the wrapper then leaves the guest to the backup which holds the lock.
…it completes (apache#12843) The pull-mode path (apache#14194) cleared every trap once the backup was complete and then unmounted with a plain umount, so a slow or failed unmount failed a finished backup and left the share mounted. Hand the EXIT trap back to cleanup(), mark the backup complete and use unmount_completed_backup(), as the push and stopped-VM paths do. Signed-off-by: James Peru <jmsperu@gmail.com>
Description
This PR adds incremental NAS backup support for KVM VMs whose disks live on raw block-device storage such as LINSTOR/DRBD.
#13877 (backport of #13074) implements incremental NAS backups with QEMU dirty bitmaps and libvirt checkpoints. Bitmap persistence is a qcow2-only feature, so
allVolumesOnCheckpointCapableStorage()excludes raw block devices and every LINSTOR VM stays pinned to full-only backups regardless of the configured cadence. On top of that, the push-mode full backup of a raw device writes a fully allocated qcow2 which then needs a secondqemu-img convertpass to reclaim space.This PR adds a content-based backup path driven by libvirt pull mode and routes VMs on content-diff-capable storage (currently LINSTOR) to it:
nasbackup.sh– newcontentbackup methodThe script gets a
--methodoption next to-M|--mode:qcow2(default, the existing push-mode path with dirty bitmaps) orcontent. With--method content, libvirt is asked for a pull-mode backup: it starts an NBD server exposing a point-in-time view of each disk, held consistent by copy-before-write into a scratch block device per disk. The backup is then derived from that export:full:qemu-img convertfrom the NBD export straight into a sparse qcow2 in a single pass. This replaces the bloated push-mode output and its re-convert pass.incremental: a qcow2 overlay backed by the NBD export, then a safeqemu-img rebaseonto the parent backup. This merges in exactly the clusters that differ and yields a delta qcow2 backed by the parent, with a relative backing path. The chain has the same shape as a bitmap incremental, so the existing restore and cascade-delete logic applies unchanged.A missing or short parent list degrades to a full and emits
INCREMENTAL_FALLBACK=true, mirroring the push-mode fallback. Also handles the raw/dev/drbdNdevice paths of long-running VMs the same way the push/stopped paths do (viaget_linstor_uuid_from_device).The scratch devices are passed with
--scratch-devs, one per disk; libvirt formats them as qcow2 (<scratch dev=.../>). The NBD socket and the backup XML live in a small work directory under/var/tmp.A pull-mode job never ends on its own, so an EXIT/INT/TERM/HUP trap ends it (via
abort_backup_job()from #14305), removes the work directory and cleans up on any failed exit. The freeze/thaw handling uses the helpers from #14305 as well.Scratch space on the primary storage
Copy-before-write runs inline with the guest's writes and saves every block overwritten during the backup, at most once. The agent therefore creates one LINSTOR resource per backup (
cs-bkscratch-<uuid>), with one volume per disk sized for the whole disk plus qcow2 metadata, so the scratch can never fill up and pause the VM, also with several backups running at once:cs-bkscratch-*resource definition with a resource on its node. This happens once per controller and agent process: pools are registered again on every reconnect, while backups may still be running. After a hard crash the VM's pull-mode job can outlive the agent and still hold the scratch, so LINSTOR refuses the delete; the warning then names the VM (fromAux/cs-backup-vm) and says to end its job withvirsh domjobabortand delete the resource manually.KVMStoragePoolgetscreateBackupScratch()/deleteBackupScratch(), implemented byLinstorStoragePool. A pool that cannot provide scratch space fails the pull-mode backup; there is no fallback to host-local files.NASBackupProvider– routing and cadencedecideContentChain()mirrors the bitmap cadence logic (stopped VMs,nas.backup.full.every, chain length) but anchors on backup history alone. There is no host-side bitmap that can be invalidated, so a VM restart, live migration or restore cannot break the chain; content comparison is stateless and self-correcting.nas.backup.incremental.enabledapplies first: with incrementals disabled every VM, LINSTOR included, keeps the legacy push-mode full backup. Enabling incrementals is the opt-in to the content-based path.ChainDecisionseparates the two concerns:modeisfullorincremental, a newmethodfield isqcow2orcontent. Further methods (e.g. an RBD diff) can be added without new mode tokens.ChainDecisioncarries the parent backup uuid directly, since a content chain has no bitmap name to resolve the parent by.LibvirtTakeBackupCommandWrapper/ agentTakeBackupCommandcarries the newmethodfield, passed to the script as--method. When absent the agent assumesqcow2, so a management server that does not send it keeps working. Acontentincremental requires only its per-disk parent paths, no bitmap. No newagent.propertieskeys are needed.The agent kills a timed-out script with SIGKILL, which no trap can catch, so after a pull-mode timeout the wrapper aborts the backup job itself.
Restore onto LINSTOR: do not skip zero regions (bug fix, independent of the above)
replaceBlockDeviceWithBackupranqemu-img convertwith--target-is-zerowhenever the target device existed, skipping every zero/unallocated qcow2 cluster of the backup. On an in-place restore those clusters kept the volume's current data, and a new LINSTOR volume on thick LVM is not zeroed either. A newKVMStoragePool.newVolumeReadsAsZero()hook (false by default,LinstorStoragePoolanswers it withLinstorUtil.resourceSupportZeroBlocks()) now limits zero skipping to freshly created volumes on thin or ZFS backed pools. RBD targets were never affected.LINSTOR: wait for the device after making a resource available (bug fix)
createPhysicalDiskandconnectPhysicalDiskreturned as soon as LINSTOR had made the resource available on the node, but udev creates the/dev/drbd/by-reslink a little later. Restoring a backup runsqemu-img convertonto the volume right away and failed with "Could not open '/dev/drbd/by-res/cs-/0': No such file or directory": on every new volume when creating an instance from a backup, and on an in-place restore whenever the host held no replica. Both now wait up to 10 seconds for the local device.Stopped-VM backups (bug fixes)
backup_stopped_vmredirectedqemu-img convertwith>into$logFile, the agent's ownagent.log, truncating it on every stopped-VM backup. It now appends.cleanupbut carried on with the next disk, which then failed the second cleanup and left the backup in Error state ("Backup cleanup failed"). It now exits after the cleanup.Behaviour for VMs on qcow2/NFS/Ceph storage is unchanged; they keep using the bitmap path from #13877.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
Unit tests
Seven new
NASBackupProviderTestcases cover the routing and cadence decisions and the volume pools sent for content-method backups:decideChainReturnsLegacyFullForLinstorWhenIncrementalDisableddecideChainReturnsContentFullForStoppedLinstorVmdecideChainReturnsContentIncrementalForLinstorWithValidParentdecideChainReturnsContentFullForLinstorAtChainEndallVolumesOnContentDiffCapableStorageFalseForMixedStorageallVolumesOnContentDiffCapableStorageFalseForNoVolumestakeBackupSendsVolumePoolsForContentMethodOnRunningVmLibvirtTakeBackupCommandWrapperTestcovers the--method/--scratch-devsarguments, scratch creation, sizing and cleanup (also when the backup fails or times out), the method validation, the job abort after a pull-mode timeout and connecting a stopped VM's LINSTOR volumes. The newLinstorStorageAdaptorTestcovers local STORAGE-only and remote diskless scratch placement, cleanup of a scratch that cannot be placed, the device wait increatePhysicalDisk/connectPhysicalDisk, and deleting leftover scratch on pool registration (only this node's, once per controller, never failing the registration).LibvirtRestoreBackupCommandWrapperTestcovers zero skipping for in-place, new thick and new thin LINSTOR restores.All
NASBackupProviderTest(30),LibvirtTakeBackupCommandWrapperTest(18),LibvirtRestoreBackupCommandWrapperTest(23) andLinstorStorageAdaptorTest(11) cases pass, as do the full agent, KVM plugin, LINSTOR plugin and NAS plugin suites.End-to-end on a 3-host KVM/LINSTOR cluster (management server + 3 agents, LINSTOR 1.35.2, libvirt 10.0, NFS backup repository,
nas.backup.incremental.enabled=true), on the current revision:agent.logintacttest/integration/smoke/test_backup_recovery_nas.pyagainst LINSTORTest 6 ran with the small
marvin-alpineguest template (see #13746) in a Basic zone. Creating an instance from a backup does not work in a Basic zone on current 4.22 for reasons outside this PR (it passes the backup's network ids, which a Basic zone rejects, and the new instance gets the account's default security group), so those were worked around locally for the run.How did you try to break this feature and the system with this change?
The first four were run on the current revision, the others on the initial one with host-local scratch files.
virsh domjobabortand deleting the resource the next backup succeeds.INCREMENTAL_FALLBACK=true, and the DB records a full.qemu-imgduring the pull): the backup job is aborted, scratch and partial output removed, mount released; the next backup succeeds. Deleting the LINSTOR scratch resource after a failed or timed-out backup is covered by the unit tests./dev/drbdNinstead of/dev/drbd/by-res/…in live XML): resolved via udev like the push path; if the UUID cannot be derived the backup fails hard rather than producing a file restore cannot find.