mirror of https://github.com/xqemu/xqemu.git
block: Add bdrv_subtree_drained_begin/end()
bdrv_drained_begin() waits for the completion of requests in the whole subtree, but it only actually keeps its immediate bs parameter quiesced until bdrv_drained_end(). Add a version that keeps the whole subtree drained. As of this commit, graph changes cannot be allowed during a subtree drained section, but this will be fixed soon. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
0152bf400f
commit
b016558590
54
block/io.c
54
block/io.c
|
@ -145,6 +145,7 @@ typedef struct {
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
bool done;
|
bool done;
|
||||||
bool begin;
|
bool begin;
|
||||||
|
bool recursive;
|
||||||
BdrvChild *parent;
|
BdrvChild *parent;
|
||||||
} BdrvCoDrainData;
|
} BdrvCoDrainData;
|
||||||
|
|
||||||
|
@ -218,8 +219,10 @@ static bool bdrv_drain_recurse(BlockDriverState *bs)
|
||||||
return waited;
|
return waited;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent);
|
static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
|
||||||
static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent);
|
BdrvChild *parent);
|
||||||
|
static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
|
||||||
|
BdrvChild *parent);
|
||||||
|
|
||||||
static void bdrv_co_drain_bh_cb(void *opaque)
|
static void bdrv_co_drain_bh_cb(void *opaque)
|
||||||
{
|
{
|
||||||
|
@ -229,9 +232,9 @@ static void bdrv_co_drain_bh_cb(void *opaque)
|
||||||
|
|
||||||
bdrv_dec_in_flight(bs);
|
bdrv_dec_in_flight(bs);
|
||||||
if (data->begin) {
|
if (data->begin) {
|
||||||
bdrv_do_drained_begin(bs, data->parent);
|
bdrv_do_drained_begin(bs, data->recursive, data->parent);
|
||||||
} else {
|
} else {
|
||||||
bdrv_do_drained_end(bs, data->parent);
|
bdrv_do_drained_end(bs, data->recursive, data->parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->done = true;
|
data->done = true;
|
||||||
|
@ -239,7 +242,8 @@ static void bdrv_co_drain_bh_cb(void *opaque)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
|
static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
|
||||||
bool begin, BdrvChild *parent)
|
bool begin, bool recursive,
|
||||||
|
BdrvChild *parent)
|
||||||
{
|
{
|
||||||
BdrvCoDrainData data;
|
BdrvCoDrainData data;
|
||||||
|
|
||||||
|
@ -253,6 +257,7 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
|
||||||
.bs = bs,
|
.bs = bs,
|
||||||
.done = false,
|
.done = false,
|
||||||
.begin = begin,
|
.begin = begin,
|
||||||
|
.recursive = recursive,
|
||||||
.parent = parent,
|
.parent = parent,
|
||||||
};
|
};
|
||||||
bdrv_inc_in_flight(bs);
|
bdrv_inc_in_flight(bs);
|
||||||
|
@ -265,10 +270,13 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
|
||||||
assert(data.done);
|
assert(data.done);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent)
|
static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive,
|
||||||
|
BdrvChild *parent)
|
||||||
{
|
{
|
||||||
|
BdrvChild *child, *next;
|
||||||
|
|
||||||
if (qemu_in_coroutine()) {
|
if (qemu_in_coroutine()) {
|
||||||
bdrv_co_yield_to_drain(bs, true, parent);
|
bdrv_co_yield_to_drain(bs, true, recursive, parent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,19 +288,32 @@ static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent)
|
||||||
bdrv_parent_drained_begin(bs, parent);
|
bdrv_parent_drained_begin(bs, parent);
|
||||||
bdrv_drain_invoke(bs, true, false);
|
bdrv_drain_invoke(bs, true, false);
|
||||||
bdrv_drain_recurse(bs);
|
bdrv_drain_recurse(bs);
|
||||||
|
|
||||||
|
if (recursive) {
|
||||||
|
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
|
||||||
|
bdrv_do_drained_begin(child->bs, true, child);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_drained_begin(BlockDriverState *bs)
|
void bdrv_drained_begin(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
bdrv_do_drained_begin(bs, NULL);
|
bdrv_do_drained_begin(bs, false, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent)
|
void bdrv_subtree_drained_begin(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
|
bdrv_do_drained_begin(bs, true, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive,
|
||||||
|
BdrvChild *parent)
|
||||||
|
{
|
||||||
|
BdrvChild *child, *next;
|
||||||
int old_quiesce_counter;
|
int old_quiesce_counter;
|
||||||
|
|
||||||
if (qemu_in_coroutine()) {
|
if (qemu_in_coroutine()) {
|
||||||
bdrv_co_yield_to_drain(bs, false, parent);
|
bdrv_co_yield_to_drain(bs, false, recursive, parent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(bs->quiesce_counter > 0);
|
assert(bs->quiesce_counter > 0);
|
||||||
|
@ -304,11 +325,22 @@ static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent)
|
||||||
if (old_quiesce_counter == 1) {
|
if (old_quiesce_counter == 1) {
|
||||||
aio_enable_external(bdrv_get_aio_context(bs));
|
aio_enable_external(bdrv_get_aio_context(bs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (recursive) {
|
||||||
|
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
|
||||||
|
bdrv_do_drained_end(child->bs, true, child);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_drained_end(BlockDriverState *bs)
|
void bdrv_drained_end(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
bdrv_do_drained_end(bs, NULL);
|
bdrv_do_drained_end(bs, false, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bdrv_subtree_drained_end(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
bdrv_do_drained_end(bs, true, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -607,6 +607,14 @@ void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore);
|
||||||
*/
|
*/
|
||||||
void bdrv_drained_begin(BlockDriverState *bs);
|
void bdrv_drained_begin(BlockDriverState *bs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like bdrv_drained_begin, but recursively begins a quiesced section for
|
||||||
|
* exclusive access to all child nodes as well.
|
||||||
|
*
|
||||||
|
* Graph changes are not allowed during a subtree drain section.
|
||||||
|
*/
|
||||||
|
void bdrv_subtree_drained_begin(BlockDriverState *bs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bdrv_drained_end:
|
* bdrv_drained_end:
|
||||||
*
|
*
|
||||||
|
@ -614,6 +622,11 @@ void bdrv_drained_begin(BlockDriverState *bs);
|
||||||
*/
|
*/
|
||||||
void bdrv_drained_end(BlockDriverState *bs);
|
void bdrv_drained_end(BlockDriverState *bs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End a quiescent section started by bdrv_subtree_drained_begin().
|
||||||
|
*/
|
||||||
|
void bdrv_subtree_drained_end(BlockDriverState *bs);
|
||||||
|
|
||||||
void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child,
|
void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child,
|
||||||
Error **errp);
|
Error **errp);
|
||||||
void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **errp);
|
void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **errp);
|
||||||
|
|
Loading…
Reference in New Issue