Commit ccb63de38e63bd8cdcd3db7aeaebc8a34a02ded8

Authored by Gerd Hoffmann
Committed by Anthony Liguori
1 parent 96cc1810

qdev: add user-specified identifier to devices.

Add id field to DeviceState.  Make "info qtree" print it.

This helps users and management apps identifying devices in monitor
output, which is especially useful with otherwise identical devices
such as two virtio disks.

This patch doesn't add a way to set the id, followup patches will do.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 2 changed files with 5 additions and 2 deletions
hw/qdev.c
@@ -114,7 +114,8 @@ void qdev_init(DeviceState *dev) @@ -114,7 +114,8 @@ void qdev_init(DeviceState *dev)
114 void qdev_free(DeviceState *dev) 114 void qdev_free(DeviceState *dev)
115 { 115 {
116 LIST_REMOVE(dev, sibling); 116 LIST_REMOVE(dev, sibling);
117 - free(dev); 117 + qemu_free(dev->id);
  118 + qemu_free(dev);
118 } 119 }
119 120
120 /* Get a character (serial) device interface. */ 121 /* Get a character (serial) device interface. */
@@ -266,7 +267,8 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props, @@ -266,7 +267,8 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
266 static void qdev_print(Monitor *mon, DeviceState *dev, int indent) 267 static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
267 { 268 {
268 BusState *child; 269 BusState *child;
269 - qdev_printf("dev: %s\n", dev->info->name); 270 + qdev_printf("dev: %s, id \"%s\"\n", dev->info->name,
  271 + dev->id ? dev->id : "");
270 indent += 2; 272 indent += 2;
271 if (dev->num_gpio_in) { 273 if (dev->num_gpio_in) {
272 qdev_printf("gpio-in %d\n", dev->num_gpio_in); 274 qdev_printf("gpio-in %d\n", dev->num_gpio_in);
hw/qdev.h
@@ -19,6 +19,7 @@ typedef struct BusInfo BusInfo; @@ -19,6 +19,7 @@ typedef struct BusInfo BusInfo;
19 /* This structure should not be accessed directly. We declare it here 19 /* This structure should not be accessed directly. We declare it here
20 so that it can be embedded in individual device state structures. */ 20 so that it can be embedded in individual device state structures. */
21 struct DeviceState { 21 struct DeviceState {
  22 + char *id;
22 DeviceInfo *info; 23 DeviceInfo *info;
23 BusState *parent_bus; 24 BusState *parent_bus;
24 int num_gpio_out; 25 int num_gpio_out;