lguest: debugging patch to dump device state
---
 Documentation/lguest/lguest.c |   35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff -r c6288717b728 Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c	Tue Aug 26 09:46:36 2008 +1000
+++ b/Documentation/lguest/lguest.c	Tue Aug 26 09:46:59 2008 +1000
@@ -818,6 +818,29 @@ static u16 timeout_nums[1000];
 static u16 timeout_nums[1000];
 static int timeout_num_idx;
 
+static void dump_devices(void)
+{
+	struct device *i;
+	struct virtqueue *vq;
+
+	/* Check each virtqueue. */
+	for (i = devices.dev; i; i = i->next) {
+		printf("Device %s:\n", i->name);
+		for (vq = i->vq; vq; vq = vq->next) {
+			printf("  Virtqueue %p:\n", vq);
+			printf("   num = %u\n", vq->vring.num);
+			printf("   avail: flags=%u idx=%u (last=%u)\n",
+			       vq->vring.avail->flags,
+			       vq->vring.avail->idx,
+			       vring_last_avail(&vq->vring));
+			printf("   used: flags=%u idx=%u (last=%u)\n",
+			       vq->vring.used->flags,
+			       vq->vring.used->idx,
+			       vring_last_used(&vq->vring));
+		}
+	}
+}
+
 /* This is the routine which handles console input (ie. stdin). */
 static bool handle_console_input(int fd, struct device *dev)
 {
@@ -861,9 +884,10 @@ static bool handle_console_input(int fd,
 	 * in a buffer by itself, so they can't be too fast.  But we check that
 	 * we get three within about a second, so they can't be too slow. */
 	if (len == 1 && ((char *)iov[0].iov_base)[0] == 3) {
-		if (!abort->count++)
+		if (!abort->count++) {
 			gettimeofday(&abort->start, NULL);
-		else if (abort->count == 3) {
+			dump_devices();
+		} else if (abort->count == 3) {
 			struct timeval now;
 			gettimeofday(&now, NULL);
 			if (now.tv_sec <= abort->start.tv_sec+1) {
@@ -874,6 +898,7 @@ static bool handle_console_input(int fd,
 				/* Just in case Waker is blocked in BREAK, send
 				 * unbreak now. */
 				write(fd, args, sizeof(args));
+				dump_devices();
 				printf("network xmit %u recv %u timeout %u usec %u last_timeout_num %u\n",
 				       net_xmit_notify, net_recv_notify,
 				       net_timeout, timeout_usec, last_timeout_num);
@@ -891,10 +916,14 @@ static bool handle_console_input(int fd,
 				exit(2);
 			}
 			abort->count = 0;
-		}
+		} else if (abort->count == 2)
+			dump_devices();	
 	} else
 		/* Any other key resets the abort counter. */
 		abort->count = 0;
+
+	if (len == 1 && ((char *)iov[0].iov_base)[0] == 2)
+		dump_devices();
 
 	/* Everything went OK! */
 	return true;
