Skip to content

Backup: support StorPool volumes in NAS backup provider on KVM - #14203

Open
slavkap wants to merge 7 commits into
apache:mainfrom
storpool:sp-nas-backup
Open

slavkap wants to merge 7 commits into
apache:mainfrom
storpool:sp-nas-backup

Conversation

@slavkap

@slavkap slavkap commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Description

Volume pool/path info is now sent to the agent whenever a VM has a StorPool volume, not just when the VM looks Stopped, since nasbackup.sh re-checks the VM's actual liveness itself right before acting and needs the StorPool path to clone a backup source disk if it finds the VM already stopped.

  • StorPoolStorageAdaptor.createPhysicalDisk() now creates and attaches a StorPool volume (previously a no-op returning null), used when restoring a backup provisions a new volume.
  • nasbackup.sh clones the live StorPool volume into a point-in-time volume before reading from it for a cold backup, and cleans it up afterwards (with an EXIT trap as a safety net).
  • Backup size is now reported via an explicit BACKUP_SIZE_TOTAL= marker on stdout instead of being inferred from output position/shape, which broke down once StorPool added a third code shape; take-backup errors are now always returned as a BackupAnswer rather than letting an uncaught exception surface as a plain Answer.
  • Restore reports back the volume path StorPool actually assigned (BackupAnswer.restoredVolumePath) instead of the path CloudStack guessed, since StorPool controls the device path itself.
  • Backup file identifiers are normalized to the qcow2 basename so StorPool's full device path matches what nasbackup.sh expects.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

How Has This Been Tested?

Manual testing and smoke tests with StorPool as a primary storage, KVM hypervisors

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Restore attachment compatibility and StorPool volume cleanup failures remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds StorPool support to KVM NAS backup and restore workflows.

Changes:

  • Adds StorPool volume provisioning and restored-path reporting.
  • Adds point-in-time cloning for cold backups.
  • Improves backup size reporting, cleanup, and error handling.
  • Expands integration and provider tests.
File summaries
File Summary
test/integration/plugins/storpool/TestNasBackupStorPool.py StorPool NAS backup/restore tests
test/integration/plugins/storpool/sp_util.py StorPool test helpers
scripts/vm/hypervisor/kvm/nasbackup.sh StorPool cloning and cleanup
plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java StorPool volume provisioning
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtTakeBackupCommandWrapper.java Backup output and size parsing
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java StorPool restore handling
plugins/backup/nas/src/test/java/org/apache/cloudstack/backup/NASBackupProviderTest.java Provider restore-path tests
plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java Backup and restore path propagation
core/src/main/java/org/apache/cloudstack/backup/BackupAnswer.java Restored-volume path response
Review details

