From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuP7Z-00026N-HD for qemu-devel@nongnu.org; Thu, 05 Nov 2015 13:18:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuP7Y-0005zm-ER for qemu-devel@nongnu.org; Thu, 05 Nov 2015 13:18:49 -0500 From: Kevin Wolf Date: Thu, 5 Nov 2015 19:17:54 +0100 Message-Id: <1446747485-6562-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1446747485-6562-1-git-send-email-kwolf@redhat.com> References: <1446747485-6562-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 26/37] throttle: Check for pending requests in throttle_group_unregister_bs() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Alberto Garcia throttle_group_unregister_bs() removes a BlockDriverState from its throttling group and destroys the timers. This means that there must be no pending throttled requests at that point (because it would be impossible to complete them), so the caller has to drain them first. At the moment throttle_group_unregister_bs() is only called from bdrv_io_limits_disable(), which already takes care of draining the requests, so there's nothing to worry about, but this patch makes this invariant explicit in the documentation and adds the relevant assertions. Signed-off-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/throttle-groups.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 3419af7..13b5baa 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -437,6 +437,9 @@ void throttle_group_register_bs(BlockDriverState *bs, const char *groupname) * list, destroying the timers and setting the throttle_state pointer * to NULL. * + * The BlockDriverState must not have pending throttled requests, so + * the caller has to drain them first. + * * The group will be destroyed if it's empty after this operation. * * @bs: the BlockDriverState to remove @@ -446,6 +449,10 @@ void throttle_group_unregister_bs(BlockDriverState *bs) ThrottleGroup *tg = container_of(bs->throttle_state, ThrottleGroup, ts); int i; + assert(bs->pending_reqs[0] == 0 && bs->pending_reqs[1] == 0); + assert(qemu_co_queue_empty(&bs->throttled_reqs[0])); + assert(qemu_co_queue_empty(&bs->throttled_reqs[1])); + qemu_mutex_lock(&tg->lock); for (i = 0; i < 2; i++) { if (tg->tokens[i] == bs) { -- 1.8.3.1