From nobody Mon Sep 16 19:16:45 2024 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=1695283118; cv=none; d=zohomail.com; s=zohoarc; b=CD6/BK28pt3rFAmtt9AuO8hTWZCiSj7VeO/OKmRB2FmONFeV4lZkujJ11GcY/PbDC5Bn6FnaerZJmH0B69qZ1+6iH5XP1Bdr7ziwTauR3FGkRgHxOjS0xpfiNbhERSgjSkLj6l/A/+91OSsXCZEz8Zvx03abDx9pyWzkrS7I7dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695283118; 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=OnkyIqS4Qv5QQrhljMnRhQl/m8UiruDAkbFVi1lCI6U=; b=m8LRs9Rsqs0ApmejSZhFvv2bju+MWR0ULGqJOdyveu4kkP8R/AP44oT2vJYIfpXNyL0r49lpG+Hm1PoHtA7Mh+VIv6SpBQFC3zTOpC+VOABk2txBgqaKO4pzlMLxoPd758ZHj1YnqvWhmVI02y8McJxG7Z9uzO5BuouNRXNPwD4= 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 1695283118722606.1336648996916; Thu, 21 Sep 2023 00:58:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjEWn-0004yt-0z; Thu, 21 Sep 2023 03:55:13 -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 1qjEWi-0004lD-GE; Thu, 21 Sep 2023 03:55:08 -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 1qjEWg-0001WG-9I; Thu, 21 Sep 2023 03:55:08 -0400 Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=iris.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1qjEWR-00BsUn-0d; Thu, 21 Sep 2023 09:55:04 +0200 To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Alexander Ivanov Subject: [PULL v2 08/22] parallels: create mark_used() helper which sets bit in used bitmap Date: Thu, 21 Sep 2023 09:54:46 +0200 Message-Id: <20230921075500.694585-9-den@openvz.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921075500.694585-1-den@openvz.org> References: <20230921075500.694585-1-den@openvz.org> 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=den@openvz.org; 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: "Denis V. Lunev" From: "Denis V. Lunev" via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1695283119477100003 Content-Type: text/plain; charset="utf-8" This functionality is used twice already and next patch will add more code with it. Signed-off-by: Denis V. Lunev Reviewed-by: Alexander Ivanov --- block/parallels.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index af3b4894d7..66c86d87e3 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -178,6 +178,21 @@ static void parallels_set_bat_entry(BDRVParallelsState= *s, bitmap_set(s->bat_dirty_bmap, bat_entry_off(index) / s->bat_dirty_bloc= k, 1); } =20 +static int mark_used(BlockDriverState *bs, + unsigned long *bitmap, uint32_t bitmap_size, int64_t = off) +{ + BDRVParallelsState *s =3D bs->opaque; + uint32_t cluster_index =3D host_cluster_index(s, off); + if (cluster_index >=3D bitmap_size) { + return -E2BIG; + } + if (test_bit(cluster_index, bitmap)) { + return -EBUSY; + } + bitmap_set(bitmap, cluster_index, 1); + return 0; +} + static int64_t coroutine_fn GRAPH_RDLOCK allocate_clusters(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) @@ -621,7 +636,7 @@ parallels_check_duplicate(BlockDriverState *bs, BdrvChe= ckResult *res, BDRVParallelsState *s =3D bs->opaque; int64_t host_off, host_sector, guest_sector; unsigned long *bitmap; - uint32_t i, bitmap_size, cluster_index, bat_entry; + uint32_t i, bitmap_size, bat_entry; int n, ret =3D 0; uint64_t *buf =3D NULL; bool fixed =3D false; @@ -655,10 +670,9 @@ parallels_check_duplicate(BlockDriverState *bs, BdrvCh= eckResult *res, continue; } =20 - cluster_index =3D host_cluster_index(s, host_off); - assert(cluster_index < bitmap_size); - if (!test_bit(cluster_index, bitmap)) { - bitmap_set(bitmap, cluster_index, 1); + ret =3D mark_used(bs, bitmap, bitmap_size, host_off); + assert(ret !=3D -E2BIG); + if (ret =3D=3D 0) { continue; } =20 @@ -713,11 +727,13 @@ parallels_check_duplicate(BlockDriverState *bs, BdrvC= heckResult *res, * consistent for the new allocated clusters too. * * Note, clusters allocated outside the current image are not - * considered, and the bitmap size doesn't change. + * considered, and the bitmap size doesn't change. This specifical= ly + * means that -E2BIG is OK. */ - cluster_index =3D host_cluster_index(s, host_off); - if (cluster_index < bitmap_size) { - bitmap_set(bitmap, cluster_index, 1); + ret =3D mark_used(bs, bitmap, bitmap_size, host_off); + if (ret =3D=3D -EBUSY) { + res->check_errors++; + goto out_repair_bat; } =20 fixed =3D true; --=20 2.34.1