From patchwork Tue Mar 13 01:53:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 146325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AC755B6FA7 for ; Tue, 13 Mar 2012 12:53:56 +1100 (EST) Received: from localhost ([::1]:58792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Gvy-0003p6-J4 for incoming@patchwork.ozlabs.org; Mon, 12 Mar 2012 21:53:54 -0400 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 d03dlp02.boulder.ibm.com (9.17.202.178) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 12 Mar 2012 19:53:38 -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 Received: from us.ibm.com (f15.cn.ibm.com [9.115.118.120] (may be forged)) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q2D1rXPu009269; Mon, 12 Mar 2012 19:53:34 -0600 Received: by us.ibm.com (sSMTP sendmail emulation); Tue, 13 Mar 2012 09:53:32 +0800 From: zwu.kernel@gmail.com To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2012 09:53:31 +0800 Message-Id: <1331603611-9103-1-git-send-email-zwu.kernel@gmail.com> X-Mailer: git-send-email 1.7.6 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12031301-2398-0000-0000-000004FCEF81 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.110.151 Cc: zwu.kernel@gmail.com, pbonzini@redhat.com, Zhi Yong Wu , stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH] block: add the support to drain throttled requests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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) {