qemu: implement setting of rotation rate for SCSI/IDE disks

This is available in QEMU with "ide-hd" and "scsi-hd" device
types. It was originally mistakenly added to the "scsi-block"
device type too, but later removed. This doesn't affect libvirt
since we restrict usage to device=disk.

When this property is not set then QEMU's default behaviour
is to not report any rotation rate information, which
causes most guest OS to assume rotational storage.

https://bugzilla.redhat.com/show_bug.cgi?id=1498955

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2021-03-31 10:17:07 +01:00
parent feac14fa2e
commit 8dac0ca1b2
33 changed files with 203 additions and 0 deletions

View File

@ -624,6 +624,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
"audiodev",
"blockdev-backup",
"object.qapified",
"rotation-rate",
);
@ -1440,6 +1441,7 @@ static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsSCSIDisk[] = {
{ "write-cache", QEMU_CAPS_DISK_WRITE_CACHE, NULL },
{ "device_id", QEMU_CAPS_SCSI_DISK_DEVICE_ID, NULL },
{ "werror", QEMU_CAPS_STORAGE_WERROR, NULL },
{ "rotation_rate", QEMU_CAPS_ROTATION_RATE, NULL },
};
static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsIDEDrive[] = {

View File

@ -604,6 +604,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */
QEMU_CAPS_AUDIODEV, /* -audiodev instead of QEMU_AUDIO_DRV */
QEMU_CAPS_BLOCKDEV_BACKUP, /* qemu supports the blockdev-backup job */
QEMU_CAPS_OBJECT_QAPIFIED, /* parameters for object-add are formally described */
QEMU_CAPS_ROTATION_RATE, /* scsi-disk / ide-drive rotation-rate prop */
QEMU_CAPS_LAST /* this must always be the last item */
} virQEMUCapsFlags;

View File

@ -1863,6 +1863,9 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
virBufferAsprintf(&opt, ",wwn=0x%s", disk->wwn);
}
if (disk->rotation_rate)
virBufferAsprintf(&opt, ",rotation_rate=%u", disk->rotation_rate);
if (disk->vendor) {
virBufferAddLit(&opt, ",vendor=");
virQEMUBuildBufferEscapeComma(&opt, disk->vendor);

View File

@ -2547,6 +2547,28 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
}
}
if (disk->rotation_rate) {
if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI &&
disk->bus != VIR_DOMAIN_DISK_BUS_IDE &&
disk->bus != VIR_DOMAIN_DISK_BUS_SATA) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("rotation rate is only valid for SCSI/IDE/SATA bus"));
return -1;
}
if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("rotation rate is only valid for disk device"));
return -1;
}
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_ROTATION_RATE)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("rotation rate is not supported with this QEMU"));
return -1;
}
}
switch (disk->bus) {
case VIR_DOMAIN_DISK_BUS_SCSI:
diskInfo = (virDomainDeviceInfoPtr)&disk->info;

View File

@ -169,6 +169,7 @@
<flag name='vhost-user-blk'/>
<flag name='cpu-max'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>2012000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>61700289</microcodeVersion>

View File

@ -184,6 +184,7 @@
<flag name='cpu-max'/>
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>4000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>61700240</microcodeVersion>

View File

@ -192,6 +192,7 @@
<flag name='cpu-max'/>
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>4000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>42900240</microcodeVersion>

View File

@ -184,6 +184,7 @@
<flag name='vhost-user-blk'/>
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>4000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>0</microcodeVersion>

View File

@ -184,6 +184,7 @@
<flag name='vhost-user-blk'/>
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>4000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>0</microcodeVersion>

View File

@ -148,6 +148,7 @@
<flag name='cpu-max'/>
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>4000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>39100240</microcodeVersion>

View File

@ -229,6 +229,7 @@
<flag name='cpu-max'/>
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>4000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>43100240</microcodeVersion>

View File

@ -236,6 +236,7 @@
<flag name='cpu-max'/>
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='rotation-rate'/>
<version>4001000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>43100241</microcodeVersion>

View File

@ -199,6 +199,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>4001050</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>61700242</microcodeVersion>

View File

@ -199,6 +199,7 @@
<flag name='memory-backend-file.x-use-canonical-path-for-ramblock-id'/>
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='rotation-rate'/>
<version>4001050</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>42900242</microcodeVersion>

View File

@ -161,6 +161,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>4002000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>39100242</microcodeVersion>

View File

@ -247,6 +247,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>4002000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>43100242</microcodeVersion>

View File

@ -209,6 +209,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>61700241</microcodeVersion>

View File

@ -218,6 +218,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>42900241</microcodeVersion>

View File

@ -204,6 +204,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>0</microcodeVersion>

View File

@ -254,6 +254,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5000000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>43100241</microcodeVersion>

View File

@ -119,6 +119,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5001000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>0</microcodeVersion>

View File

@ -256,6 +256,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5001000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>43100242</microcodeVersion>

View File

@ -213,6 +213,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5002000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>61700243</microcodeVersion>

View File

@ -220,6 +220,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5002000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>42900243</microcodeVersion>

View File

@ -206,6 +206,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5002000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>0</microcodeVersion>

View File

@ -168,6 +168,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5002000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>39100243</microcodeVersion>

View File

@ -257,6 +257,7 @@
<flag name='vnc-opts'/>
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='rotation-rate'/>
<version>5002000</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>43100243</microcodeVersion>

View File

@ -260,6 +260,7 @@
<flag name='audiodev'/>
<flag name='blockdev-backup'/>
<flag name='object.qapified'/>
<flag name='rotation-rate'/>
<version>5002050</version>
<kvmVersion>0</kvmVersion>
<microcodeVersion>43100242</microcodeVersion>

View File

@ -0,0 +1,56 @@
LC_ALL=C \
PATH=/bin \
HOME=/tmp/lib/domain--1-QEMUGuest1 \
USER=test \
LOGNAME=test \
XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
/usr/bin/qemu-system-i386 \
-name guest=QEMUGuest1,debug-threads=on \
-S \
-object '{"qom-type":"secret","id":"masterKey0","format":"raw",\
"file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \
-machine pc,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \
-cpu qemu64 \
-m 214 \
-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \
-overcommit mem-lock=off \
-smp 8,sockets=8,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
-display none \
-no-user-config \
-nodefaults \
-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
-mon chardev=charmonitor,id=monitor,mode=control \
-rtc base=utc \
-no-shutdown \
-no-acpi \
-boot strict=on \
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x2 \
-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\
"node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"raw",\
"file":"libvirt-3-storage"}' \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\
device_id=drive-scsi0-0-0-0,drive=libvirt-3-format,id=scsi0-0-0-0,bootindex=1,\
rotation_rate=7200 \
-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest2",\
"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw",\
"file":"libvirt-2-storage"}' \
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=1,\
device_id=drive-scsi0-0-0-1,drive=libvirt-2-format,id=scsi0-0-0-1,\
rotation_rate=1 \
-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest3",\
"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\
"file":"libvirt-1-storage"}' \
-device ide-hd,bus=ide.0,unit=0,drive=libvirt-1-format,id=ide0-0-0,\
rotation_rate=4500 \
-audiodev id=audio1,driver=none \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
resourcecontrol=deny \
-msg timestamp=on

