Skip to contentSkip to conversation

usb-linux: physical port handling.

PATCH In review Gerd Hoffmann 6 participants 28 messages May 10, 2011 – May 13, 2011 Kbuild

lore
Share & tools
lore
#0 lore raw

cover usb-linux: physical port handling.

Hi,

These patches fix and improve the physical port handling in the usb host driver. Passthrough of devices connected via usb hub should work better now. Also you can specify usb devices for passthrough by physical port (on the host) now.

please review,
Gerd

Gerd Hoffmann (2):
usb-linux: fix device path aka physical port handling
usb-linux: add hostport property

 usb-linux.c |   47 +++++++++++++++++++++++++++--------------------
 1 files changed, 27 insertions(+), 20 deletions(-)
#1 lore raw

PATCH 1/2 usb-linux: fix device path aka physical port handling

The device path isn't just a number. It specifies the physical port the device is connected to and in case the device is connected via usb hub you'll have two numbers there, like this: "5.1". The first specifies the root port where the hub is plugged into, the second specifies the port number of the hub where the device is plugged in. With multiple hubs chained the string can become longer.

This patch renames devpath to port and makes it a string. It also
adapts the sysfs parsing code accordingly. The "info usbhost" monitor command now prints bus number, (os-assigned) device address and physical port for each device.

---
 usb-linux.c |   38 ++++++++++++++++++++------------------
 1 files changed, 20 insertions(+), 18 deletions(-)
usb-linux.c +20 -18
index 72fe6f5..9543a69 100644
@@ -62,7 +62,7 @@ struct usb_ctrlrequest {
     uint16_t wLength;
 };
 
-typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath,
+typedef int USBScanFunc(void *opaque, int bus_num, int addr, char *port,
                         int class_id, int vendor_id, int product_id,
                         const char *product_name, int speed);
 
@@ -79,6 +79,7 @@ typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath,
 #define USBPROCBUS_PATH "/proc/bus/usb"
 #define PRODUCT_NAME_SZ 32
 #define MAX_ENDPOINTS 15
+#define MAX_PORTLEN 8
 #define USBDEVBUS_PATH "/dev/bus/usb"
 #define USBSYSBUS_PATH "/sys/bus/usb"
 
