monitor: add peripheral device del completion support
v3 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.
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 (2):
qdev: add qdev_build_hotpluggable_device_list helper
monitor: add del completion for peripheral device
hw/core/qdev.c | 14 ++++++++++++++ include/hw/qdev-core.h | 2 ++ monitor.c | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+)
Signature · 1 line
1.9.3
PATCH v3 1/2 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 | 14 ++++++++++++++ include/hw/qdev-core.h | 2 ++ 2 files changed, 16 insertions(+)
hw/core/qdev.c +14 -0
@@ -801,6 +801,20 @@ 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); +DeviceClass *dc =DEVICE_GET_CLASS (dev); + +if (dev->realized && dc->hotpluggable) { + *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
@@ -361,6 +361,8 @@ extern int qdev_hotplug;char *qdev_get_dev_path (DeviceState *dev); +int qdev_build_hotpluggable_device_list (Object *obj,void *opaque); +static inline void qbus_set_hotplug_handler (BusState *bus,DeviceState *handler,Error **errp) {
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v3 1/2] qdev: add qdev_build_hotpluggable_device_list helper
Quoted 14 lines · On Mon, 6 Oct 2014 19:38:43 +0800 Zhu Guihua <[email protected]> wrote:
For peripheral device del completion, add a function to build a list for hotpluggable devices.
Signed-off-by Zhu Guihua <[email protected]>--- hw/core/qdev.c | 14 ++++++++++++++ include/hw/qdev-core.h | 2 ++ 2 files changed, 16 insertions(+)hw/core/qdev.c +0
-0
hw/core/qdev.c void qdev_alias_all_properties(DeviceState · line 810
Quoted 10 lines
hw/core/qdev.c +7
-0@@ -801,6 +801,20 @@ 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); +DeviceClass *dc =DEVICE_GET_CLASS (dev); + +if (dev->realized && dc->hotpluggable) {
pls use object_property_get_bool() to get value of hotpluggable property since it's might not be enough to have dc->hotpluggable set to true to be hotpluggable.
Quoted 24 lines
hw/core/qdev.c +7
-0+ *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@@ -361,6 +361,8 @@ extern int qdev_hotplug;char *qdev_get_dev_path (DeviceState *dev); +int qdev_build_hotpluggable_device_list (Object *obj,void *opaque); +static inline void qbus_set_hotplug_handler (BusState *bus,DeviceState *handler,Error **errp) {
PATCH v3 2/2 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
@@ -4351,6 +4351,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 (!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 +4447,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 v3 2/2] monitor: add del completion for peripheral device
Quoted 14 lines · On Mon, 6 Oct 2014 19:38:44 +0800 Zhu Guihua <[email protected]> wrote:
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 +0
-0@@ -4351,6 +4351,29 @@ static void device_del_bus_completion(ReadLineState *rs, BusState *bus, }
monitor.c static void · line 4361
Quoted 10 lines
monitor.c +7
-0} +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 ); +
pls remove unnecessary blank line
monitor.c static void device_del_bus_completion(ReadLineState *rs, BusState *bus, · line 4370
Quoted 10 lines
monitor.c +9
-0+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;
add blank line here, pls.
monitor.c void device_del_completion(ReadLineState *rs, · line 4449
Quoted 13 lines
monitor.c +6
-0+if (!strncmp (str, dev->id, len)) { +readline_add_completion (rs, dev->id); + } + } +} + void chardev_remove_completion(ReadLineState *rs, int nb_args, constchar *str) { size_t len;monitor.c +0
-0@@ -4424,6 +4447,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);
All ID-ed devices that might be available for removal are returned by following line, so do we still need above recusive bus walker that gathers duplicate devices from buses?
Quoted 5 lines
monitor.c +1
-0+peripheral_device_del_completion (rs, str, len); } void object_del_completion(ReadLineState *rs, int nb_args, constchar *str)
Re: [Qemu-devel] [PATCH v3 2/2] monitor: add del completion for peripheral device
Quoted 41 lines · Igor Mammedov
Quoted 14 lines · On Mon, 6 Oct 2014 19:38:44 +0800 Zhu Guihua <[email protected]> wrote:
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 +0
-0@@ -4351,6 +4351,29 @@ static void device_del_bus_completion(ReadLineState *rs, BusState *bus, }monitor.c static void · line 4361
Quoted 10 lines
monitor.c +7
-0} +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 ); +pls remove unnecessary blank line
monitor.c static void device_del_bus_completion(ReadLineState *rs, BusState *bus, · line 4370
Quoted 10 lines
monitor.c +9
-0+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;add blank line here, pls.
Quoted 17 lines
monitor.c void device_del_completion(ReadLineState *rs, · line 4449
Quoted 13 lines
monitor.c +6
-0+if (!strncmp (str, dev->id, len)) { +readline_add_completion (rs, dev->id); + } + } +} + void chardev_remove_completion(ReadLineState *rs, int nb_args, constchar *str) { size_t len;monitor.c +0
-0@@ -4424,6 +4447,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);All ID-ed devices that might be available for removal are returned by following line, so do we still need above recusive bus walker that gathers duplicate devices from buses?
yeah, we do not need recursive bus walker any more. I will change it, thanks.
Regards,
Zhu
Quoted 6 lines
Quoted 5 lines
monitor.c +1
-0+peripheral_device_del_completion (rs, str, len); } void object_del_completion(ReadLineState *rs, int nb_args, constchar *str)
ping...
Quoted 22 lines · Zhu Guihua
After inputting
device_delcommand 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.v3:
- commit message changes (Igor)
- rename function in patch 1 (Igor)
- use 'hotpluggable' property to discard non-hotpluggable devices (Igor)v2:
- useobject_child_foreach()to simplify the implementation (Andreas)Zhu Guihua (2):
qdev: addqdev_build_hotpluggable_device_listhelper
monitor: add del completion for peripheral devicehw/core/qdev.c | 14 ++++++++++++++ include/hw/qdev-core.h | 2 ++ monitor.c | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+)