qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-next v2 0/2] QOM realize for virtio-console
@ 2013-08-01  2:35 Andreas Färber
  2013-08-01  2:35 ` [Qemu-devel] [PATCH for-next v2 1/2] virtio-console: QOM cast cleanup for VirtConsole Andreas Färber
  2013-08-01  2:35 ` [Qemu-devel] [PATCH for-next v2 2/2] virtio-serial-port: Convert to QOM realize/unrealize Andreas Färber
  0 siblings, 2 replies; 3+ messages in thread
From: Andreas Färber @ 2013-08-01  2:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S. Tsirkin, Hu Tao, Anthony Liguori, Paolo Bonzini,
	Andreas Färber, Frederic Konrad

Hello,

This series converts VirtIOSerialPort to QOM realize/unrealize.

As a side-effect, virtio-console realization is changed from in-order to pre-order.

v2 splits off cleanups, requested by mst.

Available from:
https://github.com/afaerber/qemu-cpu/commits/realize-virtio-console.v2
git://github.com/afaerber/qemu-cpu.git realize-virtio-console.v2

Regards,
Andreas

v1 -> v2:
* Split off virtserialport fix for 1.6.
* Split off from main virtio realization series.
* Split out cleanups (mst).

Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Frederic Konrad <fred.konrad@greensocs.com>
Cc: Hu Tao <hutao@cn.fujitsu.com>

Andreas Färber (2):
  virtio-console: QOM cast cleanup for VirtConsole
  virtio-serial-port: Convert to QOM realize/unrealize

 hw/char/virtio-console.c          | 70 +++++++++++++++++++++++++--------------
 hw/char/virtio-serial-bus.c       | 48 +++++++++++----------------
 include/hw/virtio/virtio-serial.h | 11 ------
 3 files changed, 64 insertions(+), 65 deletions(-)

-- 
1.8.1.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH for-next v2 1/2] virtio-console: QOM cast cleanup for VirtConsole
  2013-08-01  2:35 [Qemu-devel] [PATCH for-next v2 0/2] QOM realize for virtio-console Andreas Färber
@ 2013-08-01  2:35 ` Andreas Färber
  2013-08-01  2:35 ` [Qemu-devel] [PATCH for-next v2 2/2] virtio-serial-port: Convert to QOM realize/unrealize Andreas Färber
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2013-08-01  2:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Amit Shah, Anthony Liguori, Andreas Färber

Introduce type constant, cast macro and rename parent field.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/char/virtio-console.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index 2e00ad2..73e18f2 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -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,
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH for-next v2 2/2] virtio-serial-port: Convert to QOM realize/unrealize
  2013-08-01  2:35 [Qemu-devel] [PATCH for-next v2 0/2] QOM realize for virtio-console Andreas Färber
  2013-08-01  2:35 ` [Qemu-devel] [PATCH for-next v2 1/2] virtio-console: QOM cast cleanup for VirtConsole Andreas Färber
@ 2013-08-01  2:35 ` Andreas Färber
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Färber @ 2013-08-01  2:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Amit Shah, Anthony Liguori, Andreas Färber

Note: virtconsole's/virtserialport's realizefn now registers its
handlers before VirtIOSerialPort's realizefn.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/char/virtio-console.c          | 41 +++++++++++++++++++++------------
 hw/char/virtio-serial-bus.c       | 48 ++++++++++++++++-----------------------
 include/hw/virtio/virtio-serial.h | 11 ---------
 3 files changed, 46 insertions(+), 54 deletions(-)

diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index 73e18f2..159dff4 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -18,6 +18,8 @@
 #define TYPE_VIRTIO_CONSOLE "virtconsole"
 #define VIRTIO_CONSOLE(obj) \
     OBJECT_CHECK(VirtConsole, (obj), TYPE_VIRTIO_CONSOLE)
+#define VIRTIO_CONSOLE_GET_PARENT_CLASS(obj) \
+    OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_CONSOLE)
 
 typedef struct VirtConsole {
     VirtIOSerialPort parent_obj;
@@ -126,14 +128,18 @@ 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);
+    ObjectClass *parent_oc = VIRTIO_CONSOLE_GET_PARENT_CLASS(dev);
+    DeviceClass *parent_dc = DEVICE_CLASS(parent_oc);
 
     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) {
@@ -142,18 +148,25 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
                               vcon);
     }
 
-    return 0;
+    parent_dc->realize(dev, errp);
 }
 
-static int virtconsole_exitfn(VirtIOSerialPort *port)
+static void virtconsole_unrealize(DeviceState *dev, Error **errp)
 {
-    VirtConsole *vcon = VIRTIO_CONSOLE(port);
+    VirtConsole *vcon = VIRTIO_CONSOLE(dev);
+    ObjectClass *parent_oc = VIRTIO_CONSOLE_GET_PARENT_CLASS(dev);
+    DeviceClass *parent_dc = DEVICE_CLASS(parent_oc);
+    Error *err = NULL;
+
+    parent_dc->unrealize(dev, &err);
+    if (err != NULL) {
+        error_propagate(errp, err);
+        return;
+    }
 
     if (vcon->watch) {
         g_source_remove(vcon->watch);
     }
-
-    return 0;
 }
 
 static Property virtconsole_properties[] = {
@@ -167,10 +180,10 @@ 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->have_data = flush_buf;
     k->set_guest_connected = set_guest_connected;
+    dc->realize = virtconsole_realize;
+    dc->unrealize = virtconsole_unrealize;
     dc->props = virtconsole_properties;
 }
 
