andrijapanicsb opened a new pull request, #14844:
URL: https://github.com/apache/cloudstack/pull/14844
### Description
This PR makes the KVM agent use the disk bus that is set for a VM with the
`rootDiskController` and
`dataDiskController` details (VM details, or template details copied to the
VM), whatever the guest OS, the boot
mode (BIOS, UEFI legacy, UEFI secure) and the primary storage type. When no
controller is set, nothing changes.
**Problem.** A Windows VM with UEFI Secure Boot on a file-based primary
storage (NFS, local, SharedMountPoint) always
gets its disks on SATA, even when its details say
`rootDiskController=virtio` and `dataDiskController=virtio` and the
guest has the virtio storage drivers. Example: a Windows Server 2025 VM
(q35, UEFI Secure Boot, NFS primary storage)
imported with `UEFI=SECURE`, `rootDiskController=virtio`,
`dataDiskController=virtio`, `nicAdapter=virtio`: libvirt
gets both disks with `bus='sata'`. The same happens for Windows Server 2019
and 2022: there is no Windows version
specific code, the KVM agent only checks whether the OS name contains
"window".
**Expected.** If the VM settings say the disk controller is virtio, the
disks are virtio. A VM without these settings
keeps today's defaults (SATA for Windows UEFI VMs), and the CD-ROMs of UEFI
VMs stay on SATA.
#### Root cause
The bus is forced in `LibvirtComputingResource.createVbd()` after the
controller details have been read:
- #3638 (4.14, UEFI support) added `DiskDef.defFileBasedDisk(path, devId,
format, isWindowsOS)`, which puts the disk
of a Secure Boot VM on SATA (Windows) or virtio (other OSes), ignoring the
controller details. Its author later
explained it as an issue with Windows Secure Boot guests and virtio disks,
and noted that this "always over-rides
the os configuration setting, no matter what controller configured"
(https://github.com/apache/cloudstack/pull/10213#discussion_r1922711472).
- #4773 (4.15.1) made SATA the default disk bus of Windows UEFI VMs, made
their data disks follow the root disk (so
they are forced too), and put the CD-ROMs of UEFI VMs on SATA (the q35
machine type has no IDE bus).
- #5072 extended the UEFI SATA default to guest OSes starting with "Other".
- #11554 forced SATA for all disks of Windows UEFI VMs on PowerFlex.
- #10213 tried to honour the controllers and was closed without a consensus.
#11750 added the `skip.force.disk.controller`
VM/template detail as an opt-out, on file-based pools only (issue #9460).
As a result, whether an explicit controller is honoured depends on the
storage type:
| Pool type (branch in `createVbd`) | Root disk | Data disks |
|---|---|---|
| File-based QCOW2 (NFS, local, SharedMountPoint, ...) | Secure Boot: forced
to SATA (Windows) or virtio (other OSes) | Windows UEFI: forced to SATA (Secure
Boot) or root disk bus |
| PowerFlex | uses the **data** disk bus; Windows UEFI: forced to SATA |
data disk bus; Windows UEFI: forced to SATA |
| RBD, Gluster | `rootDiskController` honoured (no forcing) | always the
root disk bus, `dataDiskController` ignored |
| CLVM, CLVM_NG, RAW format (Linstor, StorPool, ...) | `rootDiskController`
honoured | Windows UEFI: root disk bus, `dataDiskController` ignored |
So Windows UEFI Secure Boot VMs with `rootDiskController=virtio` already get
virtio disks on RBD and CLVM pools today;
only file-based pools and PowerFlex force SATA.
#### The change (KVM agent only)
`plugins/hypervisors/kvm/.../LibvirtComputingResource.java`:
- New `getExplicitDiskBus()`: returns the bus set for a disk by
`rootDiskController` (root volume) or
`dataDiskController` (data volume), or `null` when the detail is not set
or is not `virtio`, `scsi`, `sata` or `ide`
(for example `osdefault`, which the UI puts in KVM templates by default).
Two rules keep it compatible:
- The data disks of a Windows UEFI VM without `dataDiskController` follow
the root disk, as they do today.
- `ide` on a UEFI VM gives `sata`: UEFI VMs use q35, which has no IDE bus
(libvirt refuses it), and SATA is what the
CD-ROMs of UEFI VMs already use.
- `createVbd()`: when that bus is set, it is used for the disk on every pool
type (file-based, PowerFlex, RBD, Gluster,
CLVM, RAW). When it is not set, the existing code runs unchanged,
including the SATA defaults of Windows UEFI VMs and
the PowerFlex SATA forcing.
- `defineDiskForDefaultPoolType()`: new `explicitDiskBus` parameter.
`skip.force.disk.controller` is still checked
first and behaves exactly as before.
Not changed: CD-ROMs (still SATA on UEFI, IDE on BIOS), device names (`vdX`
for virtio, `sdX` for SATA/SCSI, letter from
the device id), the hot-plug path (`KVMStorageProcessor`, which already
honours the controller details since #12452),
the management server, the API, the UI and the database.
#### Behaviour
Only VMs with `rootDiskController` and/or `dataDiskController` set to
`virtio`, `scsi`, `sata` or `ide` can change, and
only at their next start.
| VM | rootDiskController | dataDiskController | Before | After |
|---|---|---|---|---|
| Windows, UEFI secure, file-based pool | not set / `osdefault` | not set /
`osdefault` | sata / sata | sata / sata |
| Windows, UEFI secure, file-based pool | virtio | virtio | sata / sata |
**virtio / virtio** |
| Windows, UEFI secure, file-based pool | virtio | not set | sata / sata |
**virtio / virtio** |
| Windows, UEFI secure, file-based pool | not set | virtio | sata / sata |
sata / **virtio** |
| Windows, UEFI secure, file-based pool | ide | not set | sata / sata | sata
/ sata |
| Windows, UEFI legacy, file-based pool | virtio | sata | virtio / virtio |
virtio / **sata** |
| Windows, UEFI legacy, file-based pool | ide | not set | ide / ide (libvirt
refuses IDE on q35) | **sata / sata** |
| Linux, UEFI secure, file-based pool | not set | not set | virtio / virtio
| virtio / virtio |
| Linux, UEFI secure, file-based pool | scsi | not set | virtio / scsi |
**scsi** / scsi |
| Any OS, BIOS, file-based, CLVM or RAW pool | any | any | unchanged |
unchanged |
| Windows, UEFI, PowerFlex | virtio | virtio | sata / sata | **virtio /
virtio** |
| Windows, UEFI, PowerFlex | not set | not set | sata / sata | sata / sata |
| Non-Windows or BIOS VM, PowerFlex | scsi | virtio | virtio / virtio |
**scsi** / virtio |
| Any VM, RBD or Gluster | virtio | scsi | virtio / virtio | virtio /
**scsi** |
| Any VM | virtio-blk | not set | unchanged | unchanged |
#### Compatibility and upgrade notes
- The agent cannot tell who set a controller detail, but on KVM the
management server never writes a default one:
the details come from the user (deploy or update details, UI settings),
from the template details, or from the
import of an unmanaged or converted VM, which copies the bus the source
disk used
(`UnmanagedVMsManagerImpl`). The `osdefault` value is not a bus and is
treated as not set, as before.
- VMs whose explicit controller was overridden get it at their next start
(bold cells above). A Windows guest moved
from SATA to virtio needs the virtio storage driver installed and enabled
for boot, otherwise it stops with
INACCESSIBLE_BOOT_DEVICE. Note that the VMware to KVM conversion stores
`virtio` for a disk when the converted domain
XML cannot be parsed (`LibvirtBaseConvertCommandWrapper`). Operators can
list these VMs before upgrading the agents
and set `rootDiskController=sata` / `dataDiskController=sata` to keep SATA:
```sql
SELECT vm.uuid, vm.instance_name, d.name, d.value
FROM cloud.vm_instance vm
JOIN cloud.vm_instance_details d ON d.vm_id = vm.id
WHERE vm.hypervisor_type = 'KVM' AND vm.removed IS NULL
AND d.name IN ('rootDiskController', 'dataDiskController')
AND LOWER(d.value) IN ('virtio', 'scsi', 'sata', 'ide')
AND vm.id IN (SELECT vm_id FROM cloud.vm_instance_details WHERE name =
'UEFI');
```
(4.20 uses the table `user_vm_details`. Add the PowerFlex, RBD and Gluster
VMs listed in the table above if those
pools are used.)
- Running VMs are not touched. Live migration keeps the running domain
definition.
- During a rolling upgrade, a VM gets SATA or virtio depending on the agent
version of the host it starts on.
- `skip.force.disk.controller` keeps working. It is no longer needed to get
explicit controllers honoured; it only
changes the defaults used when no controller is set.
- On q35, each virtio disk takes a PCIe root port and SATA disks do not. See
#11212 about the PCIe slots left for
hot-plugging volumes and NICs into UEFI VMs.
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] Build/CI
- [ ] Test (unit or integration test code)
### Feature/Enhancement Scale or Bug Severity
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [x] Major
- [ ] Minor
- [ ] Trivial
### How Has This Been Tested?
Unit tests in `LibvirtComputingResourceTest` (20 new, 5 updated for the new
parameter). The `createVbd` tests build the
libvirt disk definitions of a User VM the way it is done at start, and check
bus, target name and the `<target>` XML
of every disk and CD-ROM:
- Windows UEFI Secure Boot with virtio root and data controllers, for the OS
types Windows Server 2019, 2022 and 2025:
`vda`/`vdb` virtio, CD-ROMs `sdd`/`sde` SATA.
- Windows UEFI Secure Boot with no controller (same three OS types), and
with `osdefault`: SATA, as before.
- Windows UEFI legacy: explicit controllers honoured; no controller: SATA as
before.
- Windows UEFI data disks follow an explicit root controller when
`dataDiskController` is not set.
- Linux without controllers (UEFI Secure Boot and BIOS): unchanged; Linux
UEFI Secure Boot with `scsi`: honoured.
- CD-ROMs of UEFI VMs stay SATA next to virtio disks, with and without an
ISO.
- `ide` on UEFI gives SATA; `ide` on BIOS stays IDE; `virtio-blk` keeps the
current behaviour.
- `skip.force.disk.controller=true` gives the same buses as before.
- Target names are unique for root + 3 data disks (device ids 0, 1, 2, 5) +
2 CD-ROMs, for Windows and Linux, BIOS,
UEFI legacy and UEFI secure, and 7 controller combinations.
- PowerFlex and RBD.
Results (JDK 17, Maven 3.8.7):
- `mvn -pl plugins/hypervisors/kvm test
-Dtest=LibvirtComputingResourceTest`: 350 tests, 0 failures.
- `mvn -pl plugins/hypervisors/kvm test` (whole KVM plugin, checkstyle
included): 1119 tests, 0 failures, 0 errors,
1 skipped (`QemuImgTest`, needs a local qemu-img).
- The 15 new `createVbd` tests run against `main` without the fix: the 8
that check explicit controllers fail
(for example "expected virtio but was sata" for the Windows Secure Boot
case) and the 7 that check unchanged
behaviour pass.
#### Lab tests
These were run before this change, using `skip.force.disk.controller=true`.
For a VM with explicit virtio controllers
that gives the same libvirt disk definitions as this change. A run with the
patched agent jar itself is still to be
done; only the `cloud-plugin-hypervisor-kvm` jar needs to be replaced on a
host for it.
**Setup**
- CloudStack 24.0.0-SNAPSHOT (KVM agent 24.0.0-101), EL9 KVM hosts, NFS
primary storage.
- q35 `pc-q35-rhel9.0.0`, `OVMF_CODE.secboot.fd` with SMM.
- Guest: Windows Server 2025 Standard with UEFI and Secure Boot, moved from
VMware with virt-v2v
(virtio-win 1.9.61, viostor 100.103.104.30200).
- Imported with `UEFI=SECURE`, `rootDiskController=virtio`,
`dataDiskController=virtio`, `nicAdapter=virtio`.
- OS type "Windows Server 2022 (64-bit)".
**Results**
| Run | `skip.force.disk.controller` | Disks in the libvirt XML | CD-ROMs |
Result |
|---|---|---|---|---|
| 1 | not set (current behaviour) | `sdb`, `sdc`, `bus='sata'` | `sdd`,
`sde`, SATA | booted, first boot completed, guest agent running |
| 2 | `true` | `vdb`, `vdc`, `bus='virtio'` | `sdd`, `sde`, SATA | booted,
first boot completed, guest agent running |
| 3 | `true` (a fresh VM) | `vdb`, `vdc`, `bus='virtio'` | `sdd`, `sde`,
SATA | booted, first boot completed, guest agent running |
- Each VM was watched for 30 minutes after its first start and settled with
no restart loop.
- In runs 2 and 3 Windows runs both disks on viostor ("Red Hat VirtIO SCSI
controller").
- On its first boot from virtio, Windows replaced the boot-time placeholder
driver with viostor and restarted once on
its own ("Operating System: Upgrade (Planned)"); after that it settled.
- The Secure Boot state inside the guest was read on KVM outside CloudStack,
with the same guest, OVMF with the
Microsoft keys and a virtio-blk boot disk: `Confirm-SecureBootUEFI`
returned `True` on the first boot and after a
reboot.
- The same guest also boots and settles with SATA disks (run 1).
#### How did you try to break this feature and the system with this change?
- VMs without controller details, with `osdefault`, with `virtio-blk`, with
`skip.force.disk.controller`: same buses as
before (unit tests above).
- Device name collisions between SATA disks and the SATA CD-ROMs of UEFI VMs
(#13484, #14321): virtio disks use `vdX`
names, which cannot collide with the CD-ROMs; SATA and SCSI disks keep the
`sdX` name of their device id, and the
device ids of the CD-ROMs are still kept free for the volumes (#14407).
- `ide` on UEFI VMs, which libvirt refuses on q35: given SATA.
### Backport
4.22 and 4.20 have the same forcing code (#11554, #11750 and #12452 are on
both branches), so they need the fix too.
The patch does not apply cleanly to them: one trivial conflict in
`createVbd` (`CLVM_NG` does not exist on these
branches) and context differences in the test class. The `createVbd` tests
also need the CD-ROMs passed as ISO volumes,
because the KVM agent of these branches does not define the empty CD-ROM
slots itself (#13101 is not on them).
#14407 is not on these branches (#14073 is open for 4.22), so the SATA name
collisions of #13484 can still happen there
for VMs whose disks are on SATA; this PR does not change that, and VMs whose
disks are on virtio do not have it.
Checked locally with the conflicts resolved (JDK 17):
`LibvirtComputingResourceTest` passes on 4.22 at `759bb81886`
(289 tests) and on 4.20 at `e6f193db80` (262 tests), the 20 new tests
included. The resolved 4.22 change applies
cleanly to the tags 4.22.1.0 and 4.22.1.1, the 4.20 one to 4.20.3.1. On the
tag 4.23.0.0 the `main` patch applies
with a 3-way merge and no conflict, and the test class passes (335 tests).
### Documentation
The admin guide notes added by apache/cloudstack-documentation#616 and #655
should say that the `rootDiskController`
and `dataDiskController` settings are honoured for UEFI and Windows VMs, and
that `skip.force.disk.controller` only
matters when no controller is set.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]