Skip to contentSkip to conversation

monitor: add peripheral device del completion support

PATCH Superseded Zhu Guihua 2 participants 4 messages Sep 30, 2014

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zhu Guihua

author
#0 lore raw

v2 cover monitor: add peripheral device del completion support

After inputting device_del command in monitor, we expect to list all hotpluggable devices automatically by pressing tab key. This patchset provides the function to list all peripheral devices such as memory devices.

v2:
- use object_child_foreach() to simplify the implementation (Andreas)

Zhu Guihua (2):
qdev: add list built for devices
monitor: add del completion for peripheral device

 hw/core/qdev.c         | 13 +++++++++++++
 include/hw/qdev-core.h |  2 ++
 monitor.c              | 23 +++++++++++++++++++++++
 3 files changed, 38 insertions(+)
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH v2 1/2 qdev: add list built for devices

For peripheral device del completion, add a function to build a list for devices.

---
 hw/core/qdev.c         | 13 +++++++++++++
 include/hw/qdev-core.h |  2 ++
 2 files changed, 15 insertions(+)
hw/core/qdev.c +13 -0
index fcb1638..041ac38 100644
@@ -1074,6 +1074,19 @@ void device_reset(DeviceState *dev)
     }
 }
 
+int device_built_list(Object *obj, void *opaque)
+{
+    GSList **list = opaque;
+    DeviceState *dev = DEVICE(obj);
+
+    if (dev->realized) {
+        *list = g_slist_append(*list, dev);
+    }
+
+    return 0;
+
+}
+
 Object *qdev_get_machine(void)
 {
     static Object *dev;
include/hw/qdev-core.h +2 -0
index 178fee2..3c30837 100644
@@ -348,6 +348,8 @@ void qdev_machine_init(void);
  */
 void device_reset(DeviceState *dev);
 
+int device_built_list(Object *obj, void *opaque);
+
 const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
 
 const char *qdev_fw_name(DeviceState *dev);
Signature · 1 line
1.9.3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] qdev: add list built for devices

On Tue, 30 Sep 2014 17:40:34 +0800
Zhu Guihua <[email protected]> wrote:

rephrase subj to
qdev: func_name() helper

Quoted 14 lines

For peripheral device del completion, add a function to build a list for devices.

---
 hw/core/qdev.c         | 13 +++++++++++++
 include/hw/qdev-core.h |  2 ++
 2 files changed, 15 insertions(+)
hw/core/qdev.c +0 -0
index fcb1638..041ac38 100644

hw/core/qdev.c void device_reset(DeviceState *dev) · line 1077

Quoted 4 lines
hw/core/qdev.c +1 -0
@@ -1074,6 +1074,19 @@ void device_reset(DeviceState *dev)
     }
 }
 
+int device_built_list(Object *obj, void *opaque)

qdev_build_hotpluggable_device_list()
might describe better what function does

You can put object_child_foreach(peripheral, device_built_list, &list) inside if this callback, see for example qmp_pc_dimm_device_list()

Also function would return ALL devices regardless of
whether they are hotpluggable or not.
"hotpluggable" property can be used to discard non hotpluggable devices.

Quoted 28 lines
hw/core/qdev.c +12 -0
+{
+    GSList **list = opaque;
+    DeviceState *dev = DEVICE(obj);
+
+    if (dev->realized) {
+        *list = g_slist_append(*list, dev);
+    }
+
+    return 0;
+
+}
+
 Object *qdev_get_machine(void)
 {
     static Object *dev;
include/hw/qdev-core.h +2 -0
index 178fee2..3c30837 100644
@@ -348,6 +348,8 @@ void qdev_machine_init(void);
  */
 void device_reset(DeviceState *dev);
 
+int device_built_list(Object *obj, void *opaque);
+
 const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
 
 const char *qdev_fw_name(DeviceState *dev);
author
#3 lore raw

PATCH v2 2/2 monitor: add del completion for peripheral device

In reply to Zhu Guihua

Add peripheral_device_del_completion() to let peripheral device del completion be possible.

---
 monitor.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
monitor.c +23 -0
index 667efb7..55f4466 100644
@@ -4351,6 +4351,28 @@ static void device_del_bus_completion(ReadLineState *rs,  BusState *bus,
     }
 }
 
+static void peripheral_device_del_completion(ReadLineState *rs,
+                                             const char *str, size_t len)
+{
+    Object *peripheral;
+    GSList *list = NULL, *item;
+
+    peripheral = object_resolve_path("/machine/peripheral/", NULL);
+
+    if (peripheral == NULL) {
+        return;
+    }
+
+    object_child_foreach(peripheral, device_built_list, &list);
+
+    for (item = list; item; item = g_slist_next(item)) {
+        DeviceState *dev = item->data;
+        if (!strncmp(str, dev->id, len)) {
+            readline_add_completion(rs, dev->id);
+        }
+    }
+}
+
 void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     size_t len;
@@ -4424,6 +4446,7 @@ void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
     len = strlen(str);
     readline_set_completion_index(rs, len);
     device_del_bus_completion(rs, sysbus_get_default(), str, len);
+    peripheral_device_del_completion(rs, str, len);
 }
 
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
Signature · 1 line
1.9.3