From 0d90cc2b7aaf75d7d17f4e3fdafc28137a6b8b3c Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Thu, 22 Dec 2011 05:01:57 +0100
Subject: [PATCH 05/10] virtio-serial: Drop redundant VirtIOSerialPort member
 info

RH-Author: Amit Shah <amit.shah@redhat.com>
Message-id: <3e826fe0a642c4c3fd1d9800f5d672ee855cc811.1324529974.git.amit.shah@redhat.com>
Patchwork-id: 35923
O-Subject: [RHEL6.3 qemu-kvm PATCH 05/10] virtio-serial: Drop redundant VirtIOSerialPort member info
Bugzilla: 769528
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
(cherry picked from commit a15bb0d6a981de749452a5180fc8084d625671da)

Conflicts:

	hw/virtio-console.c
	hw/virtio-serial-bus.c
	(Conflicts due to non-upstream flow control patches)
---
 hw/virtio-console.c    |    8 +++++---
 hw/virtio-serial-bus.c |   45 ++++++++++++++++++++++++++++-----------------
 hw/virtio-serial.h     |    1 -
 3 files changed, 33 insertions(+), 21 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/virtio-console.c    |    8 +++++---
 hw/virtio-serial-bus.c |   45 ++++++++++++++++++++++++++++-----------------
 hw/virtio-serial.h     |    1 -
 3 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index ebf4f90..f3954c4 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -116,6 +116,8 @@ static const QemuChrHandlers chr_handlers_no_flow_control = {
 static int generic_port_init(VirtConsole *vcon, VirtIOSerialPort *port)
 {
     static const QemuChrHandlers *handlers;
+    VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
+                                           vcon->port.dev.info);
 
     if (vcon->chr) {
         handlers = &chr_handlers;
@@ -123,9 +125,9 @@ static int generic_port_init(VirtConsole *vcon, VirtIOSerialPort *port)
             handlers = &chr_handlers_no_flow_control;
         }
         qemu_chr_add_handlers(vcon->chr, handlers, vcon);
-        vcon->port.info->have_data = flush_buf;
-        vcon->port.info->guest_open = guest_open;
-        vcon->port.info->guest_close = guest_close;
+        info->have_data = flush_buf;
+        info->guest_open = guest_open;
+        info->guest_close = guest_close;
     }
     return 0;
 }
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index cda92f3..7ab6011 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -133,7 +133,9 @@ static void do_flush_queued_data_no_flow_control(VirtIOSerialPort *port,
                                                  VirtIODevice *vdev)
 {
     VirtQueueElement elem;
+    VirtIOSerialPortInfo *info;
 
+    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
     while (!port->throttled && virtqueue_pop(vq, &elem)) {
         uint8_t *buf;
         size_t ret, buf_size;
@@ -149,7 +151,7 @@ static void do_flush_queued_data_no_flow_control(VirtIOSerialPort *port,
          * it here.  virtio-console.c has been suitably updated to not
          * do any flow control, and just use the rhel6.0 behaviour.
          */
-        port->info->have_data(port, buf, ret);
+        info->have_data(port, buf, ret);
         qemu_free(buf);
 
         virtqueue_push(vq, &elem, 0);
@@ -160,6 +162,8 @@ static void do_flush_queued_data_no_flow_control(VirtIOSerialPort *port,
 static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
                                  VirtIODevice *vdev)
 {
+    VirtIOSerialPortInfo *info;
+
     assert(port);
     assert(virtio_queue_ready(vq));
 
@@ -167,6 +171,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
         do_flush_queued_data_no_flow_control(port, vq, vdev);
         return;
     }
+    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
 
     while (!port->throttled) {
         unsigned int i;
@@ -185,10 +190,10 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
             ssize_t ret;
 
             buf_size = port->elem.out_sg[i].iov_len - port->iov_offset;
-            ret = port->info->have_data(port,
-                                        port->elem.out_sg[i].iov_base
-                                          + port->iov_offset,
-                                        buf_size);
+            ret = info->have_data(port,
+                                  port->elem.out_sg[i].iov_base
+                                  + port->iov_offset,
+                                  buf_size);
             if (ret < 0 && ret != -EAGAIN) {
                 /* We don't handle any other type of errors here */
                 abort();
@@ -354,6 +359,7 @@ bool virtio_serial_flow_control_enabled(VirtIOSerialPort *port)
 static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
 {
     struct VirtIOSerialPort *port;
+    struct VirtIOSerialPortInfo *info;
     struct virtio_console_control cpkt, *gcpkt;
     uint8_t *buffer;
     size_t buffer_len;
@@ -372,6 +378,8 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
     if (!port && cpkt.event != VIRTIO_CONSOLE_DEVICE_READY)
         return;
 
+    info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+
     switch(cpkt.event) {
     case VIRTIO_CONSOLE_DEVICE_READY:
         if (!cpkt.value) {
@@ -401,7 +409,7 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
          * this port is a console port so that the guest can hook it
          * up to hvc.
          */
-        if (port->info->is_console) {
+        if (info->is_console) {
             send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1);
         }
 
@@ -430,21 +438,21 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
          * initialised. If some app is interested in knowing about
          * this event, let it know.
          */
-        if (port->info->guest_ready) {
-            port->info->guest_ready(port);
+        if (info->guest_ready) {
+            info->guest_ready(port);
         }
         break;
 
     case VIRTIO_CONSOLE_PORT_OPEN:
         port->guest_connected = cpkt.value;
-        if (cpkt.value && port->info->guest_open) {
+        if (cpkt.value && info->guest_open) {
             /* Send the guest opened notification if an app is interested */
-            port->info->guest_open(port);
+            info->guest_open(port);
         }
 
-        if (!cpkt.value && port->info->guest_close) {
+        if (!cpkt.value && info->guest_close) {
             /* Send the guest closed notification if an app is interested */
-            port->info->guest_close(port);
+            info->guest_close(port);
         }
         break;
     }
@@ -493,11 +501,13 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOSerial *vser;
     VirtIOSerialPort *port;
+    VirtIOSerialPortInfo *info;
 
     vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
     port = find_port_by_vq(vser, vq);
+    info = port ? DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info) : NULL;
 
-    if (!port || !port->host_connected || !port->info->have_data) {
+    if (!port || !port->host_connected || !info->have_data) {
         discard_vq_data(vq, vdev);
         return;
     }
@@ -813,7 +823,6 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
         return -1;
     }
 
-    port->info = info;
     ret = info->init(port);
     if (ret) {
         return ret;
@@ -844,6 +853,8 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
 static int virtser_port_qdev_exit(DeviceState *qdev)
 {
     VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
+    VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
+                                           port->dev.info);
     VirtIOSerial *vser = port->vser;
 
     qemu_bh_delete(port->bh);
@@ -851,9 +862,9 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
 
     QTAILQ_REMOVE(&vser->ports, port, next);
 
-    if (port->info->exit)
-        port->info->exit(port);
-
+    if (info->exit) {
+        info->exit(port);
+    }
     return 0;
 }
 
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index d6fab00..7aba755 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -82,7 +82,6 @@ typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
  */
 struct VirtIOSerialPort {
     DeviceState dev;
-    VirtIOSerialPortInfo *info;
 
     QTAILQ_ENTRY(VirtIOSerialPort) next;
 
-- 
1.7.7.4

