From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xj8Xi-0002dX-4e for qemu-devel@nongnu.org; Tue, 28 Oct 2014 11:18:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xj8Xb-0004mm-WB for qemu-devel@nongnu.org; Tue, 28 Oct 2014 11:18:42 -0400 Received: from mx6-phx2.redhat.com ([209.132.183.39]:50419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xj8Xb-0004mZ-PG for qemu-devel@nongnu.org; Tue, 28 Oct 2014 11:18:35 -0400 Date: Tue, 28 Oct 2014 11:18:31 -0400 (EDT) From: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Message-ID: <2016085238.1172569.1414509511699.JavaMail.zimbra@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 1/1] virtio: serial: expose a 'guest_writable' callback for users List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Amit Shah Cc: Peter Maydell , qemu list , Markus Armbruster , Gerd Hoffmann , marcandre lureau , Amos Kong Reviewed-by: Marc-Andr=C3=A9 Lureau I have a somewhat related question, that perhaps someone may help me with: Why isn't the qemu char driver/device interface based (for most devices) on socketpair (and equivalent bi-directional pipe on other OS). It looks to me like it could simplify API and event handling on both fe/be sides, although it may cost a few more open fds and additional copy. ----- Mail original ----- > 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. >=20 > 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. >=20 > Signed-off-by: Amit Shah >=20 > --- > v3: document the semantics of the callback (Peter Maydell, Markus) > v2: check for port !=3D NULL (Peter Maydell) > --- > hw/char/virtio-serial-bus.c | 31 +++++++++++++++++++++++++++++++ > include/hw/virtio/virtio-serial.h | 11 +++++++++++ > 2 files changed, 42 insertions(+) >=20 > diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c > index c6870f1..bea7a17 100644 > --- a/hw/char/virtio-serial-bus.c > +++ b/hw/char/virtio-serial-bus.c > @@ -465,6 +465,37 @@ static void handle_output(VirtIODevice *vdev, VirtQu= eue > *vq) > =20 > 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. However, this call is > + * made for each buffer addition by the guest -- even though free > + * buffers existed prior to the current buffer addition. This is > + * done so as not to maintain previous state, which will need > + * additional live-migration-related changes. > + */ > + VirtIOSerial *vser; > + VirtIOSerialPort *port; > + VirtIOSerialPortClass *vsc; > + > + vser =3D VIRTIO_SERIAL(vdev); > + port =3D find_port_by_vq(vser, vq); > + > + if (!port) { > + return; > + } > + vsc =3D 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); > + } > } > =20 > 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..fe6e696 100644 > --- a/include/hw/virtio/virtio-serial.h > +++ b/include/hw/virtio/virtio-serial.h > @@ -98,6 +98,17 @@ typedef struct VirtIOSerialPortClass { > /* Guest is now ready to accept data (virtqueues set up). */ > void (*guest_ready)(VirtIOSerialPort *port); > =20 > + /* > +=09 * Guest has enqueued a buffer for the host to write into. > +=09 * Called each time a buffer is enqueued by the guest; > +=09 * irrespective of whether there already were free buffers the > +=09 * host could have consumed. > +=09 * > +=09 * This is dependent on both, the guest and host ends being > +=09 * connected. > +=09 */ > + 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 > -- > 1.9.3 >=20 >=20