block/dirty-bitmaps: unify qmp_locked and user_locked calls

These mean the same thing now. Unify them and rename the merged call
bdrv_dirty_bitmap_busy to indicate semantically what we are describing,
as well as help disambiguate from the various _locked and _unlocked
versions of bitmap helpers that refer to mutex locks.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20190223000614.13894-8-jsnow@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
This commit is contained in:
John Snow 2019-03-12 12:05:48 -04:00
parent 21d2376f26
commit 27a1b301a4
5 changed files with 36 additions and 42 deletions

View File

@ -48,8 +48,7 @@ struct BdrvDirtyBitmap {
QemuMutex *mutex; QemuMutex *mutex;
HBitmap *bitmap; /* Dirty bitmap implementation */ HBitmap *bitmap; /* Dirty bitmap implementation */
HBitmap *meta; /* Meta dirty bitmap */ HBitmap *meta; /* Meta dirty bitmap */
bool qmp_locked; /* Bitmap is locked, it can't be modified bool busy; /* Bitmap is busy, it can't be used via QMP */
through QMP */
BdrvDirtyBitmap *successor; /* Anonymous child, if any. */ BdrvDirtyBitmap *successor; /* Anonymous child, if any. */
char *name; /* Optional non-empty unique ID */ char *name; /* Optional non-empty unique ID */
int64_t size; /* Size of the bitmap, in bytes */ int64_t size; /* Size of the bitmap, in bytes */
@ -188,22 +187,18 @@ bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap)
return bitmap->successor; return bitmap->successor;
} }
bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap) { bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap)
return bdrv_dirty_bitmap_qmp_locked(bitmap); {
return bitmap->busy;
} }
void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked) void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy)
{ {
qemu_mutex_lock(bitmap->mutex); qemu_mutex_lock(bitmap->mutex);
bitmap->qmp_locked = qmp_locked; bitmap->busy = busy;
qemu_mutex_unlock(bitmap->mutex); qemu_mutex_unlock(bitmap->mutex);
} }
bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap)
{
return bitmap->qmp_locked;
}
/* Called with BQL taken. */ /* Called with BQL taken. */
bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap) bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap)
{ {
@ -215,7 +210,7 @@ DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap)
{ {
if (bdrv_dirty_bitmap_has_successor(bitmap)) { if (bdrv_dirty_bitmap_has_successor(bitmap)) {
return DIRTY_BITMAP_STATUS_FROZEN; return DIRTY_BITMAP_STATUS_FROZEN;
} else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) { } else if (bdrv_dirty_bitmap_busy(bitmap)) {
return DIRTY_BITMAP_STATUS_LOCKED; return DIRTY_BITMAP_STATUS_LOCKED;
} else if (!bdrv_dirty_bitmap_enabled(bitmap)) { } else if (!bdrv_dirty_bitmap_enabled(bitmap)) {
return DIRTY_BITMAP_STATUS_DISABLED; return DIRTY_BITMAP_STATUS_DISABLED;
@ -233,7 +228,7 @@ static bool bdrv_dirty_bitmap_recording(BdrvDirtyBitmap *bitmap)
/** /**
* Create a successor bitmap destined to replace this bitmap after an operation. * Create a successor bitmap destined to replace this bitmap after an operation.
* Requires that the bitmap is not user_locked and has no successor. * Requires that the bitmap is not marked busy and has no successor.
* The successor will be enabled if the parent bitmap was. * The successor will be enabled if the parent bitmap was.
* Called with BQL taken. * Called with BQL taken.
*/ */
@ -243,7 +238,7 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
uint64_t granularity; uint64_t granularity;
BdrvDirtyBitmap *child; BdrvDirtyBitmap *child;
if (bdrv_dirty_bitmap_user_locked(bitmap)) { if (bdrv_dirty_bitmap_busy(bitmap)) {
error_setg(errp, "Cannot create a successor for a bitmap that is " error_setg(errp, "Cannot create a successor for a bitmap that is "
"in-use by an operation"); "in-use by an operation");
return -1; return -1;
@ -265,9 +260,9 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
child->disabled = bitmap->disabled; child->disabled = bitmap->disabled;
bitmap->disabled = true; bitmap->disabled = true;
/* Install the successor and lock the parent */ /* Install the successor and mark the parent as busy */
bitmap->successor = child; bitmap->successor = child;
bitmap->qmp_locked = true; bitmap->busy = true;
return 0; return 0;
} }
@ -289,7 +284,7 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap)
static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap) static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
{ {
assert(!bitmap->active_iterators); assert(!bitmap->active_iterators);
assert(!bdrv_dirty_bitmap_user_locked(bitmap)); assert(!bdrv_dirty_bitmap_busy(bitmap));
assert(!bdrv_dirty_bitmap_has_successor(bitmap)); assert(!bdrv_dirty_bitmap_has_successor(bitmap));
assert(!bitmap->meta); assert(!bitmap->meta);
QLIST_REMOVE(bitmap, list); QLIST_REMOVE(bitmap, list);
@ -322,7 +317,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
bitmap->successor = NULL; bitmap->successor = NULL;
successor->persistent = bitmap->persistent; successor->persistent = bitmap->persistent;
bitmap->persistent = false; bitmap->persistent = false;
bitmap->qmp_locked = false; bitmap->busy = false;
bdrv_release_dirty_bitmap(bs, bitmap); bdrv_release_dirty_bitmap(bs, bitmap);
return successor; return successor;
@ -331,7 +326,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
/** /**
* In cases of failure where we can no longer safely delete the parent, * In cases of failure where we can no longer safely delete the parent,
* we may wish to re-join the parent and child/successor. * we may wish to re-join the parent and child/successor.
* The merged parent will not be user_locked. * The merged parent will be marked as not busy.
* The marged parent will be enabled if and only if the successor was enabled. * The marged parent will be enabled if and only if the successor was enabled.
* Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken. * Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.
*/ */
@ -352,7 +347,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
} }
parent->disabled = successor->disabled; parent->disabled = successor->disabled;
parent->qmp_locked = false; parent->busy = false;
bdrv_release_dirty_bitmap_locked(successor); bdrv_release_dirty_bitmap_locked(successor);
parent->successor = NULL; parent->successor = NULL;
@ -383,7 +378,7 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
bdrv_dirty_bitmaps_lock(bs); bdrv_dirty_bitmaps_lock(bs);
QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
assert(!bdrv_dirty_bitmap_user_locked(bitmap)); assert(!bdrv_dirty_bitmap_busy(bitmap));
assert(!bdrv_dirty_bitmap_has_successor(bitmap)); assert(!bdrv_dirty_bitmap_has_successor(bitmap));
assert(!bitmap->active_iterators); assert(!bitmap->active_iterators);
hbitmap_truncate(bitmap->bitmap, bytes); hbitmap_truncate(bitmap->bitmap, bytes);
@ -402,7 +397,7 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
/** /**
* Release all named dirty bitmaps attached to a BDS (for use in bdrv_close()). * Release all named dirty bitmaps attached to a BDS (for use in bdrv_close()).
* There must not be any user_locked bitmaps attached. * There must not be any busy 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. * Called with BQL taken.
*/ */
@ -466,7 +461,7 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)
info->name = g_strdup(bm->name); info->name = g_strdup(bm->name);
info->status = bdrv_dirty_bitmap_status(bm); info->status = bdrv_dirty_bitmap_status(bm);
info->recording = bdrv_dirty_bitmap_recording(bm); info->recording = bdrv_dirty_bitmap_recording(bm);
info->busy = bdrv_dirty_bitmap_user_locked(bm); info->busy = bdrv_dirty_bitmap_busy(bm);
info->persistent = bm->persistent; info->persistent = bm->persistent;
entry->value = info; entry->value = info;
*plist = entry; *plist = entry;
@ -774,7 +769,7 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
qemu_mutex_lock(dest->mutex); qemu_mutex_lock(dest->mutex);
if (bdrv_dirty_bitmap_user_locked(dest)) { if (bdrv_dirty_bitmap_busy(dest)) {
error_setg(errp, "Bitmap '%s' is currently in use by another" error_setg(errp, "Bitmap '%s' is currently in use by another"
" operation and cannot be modified", dest->name); " operation and cannot be modified", dest->name);
goto out; goto out;

View File

@ -2011,7 +2011,7 @@ static void block_dirty_bitmap_clear_prepare(BlkActionState *common,
return; return;
} }
if (bdrv_dirty_bitmap_user_locked(state->bitmap)) { if (bdrv_dirty_bitmap_busy(state->bitmap)) {
error_setg(errp, "Cannot modify a bitmap in use by another operation"); error_setg(errp, "Cannot modify a bitmap in use by another operation");
return; return;
} else if (bdrv_dirty_bitmap_readonly(state->bitmap)) { } else if (bdrv_dirty_bitmap_readonly(state->bitmap)) {
@ -2060,7 +2060,7 @@ static void block_dirty_bitmap_enable_prepare(BlkActionState *common,
return; return;
} }
if (bdrv_dirty_bitmap_user_locked(state->bitmap)) { if (bdrv_dirty_bitmap_busy(state->bitmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation" "Bitmap '%s' is currently in use by another operation"
" and cannot be enabled", action->name); " and cannot be enabled", action->name);
@ -2101,7 +2101,7 @@ static void block_dirty_bitmap_disable_prepare(BlkActionState *common,
return; return;
} }
if (bdrv_dirty_bitmap_user_locked(state->bitmap)) { if (bdrv_dirty_bitmap_busy(state->bitmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation" "Bitmap '%s' is currently in use by another operation"
" and cannot be disabled", action->name); " and cannot be disabled", action->name);
@ -2895,7 +2895,7 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
return; return;
} }
if (bdrv_dirty_bitmap_user_locked(bitmap)) { if (bdrv_dirty_bitmap_busy(bitmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation and" "Bitmap '%s' is currently in use by another operation and"
" cannot be removed", name); " cannot be removed", name);
@ -2934,7 +2934,7 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
return; return;
} }
if (bdrv_dirty_bitmap_user_locked(bitmap)) { if (bdrv_dirty_bitmap_busy(bitmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation" "Bitmap '%s' is currently in use by another operation"
" and cannot be cleared", name); " and cannot be cleared", name);
@ -2958,7 +2958,7 @@ void qmp_block_dirty_bitmap_enable(const char *node, const char *name,
return; return;
} }
if (bdrv_dirty_bitmap_user_locked(bitmap)) { if (bdrv_dirty_bitmap_busy(bitmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation" "Bitmap '%s' is currently in use by another operation"
" and cannot be enabled", name); " and cannot be enabled", name);
@ -2979,7 +2979,7 @@ void qmp_block_dirty_bitmap_disable(const char *node, const char *name,
return; return;
} }
if (bdrv_dirty_bitmap_user_locked(bitmap)) { if (bdrv_dirty_bitmap_busy(bitmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation" "Bitmap '%s' is currently in use by another operation"
" and cannot be disabled", name); " and cannot be disabled", name);
@ -3561,7 +3561,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
bdrv_unref(target_bs); bdrv_unref(target_bs);
goto out; goto out;
} }
if (bdrv_dirty_bitmap_user_locked(bmap)) { if (bdrv_dirty_bitmap_busy(bmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation" "Bitmap '%s' is currently in use by another operation"
" and cannot be used for backup", backup->bitmap); " and cannot be used for backup", backup->bitmap);
@ -3674,7 +3674,7 @@ BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn,
error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap); error_setg(errp, "Bitmap '%s' could not be found", backup->bitmap);
goto out; goto out;
} }
if (bdrv_dirty_bitmap_user_locked(bmap)) { if (bdrv_dirty_bitmap_busy(bmap)) {
error_setg(errp, error_setg(errp,
"Bitmap '%s' is currently in use by another operation" "Bitmap '%s' is currently in use by another operation"
" and cannot be used for backup", backup->bitmap); " and cannot be used for backup", backup->bitmap);

View File

@ -68,7 +68,7 @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
bool persistent); bool persistent);
void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked); void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
HBitmap **backup, Error **errp); HBitmap **backup, Error **errp);
void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migration); void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migration);
@ -91,8 +91,7 @@ bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_busy(BdrvDirtyBitmap *bitmap);
bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap);
bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
BdrvDirtyBitmap *bitmap); BdrvDirtyBitmap *bitmap);

