sureshanaparti commented on a change in pull request #2090: CLOUDSTACK-8415
[VMware] SSVM shutdown during snapshot operation results in disks to be left
behind
URL: https://github.com/apache/cloudstack/pull/2090#discussion_r116932353
##########
File path: server/src/com/cloud/storage/StorageManagerImpl.java
##########
@@ -1104,14 +1107,61 @@ public void cleanupStorage(boolean recurring) {
}
// remove snapshots in Error state
- List<SnapshotVO> snapshots =
_snapshotDao.listAllByStatus(Snapshot.State.Error);
+ List<SnapshotVO> snapshots =
_snapshotDao.listAllByStatusIncludingRemoved(Snapshot.State.Error);
for (SnapshotVO snapshotVO : snapshots) {
try {
List<SnapshotDataStoreVO> storeRefs =
_snapshotStoreDao.findBySnapshotId(snapshotVO.getId());
+ boolean isVMware =
snapshotVO.getHypervisorType().equals(HypervisorType.VMware);
+ boolean removeSnapshot = true;
for (SnapshotDataStoreVO ref : storeRefs) {
- _snapshotStoreDao.expunge(ref.getId());
+ // Cleanup corresponding items (if any) from
secondary storage.
+ if (isVMware) {
+ if (ref.getRole().isImageStore()) { //
Delete items from secondary storage
+ DataStore snapshotDataStore =
_dataStoreMgr.getDataStore(ref.getDataStoreId(), DataStoreRole.Image);
+ DeleteSnapshotsDirCommand cmd = new
DeleteSnapshotsDirCommand(snapshotDataStore.getTO(), ref.getInstallPath());
+ EndPoint ep =
_epSelector.select(snapshotDataStore);
+ if (ep == null) {
+ s_logger.warn("There is no
secondary storage VM for image store: " + snapshotDataStore.getName() + ",
cannot cleanup snapshot: "
+ + snapshotVO.getUuid());
+ removeSnapshot = false;
+ continue;
+ }
+ Answer deleteSnapshotsDirAnswer =
ep.sendMessage(cmd);
+ if ((deleteSnapshotsDirAnswer != null)
&& deleteSnapshotsDirAnswer.getResult()) {
+ s_logger.debug("Deleted snapshot:
" + snapshotVO.getUuid() + " from secondary storage: " +
snapshotDataStore.getName());
+
_snapshotStoreDao.expunge(ref.getId());
+ } else {
+ s_logger.warn("Failed to delete
snapshot: " + snapshotVO.getUuid() + " from secondary storage: " +
snapshotDataStore.getName());
+ removeSnapshot = false;
+ }
+ } else if (ref.getRole() ==
DataStoreRole.Primary) { // Delete worker VM snapshot
+ VolumeVO volume =
_volumeDao.findByIdIncludingRemoved(snapshotVO.getVolumeId());
+ if (volume.getInstanceId() == null)
+ continue;
+ VMInstanceVO vm =
_vmInstanceDao.findById(volume.getInstanceId());
+ Long hostId = vm.getHostId() != null ?
vm.getHostId() : vm.getLastHostId();
+ if (hostId != null) {
+ VMSnapshotTO vmSnapshotTO = new
VMSnapshotTO();
+
vmSnapshotTO.setSnapshotName(ref.getInstallPath());
+
vmSnapshotTO.setDescription(snapshotVO.getName());
+ DeleteVMSnapshotCommand
deleteSnapshotCommand = new DeleteVMSnapshotCommand(vm.getInstanceName(),
vmSnapshotTO, null, null);
+ Answer deleteSnapshotAnswer =
_agentMgr.send(hostId, deleteSnapshotCommand);
+ if ((deleteSnapshotAnswer != null)
&& deleteSnapshotAnswer.getResult()) {
+ s_logger.debug("Deleted worker
VM snapshot: " + snapshotVO.getName());
+
_snapshotStoreDao.expunge(ref.getId());
+ } else {
+ s_logger.warn("Failed to
delete worker VM snapshot: " + snapshotVO.getName());
+ removeSnapshot = false;
+ }
+ }
+ }
+ } else {
+ _snapshotStoreDao.expunge(ref.getId());
+ }
+ }
+ if (removeSnapshot) {
+ _snapshotDao.expunge(snapshotVO.getId());
Review comment:
@DaanHoogland moved to a private method `removeSnapshot()`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services