Skip to contentSkip to conversation

Multiple port support for virtio-console

Qemu-devel In review Amit Shah 2 participants 14 messages Sep 22, 2009 – Sep 23, 2009 Kbuild

lore
Share & tools
lore

Amit Shah

author
#0 lore raw

Hello,

This patch series converts virtio-console to qdev, adds a new virtio-console bus and spawns new ports as devices on the bus.

A few regressions have been introduced (old kernel / new userspace doesn't work), I'll be looking at that and other issues.

Posting this just to show the approach taken for the new bus.

Amit

author
#1 lore raw

PATCH 1/4 char: Emit 'OPENED' events on char device open

Notify users of the char interface whenever the file / connection is opened.

The existing RESET event is triggered when the qemu char state is reset as well; which may not be as interesting as char device open events.

---
 qemu-char.c |   14 +++++++++++++-
 qemu-char.h |    1 +
 2 files changed, 14 insertions(+), 1 deletions(-)
qemu-char.c +13 -1
index 8084a67..e7d091c 100644
@@ -479,6 +479,8 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
     chr->chr_write = mux_chr_write;
     chr->chr_update_read_handler = mux_chr_update_read_handler;
     chr->chr_accept_input = mux_chr_accept_input;
+
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
     return chr;
 }
 
@@ -627,6 +629,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
     chr->chr_close = fd_chr_close;
 
     qemu_chr_reset(chr);
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
 
     return chr;
 }
@@ -925,8 +928,10 @@ static void pty_chr_state(CharDriverState *chr, int connected)
          * the virtual device linked to our pty. */
         qemu_mod_timer(s->timer, qemu_get_clock(rt_clock) + 1000);
     } else {
-        if (!s->connected)
+        if (!s->connected) {
             qemu_chr_reset(chr);
+            qemu_chr_event(chr, CHR_EVENT_OPENED);
+        }
         s->connected = 1;
     }
 }
@@ -1166,6 +1171,7 @@ static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
     }
     chr->chr_ioctl = tty_serial_ioctl;
     qemu_chr_reset(chr);
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
     return chr;
 }
 #else  /* ! __linux__ && ! __sun__ */
@@ -1312,6 +1318,7 @@ static CharDriverState *qemu_chr_open_pp(QemuOpts *opts)
     chr->opaque = drv;
 
     qemu_chr_reset(chr);
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
 
     return chr;
 }
@@ -1593,6 +1600,7 @@ static CharDriverState *qemu_chr_open_win(QemuOpts *opts)
         return NULL;
     }
     qemu_chr_reset(chr);
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
     return chr;
 }
 
@@ -1693,6 +1701,7 @@ static CharDriverState *qemu_chr_open_win_pipe(QemuOpts *opts)
         return NULL;
     }
     qemu_chr_reset(chr);
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
     return chr;
 }
 
@@ -1707,6 +1716,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
     chr->opaque = s;
     chr->chr_write = win_chr_write;
     qemu_chr_reset(chr);
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
     return chr;
 }
 
@@ -1828,6 +1838,7 @@ static CharDriverState *qemu_chr_open_udp(QemuOpts *opts)
     chr->chr_write = udp_chr_write;
     chr->chr_update_read_handler = udp_chr_update_read_handler;
     chr->chr_close = udp_chr_close;
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
     return chr;
 
 return_err:
@@ -2034,6 +2045,7 @@ static void tcp_chr_connect(void *opaque)
     qemu_set_fd_handler2(s->fd, tcp_chr_read_poll,
                          tcp_chr_read, NULL, chr);
     qemu_chr_reset(chr);
+    qemu_chr_event(chr, CHR_EVENT_OPENED);
 }
 
 #define IACSET(x,a,b,c) x[0] = a; x[1] = b; x[2] = c;
qemu-char.h +1 -0
index c0654bc..43e61e0 100644
@@ -14,6 +14,7 @@
 #define CHR_EVENT_MUX_IN  3 /* mux-focus was set to this terminal */
 #define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
 #define CHR_EVENT_CLOSED  5 /* connection closed */
+#define CHR_EVENT_OPENED  6 /* connection opened */
 
 
 #define CHR_IOCTL_SERIAL_SET_PARAMS   1
Signature · 1 line
1.6.2.5
author
#2 lore raw

PATCH 2/4 qdev: add string property.

From: Gerd Hoffmann <[email protected]>

---
 hw/qdev-properties.c |   28 ++++++++++++++++++++++++++++
 hw/qdev.h            |    4 ++++
 2 files changed, 32 insertions(+), 0 deletions(-)
hw/qdev-properties.c +28 -0
index 2ecb58d..7e085f6 100644
@@ -165,6 +165,34 @@ PropertyInfo qdev_prop_hex64 = {
     .print = print_hex64,
 };
 
+/* --- string --- */
+
+static int parse_string(DeviceState *dev, Property *prop, const char *str)
+{
+    char **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr)
+        qemu_free(*ptr);
+    *ptr = qemu_strdup(str);
+    return 0;
+}
+
+static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+    char **ptr = qdev_get_prop_ptr(dev, prop);
+    if (!*ptr)
+        return snprintf(dest, len, "<null>");
+    return snprintf(dest, len, "\"%s\"", *ptr);
+}
+
+PropertyInfo qdev_prop_string = {
+    .name  = "string",
+    .type  = PROP_TYPE_STRING,
+    .size  = sizeof(char*),
+    .parse = parse_string,
+    .print = print_string,
+};
+
 /* --- drive --- */
 
 static int parse_drive(DeviceState *dev, Property *prop, const char *str)
hw/qdev.h +4 -0
index 623ded5..cd9da17 100644
@@ -68,6 +68,7 @@ enum PropertyType {
     PROP_TYPE_MACADDR,
     PROP_TYPE_DRIVE,
     PROP_TYPE_CHR,
+    PROP_TYPE_STRING,
     PROP_TYPE_PTR,
 };
 
@@ -161,6 +162,7 @@ extern PropertyInfo qdev_prop_int32;
 extern PropertyInfo qdev_prop_uint64;
 extern PropertyInfo qdev_prop_hex32;
 extern PropertyInfo qdev_prop_hex64;
+extern PropertyInfo qdev_prop_string;
 extern PropertyInfo qdev_prop_chr;
 extern PropertyInfo qdev_prop_ptr;
 extern PropertyInfo qdev_prop_macaddr;
@@ -200,6 +202,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
     DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
 #define DEFINE_PROP_CHR(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