View File

@ -261,7 +261,7 @@ static void dirty_bitmap_mig_cleanup(void)
while ((dbms = QSIMPLEQ_FIRST(&dirty_bitmap_mig_state.dbms_list)) != NULL) { while ((dbms = QSIMPLEQ_FIRST(&dirty_bitmap_mig_state.dbms_list)) != NULL) {
QSIMPLEQ_REMOVE_HEAD(&dirty_bitmap_mig_state.dbms_list, entry); QSIMPLEQ_REMOVE_HEAD(&dirty_bitmap_mig_state.dbms_list, entry);
bdrv_dirty_bitmap_set_qmp_locked(dbms->bitmap, false); bdrv_dirty_bitmap_set_busy(dbms->bitmap, false);
bdrv_unref(dbms->bs); bdrv_unref(dbms->bs);
g_free(dbms); g_free(dbms);
} }
@ -301,7 +301,7 @@ static int init_dirty_bitmap_migration(void)
goto fail; goto fail;
} }
if (bdrv_dirty_bitmap_user_locked(bitmap)) { if (bdrv_dirty_bitmap_busy(bitmap)) {
error_report("Can't migrate a bitmap that is in use by another operation: '%s'", error_report("Can't migrate a bitmap that is in use by another operation: '%s'",
bdrv_dirty_bitmap_name(bitmap)); bdrv_dirty_bitmap_name(bitmap));
goto fail; goto fail;
@ -314,7 +314,7 @@ static int init_dirty_bitmap_migration(void)
} }
bdrv_ref(bs); bdrv_ref(bs);
bdrv_dirty_bitmap_set_qmp_locked(bitmap, true); bdrv_dirty_bitmap_set_busy(bitmap, true);
dbms = g_new0(DirtyBitmapMigBitmapState, 1); dbms = g_new0(DirtyBitmapMigBitmapState, 1);
dbms->bs = bs; dbms->bs = bs;

View File

@ -1510,7 +1510,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
goto fail; goto fail;
} }
if (bdrv_dirty_bitmap_user_locked(bm)) { if (bdrv_dirty_bitmap_busy(bm)) {
error_setg(errp, "Bitmap '%s' is in use", bitmap); error_setg(errp, "Bitmap '%s' is in use", bitmap);
goto fail; goto fail;
} }
@ -1523,7 +1523,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
goto fail; goto fail;
} }
bdrv_dirty_bitmap_set_qmp_locked(bm, true); bdrv_dirty_bitmap_set_busy(bm, true);
exp->export_bitmap = bm; exp->export_bitmap = bm;
exp->export_bitmap_context = g_strdup_printf("qemu:dirty-bitmap:%s", exp->export_bitmap_context = g_strdup_printf("qemu:dirty-bitmap:%s",
bitmap); bitmap);
@ -1641,7 +1641,7 @@ void nbd_export_put(NBDExport *exp)
} }
if (exp->export_bitmap) { if (exp->export_bitmap) {
bdrv_dirty_bitmap_set_qmp_locked(exp->export_bitmap, false); bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false);
g_free(exp->export_bitmap_context); g_free(exp->export_bitmap_context);
} }