From patchwork Fri Jul 5 11:32:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 257159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CDE542C008F for ; Fri, 5 Jul 2013 21:33:49 +1000 (EST) Received: from localhost ([::1]:49758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uv4Gp-0001gK-KD for incoming@patchwork.ozlabs.org; Fri, 05 Jul 2013 07:33:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uv4GI-0001Sd-A2 for qemu-devel@nongnu.org; Fri, 05 Jul 2013 07:33:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uv4GD-0004jj-Qy for qemu-devel@nongnu.org; Fri, 05 Jul 2013 07:33:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18298) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uv4GD-0004jY-IQ; Fri, 05 Jul 2013 07:33:09 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r65BX8Jp032584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Jul 2013 07:33:09 -0400 Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r65BX6pa030260; Fri, 5 Jul 2013 07:33:08 -0400 From: Stefan Hajnoczi To: Date: Fri, 5 Jul 2013 13:32:52 +0200 Message-Id: <1373023972-3587-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1373023972-3587-1-git-send-email-stefanha@redhat.com> References: <1373023972-3587-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , qemu-stable@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 3/3] block: fix bdrv_flush() ordering in bdrv_close() 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 Since 80ccf93b we flush the block device during close. The bdrv_drain_all() call should come before bdrv_flush() to ensure guest write requests have completed. Otherwise we may miss pending writes when flushing. Call bdrv_drain_all() again for safety as the final step after bdrv_flush(). This should not be necessary but we can be paranoid here in case bdrv_flush() left I/O pending. Cc: qemu-stable@nongnu.org Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf --- block.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 6c493ad..183fec8 100644 --- a/block.c +++ b/block.c @@ -1358,11 +1358,12 @@ void bdrv_reopen_abort(BDRVReopenState *reopen_state) void bdrv_close(BlockDriverState *bs) { - bdrv_flush(bs); if (bs->job) { block_job_cancel_sync(bs->job); } - bdrv_drain_all(); + bdrv_drain_all(); /* complete I/O */ + bdrv_flush(bs); + bdrv_drain_all(); /* in case flush left pending I/O */ notifier_list_notify(&bs->close_notifiers, bs); if (bs->drv) {