Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/src/main/java/com/cloud/host/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public static String[] toStrings(Host.Type... types) {
}
}

/**
* Reported by KVM agents that honour the {@link com.cloud.vm.VmDetailConstants#KVM_HONOUR_DISK_CONTROLLER} VM detail.
*/
String HOST_HONOUR_DISK_CONTROLLER = "host.honour.disk.controller";
String HOST_UEFI_ENABLE = "host.uefi.enable";
String HOST_KVM_DISK_ONLY_VM_SNAPSHOT_NVRAM = "host.kvm.diskonlyvmsnapshot.nvram";
String HOST_VOLUME_ENCRYPTION = "host.volume.encryption";
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/java/com/cloud/vm/VmDetailConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public interface VmDetailConstants {

// KVM specific, disk controllers
String KVM_SKIP_FORCE_DISK_CONTROLLER = "skip.force.disk.controller";
/**
* "true" when the disks of a KVM VM boot from the buses its rootDiskController and dataDiskController details name.
* The KVM agent uses those details on every storage pool type only for VMs with it. The management server sets it
* (hidden) on the KVM VMs it creates or imports with an explicit disk controller, from the version that introduced
* it, and on the KVM templates it registers. Older VMs keep the disk buses they boot from, because Windows only
* keeps the storage driver it booted from ready for boot.
*/
String KVM_HONOUR_DISK_CONTROLLER = "honour.disk.controller";

// KVM specific, configuring special features
String KVM_HINT_DEDICATED = "kvm.hint.dedicated";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,28 @@ public void notifyMonitorsOfNewlyAddedHost(long hostId) {
}
}

/**
* Stores whether a KVM host honours the {@link com.cloud.vm.VmDetailConstants#KVM_HONOUR_DISK_CONTROLLER} VM detail,
* as its agent reports with {@link Host#HOST_HONOUR_DISK_CONTROLLER} when it connects. An agent that does not report
* it (an older version) gets "false", so that a host moved back to an older agent does not keep "true".
*/
protected void syncHonourDiskControllerCapability(HostVO host, Map<String, String> detailsMap) {
if (host == null || host.getHypervisorType() != HypervisorType.KVM) {
return;
}
String reported = Boolean.toString(detailsMap != null && Boolean.parseBoolean(detailsMap.get(Host.HOST_HONOUR_DISK_CONTROLLER)));
_hostDao.loadDetails(host);
Map<String, String> hostDetails = host.getDetails() != null ? new HashMap<>(host.getDetails()) : new HashMap<>();
String stored = hostDetails.get(Host.HOST_HONOUR_DISK_CONTROLLER);
if (reported.equals(stored) || (stored == null && !Boolean.parseBoolean(reported))) {
return;
}
logger.info("Host {} reports {}={}, it was {}", host, Host.HOST_HONOUR_DISK_CONTROLLER, reported, stored);
hostDetails.put(Host.HOST_HONOUR_DISK_CONTROLLER, reported);
host.setDetails(hostDetails);
_hostDao.saveDetails(host);
}

protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, final StartupCommand[] cmds, final boolean forRebalance) throws ConnectionException {
final long hostId = attache.getId();
final HostVO host = _hostDao.findById(hostId);
Expand Down Expand Up @@ -805,6 +827,7 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
if (answer instanceof ReadyAnswer) {
ReadyAnswer readyAnswer = (ReadyAnswer)answer;
Map<String, String> detailsMap = readyAnswer.getDetailsMap();
syncHonourDiskControllerCapability(host, detailsMap);
if (detailsMap != null) {
_hostDao.loadDetails(host);
if (host.getDetails() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,45 @@ public void testGetHostSshPortWithKVMHostCustomPort() {
int hostSshPort = mgr.getHostSshPort(host);
Assert.assertEquals(3922, hostSshPort);
}

private void syncHonourDiskControllerCapability(Hypervisor.HypervisorType hypervisorType, String stored, Map<String, String> reported) {
host.setHypervisorType(hypervisorType);
Map<String, String> details = new HashMap<>();
if (stored != null) {
details.put(Host.HOST_HONOUR_DISK_CONTROLLER, stored);
}
host.setDetails(details);
mgr.syncHonourDiskControllerCapability(host, reported);
}

@Test
public void syncHonourDiskControllerCapabilityStoresTheCapabilityOfAnUpgradedKvmAgent() {
syncHonourDiskControllerCapability(Hypervisor.HypervisorType.KVM, null, Map.of(Host.HOST_HONOUR_DISK_CONTROLLER, "true"));
Assert.assertEquals("true", host.getDetails().get(Host.HOST_HONOUR_DISK_CONTROLLER));
Mockito.verify(hostDao).saveDetails(host);
}

@Test
public void syncHonourDiskControllerCapabilitySetsFalseForAnOlderKvmAgent() {
syncHonourDiskControllerCapability(Hypervisor.HypervisorType.KVM, "true", new HashMap<>());
Assert.assertEquals("false", host.getDetails().get(Host.HOST_HONOUR_DISK_CONTROLLER));
Mockito.verify(hostDao).saveDetails(host);

syncHonourDiskControllerCapability(Hypervisor.HypervisorType.KVM, "true", null);
Assert.assertEquals("false", host.getDetails().get(Host.HOST_HONOUR_DISK_CONTROLLER));

// read-only host details are not written to
host.setDetails(Map.of(Host.HOST_HONOUR_DISK_CONTROLLER, "true"));
mgr.syncHonourDiskControllerCapability(host, Map.of());
Assert.assertEquals("false", host.getDetails().get(Host.HOST_HONOUR_DISK_CONTROLLER));
}

@Test
public void syncHonourDiskControllerCapabilityWritesNothingWithoutAChange() {
syncHonourDiskControllerCapability(Hypervisor.HypervisorType.KVM, "true", Map.of(Host.HOST_HONOUR_DISK_CONTROLLER, "true"));
syncHonourDiskControllerCapability(Hypervisor.HypervisorType.KVM, null, new HashMap<>());
syncHonourDiskControllerCapability(Hypervisor.HypervisorType.VMware, null, Map.of(Host.HOST_HONOUR_DISK_CONTROLLER, "true"));
Assert.assertNull(host.getDetails().get(Host.HOST_HONOUR_DISK_CONTROLLER));
Mockito.verify(hostDao, Mockito.never()).saveDetails(host);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -341,6 +342,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
private static final VideoDef.VideoModel X86_DEFAULT_VIDEO_MODEL = VideoDef.VideoModel.VGA;
private static final int X86_DEFAULT_VIDEO_RAM_KIB = 32768;
private static final String Q35 = "q35";
/**
* Disk buses which the rootDiskController and dataDiskController VM details can set for the disks of a VM.
*/
private static final Set<DiskDef.DiskBus> EXPLICIT_DISK_BUSES = EnumSet.of(DiskDef.DiskBus.VIRTIO, DiskDef.DiskBus.SCSI,
DiskDef.DiskBus.SATA, DiskDef.DiskBus.IDE);
private static final String PTY = "pty";
private static final String VNC = "vnc";

Expand Down Expand Up @@ -3749,19 +3755,27 @@ public static DiskDef.DiskType getDiskType(KVMPhysicalDisk physicalDisk) {
* @param devId The device ID for the disk.
* @param diskBusType The disk bus type to use if not skipping force disk controller.
* @param diskBusTypeData The disk bus type to use for data disks, if applicable.
* @param explicitDiskBus The disk bus set for the disk with the rootDiskController or dataDiskController VM detail
* (see {@link #getExplicitDiskBus}), or null. When set, it is used whatever the guest OS
* and the boot mode.
* @param details A map of VM details containing additional configuration values, such as whether to skip force
* disk controller.
*/
protected void defineDiskForDefaultPoolType(DiskDef disk, DiskTO volume, boolean isWindowsTemplate,
boolean isUefiEnabled, boolean isSecureBoot, KVMPhysicalDisk physicalDisk, int devId,
DiskDef.DiskBus diskBusType, DiskDef.DiskBus diskBusTypeData, Map<String, String> details) {
DiskDef.DiskBus diskBusType, DiskDef.DiskBus diskBusTypeData, DiskDef.DiskBus explicitDiskBus,
Map<String, String> details) {
boolean skipForceDiskController = MapUtils.getBoolean(details, VmDetailConstants.KVM_SKIP_FORCE_DISK_CONTROLLER,
false);
if (skipForceDiskController) {
disk.defFileBasedDisk(physicalDisk.getPath(), devId, Volume.Type.DATADISK.equals(volume.getType()) ?
diskBusTypeData : diskBusType, DiskDef.DiskFmtType.QCOW2);
return;
}
if (explicitDiskBus != null) {
disk.defFileBasedDisk(physicalDisk.getPath(), devId, explicitDiskBus, DiskDef.DiskFmtType.QCOW2);
return;
}
if (volume.getType() == Volume.Type.DATADISK && !(isWindowsTemplate && isUefiEnabled)) {
disk.defFileBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData, DiskDef.DiskFmtType.QCOW2);
} else {
Expand Down Expand Up @@ -3903,19 +3917,23 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {

setDiskIoDriver(disk, getIoDriverForTheStorage(ioDriver));

// A bus set for the disk with the rootDiskController/dataDiskController VM details is used on every
// pool type; the choices based on the guest OS, the boot mode and the pool type only apply without it.
final DiskDef.DiskBus explicitDiskBus = getExplicitDiskBus(vmSpec, volume.getType(), isWindowsTemplate, isUefiEnabled);

if (pool.getType() == StoragePoolType.RBD) {
/*
For RBD pools we use the secret mechanism in libvirt.
We store the secret under the UUID of the pool, that's why
we pass the pool's UUID as the authSecret
*/
disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(), pool.getAuthUserName(),
pool.getUuid(), devId, diskBusType, DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
pool.getUuid(), devId, ObjectUtils.defaultIfNull(explicitDiskBus, diskBusType), DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
} else if (pool.getType() == StoragePoolType.PowerFlex) {
if (isWindowsTemplate && isUefiEnabled) {
diskBusTypeData = DiskDef.DiskBus.SATA;
}
disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData);
disk.defBlockBasedDisk(physicalDisk.getPath(), devId, ObjectUtils.defaultIfNull(explicitDiskBus, diskBusTypeData));
if (physicalDisk.getFormat().equals(PhysicalDiskFormat.QCOW2)) {
disk.setDiskFormatType(DiskDef.DiskFmtType.QCOW2);
}
Expand All @@ -3924,9 +3942,11 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
final String path = physicalDisk.getPath();
final String glusterVolume = pool.getSourceDir().replace("/", "");
disk.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), pool.getSourceHost(), pool.getSourcePort(), null,
null, devId, diskBusType, DiskProtocol.GLUSTER, DiskDef.DiskFmtType.QCOW2);
null, devId, ObjectUtils.defaultIfNull(explicitDiskBus, diskBusType), DiskProtocol.GLUSTER, DiskDef.DiskFmtType.QCOW2);
} else if (pool.getType() == StoragePoolType.CLVM || pool.getType() == StoragePoolType.CLVM_NG || physicalDisk.getFormat() == PhysicalDiskFormat.RAW) {
if (volume.getType() == Volume.Type.DATADISK && !(isWindowsTemplate && isUefiEnabled)) {
if (explicitDiskBus != null) {
disk.defBlockBasedDisk(physicalDisk.getPath(), devId, explicitDiskBus);
} else if (volume.getType() == Volume.Type.DATADISK && !(isWindowsTemplate && isUefiEnabled)) {
disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusTypeData);
} else {
disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusType);
Expand All @@ -3942,7 +3962,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
}
} else {
defineDiskForDefaultPoolType(disk, volume, isWindowsTemplate, isUefiEnabled, isSecureBoot,
physicalDisk, devId, diskBusType, diskBusTypeData, details);
physicalDisk, devId, diskBusType, diskBusTypeData, explicitDiskBus, details);
}
pool.customizeLibvirtDiskDef(disk);
}
Expand Down Expand Up @@ -5114,6 +5134,46 @@ public DiskDef.DiskBus getDataDiskModelFromVMDetail(final VirtualMachineTO vmTO)
return null;
}

/**
* Returns the bus set for a disk of the VM with the rootDiskController (ROOT volume) or the dataDiskController
* (DATADISK volume) VM detail. This bus is used whatever the guest OS, the boot mode and the storage pool type.
* <ul>
* <li>Only VMs with the {@link VmDetailConstants#KVM_HONOUR_DISK_CONTROLLER} detail set to true get it. The
* management server sets it on the VMs it creates or imports with an explicit disk controller, from the version
* that introduced it. Older VMs keep the buses they have always booted from: Windows only keeps the storage
* driver it booted from ready for boot, so moving such a VM from SATA to virtio stops it with
* INACCESSIBLE_BOOT_DEVICE.</li>
* <li>The data disks of a Windows VM with UEFI follow the root disk when dataDiskController is not set, as
* they do when no controller is set at all.</li>
* <li>UEFI VMs use the q35 machine type, which has no IDE bus: "ide" gives SATA, as for their CD-ROMs.</li>
* </ul>
*
* @return the disk bus, or null when the VM does not have the {@link VmDetailConstants#KVM_HONOUR_DISK_CONTROLLER}
* detail, or the controller detail is not set or is not one of virtio, scsi, sata and ide (for example
* "osdefault"). The bus for the guest OS, the boot mode and the storage pool type is used then.
*/
protected DiskDef.DiskBus getExplicitDiskBus(VirtualMachineTO vmSpec, Volume.Type volumeType, boolean isWindowsTemplate,
boolean isUefiEnabled) {
if (!MapUtils.getBoolean(vmSpec.getDetails(), VmDetailConstants.KVM_HONOUR_DISK_CONTROLLER, false)) {
return null;
}
DiskDef.DiskBus bus;
if (volumeType != Volume.Type.DATADISK) {
bus = getDiskModelFromVMDetail(vmSpec);
} else {
bus = getDataDiskModelFromVMDetail(vmSpec);
if (bus == null && isWindowsTemplate && isUefiEnabled) {
bus = getDiskModelFromVMDetail(vmSpec);
}
}
if (bus == DiskDef.DiskBus.IDE && isUefiEnabled) {
LOGGER.debug("The {} disk of the UEFI VM {} is set to the ide bus, which the q35 machine type does not have, using sata",
volumeType, vmSpec.getName());
return DiskDef.DiskBus.SATA;
}
return EXPLICIT_DISK_BUSES.contains(bus) ? bus : null;
}

private DiskDef.DiskBus getGuestDiskModel(final String platformEmulator, boolean isUefiEnabled) {
if (platformEmulator == null) {
return DiskDef.DiskBus.IDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public Answer execute(final ReadyCommand command, final LibvirtComputingResource
Map<String, String> hostDetails = new HashMap<String, String>();
hostDetails.put(Host.HOST_KVM_DISK_ONLY_VM_SNAPSHOT_NVRAM, Boolean.TRUE.toString());

hostDetails.put(Host.HOST_HONOUR_DISK_CONTROLLER, Boolean.TRUE.toString());

if (hostSupportsUefi(libvirtComputingResource.isUbuntuOrDebianHost()) && libvirtComputingResource.isUefiPropertiesFileLoaded()) {
hostDetails.put(Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString());
}
Expand Down
Loading
Loading