lguest: publish last_avail_idx.

Set the VIRTIO_RING_F_PUBLISH_INDICES feature on all devices, and use
the last_avail within the vring rather than storing our own.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 Documentation/lguest/lguest.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff -r ef75a80d3284 Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c	Tue Jul 22 18:01:55 2008 +1000
+++ b/Documentation/lguest/lguest.c	Tue Jul 22 18:02:41 2008 +1000
@@ -157,9 +157,6 @@ struct virtqueue
 	/* The actual ring of buffers. */
 	struct vring vring;
 
-	/* Last available index we saw. */
-	u16 last_avail_idx;
-
 	/* The routine to call when the Guest pings us, or timeout. */
 	void (*handle_output)(int fd, struct virtqueue *me, bool timeout);
 
@@ -201,7 +198,7 @@ static void *_convert(struct iovec *iov,
 }
 
 /* Wrapper for the last available index.  Makes it easier to change. */
-#define lg_last_avail(vq)	((vq)->last_avail_idx)
+#define lg_last_avail(vq)	vring_last_avail(&(vq)->vring)
 
 /* The virtio configuration space is defined to be little-endian.  x86 is
  * little-endian too, but it's nice to be explicit so we have these helpers. */
@@ -1237,7 +1234,6 @@ static void add_virtqueue(struct device 
 
 	/* Initialize the virtqueue */
 	vq->next = NULL;
-	vq->last_avail_idx = 0;
 	vq->dev = dev;
 	vq->inflight = 0;
 	vq->blocked = false;
@@ -1295,6 +1291,10 @@ static void add_feature(struct device *d
  * how we use it. */
 static void set_config(struct device *dev, unsigned len, const void *conf)
 {
+	/* We always set the VIRTIO_RING_F_PUBLISH_INDICES feature
+	 * bit, so now is a good time to do that. */
+	add_feature(dev, VIRTIO_RING_F_PUBLISH_INDICES);
+
 	/* Check we haven't overflowed our single page. */
 	if (device_config(dev) + len > devices.descpage + getpagesize())
 		errx(1, "Too many devices");
@@ -1369,6 +1369,8 @@ static void setup_console(void)
 	add_virtqueue(dev, VIRTQUEUE_NUM, enable_fd);
 	add_virtqueue(dev, VIRTQUEUE_NUM, handle_console_output);
 
+	/* Every device should set this bit. */
+	add_feature(dev, VIRTIO_RING_F_PUBLISH_INDICES);
 	verbose("device %u: console\n", devices.device_num++);
 }
 /*:*/
