From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4WWA-0007oQ-T8 for qemu-devel@nongnu.org; Mon, 15 Jun 2015 11:41:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4WW4-0008Uw-G6 for qemu-devel@nongnu.org; Mon, 15 Jun 2015 11:41:46 -0400 From: Alberto Garcia Date: Mon, 15 Jun 2015 18:41:15 +0300 Message-Id: <1434382875-3998-1-git-send-email-berto@igalia.com> Subject: [Qemu-devel] [PATCH] throttle: Check current timers before updating any_timer_armed[] List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alberto Garcia , Stefan Hajnoczi , qemu-block@nongnu.org Calling throttle_group_config() cancels all timers from a particular BlockDriverState, so any_timer_armed[] should be updated accordingly. However, with the current code it may happen that a timer is armed in a different BlockDriverState from the same group, so any_timer_armed[] would be set to false in a situation where there is still a timer armed. The consequence is that we might end up with two timers armed. This should not have any noticeable impact however, since all accesses to the ThrottleGroup are protected by a lock, and the situation would become normal again shortly thereafter as soon as all timers have been fired. The correct way to solve this is to check that we're actually cancelling a timer before updating any_timer_armed[]. Signed-off-by: Alberto Garcia --- block/throttle-groups.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index efc462f..1abc6fc 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -324,9 +324,14 @@ void throttle_group_config(BlockDriverState *bs, ThrottleConfig *cfg) ThrottleState *ts = bs->throttle_state; ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); qemu_mutex_lock(&tg->lock); - throttle_config(ts, tt, cfg); /* throttle_config() cancels the timers */ - tg->any_timer_armed[0] = tg->any_timer_armed[1] = false; + if (timer_pending(tt->timers[0])) { + tg->any_timer_armed[0] = false; + } + if (timer_pending(tt->timers[1])) { + tg->any_timer_armed[1] = false; + } + throttle_config(ts, tt, cfg); qemu_mutex_unlock(&tg->lock); } -- 2.1.4