+#define DEFINE_PROP_STRING(_n, _s, _f)             \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
 #define DEFINE_PROP_DRIVE(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
 #define DEFINE_PROP_MACADDR(_n, _s, _f)         \
Signature · 1 line
1.6.2.5
author
#3 lore raw

PATCH 3/4 virtio-console: Add support for multiple ports for generic guest-host communication

This interface extends the virtio-console device to handle multiple ports that present a char device from which bits can be sent and read.

Sample uses for such a device can be obtaining info from the guest like the file systems used, apps installed, etc. for offline usage and logged-in users, clipboard copy-paste, etc. for online usage.

For requirements, use-cases and some history see

http://www.linux-kvm.org/page/VMchannel_Requirements

---
 Makefile.target         |    2 +-
 hw/pc.c                 |    9 -
 hw/qdev.c               |    9 +-
 hw/virtio-console-bus.c |  111 ++++++++
 hw/virtio-console.c     |  646 +++++++++++++++++++++++++++++++++++++++++++----
 hw/virtio-console.h     |   73 ++++++
 qemu-options.hx         |    8 -
 sysemu.h                |    7 +-
 vl.c                    |   37 ---
 9 files changed, 781 insertions(+), 121 deletions(-)
 create mode 100644 hw/virtio-console-bus.c
Makefile.target +1 -1
index 609015b..22a2644 100644
@@ -173,7 +173,7 @@ obj-y = vl.o monitor.o pci.o isa_mmio.o machine.o \
         gdbstub.o gdbstub-xml.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
-obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-pci.o
+obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-console-bus.o virtio-pci.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 
 LIBS+=-lz
hw/pc.c +0 -9
index 240cfe0..70b1ce9 100644
@@ -1463,15 +1463,6 @@ static void pc_init1(ram_addr_t ram_size,
 	extboot_init(info->bdrv, 1);
     }
 
-    /* Add virtio console devices */
-    if (pci_enabled) {
-        for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-            if (virtcon_hds[i]) {
-                pci_create_simple(pci_bus, -1, "virtio-console-pci");
-            }
-        }
-    }
-
 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
     if (kvm_enabled()) {
         add_assigned_devices(pci_bus, assigned_devices, assigned_devices_index);
hw/qdev.c +2 -7
index 43b1beb..1d79db0 100644
@@ -243,13 +243,8 @@ void qdev_free(DeviceState *dev)
 CharDriverState *qdev_init_chardev(DeviceState *dev)
 {
     static int next_serial;
-    static int next_virtconsole;
-    /* FIXME: This is a nasty hack that needs to go away.  */
-    if (strncmp(dev->info->name, "virtio", 6) == 0) {
-        return virtcon_hds[next_virtconsole++];
-    } else {
-        return serial_hds[next_serial++];
-    }
+
+    return serial_hds[next_serial++];
 }
 
 BusState *qdev_get_parent_bus(DeviceState *dev)
hw/virtio-console-bus.c new file +111 -0

111 lines not on this page · raw message

hw/virtio-console.c +593 -53

735 lines not on this page · raw message

hw/virtio-console.h +73 -0

89 lines not on this page · raw message

qemu-options.hx +0 -8
index 2f4291d..ca412bf 100644
@@ -1604,14 +1604,6 @@ character to Control-t.
 @end table
 ETEXI
 
-DEF("virtioconsole", HAS_ARG, QEMU_OPTION_virtiocon, \
-    "-virtioconsole c\n" \
-    "                set virtio console\n")
-STEXI
-@item -virtioconsole @var{c}
-Set virtio console.
-ETEXI
-
 DEF("show-cursor", 0, QEMU_OPTION_show_cursor, \
     "-show-cursor    show cursor\n")
 STEXI
sysemu.h +1 -6
index a8d1549..af0e7d8 100644
@@ -2,6 +2,7 @@
 #define SYSEMU_H
 /* Misc. things related to the system emulator.  */
 
+#include <stdbool.h>
 #include "qemu-common.h"
 #include "qemu-option.h"
 #include "qemu-queue.h"
@@ -233,12 +234,6 @@ extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 
 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 
-/* virtio consoles */
-
-#define MAX_VIRTIO_CONSOLES 1
-
-extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
-
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 #ifdef HAS_AUDIO
vl.c +0 -37
index 3b49c56..b5215b2 100644
@@ -213,7 +213,6 @@ static int no_frame = 0;
 int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
-CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
 #ifdef TARGET_I386
 int win2k_install_hack = 0;
 int rtc_td_hack = 0;
@@ -4690,8 +4689,6 @@ int main(int argc, char **argv, char **envp)
     int serial_device_index;
     const char *parallel_devices[MAX_PARALLEL_PORTS];
     int parallel_device_index;
-    const char *virtio_consoles[MAX_VIRTIO_CONSOLES];
-    int virtio_console_index;
     const char *loadvm = NULL;
     QEMUMachine *machine;
     const char *cpu_model;
@@ -4765,10 +4762,6 @@ int main(int argc, char **argv, char **envp)
         parallel_devices[i] = NULL;
     parallel_device_index = 0;
 
-    for(i = 0; i < MAX_VIRTIO_CONSOLES; i++)
-        virtio_consoles[i] = NULL;
-    virtio_console_index = 0;
-
     monitor_devices[0] = "vc:80Cx24C";
     for (i = 1; i < MAX_MONITOR_DEVICES; i++) {
         monitor_devices[i] = NULL;
@@ -5228,14 +5221,6 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
-            case QEMU_OPTION_virtiocon:
-                if (virtio_console_index >= MAX_VIRTIO_CONSOLES) {
-                    fprintf(stderr, "qemu: too many virtio consoles\n");
-                    exit(1);
-                }
-                virtio_consoles[virtio_console_index] = optarg;
-                virtio_console_index++;
-                break;
             case QEMU_OPTION_parallel:
                 if (parallel_device_index >= MAX_PARALLEL_PORTS) {
                     fprintf(stderr, "qemu: too many parallel ports\n");
@@ -5827,20 +5812,6 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
-    for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-        const char *devname = virtio_consoles[i];
-        if (devname && strcmp(devname, "none")) {
-            char label[32];
-            snprintf(label, sizeof(label), "virtcon%d", i);
-            virtcon_hds[i] = qemu_chr_open(label, devname, NULL);
-            if (!virtcon_hds[i]) {
-                fprintf(stderr, "qemu: could not open virtio console '%s'\n",
-                        devname);
-                exit(1);
-            }
-        }
-    }
-
     module_call_init(MODULE_INIT_DEVICE);
 
     if (watchdog) {
@@ -5968,14 +5939,6 @@ int main(int argc, char **argv, char **envp)
         }
     }
 
-    for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
-        const char *devname = virtio_consoles[i];
-        if (virtcon_hds[i] && devname) {
-            if (strstart(devname, "vc", 0))
-                qemu_chr_printf(virtcon_hds[i], "virtio console%d\r\n", i);
-        }
-    }
-
     if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
         fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
                 gdbstub_dev);
