Skip to content

Nasbackup quiesce fixes - #14305

Open
MitchDrage wants to merge 4 commits into
apache:4.22from
MitchDrage:nasbackup-quiesce-fixes
Open

MitchDrage wants to merge 4 commits into
apache:4.22from
MitchDrage:nasbackup-quiesce-fixes

Conversation

@MitchDrage

Copy link
Copy Markdown

Description

Fixes #14295, one commit per issue:

  1. Failed scheduled backup shown as MANUAL. When cleanup fails, the NAS provider keeps the backup row in Error state, but the schedule id was only written on success. The provider now returns that row and BackupManagerImpl records the schedule id, name and description on it.
  2. Guest agent timeout not configurable. New zone-scoped setting nas.backup.quiesce.agent.timeout (default 30 seconds, 0 keeps libvirt's default of 5), passed to nasbackup.sh as --quiesce-timeout and on to virsh --timeout for freeze and thaw. The per-VM override from the issue is left out.
  3. cleanup() removing the destination under a running job. cleanup() now runs virsh domjobabort and waits up to 60 seconds for the job to end. If it is still running, the files and mount are left in place and the backup goes to Error state. Also fixed the Failed branch of the job polling loop, which called cleanup without exiting.
  4. Failed freeze never thawed. The script now always thaws after a freeze attempt and logs the freeze error. A failed thaw only fails the backup if the freeze succeeded, so VMs without a guest agent still get an unquiesced backup.

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

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

I've listed this as major as I'm having backups continuously fail. I've applied the timeout to nasbackup.sh by hand as a workaround and I'm waiting on the next scheduled run to confirm it. I'll add a comment tomorrow as to the result, or add some changes to fix it.

How Has This Been Tested?

  • Unit tests: new cases in BackupManagerTest, NASBackupProviderTest and a new LibvirtTakeBackupCommandWrapperTest. These and the NAS plugin suite pass.
  • Script: ran nasbackup.sh against stub virsh/mount commands for each failure path, including an abort that never completes.
  • Real host (4.22.1.1, libvirt 11.10.0, QEMU 10.1.0, NFS repository): a quiesced backup with --timeout 30 on freeze and thaw completed. Separately, aborting a running push backup ended the job about 1.4 seconds after domjobabort returned, after which the destination could be removed and unmounted.

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

  • Simulated: Guest agent not running, with quiesce on: freeze and thaw both fail, and the backup still completes unquiesced.
  • Simulated: Thaw failing after a successful freeze: the job is aborted before the destination is removed and unmounted.
  • Simulated: An abort that never completes: the files and mount are left alone and the backup goes to Error state.
  • Simulated: libvirt reporting the job as Failed: the script now exits. The original kept polling.
  • Real host: Aborting a backup mid-copy: the VM was unaffected and QEMU released the files within about 1.4 seconds.

@abh1sar
abh1sar requested review from abh1sar and a balanced review from Copilot October 5, 2026 08:41
@abh1sar

abh1sar commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

@MitchDrage thanks for the PR. I'll review/test it in the next few days.

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 review overview

🟡 Changes recommended

Ambiguous freeze/thaw and job-status failures can still leave guests frozen or delete destinations under active jobs, while failed-row retention remains incomplete.

Review effort: Balanced
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

Fixes NAS backup quiescing, cleanup, and failed scheduled-backup handling.

Changes:

  • Adds configurable guest-agent freeze/thaw timeouts.
  • Aborts active libvirt jobs before cleanup.
  • Preserves metadata for failed scheduled backups and expands tests.
File Description
BackupManagerTest.java Tests failed scheduled-backup linkage.
BackupManagerImpl.java Persists metadata on failed backups.
nasbackup.sh Handles quiescing, aborts, and cleanup.
LibvirtTakeBackupCommandWrapperTest.java Tests timeout argument forwarding.
LibvirtTakeBackupCommandWrapper.java Passes timeout to the script.
NASBackupProviderTest.java Tests failure and cleanup behavior.
NASBackupProvider.java Adds timeout configuration and returns Error backups.
TakeBackupCommand.java Carries the quiesce timeout.

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

Comment on lines +300 to +304
if ! response=$(qemu_agent_command '{"execute":"guest-fsfreeze-thaw"}' 2>&1); then
if [[ $freeze_ok -eq 1 ]]; then
echo "Failed to thaw the filesystem for vm $VM: $response"
cleanup
exit 1
Comment on lines +539 to +547
local i job
for ((i = 0; i < 60; i++)); do
job=$(virsh -c qemu:///system domjobinfo "$VM" 2>/dev/null | awk '/Job type:/ {print $3}')
if [[ -z "$job" || "$job" == "None" ]]; then
BACKUP_JOB_ACTIVE=0
return 0
fi
sleep 1
done
Comment on lines 830 to +833
if (!result.first()) {
if (backup != null) {
updateBackupFromCmd(backup.getId(), cmd, backupScheduleId);
}
@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 19.09%. Comparing base (2e63c60) to head (3ec681f).

Files with missing lines Patch % Lines
...rg/apache/cloudstack/backup/TakeBackupCommand.java 50.00% 3 Missing ⚠️
...ource/wrapper/LibvirtTakeBackupCommandWrapper.java 66.66% 0 Missing and 2 partials ⚠️
...rg/apache/cloudstack/backup/BackupManagerImpl.java 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14305      +/-   ##
============================================
+ Coverage     18.00%   19.09%   +1.08%     
- Complexity    16219    16234      +15     
============================================
  Files          5936     5487     -449     
  Lines        535716   497497   -38219     
  Branches      65596    58516    -7080     
============================================
- Hits          96459    94994    -1465     
+ Misses       428268   391708   -36560     
+ Partials      10989    10795     -194     
Flag Coverage Δ
uitests ?
unittests 19.09% <80.00%> (+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.

local status=0

if ! abort_backup_job; then
echo "Backup job for vm $VM is still running after abort, leaving $dest mounted at $mount_point"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if the abort never finishes, what unmounts the share on the host later? looks like the mount stays there for good

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.

4 participants