[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 4/8] qemu-img: add chunk size parameter to compare_buffers
From: |
Kevin Wolf |
Subject: |
Re: [PATCH v3 4/8] qemu-img: add chunk size parameter to compare_buffers() |
Date: |
Tue, 17 Oct 2023 21:30:28 +0200 |
Am 19.09.2023 um 18:58 hat Andrey Drobyshev geschrieben:
> Add @chsize param to the function which, if non-zero, would represent
> the chunk size to be used for comparison. If it's zero, then
> BDRV_SECTOR_SIZE is used as default chunk size, which is the previous
> behaviour.
>
> In particular, we're going to use this param in img_rebase() to make the
> write requests aligned to a predefined alignment value.
>
> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
> ---
> qemu-img.c | 24 +++++++++++++++---------
> 1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 4dc91505bf..0f67b021f7 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -1274,23 +1274,29 @@ static int is_allocated_sectors_min(const uint8_t
> *buf, int n, int *pnum,
> }
>
> /*
> - * Compares two buffers sector by sector. Returns 0 if the first
> - * sector of each buffer matches, non-zero otherwise.
> + * Compares two buffers chunk by chunk, where @chsize is the chunk size.
> + * If @chsize is 0, default chunk size of BDRV_SECTOR_SIZE is used.
> + * Returns 0 if the first chunk of each buffer matches, non-zero otherwise.
> *
> - * pnum is set to the sector-aligned size of the buffer prefix that
> - * has the same matching status as the first sector.
> + * @pnum is set to the size of the buffer prefix aligned to @chsize that
> + * has the same matching status as the first chunk.
> */
> static int compare_buffers(const uint8_t *buf1, const uint8_t *buf2,
> - int64_t bytes, int64_t *pnum)
> + int64_t bytes, uint64_t chsize, int64_t *pnum)
uint64_t might be too large, depending on the platform. memcmp() takes
size_t, so in theory we can get truncation.
I assume that we won't see a problem in practice because you'll never
pass that large values, but I'd prefer making chsize size_t here.
Kevin
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH v3 4/8] qemu-img: add chunk size parameter to compare_buffers(),
Kevin Wolf <=