You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by li...@apache.org on 2014/02/26 07:49:36 UTC

[1/2] git commit: updated refs/heads/4.3-forward to 8cb03dd

Repository: cloudstack
Updated Branches:
  refs/heads/4.3-forward 20efa0c8a -> 8cb03ddb2


CLOUDSTACK-6146. [VMware] [ESXi 5.5] Live storage migration of an already migrated volume fails
In vCenter 5.5, once a volume is migrated the VMDKs are renamed to match the name of the VM.
If a volume has been renamed upon migration update its volumePath to that of the new disk filename.


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

Branch: refs/heads/4.3-forward
Commit: c652ff45dffaafa1cb0de29103e90fe936382028
Parents: 20efa0c
Author: Likitha Shetty <li...@citrix.com>
Authored: Mon Feb 24 10:12:58 2014 +0530
Committer: Likitha Shetty <li...@citrix.com>
Committed: Wed Feb 26 11:58:20 2014 +0530

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java           | 17 +++++++++++++----
 .../hypervisor/vmware/mo/VirtualMachineMO.java    | 18 ++++++++++++------
 2 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c652ff45/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index d1fea92..d27d81f 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -4517,12 +4517,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                 throw new Exception(msg);
             }
 
-            VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(
-                    new DatastoreMO(srcHyperHost.getContext(), morDs), vmName,
-                    volumePath + ".vmdk");
+            DatastoreMO targetDsMo = new DatastoreMO(srcHyperHost.getContext(), morDs);
+            String fullVolumePath = VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(targetDsMo, vmName, volumePath + ".vmdk");
+            int diskId = getVirtualDiskInfo(vmMo, volumePath + ".vmdk");
             diskLocator = new VirtualMachineRelocateSpecDiskLocator();
             diskLocator.setDatastore(morDs);
-            diskLocator.setDiskId(getVirtualDiskInfo(vmMo, volumePath + ".vmdk"));
+            diskLocator.setDiskId(diskId);
 
             diskLocators.add(diskLocator);
             relocateSpec.getDisk().add(diskLocator);
@@ -4534,6 +4534,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                 s_logger.debug("Successfully migrated volume " + volumePath + " to target datastore " + tgtDsName);
             }
 
+            // Update and return volume path because that could have changed after migration
+            if (!targetDsMo.fileExists(fullVolumePath)) {
+                VirtualDisk[] disks = vmMo.getAllDiskDevice();
+                for (VirtualDisk disk : disks)
+                    if (disk.getKey() == diskId) {
+                        volumePath = vmMo.getVmdkFileBaseName(disk);
+                    }
+            }
+
             return new MigrateVolumeAnswer(cmd, true, null, volumePath);
         } catch (Exception e) {
             String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c652ff45/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index e4e2712..69a7e50 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -1783,17 +1783,23 @@ public class VirtualMachineMO extends BaseMO {
         VirtualDevice[] devices = getAllDiskDevice();
         for(VirtualDevice device : devices) {
             if(device instanceof VirtualDisk) {
-                VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
-                if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
-                    VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
-                    DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
-                    vmdkFileBaseNames.add(dsBackingFile.getFileBaseName());
-                }
+                vmdkFileBaseNames.add(getVmdkFileBaseName((VirtualDisk)device));
             }
         }
         return vmdkFileBaseNames;
     }
 
+    public String getVmdkFileBaseName(VirtualDisk disk) throws Exception {
+        String vmdkFileBaseName = null;
+        VirtualDeviceBackingInfo backingInfo = disk.getBacking();
+        if(backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
+            VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
+            DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
+            vmdkFileBaseName = dsBackingFile.getFileBaseName();
+        }
+        return vmdkFileBaseName;
+    }
+
 	// this method relies on un-offical VMware API
 	@Deprecated
 	public void moveAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean followDiskChain) throws Exception {


[2/2] git commit: updated refs/heads/4.3-forward to 8cb03dd

Posted by li...@apache.org.
CLOUDSTACK-6146. [VMware] [ESXi 5.5] Live VM migration of an already migrated VM (with storage) across clusters fails
In vCenter 5.5, once a volume is migrated the VMDKs are renamed to match the name of the VM.
Update volume path for every volume belonging to the VM to the corresponding new disk filename.


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

Branch: refs/heads/4.3-forward
Commit: 8cb03ddb2387c7aebf20dc0aa011e41f227e9f68
Parents: c652ff4
Author: Likitha Shetty <li...@citrix.com>
Authored: Tue Feb 25 18:10:52 2014 +0530
Committer: Likitha Shetty <li...@citrix.com>
Committed: Wed Feb 26 11:58:49 2014 +0530

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java         | 25 ++++++++++++--
 .../motion/VmwareStorageMotionStrategy.java     | 36 +++++++++++++-------
 2 files changed, 45 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8cb03ddb/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index d27d81f..9f5cf04 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -4338,6 +4338,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
         VolumeTO volume;
         StorageFilerTO filerTo;
         Set<String> mountedDatastoresAtSource = new HashSet<String>();
+        List<VolumeObjectTO> volumeToList =  new ArrayList<VolumeObjectTO>();
+        Map<Long, Integer> volumeDeviceKey = new HashMap<Long, Integer>();
 
         Map<VolumeTO, StorageFilerTO> volToFiler = cmd.getVolumeToFiler();
         String tgtHost = cmd.getTargetHost();
@@ -4402,9 +4404,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                         volume.getPath() + ".vmdk");
                 diskLocator = new VirtualMachineRelocateSpecDiskLocator();
                 diskLocator.setDatastore(morDsAtSource);