@@ -155,7 +156,7 @@ typedef struct USBHostDevice {
     /* Host side address */
     int bus_num;
     int addr;
-    int devpath;
+    char port[MAX_PORTLEN];
     struct USBAutoFilter match;
 
     QTAILQ_ENTRY(USBHostDevice) next;
@@ -1092,7 +1093,7 @@ static int usb_linux_get_configuration(USBHostDevice *s)
         char device_name[32], line[1024];
         int configuration;
 
-        sprintf(device_name, "%d-%d", s->bus_num, s->devpath);
+        sprintf(device_name, "%d-%s", s->bus_num, s->port);
 
         if (!usb_host_read_file(line, sizeof(line), "bConfigurationValue",
                                 device_name)) {
@@ -1138,7 +1139,7 @@ static uint8_t usb_linux_get_alt_setting(USBHostDevice *s,
         char device_name[64], line[1024];
         int alt_setting;
 
-        sprintf(device_name, "%d-%d:%d.%d", s->bus_num, s->devpath,
+        sprintf(device_name, "%d-%s:%d.%d", s->bus_num, s->port,
                 (int)configuration, (int)interface);
 
         if (!usb_host_read_file(line, sizeof(line), "bAlternateSetting",
@@ -1257,7 +1258,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
 }
 
 static int usb_host_open(USBHostDevice *dev, int bus_num,
-                         int addr, int devpath, const char *prod_name)
+                         int addr, char *port, const char *prod_name)
 {
     int fd = -1, ret;
     struct usbdevfs_connectinfo ci;
@@ -1283,7 +1284,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
 
     dev->bus_num = bus_num;
     dev->addr = addr;
-    dev->devpath = devpath;
+    strcpy(dev->port, port);
     dev->fd = fd;
 
     /* read the device description */
@@ -1655,8 +1656,9 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
 {
     DIR *dir = NULL;
     char line[1024];
-    int bus_num, addr, devpath, speed, class_id, product_id, vendor_id;
+    int bus_num, addr, speed, class_id, product_id, vendor_id;
     int ret = 0;
+    char port[MAX_PORTLEN];
     char product_name[512];
     struct dirent *de;
 
@@ -1672,8 +1674,8 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
             if (!strncmp(de->d_name, "usb", 3)) {
                 tmpstr += 3;
             }
-            if (sscanf(tmpstr, "%d-%d", &bus_num, &devpath) < 1) {
-                goto the_end;
+            if (sscanf(tmpstr, "%d-%7[0-9.]", &bus_num, port) < 2) {
+                continue;
             }
 
             if (!usb_host_read_file(line, sizeof(line), "devnum", de->d_name)) {
@@ -1725,7 +1727,7 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
                 speed = USB_SPEED_FULL;
             }
 
-            ret = func(opaque, bus_num, addr, devpath, class_id, vendor_id,
+            ret = func(opaque, bus_num, addr, port, class_id, vendor_id,
                        product_id, product_name, speed);
             if (ret) {
                 goto the_end;
@@ -1816,7 +1818,7 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
 
 static QEMUTimer *usb_auto_timer;
 
-static int usb_host_auto_scan(void *opaque, int bus_num, int addr, int devpath,
+static int usb_host_auto_scan(void *opaque, int bus_num, int addr, char *port,
                               int class_id, int vendor_id, int product_id,
                               const char *product_name, int speed)
 {
@@ -1852,7 +1854,7 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr, int devpath,
         }
         DPRINTF("husb: auto open: bus_num %d addr %d\n", bus_num, addr);
 
-        usb_host_open(s, bus_num, addr, devpath, product_name);
+        usb_host_open(s, bus_num, addr, port, product_name);
     }
 
     return 0;
@@ -1974,8 +1976,8 @@ static const char *usb_class_str(uint8_t class)
     return p->class_name;
 }
 
-static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id,
-                            int vendor_id, int product_id,
+static void usb_info_device(Monitor *mon, int bus_num, int addr, char *port,
+                            int class_id, int vendor_id, int product_id,
                             const char *product_name,
                             int speed)
 {
@@ -1996,8 +1998,8 @@ static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id,
         break;
     }
 
-    monitor_printf(mon, "  Device %d.%d, speed %s Mb/s\n",
-                bus_num, addr, speed_str);
+    monitor_printf(mon, "  Bus %d, Addr %d, Port %s, Speed %s Mb/s\n",
+                   bus_num, addr, port, speed_str);
     class_str = usb_class_str(class_id);
     if (class_str) {
         monitor_printf(mon, "    %s:", class_str);
@@ -2012,14 +2014,14 @@ static void usb_info_device(Monitor *mon, int bus_num, int addr, int class_id,
 }
 
 static int usb_host_info_device(void *opaque, int bus_num, int addr,
-                                int devpath, int class_id,
+                                char *path, int class_id,
                                 int vendor_id, int product_id,
                                 const char *product_name,
                                 int speed)
 {
     Monitor *mon = opaque;
 
-    usb_info_device(mon, bus_num, addr, class_id, vendor_id, product_id,
+    usb_info_device(mon, bus_num, addr, path, class_id, vendor_id, product_id,
                     product_name, speed);
     return 0;
 }
Signature · 1 line
1.7.1
#4 lore raw

PATCH 2/2 usb-linux: add hostport property

In reply to Gerd Hoffmann

This patch adds a hostport property which allows to specify the host usb devices to pass through by bus number and physical port. This means you can basically hand over one (or more) of the usb plugs on your host to the guest and whatever device is plugged in there will show up in the guest.

Usage:

-device usb-host,hostbus=1,hostport=1

You can figure the port numbers by plugging in some usb device, then find it in "info usbhost" and pick bus and port specified there.

---
 usb-linux.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
usb-linux.c +7 -2
index 9543a69..5f50767 100644
@@ -135,6 +135,7 @@ struct ctrl_struct {
 struct USBAutoFilter {
     uint32_t bus_num;
     uint32_t addr;
+    char     *port;
     uint32_t vendor_id;
     uint32_t product_id;
 };
@@ -1416,6 +1417,7 @@ static struct USBDeviceInfo usb_host_dev_info = {
     .qdev.props     = (Property[]) {
         DEFINE_PROP_UINT32("hostbus",  USBHostDevice, match.bus_num,    0),
         DEFINE_PROP_UINT32("hostaddr", USBHostDevice, match.addr,       0),
+        DEFINE_PROP_STRING("hostport", USBHostDevice, match.port),
         DEFINE_PROP_HEX32("vendorid",  USBHostDevice, match.vendor_id,  0),
         DEFINE_PROP_HEX32("productid", USBHostDevice, match.product_id, 0),
         DEFINE_PROP_END_OF_LIST(),
@@ -1838,6 +1840,9 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr, char *port,
         if (f->addr > 0 && f->addr != addr) {
             continue;
         }
+        if (f->port != NULL && (port == NULL || strcmp(f->port, port) != 0)) {
+            continue;
+        }
 
         if (f->vendor_id > 0 && f->vendor_id != vendor_id) {
             continue;
@@ -2063,7 +2068,7 @@ void usb_host_info(Monitor *mon)
         dec2str(f->addr, addr, sizeof(addr));
         hex2str(f->vendor_id, vid, sizeof(vid));
         hex2str(f->product_id, pid, sizeof(pid));
-        monitor_printf(mon, "    Device %s.%s ID %s:%s\n",
-                       bus, addr, vid, pid);
+        monitor_printf(mon, "    Bus %s, Addr %s, Port %s, ID %s:%s\n",
+                       bus, addr, f->port ? f->port : "*", vid, pid);
     }
 }
Signature · 1 line
1.7.1
#5 lore raw
In reply to Gerd Hoffmann
Quoted 10 lines · On Tuesday 10 May 2011 12:30:41 Gerd Hoffmann wrote:

Hi,

These patches fix and improve the physical port handling in the usb host driver. Passthrough of devices connected via usb hub should work better now. Also you can specify usb devices for passthrough by physical port (on the host) now.

please review,
Gerd

Quoted 6 lines

Gerd Hoffmann (2):
usb-linux: fix device path aka physical port handling
usb-linux: add hostport property

 usb-linux.c |   47 +++++++++++++++++++++++++++--------------------
 1 files changed, 27 insertions(+), 20 deletions(-)

Some additional docs (based on 2/2 hints) might be a useful addition. Possible candidates:
- docs/qdev-device-use.txt
- qemu-doc.texi

Brad

#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] usb-linux: fix device path aka physical port handling

In reply to Gerd Hoffmann

Good stuff, just a few questions.

Quoted 6 lines · Gerd Hoffmann

The device path isn't just a number. It specifies the physical port the device is connected to and in case the device is connected via usb hub you'll have two numbers there, like this: "5.1". The first specifies the root port where the hub is plugged into, the second specifies the port number of the hub where the device is plugged in. With multiple hubs chained the string can become longer.

"5.1"? Do you mean "5-1"?

I think you're talking about the file names in /sys/bus/usb/devices. Kernel names them in drivers/usb/core/usb.c's usb_alloc_dev().

Roots:

		dev->devpath[0] = '0';
		dev_set_name(&dev->dev, "usb%d", bus->busnum);

Hubs:

		if (parent->devpath[0] == '0') {
			snprintf(dev->devpath, sizeof dev->devpath,
				"%d", port1);
		} else {
			snprintf(dev->devpath, sizeof dev->devpath,
				"%s.%d", parent->devpath, port1);
		}
		dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath);

On my system:

$ ls /sys/bus/usb/devices
1-0:1.0  2-0:1.0  3-0:1.0  4-0:1.0  5-0:1.0  usb1  usb2  usb3  usb4  usb5
Quoted 24 lines

This patch renames devpath to port and makes it a string. It also
adapts the sysfs parsing code accordingly. The "info usbhost" monitor command now prints bus number, (os-assigned) device address and physical port for each device.

---
 usb-linux.c |   38 ++++++++++++++++++++------------------
 1 files changed, 20 insertions(+), 18 deletions(-)
usb-linux.c +1 -1
index 72fe6f5..9543a69 100644
@@ -62,7 +62,7 @@ struct usb_ctrlrequest {
     uint16_t wLength;
 };
 
-typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath,
+typedef int USBScanFunc(void *opaque, int bus_num, int addr, char *port,
                         int class_id, int vendor_id, int product_id,
                         const char *product_name, int speed);
 

usb-linux.c typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath, · line 82

Quoted 4 lines
usb-linux.c +1 -0
@@ -79,6 +79,7 @@ typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath,
 #define USBPROCBUS_PATH "/proc/bus/usb"
 #define PRODUCT_NAME_SZ 32
 #define MAX_ENDPOINTS 15
+#define MAX_PORTLEN 8

Where does 8 come from? For what it's worth, kernel's struct usb_device has char devpath[16].

Quoted 60 lines
usb-linux.c +7 -6
 #define USBDEVBUS_PATH "/dev/bus/usb"
 #define USBSYSBUS_PATH "/sys/bus/usb"
 
@@ -155,7 +156,7 @@ typedef struct USBHostDevice {
     /* Host side address */
     int bus_num;
     int addr;
-    int devpath;
+    char port[MAX_PORTLEN];
     struct USBAutoFilter match;
 
     QTAILQ_ENTRY(USBHostDevice) next;
@@ -1092,7 +1093,7 @@ static int usb_linux_get_configuration(USBHostDevice *s)
         char device_name[32], line[1024];
         int configuration;
 
-        sprintf(device_name, "%d-%d", s->bus_num, s->devpath);
+        sprintf(device_name, "%d-%s", s->bus_num, s->port);
 
         if (!usb_host_read_file(line, sizeof(line), "bConfigurationValue",
                                 device_name)) {
@@ -1138,7 +1139,7 @@ static uint8_t usb_linux_get_alt_setting(USBHostDevice *s,
         char device_name[64], line[1024];
         int alt_setting;
 
-        sprintf(device_name, "%d-%d:%d.%d", s->bus_num, s->devpath,
+        sprintf(device_name, "%d-%s:%d.%d", s->bus_num, s->port,
                 (int)configuration, (int)interface);
 
         if (!usb_host_read_file(line, sizeof(line), "bAlternateSetting",
@@ -1257,7 +1258,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
 }
 
 static int usb_host_open(USBHostDevice *dev, int bus_num,
-                         int addr, int devpath, const char *prod_name)
+                         int addr, char *port, const char *prod_name)
 {
     int fd = -1, ret;
     struct usbdevfs_connectinfo ci;
@@ -1283,7 +1284,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
 
     dev->bus_num = bus_num;
     dev->addr = addr;
-    dev->devpath = devpath;
+    strcpy(dev->port, port);
     dev->fd = fd;
 
     /* read the device description */
@@ -1655,8 +1656,9 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
 {
     DIR *dir = NULL;
     char line[1024];
-    int bus_num, addr, devpath, speed, class_id, product_id, vendor_id;
+    int bus_num, addr, speed, class_id, product_id, vendor_id;
     int ret = 0;
+    char port[MAX_PORTLEN];
     char product_name[512];
     struct dirent *de;
 

usb-linux.c static int usb_host_scan_sys(void *opaque, USBScanFunc *func) · line 1676

Quoted 3 lines
usb-linux.c +0 -0
@@ -1672,8 +1674,8 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
             if (!strncmp(de->d_name, "usb", 3)) {
                 tmpstr += 3;
             }

Sloppy parsing, but that's not your fault.

usb-linux.c static int usb_host_scan_sys(void *opaque, USBScanFunc *func) · line 1681

Quoted 7 lines
usb-linux.c +2 -2
-            if (sscanf(tmpstr, "%d-%d", &bus_num, &devpath) < 1) {
-                goto the_end;
+            if (sscanf(tmpstr, "%d-%7[0-9.]", &bus_num, port) < 2) {
+                continue;
             }
 
             if (!usb_host_read_file(line, sizeof(line), "devnum", de->d_name)) {

The old sscanf() succeeds if at least one item is assigned, i.e. tmpstr starts with an integer. I suspect this is broken for roots. Consider d_name "usb1": tmpstr is "1", sscan() returns 1, and devpath remains uninitialized. It's passed to the func() callback. Bug? If yes, the commit message should mention it.

The new sscan() succeeds only if both items are assigned, i.e. tmpstr starts with an integer, '-', and up to 7 of [0-9.]. Unlike the old one, it fails for roots. Intentional?

[...]

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] usb-linux: fix device path aka physical port handling

Quoted 4 lines · Markus Armbruster

Good stuff, just a few questions.

Gerd Hoffmann<[email protected]> writes:

Quoted 8 lines
Quoted 6 lines

The device path isn't just a number. It specifies the physical port the device is connected to and in case the device is connected via usb hub you'll have two numbers there, like this: "5.1". The first specifies the root port where the hub is plugged into, the second specifies the port number of the hub where the device is plugged in. With multiple hubs chained the string can become longer.

"5.1"? Do you mean "5-1"?

No.

Quoted 2 lines
			snprintf(dev->devpath, sizeof dev->devpath,
				"%s.%d", parent->devpath, port1);
                                 ^^^^^
Quoted 2 lines
$ ls /sys/bus/usb/devices
1-0:1.0  2-0:1.0  3-0:1.0  4-0:1.0  5-0:1.0  usb1  usb2  usb3  usb4  usb5

Boring, nothing plugged in here ;)

Laptop docking stations often have a usb hub built in. If you have one place your laptop there, then connect a usb device to one of the ports of the docking station. You'll see a file named like this:

1-5.3

where "1" is the bus number, "5" is the port number of the root hub and "3" is the port number of the docking station hub.

Quoted 7 lines

usb-linux.c typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath, · line 82

Quoted 5 lines
usb-linux.c +1 -0
@@ -79,6 +79,7 @@ typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath,
  #define USBPROCBUS_PATH "/proc/bus/usb"
  #define PRODUCT_NAME_SZ 32
  #define MAX_ENDPOINTS 15
+#define MAX_PORTLEN 8

Where does 8 come from?

Pulled out of thin air. Should be enougth, you can build chains with three usb hubs (anyone ever did in practice? did the devices still work?), getting port addresses like "1.2.3.4", and it still fits in.

Quoted 2 lines

For what it's worth, kernel's struct usb_device
has char devpath[16].

We can make that 16 too to be on the really safe side.

Quoted 6 lines

usb-linux.c static int usb_host_scan_sys(void *opaque, USBScanFunc *func) · line 1676

Quoted 4 lines
usb-linux.c +0 -0
@@ -1672,8 +1674,8 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc *func)
              if (!strncmp(de->d_name, "usb", 3)) {
                  tmpstr += 3;
              }

Sloppy parsing, but that's not your fault.

I think this can be zapped now, the new sscanf will fail on them and skip the entries anyway.

Quoted 6 lines
Quoted 6 lines
usb-linux.c +2 -2
-            if (sscanf(tmpstr, "%d-%d",&bus_num,&devpath)<  1) {
-                goto the_end;
+            if (sscanf(tmpstr, "%d-%7[0-9.]",&bus_num, port)<  2) {
+                continue;
              }
 
Quoted 7 lines

usb-linux.c static int usb_host_scan_sys(void *opaque, USBScanFunc *func) · line 1681

Quoted 1 line
usb-linux.c +0 -0
              if (!usb_host_read_file(line, sizeof(line), "devnum", de->d_name)) {

The old sscanf() succeeds if at least one item is assigned, i.e. tmpstr starts with an integer. I suspect this is broken for roots. Consider d_name "usb1": tmpstr is "1", sscan() returns 1, and devpath remains uninitialized. It's passed to the func() callback. Bug? If yes, the commit message should mention it.

Indeed.

Quoted 3 lines

The new sscan() succeeds only if both items are assigned, i.e. tmpstr starts with an integer, '-', and up to 7 of [0-9.]. Unlike the old one, it fails for roots. Intentional?

Yes, now the roots are skipped. You can't assign them anyway, so it is pretty pointless to loom at them and to list them in "info usbhost".

cheers,
Gerd

#6 lore raw

[Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Brad Hards

Hi,

Quoted 1 line

Some additional docs (based on 2/2 hints) might be a useful addition.

Indeed.

Quoted 3 lines

Possible candidates:
- docs/qdev-device-use.txt
- qemu-doc.texi

Hmm.

qemu-doc.texi only documents the pre-qdev way to create devices. qdev-device-use.txt is a conversion guide.

devices which can only be created via -device (or provide additional features via qdev attributes when created that way) are not documented anywhere now.

Suggestions? Should we add a qdev section to qemu-doc.texi? Or better a separate qemu-devices.txt (or .texi)?

What is the status of the qdev documentation patches btw.? Maybe we should just merge them, then start filling stuff and maybe also autogenerate documentation from that?

cheers,
Gerd

#7 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

[note cc: Amit]

Quoted 15 lines · Gerd Hoffmann

Hi,

Quoted 1 line

Some additional docs (based on 2/2 hints) might be a useful addition.

Indeed.

Quoted 3 lines

Possible candidates:
- docs/qdev-device-use.txt
- qemu-doc.texi

Hmm.

qemu-doc.texi only documents the pre-qdev way to create devices. qdev-device-use.txt is a conversion guide.

Quoted 8 lines

devices which can only be created via -device (or provide additional features via qdev attributes when created that way) are not documented anywhere now.

Suggestions? Should we add a qdev section to qemu-doc.texi? Or better a separate qemu-devices.txt (or .texi)?

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

Quoted 3 lines

Maybe we
should just merge them, then start filling stuff and maybe also autogenerate documentation from that?

Yes.

Amit, once more into the breach?

#8 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

cheers,
Gerd

#9 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Inline documentation is bad. Our documentation should be centralized.
That's the only way to keep it consistent and thorough.

There's no way to easily extract the inline docs in a complete way since some devices are built conditionally.

Regards,

Anthony Liguori

Quoted 5 lines

cheers,
Gerd

#23 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Gerd Hoffmann
Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Here's an example of what I'm suggesting. I think we should just go with this and add better output as we go.

But we need all of the qdev information.. not just a doc string for each property.

Regards,

Anthony Liguori

Quoted 7 lines

cheers,
Gerd

From 130c817790880c61b79dbccf66f5863c406eb7d4 Mon Sep 17 00:00:00 2001

From: Anthony Liguori <[email protected]>
Date: Thu, 12 May 2011 10:56:29 -0500
Subject: [PATCH] qdev: add centralized documentation for qdev

This is mostly a proof-of-concept.

Makefile +2 -0
index 2b0438c..fddb261 100644
@@ -341,5 +341,7 @@ tarbin:
 	$(mandir)/man1/qemu-img.1 \
 	$(mandir)/man8/qemu-nbd.8
 
+include $(SRC_PATH)/Makefile.doc
+
 # Include automatically generated dependency files
 -include $(wildcard *.d audio/*.d slirp/*.d block/*.d net/*.d ui/*.d)
Makefile.doc new file +2 -0
new file mode 100644
index 0000000..f769b23
@@ -0,0 +1,2 @@
+qdev-doc.html: $(SRC_PATH)/qdev-doc.json
+	python $(SRC_PATH)/scripts/qdev-doc-to-html.py < $< > $@
qdev-doc.json new file +14 -0
new file mode 100644
index 0000000..c24630b
@@ -0,0 +1,14 @@
+# -*- Mode: Python -*-
+
+[ { "device": "isa-serial",
+    "parent": "ISADevice",
+    "properties": {
+            "index": { "type": "uint32",
+                       "doc": "A value from 0-3 that describes which IO regions to expose the device on.  This sets appropriate values for iobase and irq." },
+            "iobase": { "type": "hex32",
+                        "doc": "The base IO address to expose the device on." },
+            "irq": { "type": "uint32",
+                     "doc": "The IRQ to use for the device." },
+            "chardev": { "type": "chr",
+                         "doc": "The name of a character device to specify." } } }
+  ]
scripts/qdev-doc-to-html.py new file +40 -0
new file mode 100644
index 0000000..a25fe35
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+import sys
+
+data = sys.stdin.read()
+
+docs = eval(data)
+
+sys.stdout.write('''
+<html>
+<head>
+<title>QEMU device documentation</title>
+</head>
+<body>
+''')
+
+for item in docs:
+    sys.stdout.write('''
+<h2>%(device)s :: %(parent)s</h2>
+
+<table border="1">
+<tr>
+<th>Name</th><th>Type</th><th>Comments</th>
+</tr>
+''' % item)
+    for prop in item["properties"]:
+        sys.stdout.write('''
+<tr>
+<td>%s</td><td>%s</td><td>%s</td>
+</tr>
+''' % (prop, item["properties"][prop]['type'], item["properties"][prop]['doc']))
+
+    sys.stdout.write('''
+</table>
+''')
+
+sys.stdout.write('''
+</body>
+</html>
+''')
Signature · 1 line
1.7.4.1
#22 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Markus Armbruster
Quoted 11 lines · Markus Armbruster
Quoted 7 lines · Gerd Hoffmann
   Hi,
Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

Anthony ;)

1) It doesn't help us get good written documentation without non-existent magic to extract a qdev schema.

2) It makes the documentation hidden in random places in the tree making it hard to audit what is undocumented.

3) It guarantees that documentation will vary drastically in language and quality.

4) I greatly fear that we're embarking down yet another "introduce a new API that never gets fully converted" path.

I've sent a quick patch out with what I think is a significantly better approach.

Regards,

Anthony Liguori

Quoted 3 lines

[...]

#10 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

Quoted 8 lines
Quoted 5 lines

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Inline documentation is bad. Our documentation should be centralized. That's the only way to keep it consistent and thorough.

External documentation of code details is bad. Our documentation should be next to the code. That's the only way to keep it up-to-date and consistent with the code.

Quoted 2 lines

There's no way to easily extract the inline docs in a complete way since some devices are built conditionally.

For each configured target: extract docs of the devices it builds Concatenate and discard the duplicates

Yes, that means you don't get docs for devices none of your targets has. That's a feature. If you really want docs for all devices, build all targets.

#24 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Anthony Liguori
Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Quoted 5 lines

Here's an example of what I'm suggesting. I think we should just go with this and add better output as we go.

But we need all of the qdev information.. not just a doc string for each property.

Missing: make "device_add ?" show your device doc strings, and "device_add NAME,?" show your property doc strings.

Missing: automated check qdev-doc.json matches the code. Keeping the docs far from the code is a bad idea even with such a check.

[...]

#11 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Markus Armbruster
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Quoted 6 lines
Quoted 2 lines

Inline documentation is bad. Our documentation should be centralized. That's the only way to keep it consistent and thorough.

External documentation of code details is bad. Our documentation should be next to the code. That's the only way to keep it up-to-date and consistent with the code.

qdev properties are *not* code details. It's a public user interface that we have to support for every.

It should be disconnected from the internal implementation. And yes, the incestuous relationship that exists today is a problem, but it's one we're going to have to live with.

Quoted 10 lines
Quoted 3 lines

There's no way to easily extract the inline docs in a complete way since some devices are built conditionally.

For each configured target: extract docs of the devices it builds Concatenate and discard the duplicates

Yes, that means you don't get docs for devices none of your targets has. That's a feature. If you really want docs for all devices, build all targets.

But for things like Spice where the lack of libspice influences whether the device is available, how do I extract formal documentation to publish on qemu.org reliably?

Regards,

Anthony Liguori

Quoted 1 line
#25 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Markus Armbruster
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Quoted 8 lines
Quoted 5 lines

Here's an example of what I'm suggesting. I think we should just go with this and add better output as we go.

But we need all of the qdev information.. not just a doc string for each property.

Missing: make "device_add ?" show your device doc strings, and "device_add NAME,?" show your property doc strings.

I really dislike overloading things for inline help. Introducing a device_help is fine and hopefully you realize that generating this is trivial.

Quoted 3 lines

Missing: automated check qdev-doc.json matches the code. Keeping the docs far from the code is a bad idea even with such a check.

I view this as a feature. What's documented is what's supported. Anything that isn't documented isn't supported.

But yes, hopefully it's obvious that we can add automated checks to improve this.

But if we're going to start somewhere, this is where I think we should start.

Regards,

Anthony Liguori

Quoted 2 lines

[...]

#27 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Markus Armbruster
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Anthony Liguori
Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Quoted 8 lines
Quoted 5 lines

Here's an example of what I'm suggesting. I think we should just go with this and add better output as we go.

But we need all of the qdev information.. not just a doc string for each property.

Missing: make "device_add ?" show your device doc strings, and "device_add NAME,?" show your property doc strings.

This is all it takes:

#!/usr/bin/python

import sys

data = sys.stdin.read()

docs = eval(data)

sys.stdout.write('DeviceStateDocumentation device_docs[] = {')

for item in docs:

    sys.stdout.write('''
    {
      .name = "%(device)s",
      .properties = (PropertyDocumentation[])({''' % item)
    for prop in item["properties"]:
        sys.stdout.write('''
        { "%s", "%s", "%s" },''' % (prop, 

item["properties"][prop]['type'], item["properties"][prop]['doc']))

    sys.stdout.write('''
        { },
    },''')

sys.stdout.write('''
};
''')

Plus a little plumbing magic to add the actual command.

Quoted 2 lines

Missing: automated check qdev-doc.json matches the code. Keeping the docs far from the code is a bad idea even with such a check.

If you walk the DeviceInfo list, you can validate that (1) each device has a corresponding entry in device_docs (2) any field in device_docs is present in device (3) the types match.

Regards,

Anthony Liguori

Quoted 2 lines

[...]

#12 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Anthony Liguori
Quoted 19 lines · Anthony Liguori
Quoted 18 lines · Markus Armbruster
Quoted 15 lines · Anthony Liguori
Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Inline documentation is bad. Our documentation should be centralized. That's the only way to keep it consistent and thorough.

Quoted 6 lines
Quoted 3 lines

External documentation of code details is bad. Our documentation should be next to the code. That's the only way to keep it up-to-date and consistent with the code.

qdev properties are *not* code details. It's a public user interface that we have to support for every.

The fact that they are public user interface doesn't change the fact that they're code at all. They are *both*.

Quoted 3 lines

It should be disconnected from the internal implementation. And yes, the incestuous relationship that exists today is a problem, but it's one we're going to have to live with.

I doubt we'll ever reach consensus on this one.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

There's no way to easily extract the inline docs in a complete way since some devices are built conditionally.

For each configured target: extract docs of the devices it builds Concatenate and discard the duplicates

Quoted 7 lines
Quoted 3 lines

Yes, that means you don't get docs for devices none of your targets has. That's a feature. If you really want docs for all devices, build all targets.

But for things like Spice where the lack of libspice influences whether the device is available, how do I extract formal documentation to publish on qemu.org reliably?

If no maintainer of QEMU can build with Spice enabled, it got more serious problems than extracting its documentation.

#13 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Anthony Liguori
Quoted 21 lines · Markus Armbruster
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

Quoted 8 lines
Quoted 5 lines

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Inline documentation is bad. Our documentation should be centralized. That's the only way to keep it consistent and thorough.

External documentation of code details is bad. Our documentation should be next to the code. That's the only way to keep it up-to-date and consistent with the code.

Quoted 5 lines
Quoted 2 lines

qdev properties are *not* code details. It's a public user interface that we have to support for every.

The fact that they are public user interface doesn't change the fact that they're code at all. They are *both*.

That's fine. But what better way to ensure a consistent and stable UI than having it centralized in one place.

Quoted 5 lines
Quoted 3 lines

It should be disconnected from the internal implementation. And yes, the incestuous relationship that exists today is a problem, but it's one we're going to have to live with.

I doubt we'll ever reach consensus on this one.

I don't think that matters though. qdev properties are part of our UI and need to be stable.

Just like we express our command line options centrally (with documentation) via qemu-options.hx, it seems reasonable to me to do it for qdev properties.

I think the only downside is that we have to duplicate this the current DeviceInfo definitions but that's a harder problem that can be deferred for another day.

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

Yes, that means you don't get docs for devices none of your targets has. That's a feature. If you really want docs for all devices, build all targets.

But for things like Spice where the lack of libspice influences whether the device is available, how do I extract formal documentation to publish on qemu.org reliably?

If no maintainer of QEMU can build with Spice enabled, it got more serious problems than extracting its documentation.

It's not about Spice. But having documentation that is influenced by build options seems like a bad thing to me.

But regardless, centralized documentation means more consistency in the documentation. I think this is a critically important point.

Regards,

Anthony Liguori

#17 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Markus Armbruster
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Anthony Liguori

But for things like Spice where the lack of libspice influences whether the device is available, how do I extract formal documentation to publish on qemu.org reliably?

If no maintainer of QEMU can build with Spice enabled, it got more serious problems than extracting its documentation.

The point isn't that you can arrange to build with option Foo enabled but that if the build environment changes accidentally there's not much warning that the official docs have suddenly lost some devices. The spice probe in configure will barf if you said "--enable-spice" and spice wasn't found, but I bet not all configure checks that influence availability of a device do that. And since there isn't currently an '--enable-all' option to configure the docs builder would have to keep track of every new --enable-foo switch and add it to the configure command...

Which looks pretty ugly and not very reliable to me.

-- PMM

#26 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Anthony Liguori
Quoted 22 lines · Anthony Liguori
Quoted 21 lines · Markus Armbruster
Quoted 18 lines · Anthony Liguori
Quoted 11 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Here's an example of what I'm suggesting. I think we should just go with this and add better output as we go.

But we need all of the qdev information.. not just a doc string for each property.

Quoted 6 lines
Quoted 2 lines

Missing: make "device_add ?" show your device doc strings, and "device_add NAME,?" show your property doc strings.

I really dislike overloading things for inline help. Introducing a device_help is fine and hopefully you realize that generating this is trivial.

I never liked "device_add ?" myself, but it's what we got. I'd support replacing it with something more decent.

[...]

#18 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Peter Maydell
Quoted 19 lines · Peter Maydell
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Anthony Liguori

But for things like Spice where the lack of libspice influences whether the device is available, how do I extract formal documentation to publish on qemu.org reliably?

If no maintainer of QEMU can build with Spice enabled, it got more serious problems than extracting its documentation.

The point isn't that you can arrange to build with option Foo enabled but that if the build environment changes accidentally there's not much warning that the official docs have suddenly lost some devices. The spice probe in configure will barf if you said "--enable-spice" and spice wasn't found, but I bet not all configure checks that influence availability of a device do that. And since there isn't currently an '--enable-all' option to configure the docs builder would have to keep track of every new --enable-foo switch and add it to the configure command...

Quoted 2 lines

Which looks pretty ugly and not very reliable to me.

We could have a (just picking up the Spice example) spice-docs file
that was checked in and updated periodically by generation by the maintainer. It's error prone, you could still update the source but forget to checkin the spice-docs and get an old version, but at least it would still be auto-generated, and it would not prevent the docs builder from working.

Quoted 2 lines

-- PMM

#19 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

Quoted 5 lines · Alon Levy

We could have a (just picking up the Spice example) spice-docs file
that was checked in and updated periodically by generation by the maintainer. It's error prone, you could still update the source but forget to checkin the spice-docs and get an old version, but at least it would still be auto-generated, and it would not prevent the docs builder from working.

It's not just Spice though. There are still a number of devices that only get built with certain targets.

Doing it right is actually fairly complicated. It's far easier to use a central doc file, and then add mechanisms to ensure things don't get out of sync.

Regards,

Anthony Liguori

Quoted 4 lines
Quoted 3 lines

-- PMM

#20 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Peter Maydell
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Anthony Liguori

But for things like Spice where the lack of libspice influences whether the device is available, how do I extract formal documentation to publish on qemu.org reliably?

Quoted 7 lines
Quoted 2 lines

If no maintainer of QEMU can build with Spice enabled, it got more serious problems than extracting its documentation.

The point isn't that you can arrange to build with option Foo enabled but that if the build environment changes accidentally there's not much warning that the official docs have suddenly lost some devices.

Fair point. Compare against list of known devices. That way, all you keep at bit-rotting distance from code is the list of known devices.

[...]

#14 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Anthony Liguori
Quoted 26 lines · Anthony Liguori
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Anthony Liguori
Quoted 21 lines · Markus Armbruster
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Gerd Hoffmann

Hi,

Quoted 3 lines
Quoted 1 line

What is the status of the qdev documentation patches btw.?

http://lists.gnu.org/archive/html/qemu-devel/2011-02/msg02169.html

Quoted 8 lines
Quoted 5 lines

What is the problem with the empty strings btw?

The only way around I can see is having _DOC and _NODOC versions for all the property macros, but I'd prefer to not have _NODOC macros in the tree ...

Inline documentation is bad. Our documentation should be centralized. That's the only way to keep it consistent and thorough.

External documentation of code details is bad. Our documentation should be next to the code. That's the only way to keep it up-to-date and consistent with the code.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

qdev properties are *not* code details. It's a public user interface that we have to support for every.

The fact that they are public user interface doesn't change the fact that they're code at all. They are *both*.

That's fine. But what better way to ensure a consistent and stable UI than having it centralized in one place.

Consistent, stable, and bit-rotten. Unless you come up with a way to catch bit-rot immediately. That means on "make", not on "make docs".

Extra points if the error message points right to the offending source line.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

It should be disconnected from the internal implementation. And yes, the incestuous relationship that exists today is a problem, but it's one we're going to have to live with.

I doubt we'll ever reach consensus on this one.

I don't think that matters though.

No need to tell me; I'm well aware that when you have sufficiently strong opinions, consensus doesn't matter ;-P

Quoted 2 lines

qdev properties are part of our UI
and need to be stable.

Presenting them all to the user in a single document makes sense. Doesn't follow we have to *write* the documentation in a single place.

Keeping property documentation in one place makes it soemwhat easier to keep the properties consistent with each other across devices.

Property documentation next the device code implementing them makes it easier to keep the documentation consistent with reality. It also serves as code documentation.

It's a trade off. I prefer property documentation next to the code. To really get consistency across devices, you have to read the resulting user document, anyway.

Quoted 7 lines

Just like we express our command line options centrally (with documentation) via qemu-options.hx, it seems reasonable to me to do it for qdev properties.

I think the only downside is that we have to duplicate this the current DeviceInfo definitions but that's a harder problem that can be deferred for another day.

Having to code stuff twice, once in C and once in JSON, is a pretty ugly downside.

JSON is a fine data interchange format for programs, but neither a programming language, nor a document markup language.

[...]

#15 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

Quoted 5 lines · Markus Armbruster
Quoted 2 lines

That's fine. But what better way to ensure a consistent and stable UI than having it centralized in one place.

Consistent, stable, and bit-rotten. Unless you come up with a way to catch bit-rot immediately. That means on "make", not on "make docs".

How about make check?

See the latest patch. Here is the output from a bad doc file:

Warning: device `virtio-9p-pci' is undocumented
Warning: device `virtio-balloon-pci' is undocumented
Warning: device `virtio-serial-pci' is undocumented
Warning: device `virtio-net-pci' is undocumented
Warning: device `virtio-blk-pci' is undocumented
[ .. snip .. ]
Warning: device `x3130-upstream' is undocumented
Warning: device `xio3130-downstream' is undocumented
Error: device isa-serial' has documented property bad-property' with no definition
Warning: device `isa-parallel' is undocumented
Warning: device `isa-pit' is undocumented
[ .. snip .. ]
Warning: device `i440FX-xen' is undocumented
Warning: device `i440FX' is undocumented
Warning: device `i440FX-pcihost' is undocumented
Warning: device `vmport' is undocumented
Warning: device `ib700' is undocumented
Warning: device `isa-debugcon' is undocumented
Error: documented device `BadDevice' has no definition
91 warnings, 2 errors.

Quoted 2 lines

Extra points if the error message points right to the offending source line.

Would need some macro magic in the qdev registration functions. It's not outside the realm of possibility.

Quoted 9 lines
Quoted 2 lines

qdev properties are part of our UI
and need to be stable.

Presenting them all to the user in a single document makes sense. Doesn't follow we have to *write* the documentation in a single place.

Keeping property documentation in one place makes it soemwhat easier to keep the properties consistent with each other across devices.

Quoted 7 lines

Property documentation next the device code implementing them makes it easier to keep the documentation consistent with reality. It also serves as code documentation.

It's a trade off. I prefer property documentation next to the code. To really get consistency across devices, you have to read the resulting user document, anyway.

I see this evolving. To me, this is the start of a qdev schema from which we can generate factory interfaces to each qdev device.

Quoted 10 lines
Quoted 7 lines

Just like we express our command line options centrally (with documentation) via qemu-options.hx, it seems reasonable to me to do it for qdev properties.

I think the only downside is that we have to duplicate this the current DeviceInfo definitions but that's a harder problem that can be deferred for another day.

Having to code stuff twice, once in C and once in JSON, is a pretty ugly downside.

At least I didn't submit it using XML ;-)

Regards,

Anthony Liguori

Quoted 5 lines

JSON is a fine data interchange format for programs, but neither a programming language, nor a document markup language.

[...]

#16 lore raw

Re: [Qemu-devel] qdev device documentation (Re: [PATCH 0/2] usb-linux: physical port handling.)

In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster
Quoted 2 lines · Anthony Liguori

That's fine. But what better way to ensure a consistent and stable UI than having it centralized in one place.

Consistent, stable, and bit-rotten. Unless you come up with a way to catch bit-rot immediately. That means on "make", not on "make docs".

Extra points if the error message points right to the offending source line.

Er, hit send too fast. Here's the next patch.

Quoted 1 line

From f5c30c922ce1cf755ef78887f4015c131d8d6841 Mon Sep 17 00:00:00 2001

From: Anthony Liguori <[email protected]>
Date: Thu, 12 May 2011 10:56:29 -0500
Subject: [PATCH 1/1] qdev: add centralized documentation for qdev (v2)

This adds a -qdev-verify option that will confirm that the documentation matches the code. It returns a non-zero exit status if any errors are detected.

---
 Makefile                    |    2 +
 Makefile.doc                |    5 ++
 Makefile.objs               |    2 +-
 qdev-doc.h                  |   23 +++++++++++
 qdev-doc.json               |   16 ++++++++
 qemu-options.hx             |   10 +++++
 scripts/qdev-doc-to-c.py    |   30 ++++++++++++++
 scripts/qdev-doc-to-html.py |   40 +++++++++++++++++++
 vl.c                        |   89 +++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 216 insertions(+), 1 deletions(-)
 create mode 100644 Makefile.doc
 create mode 100644 qdev-doc.h
 create mode 100644 qdev-doc.json
 create mode 100644 scripts/qdev-doc-to-c.py
 create mode 100644 scripts/qdev-doc-to-html.py
Makefile +2 -0
index 2b0438c..fddb261 100644
@@ -341,5 +341,7 @@ tarbin:
 	$(mandir)/man1/qemu-img.1 \
 	$(mandir)/man8/qemu-nbd.8
 
+include $(SRC_PATH)/Makefile.doc
+
 # Include automatically generated dependency files
 -include $(wildcard *.d audio/*.d slirp/*.d block/*.d net/*.d ui/*.d)
Makefile.doc new file +5 -0
new file mode 100644
index 0000000..c1cf74a
@@ -0,0 +1,5 @@
+qdev-doc.html: $(SRC_PATH)/qdev-doc.json $(SRC_PATH)/scripts/qdev-doc-to-html.py
+	python $(SRC_PATH)/scripts/qdev-doc-to-html.py < $< > $@
+
+qdev-doc.c: $(SRC_PATH)/qdev-doc.json $(SRC_PATH)/scripts/qdev-doc-to-c.py
+	python $(SRC_PATH)/scripts/qdev-doc-to-c.py < $< > $@
Makefile.objs +1 -1
index 4478c61..9547ab1 100644
@@ -97,7 +97,7 @@ common-obj-y += bt-hci-csr.o
 common-obj-y += buffered_file.o migration.o migration-tcp.o
 common-obj-y += qemu-char.o savevm.o #aio.o
 common-obj-y += msmouse.o ps2.o
-common-obj-y += qdev.o qdev-properties.o
+common-obj-y += qdev.o qdev-properties.o qdev-doc.o
 common-obj-y += block-migration.o iohandler.o
 common-obj-y += pflib.o
 common-obj-y += bitmap.o bitops.o
qdev-doc.h new file +23 -0
new file mode 100644
index 0000000..401e03e
@@ -0,0 +1,23 @@
+#ifndef QDEV_DOC_H
+#define QDEV_DOC_H
+
+#include "qemu-common.h"
+
+typedef struct PropertyDocumentation
+{
+    const char *name;
+    const char *type;
+    const char *docs;
+} PropertyDocumentation;
+
+typedef struct DeviceStateDocumentation
+{
+    const char *name;
+    PropertyDocumentation *properties;
+} DeviceStateDocumentation;
+
+extern DeviceStateDocumentation device_docs[];
+
+bool qdev_verify_docs(void);
+
+#endif
qdev-doc.json new file +16 -0
new file mode 100644
index 0000000..a798bff
@@ -0,0 +1,16 @@
+# -*- Mode: Python -*-
+
+[ { "device": "isa-serial",
+    "parent": "ISADevice",
+    "properties": {
+            "index": { "type": "uint32",
+                       "doc": "A value from 0-3 that describes which IO regions to expose the device on.  This sets appropriate values for iobase and irq." },
+            "iobase": { "type": "hex32",
+                        "doc": "The base IO address to expose the device on." },
+            "irq": { "type": "uint32",
+                     "doc": "The IRQ to use for the device." },
+            "chardev": { "type": "chr",
+                         "doc": "The name of a character device to specify." }
+            }
+  }
+  ]
qemu-options.hx +10 -0
index 9f121ad..a6abab4 100644
@@ -2378,6 +2378,16 @@ Specify a trace file to log output traces to.
 ETEXI
 #endif
 
+DEF("qdev-verify", 0, QEMU_OPTION_qdev_verify,
+    "-qdev-verify\n"
+    "                Verify qdev properties match documentation\n",
+    QEMU_ARCH_ALL)
+STEXI
+@item -qdev-verify
+@findex -qdev-verify
+Verify qdev properties match documentation.
+ETEXI
+
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
 @end table
scripts/qdev-doc-to-c.py new file +30 -0
new file mode 100644
index 0000000..eb7ee59
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+
+import sys
+
+data = sys.stdin.read()
+
+docs = eval(data)
+
+sys.stdout.write('''
+#include "qdev-doc.h"
+
+DeviceStateDocumentation device_docs[] = {''')
+
+for item in docs:
+    sys.stdout.write('''
+    {
+      .name = "%(device)s",
+      .properties = (PropertyDocumentation[]){''' % item)
+    for prop in item["properties"]:
+        sys.stdout.write('''
+        { "%s", "%s", "%s" },''' % (prop, item["properties"][prop]['type'], item["properties"][prop]['doc']))
+
+    sys.stdout.write('''
+        { } },
+    },''')
+
+sys.stdout.write('''
+    { }
+};
+''')
scripts/qdev-doc-to-html.py new file +40 -0
new file mode 100644
index 0000000..a25fe35
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+import sys
+
+data = sys.stdin.read()
+
+docs = eval(data)
+
+sys.stdout.write('''
+<html>
+<head>
+<title>QEMU device documentation</title>
+</head>
+<body>
+''')
+
+for item in docs:
+    sys.stdout.write('''
+<h2>%(device)s :: %(parent)s</h2>
+
+<table border="1">
+<tr>
+<th>Name</th><th>Type</th><th>Comments</th>
+</tr>
+''' % item)
+    for prop in item["properties"]:
+        sys.stdout.write('''
+<tr>
+<td>%s</td><td>%s</td><td>%s</td>
+</tr>
+''' % (prop, item["properties"][prop]['type'], item["properties"][prop]['doc']))
+
+    sys.stdout.write('''
+</table>
+''')
+
+sys.stdout.write('''
+</body>
+</html>
+''')
vl.c +89 -0

119 lines not on this page · raw message

Signature · 1 line
1.7.4.1