virtio-console-bus, multiport, virtio-console-port
Hello,
This patch series converts the virtio-console device to qdev, adds a virtio-console bus on which similar devices can ride and shows how such devices can be used by adding a new virtio-console-port device and also a virtio-console-vnc device.
This is working well in my testing. I tested old kernel/new qemu, new kernel/old qemu and new kernel/new qemu.
The ports are also tested by spawning two virtio consoles and one generic port. Heavy activity on all three ports is sustained for quite a long time with correct results.
Please review and apply.
PATCH 1/6 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
@@ -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
@@ -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
PATCH 2/6 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
@@ -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
@@ -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
PATCH 3/6 virtio-console: Add a virtio-console bus, support for multiple ports
This patch migrates virtio-console to the qdev infrastructure, and creates a new virtio-console bus on which multiple ports are exposed as devices. The bulk of the code now resides in a new file with virtio-console.c being just a simple qdev device.
This interface extends the virtio-console device to handle multiple ports from which bits can be sent and read.
The older -virtioconsole argument is now deprecated in favour of:
-device virtio-console-pci -device virtconsole
The virtconsole device type accepts a chardev as an argument and a 'name' argument to identify the corresponding consoles on the host as well as the guest. The name, if given, is exposed via the 'name' sysfs attribute.
Care has been taken to ensure compatibility with kernels that do not support multiple ports.
--- Makefile.target | 2 +- hw/pc.c | 9 - hw/qdev.c | 8 +- hw/virtio-console-bus.c | 738 +++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-console.c | 148 +++------- hw/virtio-console.h | 130 +++++++++ qemu-options.hx | 8 - sysemu.h | 6 - vl.c | 37 --- 9 files changed, 907 insertions(+), 179 deletions(-) create mode 100644 hw/virtio-console-bus.c
Makefile.target +1 -1
@@ -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
@@ -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 -6
@@ -243,13 +243,9 @@ 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 +738 -0
738 lines not on this page · raw message
hw/virtio-console.c +36 -112
177 lines not on this page · raw message
hw/virtio-console.h +130 -0
146 lines not on this page · raw message
qemu-options.hx +0 -8
@@ -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 +0 -6
@@ -233,12 +233,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
@@ -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
PATCH 4/6 virtio-console-port: Add a new device on the virtio-console-bus for generic host-guest communication
This is a new device that uses the virtio-console bus.
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/virtio-console-port.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletions(-) create mode 100644 hw/virtio-console-port.c
Makefile.target +1 -1
@@ -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-console-bus.o virtio-pci.o +obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o virtio-console-port.o virtio-console-bus.o virtio-pci.o obj-$(CONFIG_KVM) += kvm.o kvm-all.o LIBS+=-lz
hw/virtio-console-port.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 5/6 vnc: add a is_vnc_active() helper
This helper is introduced to query the status of vnc.
--- vnc.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
vnc.c +9 -1
@@ -178,9 +178,17 @@ static void do_info_vnc_client(Monitor *mon, VncState *client)#endif } -void do_info_vnc (Monitor *mon) +static int is_vnc_active (void ) {if (vnc_display ==NULL || vnc_display->display ==NULL ) { +return 0 ; + } +return 1 ; +} + +void do_info_vnc (Monitor *mon) +{ +if (!is_vnc_active ()) {monitor_printf (mon,"Server: disabled\n" ); }else { char *serverAddr = vnc_socket_local_addr(" address: %s:%s\n",
Signature · 1 line
1.6.2.5
PATCH 6/6 vnc: Add a virtio-console-bus device to send / receive guest clipboard
This is a simple device on the virtio-console-bus that syncs with the guest for clipboard activity.
A daemon is needed in the guest to send / receive the clipboard data.
This patch is just meant to show how to use the read/write api is exposed for devices that ride on top of the virtio-console-bus.
--- vnc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 67 insertions(+), 0 deletions(-)
vnc.c +67 -0
@@ -29,6 +29,7 @@#include "qemu_socket.h" #include "qemu-timer.h" #include "acl.h" +#include "hw/virtio-console.h" #define VNC_REFRESH_INTERVAL_BASE 30#define VNC_REFRESH_INTERVAL_INC 50
@@ -44,6 +45,11 @@ } \ } +typedef struct VirtConVnc { +VirtConPort port; +}VirtConVnc ; + +static VirtConVnc *virtcon_vnc;static VncDisplay *vnc_display;/* needed for info vnc */ static DisplayChangeListener *dcl;
@@ -659,6 +665,34 @@ static void send_framebuffer_update(VncState *vs, int x, int y, int w, int h) } } +static size_t vnc_clipboard_data_from_guest (VirtConPort *port, +const uint8_t *buf,size_t len) +{ +VncState *vs; +VncDisplay *vd; +DisplayState *ds; + +if (!is_vnc_active ()) +return 0 ; + + ds = vnc_display->ds; + vd = ds->opaque; + +for (vs = vd->clients; vs; vs = vs->next) { +vnc_write_u8 (vs,3 );/* ServerCutText */ +vnc_write_u8 (vs,0 );/* Padding */ +vnc_write_u8 (vs,0 );/* Padding */ +vnc_write_u8 (vs,0 );/* Padding */ +vnc_write_u32 (vs, len); +while (len--) { +vnc_write_u8 (vs, *(buf++)); + } +vnc_flush (vs); + } +return len; +} + +static void vnc_copy (VncState *vs,int src_x,int src_y,int dst_x,int dst_y,int w,int h) {/* send bitblit op to the vnc client */
@@ -1240,6 +1274,7 @@ uint32_t read_u32(uint8_t *data, size_t offset)static void client_cut_text (VncState *vs,size_t len,uint8_t *text) { +virtio_console_write (&virtcon_vnc->port, text, len); }static void check_pointer_type_change (VncState *vs,int absolute)
@@ -2197,6 +2232,10 @@ static void vnc_connect(VncDisplay *vd, int csock)vnc_init_timer (vd); +if (virtcon_vnc) { +virtio_console_open (&virtcon_vnc->port); + } +/* vs might be free()ed here */ }
@@ -2516,3 +2555,31 @@ int vnc_display_open(DisplayState *ds, const char *display) }return qemu_set_fd_handler2 (vs->lsock,NULL , vnc_listen_read,NULL , vs); } + +static int vcon_vnc_initfn (VirtConDevice *dev) +{ +VirtConPort *port; +VirtConVnc *vnc; + + port =DO_UPCAST (VirtConPort, dev, &dev->qdev); + vnc =DO_UPCAST (VirtConVnc, port, port); + virtcon_vnc = vnc; + + port->name =qemu_strdup ("org.qemu.clipboard" ); +/* We don't want to keep old data lingering if vnc is not connected */ + port->flush_buffers =1 ; +return 0 ; +} + +static VirtConPortInfo virtcon_vnc_info = { + .qdev.name ="virtconvnc" , + .qdev.size =sizeof (VirtConVnc), + .init = vcon_vnc_initfn, + .have_data = vnc_clipboard_data_from_guest, +}; + +static void virtcon_port_register (void ) +{ +virtcon_port_qdev_register (&virtcon_vnc_info); +} +device_init (virtcon_port_register)
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 6/6] vnc: Add a virtio-console-bus device to send / receive guest clipboard
Quoted 3 lines
static void
client_cut_text(VncState *vs, size_t len, uint8_t *text){
+virtio_console_write(&virtcon_vnc->port, text, len);
Needs "if (virtcon_vnc)" ?
vnc.c static void vnc_connect(VncDisplay *vd, int csock) · line 2237
Quoted 3 lines
vnc.c +3
-0+if (virtcon_vnc) { +virtio_console_open (&virtcon_vnc->port); + }
Like it is done here?
There is no virtio_console_close() in this patch. Does this work correctly after multiple connects + disconnects (with multiple vnc clients connected at the same time)?
I think when moving the buffering and host_connected state tracking into the port driver (patch 4/6) which is the only user of the facility you don't need these open/close calls at all.
cheers
Gerd
Re: [Qemu-devel] [PATCH 6/6] vnc: Add a virtio-console-bus device to send / receive guest clipboard
Quoted 5 lines · Gerd Hoffmann
Quoted 3 lines
static void
client_cut_text(VncState *vs, size_t len, uint8_t *text){
+virtio_console_write(&virtcon_vnc->port, text, len);Needs "if (
virtcon_vnc)" ?
Yes.
Quoted 9 lines
vnc.c static void vnc_connect(VncDisplay *vd, int csock) · line 2237
Quoted 3 lines
vnc.c +3
-0+if (virtcon_vnc) { +virtio_console_open (&virtcon_vnc->port); + }Like it is done here?
There is no
virtio_console_close()in this patch. Does this work correctly after multiple connects + disconnects (with multiple vnc clients connected at the same time)?
Yes, I actually don't propose this for inclusion. It's just a way to show how the api works. I've only done some very basic testing with this vnc patch (and found some bug in the vnc code that I reported about a while back).
Quoted 3 lines
I think when moving the buffering and
host_connectedstate tracking into the port driver (patch 4/6) which is the only user of the facility you don't need these open/close calls at all.
True for vnc, but may not be for the future users.
Amit
Re: [Qemu-devel] [PATCH 4/6] virtio-console-port: Add a new device on the virtio-console-bus for generic host-guest communication
In reply to Amit Shahhw/virtio-console-port.c line 20
Quoted 3 lines
hw/virtio-console-port.c new file +3
-0+typedef struct VirtIOConsole +{ + VirtConPort port;
Your CharDriverState should go here.
Quoted 1 line
+
DEFINE_PROP_INT32("flush_buffers", VirtConPort, flush_buffers, 0),
Well, we should find a better name for that one. flush_buffers is very unclear. It actually is dont_cache_data_when_unconnected. That name is insane long though.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 4/6] virtio-console-port: Add a new device on the virtio-console-bus for generic host-guest communication
Quoted 11 lines · Gerd Hoffmann
hw/virtio-console-port.c line 20
Quoted 3 lines
hw/virtio-console-port.c new file +3
-0+typedef struct VirtIOConsole +{ + VirtConPort port;Your CharDriverState should go here.
Quoted 1 line
+
DEFINE_PROP_INT32("flush_buffers", VirtConPort, flush_buffers, 0),Well, we should find a better name for that one.
flush_buffersis very unclear. It actually isdont_cache_data_when_unconnected. That name is insane long though.
volatile_when_unconnected?
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
In reply to Amit ShahReview
Quoted 3 lines
(quoted diff) +2
-0+typedef struct VirtIOConsole +{
You are reusing this struct name a few times.
Better don't do that, it is confusing.
Quoted 1 line
+static VirtIOConsole
*virtio_console;
Why do you need this?
hw/virtio-console-bus.c line 123
Quoted 13 lines
hw/virtio-console-bus.c new file +13
-0+static void flush_queue (VirtConPort *port) +{ +VirtConPortBuffer *buf, *buf2; +uint8_t *outbuf; +size_t outlen, outsize; + +/* +* If the app isn't interested in buffering packets till it's +* opened, just drop the data guest sends us till a connection is +* established. +*/ +if (!port->host_connected&& !port->flush_buffers) +return ;
Hmm. Who needs that buffering? Only user seems to be the port driver (patch 4/6). So move the buffering (and the host_connected state tracking) from the core to that driver?
hw/virtio-console-bus.c line 417
Quoted 2 lines
hw/virtio-console-bus.c new file +2
-0+/* Readiness of the guest to accept data on a port */ +static int vcon_can_read (void *opaque)
int vcon_can_read(VirtConPort *port)
hw/virtio-console-bus.c line 456
Quoted 2 lines
hw/virtio-console-bus.c new file +2
-0+static void vcon_read(void *opaque, const uint8_t *buf, int size) +static void vcon_event(void *opaque, int event)
Likewise.
Quoted 1 line
+static VirtConBus
*virtcon_bus;
Why do you need this?
hw/virtio-console-bus.c line 678
Quoted 6 lines
hw/virtio-console-bus.c new file +5
-0+static int virtcon_port_qdev_init (DeviceState *qdev,DeviceInfo *base) +{ +if (port->chr) { +qemu_chr_add_handlers (port->chr, vcon_can_read, vcon_read, vcon_event, + port);
Should be handled by the VirtConPort drivers.
hw/virtio-console-bus.c line 713
Quoted 7 lines
hw/virtio-console-bus.c new file +7
-0+if (MAX_VIRTIO_CONSOLE_PORTS %32 ) { +/* We require MAX_VIRTIO_CONSOLE_PORTS be a multiple of 32: +* We anyway use up that much space for the bitmap and it +* simplifies some calculations +*/ +return NULL ; + }
Huh? Runtime check for a compile-time constant?
hw/virtio-console-bus.c line 735
Quoted 2 lines
hw/virtio-console-bus.c new file +2
-0+/* Spawn a new virtio-console bus on which the ports will ride as devices */ +virtcon_bus_new (dev);
s->bus = virtcon_bus_new(dev);
port0 = qdev_create(s->bus, "virtconsole"); /* console @ port0 for backward compat */ qdev_prop_set_*(port0, ...);qdev_init(port0);
Or does that happen somewhere else?
hw/virtio-console.h line 76
Quoted 8 lines
hw/virtio-console.h +8
-0+typedef struct VirtConBus VirtConBus ; +typedef struct VirtConPort VirtConPort ; +typedef struct VirtConPortInfo VirtConPortInfo ; + +typedef struct VirtConDevice { +DeviceState qdev; +VirtConPortInfo *info; +}VirtConDevice ;
Leftover from old patch version?
hw/virtio-console.h line 89
Quoted 12 lines
hw/virtio-console.h +12
-0+/* +* This is the state that's shared between all the ports. Some of the +* state is configurable via command-line options. Some of it can be +* set by individual devices in their initfn routines. Some of the +* state is set by the generic qdev device init routine. +*/ +struct VirtConPort { +DeviceState dev; +VirtConPortInfo *info; + +/* State for the chardevice associated with this port */ +CharDriverState *chr;
That should go to the port driver if needed.
hw/virtio-console.h line 139
Quoted 11 lines
hw/virtio-console.h +11
-0+typedef int (*virtcon_port_qdev_initfn )(VirtConDevice *dev); + +struct VirtConPortInfo { +DeviceInfo qdev; +virtcon_port_qdev_initfn init; + +/* Callbacks for guest events */ +void (*guest_open)(VirtConPort *port); +void (*guest_close)(VirtConPort *port); + +size_t (*have_data)(VirtConPort *port,const uint8_t *buf,size_t len);
Maybe it is a good idea to pass a VirtConPortBuffer here instead of buf+len, especially when it becomes the port drivers job to do any buffering if needed.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 6 lines · Gerd Hoffmann
Review
Quoted 3 lines
(quoted diff) +2
-0+typedef struct VirtIOConsole +{You are reusing this struct name a few times.
Better don't do that, it is confusing.
Yeah; I still have to go through the entire naming thing. I also really think virtio-console-bus, virtio-console and virtio-console-port are confusing. I thought it's better to do:
virtio-serial-bus (and the corresponding -device virtio-serial-pci) virtio-console
virtio-serial-port
virtio-serial-vnc
Is that OK with all?
Quoted 3 lines
Quoted 1 line
+static VirtIOConsole
*virtio_console;Why do you need this?
Just to keep the current behaviour of restricting to one virtio-console device. This can be later reworked to allow multiple devices.
Quoted 9 lines
Quoted 9 lines
hw/virtio-console-bus.c new file +9
-0+static void flush_queue (VirtConPort *port) +{ +VirtConPortBuffer *buf, *buf2; +uint8_t *outbuf; +size_t outlen, outsize; + +/* +* If the app isn't interested in buffering packets till it's +* opened, just drop the data guest sends us till a connection is
Quoted 8 lines
hw/virtio-console-bus.c line 123
Quoted 4 lines
hw/virtio-console-bus.c new file +4
-0+* established. +*/ +if (!port->host_connected&& !port->flush_buffers) +return ;Hmm. Who needs that buffering? Only user seems to be the port driver (patch 4/6). So move the buffering (and the
host_connectedstate tracking) from the core to that driver?
The buffering could be used by other devices too I guess. The other two users that we currently have, vnc (which is just a demo patch) and console, don't need the buffering, but it's a general facility.
If more users need the buffering, the code could get duplicated so I thought of keeping it here.
Quoted 4 lines
hw/virtio-console-bus.c line 417
Quoted 2 lines
hw/virtio-console-bus.c new file +2
-0+/* Readiness of the guest to accept data on a port */ +static int vcon_can_read (void *opaque)int
vcon_can_read(VirtConPort *port)
OK
Quoted 3 lines
Quoted 1 line
+static VirtConBus
*virtcon_bus;Why do you need this?
I could put this in the VirtIOConsole struct.
Quoted 8 lines
hw/virtio-console-bus.c line 678
Quoted 6 lines
hw/virtio-console-bus.c new file +5
-0+static int virtcon_port_qdev_init (DeviceState *qdev,DeviceInfo *base) +{ +if (port->chr) { +qemu_chr_add_handlers (port->chr, vcon_can_read, vcon_read, vcon_event, + port);Should be handled by the VirtConPort drivers.
There are two reasons why I didn't put this there: virtio-console as well as virtio-serial-port will need char drivers. There could be others as well.
Also, some virtio-specific checks are done in vcon_can_read. So it's better this is put in the common code.
Quoted 9 lines
hw/virtio-console-bus.c line 713
Quoted 7 lines
hw/virtio-console-bus.c new file +7
-0+if (MAX_VIRTIO_CONSOLE_PORTS %32 ) { +/* We require MAX_VIRTIO_CONSOLE_PORTS be a multiple of 32: +* We anyway use up that much space for the bitmap and it +* simplifies some calculations +*/ +return NULL ; + }Huh? Runtime check for a compile-time constant?
Yeah; bad enough it was this way but I now think I can get rid of this entirely as I don't depend on a ports_map.
Quoted 10 lines
hw/virtio-console-bus.c line 735
Quoted 2 lines
hw/virtio-console-bus.c new file +2
-0+/* Spawn a new virtio-console bus on which the ports will ride as devices */ +virtcon_bus_new (dev);
s->bus=virtcon_bus_new(dev);
port0 =qdev_create(s->bus, "virtconsole"); /* console @ port0 for backward compat */
qdev_prop_set_*(port0, ...);qdev_init(port0);Or does that happen somewhere else?
I'm nowhere assuming now any port number - function mapping and so spawning a virtio-console on port#0 is not necessary.
And yeah; as mentioned previously, I'll put the bus into VirtIOConsole so that it doesn't have to be static.
Quoted 10 lines
hw/virtio-console.h line 76
Quoted 8 lines
hw/virtio-console.h +8
-0+typedef struct VirtConBus VirtConBus ; +typedef struct VirtConPort VirtConPort ; +typedef struct VirtConPortInfo VirtConPortInfo ; + +typedef struct VirtConDevice { +DeviceState qdev; +VirtConPortInfo *info; +}VirtConDevice ;Leftover from old patch version?
You mean this should not be in the .h? Yeah.
Quoted 5 lines
Quoted 5 lines
+ * This is the state that's shared between all the ports. Some of the
+ * state is configurable via command-line options. Some of it can be
+ * set by individual devices in their initfn routines. Some of the
+ * state is set by the generic qdev device init routine.
+ */
Quoted 8 lines
hw/virtio-console.h line 89
Quoted 6 lines
hw/virtio-console.h +6
-0+struct VirtConPort { +DeviceState dev; +VirtConPortInfo *info; + +/* State for the chardevice associated with this port */ +CharDriverState *chr;That should go to the port driver if needed.
Wrote about the char driver above.
Quoted 7 lines
Quoted 7 lines
hw/virtio-console.h +7
-0+typedef int (*virtcon_port_qdev_initfn )(VirtConDevice *dev); + +struct VirtConPortInfo { +DeviceInfo qdev; +virtcon_port_qdev_initfn init; + +/* Callbacks for guest events */
Quoted 8 lines
hw/virtio-console.h line 139
Quoted 4 lines
hw/virtio-console.h +4
-0+void (*guest_open)(VirtConPort *port); +void (*guest_close)(VirtConPort *port); + +size_t (*have_data)(VirtConPort *port,const uint8_t *buf,size_t len);Maybe it is a good idea to pass a VirtConPortBuffer here instead of buf+len, especially when it becomes the port drivers job to do any buffering if needed.
Also touched upon above.
Thanks,
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 6 lines
virtio-serial-bus (and the corresponding -device virtio-serial-pci) virtio-console
virtio-serial-port
virtio-serial-vncIs that OK with all?
Looks fine to me.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+static VirtIOConsole
*virtio_console;Why do you need this?
Just to keep the current behaviour of restricting to one virtio-console device. This can be later reworked to allow multiple devices.
I'd drop the limit right from the start.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
hw/virtio-console-bus.c new file +9
-0+static void flush_queue (VirtConPort *port) +{ +VirtConPortBuffer *buf, *buf2; +uint8_t *outbuf; +size_t outlen, outsize; + +/* +* If the app isn't interested in buffering packets till it's +* opened, just drop the data guest sends us till a connection is Quoted 8 lines
hw/virtio-console-bus.c line 123
Quoted 4 lines
hw/virtio-console-bus.c new file +4
-0+* established. +*/ +if (!port->host_connected&& !port->flush_buffers) +return ;Hmm. Who needs that buffering? Only user seems to be the port driver (patch 4/6). So move the buffering (and the
host_connectedstate tracking) from the core to that driver?
Quoted 6 lines
The buffering could be used by other devices too I guess. The other two users that we currently have, vnc (which is just a demo patch) and console, don't need the buffering, but it's a general facility.
If more users need the buffering, the code could get duplicated so I thought of keeping it here.
I'd suggest to look what do do when another user which wants buffering comes along. Might be the requirements are different, so it wouldn't work anyway.
Also when you pass around pointers to VirtConPortBuffer the port drivers can implement buffering very easily.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+static VirtConBus
*virtcon_bus;Why do you need this?
I could put this in the VirtIOConsole struct.
Yes, please. You'll need that for multiple devices anyway.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
hw/virtio-console-bus.c new file +5
-0+static int virtcon_port_qdev_init (DeviceState *qdev,DeviceInfo *base) +{ +if (port->chr) { +qemu_chr_add_handlers (port->chr, vcon_can_read, vcon_read, vcon_event, + port);
Quoted 5 lines
Quoted 1 line
Should be handled by the VirtConPort drivers.
There are two reasons why I didn't put this there: virtio-console as well as virtio-serial-port will need char drivers. There could be others as well.
They are handled differently though. I think console will not do any buffering at all, whereas serial-port provides the option to do buffering.
There is also the option to stick both console and serial-port implementations into the same source file and make them share the functions which handle the chardev interaction.
Quoted 2 lines
Also, some virtio-specific checks are done in
vcon_can_read. So it's better this is put in the common code.
Having a helper function for the port drivers which fill the role vcon_can_read() fills right now certainly makes sense.
The naming is bad though. vcon_can_read() is named from the chardevs point of view. It actually checks how many bytes can be written to the virtio ring. It should be named accordingly.
Also the parameters should make sense from a port drivers point of view, not tweaked for chardev. Port drivers which don't need a chardev at all might want to use this too. Port drivers which link to a chardev can have a trivial one-liner wrapper function to map chardev callbacks into virtio-serial helper functions.
Quoted 9 lines
Quoted 9 lines
hw/virtio-console-bus.c line 735
Quoted 2 lines
hw/virtio-console-bus.c new file +2
-0+/* Spawn a new virtio-console bus on which the ports will ride as devices */ +virtcon_bus_new (dev);
s->bus=virtcon_bus_new(dev);
port0 =qdev_create(s->bus, "virtconsole"); /* console @ port0 for backward compat */
qdev_prop_set_*(port0, ...);qdev_init(port0);
Quoted 4 lines
Quoted 1 line
Or does that happen somewhere else?
I'm nowhere assuming now any port number - function mapping and so spawning a virtio-console on port#0 is not necessary.
How old kernels which expect a single console are supposed to work if you don't create one?
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 8 lines · Gerd Hoffmann
Quoted 6 lines
virtio-serial-bus (and the corresponding -device virtio-serial-pci) virtio-console
virtio-serial-port
virtio-serial-vncIs that OK with all?
Looks fine to me.
OK; that'll replace the current virtio-console-pci device but since it's not in use yet (from the command line explicity) that doesn't break anything.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+static VirtIOConsole
*virtio_console;Why do you need this?
Just to keep the current behaviour of restricting to one virtio-console device. This can be later reworked to allow multiple devices.
I'd drop the limit right from the start.
BTW the kernel too doesn't support multiple devices so far.
Quoted 25 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
hw/virtio-console-bus.c new file +9
-0+static void flush_queue (VirtConPort *port) +{ +VirtConPortBuffer *buf, *buf2; +uint8_t *outbuf; +size_t outlen, outsize; + +/* +* If the app isn't interested in buffering packets till it's +* opened, just drop the data guest sends us till a connection is Quoted 8 lines
hw/virtio-console-bus.c line 123
Quoted 4 lines
hw/virtio-console-bus.c new file +4
-0+* established. +*/ +if (!port->host_connected&& !port->flush_buffers) +return ;Hmm. Who needs that buffering? Only user seems to be the port driver (patch 4/6). So move the buffering (and the
host_connectedstate tracking) from the core to that driver?Quoted 6 lines
The buffering could be used by other devices too I guess. The other two users that we currently have, vnc (which is just a demo patch) and console, don't need the buffering, but it's a general facility.
If more users need the buffering, the code could get duplicated so I thought of keeping it here.
Quoted 6 lines
I'd suggest to look what do do when another user which wants buffering comes along. Might be the requirements are different, so it wouldn't work anyway.
Also when you pass around pointers to VirtConPortBuffer the port drivers can implement buffering very easily.
It will mostly be duplicated. Right now, I pass on an entire message as was passed on by the kernel in one write() request. If I start passing around buffers, it'll be incomplete messages (eg, an 8K write request in the kernel will be split in two buffers of 4K each -- or three buffers with the last one containing a few bytes). I don't think I want the ports to worry about that. The ports should just get the entire message.
In fact, it is this way because vnc needs the entire message handed out to it in one go.
So I don't think I want to expose the buffers to individual devices.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
hw/virtio-console-bus.c line 678
Quoted 6 lines
hw/virtio-console-bus.c new file +5
-0+static int virtcon_port_qdev_init (DeviceState *qdev,DeviceInfo *base) +{ +if (port->chr) { +qemu_chr_add_handlers (port->chr, vcon_can_read, vcon_read, vcon_event, + port);Should be handled by the VirtConPort drivers.
Quoted 7 lines
Quoted 3 lines
There are two reasons why I didn't put this there: virtio-console as well as virtio-serial-port will need char drivers. There could be others as well.
They are handled differently though. I think console will not do any buffering at all, whereas serial-port provides the option to do buffering.
But the buffering is independent of the char drivers.
Quoted 3 lines
There is also the option to stick both console and serial-port implementations into the same source file and make them share the functions which handle the chardev interaction.
Sure; that's a possibility.
Quoted 5 lines
Quoted 2 lines
Also, some virtio-specific checks are done in
vcon_can_read. So it's better this is put in the common code.Having a helper function for the port drivers which fill the role
vcon_can_read()fills right now certainly makes sense.
Yeah; if the char stuff is to be taken out of the bus file.
Quoted 9 lines
The naming is bad though.
vcon_can_read()is named from the chardevs point of view. It actually checks how many bytes can be written to the virtio ring. It should be named accordingly.Also the parameters should make sense from a port drivers point of view, not tweaked for chardev. Port drivers which don't need a chardev at all might want to use this too. Port drivers which link to a chardev can have a trivial one-liner wrapper function to map chardev callbacks into virtio-serial helper functions.
Yeah; again, if the chardev stuff is to be moved out of the bus file, then yes.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
hw/virtio-console-bus.c line 735
Quoted 2 lines
hw/virtio-console-bus.c new file +2
-0+/* Spawn a new virtio-console bus on which the ports will ride as devices */ +virtcon_bus_new (dev);
s->bus=virtcon_bus_new(dev);
port0 =qdev_create(s->bus, "virtconsole"); /* console @ port0 for backward compat */
qdev_prop_set_*(port0, ...);qdev_init(port0);
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Or does that happen somewhere else?
I'm nowhere assuming now any port number - function mapping and so spawning a virtio-console on port#0 is not necessary.
How old kernels which expect a single console are supposed to work if you don't create one?
Basically I've now dropped the old -virtioconsole argument.
So one has to do:
-device virtio-console-pci -device virtioconsole ...
to start a console.
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 1 line
BTW the kernel too doesn't support multiple devices so far.
Needs fixing too ;)
Quoted 7 lines
Quoted 6 lines
I'd suggest to look what do do when another user which wants buffering comes along. Might be the requirements are different, so it wouldn't work anyway.
Also when you pass around pointers to VirtConPortBuffer the port drivers can implement buffering very easily.
Quoted 6 lines
It will mostly be duplicated. Right now, I pass on an entire message as was passed on by the kernel in one
write()request. If I start passing around buffers, it'll be incomplete messages (eg, an 8K write request in the kernel will be split in two buffers of 4K each -- or three buffers with the last one containing a few bytes). I don't think I want the ports to worry about that. The ports should just get the entire message.
Sure. I think there is a misunderstanding here. I meant only the "buffer messages when unconnected" thing. Reassembling the messages in the core and forward only complete messages to the ports is fine.
Quoted 1 line
So I don't think I want to expose the buffers to individual devices.
My idea was to pass the (reassembled) message to the port drivers in a form they can just stick into a list without memcpy()ing the message in case they want to keep it. Maybe to buffer it because the chardev is unconnected. Maybe just keep the most recent message because it contains some kind of guest status.
VirtConPortBuffer looked like it could do the job. Well, not perfectly, it has extra status which is needed only by the core for reassembling messages.
Quoted 5 lines
Quoted 3 lines
They are handled differently though. I think console will not do any buffering at all, whereas serial-port provides the option to do buffering.
But the buffering is independent of the char drivers.
See above ;)
Quoted 7 lines
Basically I've now dropped the old -virtioconsole argument.
So one has to do:
-device virtio-console-pci -device virtioconsole ...
to start a console.
If you do '-device virtio-console-pci -device virtio-port' (i.e. no console) and boot a old guest kernel which expects a (single) console being there, what will happen?
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 3 lines · Gerd Hoffmann
Quoted 1 line
BTW the kernel too doesn't support multiple devices so far.
Needs fixing too ;)
Agreed :-) I've fixed multiple devices in qemu.
Quoted 14 lines
Quoted 7 lines
Quoted 6 lines
I'd suggest to look what do do when another user which wants buffering comes along. Might be the requirements are different, so it wouldn't work anyway.
Also when you pass around pointers to VirtConPortBuffer the port drivers can implement buffering very easily.
Quoted 6 lines
It will mostly be duplicated. Right now, I pass on an entire message as was passed on by the kernel in one
write()request. If I start passing around buffers, it'll be incomplete messages (eg, an 8K write request in the kernel will be split in two buffers of 4K each -- or three buffers with the last one containing a few bytes). I don't think I want the ports to worry about that. The ports should just get the entire message.
Quoted 3 lines
Sure. I think there is a misunderstanding here. I meant only the "buffer messages when unconnected" thing. Reassembling the messages in the core and forward only complete messages to the ports is fine.
OK; so in that case, passing a ptr to the buffer and its length is fine, no?
Quoted 11 lines
Quoted 7 lines
Basically I've now dropped the old -virtioconsole argument.
So one has to do:
-device virtio-console-pci -device virtioconsole ...
to start a console.
If you do '-device virtio-console-pci -device virtio-port' (i.e. no console) and boot a old guest kernel which expects a (single) console being there, what will happen?
OK -- I get what you're saying now. However, I don't see any problem here. If there is no virtioconsole specified to qemu, there's no reason to expect a console in the guest. That was the case in the past and is the case now as well. The difference is earlier, when probe() in the guest was called, it definitely meant the existence of a console. Now, even if probe() is invoked, it doesn't mean a console was found. But this hardly is a concern.
Also, the way to attach to a virtioconsole is by spawning a tty on /dev/hvc0. If no -virtioconsole is specified on the host command line, no hvc device is spawned on the guest. So things are as they are.
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Hi,
Quoted 6 lines
Quoted 3 lines
Sure. I think there is a misunderstanding here. I meant only the "buffer messages when unconnected" thing. Reassembling the messages in the core and forward only complete messages to the ports is fine.
OK; so in that case, passing a ptr to the buffer and its length is fine, no?
Will work. We need some clear rules for buffer memory though. Possible ways to deal with it:
(1) core owns the buffer. If the port driver wants to keep the content it has to memcpy() it to own memory.
(2) have_data() callback transfers buffer ownership from core to the port driver. It is the port drivers job to free the memory when it doesn't need it any more.
(3) reference-count the buffers.
For (1) + (2) both buffer struct and ptr+len will work.
For (3) ptr+len wouldn't work though, you'll need some struct containing ptr, len, refcount and helper functions to get/put buffers.
Quoted 11 lines
Quoted 3 lines
If you do '-device virtio-console-pci -device virtio-port' (i.e. no console) and boot a old guest kernel which expects a (single) console being there, what will happen?
OK -- I get what you're saying now. However, I don't see any problem here. If there is no virtioconsole specified to qemu, there's no reason to expect a console in the guest. That was the case in the past and is the case now as well. The difference is earlier, when
probe()in the guest was called, it definitely meant the existence of a console. Now, even ifprobe()is invoked, it doesn't mean a console was found. But this hardly is a concern.
True for new guest kernels, they simply don't create a hvc. Question is what *old* guest kernels will do in that case.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 19 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
Quoted 3 lines
Sure. I think there is a misunderstanding here. I meant only the "buffer messages when unconnected" thing. Reassembling the messages in the core and forward only complete messages to the ports is fine.
OK; so in that case, passing a ptr to the buffer and its length is fine, no?
Will work. We need some clear rules for buffer memory though. Possible ways to deal with it:
(1) core owns the buffer. If the port driver wants to keep the content it has to
memcpy()it to own memory.
(2)have_data()callback transfers buffer ownership from core to the port driver. It is the port drivers job to free the memory when it doesn't need it any more.
(3) reference-count the buffers.
Quoted 4 lines
For (1) + (2) both buffer struct and ptr+len will work.
For (3) ptr+len wouldn't work though, you'll need some struct containing ptr, len, refcount and helper functions to get/put buffers.
Yeah; Currently it's only (1). But I'm now thinking of doing (2). One concern Yaniv raised was a port driver may not consume all the data right away, so it's better to let the port do the buffer management.
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
If you do '-device virtio-console-pci -device virtio-port' (i.e. no console) and boot a old guest kernel which expects a (single) console being there, what will happen?
OK -- I get what you're saying now. However, I don't see any problem here. If there is no virtioconsole specified to qemu, there's no reason to expect a console in the guest. That was the case in the past and is the case now as well. The difference is earlier, when
probe()in the guest was called, it definitely meant the existence of a console. Now, even ifprobe()is invoked, it doesn't mean a console was found. But this hardly is a concern.
Quoted 2 lines
True for new guest kernels, they simply don't create a hvc. Question is what *old* guest kernels will do in that case.
If the guest kernel doesn't support the new virtio feature VIRTIO_F_MULTIPORT, then we disable all this functionality and only allow one port. That one port has to be the console port. I've tested this combination, btw.
However, it's possible that some of the checks got lost in the latest rework and that port 0 isn't actually a console port. I'll go through init code again to ensure this. Thanks for explaining the scenario!
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 15 lines · Amit Shah
Quoted 12 lines
Quoted 11 lines
Quoted 3 lines
If you do '-device virtio-console-pci -device virtio-port' (i.e. no console) and boot a old guest kernel which expects a (single) console being there, what will happen?
OK -- I get what you're saying now. However, I don't see any problem here. If there is no virtioconsole specified to qemu, there's no reason to expect a console in the guest. That was the case in the past and is the case now as well. The difference is earlier, when
probe()in the guest was called, it definitely meant the existence of a console. Now, even ifprobe()is invoked, it doesn't mean a console was found. But this hardly is a concern.Quoted 2 lines
True for new guest kernels, they simply don't create a hvc. Question is what *old* guest kernels will do in that case.
Quoted 8 lines
If the guest kernel doesn't support the new virtio feature
VIRTIO_F_MULTIPORT, then we disable all this functionality and only allow one port. That one port has to be the console port. I've tested this combination, btw.However, it's possible that some of the checks got lost in the latest rework and that port 0 isn't actually a console port. I'll go through init code again to ensure this. Thanks for explaining the scenario!
There are a couple of problems with what I said:
- I had to make some changes in the kernel driver because hvc didn't work as I expected. If initial consoles were spawned (currently only on s390 and powerpc), new ports have to arrive in the same order as init consoles were spawned.
This means /dev/console will be bound to the first console port that gets initialised. It's desirable to always have port0 get that distinction.
- We won't know if the guest supports multiple ports till the guest driver does a probe(). That's much much later than when port drivers in qemu are initialised.
So we will have to spawn a console port at id 0 when the bus is initialised.
There are a couple of problems though:
- How to identify which chardev to associate the port#0 with?
- If there is a virtioconsole device specified on the command line, should that be used as port0? Or should that mean we spawn two consoles?
I guess for both these cases, some special command line tweaks will be needed? Or keep the old '-virtioconsole' parameter and put that up as port0?
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Hi,
Quoted 5 lines
So we will have to spawn a console port at id 0 when the bus is initialised.
There are a couple of problems though:
- How to identify which chardev to associate the port#0 with?
I'd suggest to give the serial-bus a chardev attribute, which is then simply passed through, i.e.
-device virtio-serial-bus,chardev=<name>
automatically creates a virtioconsole with port=0 and chardev=<name> on the newly created bus.
Quoted 3 lines
- If there is a virtioconsole device specified on the command line, should that be used as port0? Or should that mean we spawn two consoles?
Two consoles.
Quoted 3 lines
I guess for both these cases, some special command line tweaks will be needed? Or keep the old '-virtioconsole' parameter and put that up as port0?
See above.
Keeping -virtioconsole for backward compatibility is easy, it would basically create a chardev with a virtio<nr> label as it does today, then create virtio-serial-bus with chardev=virtio<nr>.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 8 lines · Gerd Hoffmann
Hi,
Quoted 5 lines
So we will have to spawn a console port at id 0 when the bus is initialised.
There are a couple of problems though:
- How to identify which chardev to associate the port#0 with?
Quoted 7 lines
I'd suggest to give the serial-bus a chardev attribute, which is then simply passed through, i.e.
-device virtio-serial-bus,chardev=<name>
automatically creates a virtioconsole with port=0 and chardev=<name> on the newly created bus.
Hm, this looks weird. Because on one hand we're talking about decoupling the char driver from the core (virtio-serial-bus) and here we're actually attaching a char driver to the bus.
Quoted 9 lines
Quoted 3 lines
I guess for both these cases, some special command line tweaks will be needed? Or keep the old '-virtioconsole' parameter and put that up as port0?
See above.
Keeping -virtioconsole for backward compatibility is easy, it would basically create a chardev with a virtio<nr> label as it does today, then create virtio-serial-bus with chardev=virtio<nr>.
I prefer to remove the -virtioconsole argument because we won't be able to specify the bus that's to be attached to.
Also, we can't say if a virtio-serial-bus is also specified. If one is, we'd want the console to attach to that bus. If one isn't, we'd want to spawn a new one in that case. But as per above, a virtio-serial-bus should always spawn a virtio-console port.
I fear we'll end up in a mess of tricky if-else conditions.
And I can't think of a nice solution to the problem above right now.
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 8 lines · Amit Shah
Quoted 4 lines
-device virtio-serial-bus,chardev=<name>
automatically creates a virtioconsole with port=0 and chardev=<name> on the newly created bus.
Hm, this looks weird. Because on one hand we're talking about decoupling the char driver from the core (virtio-serial-bus) and here we're actually attaching a char driver to the bus.
We don't actually attach the chardev to the bus though. It is just passed through to the auto-created console port #0.
But it looks a bit weird indeed. I'm open to better suggestions to address the "port #0 must be console for backward compatibility reasons" issue.
Quoted 6 lines
Quoted 3 lines
Keeping -virtioconsole for backward compatibility is easy, it would basically create a chardev with a virtio<nr> label as it does today, then create virtio-serial-bus with chardev=virtio<nr>.
I prefer to remove the -virtioconsole argument because we won't be able to specify the bus that's to be attached to.
Oh, I thought it would create a new virtio-serial-bus (plus auto-created port0 console) unconditionally. Just do enougth to keep existing users of the switch working.
If you want new features (i.e. two consoles ports attached to one virtio-serial-bus device) you must use the new syntax.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Amit Shah
Quoted 4 lines
-device virtio-serial-bus,chardev=<name>
automatically creates a virtioconsole with port=0 and chardev=<name> on the newly created bus.
Quoted 6 lines
Quoted 3 lines
Hm, this looks weird. Because on one hand we're talking about decoupling the char driver from the core (virtio-serial-bus) and here we're actually attaching a char driver to the bus.
We don't actually attach the chardev to the bus though. It is just passed through to the auto-created console port #0.
Yes, but it's unituitive... and weird.
Quoted 3 lines
But it looks a bit weird indeed. I'm open to better suggestions to address the "port #0 must be console for backward compatibility reasons" issue.
Hm, me too. I'll think about this more.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Keeping -virtioconsole for backward compatibility is easy, it would basically create a chardev with a virtio<nr> label as it does today, then create virtio-serial-bus with chardev=virtio<nr>.
I prefer to remove the -virtioconsole argument because we won't be able to specify the bus that's to be attached to.
Quoted 6 lines
Oh, I thought it would create a new virtio-serial-bus (plus auto-created port0 console) unconditionally. Just do enougth to keep existing users of the switch working.
If you want new features (i.e. two consoles ports attached to one virtio-serial-bus device) you must use the new syntax.
So it's better overall to drop the old syntax altogether, right? It could get easily confusing otherwise.
We can easily end up having:
-virtioconsole <chardev>
<auto-creates a bus and attaches a console port to it>
-device virtio-serial-pci,id=blah
<a second bus>
-device virtport,bus=blah.0
<and no way to connect a device to the bus that got created by virtioconsole>
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 15 lines · Amit Shah
Quoted 6 lines
Oh, I thought it would create a new virtio-serial-bus (plus auto-created port0 console) unconditionally. Just do enougth to keep existing users of the switch working.
If you want new features (i.e. two consoles ports attached to one virtio-serial-bus device) you must use the new syntax.
So it's better overall to drop the old syntax altogether, right? It could get easily confusing otherwise.
We can easily end up having:
-virtioconsole<chardev>
<auto-creates a bus and attaches a console port to it>
Quoted 7 lines
-device virtio-serial-pci,id=blah
<a second bus>-device virtport,bus=blah.0
<and no way to connect a device to the bus that got created by virtioconsole>
It isn't that bad.
First, the busses get names based on the bus type by default, i.e. when creating a scsi adapter without specifying id=seomthing the bus is simply named "scsi.0". Likewise the -virtioconsole created bus would be "port.0" or simliar (depends on the name in BusInfo).
Second, the bus= argument is optional. If not specified, qdev will pick the first bus of a matching type it finds. So as long you have a single port/scsi/usb/... bus only you don't need bus= at all. You can do:
-virtioconsole <chardev> -device virtport,<args>
and it will work just fine (creating a bus with the autocreated console and additionally a virtport device attached to the same bus).
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 26 lines · Gerd Hoffmann
Quoted 15 lines · Amit Shah
Quoted 6 lines
Oh, I thought it would create a new virtio-serial-bus (plus auto-created port0 console) unconditionally. Just do enougth to keep existing users of the switch working.
If you want new features (i.e. two consoles ports attached to one virtio-serial-bus device) you must use the new syntax.
So it's better overall to drop the old syntax altogether, right? It could get easily confusing otherwise.
We can easily end up having:
-virtioconsole<chardev>
<auto-creates a bus and attaches a console port to it>Quoted 7 lines
-device virtio-serial-pci,id=blah
<a second bus>-device virtport,bus=blah.0
<and no way to connect a device to the bus that got created by virtioconsole>
It isn't that bad.
Quoted 8 lines
First, the busses get names based on the bus type by default, i.e. when creating a scsi adapter without specifying id=seomthing the bus is simply named "scsi.0". Likewise the -virtioconsole created bus would be "port.0" or simliar (depends on the name in BusInfo).
Second, the bus= argument is optional. If not specified, qdev will pick the first bus of a matching type it finds. So as long you have a single port/scsi/usb/... bus only you don't need bus= at all. You can do:
The problem with this is that the management solution needs to know then what is the default bus name (which could change if the code gets updated).
And also there's the other problem of a console port spawning a bus (which could end up spawning another console port at #0...)
So IMO it's better to leave that command line param out.
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 8 lines · Amit Shah
Quoted 3 lines · Gerd Hoffmann
Second, the bus= argument is optional. If not specified, qdev will pick the first bus of a matching type it finds. So as long you have a single port/scsi/usb/... bus only you don't need bus= at all. You can do:
The problem with this is that the management solution needs to know then what is the default bus name (which could change if the code gets updated).
No problem. Just don't use -virtioconsole. Go with -device virtio-serial-bus,id=... + -device virtport,bus=.. then and explicitly name your devices (and thereby the buses too).
-virtioconsole should *really* be a pure backward compatibility thing. Use case: You have a script starting qemu using -virtioconsole. After upgrading qemu it should continue to work, i.e. create a device which the guest can use as before the upgrade and which is linked up to a chardev as it was before.
Anything which wants to use the new features can (and should) completely ignore -virtioconsole. I just wanted to point out that mixing old and new style is *possible*. It wasn't my intention to imply that I *recommend* doing that.
Quoted 2 lines
And also there's the other problem of a console port spawning a bus (which could end up spawning another console port at #0...)
parse error.
I don't understand what problem you are trying to point out.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 20 lines · Gerd Hoffmann
Quoted 8 lines · Amit Shah
Quoted 3 lines · Gerd Hoffmann
Second, the bus= argument is optional. If not specified, qdev will pick the first bus of a matching type it finds. So as long you have a single port/scsi/usb/... bus only you don't need bus= at all. You can do:
The problem with this is that the management solution needs to know then what is the default bus name (which could change if the code gets updated).
No problem. Just don't use -virtioconsole. Go with -device virtio-serial-bus,id=... + -device virtport,bus=.. then and explicitly name your devices (and thereby the buses too).
-virtioconsole should *really* be a pure backward compatibility thing. Use case: You have a script starting qemu using -virtioconsole. After upgrading qemu it should continue to work, i.e. create a device which the guest can use as before the upgrade and which is linked up to a chardev as it was before.
Quoted 4 lines
Anything which wants to use the new features can (and should) completely ignore -virtioconsole. I just wanted to point out that mixing old and new style is *possible*. It wasn't my intention to imply that I *recommend* doing that.
There should be some way of deprecating commands in qemu. Maybe in 1-2 release cycles.
Quoted 5 lines
Quoted 2 lines
And also there's the other problem of a console port spawning a bus (which could end up spawning another console port at #0...)
parse error.
I don't understand what problem you are trying to point out.
Oh; I was stuck at the earlier suggestion made by you:
-device virtio-serial-pci,chardev=...
which implies -device virtioconsole (with a port at id 0)
and then someone also doing
-virtioconsole ...
which would end up creating another bus for this current backward compat reason.
Amit
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
Quoted 3 lines · Amit Shah
On (Wed) Oct 07 2009 [15:06:08], Gerd Hoffmann wrote:
There should be some way of deprecating commands in qemu. Maybe in 1-2 release cycles.
Yes, we should think about that, especially as the qdev switch brings alot of changes here.
Quoted 4 lines
Oh; I was stuck at the earlier suggestion made by you:
-device virtio-serial-pci,chardev=...
Quoted 8 lines
which implies -device virtioconsole (with a port at id 0)
and then someone also doing
-virtioconsole ...
which would end up creating another bus for this current backward compat reason.
Yes, mixing old and new style is good for surprises. Better avoid that ;)
cheers,
Gerd
Re: [Qemu-devel] [PATCH 3/6] virtio-console: Add a virtio-console bus, support for multiple ports
In reply to Gerd HoffmannQuoted 10 lines · Gerd Hoffmann
Quoted 8 lines · Amit Shah
Quoted 3 lines · Gerd Hoffmann
Second, the bus= argument is optional. If not specified, qdev will pick the first bus of a matching type it finds. So as long you have a single port/scsi/usb/... bus only you don't need bus= at all. You can do:
The problem with this is that the management solution needs to know then what is the default bus name (which could change if the code gets updated).
Quoted 6 lines
No problem. Just don't use -virtioconsole. Go with -device virtio-serial-bus,id=... + -device virtport,bus=.. then and explicitly name your devices (and thereby the buses too).
-virtioconsole should *really* be a pure backward compatibility thing.
Use case: You have a script starting qemu using -virtioconsole. After upgrading qemu it should continue to work, i.e. create a device which the guest can use as before the upgrade and which is linked up to a chardev as it was before.Anything which wants to use the new features can (and should) completely ignore -virtioconsole. I just wanted to point out that mixing old and new style is *possible*. It wasn't my intention to imply that I *recommend* doing that.
I agree.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open
In reply to Amit ShahQuoted 8 lines · Amit Shah
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.
Signed-off-by Amit Shah <[email protected]>
This series breaks the build (ppc440_bamboo.c).
You should always build without an explicit --target-list to avoid this in the future.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Amit Shah
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.
Signed-off-by Amit Shah <[email protected]>This series breaks the build (
ppc440_bamboo.c).
This patch or this series? If it's this patch, that's surprising!
Quoted 2 lines
You should always build without an explicit --target-list to avoid this in the future.
Sure -- I intend to when I send a request for the merging once all the comments have been sorted out.
Thanks,
Amit
Re: [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open
Quoted 8 lines · Amit Shah
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Amit Shah
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.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Amit Shah <[email protected]>This series breaks the build (
ppc440_bamboo.c).This patch or this series? If it's this patch, that's surprising!
OK; it's the other patch. This ppc440 machine also init'ed the virtio-console-pci the way pc.c did; I'll remove this as well.
Amit
Re: [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open
In reply to Amit ShahQuoted 16 lines · Amit Shah
Quoted 5 lines · Anthony Liguori
Quoted 3 lines · Amit Shah
Notify users of the char interface whenever the file / connection is opened.
Quoted 8 lines
Quoted 6 lines
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.
Signed-off-by Amit Shah <[email protected]>This series breaks the build (
ppc440_bamboo.c).
Quoted 9 lines
This patch or this series? If it's this patch, that's surprising!
Quoted 2 lines
You should always build without an explicit --target-list to avoid this in the future.
Sure -- I intend to when I send a request for the merging once all the comments have been sorted out.
If you don't intend a patch series to be merged, then you should put [RFC] in the subject.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open
Quoted 8 lines · Anthony Liguori
Quoted 5 lines
Quoted 2 lines
You should always build without an explicit --target-list to avoid this in the future.
Sure -- I intend to when I send a request for the merging once all the comments have been sorted out.
If you don't intend a patch series to be merged, then you should put [RFC] in the subject.
Huh? I'm a bit surprised you are considering patches for merge which are discussed alot on the list and thus most likely not final.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open
Quoted 11 lines · Gerd Hoffmann
Quoted 8 lines · Anthony Liguori
Quoted 5 lines
Quoted 2 lines
You should always build without an explicit --target-list to avoid this in the future.
Sure -- I intend to when I send a request for the merging once all the comments have been sorted out.
If you don't intend a patch series to be merged, then you should put [RFC] in the subject.
Huh? I'm a bit surprised you are considering patches for merge which are discussed alot on the list and thus most likely not final.
Amit has repeatedly asked me to consider these series for merging. If there is no indicator in the subject that they are not intended to be merged, then they're going to go through staging.
I'll remove them from staging once I see that the patches are contended. The reason I do this is to make sure that patches don't get dropped.
There's no excuse for a patch to be on the mailing list that isn't properly tested (especially build tested) without an appropriate tag indicating that like [RFC].
Regards,
Anthony Liguori
Quoted 2 lines
cheers,
Gerd
Re: [Qemu-devel] [PATCH 1/6] char: Emit 'OPENED' events on char device open
Quoted 2 lines · Anthony Liguori
I'll remove them from staging once I see that the patches are contended. The reason I do this is to make sure that patches don't get dropped.
Stick everything into the staging queue, solve conflicts, just to throw them out again later (which might produce conflicts again) doesn't look like a good workflow to me. You spend time solving patch conflicts for nothing.
There must be better ways to keep track of the patches ...
Quoted 3 lines
There's no excuse for a patch to be on the mailing list that isn't properly tested (especially build tested) without an appropriate tag indicating that like [RFC].
Indeed.
cheers,
Gerd
Quoted 7 lines · Amit Shah
Hello,
This patch series converts the virtio-console device to qdev, adds a virtio-console bus on which similar devices can ride and shows how such devices can be used by adding a new virtio-console-port device and also a virtio-console-vnc device.
Quoted 8 lines
This is working well in my testing. I tested old kernel/new qemu, new kernel/old qemu and new kernel/new qemu.
The ports are also tested by spawning two virtio consoles and one generic port. Heavy activity on all three ports is sustained for quite a long time with correct results.
Please review and apply.
BTW I've just kept the names to
-device virtio-console-pci (for the bus)
-device virtconsole (for the console device)
-device virtconport (for a generic port)
I'm open to changing these -- or keeping as they are.
There's also a 'flush_buffers' option to the devices, that could do with a better name.
Also these patches are against qemu-kvm.git so they won't apply to qemu.git -- I'll send the patches against qemu.git next time around.
Amit