Skip to content

nas: trim whitespace around backup repository mount options - #14096

Open
stag7824 wants to merge 5 commits into
apache:4.22from
stag7824:fix-nas-restore-mount-options-whitespace
Open

stag7824 wants to merge 5 commits into
apache:4.22from
stag7824:fix-nas-restore-mount-options-whitespace

Conversation

@stag7824

@stag7824 stag7824 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #14013

A backup repository whose mount options carry stray whitespace, for example vers=4.1 ,
backs up fine but fails to restore:

mount.nfs: an incorrect mount option was specified for
/usr/share/cloudstack-agent/tmp/csbackup...

Restore builds the mount command in Java (LibvirtRestoreBackupCommandWrapper.mountBackupDirectory)
and passes the option list to mount as a single argument, so mount receives the literal
vers=4.1 . libmount splits that list on commas only, so the blank stays glued to the last
option and the kernel rejects it.

Backup, delete and stats do not hit this today only because nasbackup.sh expands the options
unquoted, and shell word splitting drops the blank:

mount -t ${NAS_TYPE} ${NAS_ADDRESS} ${mount_point} $([[ ! -z "${MOUNT_OPTS}" ]] && echo -o ${MOUNT_OPTS})

#14009 quotes MOUNT_OPTS there, after which an existing row such as the one in #14013 would
break those operations as well.

So the options are now normalised where the stored value is read: NASBackupProvider passes
getMountOptions(repository) instead of repository.getMountOptions() to all five commands
(take, both restores, delete, stats). This fixes rows that are already in the database, without
a schema migration, and every operation gets the same option list.

The normalisation only removes whitespace:

The agent is unchanged, so the cifs nobrl append in the restore wrapper now always follows an
already clean list.

Types of changes

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

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • Minor

How Has This Been Tested?

Added eight unit tests to NASBackupProviderTest:

stored mount options sent to the agent fails without the fix
vers=4.1 (through syncBackupStorageStats, asserting on the command sent) vers=4.1 yes
vers=4.1 vers=4.1 yes
vers=4.1 , soft vers=4.1,soft yes
vers=4.1, ,soft, vers=4.1,soft yes
username=user,password=pa,,ss,vers=3.0 username=user,password=pa,,ss,vers=3.0 yes
empty yes
username=some user username=some user no
null null no

The last two pin behaviour the change must not alter.

mvn test -pl plugins/backup/nas -Dtest=NASBackupProviderTest
Tests run: 31, Failures: 0, Errors: 0, Skipped: 0

With the helper reduced to returning the stored value unchanged, the six tests marked above fail,
for example expected:<vers=4.1[]> but was:<vers=4.1[ ]>.

I don't have a KVM zone with a NAS repository. Earlier in this PR (see the comments) I ran the
restore mount path against a real samba share with nothing mocked: with guest,vers=3.0 the
share did not mount, and with the trailing blank removed it did. That check was against the
earlier, agent-side version of this change, but it shows the same failure the normalisation now
prevents for every command.

The same construction is present on 4.20. I targeted 4.22 because that is the version the issue
is reported against, but happy to retarget if it should land on 4.20 first.

A repository saved with mount options such as "vers=4.1 " backs up but fails to
restore. mountBackupDirectory builds the mount command as an argv list and runs
it without a shell, so ProcessBuilder hands the option list to mount verbatim.
libmount splits that list on commas only, so the blank stays glued to the last
option and the kernel rejects it as part of the option value.

The other backup operations pass the options to nasbackup.sh, which expands
MOUNT_OPTS unquoted, so shell word splitting drops the blank there. Restore is
the only one of the four that builds the mount command in Java.

Trim each comma-separated option and drop the empty ones before the list is
used. Only the whitespace around the delimiters is removed; validating the
option text belongs to the API layer. The normalisation runs before the cifs
branch appends nobrl, otherwise the blank would be moved into the middle of the
list rather than removed.

Fixes apache#14013
@boring-cyborg

boring-cyborg Bot commented Sep 9, 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:

@weizhouapache

Copy link
Copy Markdown
Member

@stag7824
have you verified it on a cloudstack environment ?

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 17.86%. Comparing base (a9b2f33) to head (afdeb67).
⚠️ Report is 31 commits behind head on 4.22.

Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14096      +/-   ##
============================================
- Coverage     17.86%   17.86%   -0.01%     
- Complexity    16037    16040       +3     
============================================
  Files          5928     5928              
  Lines        534479   534490      +11     
  Branches      65410    65412       +2     
============================================
- Hits          95468    95460       -8     
- Misses       428173   428199      +26     
+ Partials      10838    10831       -7     
Flag Coverage Δ
uitests 4.02% <ø> (ø)
unittests 18.92% <100.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.

