From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=44612 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PznTO-0001s4-Kn for qemu-devel@nongnu.org; Wed, 16 Mar 2011 05:56:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PznTM-00028j-Nu for qemu-devel@nongnu.org; Wed, 16 Mar 2011 05:56:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PznTM-00028b-7A for qemu-devel@nongnu.org; Wed, 16 Mar 2011 05:56:56 -0400 Message-ID: <4D8089E5.3060606@redhat.com> Date: Wed, 16 Mar 2011 10:59:01 +0100 From: Kevin Wolf MIME-Version: 1.0 References: <20110315141049.GA30627@lst.de> <20110315141132.GB30710@lst.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 2/4] block: add a helper to change writeback mode on the fly List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Jes Sorensen , aliguori@us.ibm.com, prerna@linux.vnet.ibm.com, Christoph Hellwig , qemu-devel@nongnu.org Am 16.03.2011 10:49, schrieb Stefan Hajnoczi: > On Tue, Mar 15, 2011 at 2:11 PM, Christoph Hellwig wrote: >> Add a new bdrv_change_cache that can set/clear the writeback flag >> at runtime by stopping all I/O and closing/reopening the image file. >> >> All code is based on a patch from Prerna Saxena >> with minimal refactoring. >> >> Signed-off-by: Christoph Hellwig >> >> Index: qemu/block.c >> =================================================================== >> --- qemu.orig/block.c 2011-03-15 11:47:31.285634626 +0100 >> +++ qemu/block.c 2011-03-15 14:57:03.680633093 +0100 >> @@ -441,6 +441,8 @@ static int bdrv_open_common(BlockDriverS >> >> if (flags & BDRV_O_CACHE_WB) >> bs->enable_write_cache = 1; >> + else >> + bs->enable_write_cache = 0; >> >> /* >> * Clear flags that are internal to the block layer before opening the >> @@ -651,6 +653,44 @@ unlink_and_fail: >> return ret; >> } >> >> +static int bdrv_reopen(BlockDriverState *bs, int bdrv_flags) >> +{ >> + BlockDriver *drv = bs->drv; >> + int ret; >> + >> + if (bdrv_flags == bs->open_flags) { >> + return 0; >> + } >> + >> + /* Quiesce IO for the given block device */ >> + qemu_aio_flush(); >> + bdrv_flush(bs); >> + >> + bdrv_close(bs); >> + ret = bdrv_open(bs, bs->filename, bdrv_flags, drv); > > This will fail for -snapshot disks since the on-disk file is deleted. > > In general it would be more robust to keep the original file > descriptor around in case the file cannot be opened with the new > flags. Looks like we'll need a bdrv_reopen for protocols? Kevin