[PATCH 8/8] qemu: format options for enforcing virtio revisions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Translate the optional <virtio revision> attribute to
disable-legacy=on/off and disable-modern=on/off options
for the following devices:

<memballoon>    virtio-balloon-pci
<disk>          virtio-blk-pci
<controller>    virtio-scsi-pci
                virtio-serial-pci
<filesystem>    virtio-9p-pci
<interface>     virtio-net-pci
<rng>           virtio-rng-pci
---
 src/qemu/qemu_command.c                            | 31 ++++++++++++
 .../qemuxml2argv-virtio-revision.args              | 58 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           | 10 ++++
 3 files changed, 99 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-virtio-revision.args

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 5325f48..db38279 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -386,6 +386,23 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
     return ret;
 }
 
+static void
+qemuBuildVirtioRevisionStr(virBufferPtr buf,
+                           virDomainVirtioRevision rev)
+{
+    switch (rev) {
+    case VIR_DOMAIN_VIRTIO_REVISION_HERITAGE:
+        virBufferAddLit(buf, ",disable-legacy=off,disable-modern=on");
+        break;
+    case VIR_DOMAIN_VIRTIO_REVISION_CONTEMPORARY:
+        virBufferAddLit(buf, ",disable-legacy=on,disable-modern=off");
+        break;
+    case VIR_DOMAIN_VIRTIO_REVISION_DEFAULT:
+    case VIR_DOMAIN_VIRTIO_REVISION_LAST:
+        break;
+    }
+}
+
 static int
 qemuBuildRomStr(virBufferPtr buf,
                 virDomainDeviceInfoPtr info)
@@ -1992,6 +2009,9 @@ qemuBuildDriveDevStr(const virDomainDef *def,
                               (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN)
                               ? "on" : "off");
         }
+
+        qemuBuildVirtioRevisionStr(&opt, disk->virtio_rev);
+
         if (qemuBuildDeviceAddressStr(&opt, def, &disk->info, qemuCaps) < 0)
             goto error;
         break;
@@ -2311,6 +2331,8 @@ qemuBuildFSDevStr(const virDomainDef *def,
                       QEMU_FSDEV_HOST_PREFIX, fs->info.alias);
     virBufferAsprintf(&opt, ",mount_tag=%s", fs->dst);
 
+    qemuBuildVirtioRevisionStr(&opt, fs->virtio_rev);
+
     if (qemuBuildDeviceAddressStr(&opt, def, &fs->info, qemuCaps) < 0)
         goto error;
 
@@ -2568,6 +2590,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                                       def->iothread);
                 }
             }
+            qemuBuildVirtioRevisionStr(&buf, def->virtio_rev);
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC:
             virBufferAddLit(&buf, "lsi");
@@ -2613,6 +2636,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
             virBufferAsprintf(&buf, ",vectors=%d",
                               def->opts.vioserial.vectors);
         }
+        qemuBuildVirtioRevisionStr(&buf, def->virtio_rev);
         break;
 
     case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
@@ -3557,6 +3581,9 @@ qemuBuildNicDevStr(virDomainDefPtr def,
     virBufferAsprintf(&buf, ",id=%s", net->info.alias);
     virBufferAsprintf(&buf, ",mac=%s",
                       virMacAddrFormat(&net->mac, macaddr));
+
+    qemuBuildVirtioRevisionStr(&buf, net->virtio_rev);
+
     if (qemuBuildDeviceAddressStr(&buf, def, &net->info, qemuCaps) < 0)
         goto error;
     if (qemuBuildRomStr(&buf, &net->info) < 0)
@@ -3827,6 +3854,8 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd,
                           virTristateSwitchTypeToString(def->memballoon->autodeflate));
     }
 
+    qemuBuildVirtioRevisionStr(&buf, def->memballoon->virtio_rev);
+
     virCommandAddArg(cmd, "-device");
     virCommandAddArgBuffer(cmd, &buf);
     return 0;
@@ -5564,6 +5593,8 @@ qemuBuildRNGDevStr(const virDomainDef *def,
             virBufferAddLit(&buf, ",period=1000");
     }
 
