mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-01 06:21:52 -06:00
block: refactor bdrv_child* permission functions
Split out non-recursive parts, and refactor as block graph transaction action. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20210428151804.439460-11-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
3bf416ba0f
commit
b0defa8356
1 changed files with 59 additions and 20 deletions
79
block.c
79
block.c
|
@ -49,6 +49,7 @@
|
||||||
#include "qemu/timer.h"
|
#include "qemu/timer.h"
|
||||||
#include "qemu/cutils.h"
|
#include "qemu/cutils.h"
|
||||||
#include "qemu/id.h"
|
#include "qemu/id.h"
|
||||||
|
#include "qemu/transactions.h"
|
||||||
#include "block/coroutines.h"
|
#include "block/coroutines.h"
|
||||||
|
|
||||||
#ifdef CONFIG_BSD
|
#ifdef CONFIG_BSD
|
||||||
|
@ -2093,6 +2094,61 @@ static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bdrv_child_set_perm_commit(void *opaque)
|
||||||
|
{
|
||||||
|
BdrvChild *c = opaque;
|
||||||
|
|
||||||
|
c->has_backup_perm = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bdrv_child_set_perm_abort(void *opaque)
|
||||||
|
{
|
||||||
|
BdrvChild *c = opaque;
|
||||||
|
/*
|
||||||
|
* We may have child->has_backup_perm unset at this point, as in case of
|
||||||
|
* _check_ stage of permission update failure we may _check_ not the whole
|
||||||
|
* subtree. Still, _abort_ is called on the whole subtree anyway.
|
||||||
|
*/
|
||||||
|
if (c->has_backup_perm) {
|
||||||
|
c->perm = c->backup_perm;
|
||||||
|
c->shared_perm = c->backup_shared_perm;
|
||||||
|
c->has_backup_perm = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static TransactionActionDrv bdrv_child_set_pem_drv = {
|
||||||
|
.abort = bdrv_child_set_perm_abort,
|
||||||
|
.commit = bdrv_child_set_perm_commit,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* With tran=NULL needs to be followed by direct call to either
|
||||||
|
* bdrv_child_set_perm_commit() or bdrv_child_set_perm_abort().
|
||||||
|
*
|
||||||
|
* With non-NULL tran needs to be followed by tran_abort() or tran_commit()
|
||||||
|
* instead.
|
||||||
|
*/
|
||||||
|
static void bdrv_child_set_perm_safe(BdrvChild *c, uint64_t perm,
|
||||||
|
uint64_t shared, Transaction *tran)
|
||||||
|
{
|
||||||
|
if (!c->has_backup_perm) {
|
||||||
|
c->has_backup_perm = true;
|
||||||
|
c->backup_perm = c->perm;
|
||||||
|
c->backup_shared_perm = c->shared_perm;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Note: it's OK if c->has_backup_perm was already set, as we can find the
|
||||||
|
* same c twice during check_perm procedure
|
||||||
|
*/
|
||||||
|
|
||||||
|
c->perm = perm;
|
||||||
|
c->shared_perm = shared;
|
||||||
|
|
||||||
|
if (tran) {
|
||||||
|
tran_add(tran, &bdrv_child_set_pem_drv, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether permissions on this node can be changed in a way that
|
* Check whether permissions on this node can be changed in a way that
|
||||||
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
|
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
|
||||||
|
@ -2358,37 +2414,20 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!c->has_backup_perm) {
|
bdrv_child_set_perm_safe(c, perm, shared, NULL);
|
||||||
c->has_backup_perm = true;
|
|
||||||
c->backup_perm = c->perm;
|
|
||||||
c->backup_shared_perm = c->shared_perm;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Note: it's OK if c->has_backup_perm was already set, as we can find the
|
|
||||||
* same child twice during check_perm procedure
|
|
||||||
*/
|
|
||||||
|
|
||||||
c->perm = perm;
|
|
||||||
c->shared_perm = shared;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bdrv_child_set_perm(BdrvChild *c)
|
static void bdrv_child_set_perm(BdrvChild *c)
|
||||||
{
|
{
|
||||||
c->has_backup_perm = false;
|
bdrv_child_set_perm_commit(c);
|
||||||
|
|
||||||
bdrv_set_perm(c->bs);
|
bdrv_set_perm(c->bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bdrv_child_abort_perm_update(BdrvChild *c)
|
static void bdrv_child_abort_perm_update(BdrvChild *c)
|
||||||
{
|
{
|
||||||
if (c->has_backup_perm) {
|
bdrv_child_set_perm_abort(c);
|
||||||
c->perm = c->backup_perm;
|
|
||||||
c->shared_perm = c->backup_shared_perm;
|
|
||||||
c->has_backup_perm = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bdrv_abort_perm_update(c->bs);
|
bdrv_abort_perm_update(c->bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue