From nobody Tue Feb 10 05:45:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694794929; cv=none; d=zohomail.com; s=zohoarc; b=L8++O0mJIL9FZtthYBAY+XMGcDC88c++nOme5/4c+4LsYNmyPYwIDcgg2ZbZOJj2o1nh/uuwX42MSff42Ydja8q9aB0xvqRKHJA4388dmK4trDtlBb80qxPovPVj6RHC9hQ6lLIK9Y38UmiwQvvO+J1xlXYhGLV5b8mVSnBLguc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694794929; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=QPX62k65D9D12oPXRIE+ILzlaJizyiRH8/pdp+7q8TI=; b=Ai1c6rozcUxu3Ng4hit6YyBYWuvr6srqkAGNPxh7urv0Zm/J4ZI5mG8oYRk5aNGmmSwB+FmdyiEM6doznmhid4uMzbD67Pu23z6gM8YD24unF6NuIIBptwG+qXEf2iOfK+6qoDTHUR0+j/WvIXWWUUcJNaWwCheXwtd/seDzLsc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694794929169363.8459503059164; Fri, 15 Sep 2023 09:22:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhBYd-0005ND-SA; Fri, 15 Sep 2023 12:20:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qhBYQ-0005Dj-KR; Fri, 15 Sep 2023 12:20:27 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qhBYN-0000Rw-3L; Fri, 15 Sep 2023 12:20:26 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1qhBUx-00Ezdu-1C; Fri, 15 Sep 2023 18:20:15 +0200 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, eblake@redhat.com, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 4/8] qemu-img: add chunk size parameter to compare_buffers() Date: Fri, 15 Sep 2023 19:20:12 +0300 Message-Id: <20230915162016.141771-5-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230915162016.141771-1-andrey.drobyshev@virtuozzo.com> References: <20230915162016.141771-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Andrey Drobyshev From: Andrey Drobyshev via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1694794931432100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Blake Reviewed-by: Hanna Czenczek --- qemu-img.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d12e4a4753..fcd31d7b5b 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, } =20 /* - * 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 + * @pnum is set to the size of the buffer prefix aligned to @chsize that * has the same matching status as the first sector. */ 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) { bool res; - int64_t i =3D MIN(bytes, BDRV_SECTOR_SIZE); + int64_t i; =20 assert(bytes > 0); =20 + if (!chsize) { + chsize =3D BDRV_SECTOR_SIZE; + } + i =3D MIN(bytes, chsize); + res =3D !!memcmp(buf1, buf2, i); while (i < bytes) { - int64_t len =3D MIN(bytes - i, BDRV_SECTOR_SIZE); + int64_t len =3D MIN(bytes - i, chsize); =20 if (!!memcmp(buf1 + i, buf2 + i, len) !=3D res) { break; @@ -1559,7 +1565,7 @@ static int img_compare(int argc, char **argv) ret =3D 4; goto out; } - ret =3D compare_buffers(buf1, buf2, chunk, &pnum); + ret =3D compare_buffers(buf1, buf2, chunk, 0, &pnum); if (ret || pnum !=3D chunk) { qprintf(quiet, "Content mismatch at offset %" PRId64 "= !\n", offset + (ret ? 0 : pnum)); @@ -3878,7 +3884,7 @@ static int img_rebase(int argc, char **argv) int64_t pnum; =20 if (compare_buffers(buf_old + written, buf_new + written, - n - written, &pnum)) + n - written, 0, &pnum)) { if (buf_old_is_zero) { ret =3D blk_pwrite_zeroes(blk, offset + written, p= num, 0); --=20 2.39.3