Signature · 1 line
1.6.2.5
author
#4 lore raw

PATCH 4/4 virtio-console: Add a in-qemu api for open/read/write/close ports

This is a simple-to-use api for opening a port, registering a callback for read, writing to a port and closing it.

---
 hw/virtio-console.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++--
 hw/virtio-console.h |    5 ++++
 2 files changed, 69 insertions(+), 3 deletions(-)
hw/virtio-console.c +64 -3
index d750c8e..c41f13c 100644
@@ -58,6 +58,11 @@ struct VirtIOConsolePort {
 
     QTAILQ_HEAD(, VirtIOConsolePortBuffer) unflushed_buffer_head;
 
+    /* Callback that's invoked when we have a buffer that can be consumed
+     * by an in-qemu user of this port
+     */
+    size_t (*read_callback)(const uint8_t *buf, const size_t len);
+
     bool guest_connected;
     bool host_connected;
 };
@@ -128,10 +133,15 @@ static bool has_complete_data(VirtIOConsolePort *port)
 
 static size_t flush_buf(VirtIOConsolePort *port, const uint8_t *buf, size_t len)
 {
-    if (!port->hd) {
-        return 0;
+    int ret;
+
+    ret = 0;
+    if (port->read_callback) {
+        ret = port->read_callback(buf, len);
+    } else if (port->hd) {
+        ret = qemu_chr_write(port->hd, buf, len);
     }
-    return qemu_chr_write(port->hd, buf, len);
+    return ret;
 }
 
 static void flush_queue(VirtIOConsolePort *port)
@@ -443,6 +453,57 @@ static void vcon_event(void *opaque, int event)
     send_control_event(port, &cpkt);
 }
 
