Skip to content

Commit a69ab3b

Browse files
authored
Ensure configdrive path is edited properly during live migration (#6173)
1 parent 908f594 commit a69ab3b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,25 +2722,25 @@ public String getVolumePath(final Connect conn, final DiskTO volume) throws Libv
27222722
public String getVolumePath(final Connect conn, final DiskTO volume, boolean diskOnHostCache) throws LibvirtException, URISyntaxException {
27232723
final DataTO data = volume.getData();
27242724
final DataStoreTO store = data.getDataStore();
2725+
final String dataPath = data.getPath();
27252726

2726-
if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO ||
2727-
store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload())) {
2728-
2729-
if (data.getPath().startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) {
2730-
String configDrivePath = getConfigPath() + "/" + data.getPath();
2731-
return configDrivePath;
2727+
if (volume.getType() == Volume.Type.ISO && dataPath != null) {
2728+
if (dataPath.startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) {
2729+
return getConfigPath() + "/" + data.getPath();
27322730
}
27332731

2734-
final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath();
2735-
final int index = isoPath.lastIndexOf("/");
2736-
final String path = isoPath.substring(0, index);
2737-
final String name = isoPath.substring(index + 1);
2738-
final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path);
2739-
final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
2740-
return isoVol.getPath();
2741-
} else {
2742-
return data.getPath();
2732+
if (store instanceof NfsTO || store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload()) {
2733+
final String isoPath = store.getUrl().split("\\?")[0] + File.separator + dataPath;
2734+
final int index = isoPath.lastIndexOf("/");
2735+
final String path = isoPath.substring(0, index);
2736+
final String name = isoPath.substring(index + 1);
2737+
final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path);
2738+
final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name);
2739+
return isoVol.getPath();
2740+
}
27432741
}
2742+
2743+
return dataPath;
27442744
}
27452745

27462746
public void createVbd(final Connect conn, final VirtualMachineTO vmSpec, final String vmName, final LibvirtVMDef vm) throws InternalErrorException, LibvirtException, URISyntaxException {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
154154
String oldIsoVolumePath = getOldVolumePath(disks, vmName);
155155
String newIsoVolumePath = getNewVolumePathIfDatastoreHasChanged(libvirtComputingResource, conn, to);
156156
if (newIsoVolumePath != null && !newIsoVolumePath.equals(oldIsoVolumePath)) {
157-
s_logger.debug("Editing mount path");
157+
s_logger.debug(String.format("Editing mount path of iso from %s to %s", oldIsoVolumePath, newIsoVolumePath));
158158
xmlDesc = replaceDiskSourceFile(xmlDesc, newIsoVolumePath, vmName);
159159
}
160160
// delete the metadata of vm snapshots before migration
@@ -569,7 +569,7 @@ private String getNewVolumePathIfDatastoreHasChanged(LibvirtComputingResource li
569569

570570
String newIsoVolumePath = null;
571571
if (newDisk != null) {
572-
newIsoVolumePath = libvirtComputingResource.getVolumePath(conn, newDisk);
572+
newIsoVolumePath = libvirtComputingResource.getVolumePath(conn, newDisk, to.isConfigDriveOnHostCache());
573573
}
574574
return newIsoVolumePath;
575575
}

0 commit comments

Comments
 (0)