query and control virtio version

February 7, 2018
libvirt qemu virtio

virtio: modern/legacy = ???

a.k.a puzzlement about inquiring or controlling virtio revisions via libvirt

When looking around how to check for the current setting of modern/legacy virtio, or how to control it via libvirt I only found dead ends at first.

You might find the baked-in defaults changing in qemu 2.7 in include/hw/compat.h by this commit. But this has so many special cases and triggers that might change it, that at least I wasn#t sure what effectively is used.

So what could you do to:

It is not nice and clean due to above mentioned changes not having landed, but at least there is some way to do it. To query you can at least find the info in the qtree. using virsh qemu-monitor-command as an easy way to access the guests monitor you can for example run.

$ virsh qemu-monitor-command --hmp <guestname> 'info qtree'

That gave me the following per device virtio-blk-pci that I was looking for:

          dev: virtio-blk-pci, id "virtio-disk0"
            [...]
            disable-legacy = "on"
            disable-modern = false

Obviously this lets you check way more attributes and devices, so take a look even if you are looking for something else.

In my case I now knew that disable-legacy was “on”. But how could I change that when - as in my case - I can’t modify the qemu cmdline directly?

There is qemu:commandline to control qemu commandline arguments from libvirt, but in my case I needed to inject a driver property. And that the disks part of the commandline is rendered independent to qemu:commandline. Remember that due to the lack of virtio revision control you can’t just tell the libvirt to render it the way you want it per device. Also in addition I also had hotplug devices which would use a completely different path than the commandline anyway.

The solution is to combine qemu:commandline with -global of the qemu standard options. Combining all that a change to my guest looked like:

    > <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
    [...]
    >   <qemu:commandline>
    >     <qemu:arg value='-global'/>
    >     <qemu:arg value='virtio-blk-pci.disable-legacy=off'/>
    >   </qemu:commandline>

That made the qemu commandline have: -global virtio-blk-pci.disable-legacy=off And that in turn made my devices supporting modern and legcay as I wanted it for a test that I was doing.

      dev: virtio-blk-pci, id "virtio-disk0"
        [...]
        disable-legacy = "off"
        disable-modern = false

I hope that might help somebody else out there as well.

Dusma bleiwe …