From nobody Mon May 12 14:00:21 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1695142832; cv=none; d=zohomail.com; s=zohoarc; b=eNslS2rf3We97NZ1gR34JFegODlAfgDvf9U/vhDS19aXGz6V+es49Vbzub4oezskjOiO9upO+Owfu7Qv+8wigaCCthx4v6Wh8m/6pzyzof60WeEv4HKSMwT0ULMPh7q0zpL+6ZIE5aKVMVAKcIsLBApiHHmSCBa1gWzEZGzI10g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695142832; 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=apwYKk0FW82pqWLnux8T8Ah3sJvQPK+NrnzvTSd9PpQ=; b=FhOoHK5N2EIvmQ+9iCIi/oyAdl8p9CjWIYVsyXfhounfqxYJjDBokVxMw11erslucrKQ81ZfmSZC+QZ+FEVD0V0ZJJQr4QnvYOhBjfyVDFCNd6jokLOKZhzv1/vO6bNMMt05TF9AWsnWNYwENkLZXaCpAntA4bFyYqUQK/ElXj4= 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+importer2=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 1695142832856966.947174995178; Tue, 19 Sep 2023 10:00:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qie3H-0003iu-Ks; Tue, 19 Sep 2023 12:58:19 -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 1qie3C-0003go-MQ; Tue, 19 Sep 2023 12:58:14 -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 1qie37-0002Mg-Fq; Tue, 19 Sep 2023 12:58:14 -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 1qidzZ-00DUte-39; Tue, 19 Sep 2023 18:57:54 +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 v3 4/8] qemu-img: add chunk size parameter to compare_buffers() Date: Tue, 19 Sep 2023 19:58:00 +0300 Message-Id: <20230919165804.439110-5-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230919165804.439110-1-andrey.drobyshev@virtuozzo.com> References: <20230919165804.439110-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+importer2=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1695142833481100001 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 | 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, } =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 - * 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) { 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