Skip to contentSkip to conversation

Implement "info chardev" command.

PATCH In review Gerd Hoffmann 2 participants 3 messages Oct 16, 2008 – Oct 22, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Implement "info chardev" command.

Hi,

This patch makes qemu keep track of the character devices in use and implements a "info chardev" monitor command to print a list.

please apply,
Gerd

Quoted 1 line

From 3bd8020daf1de26cc76e28ae7d38ccf52f1f70bc Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Thu, 16 Oct 2008 16:03:49 +0200
Subject: [PATCH] Implement "info chardev" command.

This patch makes qemu keep track of the character devices in use and implements a "info chardev" monitor command to print a list.

qemu_chr_open() sticks the devices into a linked list now. It got a new argument (label), so there is a name for each device. It also assigns a filename to each character device. By default it just copyes the filename passed in. Individual drivers can fill in something else though. qemu_chr_open_pty() sets the filename to name of the pseudo tty allocated.

Output looks like this:

(qemu) info chardev
monitor: filename=unix:/tmp/run.sh-26827/monitor,server,nowait
serial0: filename=unix:/tmp/run.sh-26827/console,server
serial1: filename=pty:/dev/pts/5
parallel0: filename=vc:640x480

---
 gdbstub.c       |    2 +-
 hw/usb-serial.c |    5 ++-
 monitor.c       |    2 +
 qemu-char.h     |    7 +++-
 vl.c            |   98 ++++++++++++++++++++++++++++++++++++------------------
 5 files changed, 78 insertions(+), 36 deletions(-)
gdbstub.c +1 -1
index ed3f5c6..e95ca67 100644
@@ -1852,7 +1852,7 @@ int gdbserver_start(const char *port)
         port = gdbstub_port_name;
     }
 
-    chr = qemu_chr_open(port);
+    chr = qemu_chr_open("gdb", port);
     if (!chr)
         return -1;
 
hw/usb-serial.c +4 -1
index 40d04cb..a6a756d 100644
@@ -521,6 +521,8 @@ USBDevice *usb_serial_init(const char *filename)
     USBSerialState *s;
     CharDriverState *cdrv;
     unsigned short vendorid = 0x0403, productid = 0x6001;
+    char label[32];
+    static int index;
 
     while (*filename && *filename != ':') {
         const char *p;
@@ -555,7 +557,8 @@ USBDevice *usb_serial_init(const char *filename)
     if (!s)
         return NULL;
 
-    cdrv = qemu_chr_open(filename);
+    snprintf(label, sizeof(label), "usbserial%d", index++);
+    cdrv = qemu_chr_open(label, filename);
     if (!cdrv)
         goto fail;
     s->cs = cdrv;
monitor.c +2 -0
index 233c830..80facf1 100644
@@ -1470,6 +1470,8 @@ static const term_cmd_t info_cmds[] = {
       "", "show the version of qemu" },
     { "network", "", do_info_network,
       "", "show the network state" },
+    { "chardev", "", qemu_chr_info,
+      "", "show the character devices" },
     { "block", "", do_info_block,
       "", "show the block devices" },
     { "blockstats", "", do_info_blockstats,
qemu-char.h +6 -1
index 05d6899..55d81cb 100644
@@ -1,6 +1,7 @@
 #ifndef QEMU_CHAR_H
 #define QEMU_CHAR_H
 
+#include "sys-queue.h"
 /* character device */
 
 #define CHR_EVENT_BREAK 0 /* serial break char */
@@ -55,9 +56,12 @@ struct CharDriverState {
     void *opaque;
     int focus;
     QEMUBH *bh;
+    char *label;
+    char *filename;
+    TAILQ_ENTRY(CharDriverState) next;
 };
 
-CharDriverState *qemu_chr_open(const char *filename);
+CharDriverState *qemu_chr_open(const char *label, const char *filename);
 void qemu_chr_close(CharDriverState *chr);
 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
@@ -72,6 +76,7 @@ void qemu_chr_reset(CharDriverState *s);
 int qemu_chr_can_read(CharDriverState *s);
 void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
 void qemu_chr_accept_input(CharDriverState *s);
+void qemu_chr_info(void);
 
 /* async I/O support */
 
vl.c +65 -33

189 lines not on this page · raw message

Signature · 1 line
1.5.5.1
#1 lore raw
Quoted 5 lines · Gerd Hoffmann

Hi,

This patch makes qemu keep track of the character devices in use and implements a "info chardev" monitor command to print a list.

Is it better to enumerate all chardevs or to provide info functions for each type of chardev (i.e. 'info serial', 'info parallel'). I don't have a strong feeling either way.

The only thing I'd suggest about this patch is that if you're going to print pty:/dev/pty/3, then you should also support that syntax for specifying a pty. Otherwise, there's a lack of symmetry.

Regards,

Anthony Liguori

Quoted 3 lines

please apply,
Gerd

#2 lore raw
Quoted 10 lines · Anthony Liguori
Quoted 5 lines · Gerd Hoffmann

Hi,

This patch makes qemu keep track of the character devices in use and implements a "info chardev" monitor command to print a list.

Is it better to enumerate all chardevs or to provide info functions for each type of chardev (i.e. 'info serial', 'info parallel'). I don't have a strong feeling either way.

I did it this way because
(a) It is easier to implement
(b) Covers everything, not just serial and parallel. There are also usb serial dongles, and it also lists gdb & monitor. And in case we get more in the future, it is already covered ;)
(c) I prefer to keep the number of info commands low.

Quoted 3 lines

The only thing I'd suggest about this patch is that if you're going to print pty:/dev/pty/3, then you should also support that syntax for specifying a pty. Otherwise, there's a lack of symmetry.

It's not a bug, it's a feature.

First, when allocating a pts, the kernel hands out the first free one. There simply is no way to specify one, thus I simply can't support a pty:/dev/pts/$nr syntax on the command line.

Second, I think even for other types it would be useful to support this asymmetric syntax. Allow "unix:" without specifying a path, then have qemu allocate a random one in $TMPDIR and report the path via monitor. Likewise for tcp ports. That allows moving the ressource allocation from the management application into qemu, closing race windows along the way. No patches yet though.

Oh, the same thing for vnc ports is still on the todo list too. Remember the "-vnc :1,to=10" feature discussed a few weeks (months?) ago on the list?

cheers,
Gerd