From cc4b612bf604addb1ad903ef8adc504c569abe55 Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Tue, 29 Oct 2013 11:11:50 +0530 Subject: [PATCH] CLOUDSTACK-4985. NPE while deleting old root volumes of a restored VM during storage garbage collection. In case of VMware, once the state of the old root volume has been updated to destroyed force expunge it from primary storage to avoid the garbage collector from trying to delete the new root volume --- .../src/com/cloud/vm/UserVmManagerImpl.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index e97dfd798a1..f20278498ac 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -73,6 +73,10 @@ import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.managed.context.ManagedContextRunnable; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult; +import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.to.TemplateObjectTO; @@ -437,6 +441,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir PlannerHostReservationDao _plannerHostReservationDao; @Inject private ServiceOfferingDetailsDao serviceOfferingDetailsDao; + @Inject + VolumeService _volService; + @Inject + VolumeDataFactory volFactory; protected ScheduledExecutorService _executor = null; protected int _expungeInterval; @@ -4914,6 +4922,17 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir _volsDao.detachVolume(root.getId()); volumeMgr.destroyVolume(root); + // For VMware hypervisor since the old root volume is replaced by the new root volume in storage, force expunge old root volume + if (vm.getHypervisorType() == HypervisorType.VMware) { + s_logger.info("Expunging volume " + root.getId() + " from primary data store"); + AsyncCallFuture future = _volService.expungeVolumeAsync(volFactory.getVolume(root.getId())); + try { + future.get(); + } catch (Exception e) { + s_logger.debug("Failed to expunge volume:" + root.getId(), e); + } + } + if (template.getEnablePassword()) { String password = generateRandomPassword(); boolean result = resetVMPasswordInternal(vmId, password);