View File

@ -0,0 +1,38 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219136</memory>
<currentMemory unit='KiB'>219136</currentMemory>
<vcpu placement='static'>8</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-i386</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='sda' bus='scsi' rotation_rate='7200'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest2'/>
<target dev='sdb' bus='scsi' rotation_rate='1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest3'/>
<target dev='hda' bus='ide' rotation_rate='4500'/>
</disk>
<controller type='usb' index='0'/>
<controller type='scsi' index='0' model='virtio-scsi'/>
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<memballoon model='virtio'/>
</devices>
</domain>

View File

@ -1469,6 +1469,7 @@ mymain(void)
DO_TEST_CAPS_LATEST("disk-backing-chains-noindex");
DO_TEST_CAPS_LATEST("disk-slices");
DO_TEST_CAPS_LATEST("disk-rotation");
DO_TEST_CAPS_ARCH_VER("disk-arm-virtio-sd", "aarch64", "4.0.0");
DO_TEST_CAPS_ARCH_LATEST("disk-arm-virtio-sd", "aarch64");

View File

@ -0,0 +1,55 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219136</memory>
<currentMemory unit='KiB'>219136</currentMemory>
<vcpu placement='static'>8</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-i386</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='sda' bus='scsi' rotation_rate='7200'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest2'/>
<target dev='sdb' bus='scsi' rotation_rate='1'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest3'/>
<target dev='hda' bus='ide' rotation_rate='4500'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='scsi' index='0' model='virtio-scsi'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<audio id='1' type='none'/>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</memballoon>
</devices>
</domain>

View File

@ -525,6 +525,7 @@ mymain(void)
DO_TEST("pci-serial-dev-chardev", NONE);
DO_TEST_CAPS_LATEST("disk-slices");
DO_TEST_CAPS_LATEST("disk-rotation");
DO_TEST("encrypted-disk", QEMU_CAPS_QCOW2_LUKS);
DO_TEST("encrypted-disk-usage", QEMU_CAPS_QCOW2_LUKS);