diff options
authorAmit Shah <amit.shah@redhat.com>2014-07-17 20:02:45 +0530
committerPeter Maydell <peter.maydell@linaro.org>2014-09-16 22:46:12 +0100
commitc02f327dc9fedaf6276c43c3d582d57f697a188e (patch)
parent1afdbfbd02ee8f6ff0123eee4313db49a27cf793 (diff)
virtio: serial: expose a 'guest_writable' callback for users
Users of virtio-serial may want to know when a port becomes writable. A port can stop accepting writes if the guest port is open but not being read from. In this case, data gets queued up in the virtqueue, and after the vq is full, writes to the port do not succeed. When the guest reads off a vq element, and adds a new one for the host to put data in, we can tell users the port is available for more writes, via the new ->guest_writable() callback. Requested-by: Alon Levy <alevy@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com>
2 files changed, 21 insertions, 0 deletions
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 2b647b68d5..721e964f96 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -442,6 +442,24 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
+ /*
+ * Users of virtio-serial would like to know when guest becomes
+ * writable again -- i.e. if a vq had stuff queued up and the
+ * guest wasn't reading at all, the host would not be able to
+ * write to the vq anymore. Once the guest reads off something,
+ * we can start queueing things up again.
+ */
+ VirtIOSerial *vser;
+ VirtIOSerialPort *port;
+ VirtIOSerialPortClass *vsc;
+ vser = VIRTIO_SERIAL(vdev);
+ port = find_port_by_vq(vser, vq);
+ if (vsc->guest_writable) {
+ vsc->guest_writable(port);
+ }
static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index 4746312a83..3fd696b89b 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -98,6 +98,9 @@ typedef struct VirtIOSerialPortClass {
/* Guest is now ready to accept data (virtqueues set up). */
void (*guest_ready)(VirtIOSerialPort *port);
+ /* Guest vq became writable again */
+ void (*guest_writable)(VirtIOSerialPort *port);
* Guest wrote some data to the port. This data is handed over to
* the app via this callback. The app can return a size less than