qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Amit Shah" <amit.shah@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Anthony Liguori" <aliguori@amazon.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PULL for-2.0-rc0 26/31] virtio-serial-port: Convert to QOM realize/unrealize
Date: Wed, 12 Mar 2014 22:09:58 +0100	[thread overview]
Message-ID: <1394658603-13650-27-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1394658603-13650-1-git-send-email-afaerber@suse.de>

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/char/virtio-console.c          | 28 ++++++++++-----------
 hw/char/virtio-serial-bus.c       | 51 ++++++++++++++++++++-------------------
 include/hw/virtio/virtio-serial.h |  8 +++---
 3 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index 73e18f2..ffd29a8 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -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;
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 226e9f9..2b647b6 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -808,13 +808,14 @@ 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;
+    Error *err = NULL;
 
     port->vser = bus->vser;
     port->bh = qemu_bh_new(flush_queued_data_bh, port);
@@ -829,9 +830,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 +841,24 @@ 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;
+        error_setg(errp, "virtio-serial-bus: Out-of-range port id specified, "
+                         "max. allowed: %u", max_nr_ports - 1);
+        return;
     }
 
-    ret = vsc->init(port);
-    if (ret) {
-        return ret;
+    vsc->realize(dev, &err);
+    if (err != NULL) {
+        error_propagate(errp, err);
+        return;
     }
 
     port->elem.out_num = 0;
@@ -868,14 +871,12 @@ 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);
+    VirtIOSerialPortClass *vsc = VIRTIO_SERIAL_PORT_GET_CLASS(dev);
     VirtIOSerial *vser = port->vser;
 
     qemu_bh_delete(port->bh);
@@ -883,10 +884,9 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
 
     QTAILQ_REMOVE(&vser->ports, port, next);
 
-    if (vsc->exit) {
-        vsc->exit(port);
+    if (vsc->unrealize) {
+        vsc->unrealize(dev, errp);
     }
-    return 0;
 }
 
 static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
@@ -971,10 +971,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 1d2040b..4746312 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -81,15 +81,15 @@ typedef struct VirtIOSerialPortClass {
     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;
 
     /* Callbacks for guest events */
         /* Guest opened/closed device. */
-- 
1.8.4.5

  parent reply	other threads:[~2014-03-12 21:10 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-12 21:09 [Qemu-devel] [PULL for-2.0-rc0 00/31] QOM devices patch queue 2014-03-12 Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 01/31] qdev: Fix bus dependency of DeviceState::hotpluggable getter Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 02/31] qdev: Set DeviceClass::hotpluggable default in class_init() Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 03/31] qdev-monitor: Set properties after parent is assigned in device_add Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 04/31] qom: Avoid leaking str and bool properties on failure Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 05/31] ssi: Convert legacy SSI_SLAVE -> DEVICE casts Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 06/31] ssi: Convert legacy SSI_BUS -> BUS casts Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 07/31] misc/max111x: Create abstract max111x type Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 08/31] misc/max111x: QOM casting sweep Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 09/31] ssi: Remove SSI_SLAVE_FROM_QDEV() macro Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 10/31] block/m25p80: Remove FROM_SSI_SLAVE() usages Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 11/31] spapr-pci: Change the default PCI bus naming Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 12/31] qdev-monitor-test: Simplify using g_assert_cmpstr() Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 13/31] qdev-monitor-test: Don't test human-readable error message Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 14/31] hw/core: Introduce QEMU machine as QOM object Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 15/31] vl: Use MachineClass instead of global QEMUMachine list Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 16/31] hw/boards: Convert current_machine to MachineState Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 17/31] qom-test: Test QOM properties Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 18/31] tests: Clean up IndustryPack TPCI200 gcov paths Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 19/31] tests: Add virtio-blk qtest Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 20/31] tests: Add virtio-balloon qtest Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 21/31] tests: Add virtio-rng qtest Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 22/31] tests: Add virtio-scsi qtest Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 23/31] tests: Add virtio-serial qtest Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 24/31] tests: Add virtio-console qtest Andreas Färber
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 25/31] virtio-console: QOM cast cleanup for VirtConsole Andreas Färber
2014-03-13 15:32   ` [Qemu-devel] virtio-serial broken in qemu.git (was: Re: [PULL for-2.0-rc0 25/31] virtio-console: QOM cast cleanup for VirtConsole) Richard W.M. Jones
2014-03-13 15:43     ` Richard W.M. Jones
2014-03-12 21:09 ` Andreas Färber [this message]
2014-03-12 21:09 ` [Qemu-devel] [PULL for-2.0-rc0 27/31] tests: Add spapr-pci-host-bridge qtest Andreas Färber
2014-03-12 21:10 ` [Qemu-devel] [PULL for-2.0-rc0 28/31] qdev: Prepare realize/unrealize hooks for BusState Andreas Färber
2014-03-12 21:10 ` [Qemu-devel] [PULL for-2.0-rc0 29/31] qdev: Realize buses on device realization Andreas Färber
2014-03-12 21:10 ` [Qemu-devel] [PULL for-2.0-rc0 30/31] pci: Move VMState registration/unregistration to QOM realize/unrealize Andreas Färber
2014-03-12 21:10 ` [Qemu-devel] [PULL for-2.0-rc0 31/31] libqtest: Fix possible deadlock in qtest initialization Andreas Färber
2014-03-12 22:42 ` [Qemu-devel] [PULL for-2.0-rc0 00/31] QOM devices patch queue 2014-03-12 Peter Maydell
2014-03-13  0:19   ` Andreas Färber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394658603-13650-27-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=amit.shah@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).