From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: amit.shah@redhat.com
Subject: [Qemu-devel] [PATCH 4/5] virtio-serial: Drop redundant VirtIOSerialPort member info
Date: Wed, 25 May 2011 14:21:13 +0200 [thread overview]
Message-ID: <1306326074-22737-5-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1306326074-22737-1-git-send-email-armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/virtio-console.c | 9 ++++++---
hw/virtio-serial-bus.c | 42 ++++++++++++++++++++++++++----------------
hw/virtio-serial.h | 1 -
3 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 180ac0a..713f6ef 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -76,12 +76,15 @@ static void chr_event(void *opaque, int event)
static int generic_port_init(VirtConsole *vcon, VirtIOSerialPort *port)
{
+ VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
+ vcon->port.dev.info);
+
if (vcon->chr) {
qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
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 d0a4ade..e85315d 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -129,9 +129,13 @@ static void discard_vq_data(VirtQueue *vq, VirtIODevice *vdev)
static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
VirtIODevice *vdev)
{
+ VirtIOSerialPortInfo *info;
+
assert(port);
assert(virtio_queue_ready(vq));
+ info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+
while (!port->throttled) {
unsigned int i;
@@ -149,10 +153,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();
@@ -303,6 +307,7 @@ void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle)
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;
@@ -321,6 +326,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) {
@@ -350,7 +357,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);
}
@@ -379,21 +386,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;
}
@@ -442,11 +449,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;
}
@@ -749,7 +758,6 @@ static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
return -1;
}
- port->info = info;
ret = info->init(port);
if (ret) {
return ret;
@@ -780,15 +788,17 @@ 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;
remove_port(port->vser, port->id);
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 acf049d..f267404 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -75,7 +75,6 @@ typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
*/
struct VirtIOSerialPort {
DeviceState dev;
- VirtIOSerialPortInfo *info;
QTAILQ_ENTRY(VirtIOSerialPort) next;
--
1.7.2.3
next prev parent reply other threads:[~2011-05-25 15:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-25 12:21 [Qemu-devel] [PATCH 0/5] virtio-serial: Fixes and cleanups Markus Armbruster
2011-05-25 12:21 ` [Qemu-devel] [PATCH 1/5] virtio-serial: Plug memory leak on qdev exit() Markus Armbruster
2011-05-25 12:21 ` [Qemu-devel] [PATCH 2/5] virtio-serial: Clean up virtconsole detection Markus Armbruster
2011-05-25 12:21 ` [Qemu-devel] [PATCH 3/5] virtio-serial: Drop useless property is_console Markus Armbruster
2011-05-25 12:21 ` Markus Armbruster [this message]
2011-05-25 12:21 ` [Qemu-devel] [PATCH 5/5] virtio-console: Simplify init callbacks Markus Armbruster
2011-05-25 12:29 ` [Qemu-devel] [PATCH 0/5] virtio-serial: Fixes and cleanups Amit Shah
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=1306326074-22737-5-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=amit.shah@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).