From patchwork Fri Oct 29 14:40:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 69600 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 69D8FB6EF2 for ; Sat, 30 Oct 2010 01:55:00 +1100 (EST) Received: from localhost ([127.0.0.1]:39038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBqK3-0002oc-MF for incoming@patchwork.ozlabs.org; Fri, 29 Oct 2010 10:52:51 -0400 Received: from [140.186.70.92] (port=44029 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBqGJ-0000sG-GG for qemu-devel@nongnu.org; Fri, 29 Oct 2010 10:49:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PBq8h-00017E-91 for qemu-devel@nongnu.org; Fri, 29 Oct 2010 10:41:08 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:34712) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PBq8h-000176-3W for qemu-devel@nongnu.org; Fri, 29 Oct 2010 10:41:07 -0400 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e37.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o9TEcrKZ032254 for ; Fri, 29 Oct 2010 08:38:53 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id o9TEf2cb238768 for ; Fri, 29 Oct 2010 08:41:03 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9TEf2b1001336 for ; Fri, 29 Oct 2010 08:41:02 -0600 Received: from [9.65.33.18] (sig-9-65-33-18.mts.ibm.com [9.65.33.18]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9TEexfk001002; Fri, 29 Oct 2010 08:41:00 -0600 Message-ID: <4CCADCF9.5030508@linux.vnet.ibm.com> Date: Fri, 29 Oct 2010 09:40:57 -0500 From: Anthony Liguori User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101027 Lightning/1.0b1 Thunderbird/3.0.10 MIME-Version: 1.0 To: Kevin Wolf Subject: Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug() References: <1288030956-28383-1-git-send-email-ryanh@us.ibm.com> <1288030956-28383-3-git-send-email-ryanh@us.ibm.com> <4CCAD6F4.6010201@linux.vnet.ibm.com> <4CCADA4C.4030302@redhat.com> In-Reply-To: <4CCADA4C.4030302@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Stefan Hajnoczi , Ryan Harper , Markus Armbruster , qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 10/29/2010 09:29 AM, Kevin Wolf wrote: > Am 29.10.2010 16:15, schrieb Anthony Liguori: > >> On 10/29/2010 09:01 AM, Markus Armbruster wrote: >> >>> Ryan Harper writes: >>> >>>> diff --git a/block.c b/block.c >>>> index a19374d..be47655 100644 >>>> --- a/block.c >>>> +++ b/block.c >>>> @@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) >>>> } >>>> } >>>> >>>> +void bdrv_unplug(BlockDriverState *bs) >>>> +{ >>>> + qemu_aio_flush(); >>>> + bdrv_flush(bs); >>>> + bdrv_close(bs); >>>> +} >>>> >>>> >>> Stupid question: why doesn't bdrv_close() flush automatically? >>> >>> >> I don't think it's a bad idea to do that but to the extent that the >> block API is designed after posix file I/O, close does not usually imply >> flush. >> > I don't think it really resembles POSIX. More or less the only thing > they have in common is that both provide open, read, write and close, > which is something that probably any API for file accesses provides. > > The operation you're talking about here is bdrv_flush/fsync that is not > implied by a POSIX close? > Yes. But I think for the purposes of this patch, a bdrv_cancel_all() would be just as good. The intention is to eliminate pending I/O requests, the fsync is just a side effect. >>> And why do we have to flush here, but not before other uses of >>> bdrv_close(), such as eject_device()? >>> >>> >> Good question. Kevin should also confirm, but looking at the code, I >> think flush() is needed before close. If there's a pending I/O event >> and you close before the I/O event is completed, you'll get a callback >> for completion against a bogus BlockDriverState. >> >> I can't find anything in either raw-posix or the generic block layer >> that would mitigate this. >> > I'm not aware of anything either. This is what qemu_aio_flush would do. > > It seems reasonable to me to call both qemu_aio_flush and bdrv_flush in > bdrv_close. We probably don't really need to call bdrv_flush to operate > correctly, but it can't hurt and bdrv_close shouldn't happen that often > anyway. > I agree. Re: qemu_aio_flush, we have to wait for it to complete which gets a little complicated in bdrv_close(). I think it would be better to make bdrv_flush() call bdrv_aio_flush() if an explicit bdrv_flush method isn't provided. Something like the attached (still need to test). Does that seem reasonable? Regards, Anthony Liguori > Kevin > From 094049974796ddf78ee2f1541bffa40fe1176a1a Mon Sep 17 00:00:00 2001 From: Anthony Liguori Date: Fri, 29 Oct 2010 09:37:25 -0500 Subject: [PATCH 2/2] block: add bdrv_flush to bdrv_close To ensure that there are no pending completions before destroying a block device. Signed-off-by: Anthony Liguori diff --git a/block.c b/block.c index fc8defd..d2aed1b 100644 --- a/block.c +++ b/block.c @@ -644,6 +644,8 @@ unlink_and_fail: void bdrv_close(BlockDriverState *bs) { if (bs->drv) { + bdrv_flush(bs); + if (bs == bs_snapshots) { bs_snapshots = NULL; } -- 1.7.0.4