monitor: add peripheral device del completion support
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
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
@@ -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
@@ -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
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.
Signed-off-by Zhu Guihua <[email protected]>--- hw/core/qdev.c | 13 +++++++++++++ include/hw/qdev-core.h | 2 ++ 2 files changed, 15 insertions(+)hw/core/qdev.c +0
-0
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@@ -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);
PATCH v2 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
monitor.c +23 -0
@@ -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