Skip to content

Commit d332da3

Browse files
sureshanapartidhslove
authored andcommitted
Fix live migration of VM with config drive on KVM (apache#11516)
1 parent 21eb8ed commit d332da3

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4324,10 +4324,10 @@ public void detachAndAttachConfigDriveISO(final Connect conn, final String vmNam
43244324
public synchronized String attachOrDetachISO(final Connect conn, final String vmName, String isoPath, final boolean isAttach, final Integer diskSeq) throws LibvirtException, URISyntaxException,
43254325
InternalErrorException {
43264326
final DiskDef iso = new DiskDef();
4327-
if (isAttach && StringUtils.isNotBlank(isoPath) && isoPath.lastIndexOf("/") > 0) {
4328-
if (isoPath.startsWith(getConfigPath() + "/" + ConfigDrive.CONFIGDRIVEDIR) && isoPath.contains(vmName)) {
4327+
if (isAttach && StringUtils.isNotBlank(isoPath)) {
4328+
if (isoPath.startsWith(getConfigPath() + "/" + ConfigDrive.CONFIGDRIVEDIR) || isoPath.contains(vmName)) {
43294329
iso.defISODisk(isoPath, diskSeq, DiskDef.DiskType.FILE);
4330-
} else {
4330+
} else if (isoPath.lastIndexOf("/") > 0) {
43314331
final int index = isoPath.lastIndexOf("/");
43324332
final String path = isoPath.substring(0, index);
43334333
final String name = isoPath.substring(index + 1);
@@ -4351,7 +4351,6 @@ public synchronized String attachOrDetachISO(final Connect conn, final String vm
43514351
cleanupDisk(disk);
43524352
}
43534353
}
4354-
43554354
}
43564355
return result;
43574356
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ private boolean findSourceNode(Document doc, Node diskNode, String vmName, Strin
10181018
Node sourceNode = diskChildNode;
10191019
NamedNodeMap sourceNodeAttributes = sourceNode.getAttributes();
10201020
Node sourceNodeAttribute = sourceNodeAttributes.getNamedItem("file");
1021-
if ( sourceNodeAttribute != null && sourceNodeAttribute.getNodeValue().contains(vmName)) {
1021+
if (sourceNodeAttribute != null && sourceNodeAttribute.getNodeValue().contains(vmName)) {
10221022
diskNode.removeChild(diskChildNode);
10231023
Element newChildSourceNode = doc.createElement("source");
10241024
newChildSourceNode.setAttribute("file", isoPath);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,19 @@ public KVMStoragePool getStoragePoolByURI(String uri) {
322322
String uuid = null;
323323
String sourceHost = "";
324324
StoragePoolType protocol = null;
325-
final String scheme = (storageUri.getScheme() != null) ? storageUri.getScheme().toLowerCase() : "";
326325
List<String> acceptedSchemes = List.of("nfs", "networkfilesystem", "filesystem");
327-
if (acceptedSchemes.contains(scheme)) {
328-
sourcePath = storageUri.getPath();
329-
sourcePath = sourcePath.replace("//", "/");
330-
sourceHost = storageUri.getHost();
331-
uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
332-
protocol = scheme.equals("filesystem") ? StoragePoolType.Filesystem: StoragePoolType.NetworkFilesystem;
326+
if (storageUri.getScheme() == null || !acceptedSchemes.contains(storageUri.getScheme().toLowerCase())) {
327+
throw new CloudRuntimeException("Empty or unsupported storage pool uri scheme");
333328
}
334329

335-
// secondary storage registers itself through here
330+
final String scheme = storageUri.getScheme().toLowerCase();
331+
sourcePath = storageUri.getPath();
332+
sourcePath = sourcePath.replace("//", "/");
333+
sourceHost = storageUri.getHost();
334+
uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
335+
protocol = scheme.equals("filesystem") ? StoragePoolType.Filesystem: StoragePoolType.NetworkFilesystem;
336+
337+
// storage registers itself through here
336338
return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocol, null, false);
337339
}
338340

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ private boolean decStoragePoolRefCount(String uuid) {
876876

877877
@Override
878878
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage) {
879-
logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt");
879+
logger.info("Attempting to create storage pool {} ({}) in libvirt", name, type);
880880

881881
// gluefs mount script call
882882
if (type == StoragePoolType.SharedMountPoint && !MapUtils.isEmpty(details) && !ObjectUtils.isEmpty(details.get("provider")) && "ABLESTACK".equals(details.get("provider"))) {

0 commit comments

Comments
 (0)