[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 27/36] block: make bdrv_refresh_limits() to be a transaction a
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 27/36] block: make bdrv_refresh_limits() to be a transaction action |
Date: |
Wed, 17 Mar 2021 17:35:20 +0300 |
To be used in further commit.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
include/block/block.h | 3 ++-
block.c | 9 ++++-----
block/io.c | 31 +++++++++++++++++++++++++++++--
3 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/include/block/block.h b/include/block/block.h
index 85481a05c6..ad38259c91 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -9,6 +9,7 @@
#include "block/dirty-bitmap.h"
#include "block/blockjob.h"
#include "qemu/hbitmap.h"
+#include "qemu/transactions.h"
/*
* generated_co_wrapper
@@ -421,7 +422,7 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts,
BlockDriverState *in_bs, Error **errp);
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
-void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
+void bdrv_refresh_limits(BlockDriverState *bs, Transaction *tran, Error
**errp);
int bdrv_commit(BlockDriverState *bs);
int bdrv_make_empty(BdrvChild *c, Error **errp);
int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file,
diff --git a/block.c b/block.c
index 3b9681a738..03a1f02e5b 100644
--- a/block.c
+++ b/block.c
@@ -49,7 +49,6 @@
#include "qemu/timer.h"
#include "qemu/cutils.h"
#include "qemu/id.h"
-#include "qemu/transactions.h"
#include "block/coroutines.h"
#ifdef CONFIG_BSD
@@ -1543,7 +1542,7 @@ static int bdrv_open_driver(BlockDriverState *bs,
BlockDriver *drv,
return ret;
}
- bdrv_refresh_limits(bs, &local_err);
+ bdrv_refresh_limits(bs, NULL, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return -EINVAL;
@@ -3328,7 +3327,7 @@ int bdrv_set_backing_hd(BlockDriverState *bs,
BlockDriverState *backing_hd,
}
out:
- bdrv_refresh_limits(bs, NULL);
+ bdrv_refresh_limits(bs, NULL, NULL);
return ret;
}
@@ -4812,7 +4811,7 @@ static void bdrv_reopen_commit(BDRVReopenState
*reopen_state)
bdrv_set_backing_hd(bs, reopen_state->new_backing_bs, &error_abort);
}
- bdrv_refresh_limits(bs, NULL);
+ bdrv_refresh_limits(bs, NULL, NULL);
}
/*
@@ -5203,7 +5202,7 @@ int bdrv_append(BlockDriverState *bs_new,
BlockDriverState *bs_top,
out:
tran_finalize(tran, ret);
- bdrv_refresh_limits(bs_top, NULL);
+ bdrv_refresh_limits(bs_top, NULL, NULL);
return ret;
}
diff --git a/block/io.c b/block/io.c
index ca2dca3007..35b6c56efc 100644
--- a/block/io.c
+++ b/block/io.c
@@ -133,13 +133,40 @@ static void bdrv_merge_limits(BlockLimits *dst, const
BlockLimits *src)
dst->max_iov = MIN_NON_ZERO(dst->max_iov, src->max_iov);
}
-void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
+typedef struct BdrvRefreshLimitsState {
+ BlockDriverState *bs;
+ BlockLimits old_bl;
+} BdrvRefreshLimitsState;
+
+static void bdrv_refresh_limits_abort(void *opaque)
+{
+ BdrvRefreshLimitsState *s = opaque;
+
+ s->bs->bl = s->old_bl;
+}
+
+static TransactionActionDrv bdrv_refresh_limits_drv = {
+ .abort = bdrv_refresh_limits_abort,
+ .clean = g_free,
+};
+
+/* @tran is allowed to be NULL, in this case no rollback is possible. */
+void bdrv_refresh_limits(BlockDriverState *bs, Transaction *tran, Error **errp)
{
ERRP_GUARD();
BlockDriver *drv = bs->drv;
BdrvChild *c;
bool have_limits;
+ if (tran) {
+ BdrvRefreshLimitsState *s = g_new(BdrvRefreshLimitsState, 1);
+ *s = (BdrvRefreshLimitsState) {
+ .bs = bs,
+ .old_bl = bs->bl,
+ };
+ tran_add(tran, &bdrv_refresh_limits_drv, s);
+ }
+
memset(&bs->bl, 0, sizeof(bs->bl));
if (!drv) {
@@ -156,7 +183,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error **errp)
QLIST_FOREACH(c, &bs->children, next) {
if (c->role & (BDRV_CHILD_DATA | BDRV_CHILD_FILTERED | BDRV_CHILD_COW))
{
- bdrv_refresh_limits(c->bs, errp);
+ bdrv_refresh_limits(c->bs, tran, errp);
if (*errp) {
return;
}
--
2.29.2
- [PATCH v3 17/36] block: fix bdrv_replace_node_common, (continued)
- [PATCH v3 17/36] block: fix bdrv_replace_node_common, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 13/36] block: use topological sort for permission update, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 19/36] block: add bdrv_attach_child_noperm() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 20/36] block: split out bdrv_replace_node_noperm(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 21/36] block: adapt bdrv_append() for inserting filters, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 18/36] block: add bdrv_attach_child_common() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 14/36] block: add bdrv_drv_set_perm transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 25/36] block: drop ignore_children for permission update functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 23/36] block: introduce bdrv_drop_filter(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 22/36] block: add bdrv_remove_filter_or_cow transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 27/36] block: make bdrv_refresh_limits() to be a transaction action,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v3 32/36] block: inline bdrv_check_perm_common(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 26/36] block: make bdrv_unset_inherits_from to be a transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 24/36] block/backup-top: drop .active, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 28/36] block: add bdrv_set_backing_noperm() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 15/36] block: add bdrv_list_* permission update functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 16/36] block: add bdrv_replace_child_safe() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 29/36] block: bdrv_reopen_multiple(): move bdrv_flush to separate pre-prepare, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 30/36] block: bdrv_reopen_multiple: refresh permissions on updated graph, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 31/36] block: drop unused permission update functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 33/36] block: inline bdrv_replace_child(), Vladimir Sementsov-Ogievskiy, 2021/03/17