@@ -191,10 +204,10 @@ 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->have_data = flush_buf;
     k->set_guest_connected = set_guest_connected;
+    dc->realize = virtconsole_realize;
+    dc->unrealize = virtconsole_unrealize;
     dc->props = virtserialport_properties;
 }
 
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index ba221bf..87b2d4d 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -808,12 +808,12 @@ static void remove_port(VirtIOSerial *vser, uint32_t port_id)
     send_control_event(vser, port->id, VIRTIO_CONSOLE_PORT_REMOVE, 1);
 }
 
-static int virtser_port_qdev_init(DeviceState *qdev)
+static void virtser_port_device_realize(DeviceState *dev, Error **errp)
 {
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
+    VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev);
     VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
-    VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus);
-    int ret, max_nr_ports;
+    VirtIOSerialBus *bus = VIRTIO_SERIAL_BUS(qdev_get_parent_bus(dev));
+    int max_nr_ports;
     bool plugging_port0;
 
     port->vser = bus->vser;
@@ -829,9 +829,9 @@ static int virtser_port_qdev_init(DeviceState *qdev)
     plugging_port0 = vsc->is_console && !find_port_by_id(port->vser, 0);
 
     if (find_port_by_id(port->vser, port->id)) {
-        error_report("virtio-serial-bus: A port already exists at id %u",
-                     port->id);
-        return -1;
+        error_setg(errp, "virtio-serial-bus: A port already exists at id %u",
+                   port->id);
+        return;
     }
 
     if (port->id == VIRTIO_CONSOLE_BAD_ID) {
@@ -840,22 +840,19 @@ static int virtser_port_qdev_init(DeviceState *qdev)
         } else {
             port->id = find_free_port_id(port->vser);
             if (port->id == VIRTIO_CONSOLE_BAD_ID) {
-                error_report("virtio-serial-bus: Maximum port limit for this device reached");
-                return -1;
+                error_setg(errp, "virtio-serial-bus: Maximum port limit for "
+                                 "this device reached");
+                return;
             }
         }
     }
 
     max_nr_ports = tswap32(port->vser->config.max_nr_ports);
     if (port->id >= max_nr_ports) {
-        error_report("virtio-serial-bus: Out-of-range port id specified, max. allowed: %u",
-                     max_nr_ports - 1);
-        return -1;
-    }
-
-    ret = vsc->init(port);
-    if (ret) {
-        return ret;
+        error_setg(errp, "virtio-serial-bus: Out-of-range port id specified, "
+                         "max. allowed: %u",
+                   max_nr_ports - 1);
+        return;
     }
 
     port->elem.out_num = 0;
@@ -868,25 +865,17 @@ static int virtser_port_qdev_init(DeviceState *qdev)
 
     /* Send an update to the guest about this new port added */
     virtio_notify_config(VIRTIO_DEVICE(port->vser));
-
-    return ret;
 }
 
-static int virtser_port_qdev_exit(DeviceState *qdev)
+static void virtser_port_device_unrealize(DeviceState *dev, Error **errp)
 {
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
-    VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port);
+    VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(dev);
     VirtIOSerial *vser = port->vser;
 
     qemu_bh_delete(port->bh);
     remove_port(port->vser, port->id);
 
     QTAILQ_REMOVE(&vser->ports, port, next);
-
-    if (vsc->exit) {
-        vsc->exit(port);
-    }
-    return 0;
 }
 
 static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
@@ -975,10 +964,11 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
 static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
-    k->init = virtser_port_qdev_init;
+
     set_bit(DEVICE_CATEGORY_INPUT, k->categories);
     k->bus_type = TYPE_VIRTIO_SERIAL_BUS;
-    k->exit = virtser_port_qdev_exit;
+    k->realize = virtser_port_device_realize;
+    k->unrealize = virtser_port_device_unrealize;
     k->unplug = qdev_simple_unplug_cb;
     k->props = virtser_props;
 }
diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index 9a94abd..75d4c59 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -80,17 +80,6 @@ typedef struct VirtIOSerialPortClass {
     /* 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
-     * new device is found on the bus.
-     */
-    int (*init)(VirtIOSerialPort *port);
-    /*
-     * Per-port exit function that's called when a port gets
-     * hot-unplugged or removed.
-     */
-    int (*exit)(VirtIOSerialPort *port);
-
     /* Callbacks for guest events */
         /* Guest opened/closed device. */
     void (*set_guest_connected)(VirtIOSerialPort *port, int guest_connected);
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-01  3:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-01  2:35 [Qemu-devel] [PATCH for-next v2 0/2] QOM realize for virtio-console Andreas Färber
2013-08-01  2:35 ` [Qemu-devel] [PATCH for-next v2 1/2] virtio-console: QOM cast cleanup for VirtConsole Andreas Färber
2013-08-01  2:35 ` [Qemu-devel] [PATCH for-next v2 2/2] virtio-serial-port: Convert to QOM realize/unrealize Andreas Färber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).