Skip to content

Commit ef11a94

Browse files
committed
가상머신 마이그레이션 시 configdrive iso 경로 설정 버그 수정
1 parent 9f7bde7 commit ef11a94

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,6 +3792,81 @@ protected KVMStoragePoolManager getPoolManager() {
37923792
return storagePoolManager;
37933793
}
37943794

3795+
public void detachAndAttachConfigDriveISO(final Connect conn, final String vmName, VirtualMachineTO to) {
3796+
// detach and re-attach configdrive ISO
3797+
List<DiskDef> disks = getDisks(conn, vmName);
3798+
DiskDef configdrive = null;
3799+
for (DiskDef disk : disks) {
3800+
if (disk.getDeviceType() == DiskDef.DeviceType.CDROM && CONFIG_DRIVE_ISO_DISK_LABEL.equals(disk.getDiskLabel())) {
3801+
configdrive = disk;
3802+
}
3803+
}
3804+
3805+
if (configdrive != null) {
3806+
try {
3807+
LOGGER.debug(String.format("Detaching ConfigDrive ISO of the VM %s, at path %s", vmName, configdrive.getDiskPath()));
3808+
String result = attachOrDetachConfigDriveISO(conn, vmName, to, configdrive.getDiskPath(), false, CONFIG_DRIVE_ISO_DEVICE_ID);
3809+
if (result != null) {
3810+
LOGGER.warn(String.format("Detach ConfigDrive ISO of the VM %s, at path %s with %s: ", vmName, configdrive.getDiskPath(), result));
3811+
}
3812+
LOGGER.debug(String.format("Attaching ConfigDrive ISO of the VM %s, at path %s", vmName, configdrive.getDiskPath()));
3813+
result = attachOrDetachConfigDriveISO(conn, vmName, to, configdrive.getDiskPath(), true, CONFIG_DRIVE_ISO_DEVICE_ID);
3814+
if (result != null) {
3815+
LOGGER.warn(String.format("Attach ConfigDrive ISO of the VM %s, at path %s with %s: ", vmName, configdrive.getDiskPath(), result));
3816+
}
3817+
} catch (final LibvirtException | InternalErrorException | URISyntaxException e) {
3818+
final String msg = "Detach and attach ConfigDrive ISO failed due to " + e.toString();
3819+
LOGGER.warn(msg, e);
3820+
}
3821+
}
3822+
}
3823+
3824+
public synchronized String attachOrDetachConfigDriveISO(final Connect conn, final String vmName, VirtualMachineTO to, String cdPath, final boolean isAttach, final Integer diskSeq) throws LibvirtException, URISyntaxException,
3825+
InternalErrorException {
3826+
String isoPath = "";
3827+
DiskTO configDriveDisk = null;
3828+
for (DiskTO disk : to.getDisks()) {
3829+
if (disk.getPath() != null && disk.getPath().contains("configdrive")) {
3830+
configDriveDisk = disk;
3831+
break;
3832+
}
3833+
}
3834+
isoPath = getVolumePath(conn, configDriveDisk, to.isConfigDriveOnHostCache());
3835+
DiskDef iso = new DiskDef();
3836+
if (isAttach && StringUtils.isNotBlank(isoPath) && configDriveDisk !=null && isoPath.lastIndexOf("/") > 0) {
3837+
if (isoPath.startsWith(getConfigPath() + "/" + ConfigDrive.CONFIGDRIVEDIR) && isoPath.contains(vmName)) {
3838+
iso.defISODisk(isoPath, diskSeq, DiskDef.DiskType.FILE);
3839+
} else {
3840+
final DataTO diskData = configDriveDisk.getData();
3841+
final String dataName = configDriveDisk.getPath();
3842+
final DataStoreTO store = diskData.getDataStore();
3843+
isoPath = store.getUrl().split("\\?")[0] + File.separator + dataName;
3844+
3845+
final int index = isoPath.lastIndexOf("/");
3846+
final String path = isoPath.substring(0, index);
3847+
final String name = isoPath.substring(index + 1);
3848+
final KVMStoragePool storagePool = storagePoolManager.getStoragePoolByURI(path);
3849+
final KVMPhysicalDisk isoVol = storagePool.getPhysicalDisk(name);
3850+
final DiskDef.DiskType diskType = getDiskType(isoVol);
3851+
isoPath = isoVol.getPath();
3852+
iso.defISODisk(isoPath, diskSeq, diskType);
3853+
}
3854+
} else {
3855+
iso.defISODisk(null, diskSeq, DiskDef.DiskType.FILE);
3856+
}
3857+
final String result = attachOrDetachDevice(conn, true, vmName, iso.toString());
3858+
if (result == null && !isAttach) {
3859+
final List<DiskDef> disks = getDisks(conn, vmName);
3860+
for (final DiskDef disk : disks) {
3861+
if (disk.getDeviceType() == DiskDef.DeviceType.CDROM
3862+
&& (diskSeq == null || disk.getDiskLabel().equals(iso.getDiskLabel()))) {
3863+
cleanupDisk(disk);
3864+
}
3865+
}
3866+
}
3867+
return result;
3868+
}
3869+
37953870
public void detachAndAttachConfigDriveISO(final Connect conn, final String vmName) {
37963871
// detach and re-attach configdrive ISO
37973872
List<DiskDef> disks = getDisks(conn, vmName);

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
@@ -229,7 +229,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
229229
dconn = libvirtUtilitiesHelper.retrieveQemuConnection(destinationUri);
230230

231231
if (to.getType() == VirtualMachine.Type.User) {
232-
libvirtComputingResource.detachAndAttachConfigDriveISO(conn, vmName);
232+
libvirtComputingResource.detachAndAttachConfigDriveISO(conn, vmName, to);
233233
}
234234

235235
//run migration in thread so we can monitor it
@@ -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);

0 commit comments

Comments
 (0)