From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Gvr-0003oq-6n for qemu-devel@nongnu.org; Mon, 12 Mar 2012 21:53:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7Gvp-00016k-EZ for qemu-devel@nongnu.org; Mon, 12 Mar 2012 21:53:46 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:34185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Gvn-00016b-Up for qemu-devel@nongnu.org; Mon, 12 Mar 2012 21:53:45 -0400 Received: from /spool/local by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 12 Mar 2012 19:53:41 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id E4F373E40036 for ; Mon, 12 Mar 2012 19:53:37 -0600 (MDT) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2D1rbvQ167062 for ; Mon, 12 Mar 2012 19:53:37 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2D1raRZ009399 for ; Mon, 12 Mar 2012 19:53:37 -0600 From: zwu.kernel@gmail.com Date: Tue, 13 Mar 2012 09:53:31 +0800 Message-Id: <1331603611-9103-1-git-send-email-zwu.kernel@gmail.com> Subject: [Qemu-devel] [PATCH] block: add the support to drain throttled requests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: zwu.kernel@gmail.com, pbonzini@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com From: Zhi Yong Wu Signed-off-by: Zhi Yong Wu [ Iterate until all block devices have processed all requests, add comments. - Paolo ] Signed-off-by: Paolo Bonzini --- block.c | 24 ++++++++++++++++++++++-- 1 files changed, 22 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 52ffe14..52dabd0 100644 --- a/block.c +++ b/block.c @@ -858,12 +858,32 @@ void bdrv_close_all(void) * * This function does not flush data to disk, use bdrv_flush_all() for that * after calling this function. - */ + * + * Note that completion of an asynchronous I/O operation can trigger any + * number of other I/O operations on other devices---for example a coroutine + * can be arbitrarily complex and a constant flow of I/O to multiple devices + * can come until the coroutine is complete. Because of this, it is not + * possible to drain a single device's I/O queue. +*/ void bdrv_drain_all(void) { BlockDriverState *bs; + bool busy; - qemu_aio_flush(); + do { + busy = false; + qemu_aio_flush(); + + /* FIXME: We do not have timer support here, so this is effectively + * a busy wait. + */ + QTAILQ_FOREACH(bs, &bdrv_states, list) { + if (!qemu_co_queue_empty(&bs->throttled_reqs)) { + qemu_co_queue_restart_all(&bs->throttled_reqs); + busy = true; + } + } + } while (busy); /* If requests are still pending there is a bug somewhere */ QTAILQ_FOREACH(bs, &bdrv_states, list) { -- 1.7.6