[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 44/45] block: bdrv_open_inherit: create BlockBackend only when
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v5 44/45] block: bdrv_open_inherit: create BlockBackend only when necessary |
Date: |
Thu, 31 Mar 2022 00:29:01 +0300 |
We need this blk only for probing - let's create it only when we are
going to probe.
That's significant for further changes: we'll need to avoid permission
update during open() when possible (to refresh them later of course).
But blk_unref() leads to permission update. Instead of implementing
extra logic to avoid permission update during blk_unref when we want
it, let's just drop blk_unref() from normal code path.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
---
block.c | 48 +++++++++++++++++++++++++-----------------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/block.c b/block.c
index 40f54fe121..5a4b59eb6c 100644
--- a/block.c
+++ b/block.c
@@ -1821,7 +1821,7 @@ QemuOptsList bdrv_create_opts_simple = {
*
* Removes all processed options from *options.
*/
-static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
+static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
QDict *options, Error **errp)
{
int ret, open_flags;
@@ -1861,8 +1861,8 @@ static int bdrv_open_common(BlockDriverState *bs,
BlockBackend *file,
}
if (file != NULL) {
- bdrv_refresh_filename(blk_bs(file));
- filename = blk_bs(file)->filename;
+ bdrv_refresh_filename(file);
+ filename = file->filename;
} else {
/*
* Caution: while qdict_get_try_str() is fine, getting
@@ -3883,7 +3883,7 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
Error **errp)
{
int ret;
- BlockBackend *file = NULL;
+ BlockDriverState *file_bs = NULL;
BlockDriverState *bs;
BlockDriver *drv = NULL;
BdrvChild *child;
@@ -4016,8 +4016,6 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
* probing, the block drivers will do their own bdrv_open_child() for the
* same BDS, which is why we put the node name back into options. */
if ((flags & BDRV_O_PROTOCOL) == 0) {
- BlockDriverState *file_bs;
-
file_bs = bdrv_open_child_bs(filename, options, "file", bs,
&child_of_bds, BDRV_CHILD_IMAGE,
true, &local_err);
@@ -4025,24 +4023,28 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
goto fail;
}
if (file_bs != NULL) {
- /* Not requesting BLK_PERM_CONSISTENT_READ because we're only
- * looking at the header to guess the image format. This works even
- * in cases where a guest would not see a consistent state. */
- file = blk_new(bdrv_get_aio_context(file_bs), 0, BLK_PERM_ALL);
- blk_insert_bs(file, file_bs, &local_err);
- bdrv_unref(file_bs);
- if (local_err) {
- goto fail;
- }
-
qdict_put_str(options, "file", bdrv_get_node_name(file_bs));
}
}
/* Image format probing */
bs->probed = !drv;
- if (!drv && file) {
+ if (!drv && file_bs) {
+ /*
+ * Not requesting BLK_PERM_CONSISTENT_READ because we're only
+ * looking at the header to guess the image format. This works even
+ * in cases where a guest would not see a consistent state.
+ */
+ BlockBackend *file = blk_new(bdrv_get_aio_context(file_bs), 0,
+ BLK_PERM_ALL);
+ blk_insert_bs(file, file_bs, &local_err);
+ if (local_err) {
+ blk_unref(file);
+ goto fail;
+ }
+
ret = find_image_format(file, filename, &drv, &local_err);
+ blk_unref(file);
if (ret < 0) {
goto fail;
}
@@ -4068,17 +4070,17 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
assert(!!(flags & BDRV_O_PROTOCOL) == !!drv->bdrv_file_open);
/* file must be NULL if a protocol BDS is about to be created
* (the inverse results in an error message from bdrv_open_common()) */
- assert(!(flags & BDRV_O_PROTOCOL) || !file);
+ assert(!(flags & BDRV_O_PROTOCOL) || !file_bs);
/* Open the image */
- ret = bdrv_open_common(bs, file, options, &local_err);
+ ret = bdrv_open_common(bs, file_bs, options, &local_err);
if (ret < 0) {
goto fail;
}
- if (file) {
- blk_unref(file);
- file = NULL;
+ if (file_bs) {
+ bdrv_unref(file_bs);
+ file_bs = NULL;
}
/* If there is a backing file, use it */
@@ -4142,7 +4144,7 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
return bs;
fail:
- blk_unref(file);
+ bdrv_unref(file_bs);
qobject_unref(snapshot_options);
qobject_unref(bs->explicit_options);
qobject_unref(bs->options);
--
2.35.1
- [PATCH v5 19/45] block: refactor bdrv_list_refresh_perms to allow any list of nodes, (continued)
- [PATCH v5 19/45] block: refactor bdrv_list_refresh_perms to allow any list of nodes, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 22/45] block: implemet bdrv_unref_tran(), Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 23/45] blockdev: refactor transaction to use Transaction API, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 26/45] blockdev: transaction: refactor handling transaction properties, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 25/45] blockdev: qmp_transaction: refactor loop to classic for, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 29/45] block: introduce BDRV_O_NOPERM flag, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 35/45] block: make bdrv_find_child() function public, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 36/45] block: bdrv_replace_child_bs(): move to external transaction, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 32/45] iotests: add blockdev-add-transaction, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 39/45] block: bdrv_get_xdbg_block_graph(): report export ids, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 44/45] block: bdrv_open_inherit: create BlockBackend only when necessary,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v5 07/45] block: document connection between child roles and bs->backing/bs->file, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 10/45] Revert "block: Let replace_child_tran keep indirect pointer", Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 14/45] block/snapshot: drop indirection around bdrv_snapshot_fallback_ptr, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 15/45] block: refactor bdrv_remove_file_or_backing_child to bdrv_remove_child, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 20/45] block: make permission update functions public, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 24/45] blockdev: transactions: rename some things, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 27/45] blockdev: qmp_transaction: drop extra generic layer, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 28/45] qapi: block: add blockdev-del transaction action, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 30/45] block: bdrv_insert_node(): use BDRV_O_NOPERM, Vladimir Sementsov-Ogievskiy, 2022/03/30
- [PATCH v5 31/45] qapi: block: add blockdev-add transaction action, Vladimir Sementsov-Ogievskiy, 2022/03/30