[PATCH 6/8] qdev: realize BlockParentClass

Markus Armbruster armbru at redhat.com
Mon Sep 20 06:08:28 UTC 2021


Vladimir Sementsov-Ogievskiy <vsementsov at virtuozzo.com> writes:

> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov at 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);




More information about the libvir-list mailing list