-                diskLocator.setDiskId(getVirtualDiskInfo(vmMo, volume.getPath() + ".vmdk"));
+                int diskId = getVirtualDiskInfo(vmMo, volume.getPath() + ".vmdk");
+                diskLocator.setDiskId(diskId);
 
                 diskLocators.add(diskLocator);
+                volumeDeviceKey.put(volume.getId(), diskId);
 
             }
             relocateSpec.getDisk().addAll(diskLocators);
@@ -4436,6 +4440,22 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
                 s_logger.debug("Successfully migrated storage of VM " + vmName + " to target datastore(s)");
             }
 
+            // Update and return volume path for every disk because that could have changed after migration
+            for (Entry<VolumeTO, StorageFilerTO> entry : volToFiler.entrySet()) {
+                volume = entry.getKey();
+                long volumeId = volume.getId();
+                VirtualDisk[] disks = vmMo.getAllDiskDevice();
+                for (VirtualDisk disk : disks) {
+                    if (volumeDeviceKey.get(volumeId) == disk.getKey()) {
+                        VolumeObjectTO newVol = new VolumeObjectTO();
+                        newVol.setId(volumeId);
+                        newVol.setPath(vmMo.getVmdkFileBaseName(disk));
+                        volumeToList.add(newVol);
+                        break;
+                    }
+                }
+            }
+
             // Change host
             ManagedObjectReference morPool = tgtHyperHost.getHyperHostOwnerResourcePool();
             if (!vmMo.migrate(morPool, tgtHyperHost.getMor())) {
@@ -4445,7 +4465,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
             }
 
             state = State.Stopping;
-            List<VolumeObjectTO> volumeToList = null;
             return new MigrateWithStorageAnswer(cmd, volumeToList);
         } catch (Throwable e) {
             if (e instanceof RemoteException) {
@@ -4552,7 +4571,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
     }
 
     private int getVirtualDiskInfo(VirtualMachineMO vmMo, String srcDiskName) throws Exception {
-        Pair<VirtualDisk, String> deviceInfo = vmMo.getDiskDevice(srcDiskName, false);
+        Pair<VirtualDisk, String> deviceInfo = vmMo.getDiskDevice(srcDiskName, true);
         if(deviceInfo == null) {
             throw new Exception("No such disk device: " + srcDiskName);
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8cb03ddb/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java b/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java
index 446093f..3c4d704 100644
--- a/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java
+++ b/plugins/hypervisors/vmware/src/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java
@@ -20,6 +20,7 @@
 package org.apache.cloudstack.storage.motion;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.inject.Inject;
@@ -33,6 +34,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -143,7 +145,7 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy {
                         ". " + migrateWithStorageAnswer.getDetails());
             } else {
                 // Update the volume details after migration.
-                updateVolumesAfterMigration(volumeToPool);
+                updateVolumesAfterMigration(volumeToPool, migrateWithStorageAnswer.getVolumeTos());
             }
             s_logger.debug("Storage migration of VM " + vm.getInstanceName() + " completed successfully. Migrated to host " + destHost.getName());
 
@@ -178,7 +180,7 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy {
                         ". " + answer.getDetails());
             } else {
                 // Update the volume details after migration.
-                updateVolumesAfterMigration(volumeToPool);
+                updateVolumesAfterMigration(volumeToPool, answer.getVolumeTos());
             }
 
             return answer;
@@ -188,20 +190,28 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy {
         }
     }
 
-    private void updateVolumesAfterMigration(Map<VolumeInfo, DataStore> volumeToPool) {
+    private void updateVolumesAfterMigration(Map<VolumeInfo, DataStore> volumeToPool, List<VolumeObjectTO> volumeTos) {
         for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
+            boolean updated = false;
             VolumeInfo volume = entry.getKey();
             StoragePool pool = (StoragePool)entry.getValue();
-
-            VolumeVO volumeVO = volDao.findById(volume.getId());
-            Long oldPoolId = volumeVO.getPoolId();
-            volumeVO.setLastPoolId(oldPoolId);
-            volumeVO.setFolder(pool.getPath());
-            volumeVO.setPodId(pool.getPodId());
-            volumeVO.setPoolId(pool.getId());
-
-            volDao.update(volume.getId(), volumeVO);
-            s_logger.debug("Volume path was successfully updated for volume " + volume.getName() + " after it was migrated.");
+            for (VolumeObjectTO volumeTo : volumeTos) {
+                if (volume.getId() == volumeTo.getId()) {
+                    VolumeVO volumeVO = volDao.findById(volume.getId());
+                    Long oldPoolId = volumeVO.getPoolId();
+                    volumeVO.setPath(volumeTo.getPath());
+                    volumeVO.setLastPoolId(oldPoolId);
+                    volumeVO.setFolder(pool.getPath());
+                    volumeVO.setPodId(pool.getPodId());
+                    volumeVO.setPoolId(pool.getId());
+                    volDao.update(volume.getId(), volumeVO);
+                    updated = true;
+                    break;
+                }
+            }
+            if (!updated) {
+                s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated.");
+            }
         }
     }
 }