[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] Re: [PATCH 2/4] block: add a helper to change writeback mod
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] Re: [PATCH 2/4] block: add a helper to change writeback mode on the fly |
Date: |
Wed, 16 Mar 2011 09:49:20 +0000 |
On Tue, Mar 15, 2011 at 2:11 PM, Christoph Hellwig <address@hidden> 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 <address@hidden>
> with minimal refactoring.
>
> Signed-off-by: Christoph Hellwig <address@hidden>
>
> 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.
Stefan
- [Qemu-devel] [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, (continued)
- [Qemu-devel] [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, Christoph Hellwig, 2011/03/15
- [Qemu-devel] Re: [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, Stefan Hajnoczi, 2011/03/16
- [Qemu-devel] Re: [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, Kevin Wolf, 2011/03/16
- [Qemu-devel] Re: [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, Christoph Hellwig, 2011/03/16
- [Qemu-devel] Re: [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, Stefan Hajnoczi, 2011/03/16
- [Qemu-devel] Re: [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, Kevin Wolf, 2011/03/17
- [Qemu-devel] Re: [PATCH 1/4] block: clarify the meaning of BDRV_O_NOCACHE, Stefan Hajnoczi, 2011/03/17
[Qemu-devel] [PATCH 2/4] block: add a helper to change writeback mode on the fly, Christoph Hellwig, 2011/03/15
[Qemu-devel] [PATCH, RFC] virtio_blk: add cache control support, Christoph Hellwig, 2011/03/15