monitor: add peripheral device del completion support
v4 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.
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 | 26 +++++++++++++++----------- 3 files changed, 30 insertions(+), 11 deletions(-)
Signature · 1 line
1.9.3
PATCH v4 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
@@ -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
@@ -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
PATCH v4 2/3 monitor: add del completion for peripheral device
In reply to Zhu GuihuaAdd peripheral_device_del_completion() to let peripheral device del completion be possible.
--- monitor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
monitor.c +24 -0
@@ -4359,6 +4359,29 @@ 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); + } + } +} +void chardev_remove_completion (ReadLineState *rs,int nb_args,const char *str) {size_t len;
@@ -4432,6 +4455,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
Re: [Qemu-devel] [PATCH v4 2/3] monitor: add del completion for peripheral device
Quoted 27 lines · Zhu Guihua
Add
peripheral_device_del_completion()to let peripheral device del completion be possible.Signed-off-by Zhu Guihua <[email protected]>--- monitor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)monitor.c +11
-0@@ -4359,6 +4359,29 @@ 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 ; + } +
monitor.c static void device_del_bus_completion(ReadLineState *rs, BusState *bus, · line 4382
Quoted 10 lines
monitor.c +10
-0+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); + } +
Hi,
Am I missing something or g_slist_free(list)
should be somewhere here?
Thanks,
Marcel
Quoted 13 lines
monitor.c +3
-0+} +void chardev_remove_completion (ReadLineState *rs,int nb_args,const char *str) {size_t len;@@ -4432,6 +4455,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)
Re: [Qemu-devel] [PATCH v4 2/3] monitor: add del completion for peripheral device
Quoted 40 lines · Marcel Apfelbaum
Quoted 27 lines · Zhu Guihua
Add
peripheral_device_del_completion()to let peripheral device del completion be possible.Signed-off-by Zhu Guihua <[email protected]>--- monitor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)monitor.c +11
-0@@ -4359,6 +4359,29 @@ 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 ; + } +monitor.c static void device_del_bus_completion(ReadLineState *rs, BusState *bus, · line 4382
Quoted 10 lines
monitor.c +10
-0+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); + } +Hi,
Quoted 3 lines
Am I missing something or
g_slist_free(list)
should be somewhere here?
Yes, you are right, g_slist_free(list) should be here.
I am sorry to forget to do this. Thanks for your reminding, I will fix this.
Regards,
Zhu
Quoted 21 lines
Thanks,
MarcelQuoted 13 lines
monitor.c +3
-0+} +void chardev_remove_completion (ReadLineState *rs,int nb_args,const char *str) {size_t len;@@ -4432,6 +4455,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)
PATCH v4 3/3 monitor: delete device_del_bus_completion
In reply to Zhu Guihuadevice_del_bus_completion() that gathers devices from buses is unused; delete it.
--- monitor.c | 20 -------------------- 1 file changed, 20 deletions(-)
monitor.c +0 -20
@@ -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) {
@@ -4454,7 +4435,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