Skip to content

Fix instance snapshots with KvmFileBasedStorageVmSnapshotStrategy - #14515

Open
sureshanaparti wants to merge 4 commits into
apache:4.22from
shapeblue:vm-snapshot-kvm-fixes
Open

sureshanaparti wants to merge 4 commits into
apache:4.22from
shapeblue:vm-snapshot-kvm-fixes

Conversation

@sureshanaparti

@sureshanaparti sureshanaparti commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes the instance snapshots with KvmFileBasedStorageVmSnapshotStrategy.

  • KvmFileBasedStorageVmSnapshotStrategy.canHandle() rejected any snapshot past Allocated that lacked the kvmFileBasedStorageSnapshot detail, but that detail is only persisted after a successful create. A failed create (e.g. quiescevm=true on a guest without a running agent) therefore left an Error row no strategy would claim once DefaultVMSnapshotStrategy was excluded. deleteVMSnapshot then failed, and deleteAllVMSnapshots made destroyVirtualMachine fail too, leaving the instance undeletable.

  • The strategy now tags every snapshot it starts creating with a kvmFileBasedStorageSnapshotStrategy detail, so it recognises its own rows in any later state regardless of whether the VM is still eligible for disk-only snapshots. Error rows that predate the marker carry no detail at all. When another strategy (typically DefaultVMSnapshotStrategy) is available it handles them as before; when none can, the manager removes the row's metadata directly, the same way it already removes Allocated rows, so deleteVMSnapshot and destroyVirtualMachine succeed after an upgrade..

  • Deleting a row that never recorded volume snapshots only removes its metadata: nothing reached primary storage and no create usage events were published, so no host command or delete usage events are issued.

Fixes #14481

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

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

6 open issues
What changed in this PR

Fixes KVM file-based VM snapshot lifecycle issues where failed snapshot creates could leave unclaimed Error rows and block instance deletion, by tagging snapshots early and adjusting handling/deletion behavior.

Changes:

  • Persist a strategy marker detail early during snapshot creation so later Error rows are still recognized by this strategy.
  • Relax canHandle() logic to claim snapshots based on either volume-snapshot details or the new strategy marker, with an eligibility fallback for legacy Error rows.
  • Add a “metadata-only” deletion path for snapshots that never recorded volume snapshot details.
File Description
engine/​storage/​snapshot/​src/​main/​java/​org/​apache/​cloudstack/​storage/​vmsnapshot/​KvmFileBasedStorageVmSnapshotStrategy.java Adds strategy marker persistence, updates canHandle(), and introduces metadata-only deletion for detail-less snapshots.
engine/​storage/​snapshot/​src/​test/​java/​org/​apache/​cloudstack/​storage/​vmsnapshot/​KvmFileBasedStorageVmSnapshotStrategyTest.java Adds unit tests for strategy marker persistence, updated canHandle() behavior, and metadata-only deletion behavior.

Review effort: Lite

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.87179% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.35%. Comparing base (c4c9731) to head (44a4e2a).
⚠️ Report is 9 commits behind head on 4.22.

Files with missing lines Patch % Lines
...a/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java 83.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14515      +/-   ##
============================================
+ Coverage     18.31%   18.35%   +0.04%     
- Complexity    16633    16689      +56     
============================================
  Files          5939     5939              
  Lines        537748   537847      +99     
  Branches      65924    65944      +20     
============================================
+ Hits          98472    98728     +256     
+ Misses       428070   427893     -177     
- Partials      11206    11226      +20     
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.44% <94.87%> (+0.04%) ⬆️

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.

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti 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.

@blueorangutan

Copy link
Copy Markdown

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

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti 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.

@blueorangutan

Copy link
Copy Markdown

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

