From ee598d44c5a0e822608da537afa9d302709d4531 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 c7079b4e39f..c3d902b382a 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); @@ -2532,7 +2536,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)) { @@ -2581,12 +2585,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 730262b2dc7..4b7e32df935 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -597,10 +597,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; } }