From 6e39019b6a0723900c490cd0f20109b797eb5419 Mon Sep 17 00:00:00 2001 From: prachi Date: Tue, 26 Apr 2011 11:35:24 -0700 Subject: [PATCH] Bug 9548 [Cloud Stack Upgrade - 2.1.8 to 2.2.4] System VM's Volumes Recreation is not happening on an event of New Volume creation Failures Changes: - Reason was that the old volume's templateId was being updated before volume creation was attempted. So on the retry, we dint find a difference in volume's templateId and VM's templateId and did not enter the recreation logic. - Fix is to update the new volume's templateId with the VM's templateId while creating the new volume. The old volume's templateId stays the same and the volume is marked as 'Destroy' when a new volume is created. --- .../com/cloud/storage/StorageManagerImpl.java | 24 +++++++++++++++---- .../cloud/vm/VirtualMachineManagerImpl.java | 4 +--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 4dd971591ec..edaf2a50881 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -326,9 +326,13 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag return true; } - VolumeVO allocateDuplicateVolume(VolumeVO oldVol) { + VolumeVO allocateDuplicateVolume(VolumeVO oldVol, Long templateId) { VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize()); - newVol.setTemplateId(oldVol.getTemplateId()); + if(templateId != null){ + newVol.setTemplateId(templateId); + }else{ + newVol.setTemplateId(oldVol.getTemplateId()); + } newVol.setDeviceId(oldVol.getDeviceId()); newVol.setInstanceId(oldVol.getInstanceId()); return _volsDao.persist(newVol); @@ -2548,7 +2552,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag vol.setRecreatable(true); newVol = vol; } else { - newVol = switchVolume(vol); + newVol = switchVolume(vol, vm); newVol.setRecreatable(true); // update the volume->storagePool map since volumeId has changed if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) { @@ -2597,12 +2601,22 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag } @DB - protected VolumeVO switchVolume(VolumeVO existingVolume) throws StorageUnavailableException { + protected VolumeVO switchVolume(VolumeVO existingVolume, VirtualMachineProfile vm) throws StorageUnavailableException { Transaction txn = Transaction.currentTxn(); try { txn.start(); _volsDao.update(existingVolume, Volume.Event.Destroy); - VolumeVO newVolume = allocateDuplicateVolume(existingVolume); + + Long templateIdToUse = null; + Long volTemplateId = existingVolume.getTemplateId(); + long vmTemplateId = vm.getTemplateId(); + if (volTemplateId != null && volTemplateId.longValue() != vmTemplateId) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("switchVolume: Old Volume's templateId: "+volTemplateId + " does not match the VM's templateId: "+vmTemplateId+", updating templateId in the new Volume"); + } + templateIdToUse = vmTemplateId; + } + VolumeVO newVolume = allocateDuplicateVolume(existingVolume, templateIdToUse); txn.commit(); return newVolume; } catch (ConcurrentOperationException e) { diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 8b636f806f2..b1f1ea375c8 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -598,10 +598,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene if (volTemplateId.longValue() != template.getId()) { if (s_logger.isDebugEnabled()) { s_logger.debug("Root Volume " + vol + " of " + vm.getType().toString() - + " System VM is ready, but volume's templateId does not match the System VM Template, updating templateId and reassigning a new pool"); + + " System VM is ready, but volume's templateId does not match the System VM Template, let the planner reassign a new pool"); } - vol.setTemplateId(template.getId()); - _volsDao.update(vol.getId(), vol); continue; } }