From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcCeu-000119-3u for qemu-devel@nongnu.org; Thu, 09 Oct 2014 08:17:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcCen-0005fw-SL for qemu-devel@nongnu.org; Thu, 09 Oct 2014 08:17:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcCen-0005fg-M0 for qemu-devel@nongnu.org; Thu, 09 Oct 2014 08:17:21 -0400 Date: Thu, 9 Oct 2014 17:47:14 +0530 From: Amit Shah Message-ID: <20141009121714.GA22195@grmbl.mre> References: <87fvexfq4n.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87fvexfq4n.fsf@blackfin.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH v2 1/1] virtio: serial: expose a 'guest_writable' callback for users List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Peter Maydell , Amos Kong , qemu list On (Thu) 09 Oct 2014 [13:18:16], Markus Armbruster wrote: > Amit Shah writes: > > > 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. > > > > Signed-off-by: Amit Shah > > > > --- > > v2: check for port != NULL (Peter Maydell) > > --- > > hw/char/virtio-serial-bus.c | 27 +++++++++++++++++++++++++++ > > include/hw/virtio/virtio-serial.h | 3 +++ > > 2 files changed, 30 insertions(+) > > > > diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c > > index 3931085..1c7acbf 100644 > > --- a/hw/char/virtio-serial-bus.c > > +++ b/hw/char/virtio-serial-bus.c > > @@ -465,6 +465,33 @@ 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 (!port) { > > + return; > > + } > > + vsc = VIRTIO_SERIAL_PORT_GET_CLASS(port); > > + > > + /* > > + * If guest_connected is false, this call is being made by the > > + * early-boot queueing up of descriptors, which is just noise for > > + * the host apps -- don't disturb them in that case. > > + */ > > + if (port->guest_connected && port->host_connected && 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 a679e54..b434f78 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 > > The code should work, but whether it makes sense is hard to judge for > virtio noobs like me without a user of guest_writable. The conditional > guarding vsc->guest_writable(port) in particular. Right. This was originally requested by the spice folks, and they don't yet have a user implemented (waiting for the spice-char implementation). But Peter came up with a user; so I posted this w/o the spice part of it. But looks like Peter has lost the code for his user, so this patch will have to wait ;-) > virtio_add_queue()'s callback being undocumented doesn't exactly help, > either. Fun: the parameter is called handle_output, the argument is > handle_input. Clear as mud! Yea - some things in virtio are from the guest's POV so it makes these things really confusing in qemu. Amit