mirror of https://github.com/xemu-project/xemu.git
block: simplify code around releasing bitmaps
QLIST_REMOVE does not require walking the list, and once the "bitmap" argument is removed from bdrv_do_release_matching_dirty_bitmap_locked the code simplifies a lot and it is worth inlining everything in the callers of bdrv_do_release_matching_dirty_bitmap. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: John Snow <jsnow@redhat.com> Message-id: 20180326104037.6894-1-pbonzini@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
This commit is contained in:
parent
ab41fc4853
commit
b133c27f5d
|
@ -249,49 +249,16 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap)
|
||||||
qemu_mutex_unlock(bitmap->mutex);
|
qemu_mutex_unlock(bitmap->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called within bdrv_dirty_bitmap_lock..unlock */
|
/* Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken. */
|
||||||
static void bdrv_do_release_matching_dirty_bitmap_locked(
|
static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
|
||||||
BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
|
|
||||||
bool (*cond)(BdrvDirtyBitmap *bitmap))
|
|
||||||
{
|
{
|
||||||
BdrvDirtyBitmap *bm, *next;
|
assert(!bitmap->active_iterators);
|
||||||
|
assert(!bdrv_dirty_bitmap_frozen(bitmap));
|
||||||
QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
|
assert(!bitmap->meta);
|
||||||
if ((!bitmap || bm == bitmap) && (!cond || cond(bm))) {
|
QLIST_REMOVE(bitmap, list);
|
||||||
assert(!bm->active_iterators);
|
hbitmap_free(bitmap->bitmap);
|
||||||
assert(!bdrv_dirty_bitmap_frozen(bm));
|
g_free(bitmap->name);
|
||||||
assert(!bm->meta);
|
g_free(bitmap);
|
||||||
QLIST_REMOVE(bm, list);
|
|
||||||
hbitmap_free(bm->bitmap);
|
|
||||||
g_free(bm->name);
|
|
||||||
g_free(bm);
|
|
||||||
|
|
||||||
if (bitmap) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bitmap) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with BQL taken. */
|
|
||||||
static void bdrv_do_release_matching_dirty_bitmap(
|
|
||||||
BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
|
|
||||||
bool (*cond)(BdrvDirtyBitmap *bitmap))
|
|
||||||
{
|
|
||||||
bdrv_dirty_bitmaps_lock(bs);
|
|
||||||
bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, cond);
|
|
||||||
bdrv_dirty_bitmaps_unlock(bs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called within bdrv_dirty_bitmap_lock..unlock */
|
|
||||||
static void bdrv_release_dirty_bitmap_locked(BlockDriverState *bs,
|
|
||||||
BdrvDirtyBitmap *bitmap)
|
|
||||||
{
|
|
||||||
bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -344,7 +311,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
|
||||||
error_setg(errp, "Merging of parent and successor bitmap failed");
|
error_setg(errp, "Merging of parent and successor bitmap failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bdrv_release_dirty_bitmap_locked(bs, successor);
|
bdrv_release_dirty_bitmap_locked(successor);
|
||||||
parent->successor = NULL;
|
parent->successor = NULL;
|
||||||
|
|
||||||
return parent;
|
return parent;
|
||||||
|
@ -382,15 +349,12 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
|
||||||
bdrv_dirty_bitmaps_unlock(bs);
|
bdrv_dirty_bitmaps_unlock(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap *bitmap)
|
|
||||||
{
|
|
||||||
return !!bdrv_dirty_bitmap_name(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Called with BQL taken. */
|
/* Called with BQL taken. */
|
||||||
void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
|
void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
|
||||||
{
|
{
|
||||||
bdrv_do_release_matching_dirty_bitmap(bs, bitmap, NULL);
|
bdrv_dirty_bitmaps_lock(bs);
|
||||||
|
bdrv_release_dirty_bitmap_locked(bitmap);
|
||||||
|
bdrv_dirty_bitmaps_unlock(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -401,7 +365,15 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
|
||||||
*/
|
*/
|
||||||
void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
|
void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
bdrv_do_release_matching_dirty_bitmap(bs, NULL, bdrv_dirty_bitmap_has_name);
|
BdrvDirtyBitmap *bm, *next;
|
||||||
|
|
||||||
|
bdrv_dirty_bitmaps_lock(bs);
|
||||||
|
QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
|
||||||
|
if (bdrv_dirty_bitmap_name(bm)) {
|
||||||
|
bdrv_release_dirty_bitmap_locked(bm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bdrv_dirty_bitmaps_unlock(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -409,11 +381,19 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
|
||||||
* bdrv_inactivate_recurse()).
|
* bdrv_inactivate_recurse()).
|
||||||
* There must not be any frozen bitmaps attached.
|
* There must not be any frozen bitmaps attached.
|
||||||
* This function does not remove persistent bitmaps from the storage.
|
* This function does not remove persistent bitmaps from the storage.
|
||||||
|
* Called with BQL taken.
|
||||||
*/
|
*/
|
||||||
void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs)
|
void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
bdrv_do_release_matching_dirty_bitmap(bs, NULL,
|
BdrvDirtyBitmap *bm, *next;
|
||||||
bdrv_dirty_bitmap_get_persistance);
|
|
||||||
|
bdrv_dirty_bitmaps_lock(bs);
|
||||||
|
QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
|
||||||
|
if (bdrv_dirty_bitmap_get_persistance(bm)) {
|
||||||
|
bdrv_release_dirty_bitmap_locked(bm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bdrv_dirty_bitmaps_unlock(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue