[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC PATCH 2/4] block/raw-posix: implement bdrv_zero_in
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [RFC PATCH 2/4] block/raw-posix: implement bdrv_zero_init |
Date: |
Tue, 12 Nov 2013 11:28:05 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Am 12.11.2013 um 08:47 hat Hu Tao geschrieben:
> Implement bdrv_zero_init using posix_fallocate.
>
> Signed-off-by: Hu Tao <address@hidden>
> ---
> block/raw-posix.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index f6d48bb..8798599 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1190,6 +1190,18 @@ static int64_t coroutine_fn
> raw_co_get_block_status(BlockDriverState *bs,
> return ret;
> }
>
> +static int raw_zero_init(BlockDriverState *bs, int64_t offset, int64_t
> length)
> +{
> + BDRVRawState *s = bs->opaque;
> + int64_t len = bdrv_getlength(bs);
> +
> + if (offset + length < 0 || offset + length > len) {
> + return -1;
> + }
> +
> + return posix_fallocate(s->fd, offset, length);
> +}
This doesn't really initialise anything to zero. It merely preallocates
those parts of a file that aren't allocated yet (and they happen to be
zeroed in this case), but leaves already existing parts untouched.
I wonder if this would be a correct implementation for a bdrv_anchor(),
though. I also wouldn't call that full preallocation, but it might be
useful anyway.
Kevin