From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4k0T-00086U-Ju for qemu-devel@nongnu.org; Wed, 31 Jul 2013 23:56:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V4ijn-0002ht-4t for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:35:40 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33335 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V4ijm-0002hK-G5 for qemu-devel@nongnu.org; Wed, 31 Jul 2013 22:35:34 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 1 Aug 2013 04:35:23 +0200 Message-Id: <1375324524-3353-3-git-send-email-afaerber@suse.de> In-Reply-To: <1375324524-3353-1-git-send-email-afaerber@suse.de> References: <1375324524-3353-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH for-next v2 2/2] virtio-serial-port: Convert to QOM realize/unrealize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Amit Shah , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= Note: virtconsole's/virtserialport's realizefn now registers its handlers before VirtIOSerialPort's realizefn. Signed-off-by: Andreas F=C3=A4rber --- 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) =20 typedef struct VirtConsole { VirtIOSerialPort parent_obj; @@ -126,14 +128,18 @@ static void chr_event(void *opaque, int event) } } =20 -static int virtconsole_initfn(VirtIOSerialPort *port) +static void virtconsole_realize(DeviceState *dev, Error **errp) { - VirtConsole *vcon =3D VIRTIO_CONSOLE(port); - VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); + VirtIOSerialPort *port =3D VIRTIO_SERIAL_PORT(dev); + VirtConsole *vcon =3D VIRTIO_CONSOLE(dev); + VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_GET_CLASS(dev); + ObjectClass *parent_oc =3D VIRTIO_CONSOLE_GET_PARENT_CLASS(dev); + DeviceClass *parent_dc =3D DEVICE_CLASS(parent_oc); =20 if (port->id =3D=3D 0 && !k->is_console) { - error_report("Port number 0 on virtio-serial devices reserved fo= r virtconsole devices for backward compatibility."); - return -1; + error_setg(errp, "Port number 0 on virtio-serial devices reserve= d " + "for virtconsole devices for backward compatibility."= ); + return; } =20 if (vcon->chr) { @@ -142,18 +148,25 @@ static int virtconsole_initfn(VirtIOSerialPort *por= t) vcon); } =20 - return 0; + parent_dc->realize(dev, errp); } =20 -static int virtconsole_exitfn(VirtIOSerialPort *port) +static void virtconsole_unrealize(DeviceState *dev, Error **errp) { - VirtConsole *vcon =3D VIRTIO_CONSOLE(port); + VirtConsole *vcon =3D VIRTIO_CONSOLE(dev); + ObjectClass *parent_oc =3D VIRTIO_CONSOLE_GET_PARENT_CLASS(dev); + DeviceClass *parent_dc =3D DEVICE_CLASS(parent_oc); + Error *err =3D NULL; + + parent_dc->unrealize(dev, &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } =20 if (vcon->watch) { g_source_remove(vcon->watch); } - - return 0; } =20 static Property virtconsole_properties[] =3D { @@ -167,10 +180,10 @@ static void virtconsole_class_init(ObjectClass *kla= ss, void *data) VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_CLASS(klass); =20 k->is_console =3D true; - k->init =3D virtconsole_initfn; - k->exit =3D virtconsole_exitfn; k->have_data =3D flush_buf; k->set_guest_connected =3D set_guest_connected; + dc->realize =3D virtconsole_realize; + dc->unrealize =3D virtconsole_unrealize; dc->props =3D virtconsole_properties; } =20 @@ -191,10 +204,10 @@ static void virtserialport_class_init(ObjectClass *= klass, void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); VirtIOSerialPortClass *k =3D VIRTIO_SERIAL_PORT_CLASS(klass); =20 - k->init =3D virtconsole_initfn; - k->exit =3D virtconsole_exitfn; k->have_data =3D flush_buf; k->set_guest_connected =3D set_guest_connected; + dc->realize =3D virtconsole_realize; + dc->unrealize =3D virtconsole_unrealize; dc->props =3D virtserialport_properties; } =20 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); } =20 -static int virtser_port_qdev_init(DeviceState *qdev) +static void virtser_port_device_realize(DeviceState *dev, Error **errp) { - VirtIOSerialPort *port =3D DO_UPCAST(VirtIOSerialPort, dev, qdev); + VirtIOSerialPort *port =3D VIRTIO_SERIAL_PORT(dev); VirtIOSerialPortClass *vsc =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); - VirtIOSerialBus *bus =3D DO_UPCAST(VirtIOSerialBus, qbus, qdev->pare= nt_bus); - int ret, max_nr_ports; + VirtIOSerialBus *bus =3D VIRTIO_SERIAL_BUS(qdev_get_parent_bus(dev))= ; + int max_nr_ports; bool plugging_port0; =20 port->vser =3D bus->vser; @@ -829,9 +829,9 @@ static int virtser_port_qdev_init(DeviceState *qdev) plugging_port0 =3D vsc->is_console && !find_port_by_id(port->vser, 0= ); =20 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; } =20 if (port->id =3D=3D VIRTIO_CONSOLE_BAD_ID) { @@ -840,22 +840,19 @@ static int virtser_port_qdev_init(DeviceState *qdev= ) } else { port->id =3D find_free_port_id(port->vser); if (port->id =3D=3D 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; } } } =20 max_nr_ports =3D tswap32(port->vser->config.max_nr_ports); if (port->id >=3D max_nr_ports) { - error_report("virtio-serial-bus: Out-of-range port id specified,= max. allowed: %u", - max_nr_ports - 1); - return -1; - } - - ret =3D vsc->init(port); - if (ret) { - return ret; + error_setg(errp, "virtio-serial-bus: Out-of-range port id specif= ied, " + "max. allowed: %u", + max_nr_ports - 1); + return; } =20 port->elem.out_num =3D 0; @@ -868,25 +865,17 @@ static int virtser_port_qdev_init(DeviceState *qdev= ) =20 /* Send an update to the guest about this new port added */ virtio_notify_config(VIRTIO_DEVICE(port->vser)); - - return ret; } =20 -static int virtser_port_qdev_exit(DeviceState *qdev) +static void virtser_port_device_unrealize(DeviceState *dev, Error **errp= ) { - VirtIOSerialPort *port =3D DO_UPCAST(VirtIOSerialPort, dev, qdev); - VirtIOSerialPortClass *vsc =3D VIRTIO_SERIAL_PORT_GET_CLASS(port); + VirtIOSerialPort *port =3D VIRTIO_SERIAL_PORT(dev); VirtIOSerial *vser =3D port->vser; =20 qemu_bh_delete(port->bh); remove_port(port->vser, port->id); =20 QTAILQ_REMOVE(&vser->ports, port, next); - - if (vsc->exit) { - vsc->exit(port); - } - return 0; } =20 static void virtio_serial_device_realize(DeviceState *dev, Error **errp) @@ -975,10 +964,11 @@ static void virtio_serial_device_realize(DeviceStat= e *dev, Error **errp) static void virtio_serial_port_class_init(ObjectClass *klass, void *data= ) { DeviceClass *k =3D DEVICE_CLASS(klass); - k->init =3D virtser_port_qdev_init; + set_bit(DEVICE_CATEGORY_INPUT, k->categories); k->bus_type =3D TYPE_VIRTIO_SERIAL_BUS; - k->exit =3D virtser_port_qdev_exit; + k->realize =3D virtser_port_device_realize; + k->unrealize =3D virtser_port_device_unrealize; k->unplug =3D qdev_simple_unplug_cb; k->props =3D 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; =20 - /* - * 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_connec= ted); --=20 1.8.1.4