This is an automated email from the ASF dual-hosted git repository.

shwstppr pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.19 by this push:
     new 9033ab709e6 Fix snapshot chain being deleted on XenServer (#9447)
9033ab709e6 is described below

commit 9033ab709e6fad4ac9300649214d7e2ba938b020
Author: João Jandre <[email protected]>
AuthorDate: Thu Aug 1 09:03:04 2024 -0300

    Fix snapshot chain being deleted on XenServer (#9447)
    
    Using XenServer as the hypervisor, when deleting a snapshot that has a 
parent, that parent will also get erased on storage, causing data loss. This 
behavior was introduced with #7873, where the list of snapshot states that can 
be deleted was changed to add BackedUp snapshots.
    
    This PR changes the states list back to the original list, and swaps the 
while loop for a do while loop to account for the changes in #7873.
    
    Fixes #9446
---
 .../cloudstack/storage/snapshot/DefaultSnapshotStrategy.java       | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git 
a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java
 
b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java
index f1f073db170..333272113bd 100644
--- 
a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java
+++ 
b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java
@@ -102,6 +102,8 @@ public class DefaultSnapshotStrategy extends 
SnapshotStrategyBase {
     @Inject
     SnapshotZoneDao snapshotZoneDao;
 
+    private final List<Snapshot.State> snapshotStatesAbleToDeleteSnapshot = 
Arrays.asList(Snapshot.State.Destroying, Snapshot.State.Destroyed, 
Snapshot.State.Error);
+
     public SnapshotDataStoreVO getSnapshotImageStoreRef(long snapshotId, long 
zoneId) {
         List<SnapshotDataStoreVO> snaps = 
snapshotStoreDao.listReadyBySnapshot(snapshotId, DataStoreRole.Image);
         for (SnapshotDataStoreVO ref : snaps) {
@@ -199,9 +201,8 @@ public class DefaultSnapshotStrategy extends 
SnapshotStrategyBase {
 
         boolean result = false;
         boolean resultIsSet = false;
-        final List<Snapshot.State> snapshotStatesAbleToDeleteSnapshot = 
Arrays.asList(Snapshot.State.BackedUp, Snapshot.State.Destroying, 
Snapshot.State.Destroyed, Snapshot.State.Error);
         try {
-            while (snapshot != null && 
snapshotStatesAbleToDeleteSnapshot.contains(snapshot.getState())) {
+            do {
                 SnapshotInfo child = snapshot.getChild();
 
                 if (child != null) {
@@ -247,7 +248,7 @@ public class DefaultSnapshotStrategy extends 
SnapshotStrategyBase {
                 }
 
                 snapshot = parent;
-            }
+            } while (snapshot != null && 
snapshotStatesAbleToDeleteSnapshot.contains(snapshot.getState()));
         } catch (Exception e) {
             s_logger.error(String.format("Failed to delete snapshot [%s] on 
storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e);
         }

Reply via email to