lguest: add finalize_device() to neaten example launcher

Centralize verbose printing of device names, and also give us a place
to add features to all devices without patching all the setup functions.

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

diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -37,6 +37,7 @@
 #include <limits.h>
 #include <stddef.h>
 #include <signal.h>
+#include <stdarg.h>
 #include "linux/lguest_launcher.h"
 #include "linux/virtio_config.h"
 #include "linux/virtio_net.h"
@@ -1133,6 +1134,24 @@ static struct device *new_device(const c
 	return dev;
 }
 
+static void finalize_device(struct device *dev, const char *fmt, ...)
+{
+	struct virtqueue *vq;
+	va_list ap;
+
+	devices.device_num++;
+	verbose("device %u: %s", devices.device_num, dev->name);
+	va_start(ap, fmt);
+	if (verbose)
+		vprintf(fmt, ap);
+	va_end(ap);
+
+	verbose(" vqs:");
+	for (vq = dev->vq; vq; vq = vq->next)
+		verbose(" %#x", vq->config.pfn * getpagesize());
+	verbose("\n");
+}
+
 /* Our first setup routine is the console.  It's a fairly simple device, but
  * UNIX tty handling makes it uglier than it could be. */
 static void setup_console(void)
@@ -1161,7 +1179,7 @@ static void setup_console(void)
 	add_virtqueue(dev, VIRTQUEUE_NUM, console_input);
 	add_virtqueue(dev, VIRTQUEUE_NUM, console_output);
 
-	verbose("device %u: console\n", ++devices.device_num);
+	finalize_device(dev, "");
 }
 /*:*/
 
@@ -1352,14 +1370,10 @@ static void setup_tun_net(char *arg)
 	/* We don't need the socket any more; setup is done. */
 	close(ipfd);
 
-	devices.device_num++;
-
 	if (bridging)
-		verbose("device %u: tun %s attached to bridge: %s\n",
-			devices.device_num, tapif, arg);
+		finalize_device(dev, " attached to bridge %s", arg);
 	else
-		verbose("device %u: tun %s: %s\n",
-			devices.device_num, tapif, arg);
+		finalize_device(dev, " address %s", arg);
 }
 
 /* Our block (disk) device should be really simple: the Guest asks for a block
@@ -1516,8 +1530,7 @@ static void setup_block_file(const char 
 
 	set_config(dev, sizeof(conf), &conf);
 
-	verbose("device %u: virtblock %llu sectors\n",
-		++devices.device_num, le64_to_cpu(conf.capacity));
+	finalize_device(dev, " %llu sectors", le64_to_cpu(conf.capacity));
 }
 
 struct rng_info {
@@ -1572,7 +1585,7 @@ static void setup_rng(void)
 	/* The device has one virtqueue, where the Guest places inbufs. */
 	add_virtqueue(dev, VIRTQUEUE_NUM, rng_input);
 
-	verbose("device %u: rng\n", devices.device_num++);
+	finalize_device(dev, "");
 }
 /* That's the end of device setup. */
 