@JoaoJandre JoaoJandre 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. I might test it later

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland 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-17483)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 95458 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr14515-t17483-kvm-ol8.zip
Smoke tests completed. 134 look OK, 15 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_CRUD_operations_userdata Error 1516.47 test_register_userdata.py
test_deploy_vm_with_registered_userdata Error 3.48 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_override_policy_allow Error 3.46 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_override_policy_append Error 3.28 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_override_policy_deny Error 3.50 test_register_userdata.py
test_deploy_vm_with_registered_userdata_with_params Error 3.34 test_register_userdata.py
test_link_and_unlink_userdata_to_template Error 3.17 test_register_userdata.py
test_user_userdata_crud Error 3.36 test_register_userdata.py
ContextSuite context=TestResetVmOnReboot>:setup Error 0.00 test_reset_vm_on_reboot.py
ContextSuite context=TestRAMCPUResourceAccounting>:setup Error 0.00 test_resource_accounting.py
test_03_register_template Error 1.10 test_resource_names.py
ContextSuite context=TestRestoreVM>:setup Error 0.00 test_restore_vm.py
ContextSuite context=TestRouterDHCPHosts>:setup Error 0.00 test_router_dhcphosts.py
ContextSuite context=TestRouterDHCPOpts>:setup Error 0.00 test_router_dhcphosts.py
ContextSuite context=TestRouterDns>:setup Error 0.00 test_router_dns.py
ContextSuite context=TestRouterDnsService>:setup Error 0.00 test_router_dnsservice.py
ContextSuite context=TestRouterIpTablesPolicies>:setup Error 0.00 test_routers_iptables_default_policy.py
ContextSuite context=TestVPCIpTablesPolicies>:setup Error 0.00 test_routers_iptables_default_policy.py
ContextSuite context=TestIsolatedNetworks>:setup Error 0.00 test_routers_network_ops.py
ContextSuite context=TestRedundantIsolateNetworks>:setup Error 0.00 test_routers_network_ops.py
ContextSuite context=TestRouterServices>:setup Error 0.00 test_routers.py
ContextSuite context=TestCpuCapServiceOfferings>:setup Error 0.00 test_service_offerings.py
ContextSuite context=TestServiceOfferings>:setup Error 0.27 test_service_offerings.py
ContextSuite context=TestSetSourceNatIp>:setup Error 0.00 test_set_sourcenat.py
ContextSuite context=TestSnapshotRootDisk>:setup Error 0.00 test_snapshots.py
ContextSuite context=TestSnapshotStandaloneBackup>:setup Error 0.00 test_snapshots.py
ContextSuite context=TestSslOffloading>:setup Error 0.00 test_ssl_offloading.py

@sureshanaparti
sureshanaparti marked this pull request as ready for review November 12, 2026 08:55
@RosiKyu RosiKyu self-assigned this Nov 24, 2026
@RosiKyu

RosiKyu commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

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

@RosiKyu

RosiKyu commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

I tested this on a KVM lab (2 hosts, NFS primary storage) with the settings from #14481: vmSnapshot.strategies.exclude=StorageVMSnapshotStrategy,DefaultVMSnapshotStrategy and kvm.vmstoragesnapshot.enabled=false. The VMs had a data disk and no guest agent. I ran the steps as the owning user and as root admin.

Step 4.22.1.1 PR packages
createVMSnapshot snapshotmemory=false quiescevm=true on a running VM fails, Error row left fails, Error row left
deleteVMSnapshot of that Error row (user, then admin) fails: "Failed to delete Instance Snapshot" works, row gone
destroyVirtualMachine expunge=true of a VM with an Error row fails: "Failed to destroy vm with specified vmId", VM left Stopped works, VM gone
Disk-only snapshot create, revert, delete on a running and a stopped VM with a data disk OK OK
Destroy with expunge of a VM that has snapshots OK OK
VMSNAPSHOT.CREATE, REVERTTO, DELETE events listed listed

@sureshanaparti One case is still failing: an Error row created on 4.22.1.1, before the upgrade to the PR packages. After the upgrade, deleteVMSnapshot of that row still fails with "Failed to delete Instance Snapshot", with the VM stopped and again after starting it, and destroyVirtualMachine expunge=true of that VM still fails with "Failed to destroy vm with specified vmId". The description says "Error rows that predate the marker fall back to the creation eligibility check." Is this row expected to be deletable after the upgrade? Users who already hit #14481 will have such rows when they upgrade.

@RosiKyu
RosiKyu self-requested a review November 25, 2026 07:18
@blueorangutan

Copy link
Copy Markdown

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

Test Result Time (s) Test File
test_02_enableHumanReadableLogs Error 0.37 test_human_readable_logs.py

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@sureshanaparti 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.

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@sureshanaparti One case is still failing: an Error row created on 4.22.1.1, before the upgrade to the PR packages. After the upgrade, deleteVMSnapshot of that row still fails with "Failed to delete Instance Snapshot", with the VM stopped and again after starting it, and destroyVirtualMachine expunge=true of that VM still fails with "Failed to destroy vm with specified vmId". The description says "Error rows that predate the marker fall back to the creation eligibility check." Is this row expected to be deletable after the upgrade? Users who already hit #14481 will have such rows when they upgrade.

@RosiKyu updated changes, please check. thanks.

@blueorangutan

Copy link
Copy Markdown

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

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.

Instance snapshot failures when using 'KvmFileBasedStorageVmSnapshotStrategy'

6 participants