qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 7/9] parallels: Rework truncation logic


From: Denis V. Lunev
Subject: Re: [PATCH 7/9] parallels: Rework truncation logic
Date: Thu, 7 May 2020 14:14:13 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

On 4/28/20 11:29 PM, Eric Blake wrote:
> The parallels driver tries to use truncation for image growth, but can
> only do so when reads are guaranteed as zero.  Now that we have a way
> to request zero contents from truncation, we can defer the decision to
> actual allocation attempts rather than up front, reducing the number
> of places that still use bdrv_has_zero_init_truncate.
>
> Signed-off-by: Eric Blake <address@hidden>
> ---
>  block/parallels.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/block/parallels.c b/block/parallels.c
> index 2be92cf41708..9dadaa3217b9 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -196,14 +196,24 @@ static int64_t allocate_clusters(BlockDriverState *bs, 
> int64_t sector_num,
>      }
>      if (s->data_end + space > (len >> BDRV_SECTOR_BITS)) {
>          space += s->prealloc_size;
> +        /*
> +         * We require the expanded size to read back as zero. If the
> +         * user permitted truncation, we try that; but if it fails, we
> +         * force the safer-but-slower fallocate.
> +         */
> +        if (s->prealloc_mode == PRL_PREALLOC_MODE_TRUNCATE) {
> +            ret = bdrv_truncate(bs->file,
> +                                (s->data_end + space) << BDRV_SECTOR_BITS,
> +                                false, PREALLOC_MODE_OFF, 
> BDRV_REQ_ZERO_WRITE,
> +                                NULL);
> +            if (ret == -ENOTSUP) {
> +                s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
> +            }
> +        }
>          if (s->prealloc_mode == PRL_PREALLOC_MODE_FALLOCATE) {
>              ret = bdrv_pwrite_zeroes(bs->file,
>                                       s->data_end << BDRV_SECTOR_BITS,
>                                       space << BDRV_SECTOR_BITS, 0);
> -        } else {
> -            ret = bdrv_truncate(bs->file,
> -                                (s->data_end + space) << BDRV_SECTOR_BITS,
> -                                false, PREALLOC_MODE_OFF, 0, NULL);
>          }
>          if (ret < 0) {
>              return ret;
> @@ -828,6 +838,7 @@ static int parallels_open(BlockDriverState *bs, QDict 
> *options, int flags,
>          qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0);
>      s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
>      buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
> +    /* prealloc_mode can be downgraded later during allocate_clusters */
>      s->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf,
>                                         PRL_PREALLOC_MODE_FALLOCATE,
>                                         &local_err);
> @@ -836,10 +847,6 @@ static int parallels_open(BlockDriverState *bs, QDict 
> *options, int flags,
>          goto fail_options;
>      }
>
> -    if (!bdrv_has_zero_init_truncate(bs->file->bs)) {
> -        s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
> -    }
> -
>      if ((flags & BDRV_O_RDWR) && !(flags & BDRV_O_INACTIVE)) {
>          s->header->inuse = cpu_to_le32(HEADER_INUSE_MAGIC);
>          ret = parallels_update_header(bs);
Reviewed-by: Denis V. Lunev <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]