+    qemuBuildVirtioRevisionStr(&buf, dev->virtio_rev);
+
     if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
         goto error;
     if (virBufferCheckError(&buf) < 0)
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-revision.args b/tests/qemuxml2argvdata/qemuxml2argv-virtio-revision.args
new file mode 100644
index 0000000..9ba70af
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-revision.args
@@ -0,0 +1,58 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest1 \
+-S \
+-M pc \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-device virtio-scsi-pci,disable-legacy=off,disable-modern=on,id=scsi0,\
+bus=pci.0,addr=0x8 \
+-device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x9 \
+-usb \
+-drive file=/var/lib/libvirt/images/img1,format=raw,if=none,\
+id=drive-virtio-disk0 \
+-device virtio-blk-pci,disable-legacy=off,disable-modern=on,bus=pci.0,addr=0xa,\
+drive=drive-virtio-disk0,id=virtio-disk0 \
+-drive file=/var/lib/libvirt/images/img2,format=raw,if=none,\
+id=drive-virtio-disk1 \
+-device virtio-blk-pci,disable-legacy=on,disable-modern=off,bus=pci.0,addr=0xb,\
+drive=drive-virtio-disk1,id=virtio-disk1 \
+-drive file=/var/lib/libvirt/images/img3,format=raw,if=none,\
+id=drive-scsi0-0-0-0 \
+-device scsi-disk,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\
+drive=drive-scsi0-0-0-0,id=scsi0-0-0-0 \
+-fsdev local,security_model=passthrough,id=fsdev-fs0,path=/export/fs1 \
+-device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=fs1,disable-legacy=off,\
+disable-modern=on,bus=pci.0,addr=0x3 \
+-fsdev local,security_model=mapped,writeout=immediate,id=fsdev-fs1,\
+path=/export/fs2 \
+-device virtio-9p-pci,id=fs1,fsdev=fsdev-fs1,mount_tag=fs2,disable-legacy=on,\
+disable-modern=off,bus=pci.0,addr=0x4 \
+-device virtio-net-pci,vlan=0,id=net0,mac=52:54:56:58:5a:5c,disable-legacy=off,\
+disable-modern=on,bus=pci.0,addr=0x6 \
+-net user,vlan=0,name=hostnet0 \
+-device virtio-net-pci,vlan=1,id=net1,mac=52:54:56:5a:5c:5e,disable-legacy=on,\
+disable-modern=off,bus=pci.0,addr=0x7 \
+-net user,vlan=1,name=hostnet1 \
+-device virtio-mouse-pci,id=input0,bus=pci.0,addr=0xe \
+-device virtio-keyboard-pci,id=input1,bus=pci.0,addr=0x10 \
+-device virtio-tablet-pci,id=input2,bus=pci.0,addr=0x11 \
+-device virtio-input-host-pci,id=input3,evdev=/dev/input/event1234,bus=pci.0,\
+addr=0x12 \
+-device virtio-vga,id=video0,virgl=on,bus=pci.0,addr=0x2 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0xc,disable-legacy=off,\
+disable-modern=on \
+-object rng-random,id=objrng0,filename=/dev/random \
+-device virtio-rng-pci,rng=objrng0,id=rng0,disable-legacy=on,\
+disable-modern=off,bus=pci.0,addr=0xd
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index a5d51a8..1d64324 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2072,6 +2072,16 @@ mymain(void)
     DO_TEST("intel-iommu", QEMU_CAPS_DEVICE_PCI_BRIDGE,
             QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_DEVICE_INTEL_IOMMU);
 
+    DO_TEST("virtio-revision", QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_VIRTIO_KEYBOARD,
+            QEMU_CAPS_VIRTIO_MOUSE, QEMU_CAPS_VIRTIO_TABLET,
+            QEMU_CAPS_VIRTIO_INPUT_HOST,
+            QEMU_CAPS_FSDEV, QEMU_CAPS_FSDEV_WRITEOUT,
+            QEMU_CAPS_DEVICE_VIRTIO_GPU,
+            QEMU_CAPS_DEVICE_VIRTIO_GPU_VIRGL,
+            QEMU_CAPS_DEVICE_VIRTIO_RNG,
+            QEMU_CAPS_OBJECT_RNG_RANDOM,
+            QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
+
     qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]