diff mbox

[v3,1/2] qdev: add qdev_build_hotpluggable_device_list helper

Message ID a1810c66456b36a391778c5ac5f7b3c5b86ede46.1412594742.git.zhugh.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhu Guihua Oct. 6, 2014, 11:38 a.m. UTC
For peripheral device del completion, add a function to build a list for
hotpluggable devices.

Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
---
 hw/core/qdev.c         | 14 ++++++++++++++
 include/hw/qdev-core.h |  2 ++
 2 files changed, 16 insertions(+)

Comments

Igor Mammedov Oct. 16, 2014, 11:42 a.m. UTC | #1
On Mon, 6 Oct 2014 19:38:43 +0800
Zhu Guihua <zhugh.fnst@cn.fujitsu.com> wrote:

> For peripheral device del completion, add a function to build a list
> for hotpluggable devices.
> 
> Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
> ---
>  hw/core/qdev.c         | 14 ++++++++++++++
>  include/hw/qdev-core.h |  2 ++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index fcb1638..5f4b2b9 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -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.

> +        *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);
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index 178fee2..aa76fdc 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -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)
>  {
diff mbox

Patch

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index fcb1638..5f4b2b9 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -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);
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 178fee2..aa76fdc 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -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)
 {