Suppressed comments (3)

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:362

  • If qemu-img convert fails after this StorPool volume has been created and attached, replaceBlockDeviceWithBackup only returns a failed answer; it never detaches or deletes the newly provisioned volume. Because the restore does not persist a CloudStack volume on this path, every failed restore can leave an attached, orphaned StorPool volume. Track the created disk and clean it up on all subsequent failure paths (or add an explicit rollback around the conversion).
                    disk = volumeStoragePool.createPhysicalDisk(volumeUuid, QemuImg.PhysicalDiskFormat.RAW, Storage.ProvisioningType.THIN, size, null);
                    if (disk == null) {
                        throw new CloudRuntimeException(String.format("Failed to provision a %s volume for restore [%s]", poolType, volumeUuid));
                    }
                    if (Storage.StoragePoolType.StorPool.equals(poolType)) {
                        volumePath = disk.getPath();

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java:490

  • attachOrDetachVolume() throws CloudRuntimeException when the StorPool attach command fails, so the if (!...) branch is not entered in that failure mode. The newly created volume is therefore left behind even though restore reports failure, leaking an unattached StorPool volume on every attach exception; wrap the attach in cleanup logic that deletes globalId for both a false return and an exception.
        if (!attachOrDetachVolume("attach", "volume", volumePath)) {
            volumeDelete(globalId);
            throw new CloudRuntimeException(String.format("Could not attach newly created StorPool volume %s", volumePath));

scripts/vm/hypervisor/kvm/nasbackup.sh:582

  • Because read_disk=$(sp_create_backup_source_disk ...) executes the function in a command-substitution subshell, the function's append to SP_CLEANUP_VOLUMES is lost when it returns. If qemu-img convert or a later per-disk step fails, the parent EXIT trap therefore has no clone name to release, leaving the attached backup-source StorPool volume orphaned. Return the path through a variable/file without command substitution (or otherwise register the clone in the parent shell) before proceeding.
      if ! read_disk=$(sp_create_backup_source_disk "$disk"); then
        log -ne "Failed to create a StorPool backup source volume for $disk"
        echo "Failed to create a StorPool backup source volume for $disk"
        cleanup
        exit 1
      fi
      sp_clone_name=$(sp_volume_name_from_path "$read_disk")
  • Files reviewed: 9/9 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
@nvazquez nvazquez added this to the 24.0 milestone Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.51064% with 125 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.15%. Comparing base (58fda71) to head (648f018).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...hypervisor/kvm/storage/StorPoolStorageAdaptor.java 0.00% 65 Missing ⚠️
...ce/wrapper/LibvirtRestoreBackupCommandWrapper.java 44.06% 22 Missing and 11 partials ⚠️
...ource/wrapper/LibvirtTakeBackupCommandWrapper.java 54.16% 8 Missing and 3 partials ⚠️
...rg/apache/cloudstack/backup/NASBackupProvider.java 75.00% 4 Missing and 4 partials ⚠️
.../hypervisor/kvm/storage/KVMStoragePoolManager.java 0.00% 5 Missing ⚠️
...m/cloud/hypervisor/kvm/storage/StorageAdaptor.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              main   #14203       +/-   ##
============================================
+ Coverage     3.86%   21.15%   +17.29%     
- Complexity       0    21543    +21543     
============================================
  Files          494     6080     +5586     
  Lines        42888   551656   +508768     
  Branches      8141    73906    +65765     
============================================
+ Hits          1657   116724   +115067     
- Misses       40999   421146   +380147     
- Partials       232    13786    +13554     
Flag Coverage Δ
uitests 3.87% <ø> (+0.01%) ⬆️
unittests 22.62% <33.51%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@weizhouapache

weizhouapache commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

this needs testing on NFS, Ceph,Linstor and Storpool to ensure there is no regression

cc @abh1sar @rp- @slavkap
I will run some tests on ceph

@rp-

rp- commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Just tested this against #14194

And nothing breaks here against Linstor (didn't test anything else).

just that whatever patch lands first, the final merge will need this:

diff --git a/scripts/vm/hypervisor/kvm/nasbackup.sh b/scripts/vm/hypervisor/kvm/nasbackup.sh
index 0d166dbc79..3658ba7972 100755
--- a/scripts/vm/hypervisor/kvm/nasbackup.sh
+++ b/scripts/vm/hypervisor/kvm/nasbackup.sh
@@ -345,11 +345,10 @@ backup_running_vm_pull() {
   rm -rf "$scratch_dir"
   sync
 
-  # Statistics -- the size on the last stdout line is parsed by the Java wrapper.
-  du -sb $dest | cut -f1
-
-  umount $mount_point
-  rmdir $mount_point
+  backup_size=$(du -sb "$dest" 2>>"$logFile" | cut -f1) || { log -ne "WARNING: du failed for $dest, reporting size as 0"; backup_size=0; }
+  timeout "$UNMOUNT_TIMEOUT" umount "$mount_point" 2>>"$logFile" || { log "WARNING: umount of $mount_point failed or timed out"; true; }
+  rmdir "$mount_point" 2>>"$logFile" || { log "WARNING: rmdir of $mount_point failed"; true; }
+  echo "BACKUP_SIZE_TOTAL=$backup_size"
 }
 
 # StorPool volume name (with the "~globalId" form the storpool/storpool_req CLIs expect) from

Copilot AI lite review requested due to automatic review settings October 12, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI lite review requested due to automatic review settings October 13, 2026 11:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

16 open findings

🧠 Review effort: Lite

Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
Copilot AI lite review requested due to automatic review settings October 19, 2026 10:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

22 open issues

And 2 more that still need to be addressed.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

41 open issues

And 21 more that still need to be addressed.

Review effort: Lite

Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
Comment thread scripts/vm/hypervisor/kvm/nasbackup.sh Resolved
@Damans227

Copy link
Copy Markdown
Contributor

@weizhouapache @Damans227 @rajiv-jain-netapp anything pending to be addressed from your reviews?

@nvazquez nothing pending from me. both my points are covered and the nov 4 changes still look right.

@Damans227 Damans227 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLGTM.

Copilot AI lite review requested due to automatic review settings November 10, 2026 13:00
@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the change contains multiple critical integration issues in StorPool path handling, volume creation defaults, encryption detection, and REST response parsing that can break restores and leave orphaned clones.

38 open issues

And 18 more that still need to be addressed.

3 resolved since last review

Review effort: Lite

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✖️ suse15. SL-JID 19977

@nvazquez

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-17541)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 58396 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14203-t17541-kvm-ol8.zip
Smoke tests completed. 157 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

Volume pool/path info is now sent to the agent whenever a VM has a
StorPool volume, not just when the VM looks Stopped, since nasbackup.sh
re-checks the VM's actual liveness itself right before acting and needs
the StorPool path to clone a backup source disk if it finds the VM
already stopped.

- StorPoolStorageAdaptor.createPhysicalDisk() now creates and attaches
  a StorPool volume (previously a no-op returning null), used when
  restoring a backup provisions a new volume.
- nasbackup.sh clones the live StorPool volume into a point-in-time
  volume before reading from it for a cold backup, and cleans it up
  afterwards (with an EXIT trap as a safety net).
- Backup size is now reported via an explicit BACKUP_SIZE_TOTAL=<bytes>
  marker on stdout instead of being inferred from output position/shape,
  which broke down once StorPool added a third code shape; take-backup
  errors are now always returned as a BackupAnswer rather than letting
  an uncaught exception surface as a plain Answer.
- Restore reports back the volume path StorPool actually assigned
  (BackupAnswer.restoredVolumePath) instead of the path CloudStack
  guessed, since StorPool controls the device path itself.
- Backup file identifiers are normalized to the qcow2 basename so
  StorPool's full device path matches what nasbackup.sh expects.
Restore (KVM agent):
- When restoring a backed-up volume to a new StorPool volume fails,
  either while copying the backup data or while attaching the volume
  to the running VM, the created volume was leaked. The management
  server persists the restored volume only on success, and StorPool
  assigns the volume's identity itself, so nothing else could find
  and delete it.
- Add StorageAdaptor#cleanupCreatedPhysicalDisk (default: no-op) and
  call it from LibvirtRestoreBackupCommandWrapper on both failure
  paths. The StorPool implementation detaches the volume from this
  host and deletes it. The restore still fails; a cleanup failure is
  only logged.
- Fix the delete when the attach in StorPoolStorageAdaptor
  #createPhysicalDisk fails: the volume was deleted by its bare
  globalId instead of "~<globalId>".

Backup (nasbackup.sh)

- Delete the clone with onAttached=detachForce, which removes it even
  if the attach succeeded but the device symlink never appeared.
  This replaces the separate detach-with-retries step.
Copilot AI lite review requested due to automatic review settings November 30, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Two critical issues remain: the StorPool clone request omits the required template, and the EXIT trap replacement can leave registered clones orphaned during failures.

38 open issues

And 18 more that still need to be addressed.

Review effort: Lite

- nasbackup.sh: use a single EXIT handler (on_script_exit) that runs
  both the StorPool backup-source-volume cleanup and the cephx keyfile
  removal. The later "trap rbd_cleanup_keyfile EXIT" replaced the
  StorPool trap, so clones left behind by a failed backup were never
  deleted; the pull path in turn replaced the keyfile cleanup.
- nasbackup.sh: read the created clone from data.name of the
  MultiCluster/VolumeCreate response instead of data.globalId.
- StorPoolStorageAdaptor.createPhysicalDisk: accept a null format as
  the pool default (RAW); StorPoolStoragePool forwards null from the
  createPhysicalDisk overload without a format.
Copilot AI lite review requested due to automatic review settings December 2, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The stopped-VM backup path still omits the configured StorPool template from its clone request, leaving an active issue that can cause clone creation or backup to fail.

8 open issues
30 resolved since last review

And 10 more resolved.

Review effort: Lite

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants