summaryrefslogtreecommitdiffstats
path: root/block.c
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy2022-07-26 22:11:21 +0200
committerKevin Wolf2022-10-27 20:14:11 +0200
commit83930780325b144a5908c45b3957b9b6457b3831 (patch)
tree459cb7104d18ea3f5115bea5cbb56b7030176113 /block.c
parentblock: BlockDriver: add .filtered_child_is_backing field (diff)
downloadqemu-83930780325b144a5908c45b3957b9b6457b3831.tar.gz
qemu-83930780325b144a5908c45b3957b9b6457b3831.tar.xz
qemu-83930780325b144a5908c45b3957b9b6457b3831.zip
block: introduce bdrv_open_file_child() helper
Almost all drivers call bdrv_open_child() similarly. Let's create a helper for this. The only not updated drivers that call bdrv_open_child() to set bs->file are raw-format and snapshot-access: raw-format sometimes want to have filtered child but don't set drv->is_filter to true. snapshot-access wants only DATA | PRIMARY Possibly we should implement drv->is_filter_func() handler, to consider raw-format as filter when it works as filter.. But it's another story. Note also, that we decrease assignments to bs->file in code: it helps us restrict modifying this field in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Message-Id: <20220726201134.924743-3-vsementsov@yandex-team.ru> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/block.c b/block.c
index c8374dac4f..25a596a612 100644
--- a/block.c
+++ b/block.c
@@ -3674,6 +3674,27 @@ BdrvChild *bdrv_open_child(const char *filename,
}
/*
+ * Wrapper on bdrv_open_child() for most popular case: open primary child of bs.
+ */
+int bdrv_open_file_child(const char *filename,
+ QDict *options, const char *bdref_key,
+ BlockDriverState *parent, Error **errp)
+{
+ BdrvChildRole role;
+
+ /* commit_top and mirror_top don't use this function */
+ assert(!parent->drv->filtered_child_is_backing);
+
+ role = parent->drv->is_filter ?
+ (BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY) : BDRV_CHILD_IMAGE;
+
+ parent->file = bdrv_open_child(filename, options, bdref_key, parent,
+ &child_of_bds, role, false, errp);
+
+ return parent->file ? 0 : -EINVAL;
+}
+
+/*
* TODO Future callers may need to specify parent/child_class in order for
* option inheritance to work. Existing callers use it for the root node.
*/