Repository navigation
Reject creating a snapshot with a duplicate name for the same volume - #14089
Conversation
|
thanks @nagaboinaramgopal makes sense, but I think it can go on branch 4.20 |
Two snapshots of the same volume with the same name map to the same file on the snapshot store, so creating the second overwrites the first, and later deleting either one removes the shared file and leaves the other snapshot pointing at nothing. Reject creating a snapshot when an active (non-destroyed) snapshot with the same name already exists for the volume. Auto-generated names already carry a timestamp so they are unaffected. Fixes: apache#13051
c0df0d6 to
b229715
Compare
Thanks. Moved it to 4.20. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.20 #14089 +/- ##
============================================
+ Coverage 16.34% 16.42% +0.07%
- Complexity 13576 13669 +93
============================================
Files 5669 5669
Lines 501405 501643 +238
Branches 60907 60944 +37
============================================
+ Hits 81975 82374 +399
+ Misses 410246 410042 -204
- Partials 9184 9227 +43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Query for an active snapshot with the given name on the volume instead of listing every snapshot of the volume and comparing names, as asked in review.
|
@DaanHoogland @sureshanaparti I've also verified on a live 4.23 KVM environment (NFS primary storage), creating snapshots of the same ROOT volume through the API. Before the change, both snapshots with the same name are accepted and end up BackedUp: With the change, the second one is rejected, a different name still works, and the name can be reused once the first snapshot is deleted: No SQL errors or exceptions in the management server log during the run. |
|
@sureshanaparti updated as suggested: the duplicate-name check now looks up by volume and snapshot name (ca6075e), verified on a live KVM environment. Could you take another look? |
|
@sureshanaparti , can you look again? |
Covers the finder added for duplicate snapshot name rejection: it returns the matching snapshot when one exists and null when none does, and queries by volume id and name.
The duplicate-name check added in this PR also ran for snapshots created without a caller-supplied name. Recurring snapshots are created that way and their name is auto-generated from the volume name and a timestamp, so an hourly and a daily policy firing on the same volume in the same second produce the same name and one of the scheduled snapshots was rejected. Only enforce the check when the caller supplied the name; the auto-generated path is left as it was before this PR.
|
Good catch, you're right. A scheduled snapshot carries no name, so allocSnapshot auto-generates |
that covers it, thx! |
|
@blueorangutan package |
|
@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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19624 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
Tested on a 4.20 KVM lab (NFS primary storage, one host) with the SL-JID 19624 packages. Test:Deploy a VM and snapshot its ROOT disk twice with the same name. Then use the same name on a data disk, again after deleting the first snapshot, and take snapshots with no name, two of them in the same second. Before: plain 4.20 (the PR's classes swapped out). Both snapshots are accepted: On KVM with NFS each one still got its own file, so the overwrite from the issue didnt show up here. After: the second one is refused: The same name on another volume works. The name can be used again after the first snapshot is deleted. Snapshots with no name still work, including two in the same second that got the same auto name (vm14089_data14089_20261021190721). @rootnomad can the error show just the volume name? right now it prints the whole volume object. |
|
[SF] Trillian test result (tid-17184)
|
Description
CloudStack lets you create more than one snapshot of the same volume with the same name. Since a snapshot's name is used to build its file name on the store, two snapshots of a volume with the same name map to the same file. Creating the second overwrites the first, and later deleting either one removes the shared file and leaves the other snapshot record pointing at a file that no longer exists.
This rejects creating a snapshot when an active (non-destroyed) snapshot with the same name already exists for the volume. Auto-generated snapshot names already include a timestamp, so they are not affected.
Fixes: #13051
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
N/A
How Has This Been Tested?
Added a unit test that creates a snapshot with a name that already exists for the volume and checks it is rejected with an InvalidParameterValueException. Before this change that test fails because the create proceeds; after it, it is rejected. The existing snapshot manager tests still pass.
Also verified on a live 4.23 environment: before the change, two snapshots of the same volume with the same name both complete and end up BackedUp; after it, the second same-name snapshot is rejected while a differently named snapshot on the same volume still completes.
How did you try to break this feature and the system with this change?
The check only compares against active snapshots (not Destroyed or Error), so re-using the name of a deleted snapshot still works. Auto-generated names carry a timestamp, so scheduled and default-named snapshots are not blocked.