mirror of https://github.com/proxmox/mirror_qemu
block/throttle-groups: Use lock guard macros
Replace manual lock()/unlock() calls with lock guard macros (QEMU_LOCK_GUARD/WITH_QEMU_LOCK_GUARD) in block/throttle-groups. Signed-off-by: Gan Qixin <ganqixin@huawei.com> Message-Id: <20201203075055.127773-4-ganqixin@huawei.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>master
parent
f5056b70e6
commit
3af613ebdb
|
@ -546,7 +546,7 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,
|
||||||
tgm->aio_context = ctx;
|
tgm->aio_context = ctx;
|
||||||
qatomic_set(&tgm->restart_pending, 0);
|
qatomic_set(&tgm->restart_pending, 0);
|
||||||
|
|
||||||
qemu_mutex_lock(&tg->lock);
|
QEMU_LOCK_GUARD(&tg->lock);
|
||||||
/* If the ThrottleGroup is new set this ThrottleGroupMember as the token */
|
/* If the ThrottleGroup is new set this ThrottleGroupMember as the token */
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if (!tg->tokens[i]) {
|
if (!tg->tokens[i]) {
|
||||||
|
@ -565,8 +565,6 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,
|
||||||
qemu_co_mutex_init(&tgm->throttled_reqs_lock);
|
qemu_co_mutex_init(&tgm->throttled_reqs_lock);
|
||||||
qemu_co_queue_init(&tgm->throttled_reqs[0]);
|
qemu_co_queue_init(&tgm->throttled_reqs[0]);
|
||||||
qemu_co_queue_init(&tgm->throttled_reqs[1]);
|
qemu_co_queue_init(&tgm->throttled_reqs[1]);
|
||||||
|
|
||||||
qemu_mutex_unlock(&tg->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unregister a ThrottleGroupMember from its group, removing it from the list,
|
/* Unregister a ThrottleGroupMember from its group, removing it from the list,
|
||||||
|
@ -594,25 +592,25 @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm)
|
||||||
/* Wait for throttle_group_restart_queue_entry() coroutines to finish */
|
/* Wait for throttle_group_restart_queue_entry() coroutines to finish */
|
||||||
AIO_WAIT_WHILE(tgm->aio_context, qatomic_read(&tgm->restart_pending) > 0);
|
AIO_WAIT_WHILE(tgm->aio_context, qatomic_read(&tgm->restart_pending) > 0);
|
||||||
|
|
||||||
qemu_mutex_lock(&tg->lock);
|
WITH_QEMU_LOCK_GUARD(&tg->lock) {
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
assert(tgm->pending_reqs[i] == 0);
|
assert(tgm->pending_reqs[i] == 0);
|
||||||
assert(qemu_co_queue_empty(&tgm->throttled_reqs[i]));
|
assert(qemu_co_queue_empty(&tgm->throttled_reqs[i]));
|
||||||
assert(!timer_pending(tgm->throttle_timers.timers[i]));
|
assert(!timer_pending(tgm->throttle_timers.timers[i]));
|
||||||
if (tg->tokens[i] == tgm) {
|
if (tg->tokens[i] == tgm) {
|
||||||
token = throttle_group_next_tgm(tgm);
|
token = throttle_group_next_tgm(tgm);
|
||||||
/* Take care of the case where this is the last tgm in the group */
|
/* Take care of the case where this is the last tgm in the group */
|
||||||
if (token == tgm) {
|
if (token == tgm) {
|
||||||
token = NULL;
|
token = NULL;
|
||||||
|
}
|
||||||
|
tg->tokens[i] = token;
|
||||||
}
|
}
|
||||||
tg->tokens[i] = token;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* remove the current tgm from the list */
|
/* remove the current tgm from the list */
|
||||||
QLIST_REMOVE(tgm, round_robin);
|
QLIST_REMOVE(tgm, round_robin);
|
||||||
throttle_timers_destroy(&tgm->throttle_timers);
|
throttle_timers_destroy(&tgm->throttle_timers);
|
||||||
qemu_mutex_unlock(&tg->lock);
|
}
|
||||||
|
|
||||||
throttle_group_unref(&tg->ts);
|
throttle_group_unref(&tg->ts);
|
||||||
tgm->throttle_state = NULL;
|
tgm->throttle_state = NULL;
|
||||||
|
@ -638,14 +636,14 @@ void throttle_group_detach_aio_context(ThrottleGroupMember *tgm)
|
||||||
assert(qemu_co_queue_empty(&tgm->throttled_reqs[1]));
|
assert(qemu_co_queue_empty(&tgm->throttled_reqs[1]));
|
||||||
|
|
||||||
/* Kick off next ThrottleGroupMember, if necessary */
|
/* Kick off next ThrottleGroupMember, if necessary */
|
||||||
qemu_mutex_lock(&tg->lock);
|
WITH_QEMU_LOCK_GUARD(&tg->lock) {
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if (timer_pending(tt->timers[i])) {
|
if (timer_pending(tt->timers[i])) {
|
||||||
tg->any_timer_armed[i] = false;
|
tg->any_timer_armed[i] = false;
|
||||||
schedule_next_request(tgm, i);
|
schedule_next_request(tgm, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qemu_mutex_unlock(&tg->lock);
|
|
||||||
|
|
||||||
throttle_timers_detach_aio_context(tt);
|
throttle_timers_detach_aio_context(tt);
|
||||||
tgm->aio_context = NULL;
|
tgm->aio_context = NULL;
|
||||||
|
|
Loading…
Reference in New Issue