monitor: add peripheral device del completion support
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.
Zhu Guihua (3):
qom: add function to get opaque property in ObjectProperty
qom: export object_property_is_child()
monitor: add del completion for peripheral device
include/qom/object.h | 2 ++ monitor.c | 24 ++++++++++++++++++++++++ qom/object.c | 11 ++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-)
Signature · 1 line
1.9.3
PATCH 1/3 qom: add function to get opaque property in ObjectProperty
Add object_property_get_opaque() to get opaque property in ObjectProperty.
--- include/qom/object.h | 1 + qom/object.c | 9 +++++++++ 2 files changed, 10 insertions(+)
include/qom/object.h +1 -0
@@ -1300,5 +1300,6 @@ int object_child_foreach(Object *obj, int (*fn)(Object *child, void *opaque),*/ Object *container_get (Object *root,const char *path); +void *object_property_get_opaque (ObjectProperty *prop,Error **errp);#endif
qom/object.c +9 -0
@@ -356,6 +356,15 @@ static inline bool object_property_is_child(ObjectProperty *prop)return strstart (prop->type,"child<" ,NULL ); } +void *object_property_get_opaque (ObjectProperty *prop,Error **errp) +{ +if (prop ==NULL ) { +return NULL ; + } + +return prop->opaque; +} +static void object_property_del_all (Object *obj) {while (!QTAILQ_EMPTY (&obj->properties)) {
Signature · 1 line
1.9.3
PATCH 2/3 qom: export object_property_is_child()
In reply to Zhu GuihuaExport object_property_is_child() to let it be invoked in other places.
--- include/qom/object.h | 1 + qom/object.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/qom/object.h +1 -0
@@ -1302,4 +1302,5 @@ Object *container_get(Object *root, const char *path);void *object_property_get_opaque (ObjectProperty *prop,Error **errp); +bool object_property_is_child (ObjectProperty *prop);#endif
qom/object.c +1 -1
@@ -351,7 +351,7 @@ void object_initialize(void *data, size_t size, const char *typename)object_initialize_with_type (data, size, type); } -static inline bool object_property_is_child (ObjectProperty *prop) +bool object_property_is_child (ObjectProperty *prop) {return strstart (prop->type,"child<" ,NULL ); }
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v1 2/3] qom: export object_property_is_child()
Am 18.09.2014 um 09:53 schrieb Zhu Guihua:
Quoted 13 lines
Export
object_property_is_child()to let it be invoked in other places.Signed-off-by Zhu Guihua <[email protected]>--- include/qom/object.h | 1 + qom/object.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)include/qom/object.h +0
-0
include/qom/object.h Object *container_get(Object *root, const char *path); · line 1305
Quoted 4 lines
include/qom/object.h +1
-0@@ -1302,4 +1302,5 @@ Object *container_get(Object *root, const char *path);void *object_property_get_opaque (ObjectProperty *prop,Error **errp); +bool object_property_is_child (ObjectProperty *prop);
You already dropped one white line in the previous patch, now you're leaving no spacing at all. Please always leave at least one before the header guard.
Regards,
Andreas
Quoted 15 lines
include/qom/object.h +0
-0#endif qom/object.c +1
-1@@ -351,7 +351,7 @@ void object_initialize(void *data, size_t size, const char *typename)object_initialize_with_type (data, size, type); } -static inline bool object_property_is_child (ObjectProperty *prop) +bool object_property_is_child (ObjectProperty *prop) {return strstart (prop->type,"child<" ,NULL ); }
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH 3/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
@@ -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; +DeviceState *dev =NULL ; +ObjectProperty *prop; + + peripheral =object_resolve_path ("/machine/peripheral/" ,NULL ); + +if (peripheral ==NULL ) { +return ; + } + + QTAILQ_FOREACH(prop, &peripheral->properties, node) { +if (object_property_is_child (prop)) { + dev =DEVICE (object_property_get_opaque (prop,NULL )); +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;
@@ -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 v1 3/3] monitor: add del completion for peripheral device
Hi,
Am 18.09.2014 um 09:53 schrieb Zhu Guihua:
Quoted 22 lines
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 +6
-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; +DeviceState *dev =NULL ; +ObjectProperty *prop;
monitor.c static void device_del_bus_completion(ReadLineState *rs, BusState *bus, · line 4369
Quoted 10 lines
monitor.c +10
-0+ + peripheral =object_resolve_path ("/machine/peripheral/" ,NULL ); + +if (peripheral ==NULL ) { +return ; + } + + QTAILQ_FOREACH(prop, &peripheral->properties, node) { +if (object_property_is_child (prop)) { + dev =DEVICE (object_property_get_opaque (prop,NULL ));
Why so complicated? Can't you use object_child_foreach()? That would obsolete patches 1-2, leaving the gory details in QOM code and making this a monitor-only series.
monitor.c static void device_del_bus_completion(ReadLineState *rs, BusState *bus, · line 4370
Quoted 1 line
monitor.c +1
-0+if (dev->id && !strncmp (str, dev->id, len)) {
All devices in /machine/peripheral/ should have an id, but better safe than sorry. :)
If you do respin, I'd have a preference for strncmp() == 0 for clarity.
Quoted 10 lines
monitor.c +6
-0+readline_add_completion (rs, dev->id); + } + } + } +} +void chardev_remove_completion (ReadLineState *rs,int nb_args,const char *str) {size_t len;
monitor.c void device_del_completion(ReadLineState *rs, int nb_args, const char *str) · line 4453
Quoted 7 lines
monitor.c +1
-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); +peripheral_device_del_completion (rs, str, len); }void object_del_completion (ReadLineState *rs,int nb_args,const char *str)
Whether these two are correct, would then just need to be reviewed by someone who knows about completion (not me).
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH v1 3/3] monitor: add del completion for peripheral device
In reply to Zhu GuihuaQuoted 43 lines · On Thu, 18 Sep 2014 15:53:21 +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 +23
-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; +DeviceState *dev =NULL ; +ObjectProperty *prop; + + peripheral =object_resolve_path ("/machine/peripheral/" ,NULL ); + +if (peripheral ==NULL ) { +return ; + } + + QTAILQ_FOREACH(prop, &peripheral->properties, node) { +if (object_property_is_child (prop)) { + dev =DEVICE (object_property_get_opaque (prop,NULL )); +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;
monitor.c void device_del_completion(ReadLineState *rs, int nb_args, const char *str) · line 4451
Quoted 5 lines
monitor.c +1
-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); +peripheral_device_del_completion (rs, str, len); }
The series intro email mentions device_del, but this is added to chardev-remove. Is there a reason for this?
Hani, could you please review this series?
Quoted 2 lines
monitor.c +0
-0void object_del_completion (ReadLineState *rs,int nb_args,const char *str)
Re: [Qemu-devel] [PATCH v1 3/3] monitor: add del completion for peripheral device
Quoted 46 lines · On Fri, 26 Sep 2014 13:25:45 -0400 Luiz Capitulino <[email protected]>…
Quoted 43 lines · On Thu, 18 Sep 2014 15:53:21 +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 +23
-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; +DeviceState *dev =NULL ; +ObjectProperty *prop; + + peripheral =object_resolve_path ("/machine/peripheral/" ,NULL ); + +if (peripheral ==NULL ) { +return ; + } + + QTAILQ_FOREACH(prop, &peripheral->properties, node) { +if (object_property_is_child (prop)) { + dev =DEVICE (object_property_get_opaque (prop,NULL )); +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;@@ -4424,6 +4447,7 @@ void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
Quoted 8 lines
monitor.c void device_del_completion(ReadLineState *rs, int nb_args, const char *str) · line 4451
Quoted 5 lines
monitor.c +1
-0len =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); }The series intro email mentions
device_del, but this is added to chardev-remove. Is there a reason for this?
Turns out this is not added to chardev_remove_completion(), looked too quickly. In any case, would be nice to have Hani's review.
Quoted 6 lines
Hani, could you please review this series?
Quoted 2 lines
monitor.c +0
-0void object_del_completion (ReadLineState *rs,int nb_args,const char *str)
Re: [Qemu-devel] [PATCH v1 3/3] monitor: add del completion for peripheral device
Quoted 58 lines · Luiz Capitulino
Quoted 46 lines · On Fri, 26 Sep 2014 13:25:45 -0400 Luiz Capitulino <[email protected]>…
Quoted 43 lines · On Thu, 18 Sep 2014 15:53:21 +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 +23
-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; +DeviceState *dev =NULL ; +ObjectProperty *prop; + + peripheral =object_resolve_path ("/machine/peripheral/" ,NULL ); + +if (peripheral ==NULL ) { +return ; + } + + QTAILQ_FOREACH(prop, &peripheral->properties, node) { +if (object_property_is_child (prop)) { + dev =DEVICE (object_property_get_opaque (prop,NULL )); +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;@@ -4424,6 +4447,7 @@ void device_del_completion(ReadLineState *rs, int nb_args, const char *str)Quoted 8 lines
monitor.c void device_del_completion(ReadLineState *rs, int nb_args, const char *str) · line 4451
Quoted 5 lines
monitor.c +1
-0len =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); }The series intro email mentions
device_del, but this is added to chardev-remove. Is there a reason for this?
Quoted 2 lines
Turns out this is not added to
chardev_remove_completion(), looked too quickly. In any case, would be nice to have Hani's review.
Hi,
I'm wrestling with my ISP at the moment. Will get back to these as soon as possible
Thanks.
Quoted 8 lines
Quoted 7 lines
Hani, could you please review this series?
Quoted 2 lines
monitor.c +0
-0void object_del_completion (ReadLineState *rs,int nb_args,const char *str)
ping ...
Quoted 14 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.Zhu Guihua (3):
qom: add function to get opaque property in ObjectProperty
qom: exportobject_property_is_child()
monitor: add del completion for peripheral deviceinclude/qom/object.h | 2 ++ monitor.c | 24 ++++++++++++++++++++++++ qom/object.c | 11 ++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-)