qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, hreitz@redhat.com,
	eblake@redhat.com, den@virtuozzo.com
Subject: Re: [PATCH v3 4/8] qemu-img: add chunk size parameter to compare_buffers()
Date: Tue, 17 Oct 2023 21:30:28 +0200	[thread overview]
Message-ID: <ZS7g1NZCHC/Rblre@redhat.com> (raw)
In-Reply-To: <20230919165804.439110-5-andrey.drobyshev@virtuozzo.com>

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



  reply	other threads:[~2023-10-17 19:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 16:57 [PATCH v3 0/8] qemu-img: rebase: add compression support Andrey Drobyshev via
2023-09-19 16:57 ` [PATCH v3 1/8] qemu-img: rebase: stop when reaching EOF of old backing file Andrey Drobyshev via
2023-11-01  9:50   ` Michael Tokarev
2023-11-01 15:38     ` Andrey Drobyshev
2023-11-01 17:51       ` Michael Tokarev
2023-11-02 10:46         ` Kevin Wolf
2023-09-19 16:57 ` [PATCH v3 2/8] qemu-iotests: 024: add rebasing test case for overlay_size > backing_size Andrey Drobyshev via
2023-09-19 16:57 ` [PATCH v3 3/8] qemu-img: rebase: use backing files' BlockBackend for buffer alignment Andrey Drobyshev via
2023-09-19 16:58 ` [PATCH v3 4/8] qemu-img: add chunk size parameter to compare_buffers() Andrey Drobyshev via
2023-10-17 19:30   ` Kevin Wolf [this message]
2023-09-19 16:58 ` [PATCH v3 5/8] qemu-img: rebase: avoid unnecessary COW operations Andrey Drobyshev via
2023-09-19 16:58 ` [PATCH v3 6/8] iotests/{024, 271}: add testcases for qemu-img rebase Andrey Drobyshev via
2023-09-19 16:58 ` [PATCH v3 7/8] qemu-img: add compression option to rebase subcommand Andrey Drobyshev via
2023-09-19 16:58 ` [PATCH v3 8/8] iotests: add tests for "qemu-img rebase" with compression Andrey Drobyshev via
2023-10-02  6:35 ` [PATCH v3 0/8] qemu-img: rebase: add compression support Andrey Drobyshev
2023-10-16  8:34   ` Andrey Drobyshev
2023-10-17 20:08 ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZS7g1NZCHC/Rblre@redhat.com \
    --to=kwolf@redhat.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).