diff mbox series

[6/8] qdev: realize BlockParentClass

Message ID 20210802185416.50877-7-vsementsov@virtuozzo.com
State New
Headers show
Series blockdev-replace | expand

Commit Message

Vladimir Sementsov-Ogievskiy Aug. 2, 2021, 6:54 p.m. UTC
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 softmmu/qdev-monitor.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Comments

Markus Armbruster Sept. 20, 2021, 6:08 a.m. UTC | #1
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:

> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  softmmu/qdev-monitor.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
>
> diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
> index 0117989009..2e149aa9b8 100644
> --- a/softmmu/qdev-monitor.c
> +++ b/softmmu/qdev-monitor.c
> @@ -18,6 +18,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "block/block-parent.h"
>  #include "hw/sysbus.h"
>  #include "monitor/hmp.h"
>  #include "monitor/monitor.h"
> @@ -1023,3 +1024,44 @@ bool qmp_command_available(const QmpCommand *cmd, Error **errp)
>      }
>      return true;
>  }
> +
> +static int qdev_find_child(const char *parent_id, const char *child_name,
> +                           BlockDriverState *child_bs,
> +                           BdrvChild **child, Error **errp)
> +{
> +    int ret;
> +    DeviceState *dev;
> +    BlockBackend *blk;
> +
> +    ret = find_device_state(parent_id, &dev, errp);
> +    if (ret <= 0) {
> +        return ret;
> +    }
> +
> +    blk = blk_by_dev(dev);
> +    if (!blk || !blk_root(blk)) {
> +        error_setg(errp, "Device '%s' does not have a block device backend",
> +                   parent_id);
> +        return -EINVAL;
> +    }
> +
> +    if (child_bs && blk_bs(blk) != child_bs) {
> +        error_setg(errp, "Root child of device '%s' doesn't match", parent_id);

What is a "root child", and why would a user care?

The contract missing in PATCH 2 leaves me floundering.

> +        return -EINVAL;
> +    }
> +
> +    *child = blk_root(blk);
> +    return 1;
> +}
> +
> +BlockParentClass block_parent_qdev = {
> +    .name = "qdev",
> +    .find_child = qdev_find_child,
> +};
> +
> +static void qdev_monitor_init(void)
> +{
> +    block_parent_class_register(&block_parent_qdev);
> +}
> +
> +block_init(qdev_monitor_init);
diff mbox series

Patch

diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 0117989009..2e149aa9b8 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -18,6 +18,7 @@ 
  */
 
 #include "qemu/osdep.h"
+#include "block/block-parent.h"
 #include "hw/sysbus.h"
 #include "monitor/hmp.h"
 #include "monitor/monitor.h"
@@ -1023,3 +1024,44 @@  bool qmp_command_available(const QmpCommand *cmd, Error **errp)
     }
     return true;
 }
+
+static int qdev_find_child(const char *parent_id, const char *child_name,
+                           BlockDriverState *child_bs,
+                           BdrvChild **child, Error **errp)
+{
+    int ret;
+    DeviceState *dev;
+    BlockBackend *blk;
+
+    ret = find_device_state(parent_id, &dev, errp);
+    if (ret <= 0) {
+        return ret;
+    }
+
+    blk = blk_by_dev(dev);
+    if (!blk || !blk_root(blk)) {
+        error_setg(errp, "Device '%s' does not have a block device backend",
+                   parent_id);
+        return -EINVAL;
+    }
+
+    if (child_bs && blk_bs(blk) != child_bs) {
+        error_setg(errp, "Root child of device '%s' doesn't match", parent_id);
+        return -EINVAL;
+    }
+
+    *child = blk_root(blk);
+    return 1;
+}
+
+BlockParentClass block_parent_qdev = {
+    .name = "qdev",
+    .find_child = qdev_find_child,
+};
+
+static void qdev_monitor_init(void)
+{
+    block_parent_class_register(&block_parent_qdev);
+}
+
+block_init(qdev_monitor_init);