Subject: lguest: Use virtio_net_info pointers rather than dev->vq
Date: Fri, 13 Jun 2008 14:27:35 +0100
From: Mark McLoughlin <markmc@redhat.com>

virtio_net_info contains pointers to the recv and xmit
virtqueues, so use them instead of assuming where they
appear in the dev->vq list.

(Against lguest:use-tun-ringfd.patch)

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 Documentation/lguest/lguest.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
index d04bb9c..fb358bb 100644
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -909,14 +909,15 @@ static void handle_netring_output(int fd, struct virtqueue *vq)
  * Guest. */
 static bool handle_tun_input(int fd, struct device *dev)
 {
+	struct virtio_net_info *ni = dev->priv;
 	unsigned int head, in_num, out_num;
 	int len;
-	struct iovec iov[dev->vq->vring.num];
+	struct iovec iov[ni->recv_vq->vring.num];
 	struct virtio_net_hdr *hdr;
 
 	/* First we need a network buffer from the Guests's recv virtqueue. */
-	head = get_vq_desc(dev->vq, iov, &out_num, &in_num);
-	if (head == dev->vq->vring.num) {
+	head = get_vq_desc(ni->recv_vq, iov, &out_num, &in_num);
+	if (head == ni->recv_vq->vring.num) {
 		/* Now, it's expected that if we try to send a packet too
 		 * early, the Guest won't be ready yet.  Wait until the device
 		 * status says it's ready. */
@@ -939,11 +940,11 @@ static bool handle_tun_input(int fd, struct device *dev)
 		err(1, "reading network");
 
 	/* Tell the Guest about the new packet. */
-	add_used_and_trigger(fd, dev->vq, head, sizeof(*hdr) + len);
+	add_used_and_trigger(fd, ni->recv_vq, head, sizeof(*hdr) + len);
 
 	verbose("tun input packet len %i [%02x %02x] (%s)\n", len,
 		((u8 *)iov[1].iov_base)[0], ((u8 *)iov[1].iov_base)[1],
-		head != dev->vq->vring.num ? "sent" : "discarded");
+		head != ni->recv_vq->vring.num ? "sent" : "discarded");
 
 	/* All good. */
 	return true;
@@ -1461,8 +1462,8 @@ static void setup_tun_net(const char *arg, bool rings)
 
 	if (rings) {
 		/* Now we create the receive and xmit ringfds. */
-		ni->recvfd = map_vring(&dev->vq->vring);
-		ni->xmitfd = map_vring(&dev->vq->next->vring);
+		ni->recvfd = map_vring(&ni->recv_vq->vring);
+		ni->xmitfd = map_vring(&ni->xmit_vq->vring);
 
 		/* Tell the tunnet to use them. */
 		if (ioctl(netfd, TUNSETRECVVRING, ni->recvfd) != 0)
