You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by de...@apache.org on 2013/07/23 07:30:16 UTC

git commit: updated refs/heads/master to 7dec27e

Updated Branches:
  refs/heads/master 51377c40f -> 7dec27e84


CLOUDSTACK-3708, Migration of a volume attached to a running instance isn't working (Storage motion).
The request to migrate was coming till ancient data motion strategy but wasn't worked on and forwarded
to the resource. The code probably got removed by a bad merge. Bringing it back.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7dec27e8
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7dec27e8
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7dec27e8

Branch: refs/heads/master
Commit: 7dec27e84479bf89cc13cb4121bf5f864a58c689
Parents: 51377c4
Author: Devdeep Singh <de...@gmail.com>
Authored: Mon Jul 22 15:46:43 2013 +0530
Committer: Devdeep Singh <de...@gmail.com>
Committed: Tue Jul 23 10:49:51 2013 +0530

----------------------------------------------------------------------
 .../motion/AncientDataMotionStrategy.java       | 34 +++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7dec27e8/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
index 00c693f..e17306a 100644
--- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
@@ -49,6 +49,8 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.storage.MigrateVolumeAnswer;
+import com.cloud.agent.api.storage.MigrateVolumeCommand;
 import com.cloud.agent.api.to.DataObjectType;
 import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.DataTO;
@@ -64,6 +66,7 @@ import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.StorageManager;
 import com.cloud.storage.StoragePool;
 import com.cloud.storage.VolumeManager;
+import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.VMTemplateDao;
@@ -330,6 +333,30 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
 
     }
 
+    protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
+        VolumeInfo volume = (VolumeInfo)srcData;
+        StoragePool destPool = (StoragePool)this.dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
+        MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool);
+        EndPoint ep = selector.select(volume.getDataStore());
+        MigrateVolumeAnswer answer = (MigrateVolumeAnswer) ep.sendMessage(command);
+
+        if (answer == null || !answer.getResult()) {
+            throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool);
+        } else {
+            // Update the volume details after migration.
+            VolumeVO volumeVo = this.volDao.findById(volume.getId());
+            Long oldPoolId = volume.getPoolId();
+            volumeVo.setPath(answer.getVolumePath());
+            volumeVo.setFolder(destPool.getPath());
+            volumeVo.setPodId(destPool.getPodId());
+            volumeVo.setPoolId(destPool.getId());
+            volumeVo.setLastPoolId(oldPoolId);
+            this.volDao.update(volume.getId(), volumeVo);
+        }
+
+        return answer;
+    }
+
     @Override
     public Void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
         Answer answer = null;
@@ -347,7 +374,12 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
             } else if (destData.getType() == DataObjectType.VOLUME && srcData.getType() == DataObjectType.VOLUME
                     && srcData.getDataStore().getRole() == DataStoreRole.Primary
                     && destData.getDataStore().getRole() == DataStoreRole.Primary) {
-                answer = copyVolumeBetweenPools(srcData, destData);
+                if (srcData.getId() == destData.getId()) {
+                    // The volume has to be migrated across storage pools.
+                    answer = migrateVolumeToPool(srcData, destData);
+                } else {
+                    answer = copyVolumeBetweenPools(srcData, destData);
+                }
             } else if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.SNAPSHOT) {
                 answer = copySnapshot(srcData, destData);
             } else {