Reject creating a snapshot with a duplicate name for the same volume - #14089
nagaboinaramgopal wants to merge 2 commits into
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.36% +0.01%
- Complexity 13576 13597 +21
============================================
Files 5669 5669
Lines 501405 501478 +73
Branches 60907 60915 +8
============================================
+ Hits 81975 82071 +96
+ Misses 410246 410219 -27
- Partials 9184 9188 +4
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? |
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.