+
+/* Functions for use inside qemu to open and read from/write to ports */
+VirtIOConsolePort *virtio_console_open(uint32_t id,
+                                       size_t(*read_callback)(const uint8_t*buf,
+                                                              const size_t len))
+{
+    VirtIOConsolePort *port;
+    struct virtio_console_control cpkt;
+
+    port = get_port_from_id(virtio_console, id);
+    if (!port) {
+        return NULL;
+    }
+    /* Don't allow opening an already-open port */
+    if (port->host_connected) {
+        return NULL;
+    }
+    port->read_callback = read_callback;
+
+    /* Send port open notification to the guest */
+    port->host_connected = true;
+    cpkt.event = VIRTIO_CONSOLE_PORT_OPEN;
+    cpkt.value = 1;
+    send_control_event(port, &cpkt);
+
+    return port;
+}
+
+void virtio_console_close(VirtIOConsolePort *port)
+{
+    struct virtio_console_control cpkt;
+
+    if (!port)
+        return;
+
+    port->read_callback = NULL;
+
+    cpkt.event = VIRTIO_CONSOLE_PORT_OPEN;
+    cpkt.value = 0;
+    send_control_event(port, &cpkt);
+}
+
+size_t virtio_console_write(VirtIOConsolePort *port, uint8_t *buf, size_t size)
+{
+    if (!port || !port->host_connected) {
+        return 0;
+    }
+    return write_to_port(port, buf, size, false);
+}
+
+
 static void set_active_in_map(uint32_t *map, uint32_t idx)
 {
     int i;
hw/virtio-console.h +5 -0
index 526713e..5f0f549 100644
@@ -88,5 +88,10 @@ VirtConBus *virtcon_bus_new(DeviceState *dev);
 typedef struct VirtIOConsolePort VirtIOConsolePort;
 void virtio_console_monitor_command(Monitor *mon,
                                     const char *command, const char *param);
+VirtIOConsolePort *virtio_console_open(uint32_t id,
+                                       size_t(*read_callback)(const uint8_t*buf,
+                                                              const size_t len));
+void virtio_console_close(VirtIOConsolePort *port);
+size_t virtio_console_write(VirtIOConsolePort *port, uint8_t *buf, size_t size);
 
 #endif
Signature · 1 line
1.6.2.5
#5 lore raw

Re: [Qemu-devel] [PATCH 4/4] virtio-console: Add a in-qemu api for open/read/write/close ports

hw/virtio-console.c struct VirtIOConsolePort { · line 60

Quoted 13 lines
hw/virtio-console.c +5 -1
index d750c8e..c41f13c 100644
@@ -58,6 +58,11 @@ struct VirtIOConsolePort {
+    size_t (*read_callback)(const uint8_t *buf, const size_t len);
 
+    if (port->read_callback) {
+        ret = port->read_callback(buf, len);
+    } else if (port->hd) {
+        ret = qemu_chr_write(port->hd, buf, len);
      }
-    return qemu_chr_write(port->hd, buf, len);

No. port->info->data_for_you() again ;)

hw/virtio-console.c static void vcon_event(void *opaque, int event) · line 460

Quoted 4 lines
hw/virtio-console.c +4 -0
+/* Functions for use inside qemu to open and read from/write to ports */
+VirtIOConsolePort *virtio_console_open(uint32_t id,
+                                       size_t(*read_callback)(const uint8_t*buf,
+                                                              const size_t len))

Anyone who wants talk using a port should be a port driver.

cheers,
Gerd

#6 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

In reply to Amit Shah

hw/qdev.c void qdev_free(DeviceState *dev) · line 247

Quoted 6 lines
  CharDriverState *qdev_init_chardev(DeviceState *dev)
  {
      static int next_serial;
hw/qdev.c +0 -2
-    static int next_virtconsole;
-    /* FIXME: This is a nasty hack that needs to go away.  */

Please don't drop this comment. The whole function is a nasty hack ;)

hw/virtio-console-bus.c line 40

Quoted 10 lines
hw/virtio-console-bus.c new file +10 -0
+VirtConBus *virtcon_bus_new(DeviceState *dev)
+{
+    if (virtcon_bus) {
+        fprintf(stderr, "Can't create a second virtio-console bus\n");
+        return NULL;
+    }
+    if (!dev) {
+        dev = qdev_create(NULL, "virtio-console-sysbus");
+        qdev_init(dev);
+    }

Can this actually happen? I think you'll allways have a virtio-console device as parent, right?

Looks like cut+pasted from isa-bus.c. The ISA bus needs this for PCI-less machines where no PCI-ISA bridge is present and thus we need a isabus-sysbus bridge to hook up the ISA bus into the device tree. Try 'info qtree' on -M pc and -M isapc to see what I mean ;)

hw/virtio-console-bus.c line 74

Quoted 2 lines
hw/virtio-console-bus.c new file +2 -0
+VirtConDevice *virtcon_create(const char *name)
+VirtConDevice *virtcon_create_simple(const char *name)

These functions should get a VirtConBus passed in as first argument.

Looks like cut+paste from ISA bus again. The ISA bus is special here as you never ever can have two ISA busses in a single machine. That isn't true in general though.

Might also be you don't need these functions at all. They usually used in case device creation is hard-coded somewhere (like standard isa devices present in every pc) or to keep old-style init functions working in the new qdev world (isa_ne2000_init for example). Devices which are only ever created via -device don't take this code path ...

hw/virtio-console-bus.c line 92

Quoted 7 lines
hw/virtio-console-bus.c new file +7 -0
+static void virtcon_bus_dev_print(Monitor *mon, DeviceState *dev, int indent)
+{
+    VirtConDevice *d = DO_UPCAST(VirtConDevice, qdev, dev);
+    if (&d->qdev) {
+      ;
+    }
+}

print callback isn't mandatory. If you don't want to print anything just drop it.

Quoted 6 lines
hw/virtio-console-bus.c new file +6 -0
+static int virtcon_bus_init(SysBusDevice *dev)
+{
+    return 0;
+}
+
+static SysBusDeviceInfo virtcon_sysbus_info = {

hw/virtio-console-bus.c line 109

Quoted 10 lines
hw/virtio-console-bus.c new file +10 -0
+    .init = virtcon_bus_init,
+    .qdev.name  = "virtio-console-sysbus",
+    .qdev.size  = sizeof(SysBusDevice),
+    .qdev.no_user = 1,
+};
+
+static void virtcon_sysbus_register_devices(void)
+{
+    sysbus_register_withprop(&virtcon_sysbus_info);
+}

See above. I'm sure you don't need that.

hw/virtio-console.c line 55

Quoted 5 lines
hw/virtio-console.c +5 -0
+struct VirtIOConsolePort {
+    DeviceState dev;
+
+    VirtIOConsole *vcon;
+    CharDriverState *hd;

This looks wrong.

hw/virtio-console.c line 63

Quoted 7 lines
hw/virtio-console.c +7 -0
+    char *name;
+
+    QTAILQ_HEAD(, VirtIOConsolePortBuffer) unflushed_buffer_head;
+
+    bool guest_connected;
+    bool host_connected;
+};

Sticking a pointer to VirtConPortDeviceInfo here is probably handy. More consistent naming please.

hw/virtio-console.c line 85

Quoted 11 lines
hw/virtio-console.c +11 -0
+static int get_id_from_port(VirtIOConsolePort *port)
+{
+    uint32_t i;
+
+    for (i = 0; i<  MAX_VIRTIO_CONSOLE_PORTS; i++) {
+        if (port == port->vcon->ports[i]) {
+            return i;
+        }
+    }
+    return VIRTIO_CONSOLE_BAD_ID;
+}

Just sick a id element into VirtIOConsolePort?

hw/virtio-console.c line 111

Quoted 10 lines
hw/virtio-console.c +10 -0
+static bool has_complete_data(VirtIOConsolePort *port)
+{
+    VirtIOConsolePortBuffer *buf;
+    size_t len, size;
+
+    len = 0;
+    size = 0;
+    QTAILQ_FOREACH(buf,&port->unflushed_buffer_head, next) {
+        if (!buf->size&&  buf == QTAILQ_FIRST(&port->unflushed_buffer_head)) {
+            /* We have a buffer that's lost its way; just flush it */

Can this happen? If not, assert() instead?

hw/virtio-console.c line 134

Quoted 6 lines
hw/virtio-console.c +6 -0
+static size_t flush_buf(VirtIOConsolePort *port, const uint8_t *buf, size_t len)
+{
+    if (!port->hd) {
+        return 0;
+    }
+    return qemu_chr_write(port->hd, buf, len);

port->info->data_for_you(port, buf, len);

Quoted 7 lines
hw/virtio-console.c +7 -0
+static void flush_queue(VirtIOConsolePort *port)
+{
+    VirtIOConsolePortBuffer *buf, *buf2;
+    uint8_t *outbuf;
+    size_t outlen, outsize;
+
+    while (!QTAILQ_EMPTY(&port->unflushed_buffer_head)) {

hw/virtio-console.c line 153

Quoted 10 lines
hw/virtio-console.c +10 -0
+        if (!has_complete_data(port)) {
+            break;
+        }
+
+        buf = QTAILQ_FIRST(&port->unflushed_buffer_head);
+        if (!buf->size) {
+            /* This is a buf that didn't get consumed as part of a
+             * previous data stream. Bad thing, shouldn't
+             * happen. But let's handle it nonetheless
+             */

If it shoudn't happen, then use assert(). If it triggers, find the bug.

hw/virtio-console.c line 238

Quoted 10 lines
hw/virtio-console.c +10 -0
+/* Guest wants to notify us of some event */
+static void handle_control_message(VirtIOConsolePort *port,
+                                   struct virtio_console_control *cpkt)
+{
+    uint8_t *buffer;
+    size_t buffer_len;
+
+    switch(cpkt->event) {
+    case VIRTIO_CONSOLE_PORT_OPEN:
+        port->guest_connected = cpkt->value;

port->info->guest_open() notify callback?

hw/virtio-console.c static void virtio_console_handle_input(VirtIODevice *vdev, VirtQueue *vq) · line 491

Quoted 11 lines
hw/virtio-console.c +11 -0
+static int vcon_port_initfn(VirtConDevice *dev)
+{
+    VirtIOConsolePort *port;
+
+    port = DO_UPCAST(VirtIOConsolePort, dev,&dev->qdev);
+
+    QTAILQ_INIT(&port->unflushed_buffer_head);
+
+    port->vcon = virtio_console;
+
+    qemu_chr_add_handlers(port->hd, vcon_can_read, vcon_read, vcon_event, port);

Why have a chardev here?

hw/virtio-console.h line 78

Quoted 3 lines
hw/virtio-console.h +3 -0
+typedef struct VirtConPortDeviceInfo {
+    DeviceInfo qdev;
+    virtcon_port_qdev_initfn init;

Stick in more function pointers here. guest_open(), data_for_you(), ...

Well. The whole thing is still *way* to mixed up. It should be cleanly separated.

You should be able to move the port driver(s) to a separate source file without much trouble. Only the port driver should deal with a chardev.
The virtio-console core should not care at all how the data is piped
to the (host side) users. It just drives the ring, forwards events, accepts data for the guest (via helper function), passes on data from the guest (via callback in VirtConPortDeviceInfo).

cheers,
Gerd

author
#7 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

Quoted 8 lines · Gerd Hoffmann

hw/qdev.c void qdev_free(DeviceState *dev) · line 247

Quoted 6 lines
  CharDriverState *qdev_init_chardev(DeviceState *dev)
  {
      static int next_serial;
hw/qdev.c +0 -2
-    static int next_virtconsole;
-    /* FIXME: This is a nasty hack that needs to go away.  */

Please don't drop this comment. The whole function is a nasty hack ;)

OK :-)

Quoted 14 lines

hw/virtio-console-bus.c line 40

Quoted 10 lines
hw/virtio-console-bus.c new file +10 -0
+VirtConBus *virtcon_bus_new(DeviceState *dev)
+{
+    if (virtcon_bus) {
+        fprintf(stderr, "Can't create a second virtio-console bus\n");
+        return NULL;
+    }
+    if (!dev) {
+        dev = qdev_create(NULL, "virtio-console-sysbus");
+        qdev_init(dev);
+    }

Can this actually happen? I think you'll allways have a virtio-console device as parent, right?

Quoted 4 lines

Looks like cut+pasted from isa-bus.c. The ISA bus needs this for PCI-less machines where no PCI-ISA bridge is present and thus we need a isabus-sysbus bridge to hook up the ISA bus into the device tree. Try 'info qtree' on -M pc and -M isapc to see what I mean ;)

You're right; I've mostly picked up the bits from isa-bus. I've not done any thinking yet.

Quoted 8 lines

hw/virtio-console-bus.c line 74

Quoted 2 lines
hw/virtio-console-bus.c new file +2 -0
+VirtConDevice *virtcon_create(const char *name)
+VirtConDevice *virtcon_create_simple(const char *name)

These functions should get a VirtConBus passed in as first argument.

Looks like cut+paste from ISA bus again. The ISA bus is special here as you never ever can have two ISA busses in a single machine. That isn't true in general though.

OK; I think receiving the bus argument might be helpful when we support more than 1 device.

Quoted 5 lines

Might also be you don't need these functions at all. They usually used in case device creation is hard-coded somewhere (like standard isa devices present in every pc) or to keep old-style init functions working in the new qdev world (isa_ne2000_init for example). Devices which are only ever created via -device don't take this code path ...

I think deprecating the old-style -virtioconsole is the better option.

Quoted 10 lines

hw/virtio-console-bus.c line 92

Quoted 7 lines
hw/virtio-console-bus.c new file +7 -0
+static void virtcon_bus_dev_print(Monitor *mon, DeviceState *dev, int indent)
+{
+    VirtConDevice *d = DO_UPCAST(VirtConDevice, qdev, dev);
+    if (&d->qdev) {
+      ;
+    }
+}

print callback isn't mandatory. If you don't want to print anything just drop it.

Yeah; I thought I'd have something to be displayed here later.

Quoted 10 lines
Quoted 10 lines
hw/virtio-console-bus.c new file +10 -0
+static int virtcon_bus_init(SysBusDevice *dev)
+{
+    return 0;
+}
+
+static SysBusDeviceInfo virtcon_sysbus_info = {
+    .init = virtcon_bus_init,
+    .qdev.name  = "virtio-console-sysbus",
+    .qdev.size  = sizeof(SysBusDevice),
+    .qdev.no_user = 1,
Quoted 8 lines

hw/virtio-console-bus.c line 109

Quoted 6 lines
hw/virtio-console-bus.c new file +6 -0
+};
+
+static void virtcon_sysbus_register_devices(void)
+{
+    sysbus_register_withprop(&virtcon_sysbus_info);
+}

See above. I'm sure you don't need that.

Yeah; will drop.

Quoted 7 lines

hw/virtio-console.c line 55

Quoted 5 lines
hw/virtio-console.c +5 -0
+struct VirtIOConsolePort {
+    DeviceState dev;
+
+    VirtIOConsole *vcon;
+    CharDriverState *hd;

This looks wrong.

We shouldn't have a charstate at all?

Quoted 10 lines

hw/virtio-console.c line 63

Quoted 7 lines
hw/virtio-console.c +7 -0
+    char *name;
+
+    QTAILQ_HEAD(, VirtIOConsolePortBuffer) unflushed_buffer_head;
+
+    bool guest_connected;
+    bool host_connected;
+};

Sticking a pointer to VirtConPortDeviceInfo here is probably handy. More consistent naming please.

Consistent naming for what?

I've only put the new bus stuff in the new file and this file has largely remained as-is, with a few functions changed to accomodate the new init methods.

Quoted 5 lines
Quoted 5 lines
hw/virtio-console.c +5 -0
+static int get_id_from_port(VirtIOConsolePort *port)
+{
+    uint32_t i;
+
+    for (i = 0; i<  MAX_VIRTIO_CONSOLE_PORTS; i++) {
Quoted 8 lines

hw/virtio-console.c line 85

Quoted 6 lines
hw/virtio-console.c +6 -0
+        if (port == port->vcon->ports[i]) {
+            return i;
+        }
+    }
+    return VIRTIO_CONSOLE_BAD_ID;
+}

Just sick a id element into VirtIOConsolePort?

Yes, that's on the todo list.

Quoted 4 lines
Quoted 4 lines
hw/virtio-console.c +4 -0
+static bool has_complete_data(VirtIOConsolePort *port)
+{
+    VirtIOConsolePortBuffer *buf;
+    size_t len, size;
Quoted 8 lines

hw/virtio-console.c line 111

Quoted 6 lines
hw/virtio-console.c +6 -0
+
+    len = 0;
+    size = 0;
+    QTAILQ_FOREACH(buf,&port->unflushed_buffer_head, next) {
+        if (!buf->size&&  buf == QTAILQ_FIRST(&port->unflushed_buffer_head)) {
+            /* We have a buffer that's lost its way; just flush it */

Can this happen? If not, assert() instead?

Shouldn't happen; but it's not a serious thing to error out instead.

Quoted 8 lines

hw/virtio-console.c line 134

Quoted 6 lines
hw/virtio-console.c +6 -0
+static size_t flush_buf(VirtIOConsolePort *port, const uint8_t *buf, size_t len)
+{
+    if (!port->hd) {
+        return 0;
+    }
+    return qemu_chr_write(port->hd, buf, len);

port->info->data_for_you(port, buf, len);

OK; haven't yet seen how the charstate can be made transparent.

Quoted 11 lines
Quoted 11 lines
hw/virtio-console.c +11 -0
+static void flush_queue(VirtIOConsolePort *port)
+{
+    VirtIOConsolePortBuffer *buf, *buf2;
+    uint8_t *outbuf;
+    size_t outlen, outsize;
+
+    while (!QTAILQ_EMPTY(&port->unflushed_buffer_head)) {
+        if (!has_complete_data(port)) {
+            break;
+        }
+
Quoted 8 lines

hw/virtio-console.c line 153

Quoted 6 lines
hw/virtio-console.c +6 -0
+        buf = QTAILQ_FIRST(&port->unflushed_buffer_head);
+        if (!buf->size) {
+            /* This is a buf that didn't get consumed as part of a
+             * previous data stream. Bad thing, shouldn't
+             * happen. But let's handle it nonetheless
+             */

If it shoudn't happen, then use assert(). If it triggers, find the bug.

The bug could actually be in the guest and not in qemu. Would be wrong to penalise in that case, I guess.

Quoted 4 lines
Quoted 4 lines
hw/virtio-console.c +4 -0
+/* Guest wants to notify us of some event */
+static void handle_control_message(VirtIOConsolePort *port,
+                                   struct virtio_console_control *cpkt)
+{
Quoted 8 lines

hw/virtio-console.c line 238

Quoted 6 lines
hw/virtio-console.c +6 -0
+    uint8_t *buffer;
+    size_t buffer_len;
+
+    switch(cpkt->event) {
+    case VIRTIO_CONSOLE_PORT_OPEN:
+        port->guest_connected = cpkt->value;

port->info->guest_open() notify callback?

You mean handle it in an async path?

Quoted 5 lines
Quoted 5 lines
hw/virtio-console.c +5 -0
+static int vcon_port_initfn(VirtConDevice *dev)
+{
+    VirtIOConsolePort *port;
+
+    port = DO_UPCAST(VirtIOConsolePort, dev,&dev->qdev);
Quoted 8 lines

hw/virtio-console.c static void virtio_console_handle_input(VirtIODevice *vdev, VirtQueue *vq) · line 491

Quoted 6 lines
hw/virtio-console.c +6 -0
+
+    QTAILQ_INIT(&port->unflushed_buffer_head);
+
+    port->vcon = virtio_console;
+
+    qemu_chr_add_handlers(port->hd, vcon_can_read, vcon_read, vcon_event, port);

Why have a chardev here?

1. Don't know how to make it transparent,
2. Don't know how to init these function handlers otherwise

Quoted 9 lines

hw/virtio-console.h line 78

Quoted 3 lines
hw/virtio-console.h +3 -0
+typedef struct VirtConPortDeviceInfo {
+    DeviceInfo qdev;
+    virtcon_port_qdev_initfn init;

Stick in more function pointers here. guest_open(), data_for_you(), ...

Well. The whole thing is still *way* to mixed up. It should be cleanly separated.

Yeah; I've only got it working with -device so far. So I guess I'll have to bug you more to get this further into shape :-)

Quoted 2 lines

You should be able to move the port driver(s) to a separate source file without much trouble. Only the port driver should deal with a chardev.

Oh OK; maybe I understand what you're saying about the chardevs now.

Quoted 4 lines

The virtio-console core should not care at all how the data is piped to the (host side) users. It just drives the ring, forwards events, accepts data for the guest (via helper function), passes on data from the guest (via callback in VirtConPortDeviceInfo).

Hm, let me think over this.

Amit

#8 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

Quoted 10 lines
Quoted 8 lines

hw/virtio-console.c line 55

Quoted 6 lines
hw/virtio-console.c +5 -0
+struct VirtIOConsolePort {
+    DeviceState dev;
+
+    VirtIOConsole *vcon;
+    CharDriverState *hd;

This looks wrong.

We shouldn't have a charstate at all?

Not here. More below ...

Quoted 11 lines
Quoted 10 lines

hw/virtio-console.c line 63

Quoted 7 lines
hw/virtio-console.c +7 -0
+    char *name;
+
+    QTAILQ_HEAD(, VirtIOConsolePortBuffer) unflushed_buffer_head;
+
+    bool guest_connected;
+    bool host_connected;
+};

Sticking a pointer to VirtConPortDeviceInfo here is probably handy. More consistent naming please.

Quoted 1 line

Consistent naming for what?

The structs. Pick a prefix (say VirtCon) and stick with that. Then for the bus implementation:

VirtConBus         (fine)
VirtConPort        (VirtIOConsolePort now)
VirtConPortInfo    (VirtConPortDeviceInfo now)

The console port driver could name its state info this way:

VirtConPortConsole (doesn't exist right now it seems ...).

Quoted 3 lines

I've only put the new bus stuff in the new file and this file has largely remained as-is, with a few functions changed to accomodate the new init methods.

This is about more than just the init ...

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
hw/virtio-console.c +4 -0
+static bool has_complete_data(VirtIOConsolePort *port)
+{
+    VirtIOConsolePortBuffer *buf;
+    size_t len, size;
Quoted 8 lines

hw/virtio-console.c line 111

Quoted 6 lines
hw/virtio-console.c +6 -0
+
+    len = 0;
+    size = 0;
+    QTAILQ_FOREACH(buf,&port->unflushed_buffer_head, next) {
+        if (!buf->size&&   buf == QTAILQ_FIRST(&port->unflushed_buffer_head)) {
+            /* We have a buffer that's lost its way; just flush it */

Can this happen? If not, assert() instead?

Quoted 1 line

Shouldn't happen; but it's not a serious thing to error out instead.

It indicates a bug somewhere though, doesn't it? I'd suggest to not paper over it.

Quoted 10 lines
Quoted 8 lines

hw/virtio-console.c line 134

Quoted 6 lines
hw/virtio-console.c +6 -0
+static size_t flush_buf(VirtIOConsolePort *port, const uint8_t *buf, size_t len)
+{
+    if (!port->hd) {
+        return 0;
+    }
+    return qemu_chr_write(port->hd, buf, len);

port->info->data_for_you(port, buf, len);

OK; haven't yet seen how the charstate can be made transparent.

chardev should go into VirtConPortConsole.

Quoted 4 lines
Quoted 1 line

If it shoudn't happen, then use assert(). If it triggers, find the bug.

The bug could actually be in the guest and not in qemu. Would be wrong to penalise in that case, I guess.

Ah, ok. Fine then. Aborting qemu on guest bugs would be insane.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
hw/virtio-console.c +4 -0
+/* Guest wants to notify us of some event */
+static void handle_control_message(VirtIOConsolePort *port,
+                                   struct virtio_console_control *cpkt)
+{
Quoted 8 lines

hw/virtio-console.c line 238

Quoted 6 lines
hw/virtio-console.c +6 -0
+    uint8_t *buffer;
+    size_t buffer_len;
+
+    switch(cpkt->event) {
+    case VIRTIO_CONSOLE_PORT_OPEN:
+        port->guest_connected = cpkt->value;

port->info->guest_open() notify callback?

Quoted 1 line

You mean handle it in an async path?

No, have a way to notify the port driver about the state change.

Quoted 12 lines
Quoted 5 lines

Stick in more function pointers here. guest_open(), data_for_you(), ...

Well. The whole thing is still *way* to mixed up. It should be cleanly separated.

Yeah; I've only got it working with -device so far. So I guess I'll have to bug you more to get this further into shape :-)

Quoted 2 lines

You should be able to move the port driver(s) to a separate source file without much trouble. Only the port driver should deal with a chardev.

Quoted 8 lines

Oh OK; maybe I understand what you're saying about the chardevs now.

Quoted 4 lines

The virtio-console core should not care at all how the data is piped to the (host side) users. It just drives the ring, forwards events, accepts data for the guest (via helper function), passes on data from the guest (via callback in VirtConPortDeviceInfo).

Hm, let me think over this.

A port driver should look roughly like the attached one. That one does something completely different: Implement a watchdog ;) Warning: didn't even compile it.

The console port driver would have the chardev instead of the timer in the driver state struct and would basically forward the data between the port and the chardev.

HTH,
Gerd

#include "hw.h"
#include "virtio-channel.h"

typedef struct VirtConPortWatchdog {
    VirtConPort dev;
    QEMUTimer *timer;
    uint32_t timeout;
} VirtConPortWatchdog;

static void timer_expired(void *ptr)

{
    VirtConPortWatchdog *s = ptr;

    watchdog_perform_action();
    qemu_del_timer(s->timer);
}

static int watchdog_open(VirtConPort *dev)

{
    VirtConPortWatchdog *s = DO_UPCAST(VirtConPortWatchdog, dev, dev);

    qemu_mod_timer(s->timer, qemu_get_clock (vm_clock) +
                   s->timeout * get_ticks_per_sec());
}

static int watchdog_data(VirtConPort *dev, uint8_t *buf, int len)

{
    VirtConPortWatchdog *s = DO_UPCAST(VirtConPortWatchdog, dev, dev);

    qemu_mod_timer(s->timer, qemu_get_clock (vm_clock) +
                   s->timeout * get_ticks_per_sec());
}

static int watchdog_init(VirtConPort *dev)

{
    VirtConPortWatchdog *s = DO_UPCAST(VirtConPortWatchdog, dev, dev);

    s->dev.name = "org.qemu.watchdog";
    s->timer = qemu_new_timer(vm_clock, timer_expired, s);
}

VirtConPortInfo watchdog_info = {

    .qdev.name    = "vmch-watchdog",
    .qdev.size    = sizeof(VirtConPortWatchdog),
    .qdev.vmsd    = /* todo */,
    .qdev.reset   = /* todo */,
    .init         = watchdog_init,
    .guest_open   = watchdog_open,

.data_for_you = watchdog_data,
.qdev.props = (Property[]) {
DEFINE_PROP_UINT32("timeout", VirtConPortWatchdog, timeout, 120), DEFINE_PROP_END_OF_LIST
},
};

void watchdog_register(void)

{
    virtcon_port_qdev_register(&watchdog_info);
}

device_init(watchdog_register)

author
#9 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

Quoted 12 lines · Gerd Hoffmann
Quoted 12 lines
Quoted 11 lines

hw/virtio-console.c line 63

Quoted 8 lines
hw/virtio-console.c +7 -0
+    char *name;
+
+    QTAILQ_HEAD(, VirtIOConsolePortBuffer) unflushed_buffer_head;
+
+    bool guest_connected;
+    bool host_connected;
+};

Sticking a pointer to VirtConPortDeviceInfo here is probably handy. More consistent naming please.

Quoted 8 lines
Quoted 1 line

Consistent naming for what?

The structs. Pick a prefix (say VirtCon) and stick with that. Then for the bus implementation:

VirtConBus         (fine)
VirtConPort        (VirtIOConsolePort now)
VirtConPortInfo    (VirtConPortDeviceInfo now)

Yeah; I've not renamed the structs yet.

Quoted 3 lines

The console port driver could name its state info this way:

VirtConPortConsole (doesn't exist right now it seems ...).

You're actually suggesting to split everything -- a console (in the current sense) is a different device and a port (the new vmchannels) are different devices. Right?

Quoted 12 lines
Quoted 11 lines
Quoted 2 lines

You should be able to move the port driver(s) to a separate source file without much trouble. Only the port driver should deal with a chardev.

Oh OK; maybe I understand what you're saying about the chardevs now.

Quoted 4 lines

The virtio-console core should not care at all how the data is piped to the (host side) users. It just drives the ring, forwards events, accepts data for the guest (via helper function), passes on data from the guest (via callback in VirtConPortDeviceInfo).

Hm, let me think over this.

Quoted 7 lines

A port driver should look roughly like the attached one. That one does something completely different: Implement a watchdog ;) Warning:
didn't even compile it.

The console port driver would have the chardev instead of the timer in the driver state struct and would basically forward the data between the port and the chardev.

Thanks; parsing all this..

Amit

#10 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

Quoted 5 lines · Amit Shah
Quoted 1 line

VirtConPortConsole (doesn't exist right now it seems ...).

You're actually suggesting to split everything -- a console (in the current sense) is a different device and a port (the new vmchannels) are different devices. Right?

Yes, you'll have two devices.

#1 virtio-console which handles all virtio and is the master of
the portbus.
#2 VirtChanPortConsole, which links the port and the chardev.

With this in place you'll have the current virtio-console functionality.
And on top you can create multiple console ports.

Then we can go enhance things and add more port drivers:

#3: One driver which allows external users (i.e. libguestfs) by linking
a chardev too and attach a name tag. That one can probably share all code except the init function with the console port driver.
#4: the watchdog.
#5: the vnc clipboard bits.
#6: whatever else we might find useful.

Ignoring backward-compatibility for now things should go like this:

-device virtio-console
Creates the portbus master. No ports (yet).

-device vmport-console,chardev=$dev
Creates a port named 'org.qemu.console' and links it to $dev.

-device vmport-channel,chardev=$dev,name=$name
Creates a port named $name, links it to $dev, for libguestfs and other external users.

-device vmport-watchdog
Creates a port named 'org.qemu.watchdog', start timer when the guest openes the device, restart the watchdog timer each time the guest writes something, trigger watchdog action when the timer expires.
Note: No chardev needed here.

-device vmport-clipboard
vnc clipboard stuff goes here. Probably needs no chardev too.

For backward-compatibility we'll allways have to create a vmport-console at port 0, so there will never be a virtio-console without a port. That is a minor bit we can fixup once the above works fine.

cheers,
Gerd

author
#11 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

Quoted 11 lines · Gerd Hoffmann
Quoted 5 lines · Amit Shah
Quoted 1 line

VirtConPortConsole (doesn't exist right now it seems ...).

You're actually suggesting to split everything -- a console (in the current sense) is a different device and a port (the new vmchannels) are different devices. Right?

Yes, you'll have two devices.

#1 virtio-console which handles all virtio and is the master of
the portbus.

Right; This is in place now.

Quoted 1 line

#2 VirtChanPortConsole, which links the port and the chardev.

OK; So based on the last mail the port functionality could be split in a separate file.

Quoted 11 lines

With this in place you'll have the current virtio-console functionality.
And on top you can create multiple console ports.

Then we can go enhance things and add more port drivers:

#3: One driver which allows external users (i.e. libguestfs) by linking
a chardev too and attach a name tag. That one can probably share all code except the init function with the console port driver.
#4: the watchdog.
#5: the vnc clipboard bits.
#6: whatever else we might find useful.

Right; this model looks good. It wasn't obvious to me the first time you mentioned it (I didn't think adding something like a VirtConPortVnc and some init functions in vnc.c would make any sense -- but actually looks like it would be cleaner to do that).

Review

Quoted 7 lines

Ignoring backward-compatibility for now things should go like this:

(quoted diff) +0 -2
-device virtio-console
   Creates the portbus master.  No ports (yet).
 
-device vmport-console,chardev=$dev
   Creates a port named 'org.qemu.console' and links it to $dev.

OK; that's what I have now, slightly different:

-device virtio-console-pci -device virtconport,port=0,chardev=$dev

Quoted 13 lines
(quoted diff) +0 -3
-device vmport-channel,chardev=$dev,name=$name
   Creates a port named $name, links it to $dev, for libguestfs and
   other external users.
 
-device vmport-watchdog
   Creates a port named 'org.qemu.watchdog', start timer when the guest
   openes the device, restart the watchdog timer each time the guest
   writes something, trigger watchdog action when the timer expires.
   Note: No chardev needed here.
 
-device vmport-clipboard
   vnc clipboard stuff goes here.  Probably needs no chardev too.
Quoted 3 lines

For backward-compatibility we'll allways have to create a vmport-console at port 0, so there will never be a virtio-console without a port. That is a minor bit we can fixup once the above works fine.

ie -virtioconsole <chardev> ?

I'd suggest we just drop that in 0.12.

Amit

#12 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +0 -2
-device virtio-console
    Creates the portbus master.  No ports (yet).
 
-device vmport-console,chardev=$dev
    Creates a port named 'org.qemu.console' and links it to $dev.

OK; that's what I have now, slightly different:

-device virtio-console-pci -device virtconport,port=0,chardev=$dev

Fine as well. The exact names don't really matter, the naming for the port drivers should be consistent though (i.e. have the same prefix for all of them or something like that). Optional port number looks reasonable too. Should default to auto-allocation if not specified.

Quoted 5 lines
Quoted 3 lines

For backward-compatibility we'll allways have to create a vmport-console at port 0, so there will never be a virtio-console without a port. That is a minor bit we can fixup once the above works fine.

ie -virtioconsole<chardev> ?

There are two kinds of backward compatibility ;) One is the qemu command line. The other is the ABI for old guest drivers. The later requires a console at port 0 ...

Quoted 1 line

I'd suggest we just drop that in 0.12.

Dropping the command line switch is with me. In case someone disagrees (libvirt folks?) it isn't hard to maintain compatibility though.

cheers,
Gerd

author
#13 lore raw

Re: [Qemu-devel] [PATCH 3/4] virtio-console: Add support for multiple ports for generic guest-host communication

Quoted 8 lines · Gerd Hoffmann
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +0 -2
-device virtio-console
    Creates the portbus master.  No ports (yet).
 
-device vmport-console,chardev=$dev
    Creates a port named 'org.qemu.console' and links it to $dev.

OK; that's what I have now, slightly different:

Quoted 4 lines
Quoted 1 line

-device virtio-console-pci -device virtconport,port=0,chardev=$dev

Fine as well. The exact names don't really matter, the naming for the port drivers should be consistent though (i.e. have the same prefix for

Yes.

Quoted 2 lines

all of them or something like that). Optional port number looks reasonable too. Should default to auto-allocation if not specified.

Once that gets decided :-)

It's still not decided if we'll be optional port numbers vs assigned.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

For backward-compatibility we'll allways have to create a vmport-console at port 0, so there will never be a virtio-console without a port. That is a minor bit we can fixup once the above works fine.

ie -virtioconsole<chardev> ?

There are two kinds of backward compatibility ;) One is the qemu

Yes, I wanted to know which one you're thinking about.

Quoted 2 lines

command line. The other is the ABI for old guest drivers. The later requires a console at port 0 ...

For that, there are two options:

1. If we go with a static port function -> port number mapping, this is easy (as I already have now).
2. If we go with dynamic numbers, the guest could register the hvc console only for a device that has the name 'org.qemu.console.0'. This supports multiple ports as well.

Quoted 4 lines
Quoted 1 line

I'd suggest we just drop that in 0.12.

Dropping the command line switch is with me. In case someone disagrees (libvirt folks?) it isn't hard to maintain compatibility though.

It's not much effort to maintain that, but the old and new syntaxes are very different. qemu 0.11 doesn't offer the ability to support multiple virtioconsoles, but 0.12 will. So the cmd line syntax has to change for that anyway, might as well deprecate the older syntax.

Amit