Skip to content

Commit 9cb37ec

Browse files
author
Likitha Shetty
committed
CLOUDSTACK-6007. Restore VM command fails with NPE.
If a VM instance is deployed with startVm=false, then calling restoreVm on the instance fails with NPE because CS tries to expunge a volume that has not been created in primary store.
1 parent 9cb2458 commit 9cb37ec

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
7272
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
7373
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
74+
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
7475
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
7576
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
7677
import org.apache.cloudstack.framework.async.AsyncCallFuture;
@@ -4737,14 +4738,17 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
47374738
_volsDao.detachVolume(root.getId());
47384739
volumeMgr.destroyVolume(root);
47394740

4740-
// For VMware hypervisor since the old root volume is replaced by the new root volume in storage, force expunge old root volume
4741+
// For VMware hypervisor since the old root volume is replaced by the new root volume, force expunge old root volume if it has been created in storage
47414742
if (vm.getHypervisorType() == HypervisorType.VMware) {
4742-
s_logger.info("Expunging volume " + root.getId() + " from primary data store");
4743-
AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId()));
4744-
try {
4745-
future.get();
4746-
} catch (Exception e) {
4747-
s_logger.debug("Failed to expunge volume:" + root.getId(), e);
4743+
VolumeInfo volumeInStorage = volFactory.getVolume(root.getId());
4744+
if (volumeInStorage != null) {
4745+
s_logger.info("Expunging volume " + root.getId() + " from primary data store");
4746+
AsyncCallFuture<VolumeApiResult> future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId()));
4747+
try {
4748+
future.get();
4749+
} catch (Exception e) {
4750+
s_logger.debug("Failed to expunge volume:" + root.getId(), e);
4751+
}
47484752
}
47494753
}
47504754

0 commit comments

Comments
 (0)