Skip to content

Commit bdd28a4

Browse files
author
Likitha Shetty
committed
CLOUDSTACK-8319. For both 'MigrateVolume' and 'MigrateVMWithVolumes, ensure VM's vconfiguration files are migrated along with VM's root volume.
1 parent adc836c commit bdd28a4

4 files changed

Lines changed: 63 additions & 13 deletions

File tree

‎core/src/com/cloud/agent/api/storage/MigrateVolumeCommand.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import com.cloud.agent.api.Command;
2323
import com.cloud.agent.api.to.StorageFilerTO;
2424
import com.cloud.storage.StoragePool;
25+
import com.cloud.storage.Volume;
2526

2627
public class MigrateVolumeCommand extends Command {
2728

2829
long volumeId;
2930
String volumePath;
3031
StorageFilerTO pool;
3132
String attachedVmName;
33+
Volume.Type volumeType;
3234

3335
public MigrateVolumeCommand(long volumeId, String volumePath, StoragePool pool, int timeout) {
3436
this.volumeId = volumeId;
@@ -37,11 +39,12 @@ public MigrateVolumeCommand(long volumeId, String volumePath, StoragePool pool,
3739
this.setWait(timeout);
3840
}
3941

40-
public MigrateVolumeCommand(long volumeId, String volumePath, StoragePool pool, String attachedVmName, int timeout) {
42+
public MigrateVolumeCommand(long volumeId, String volumePath, StoragePool pool, String attachedVmName, Volume.Type volumeType, int timeout) {
4143
this.volumeId = volumeId;
4244
this.volumePath = volumePath;
4345
this.pool = new StorageFilerTO(pool);
4446
this.attachedVmName = attachedVmName;
47+
this.volumeType = volumeType;
4548
this.setWait(timeout);
4649
}
4750

@@ -65,4 +68,8 @@ public StorageFilerTO getPool() {
6568
public String getAttachedVmName() {
6669
return attachedVmName;
6770
}
71+
72+
public Volume.Type getVolumeType() {
73+
return volumeType;
74+
}
6875
}

‎engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
389389

390390
VolumeInfo volume = (VolumeInfo)srcData;
391391
StoragePool destPool = (StoragePool)dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
392-
MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool, volume.getAttachedVmName(), waitInterval);
392+
MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool, volume.getAttachedVmName(), volume.getVolumeType(), waitInterval);
393393
EndPoint ep = selector.select(srcData, StorageAction.MIGRATEVOLUME);
394394
Answer answer = null;
395395
if (ep == null) {

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3023,7 +3023,6 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
30233023
List<VirtualMachineRelocateSpecDiskLocator> diskLocators = new ArrayList<VirtualMachineRelocateSpecDiskLocator>();
30243024
VirtualMachineRelocateSpecDiskLocator diskLocator = null;
30253025

3026-
boolean isFirstDs = true;
30273026
String tgtDsName = "";
30283027
String tgtDsHost;
30293028
String tgtDsPath;
@@ -3112,9 +3111,8 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
31123111
morTgtDatastore = morDsAtSource;
31133112
}
31143113

3115-
if (isFirstDs) {
3114+
if (volume.getType() == Volume.Type.ROOT) {
31163115
relocateSpec.setDatastore(morTgtDatastore);
3117-
isFirstDs = false;
31183116
}
31193117
diskLocator = new VirtualMachineRelocateSpecDiskLocator();
31203118
diskLocator.setDatastore(morTgtDatastore);
@@ -3124,6 +3122,18 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
31243122
diskLocators.add(diskLocator);
31253123
volumeDeviceKey.put(volume.getId(), diskId);
31263124
}
3125+
// If a target datastore is provided for the VM, then by default all volumes associated with the VM will be migrated to that target datastore.
3126+
// Hence set the existing datastore as target datastore for volumes that are not to be migrated.
3127+
List<Pair<Integer, ManagedObjectReference>> diskDatastores = vmMo.getAllDiskDatastores();
3128+
for (Pair<Integer, ManagedObjectReference> diskDatastore : diskDatastores) {
3129+
if (!volumeDeviceKey.containsValue(diskDatastore.first().intValue())) {
3130+
diskLocator = new VirtualMachineRelocateSpecDiskLocator();
3131+
diskLocator.setDiskId(diskDatastore.first().intValue());
3132+
diskLocator.setDatastore(diskDatastore.second());
3133+
diskLocators.add(diskLocator);
3134+
}
3135+
}
3136+
31273137
relocateSpec.getDisk().addAll(diskLocators);
31283138

31293139
// Prepare network at target before migration
@@ -3225,6 +3235,7 @@ protected Answer execute(MigrateWithStorageCommand cmd) {
32253235
private Answer execute(MigrateVolumeCommand cmd) {
32263236
String volumePath = cmd.getVolumePath();
32273237
StorageFilerTO poolTo = cmd.getPool();
3238+
Volume.Type volumeType = cmd.getVolumeType();
32283239

32293240
if (s_logger.isInfoEnabled()) {
32303241
s_logger.info("Executing resource MigrateVolumeCommand: " + _gson.toJson(cmd));
@@ -3271,9 +3282,23 @@ private Answer execute(MigrateVolumeCommand cmd) {
32713282
diskLocator = new VirtualMachineRelocateSpecDiskLocator();
32723283
diskLocator.setDatastore(morDs);
32733284
diskLocator.setDiskId(diskId);
3274-
32753285
diskLocators.add(diskLocator);
3276-
relocateSpec.getDisk().add(diskLocator);
3286+
if (cmd.getVolumeType() == Volume.Type.ROOT) {
3287+
relocateSpec.setDatastore(morDs);
3288+
// If a target datastore is provided for the VM, then by default all volumes associated with the VM will be migrated to that target datastore.
3289+
// Hence set the existing datastore as target datastore for volumes that are not to be migrated.
3290+
List<Pair<Integer, ManagedObjectReference>> diskDatastores = vmMo.getAllDiskDatastores();
3291+
for (Pair<Integer, ManagedObjectReference> diskDatastore : diskDatastores) {
3292+
if (diskDatastore.first().intValue() != diskId) {
3293+
diskLocator = new VirtualMachineRelocateSpecDiskLocator();
3294+
diskLocator.setDiskId(diskDatastore.first().intValue());
3295+
diskLocator.setDatastore(diskDatastore.second());
3296+
diskLocators.add(diskLocator);
3297+
}
3298+
}
3299+
}
3300+
3301+
relocateSpec.getDisk().addAll(diskLocators);
32773302

32783303
// Change datastore
32793304
if (!vmMo.changeDatastore(relocateSpec)) {
@@ -3286,12 +3311,10 @@ private Answer execute(MigrateVolumeCommand cmd) {
32863311
// In case of a linked clone VM, if VM's disks are not consolidated,
32873312
// further volume operations on the ROOT volume such as volume snapshot etc. will result in DB inconsistencies.
32883313
String apiVersion = HypervisorHostHelper.getVcenterApiVersion(vmMo.getContext());
3289-
if (apiVersion.compareTo("5.0") >= 0) {
3290-
if (!vmMo.consolidateVmDisks()) {
3291-
s_logger.warn("VM disk consolidation failed after storage migration.");
3292-
} else {
3293-
s_logger.debug("Successfully consolidated disks of VM " + vmName + ".");
3294-
}
3314+
if (!vmMo.consolidateVmDisks()) {
3315+
s_logger.warn("VM disk consolidation failed after storage migration.");
3316+
} else {
3317+
s_logger.debug("Successfully consolidated disks of VM " + vmName + ".");
32953318
}
32963319

32973320
// Update and return volume path because that could have changed after migration

‎vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,26 @@ public VirtualMachineDiskInfoBuilder getDiskInfoBuilder() throws Exception {
20692069
return builder;
20702070
}
20712071

2072+
public List<Pair<Integer, ManagedObjectReference>> getAllDiskDatastores() throws Exception {
2073+
List<Pair<Integer, ManagedObjectReference>> disks = new ArrayList<Pair<Integer, ManagedObjectReference>>();
2074+
2075+
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
2076+
if (devices != null && devices.size() > 0) {
2077+
for (VirtualDevice device : devices) {
2078+
if (device instanceof VirtualDisk) {
2079+
VirtualDeviceBackingInfo backingInfo = ((VirtualDisk)device).getBacking();
2080+
if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
2081+
VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo)backingInfo;
2082+
disks.add(new Pair<Integer, ManagedObjectReference>(new Integer(device.getKey()), diskBackingInfo.getDatastore()));
2083+
}
2084+
}
2085+
}
2086+
}
2087+
2088+
return disks;
2089+
}
2090+
2091+
20722092
@Deprecated
20732093
public List<Pair<String, ManagedObjectReference>> getDiskDatastorePathChain(VirtualDisk disk, boolean followChain) throws Exception {
20742094
VirtualDeviceBackingInfo backingInfo = disk.getBacking();

0 commit comments

Comments
 (0)