Skip to content

Commit 970a0cc

Browse files
VMSnapshot is being stuck in expunging state (#80)
* AC-139 VMSnapshot is being stuck in expunging state * Added global timeout value to take affect while executing script
1 parent 95df0fe commit 970a0cc

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

api/src/com/cloud/vm/snapshot/VMSnapshot.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public String getDescription() {
5959
s_fsm.addTransition(Error, Event.ExpungeRequested, Expunging);
6060
s_fsm.addTransition(Expunging, Event.ExpungeRequested, Expunging);
6161
s_fsm.addTransition(Expunging, Event.OperationSucceeded, Removed);
62+
s_fsm.addTransition(Expunging, Event.OperationFailed, Error);
6263
}
6364
}
6465

engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) {
242242
} else {
243243
String errMsg = (answer == null) ? null : answer.getDetails();
244244
s_logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
245+
processAnswer(vmSnapshotVO, userVm, answer, hostId);
245246
throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
246247
}
247248
} catch (OperationTimedoutException e) {
@@ -266,9 +267,13 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws NoTran
266267
finalizeRevert(vmSnapshot, answer.getVolumeTOs());
267268
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationSucceeded);
268269
} else if (as instanceof DeleteVMSnapshotAnswer) {
269-
DeleteVMSnapshotAnswer answer = (DeleteVMSnapshotAnswer)as;
270-
finalizeDelete(vmSnapshot, answer.getVolumeTOs());
271-
vmSnapshotDao.remove(vmSnapshot.getId());
270+
if (as.getResult()) {
271+
DeleteVMSnapshotAnswer answer = (DeleteVMSnapshotAnswer)as;
272+
finalizeDelete(vmSnapshot, answer.getVolumeTOs());
273+
vmSnapshotDao.remove(vmSnapshot.getId());
274+
} else {
275+
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
276+
}
272277
}
273278
}
274279
});

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ private static String removeVolumeSnapshots(DeleteVMSnapshotCommand cmd, KVMStor
136136
if (ImageFormat.QCOW2.equals(volume.getFormat())) {
137137
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
138138
KVMPhysicalDisk disk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), volume.getPath());
139-
String qemu_img_snapshot = Script.runSimpleBashScript("qemu-img snapshot -l " + disk.getPath() + " | tail -n +3 | awk -F ' ' '{print $2}' | grep ^" + cmd.getTarget().getSnapshotName() + "$");
139+
int timeout = cmd.getWait();
140+
String qemu_img_snapshot = Script.runSimpleBashScript("qemu-img snapshot -l " + disk.getPath() + " | tail -n +3 | awk -F ' ' '{print $2}' | grep ^" + cmd.getTarget().getSnapshotName() + "$", timeout);
140141
if (qemu_img_snapshot == null) {
141142
s_logger.info("Cannot find snapshot " + cmd.getTarget().getSnapshotName() + " in file " + disk.getPath());
142-
}
143-
int result = Script.runSimpleBashScriptForExitValue("qemu-img snapshot -d " + cmd.getTarget().getSnapshotName() + " " + disk.getPath());
144-
if (result != 0) {
145-
ret.add("Delete VM Snapshot Failed due to can not remove snapshot from image file " + disk.getPath() + " : " + result);
143+
} else {
144+
int result = Script.runSimpleBashScriptForExitValue("qemu-img snapshot -d " + cmd.getTarget().getSnapshotName() + " " + disk.getPath(), timeout);
145+
if (result != 0) {
146+
ret.add("Delete VM Snapshot Failed due to can not remove snapshot from image file " + disk.getPath() + " : " + result);
147+
}
146148
}
147149
}
148150
}

0 commit comments

Comments
 (0)