QOM realize for virtio-console
v3 cover QOM realize for virtio-console
Hello,
This series converts VirtIOSerialPort to QOM realize/unrealize.
v3 minimizes changes by adopting Anthony's new scheme of just replacing fields, as done for VirtioDevices already.
I have simple qtests for virtio-serial-bus and virtio-console on a different branch that I'll submit shortly, with the intent of queuing first the tests and then these leftover conversions on qom-next.
Available from:
https://github.com/afaerber/qemu-cpu/commits/realize-virtio-console.v3git://github.com/afaerber/qemu-cpu.git realize-virtio-console.v3
Regards,
Andreas
v2 -> v3:
* Revert changes to just change init/exit signature to realize/unrealize, leave the base class in control over realize/unrealize and call in-order.
* Rebased on Paolo's version of virtio QOM realize conversion - no changes.
v1 -> v2:
* Split off virtserialport fix for 1.6.
* Split off from main virtio realization series.
* Split out cleanups (mst).
Andreas Färber (2):
virtio-console: QOM cast cleanup for VirtConsole
virtio-serial-port: Convert to QOM realize/unrealize
hw/char/virtio-console.c | 57 +++++++++++++++++++++------------------ hw/char/virtio-serial-bus.c | 52 ++++++++++++++++++----------------- include/hw/virtio/virtio-serial.h | 14 +++++----- 3 files changed, 65 insertions(+), 58 deletions(-)
Signature · 1 line
1.8.4.5
PATCH v3 1/2 virtio-console: QOM cast cleanup for VirtConsole
Introduce type constant, cast macro and rename parent field.
--- hw/char/virtio-console.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-)
hw/char/virtio-console.c +20 -13
@@ -15,8 +15,13 @@#include "trace.h" #include "hw/virtio/virtio-serial.h" +#define TYPE_VIRTIO_CONSOLE "virtconsole" +#define VIRTIO_CONSOLE (obj) \ + OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE) +typedef struct VirtConsole { -VirtIOSerialPort port; +VirtIOSerialPort parent_obj; +CharDriverState *chr;guint watch; }VirtConsole ;
@@ -31,7 +36,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,VirtConsole *vcon = opaque; vcon->watch =0 ; -virtio_serial_throttle_port (&vcon->port, false); +virtio_serial_throttle_port (VIRTIO_SERIAL_PORT (vcon), false);return FALSE; }
@@ -39,7 +44,7 @@ static gboolean chr_write_unblocked(GIOChannel *chan, GIOCondition cond,static ssize_t flush_buf (VirtIOSerialPort *port,const uint8_t *buf,ssize_t len) { -VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); +VirtConsole *vcon =VIRTIO_CONSOLE (port);ssize_t ret;if (!vcon->chr) {
@@ -75,7 +80,7 @@ static ssize_t flush_buf(VirtIOSerialPort *port,/* Callback function that's called when the guest opens/closes the port */ static void set_guest_connected (VirtIOSerialPort *port,int guest_connected) { -VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); +VirtConsole *vcon =VIRTIO_CONSOLE (port);if (!vcon->chr) {return ;
@@ -88,40 +93,42 @@ static int chr_can_read(void *opaque) {VirtConsole *vcon = opaque; -return virtio_serial_guest_ready (&vcon->port); +return virtio_serial_guest_ready (VIRTIO_SERIAL_PORT (vcon)); }/* Send data from a char device over to the guest */ static void chr_read (void *opaque,const uint8_t *buf,int size) {VirtConsole *vcon = opaque; +VirtIOSerialPort *port =VIRTIO_SERIAL_PORT (vcon); -trace_virtio_console_chr_read (vcon->port.id, size); -virtio_serial_write (&vcon->port, buf, size); +trace_virtio_console_chr_read (port->id, size); +virtio_serial_write (port, buf, size); }static void chr_event (void *opaque,int event) {VirtConsole *vcon = opaque; +VirtIOSerialPort *port =VIRTIO_SERIAL_PORT (vcon); -trace_virtio_console_chr_event (vcon->port.id, event); +trace_virtio_console_chr_event (port->id, event);switch (event) {case CHR_EVENT_OPENED : -virtio_serial_open (&vcon->port); +virtio_serial_open (port);break ;case CHR_EVENT_CLOSED :if (vcon->watch) {g_source_remove (vcon->watch); vcon->watch =0 ; } -virtio_serial_close (&vcon->port); +virtio_serial_close (port);break ; } }static int virtconsole_initfn (VirtIOSerialPort *port) { -VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); +VirtConsole *vcon =VIRTIO_CONSOLE (port);VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_GET_CLASS (port);if (port->id ==0 && !k->is_console) {
@@ -140,7 +147,7 @@ static int virtconsole_initfn(VirtIOSerialPort *port)static int virtconsole_exitfn (VirtIOSerialPort *port) { -VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); +VirtConsole *vcon =VIRTIO_CONSOLE (port);if (vcon->watch) {g_source_remove (vcon->watch);
@@ -168,7 +175,7 @@ static void virtconsole_class_init(ObjectClass *klass, void *data) }static const TypeInfo virtconsole_info = { - .name ="virtconsole" , + .name =TYPE_VIRTIO_CONSOLE , .parent =TYPE_VIRTIO_SERIAL_PORT , .instance_size =sizeof (VirtConsole), .class_init = virtconsole_class_init,
Signature · 1 line
1.8.4.5
PATCH v3 2/2 virtio-serial-port: Convert to QOM realize/unrealize
In reply to Andreas Färber--- hw/char/virtio-console.c | 28 ++++++++++----------- hw/char/virtio-serial-bus.c | 52 ++++++++++++++++++++------------------- include/hw/virtio/virtio-serial.h | 14 +++++------ 3 files changed, 47 insertions(+), 47 deletions(-)
hw/char/virtio-console.c +13 -15
@@ -126,14 +126,16 @@ static void chr_event(void *opaque, int event) } } -static int virtconsole_initfn (VirtIOSerialPort *port) +static void virtconsole_realize (DeviceState *dev,Error **errp) { -VirtConsole *vcon =VIRTIO_CONSOLE (port); -VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_GET_CLASS (port); +VirtIOSerialPort *port =VIRTIO_SERIAL_PORT (dev); +VirtConsole *vcon =VIRTIO_CONSOLE (dev); +VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_GET_CLASS (dev);if (port->id ==0 && !k->is_console) { -error_report ("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility." ); -return -1 ; +error_setg (errp,"Port number 0 on virtio-serial devices reserved " +"for virtconsole devices for backward compatibility." ); +return ; }if (vcon->chr) {
@@ -141,19 +143,15 @@ static int virtconsole_initfn(VirtIOSerialPort *port)qemu_chr_add_handlers (vcon->chr, chr_can_read, chr_read, chr_event, vcon); } - -return 0 ; } -static int virtconsole_exitfn (VirtIOSerialPort *port) +static void virtconsole_unrealize (DeviceState *dev,Error **errp) { -VirtConsole *vcon =VIRTIO_CONSOLE (port); +VirtConsole *vcon =VIRTIO_CONSOLE (dev);if (vcon->watch) {g_source_remove (vcon->watch); } - -return 0 ; }static Property virtconsole_properties[] = {
@@ -167,8 +165,8 @@ static void virtconsole_class_init(ObjectClass *klass, void *data)VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_CLASS (klass); k->is_console = true; - k->init = virtconsole_initfn; - k->exit = virtconsole_exitfn; + k->realize = virtconsole_realize; + k->unrealize = virtconsole_unrealize; k->have_data = flush_buf; k->set_guest_connected = set_guest_connected; dc->props = virtconsole_properties;
@@ -191,8 +189,8 @@ static void virtserialport_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);VirtIOSerialPortClass *k =VIRTIO_SERIAL_PORT_CLASS (klass); - k->init = virtconsole_initfn; - k->exit = virtconsole_exitfn; + k->realize = virtconsole_realize; + k->unrealize = virtconsole_unrealize; k->have_data = flush_buf; k->set_guest_connected = set_guest_connected; dc->props = virtserialport_properties;
hw/char/virtio-serial-bus.c +27 -25
105 lines not on this page · raw message
include/hw/virtio/virtio-serial.h +7 -7
@@ -77,19 +77,19 @@ typedef struct VirtIOSerialPort VirtIOSerialPort; typedef struct VirtIOSerialPortClass { DeviceClass parent_class; - /* Is this a device that binds with hvc in the guest? */ - bool is_console; - /* - * The per-port (or per-app) init function that's called when a + * The per-port (or per-app) realize function that's called when a * new device is found on the bus. */ - int (*init)(VirtIOSerialPort *port); + DeviceRealize realize; /* - * Per-port exit function that's called when a port gets + * Per-port unrealize function that's called when a port gets * hot-unplugged or removed. */ - int (*exit)(VirtIOSerialPort *port); + DeviceUnrealize unrealize; + + /* Is this a device that binds with hvc in the guest? */ + bool is_console; /* Callbacks for guest events */ /* Guest opened/closed device. */
Signature · 1 line
1.8.4.5
Re: [Qemu-devel] [PATCH v3 2/2] virtio-serial-port: Convert to QOM realize/unrealize
Hi,
I haven't really followed the whole discussion, so can't say much about it -- overall looks alright. A couple of minor nits:
hw/char/virtio-serial-bus.c static int virtser_port_qdev_init(DeviceState *qdev) · line 855
Quoted 8 lines
max_nr_ports = tswap32(port->vser->config.max_nr_ports); if (port->id >= max_nr_ports) {hw/char/virtio-serial-bus.c +3
-3-error_report ("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u" , - max_nr_ports -1 ); -return -1 ; +error_setg (errp,"virtio-serial-bus: Out-of-range port id specified, " +"max. allowed: %u" , + max_nr_ports -1 );
indentation looks off. Just put this last line on the line above?
Quoted 18 lines
include/hw/virtio/virtio-serial.h +2
-5@@ -77,19 +77,19 @@ typedef struct VirtIOSerialPort VirtIOSerialPort; typedef struct VirtIOSerialPortClass { DeviceClass parent_class; - /* Is this a device that binds with hvc in the guest? */ - bool is_console; - /* - * The per-port (or per-app) init function that's called when a + * The per-port (or per-app) realize function that's called when a * new device is found on the bus. */ - int (*init)(VirtIOSerialPort *port); + DeviceRealize realize;
include/hw/virtio/virtio-serial.h typedef struct VirtIOSerialPort VirtIOSerialPort; · line 92
Quoted 10 lines
include/hw/virtio/virtio-serial.h +5
-2/* -* Per-port exit function that's called when a port gets +* Per-port unrealize function that's called when a port gets * hot-unplugged or removed. */ -int (*exit)(VirtIOSerialPort *port); +DeviceUnrealize unrealize; + +/* Is this a device that binds with hvc in the guest? */ +bool is_console;
is_console is moved unnecessarily?
Amit
Re: [Qemu-devel] [PATCH v3 2/2] virtio-serial-port: Convert to QOM realize/unrealize
Hi Amit,
Am 12.03.2014 13:41, schrieb Amit Shah:
Quoted 14 lines
Hi,
I haven't really followed the whole discussion, so can't say much about it -- overall looks alright. A couple of minor nits:
hw/char/virtio-serial-bus.c static int virtser_port_qdev_init(DeviceState *qdev) · line 855
Quoted 8 lines
max_nr_ports = tswap32(port->vser->config.max_nr_ports); if (port->id >= max_nr_ports) {hw/char/virtio-serial-bus.c +3
-3-error_report ("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u" , - max_nr_ports -1 ); -return -1 ; +error_setg (errp,"virtio-serial-bus: Out-of-range port id specified, " +"max. allowed: %u" , + max_nr_ports -1 );
Quoted 1 line
indentation looks off. Just put this last line on the line above?
Done. (Was intentional to align error string, but no need to keep on separate lines after breaking.)
Quoted 23 lines
Quoted 23 lines
include/hw/virtio/virtio-serial.h +3
-6@@ -77,19 +77,19 @@ typedef struct VirtIOSerialPort VirtIOSerialPort; typedef struct VirtIOSerialPortClass { DeviceClass parent_class; - /* Is this a device that binds with hvc in the guest? */ - bool is_console; - /* - * The per-port (or per-app) init function that's called when a + * The per-port (or per-app) realize function that's called when a * new device is found on the bus. */ - int (*init)(VirtIOSerialPort *port); + DeviceRealize realize; /* - * Per-port exit function that's called when a port gets + * Per-port unrealize function that's called when a port gets * hot-unplugged or removed.
Quoted 8 lines
include/hw/virtio/virtio-serial.h typedef struct VirtIOSerialPort VirtIOSerialPort; · line 92
Quoted 6 lines
include/hw/virtio/virtio-serial.h +4
-1*/ -int (*exit)(VirtIOSerialPort *port); +DeviceUnrealize unrealize; + +/* Is this a device that binds with hvc in the guest? */ +bool is_console;
is_consoleis moved unnecessarily?
Fixed. (Previously fields parent_realize were added right after parent_obj.)
Thanks,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg