Skip to content

Fix interrupted KVM snapshot leaving VM on orphan overlay - #14697

Open
sidshas03 wants to merge 2 commits into
apache:mainfrom
sidshas03:fix/14691-snapshot-orphan-overlay
Open

sidshas03 wants to merge 2 commits into
apache:mainfrom
sidshas03:fix/14691-snapshot-orphan-overlay

Conversation

@sidshas03

Copy link
Copy Markdown

Description

This PR fixes a data loss problem that shows up when a volume snapshot of a
running VM gets interrupted midway, either because the agent dies or the merge
fails silently. In that situation the VM keeps running off an overlay file,
but volumes.path is still pointing at the base. So the next time the VM
starts, it comes up on the base and all the writes that went to the overlay
are gone, with nothing telling you it happened.

There are a few parts to the fix. Script.runSimpleBashScriptWithFullResult()
now carries the actual virsh error output in the exception it throws. Before
this the retry logic had nothing to match against, so now it can recognise the
transient ones like "disk already in active block job" and retry properly. The
snapshot markers also store vmName, diskLabel and overlayPath now, which gives
reconcileSnapshotMarkers() enough to work with, and that method is implemented
fully in this PR. For a running VM that is sitting on an overlay it does a
blockcommit, and for the offline case it falls back to qemu-img commit, with
safety checks so a modified base file is never overwritten.

Along with that, waitForCommandsAndExit is now waitForCommandsAndReconnect. It
calls reconnect() instead of System.exit(1), because exiting was killing
snapshot merges that were still in flight. And there was a duplicate
SNAPSHOT_MARKER_DIR constant that was breaking the build, so that is removed.

Fixes: #14691

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Script.runSimpleBashScriptWithFullResult now includes error output in exceptions, enabling retry logic for transient virsh errors. Snapshot markers store VM name, disk label, overlay path for recovery. reconcileSnapshotMarkers() fully implemented with blockcommit for running VMs and qemu-img commit for offline cases. Agent reconnects instead of System.exit(1) on ReadyCommand failure. Removed duplicate SNAPSHOT_MARKER_DIR constant.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 12:47
@boring-cyborg

boring-cyborg Bot commented Nov 13, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

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 was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@JoaoJandre
JoaoJandre self-requested a review November 13, 2026 12:58
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0.46948% with 212 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.76%. Comparing base (2f34b0c) to head (2b120bd).

Files with missing lines Patch % Lines
...ud/hypervisor/kvm/storage/KVMStorageProcessor.java 0.54% 184 Missing ⚠️
agent/src/main/java/com/cloud/agent/Agent.java 0.00% 23 Missing ⚠️
...s/src/main/java/com/cloud/utils/script/Script.java 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14697      +/-   ##
============================================
- Coverage     20.77%   20.76%   -0.01%     
+ Complexity    20847    20846       -1     
============================================
  Files          6053     6053              
  Lines        548222   548428     +206     
  Branches      73236    73268      +32     
============================================
- Hits         113896   113895       -1     
- Misses       420984   421191     +207     
  Partials      13342    13342              
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.20% <0.46%> (-0.01%) ⬇️

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.

Copilot AI balanced review requested due to automatic review settings November 13, 2026 16:15

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 was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

Interrupted running-VM volume snapshot leaves the VM on an orphan overlay, disk reverts on next start

2 participants