[PATCH 6/8] qdev: realize BlockParentClass

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@xxxxxxxxxxxxx>
---
 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);
+        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);
-- 
2.29.2





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux