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
This commit is contained in:
Likitha Shetty 2013-10-29 11:11:50 +05:30
parent 6be228a438
commit cc4b612bf6
1 changed files with 19 additions and 0 deletions

View File

@ -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<VolumeApiResult> 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);