Skip to contentSkip to conversation

monitor: add peripheral device del completion support

PATCH Applied Zhu Guihua 4 participants 8 messages Oct 21, 2014 – Oct 23, 2014

lore
Share & tools
lore

Zhu Guihua

author
#0 lore raw

v5 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.

v5:
- In patch 2, make list to free (Marcel)

v4:
- Delete unused device_del_bus_completion (Igor)
- Modify the way to get value of hotpluggable property (Igor)

v3:
- Commit message changes (Igor)
- Rename function in patch 1 (Igor)
- Use 'hotpluggable' property to discard non-hotpluggable devices (Igor)

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

Zhu Guihua (3):
qdev: add qdev_build_hotpluggable_device_list helper
monitor: add del completion for peripheral device
monitor: delete device_del_bus_completion

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

PATCH v5 1/3 qdev: add qdev_build_hotpluggable_device_list helper

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

---
 hw/core/qdev.c         | 13 +++++++++++++
 include/hw/qdev-core.h |  2 ++
 2 files changed, 15 insertions(+)
hw/core/qdev.c +13 -0
index a1e9247..9357aba 100644
@@ -866,6 +866,19 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
     } while (class != object_class_by_name(TYPE_DEVICE));
 }
 
+int qdev_build_hotpluggable_device_list(Object *obj, void *opaque)
+{
+    GSList **list = opaque;
+    DeviceState *dev = DEVICE(obj);
+
+    if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
+        *list = g_slist_append(*list, dev);
+    }
+
+    object_child_foreach(obj, qdev_build_hotpluggable_device_list, opaque);
+    return 0;
+}
+
 static bool device_get_realized(Object *obj, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
include/hw/qdev-core.h +2 -0
index 1fca75c..22820fe 100644
@@ -360,6 +360,8 @@ extern int qdev_hotplug;
 
 char *qdev_get_dev_path(DeviceState *dev);
 
+int qdev_build_hotpluggable_device_list(Object *obj, void *opaque);
+
 void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler,
                               Error **errp);
 
Signature · 1 line
1.9.3
author
#2 lore raw

PATCH v5 2/3 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 | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
monitor.c +26 -0
index 2d14f39..ac41fa3 100644
@@ -4359,6 +4359,31 @@ 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, qdev_build_hotpluggable_device_list,
+                         &list);
+
+    for (item = list; item; item = g_slist_next(item)) {
+        DeviceState *dev = item->data;
+
+        if (dev->id && !strncmp(str, dev->id, len)) {
+            readline_add_completion(rs, dev->id);
+        }
+    }
+
+    g_slist_free(list);
+}
+
 void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     size_t len;
@@ -4432,6 +4457,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
author
#3 lore raw

PATCH v5 3/3 monitor: delete device_del_bus_completion

In reply to Zhu Guihua

device_del_bus_completion() that gathers devices from buses is unused; delete it.

---
 monitor.c | 20 --------------------
 1 file changed, 20 deletions(-)
monitor.c +0 -20
index ac41fa3..2cccd0a 100644
@@ -4340,25 +4340,6 @@ void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
     g_slist_free(list);
 }
 
-static void device_del_bus_completion(ReadLineState *rs,  BusState *bus,
-                                      const char *str, size_t len)
-{
-    BusChild *kid;
-
-    QTAILQ_FOREACH(kid, &bus->children, sibling) {
-        DeviceState *dev = kid->child;
-        BusState *dev_child;
-
-        if (dev->id && !strncmp(str, dev->id, len)) {
-            readline_add_completion(rs, dev->id);
-        }
-
-        QLIST_FOREACH(dev_child, &dev->child_bus, sibling) {
-            device_del_bus_completion(rs, dev_child, str, len);
-        }
-    }
-}
-
 static void peripheral_device_del_completion(ReadLineState *rs,
                                              const char *str, size_t len)
 {
@@ -4456,7 +4437,6 @@ 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);
 }
 
Signature · 1 line
1.9.3
#4 lore raw
In reply to Zhu Guihua
Quoted 3 lines · On Tue, 21 Oct 2014 19:46:03 +0800 Zhu Guihua <[email protected]> wrote:

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.

Igor, Marcel, is this series OK now? If it is can you please add your Reviewed-by?

Thanks.

Reviewed-by
#5 lore raw
Quoted 9 lines · Luiz Capitulino
Quoted 3 lines · On Tue, 21 Oct 2014 19:46:03 +0800 Zhu Guihua <[email protected]> wrote:

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.

Igor, Marcel, is this series OK now? If it is can you please add your Reviewed-by?

The series looks OK to me, I would prefer Igor to have a look too.

Thanks,
Marcel

Quoted 3 lines

Thanks.

Reviewed-by on the v5 series
#6 lore raw
In reply to Zhu Guihua
Quoted 25 lines · On Tue, 21 Oct 2014 19:46:03 +0800 Zhu Guihua <[email protected]> wrote:

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.

v5:
- In patch 2, make list to free (Marcel)

v4:
- Delete unused device_del_bus_completion (Igor)
- Modify the way to get value of hotpluggable property (Igor)

v3:
- Commit message changes (Igor)
- Rename function in patch 1 (Igor)
- Use 'hotpluggable' property to discard non-hotpluggable devices (Igor)

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

Zhu Guihua (3):
qdev: add qdev_build_hotpluggable_device_list helper
monitor: add del completion for peripheral device
monitor: delete device_del_bus_completion

Quoted 5 lines
 hw/core/qdev.c         | 13 +++++++++++++
 include/hw/qdev-core.h |  2 ++
 monitor.c              | 28 +++++++++++++++++-----------
 3 files changed, 32 insertions(+), 11 deletions(-)

For series:

#7 lore raw
In reply to Zhu Guihua
Quoted 3 lines · On Tue, 21 Oct 2014 19:46:03 +0800 Zhu Guihua <[email protected]> wrote:

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.

Applied to the qmp branch, thanks.

Quoted 27 lines

v5:
- In patch 2, make list to free (Marcel)

v4:
- Delete unused device_del_bus_completion (Igor)
- Modify the way to get value of hotpluggable property (Igor)

v3:
- Commit message changes (Igor)
- Rename function in patch 1 (Igor)
- Use 'hotpluggable' property to discard non-hotpluggable devices (Igor)

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

Zhu Guihua (3):
qdev: add qdev_build_hotpluggable_device_list helper
monitor: add del completion for peripheral device
monitor: delete device_del_bus_completion

 hw/core/qdev.c         | 13 +++++++++++++
 include/hw/qdev-core.h |  2 ++
 monitor.c              | 28 +++++++++++++++++-----------
 3 files changed, 32 insertions(+), 11 deletions(-)