Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F123210949 for ; Mon, 12 Aug 2013 10:20:11 +0000 (UTC) Received: (qmail 23107 invoked by uid 500); 12 Aug 2013 10:20:11 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 23081 invoked by uid 500); 12 Aug 2013 10:20:11 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 23074 invoked by uid 99); 12 Aug 2013 10:20:09 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Aug 2013 10:20:09 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 24B248BC530; Mon, 12 Aug 2013 10:20:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: likithas@apache.org To: commits@cloudstack.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/4.2 to 32b33be Date: Mon, 12 Aug 2013 10:20:09 +0000 (UTC) Updated Branches: refs/heads/4.2 32fd0c94a -> 32b33bea0 CLOUDSTACK-4244. Unable to attach a volume to a VM deployed in Stopped (startvm=false) state. While attaching a volume to a VM, create volume on the hypervisor only if the VM has been started on the it. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/32b33bea Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/32b33bea Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/32b33bea Branch: refs/heads/4.2 Commit: 32b33bea0fe1e823d5f5202be02c4894fc194d97 Parents: 32fd0c9 Author: Likitha Shetty Authored: Mon Aug 12 15:40:35 2013 +0530 Committer: Likitha Shetty Committed: Mon Aug 12 15:45:02 2013 +0530 ---------------------------------------------------------------------- .../com/cloud/storage/VolumeManagerImpl.java | 89 ++++++++++++-------- 1 file changed, 55 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/32b33bea/server/src/com/cloud/storage/VolumeManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index 235b970..48dda36 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -1834,46 +1834,67 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { deviceId = getDeviceId(vmId, deviceId); VolumeInfo volumeOnPrimaryStorage = volume; - if (volume.getState().equals(Volume.State.Allocated) - || volume.getState() == Volume.State.Uploaded) { - try { - volumeOnPrimaryStorage = createVolumeOnPrimaryStorage(vm, rootVolumeOfVm, volume, rootDiskHyperType); - } catch (NoTransitionException e) { - s_logger.debug("Failed to create volume on primary storage", e); - throw new CloudRuntimeException("Failed to create volume on primary storage", e); - } - } - // reload the volume from db - volumeOnPrimaryStorage = volFactory.getVolume(volumeOnPrimaryStorage.getId()); - boolean moveVolumeNeeded = needMoveVolume(rootVolumeOfVm, volumeOnPrimaryStorage); - - if (moveVolumeNeeded) { - PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo)volumeOnPrimaryStorage.getDataStore(); - if (primaryStore.isLocal()) { - throw new CloudRuntimeException( - "Failed to attach local data volume " - + volume.getName() - + " to VM " - + vm.getDisplayName() - + " as migration of local data volume is not allowed"); + // Check if volume is stored on secondary storage + boolean isVolumeOnSec = false; + VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image); + if (volOnSecondary != null) { + isVolumeOnSec = true; + if(volOnSecondary.getState() != Volume.State.Uploaded) { + throw new InvalidParameterValueException("Volume is not uploaded yet. Please try this operation once the volume is uploaded"); + } + } + + boolean createVolumeOnBackend = true; + if (rootVolumeOfVm.getState() == Volume.State.Allocated) { + createVolumeOnBackend = false; + if(isVolumeOnSec) { + throw new CloudRuntimeException("Cant attach uploaded volume to the vm which is not created. Please start it and then retry"); + } + } + + // Create volume on the backend only when VM's root volume is allocated + if (createVolumeOnBackend) { + if (volume.getState().equals(Volume.State.Allocated) + || volume.getState() == Volume.State.Uploaded) { + try { + volumeOnPrimaryStorage = createVolumeOnPrimaryStorage(vm, rootVolumeOfVm, volume, rootDiskHyperType); + } catch (NoTransitionException e) { + s_logger.debug("Failed to create volume on primary storage", e); + throw new CloudRuntimeException("Failed to create volume on primary storage", e); + } } - StoragePoolVO vmRootVolumePool = _storagePoolDao - .findById(rootVolumeOfVm.getPoolId()); - try { - volumeOnPrimaryStorage = moveVolume(volumeOnPrimaryStorage, - vmRootVolumePool.getDataCenterId(), - vmRootVolumePool.getPodId(), - vmRootVolumePool.getClusterId(), - dataDiskHyperType); - } catch (ConcurrentOperationException e) { - s_logger.debug("move volume failed", e); - throw new CloudRuntimeException("move volume failed", e); + // reload the volume from db + volumeOnPrimaryStorage = volFactory.getVolume(volumeOnPrimaryStorage.getId()); + boolean moveVolumeNeeded = needMoveVolume(rootVolumeOfVm, volumeOnPrimaryStorage); + + if (moveVolumeNeeded) { + PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo)volumeOnPrimaryStorage.getDataStore(); + if (primaryStore.isLocal()) { + throw new CloudRuntimeException( + "Failed to attach local data volume " + + volume.getName() + + " to VM " + + vm.getDisplayName() + + " as migration of local data volume is not allowed"); + } + StoragePoolVO vmRootVolumePool = _storagePoolDao + .findById(rootVolumeOfVm.getPoolId()); + + try { + volumeOnPrimaryStorage = moveVolume(volumeOnPrimaryStorage, + vmRootVolumePool.getDataCenterId(), + vmRootVolumePool.getPodId(), + vmRootVolumePool.getClusterId(), + dataDiskHyperType); + } catch (ConcurrentOperationException e) { + s_logger.debug("move volume failed", e); + throw new CloudRuntimeException("move volume failed", e); + } } } - AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor .getCurrentExecutor(); if (asyncExecutor != null) {