[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/8] block/export: realize BlockParentClass functionality
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH 4/8] block/export: realize BlockParentClass functionality |
Date: |
Mon, 2 Aug 2021 21:54:12 +0300 |
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/export/export.c | 44 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/block/export/export.c b/block/export/export.c
index 6d3b9964c8..39b45feafe 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -14,6 +14,7 @@
#include "qemu/osdep.h"
#include "block/block.h"
+#include "block/block-parent.h"
#include "sysemu/block-backend.h"
#include "sysemu/iothread.h"
#include "block/export.h"
@@ -362,3 +363,46 @@ BlockExportInfoList *qmp_query_block_exports(Error **errp)
return head;
}
+
+static int blk_exp_find_child(const char *parent_id, const char *child_name,
+ BlockDriverState *child_bs,
+ BdrvChild **child, Error **errp)
+{
+ BlockExport *exp;
+
+ exp = blk_exp_find(parent_id);
+ if (exp == NULL) {
+ return 0;
+ }
+
+ if (child_name && strcmp(child_name, "root")) {
+ error_setg(errp, "Block export may have only 'root' child");
+ return -EINVAL;
+ }
+
+ if (!exp->blk || !blk_root(exp->blk)) {
+ error_setg(errp, "Export '%s' does not have a block driver child",
+ parent_id);
+ return -EINVAL;
+ }
+
+ if (child_bs && blk_bs(exp->blk) != child_bs) {
+ error_setg(errp, "Export '%s' root child doesn't match", parent_id);
+ return -EINVAL;
+ }
+
+ *child = blk_root(exp->blk);
+ return 1;
+}
+
+BlockParentClass block_parent_export = {
+ .name = "block export",
+ .find_child = blk_exp_find_child,
+};
+
+static void export_init(void)
+{
+ block_parent_class_register(&block_parent_export);
+}
+
+block_init(export_init);
--
2.29.2
- [PATCH RFC 0/8] blockdev-replace, Vladimir Sementsov-Ogievskiy, 2021/08/02
- [PATCH 2/8] block: add BlockParentClass class, Vladimir Sementsov-Ogievskiy, 2021/08/02
- [PATCH 1/8] block-backend: blk_root(): drop const specifier on return type, Vladimir Sementsov-Ogievskiy, 2021/08/02
- [PATCH 3/8] block: realize BlockParentClass for BlockDriverState, Vladimir Sementsov-Ogievskiy, 2021/08/02
- [PATCH 5/8] qdev: improve find_device_state() to distinguish simple not found case, Vladimir Sementsov-Ogievskiy, 2021/08/02
- [PATCH 4/8] block/export: realize BlockParentClass functionality,
Vladimir Sementsov-Ogievskiy <=
- [PATCH 6/8] qdev: realize BlockParentClass, Vladimir Sementsov-Ogievskiy, 2021/08/02
- [PATCH 7/8] block: improve bdrv_replace_node_noperm(), Vladimir Sementsov-Ogievskiy, 2021/08/02
- [PATCH 8/8] qapi: add blockdev-replace command, Vladimir Sementsov-Ogievskiy, 2021/08/02