Skip to content

Commit f79ba98

Browse files
sudisonAnthony Xu
authored andcommitted
CLOUDSTACK-5370: delete snapshot on primary storage in case of backup snapshot failed.
1 parent 6647802 commit f79ba98

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
13521352
Long physicalSize = null;
13531353
Map<String, String> options = cmd.getOptions();
13541354
boolean fullbackup = Boolean.parseBoolean(options.get("fullSnapshot"));
1355+
boolean result = false;
13551356
try {
13561357
SR primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel);
13571358
if (primaryStorageSR == null) {
@@ -1477,17 +1478,23 @@ public Answer backupSnapshot(CopyCommand cmd) {
14771478
} else {
14781479
newSnapshot.setParentSnapshotPath(prevBackupUuid);
14791480
}
1481+
result = true;
14801482
return new CopyCmdAnswer(newSnapshot);
14811483
} catch (XenAPIException e) {
14821484
details = "BackupSnapshot Failed due to " + e.toString();
14831485
s_logger.warn(details, e);
1484-
// remove last bad primary snapshot when exception happens
1485-
destroySnapshotOnPrimaryStorage(conn, snapshotUuid);
14861486
} catch (Exception e) {
14871487
details = "BackupSnapshot Failed due to " + e.getMessage();
14881488
s_logger.warn(details, e);
1489-
// remove last bad primary snapshot when exception happens
1490-
destroySnapshotOnPrimaryStorage(conn, snapshotUuid);
1489+
} finally {
1490+
if (!result) {
1491+
// remove last bad primary snapshot when exception happens
1492+
try {
1493+
destroySnapshotOnPrimaryStorage(conn, snapshotUuid);
1494+
} catch (Exception e) {
1495+
s_logger.debug("clean up snapshot failed", e);
1496+
}
1497+
}
14911498
}
14921499

14931500
return new CopyCmdAnswer(details);

0 commit comments

Comments
 (0)