[libvirt] [PATCH 3/3] Add QEMU support for virtio channel

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

 



Support virtio-serial controller and virtio channel in QEMU backend. Will output
the following for virtio-serial controller:

-device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4

and the following for a virtio channel:

-chardev pty,id=channel0 \
-device virtserialport,chardev=channel0,name=org.linux-kvm.port.0

* src/qemu/qemu_conf.c: Add argument output for virtio
* tests/qemuxml2argvtest.c
  tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args
                      : Add test for QEMU command line generation
---
 src/qemu/qemu_conf.c                               |   51 +++++++++++++++++++-
 .../qemuxml2argv-channel-virtio.args               |    1 +
 tests/qemuxml2argvtest.c                           |    1 +
 3 files changed, 52 insertions(+), 1 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 0c67334..73c6e28 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1681,7 +1681,6 @@ qemuAssignDevicePCISlots(virDomainDefPtr def)
     }
     for (i = 0; i < def->nchannels ; i++) {
         /* Nada - none are PCI based (yet) */
-        /* XXX virtio-serial will need one */
     }
     if (def->watchdog) {
         qemuAssignDevicePCISlot(&def->watchdog->info, nextslot++);
@@ -2121,6 +2120,15 @@ qemuBuildControllerDevStr(virDomainControllerDefPtr def)
         virBufferVSprintf(&buf, ",id=scsi%d", def->idx);
         break;
 
+    case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
+        if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+            virBufferAddLit(&buf, "virtio-serial-pci");
+        } else {
+            virBufferAddLit(&buf, "virtio-serial");
+        }
+        virBufferVSprintf(&buf, ",id=virtio-serial%d", def->idx);
+        break;
+
     /* We always get an IDE controller, whether we want it or not. */
     case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
     default:
@@ -3508,6 +3516,47 @@ int qemudBuildCommandLine(virConnectPtr conn,
             }
 
             ADD_ARG(virBufferContentAndReset(&buf));
+            break;
+
+        case VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO:
+            if (!(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
+                qemudReportError(conn, NULL, NULL, VIR_ERR_NO_SUPPORT, "%s",
+                    _("virtio channel requires QEMU to support -device"));
+                goto error;
+            }
+
+            qemudBuildCommandLineChrDevChardevStr(channel, &buf);
+            if (virBufferError(&buf))
+                goto error;
+
+            ADD_ARG_LIT("-chardev");
+            ADD_ARG(virBufferContentAndReset(&buf));
+
+            virBufferVSprintf(&buf, "virtserialport,chardev=%s",
+                              channel->info.alias);
+            if (channel->target.virtio.name) {
+                virBufferVSprintf(&buf, ",name=%s",
+                                  channel->target.virtio.name);
+            }
+            if (channel->target.virtio.byteLimit) {
+                virBufferVSprintf(&buf, ",byte_limit=%s",
+                                  channel->target.virtio.byteLimit);
+            }
+            if (channel->target.virtio.guestByteLimit) {
+                virBufferVSprintf(&buf, ",guest_byte_limit=%s",
+                                  channel->target.virtio.guestByteLimit);
+            }
+            if (channel->target.virtio.cacheBuffers) {
+                virBufferVSprintf(&buf, ",cache_buffers=%s",
+                                  channel->target.virtio.cacheBuffers);
+            }
+            if (virBufferError(&buf))
+                goto error;
+
+            ADD_ARG_LIT("-device");
+            ADD_ARG(virBufferContentAndReset(&buf));
+
+            break;
         }
     }
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args
new file mode 100644
index 0000000..ded97d1
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4 -hda /dev/HostVG/QEMUGuest1 -chardev pty,id=channel0 -device virtserialport,chardev=channel0,name=org.linux-kvm.port.0,byte_limit=1048576,guest_byte_limit=1048576,cache_buffers=1 -usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index fc237c2..f6b33c2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -297,6 +297,7 @@ mymain(int argc, char **argv)
     DO_TEST("console-compat-chardev", QEMUD_CMD_FLAG_CHARDEV|QEMUD_CMD_FLAG_DEVICE);
 
     DO_TEST("channel-guestfwd", QEMUD_CMD_FLAG_CHARDEV|QEMUD_CMD_FLAG_DEVICE);
+    DO_TEST("channel-virtio", QEMUD_CMD_FLAG_DEVICE);
 
     DO_TEST("watchdog", 0);
     DO_TEST("watchdog-device", QEMUD_CMD_FLAG_DEVICE);
-- 
1.6.6

--
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]