Skip to content

Commit 0f0155c

Browse files
Fix live migration of VM with config drive on KVM (apache#11516)
1 parent 6e59f4f commit 0f0155c

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
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
@@ -3506,10 +3506,10 @@ public void detachAndAttachConfigDriveISO(final Connect conn, final String vmNam
35063506
public synchronized String attachOrDetachISO(final Connect conn, final String vmName, String isoPath, final boolean isAttach, final Integer diskSeq) throws LibvirtException, URISyntaxException,
35073507
InternalErrorException {
35083508
final DiskDef iso = new DiskDef();
3509-
if (isAttach && StringUtils.isNotBlank(isoPath) && isoPath.lastIndexOf("/") > 0) {
3510-
if (isoPath.startsWith(getConfigPath() + "/" + ConfigDrive.CONFIGDRIVEDIR) && isoPath.contains(vmName)) {
3509+
if (isAttach && StringUtils.isNotBlank(isoPath)) {
3510+
if (isoPath.startsWith(getConfigPath() + "/" + ConfigDrive.CONFIGDRIVEDIR) || isoPath.contains(vmName)) {
35113511
iso.defISODisk(isoPath, diskSeq, DiskDef.DiskType.FILE);
3512-
} else {
3512+
} else if (isoPath.lastIndexOf("/") > 0) {
35133513
final int index = isoPath.lastIndexOf("/");
35143514
final String path = isoPath.substring(0, index);
35153515
final String name = isoPath.substring(index + 1);
@@ -3533,7 +3533,6 @@ public synchronized String attachOrDetachISO(final Connect conn, final String vm
35333533
cleanupDisk(disk);
35343534
}
35353535
}
3536-
35373536
}
35383537
return result;
35393538
}

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
@@ -899,7 +899,7 @@ private boolean findSourceNode(Document doc, Node diskNode, String vmName, Strin
899899
Node sourceNode = diskChildNode;
900900
NamedNodeMap sourceNodeAttributes = sourceNode.getAttributes();
901901
Node sourceNodeAttribute = sourceNodeAttributes.getNamedItem("file");
902-
if ( sourceNodeAttribute.getNodeValue().contains(vmName)) {
902+
if (sourceNodeAttribute != null && sourceNodeAttribute.getNodeValue().contains(vmName)) {
903903
diskNode.removeChild(diskChildNode);
904904
Element newChildSourceNode = doc.createElement("source");
905905
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
@@ -325,17 +325,19 @@ public KVMStoragePool getStoragePoolByURI(String uri) {
325325
String uuid = null;
326326
String sourceHost = "";
327327
StoragePoolType protocol = null;
328-
final String scheme = (storageUri.getScheme() != null) ? storageUri.getScheme().toLowerCase() : "";
329328
List<String> acceptedSchemes = List.of("nfs", "networkfilesystem", "filesystem");
330-
if (acceptedSchemes.contains(scheme)) {
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;
329+
if (storageUri.getScheme() == null || !acceptedSchemes.contains(storageUri.getScheme().toLowerCase())) {
330+
throw new CloudRuntimeException("Empty or unsupported storage pool uri scheme");
336331
}
337332

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

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,9 @@ private boolean decStoragePoolRefCount(String uuid) {
733733

734734
@Override
735735
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage) {
736-
logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt");
737-
738-
StoragePool sp = null;
739-
Connect conn = null;
736+
logger.info("Attempting to create storage pool {} ({}) in libvirt", name, type);
737+
StoragePool sp;
738+
Connect conn;
740739
try {
741740
conn = LibvirtConnection.getConnection();
742741
} catch (LibvirtException e) {

0 commit comments

Comments
 (0)