cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From likit...@apache.org
Subject git commit: updated refs/heads/4.2 to 32b33be
Date Mon, 12 Aug 2013 10:20:09 GMT
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 <likitha.shetty@citrix.com>
Authored: Mon Aug 12 15:40:35 2013 +0530
Committer: Likitha Shetty <likitha.shetty@citrix.com>
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) {


Mime
View raw message