From nobody Tue Apr 30 08:17:56 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=reject dis=none) header.from=mail.ru ARC-Seal: i=1; a=rsa-sha256; t=1652786650; cv=none; d=zohomail.com; s=zohoarc; b=NLrR4Qhy4yFNX9XLsPpoVZCiApo26CTPQbs9sqb+ye+S7ybM6QUULlaAKtIDGXwk6B01sw8WrX8Jt8/qhUVm4TpQqcYgt05krVD2I/qMY+D+wT5xZTEqDna4sDFUwPfxrZnmL5ldKWkKwmiNKlubPirqAt+hI3p8A4jWRmPnlmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652786650; 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:References:Sender:Subject:To; bh=lXeFWzl1NTbHm0tWova+0uwktU3BNMNgfPD1tTKDC+g=; b=JWfV/P/karyxS5fWzVpiXqUyzsC4/wXgCCwpi6mhk1FTfhUBUBO5R5yOH3LYcNxOR3kpjz8Fa5dunG7j4bQmYyxMdmfln2bqWIFuGlMPRJbKDw6sM2nbeSRpdd+CKNm61nv8CqfMoW+A9ksrgPYEmv6jjNgFDRXBET2AvJJ7rXk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652786650151776.4806200220563; Tue, 17 May 2022 04:24:10 -0700 (PDT) Received: from localhost ([::1]:36462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqvJA-0006hv-Vk for importer2@patchew.org; Tue, 17 May 2022 07:24:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqv7q-0005y8-0N; Tue, 17 May 2022 07:12:27 -0400 Received: from smtp60.i.mail.ru ([217.69.128.40]:47424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqv7m-0006cY-Mu; Tue, 17 May 2022 07:12:25 -0400 Received: by smtp60.i.mail.ru with esmtpa (envelope-from ) id 1nqv7i-0000gZ-9I; Tue, 17 May 2022 14:12:18 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail4; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:From:Subject:Content-Type:Content-Transfer-Encoding:To:Cc; bh=lXeFWzl1NTbHm0tWova+0uwktU3BNMNgfPD1tTKDC+g=; t=1652785942;x=1653391342; b=GBI3TUiIsM/p6pmeqZ7m62sg2ovuVErJMiizCeQBSWjdiALWpNcvlkVs127CycPCckomn90okt20jDBsK2Zr+G+IRn6ziZCMmGvAurBg1RzlIQNMlgmovUJrRwFxidOtJsNxDpOnlw5E7ASvI7UnjbU5jV2VKSNENGopUWTTKpNKqAPdCyegDNYYEynNJIUK23LrXv7nSXlKUQk3g98H7lHjOBXVahCFUQqcqIn553LJZ1p082vi2ykI85kRdR/krj8QFT133YyhAuS9iVuVBTYrw/eA9yn1xYbYqjCRKZFu18F0oLEiralmWlBpNDMSwpcDrZJ5ibDh1z4gXVhtCQ==; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, v.sementsov-og@mail.ru, jsnow@redhat.com, Vladimir Sementsov-Ogievskiy , Nikita Lapshin Subject: [PATCH v4 1/3] block: block_dirty_bitmap_merge(): fix error path Date: Tue, 17 May 2022 14:12:04 +0300 Message-Id: <20220517111206.23585-2-v.sementsov-og@mail.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220517111206.23585-1-v.sementsov-og@mail.ru> References: <20220517111206.23585-1-v.sementsov-og@mail.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp60.i.mail.ru; auth=pass smtp.auth=v.sementsov-og@mail.ru smtp.mailfrom=v.sementsov-og@mail.ru X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9AB830312DE1E2EF80445B7287171AC0AAB135BFD257B16CA182A05F53808504070A2259CC62BA75DC980702FC437F40EA487356702ACCF71FAD089AF8EADD811 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70312E9A300D47E3BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A69A378178A91E348638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8028854DC24ABB61E2CC9733371944C106F9789CCF6C18C3F8528715B7D10C86878DA827A17800CE74A95F4E53E8DCE969FA2833FD35BB23D9E625A9149C048EE9ECD01F8117BC8BEA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCDC33BF1C4DF763763AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F790063768889A976CB567F3D81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F3F410F14AF5AD977156CCFE7AF13BCA4B5C8C57E37DE458BEDA766A37F9254B7 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBB0624710993A7B7B75A1415F4E783A9E06CE7118C150E429C2B6934AE262D3EE7EAB7254005DCED1C39E39C5FB3188C4EAF44D9B582CE87C8A4C02DF684249C2E763F503762DF503031C89702B531498E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34324A9840C798D500656C01C4AF402F7D8350087D04C516DE46402529BC7ED6341BBC2DBFF90C3EED1D7E09C32AA3244CE65009A008034114BE0D2D135BA91A1581560E2432555DBB27AC49D2B05FCCD8 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj3fsA429394OdaXGVcyyDfg== X-Mailru-Sender: 6C3E74F07C41AE9425C26D04B7325D44E891999DDF3A5D61B567A3E9F70B9B48E6FC31F8B608FCDFE6462B2528CDCABCE234FDC7CE4030BEBA6D275AA6409EB3BDC3C9FB484E02823A35ECB215E68A28E3F6503ABEB32C155FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok 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=217.69.128.40; envelope-from=v.sementsov-og@mail.ru; helo=smtp60.i.mail.ru X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL=1.31, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @mail.ru) X-ZM-MESSAGEID: 1652786650773100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy At the end we ignore failure of bdrv_merge_dirty_bitmap() and report success. And still set errp. That's wrong. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Nikita Lapshin Reviewed-by: Kevin Wolf --- block/monitor/bitmap-qmp-cmds.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/monitor/bitmap-qmp-cmds.c b/block/monitor/bitmap-qmp-cmd= s.c index 2b677c4a2f..bd10468596 100644 --- a/block/monitor/bitmap-qmp-cmds.c +++ b/block/monitor/bitmap-qmp-cmds.c @@ -309,7 +309,10 @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *= node, const char *target, } =20 /* Merge into dst; dst is unchanged on failure. */ - bdrv_merge_dirty_bitmap(dst, anon, backup, errp); + if (!bdrv_merge_dirty_bitmap(dst, anon, backup, errp)) { + dst =3D NULL; + goto out; + } =20 out: bdrv_release_dirty_bitmap(anon); --=20 2.35.1 From nobody Tue Apr 30 08:17:56 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=reject dis=none) header.from=mail.ru ARC-Seal: i=1; a=rsa-sha256; t=1652786477; cv=none; d=zohomail.com; s=zohoarc; b=i5f+8ZlphAMBLXrqYnrStN228m/TCrOvjIdxqYy7VtxNNKl2OzY+yqMZiO3xZZx/DrTLEF7xqBXzaYEs8yy3b1m9XE/QCMduD/Kdgn/sTO4RglyQEtPr/IB0aBTsYBvmQdVg1hxD11v1zv9r8Fah/6yhGn0FeyYkScmCkDe55yA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652786477; 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:References:Sender:Subject:To; bh=DlgD5rCdKUrMK0tSXEA/KGQdqoOomidNRcT4NrOR5U8=; b=eNyeNpZw1wY1gAT2AuRgVahtoA73TGWxZX/UoxcWLWuym6wccOpQToit1knJdAj6X7FQirpy1JS9+HS/LJUuqkzz515b5eecwD8fVQjTVcx8U6OyqLlo2ceQSBN8B/fy3Jz5raJ3FoaHgQrK9IHHeDI5kpo1fz7R79AdxiWBrBY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652786477336934.8901088774445; Tue, 17 May 2022 04:21:17 -0700 (PDT) Received: from localhost ([::1]:60260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqvGN-0003V3-Kd for importer2@patchew.org; Tue, 17 May 2022 07:21:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqv7o-0005x5-T7; Tue, 17 May 2022 07:12:24 -0400 Received: from smtp60.i.mail.ru ([217.69.128.40]:47660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqv7m-0006cd-EE; Tue, 17 May 2022 07:12:24 -0400 Received: by smtp60.i.mail.ru with esmtpa (envelope-from ) id 1nqv7i-0000gZ-Op; Tue, 17 May 2022 14:12:19 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail4; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:From:Subject:Content-Type:Content-Transfer-Encoding:To:Cc; bh=DlgD5rCdKUrMK0tSXEA/KGQdqoOomidNRcT4NrOR5U8=; t=1652785942;x=1653391342; b=L1eWfiZc4Q1MYj+VElOLiaf/cfPO4+q/aIdSW1FBFmHp9EqG2j0C7bIBYO4BKWI7AH/sq9viNjEGUoonfJVrorDikGOWSTPNV6T5F3z0yIrzR9BB43ZWYz51zdTZ5PifCeVO8RqChNRbJ42TvAiodQbmqGO17tl/2CXqC15VYjmHt75wN0eID8w2XjwuoTq2sTXL/K5amSAmIlumuJqXjdfK83NIXlFKIz7csNckWF64DF3Of7wGr3K4tFIinJRjMn0xdLTLK9GoQsHsjAg/xZqcSYfYKDd2yH7wEkioh8YkMTu5kL4XXHNP3sJe0AWByJFme80rgRKoTYf47P54hg==; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, v.sementsov-og@mail.ru, jsnow@redhat.com, Vladimir Sementsov-Ogievskiy Subject: [PATCH v4 2/3] block: improve block_dirty_bitmap_merge(): don't allocate extra bitmap Date: Tue, 17 May 2022 14:12:05 +0300 Message-Id: <20220517111206.23585-3-v.sementsov-og@mail.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220517111206.23585-1-v.sementsov-og@mail.ru> References: <20220517111206.23585-1-v.sementsov-og@mail.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp60.i.mail.ru; auth=pass smtp.auth=v.sementsov-og@mail.ru smtp.mailfrom=v.sementsov-og@mail.ru X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9AB830312DE1E2EF89CD709D1FD35DE978688BB130250C40A182A05F53808504070A2259CC62BA75DEBEF13B6F19467BFE766375DD87FEDF234983572610A3C9E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B9FBA884A7C9B8BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006374A24022C550661178638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8028854DC24ABB61E783DAA760A48A6E36F9789CCF6C18C3F8528715B7D10C86878DA827A17800CE74A95F4E53E8DCE969FA2833FD35BB23D9E625A9149C048EE33AC447995A7AD182CC0D3CB04F14752D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B8C7ADC89C2F0B2A5A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCEEA0202A80E0F0E63AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F7900637EA30E508AFFB29A2D81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F3F410F14AF5AD977156CCFE7AF13BCA4B5C8C57E37DE458BEDA766A37F9254B7 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CBB0624710993A7B7B75A1415F4E783A9F6E4874E5DAE503F9C2B6934AE262D3EE7EAB7254005DCED1C39E39C5FB3188C4EAF44D9B582CE87C8A4C02DF684249C42578FD4EBC74EEF699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D342B8615F5CFAD9D02B2D916688FE5360A11B09852D9EFA88265A3F8CA452357649745169ED6F751301D7E09C32AA3244CE65009A0080341142CCF783E6D79E5388894E9C85370243EAD832FF50B3043B1 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj3fsA429394O6iODQeOHpsg== X-Mailru-Sender: 6C3E74F07C41AE9425C26D04B7325D44E891999DDF3A5D61B567A3E9F70B9B48A40AD7AC6ECEA9DFE6462B2528CDCABCE234FDC7CE4030BEBA6D275AA6409EB3BDC3C9FB484E02823A35ECB215E68A28E3F6503ABEB32C155FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok 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=217.69.128.40; envelope-from=v.sementsov-og@mail.ru; helo=smtp60.i.mail.ru X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL=1.31, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @mail.ru) X-ZM-MESSAGEID: 1652786479721100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We don't need extra bitmap. All we need is to backup the original bitmap when we do first merge. So, drop extra temporary bitmap and work directly with target and backup. Still to keep old semantics, that on failure target is unchanged and user don't need to restore, we need a local_backup variable and do restore ourselves on failure path. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/monitor/bitmap-qmp-cmds.c | 41 +++++++++++++++++---------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/block/monitor/bitmap-qmp-cmds.c b/block/monitor/bitmap-qmp-cmd= s.c index bd10468596..282363606f 100644 --- a/block/monitor/bitmap-qmp-cmds.c +++ b/block/monitor/bitmap-qmp-cmds.c @@ -261,8 +261,9 @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *n= ode, const char *target, HBitmap **backup, Error **errp) { BlockDriverState *bs; - BdrvDirtyBitmap *dst, *src, *anon; + BdrvDirtyBitmap *dst, *src; BlockDirtyBitmapOrStrList *lst; + HBitmap *local_backup =3D NULL; =20 GLOBAL_STATE_CODE(); =20 @@ -271,12 +272,6 @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *= node, const char *target, return NULL; } =20 - anon =3D bdrv_create_dirty_bitmap(bs, bdrv_dirty_bitmap_granularity(ds= t), - NULL, errp); - if (!anon) { - return NULL; - } - for (lst =3D bms; lst; lst =3D lst->next) { switch (lst->value->type) { const char *name, *node; @@ -285,8 +280,7 @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *n= ode, const char *target, src =3D bdrv_find_dirty_bitmap(bs, name); if (!src) { error_setg(errp, "Dirty bitmap '%s' not found", name); - dst =3D NULL; - goto out; + goto fail; } break; case QTYPE_QDICT: @@ -294,29 +288,36 @@ BdrvDirtyBitmap *block_dirty_bitmap_merge(const char = *node, const char *target, name =3D lst->value->u.external.name; src =3D block_dirty_bitmap_lookup(node, name, NULL, errp); if (!src) { - dst =3D NULL; - goto out; + goto fail; } break; default: abort(); } =20 - if (!bdrv_merge_dirty_bitmap(anon, src, NULL, errp)) { - dst =3D NULL; - goto out; + /* We do backup only for first merge operation */ + if (!bdrv_merge_dirty_bitmap(dst, src, + local_backup ? NULL : &local_backup, + errp)) + { + goto fail; } } =20 - /* Merge into dst; dst is unchanged on failure. */ - if (!bdrv_merge_dirty_bitmap(dst, anon, backup, errp)) { - dst =3D NULL; - goto out; + if (backup) { + *backup =3D local_backup; + } else { + hbitmap_free(local_backup); } =20 - out: - bdrv_release_dirty_bitmap(anon); return dst; + +fail: + if (local_backup) { + bdrv_restore_dirty_bitmap(dst, local_backup); + } + + return NULL; } =20 void qmp_block_dirty_bitmap_merge(const char *node, const char *target, --=20 2.35.1 From nobody Tue Apr 30 08:17:56 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=reject dis=none) header.from=mail.ru ARC-Seal: i=1; a=rsa-sha256; t=1652786614; cv=none; d=zohomail.com; s=zohoarc; b=BXE8M8Xr9jdVoV6qYYpq7BwyQa4erclhdhx5DQaFF5mxgvb9R8Z9crKvYlQWUU5hxrji/UsR0I9XNDrYLr4DBZJr4h7waybgHF+BUC2R+ig4mNkT+tICJeGKBNMRSz/byuxpECm4F4fB9EylOqqoVM+577bxo7+fhs/5BVNVgyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652786614; 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:References:Sender:Subject:To; bh=F97noarA6sQtasLZKFD6CpxHuA6P72tlTOEHWTDiJ10=; b=Viv2VNUDVcZRQfjm2E7sDQhlMA8MOeK+Z9Q1PAayZNgzZk1RVc5Kr64lUy65D6PDDRh0DnGusHU+IBTQZkxa27JTgqo41NSrMKAVehLprgl1DQing0WxGGcadykxBuAjaql5aLd7F4P2YQqvA5XqRSYK7/hn1BgCw/RVxr3uJuE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1652786614117903.383438949991; Tue, 17 May 2022 04:23:34 -0700 (PDT) Received: from localhost ([::1]:35124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nqvIb-0005lO-1F for importer2@patchew.org; Tue, 17 May 2022 07:23:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqv7q-0005yA-9j; Tue, 17 May 2022 07:12:27 -0400 Received: from smtp60.i.mail.ru ([217.69.128.40]:47920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nqv7m-0006ck-My; Tue, 17 May 2022 07:12:26 -0400 Received: by smtp60.i.mail.ru with esmtpa (envelope-from ) id 1nqv7j-0000gZ-Cy; Tue, 17 May 2022 14:12:19 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail4; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:From:Subject:Content-Type:Content-Transfer-Encoding:To:Cc; bh=F97noarA6sQtasLZKFD6CpxHuA6P72tlTOEHWTDiJ10=; t=1652785942;x=1653391342; b=o7U3Hx1MlHmC/24qbtYbM3MJCPeKNdz2vQaEl5xzCQiOhljzB8NSTAD8Adn/RvEBfV28Y3KBhWzKn2MbNzaEDtOqVF/iG5r9mmxYMXoJJTJUHEB3CUxqTfQphFLEiA29JgsZcmCsbXYxynoiazJko1uOIAIImIIh0BMYZIBRyslOXfyxVjH2Twu+7QOfrkRR7SUH62GI87XibYAnq9+kllkhyAUxodGUA4iNFwvCs3Ia75NXXZuXEKOfun41FTDaENwr6I0aW8ES6Ai0BP8FbipRVgEilK/6cgZGIlXL5uVvpPqC9POV0an9yvofee2F4ChYlpE4+ecqQT/x5hO18g==; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, eblake@redhat.com, hreitz@redhat.com, kwolf@redhat.com, v.sementsov-og@mail.ru, jsnow@redhat.com, Vladimir Sementsov-Ogievskiy , Nikita Lapshin Subject: [PATCH v4 3/3] block: simplify handling of try to merge different sized bitmaps Date: Tue, 17 May 2022 14:12:06 +0300 Message-Id: <20220517111206.23585-4-v.sementsov-og@mail.ru> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220517111206.23585-1-v.sementsov-og@mail.ru> References: <20220517111206.23585-1-v.sementsov-og@mail.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp60.i.mail.ru; auth=pass smtp.auth=v.sementsov-og@mail.ru smtp.mailfrom=v.sementsov-og@mail.ru X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD9F33B3806BF114D159E7BD6746107077164F3C96AD71A0548182A05F5380850404C228DA9ACA6FE279E9E09E4BEACFDAAFBE131CEB22D38A46F8A4170A416843F34983572610A3C9E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE797F4D2EDC29AFAF7EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637BD7DFB1CDE6DDE538638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84A76FF60AA8E232B9039DF19F01E1DED6F9789CCF6C18C3F8528715B7D10C86878DA827A17800CE78A0F7C24A37A3D769FA2833FD35BB23D9E625A9149C048EE26055571C92BF10FBDFBBEFFF4125B51D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B05EF1B56D39DD5F7389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F790063734032FEA597FA516D81D268191BDAD3DBD4B6F7A4D31EC0BEA7A3FFF5B025636D81D268191BDAD3D78DA827A17800CE70DB7A41A747CC8E1EC76A7562686271EEC990983EF5C03292E808ACE2090B5E14AD6D5ED66289B5259CC434672EE63711DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C33E10B8FB1984732735872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FCADF0C5300679BDA76F34F224E2F626185823B7F2EE52A235B1881A6453793CE9C32612AADDFBE0614869453249F34FA4C627013B076BABB6939BCEF9C803809F250ECE3C382DB3F9DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3457FA942CB4462B4C6E50531A0D9814619CDA90DB010BD21FF1C81AB120B1098AD5C4AEB1BA9A2FD31D7E09C32AA3244CC1DADF74B566720E45F6DDBD79FEBA0FD08D48398F32B4A627AC49D2B05FCCD8 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj3fsA429394O6iODQeOHpsg== X-Mailru-Sender: 6C3E74F07C41AE9425C26D04B7325D44E891999DDF3A5D6108D809B65C5C842D9836823514443C75E6462B2528CDCABCE234FDC7CE4030BEBA6D275AA6409EB3BDC3C9FB484E02823A35ECB215E68A28E3F6503ABEB32C155FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok 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=217.69.128.40; envelope-from=v.sementsov-og@mail.ru; helo=smtp60.i.mail.ru X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_VALIDITY_RPBL=1.31, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @mail.ru) X-ZM-MESSAGEID: 1652786614476100001 Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We have too much logic to simply check that bitmaps are of the same size. Let's just define that hbitmap_merge() and bdrv_dirty_bitmap_merge_internal() require their argument bitmaps be of same size, this simplifies things. Let's look through the callers: For backup_init_bcs_bitmap() we already assert that merge can't fail. In bdrv_reclaim_dirty_bitmap_locked() we gracefully handle the error that can't happen: successor always has same size as its parent, drop this logic. In bdrv_merge_dirty_bitmap() we already has assertion and separate check. Make the check explicit and improve error message. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Nikita Lapshin Reviewed-by: Kevin Wolf --- include/block/block_int-io.h | 2 +- include/qemu/hbitmap.h | 15 ++------------- block/backup.c | 6 ++---- block/dirty-bitmap.c | 26 +++++++++++--------------- util/hbitmap.c | 25 +++++++------------------ 5 files changed, 23 insertions(+), 51 deletions(-) diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index bb454200e5..ded29e7494 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -102,7 +102,7 @@ bool blk_dev_is_tray_open(BlockBackend *blk); void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); -bool bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest, +void bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, HBitmap **backup, bool lock); =20 diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 5bd986aa44..af4e4ab746 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -76,20 +76,9 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size); * * Store result of merging @a and @b into @result. * @result is allowed to be equal to @a or @b. - * - * Return true if the merge was successful, - * false if it was not attempted. - */ -bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result); - -/** - * hbitmap_can_merge: - * - * hbitmap_can_merge(a, b) && hbitmap_can_merge(a, result) is sufficient a= nd - * necessary for hbitmap_merge will not fail. - * + * All bitmaps must have same size. */ -bool hbitmap_can_merge(const HBitmap *a, const HBitmap *b); +void hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result); =20 /** * hbitmap_empty: diff --git a/block/backup.c b/block/backup.c index 5cfd0b999c..b2b649e305 100644 --- a/block/backup.c +++ b/block/backup.c @@ -228,15 +228,13 @@ out: =20 static void backup_init_bcs_bitmap(BackupBlockJob *job) { - bool ret; uint64_t estimate; BdrvDirtyBitmap *bcs_bitmap =3D block_copy_dirty_bitmap(job->bcs); =20 if (job->sync_mode =3D=3D MIRROR_SYNC_MODE_BITMAP) { bdrv_clear_dirty_bitmap(bcs_bitmap, NULL); - ret =3D bdrv_dirty_bitmap_merge_internal(bcs_bitmap, job->sync_bit= map, - NULL, true); - assert(ret); + bdrv_dirty_bitmap_merge_internal(bcs_bitmap, job->sync_bitmap, NUL= L, + true); } else if (job->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP) { /* * We can't hog the coroutine to initialize this thoroughly. diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index da1b91166f..bf3dc0512a 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -309,10 +309,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(Bdrv= DirtyBitmap *parent, return NULL; } =20 - if (!hbitmap_merge(parent->bitmap, successor->bitmap, parent->bitmap))= { - error_setg(errp, "Merging of parent and successor bitmap failed"); - return NULL; - } + hbitmap_merge(parent->bitmap, successor->bitmap, parent->bitmap); =20 parent->disabled =3D successor->disabled; parent->busy =3D false; @@ -912,13 +909,15 @@ bool bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, c= onst BdrvDirtyBitmap *src, goto out; } =20 - if (!hbitmap_can_merge(dest->bitmap, src->bitmap)) { - error_setg(errp, "Bitmaps are incompatible and can't be merged"); + if (bdrv_dirty_bitmap_size(src) !=3D bdrv_dirty_bitmap_size(dest)) { + error_setg(errp, "Bitmaps are of different sizes (destination size= is %" + PRId64 ", source size is %" PRId64 ") and can't be merg= ed", + bdrv_dirty_bitmap_size(dest), bdrv_dirty_bitmap_size(sr= c)); goto out; } =20 - ret =3D bdrv_dirty_bitmap_merge_internal(dest, src, backup, false); - assert(ret); + bdrv_dirty_bitmap_merge_internal(dest, src, backup, false); + ret =3D true; =20 out: bdrv_dirty_bitmaps_unlock(dest->bs); @@ -932,17 +931,16 @@ out: /** * bdrv_dirty_bitmap_merge_internal: merge src into dest. * Does NOT check bitmap permissions; not suitable for use as public API. + * @dest, @src and @backup (if not NULL) must have same size. * * @backup: If provided, make a copy of dest here prior to merge. * @lock: If true, lock and unlock bitmaps on the way in/out. - * returns true if the merge succeeded; false if unattempted. */ -bool bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest, +void bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, HBitmap **backup, bool lock) { - bool ret; IO_CODE(); =20 assert(!bdrv_dirty_bitmap_readonly(dest)); @@ -959,9 +957,9 @@ bool bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *= dest, if (backup) { *backup =3D dest->bitmap; dest->bitmap =3D hbitmap_alloc(dest->size, hbitmap_granularity(*ba= ckup)); - ret =3D hbitmap_merge(*backup, src->bitmap, dest->bitmap); + hbitmap_merge(*backup, src->bitmap, dest->bitmap); } else { - ret =3D hbitmap_merge(dest->bitmap, src->bitmap, dest->bitmap); + hbitmap_merge(dest->bitmap, src->bitmap, dest->bitmap); } =20 if (lock) { @@ -970,6 +968,4 @@ bool bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *= dest, bdrv_dirty_bitmaps_unlock(src->bs); } } - - return ret; } diff --git a/util/hbitmap.c b/util/hbitmap.c index ea989e1f0e..297db35fb1 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -873,11 +873,6 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size) } } =20 -bool hbitmap_can_merge(const HBitmap *a, const HBitmap *b) -{ - return (a->orig_size =3D=3D b->orig_size); -} - /** * hbitmap_sparse_merge: performs dst =3D dst | src * works with differing granularities. @@ -901,28 +896,24 @@ static void hbitmap_sparse_merge(HBitmap *dst, const = HBitmap *src) * Given HBitmaps A and B, let R :=3D A (BITOR) B. * Bitmaps A and B will not be modified, * except when bitmap R is an alias of A or B. - * - * @return true if the merge was successful, - * false if it was not attempted. + * Bitmaps must have same size. */ -bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result) +void hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result) { int i; uint64_t j; =20 - if (!hbitmap_can_merge(a, b) || !hbitmap_can_merge(a, result)) { - return false; - } - assert(hbitmap_can_merge(b, result)); + assert(a->orig_size =3D=3D result->orig_size); + assert(b->orig_size =3D=3D result->orig_size); =20 if ((!hbitmap_count(a) && result =3D=3D b) || (!hbitmap_count(b) && result =3D=3D a)) { - return true; + return; } =20 if (!hbitmap_count(a) && !hbitmap_count(b)) { hbitmap_reset_all(result); - return true; + return; } =20 if (a->granularity !=3D b->granularity) { @@ -935,7 +926,7 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, = HBitmap *result) if (b !=3D result) { hbitmap_sparse_merge(result, b); } - return true; + return; } =20 /* This merge is O(size), as BITS_PER_LONG and HBITMAP_LEVELS are cons= tant. @@ -951,8 +942,6 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, = HBitmap *result) =20 /* Recompute the dirty count */ result->count =3D hb_count_between(result, 0, result->size - 1); - - return true; } =20 char *hbitmap_sha256(const HBitmap *bitmap, Error **errp) --=20 2.35.1