@stag7824

stag7824 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Not on a full CloudStack zone, no — I don't have a KVM host with a NAS backup repository, and I didn't want to imply otherwise in the description.

What I could do is exercise the real code path against a real CIFS server, with nothing mocked. I ran mountBackupDirectory itself by reflection — real Script, real ProcessBuilder, real mount.cifs — against a samba share holding a file that exists only on the share, and checked whether that file could be read back afterwards:

mount options with this PR without it
guest,vers=3.0 (trailing space) mounted, payload read back not mounted
guest,vers=3.0 (no space, control) mounted, payload read back mounted, payload read back

The control row is there to show the harness isn't just reporting success, and that the change is inert for well-formed options.

The command that the unfixed path actually hands to mount, captured from the process table:

/sbin/mount.cifs //127.0.0.1/backup /tmp/csbackup.epddp75190 -o rw,vers=3.0 ,nobrl

which is the case in the description — nobrl is appended after the blank, so it ends up mid-list rather than at the end.

Worth flagging separately, because it changes how this looks in the field: Script.executeCommand(String...) returns null on failure rather than throwing, and mountBackupDirectory ignores the return value. So a failed mount isn't detected — restore carries on against an empty temp directory and fails later with a confusing error rather than a mount error. That's pre-existing and I've deliberately left it out of this PR, but happy to raise it as its own issue if you'd like.

What I still can't cover locally is the full path: management server, agent, a real backup and restore of a VM volume. If that's needed before this can go in, could someone with a NAS repository confirm it? Happy to adjust the approach — including moving the normalisation elsewhere — if you'd rather it not live in the agent.

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

…nt-options-whitespace

# Conflicts:
#	plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java
#	plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapperTest.java
@stag7824

stag7824 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Synced with 4.22 to resolve the conflict with #14006, which rewrote mountBackupDirectory to check the mount's exit value. The normalisation still runs before the cifs nobrl append and before the mount, and the seven tests now capture the command through Script.executeCommandForExitValue(timeout, ...) instead of executeCommand. The diff against 4.22 is still just the two files.

mvn test -pl plugins/hypervisors/kvm -Dtest=LibvirtRestoreBackupCommandWrapperTest
Tests run: 27, Failures: 0, Errors: 0, Skipped: 0

With the normalizeMountOptions call removed, the same four tests fail as before.

@stag7824

Copy link
Copy Markdown
Contributor Author

For anyone looking at CI: the 8 workflow runs on the current head (2c9c306) have been waiting for approval since Oct 2, when I synced with 4.22 after #14006, so nothing has run since that sync. Locally the test class passes (27 tests), and the 4 new tests that fail without the change still do.

@weizhouapache, you had asked about testing earlier: the evidence from the CIFS check is in my comment above. Could you or another committer approve the workflow runs? Thanks.

Move the normalisation from the KVM restore wrapper to NASBackupProvider,
so backup, restore, delete and stats all get the same option list. Only
options that are whitespace are dropped now: an empty option is kept,
because cifs reads a double comma as a comma inside a value such as a
password.
@stag7824 stag7824 changed the title kvm: trim whitespace around backup repository mount options on restore nas: trim whitespace around backup repository mount options Oct 16, 2026
@DaanHoogland DaanHoogland added this to the 4.22.3 milestone Nov 14, 2026
@stag7824

Copy link
Copy Markdown
Contributor Author

The workflow runs on the previous head were never approved and expired after 30 days (all 8 failed with no jobs on Nov 15), so I've synced with 4.22 to get a fresh set. The merge was clean; the diff is still the two files in the NAS plugin, and NASBackupProviderTest passes locally (43 tests, including the ones that came in with the sync).

@DaanHoogland, could you start the runs when you have a moment? Damans227's two review points are addressed above. Thanks.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@DaanHoogland

Copy link
Copy Markdown
Contributor

@Damans227 , does this lgty?

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland 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 20240

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

Test Result Time (s) Test File

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

thanks @stag7824, both my points are covered. CLGTM.

@DaanHoogland

Copy link
Copy Markdown
Contributor

I feel increasingly silly adding the needs-testing label on so many PRs. This is one example. @Damans227 as you reviewed can you advise what 3rd party testing is needed? or whether all has been covered by smoke tests?

@Damans227

Copy link
Copy Markdown
Contributor

can you advise what 3rd party testing is needed? or whether all has been covered by smoke tests?

@DaanHoogland the nas backup smoke tests ran take, restore and delete and all passed, so nothing broke for normal repos. they add the repo with no mount options though, so the fix itself isnt covered. one manual run is enough: add a nas repo with mount options that end in a space, like "vers=4.1 ", then take a backup, restore it and delete it.

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.

5 participants