From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584419927; cv=none; d=zohomail.com; s=zohoarc; b=d/a/h99gNb6v87XMPLGG4N/iRcIMSrJ1TCIQDMi9TjCUn2qHhk6/QrQ0bAkrLayDGgum5yrmTM0VAgU8kIN5UZY80dLGwY6XC2YOEzCtiWvhL3Tmsdh5nK1vlv79bCRf+dgRhs6Gr5LjkwKEUeghZ27GBPMW5+5ldqHV+MWMpuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584419927; h=Content-Type: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=ahENl3BNbjiX9217T8D2HNUwmfnYsYvdtYYCuVYsDWw=; b=LJZsgJStma+BB3q1lhvvEWsVWou+vWUwBZ1V1uhK3KHgwQau5F/EyoAiyYreazDxlW5d1e5/mHK6cXxNatTWqrmJM74fSF+rHZdgSsMjxnA/Lc52Yo7zQhYW9NlaKkIZWGyegWQgQfBuAya7B+NVl0F5EPw7IWPGLRYHoZ3763M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584419926999193.427280825151; Mon, 16 Mar 2020 21:38:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-280-pUWqR0HQOpCQIrsTy68kfQ-1; Tue, 17 Mar 2020 00:38:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AAFC98017CC; Tue, 17 Mar 2020 04:38:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EE7B10027A3; Tue, 17 Mar 2020 04:38:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B419286FED; Tue, 17 Mar 2020 04:38:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cTkC012302 for ; Tue, 17 Mar 2020 00:38:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7C97210027B0; Tue, 17 Mar 2020 04:38:29 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AE151036D00; Tue, 17 Mar 2020 04:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584419925; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ahENl3BNbjiX9217T8D2HNUwmfnYsYvdtYYCuVYsDWw=; b=VwBjvfVNtjcFFOtx8tJD3PPmrPJpC5S7zHIyIk/ikxdCoePB1qyw31Ej3YWX7kT/jEQpz2 QI+1b/CqvpIwWervcYTWss644mB0sv7mug8Z05TTe4GuN0PZy994YSK+NNBE7FK95lzU4D kHshQoQu+/15t7tss2EbsksaNeZ8Qcg= X-MC-Unique: pUWqR0HQOpCQIrsTy68kfQ-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 01/10] hbitmap: assert that we don't create bitmap larger than INT64_MAX Date: Tue, 17 Mar 2020 00:38:10 -0400 Message-Id: <20200317043819.20197-2-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We have APIs which returns signed int64_t, to be able to return error. Therefore we can't handle bitmaps with absolute size larger than (INT64_MAX+1). Still, keep maximum to be INT64_MAX which is a bit safer. Note, that bitmaps are used to represent disk images, which can't exceed INT64_MAX anyway. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: John Snow Message-id: 20200205112041.6003-2-vsementsov@virtuozzo.com Signed-off-by: John Snow --- util/hbitmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/hbitmap.c b/util/hbitmap.c index 242c6e519c..7f9b3e0cd7 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -716,6 +716,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity) HBitmap *hb =3D g_new0(struct HBitmap, 1); unsigned i; =20 + assert(size <=3D INT64_MAX); hb->orig_size =3D size; =20 assert(granularity >=3D 0 && granularity < 64); @@ -746,6 +747,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size) uint64_t num_elements =3D size; uint64_t old; =20 + assert(size <=3D INT64_MAX); hb->orig_size =3D size; =20 /* Size comes in as logical elements, adjust for granularity. */ --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584419947; cv=none; d=zohomail.com; s=zohoarc; b=eSEdt7G4YVee8MXOn3FGk9iBJ4D2Pq+yjKQp7H//p4RdfLPq1LAcIl1HWXmUUJc2viGVPXL/wsQKs/370lfmiz0AdJX0TMpHX+KXMzyEUHcMWjp97D/p//RgU50fEVyUr1o8WuwPMqJLAHKedTpqkrIZDcwo43ukbLWTxRz1Vhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584419947; h=Content-Type: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=UF7bUzZTexTsPuG4oMZyLXC9yux60lZwTIeJ+jS+dJM=; b=MMSuw/kgKiZ5yVN6g+75GC07iekZBBRpsxtucyJh1fGtSq+6eaKnoYQE3nPbtVFlWtz1eIum4QG09J8/m2fO38qjZosnIHQAtWiCWFDwAm83u0MV+/eZRDJyWxNb5agS2SZunXm822isljXD/uJrHheorpaFy7WfdQVfEWwY65Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584419947628514.411521161279; Mon, 16 Mar 2020 21:39:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-356-hrp4hx7jMrm_qgHizGxs8w-1; Tue, 17 Mar 2020 00:39:03 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8691B13F9; Tue, 17 Mar 2020 04:38:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F1A45DA81; Tue, 17 Mar 2020 04:38:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 17DCA86FFE; Tue, 17 Mar 2020 04:38:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cVQw012315 for ; Tue, 17 Mar 2020 00:38:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C7D11009ABB; Tue, 17 Mar 2020 04:38:31 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE27C10016EB; Tue, 17 Mar 2020 04:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584419946; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UF7bUzZTexTsPuG4oMZyLXC9yux60lZwTIeJ+jS+dJM=; b=JI3fthPWhQDLCedXFDDPfcN5/eIPxUTJyFQvta7QwwWSlOXbmKEba3am6BzwfMHFlGjBGx URcZnIAd7LdDfyLh7sWdEHSAddMO4nnTC731F+8Mtuz9aWqn7o70bZ9dnf14Q5kEd8x8XF AmuNJiP6hL4qYfibi5sqnyUh1SEAfWk= X-MC-Unique: hrp4hx7jMrm_qgHizGxs8w-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 02/10] hbitmap: move hbitmap_iter_next_word to hbitmap.c Date: Tue, 17 Mar 2020 00:38:11 -0400 Message-Id: <20200317043819.20197-3-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy The function is definitely internal (it's not used by third party and it has complicated interface). Move it to .c file. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20200205112041.6003-3-vsementsov@virtuozzo.com Signed-off-by: John Snow --- include/qemu/hbitmap.h | 30 ------------------------------ util/hbitmap.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 1bf944ca3d..ab227b117f 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -362,34 +362,4 @@ void hbitmap_free_meta(HBitmap *hb); */ int64_t hbitmap_iter_next(HBitmapIter *hbi); =20 -/** - * hbitmap_iter_next_word: - * @hbi: HBitmapIter to operate on. - * @p_cur: Location where to store the next non-zero word. - * - * Return the index of the next nonzero word that is set in @hbi's - * associated HBitmap, and set *p_cur to the content of that word - * (bits before the index that was passed to hbitmap_iter_init are - * trimmed on the first call). Return -1, and set *p_cur to zero, - * if all remaining words are zero. - */ -static inline size_t hbitmap_iter_next_word(HBitmapIter *hbi, unsigned lon= g *p_cur) -{ - unsigned long cur =3D hbi->cur[HBITMAP_LEVELS - 1]; - - if (cur =3D=3D 0) { - cur =3D hbitmap_iter_skip_words(hbi); - if (cur =3D=3D 0) { - *p_cur =3D 0; - return -1; - } - } - - /* The next call will resume work from the next word. */ - hbi->cur[HBITMAP_LEVELS - 1] =3D 0; - *p_cur =3D cur; - return hbi->pos; -} - - #endif diff --git a/util/hbitmap.c b/util/hbitmap.c index 7f9b3e0cd7..a368dc5ef7 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -298,6 +298,35 @@ uint64_t hbitmap_count(const HBitmap *hb) return hb->count << hb->granularity; } =20 +/** + * hbitmap_iter_next_word: + * @hbi: HBitmapIter to operate on. + * @p_cur: Location where to store the next non-zero word. + * + * Return the index of the next nonzero word that is set in @hbi's + * associated HBitmap, and set *p_cur to the content of that word + * (bits before the index that was passed to hbitmap_iter_init are + * trimmed on the first call). Return -1, and set *p_cur to zero, + * if all remaining words are zero. + */ +static size_t hbitmap_iter_next_word(HBitmapIter *hbi, unsigned long *p_cu= r) +{ + unsigned long cur =3D hbi->cur[HBITMAP_LEVELS - 1]; + + if (cur =3D=3D 0) { + cur =3D hbitmap_iter_skip_words(hbi); + if (cur =3D=3D 0) { + *p_cur =3D 0; + return -1; + } + } + + /* The next call will resume work from the next word. */ + hbi->cur[HBITMAP_LEVELS - 1] =3D 0; + *p_cur =3D cur; + return hbi->pos; +} + /* Count the number of set bits between start and end, not accounting for * the granularity. Also an example of how to use hbitmap_iter_next_word. */ --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584419928; cv=none; d=zohomail.com; s=zohoarc; b=bDvqxy25RW2fhW65ro23+RveC1K/Rgy5DTv3kZ63lzNLookmlsr6Z8h4moSYv6BY0TbuvLqrx/kxHjHEg25TaMPqxHHf/R3AXMaWQZjC911+i0q3P/jXUBZVKGh4d7Y3I9Pzx+of78YVQRX+44vUTszaSfTRqB5ncjslqIVBkYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584419928; h=Content-Type: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=R+RAYyaC3HNbqMXrtUZdk3F7z6WrSOvH7OzdrSALIcU=; b=DzIBaISB/8Fbmpqr3BUuJAXLL+6hmw/7vy8vDcjL1P9+kTA7anjlSUVTRfSyBtpWqIrjd9tInUkciH2TYsmJE6vNS+Kc1vJ51OR/hwjehBugiTVA1y6a8KgPhOi/NmHVgU5p+giqTJGf72Pat1wsTgw4tpIBXGd4e1y28C+yuWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584419928082102.3050696221161; Mon, 16 Mar 2020 21:38:48 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-eB1Yh30xNt2ECre4VoEqOg-1; Tue, 17 Mar 2020 00:38:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 099CB800D53; Tue, 17 Mar 2020 04:38:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CBA3F10016EB; Tue, 17 Mar 2020 04:38:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DFDF11809567; Tue, 17 Mar 2020 04:38:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cX9P012328 for ; Tue, 17 Mar 2020 00:38:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id C104810027A1; Tue, 17 Mar 2020 04:38:33 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6E1910027A3; Tue, 17 Mar 2020 04:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584419926; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=R+RAYyaC3HNbqMXrtUZdk3F7z6WrSOvH7OzdrSALIcU=; b=I+v9uRlOwp6hw/SQIl613dCzygJboE0u9aoMJ0F7Whg/YJmodzS1vfai7HMldfCcY9urVh b+kUIfC7QPkwc+5DSVF9ePraXGJC02IZWpj5d0Cb/Hd6kixP9T7vWdIXw1cYFEbqn6HU5D d2fYFmbFld4XQbmE9UL80Ojvu5IZTh8= X-MC-Unique: eB1Yh30xNt2ECre4VoEqOg-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 03/10] hbitmap: unpublish hbitmap_iter_skip_words Date: Tue, 17 Mar 2020 00:38:12 -0400 Message-Id: <20200317043819.20197-4-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Function is internal and even commented as internal. Drop its definition from .h file. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20200205112041.6003-4-vsementsov@virtuozzo.com Signed-off-by: John Snow --- include/qemu/hbitmap.h | 7 ------- util/hbitmap.c | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index ab227b117f..15837a0e2d 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -297,13 +297,6 @@ void hbitmap_free(HBitmap *hb); */ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap *hb, uint64_t first= ); =20 -/* hbitmap_iter_skip_words: - * @hbi: HBitmapIter to operate on. - * - * Internal function used by hbitmap_iter_next and hbitmap_iter_next_word. - */ -unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi); - /* hbitmap_next_zero: * * Find next not dirty bit within selected range. If not found, return -1. diff --git a/util/hbitmap.c b/util/hbitmap.c index a368dc5ef7..26145d4b9e 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -104,7 +104,7 @@ struct HBitmap { /* Advance hbi to the next nonzero word and return it. hbi->pos * is updated. Returns zero if we reach the end of the bitmap. */ -unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi) +static unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi) { size_t pos =3D hbi->pos; const HBitmap *hb =3D hbi->hb; --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584419952; cv=none; d=zohomail.com; s=zohoarc; b=QNQLIYoQIqJiwCBvOrgQKAatcZ9KxgzGS/TAx3DrhnulKC21TgW4bvSAz/bd4vMmcpZBPTO1+6nl5AmaK1PkIfc5eP6iDeRbES7sh50ZMV6C5dFA1oTHMjZkaAAPPwU/i77DUU9bvicA4TW1MHv9rVmplzvQnpqgh0DroCPXe4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584419952; h=Content-Type: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=IKtPjnOC+qmsf/rsTqO8bPpSqljWlxweNtsd9zZRPu4=; b=cADWr5SZrrC0DkyavneJ5WsGxye5UJFwnDnvAr0rBYH37v7s4hm2mwYs1pFVihq+b5FAXIeUM3FktNHlBGfLOPFpsfxHfyRuDvKPbHNsGY7KgDIGSVXQgZZNvWcfAJwbq+hNyb93/voijlsRODuPMwtvppOqNyJ45ZV00Q6Nu+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 15844199520173.9080938199992943; Mon, 16 Mar 2020 21:39:12 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-241-FmJLcUFNPeKj3s_PDDxxzg-1; Tue, 17 Mar 2020 00:39:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38736107ACCD; Tue, 17 Mar 2020 04:39:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D34F60C84; Tue, 17 Mar 2020 04:39:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BD57018089D0; Tue, 17 Mar 2020 04:39:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4caYS012339 for ; Tue, 17 Mar 2020 00:38:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 028AE10027A1; Tue, 17 Mar 2020 04:38:36 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEAFB100E7E3; Tue, 17 Mar 2020 04:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584419951; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=IKtPjnOC+qmsf/rsTqO8bPpSqljWlxweNtsd9zZRPu4=; b=fTZlByL5spcC8x7lZvBKJCR3rYXsf0N2GjRowzHGe1qiAzEd4IGzBGHu29tX0L9bskJgra IpjbUaEtVQrIdqcUcELMQ0ClTGDGmbsXEyyvs/c9rfBcXH4l4Tg5unvxuCHfFIhiUDr7k+ Dpeyj1zzwhYeET0aW9zXyA1KKCbDB7g= X-MC-Unique: FmJLcUFNPeKj3s_PDDxxzg-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 04/10] hbitmap: drop meta bitmaps as they are unused Date: Tue, 17 Mar 2020 00:38:13 -0400 Message-Id: <20200317043819.20197-5-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20200205112041.6003-5-vsementsov@virtuozzo.com Signed-off-by: John Snow --- include/qemu/hbitmap.h | 21 -------- tests/test-hbitmap.c | 115 ----------------------------------------- util/hbitmap.c | 16 ------ 3 files changed, 152 deletions(-) diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 15837a0e2d..df922d8517 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -325,27 +325,6 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t = start, uint64_t count); bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_t *start, uint64_t *count); =20 -/* hbitmap_create_meta: - * Create a "meta" hbitmap to track dirtiness of the bits in this HBitmap. - * The caller owns the created bitmap and must call hbitmap_free_meta(hb) = to - * free it. - * - * Currently, we only guarantee that if a bit in the hbitmap is changed it - * will be reflected in the meta bitmap, but we do not yet guarantee the - * opposite. - * - * @hb: The HBitmap to operate on. - * @chunk_size: How many bits in @hb does one bit in the meta track. - */ -HBitmap *hbitmap_create_meta(HBitmap *hb, int chunk_size); - -/* hbitmap_free_meta: - * Free the meta bitmap of @hb. - * - * @hb: The HBitmap whose meta bitmap should be freed. - */ -void hbitmap_free_meta(HBitmap *hb); - /** * hbitmap_iter_next: * @hbi: HBitmapIter to operate on. diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index e1f867085f..aeaa0b3f22 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -22,7 +22,6 @@ =20 typedef struct TestHBitmapData { HBitmap *hb; - HBitmap *meta; unsigned long *bits; size_t size; size_t old_size; @@ -94,14 +93,6 @@ static void hbitmap_test_init(TestHBitmapData *data, } } =20 -static void hbitmap_test_init_meta(TestHBitmapData *data, - uint64_t size, int granularity, - int meta_chunk) -{ - hbitmap_test_init(data, size, granularity); - data->meta =3D hbitmap_create_meta(data->hb, meta_chunk); -} - static inline size_t hbitmap_test_array_size(size_t bits) { size_t n =3D DIV_ROUND_UP(bits, BITS_PER_LONG); @@ -144,9 +135,6 @@ static void hbitmap_test_teardown(TestHBitmapData *data, const void *unused) { if (data->hb) { - if (data->meta) { - hbitmap_free_meta(data->hb); - } hbitmap_free(data->hb); data->hb =3D NULL; } @@ -648,96 +636,6 @@ static void test_hbitmap_truncate_shrink_large(TestHBi= tmapData *data, hbitmap_test_truncate(data, size, -diff, 0); } =20 -static void hbitmap_check_meta(TestHBitmapData *data, - int64_t start, int count) -{ - int64_t i; - - for (i =3D 0; i < data->size; i++) { - if (i >=3D start && i < start + count) { - g_assert(hbitmap_get(data->meta, i)); - } else { - g_assert(!hbitmap_get(data->meta, i)); - } - } -} - -static void hbitmap_test_meta(TestHBitmapData *data, - int64_t start, int count, - int64_t check_start, int check_count) -{ - hbitmap_reset_all(data->hb); - hbitmap_reset_all(data->meta); - - /* Test "unset" -> "unset" will not update meta. */ - hbitmap_reset(data->hb, start, count); - hbitmap_check_meta(data, 0, 0); - - /* Test "unset" -> "set" will update meta */ - hbitmap_set(data->hb, start, count); - hbitmap_check_meta(data, check_start, check_count); - - /* Test "set" -> "set" will not update meta */ - hbitmap_reset_all(data->meta); - hbitmap_set(data->hb, start, count); - hbitmap_check_meta(data, 0, 0); - - /* Test "set" -> "unset" will update meta */ - hbitmap_reset_all(data->meta); - hbitmap_reset(data->hb, start, count); - hbitmap_check_meta(data, check_start, check_count); -} - -static void hbitmap_test_meta_do(TestHBitmapData *data, int chunk_size) -{ - uint64_t size =3D chunk_size * 100; - hbitmap_test_init_meta(data, size, 0, chunk_size); - - hbitmap_test_meta(data, 0, 1, 0, chunk_size); - hbitmap_test_meta(data, 0, chunk_size, 0, chunk_size); - hbitmap_test_meta(data, chunk_size - 1, 1, 0, chunk_size); - hbitmap_test_meta(data, chunk_size - 1, 2, 0, chunk_size * 2); - hbitmap_test_meta(data, chunk_size - 1, chunk_size + 1, 0, chunk_size = * 2); - hbitmap_test_meta(data, chunk_size - 1, chunk_size + 2, 0, chunk_size = * 3); - hbitmap_test_meta(data, 7 * chunk_size - 1, chunk_size + 2, - 6 * chunk_size, chunk_size * 3); - hbitmap_test_meta(data, size - 1, 1, size - chunk_size, chunk_size); - hbitmap_test_meta(data, 0, size, 0, size); -} - -static void test_hbitmap_meta_byte(TestHBitmapData *data, const void *unus= ed) -{ - hbitmap_test_meta_do(data, BITS_PER_BYTE); -} - -static void test_hbitmap_meta_word(TestHBitmapData *data, const void *unus= ed) -{ - hbitmap_test_meta_do(data, BITS_PER_LONG); -} - -static void test_hbitmap_meta_sector(TestHBitmapData *data, const void *un= used) -{ - hbitmap_test_meta_do(data, BDRV_SECTOR_SIZE * BITS_PER_BYTE); -} - -/** - * Create an HBitmap and test set/unset. - */ -static void test_hbitmap_meta_one(TestHBitmapData *data, const void *unuse= d) -{ - int i; - int64_t offsets[] =3D { - 0, 1, L1 - 1, L1, L1 + 1, L2 - 1, L2, L2 + 1, L3 - 1, L3, L3 + 1 - }; - - hbitmap_test_init_meta(data, L3 * 2, 0, 1); - for (i =3D 0; i < ARRAY_SIZE(offsets); i++) { - hbitmap_test_meta(data, offsets[i], 1, offsets[i], 1); - hbitmap_test_meta(data, offsets[i], L1, offsets[i], L1); - hbitmap_test_meta(data, offsets[i], L2, offsets[i], L2); - } -} - static void test_hbitmap_serialize_align(TestHBitmapData *data, const void *unused) { @@ -750,13 +648,6 @@ static void test_hbitmap_serialize_align(TestHBitmapDa= ta *data, g_assert_cmpint(r, =3D=3D, 64 << 3); } =20 -static void test_hbitmap_meta_zero(TestHBitmapData *data, const void *unus= ed) -{ - hbitmap_test_init_meta(data, 0, 0, 1); - - hbitmap_check_meta(data, 0, 0); -} - static void hbitmap_test_serialize_range(TestHBitmapData *data, uint8_t *buf, size_t buf_size, uint64_t pos, uint64_t count) @@ -1165,12 +1056,6 @@ int main(int argc, char **argv) hbitmap_test_add("/hbitmap/truncate/shrink/large", test_hbitmap_truncate_shrink_large); =20 - hbitmap_test_add("/hbitmap/meta/zero", test_hbitmap_meta_zero); - hbitmap_test_add("/hbitmap/meta/one", test_hbitmap_meta_one); - hbitmap_test_add("/hbitmap/meta/byte", test_hbitmap_meta_byte); - hbitmap_test_add("/hbitmap/meta/word", test_hbitmap_meta_word); - hbitmap_test_add("/hbitmap/meta/sector", test_hbitmap_meta_sector); - hbitmap_test_add("/hbitmap/serialize/align", test_hbitmap_serialize_align); hbitmap_test_add("/hbitmap/serialize/basic", diff --git a/util/hbitmap.c b/util/hbitmap.c index 26145d4b9e..b6d4b99a06 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -905,22 +905,6 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b,= HBitmap *result) return true; } =20 -HBitmap *hbitmap_create_meta(HBitmap *hb, int chunk_size) -{ - assert(!(chunk_size & (chunk_size - 1))); - assert(!hb->meta); - hb->meta =3D hbitmap_alloc(hb->size << hb->granularity, - hb->granularity + ctz32(chunk_size)); - return hb->meta; -} - -void hbitmap_free_meta(HBitmap *hb) -{ - assert(hb->meta); - hbitmap_free(hb->meta); - hb->meta =3D NULL; -} - char *hbitmap_sha256(const HBitmap *bitmap, Error **errp) { size_t size =3D bitmap->sizes[HBITMAP_LEVELS - 1] * sizeof(unsigned lo= ng); --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584420015; cv=none; d=zohomail.com; s=zohoarc; b=gt2aKMU5LJKZP9U4m2dJ0dqazZC0vmF+uvQtJ3uakpXhKrrJ254b5kdeV+X30wwHab3wRLWwAfOxMWGdk5dlzjtRrndC51Xt/mJEXs1Iwn9RL5rjD/jwJgzK9B5Rdd1ndCJaB5avcJSgha/BOsrjyBC1Hc9QS1jm/a8bSaGhJmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584420015; h=Content-Type: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=VaAFoqm52YsUqliURiVgvfFDyJQgBEAq3P+1a98RGJ4=; b=KbAIUZ4xu7KYtnqpO1FXC5dGM8OASTsb0iN4miU3PAe5XprLWE+QVjuKnfkni7PfcAMKjuE+6nViVW2hzKAqQPWM4vBzSo8iMvq/MRPOculzTaa4a6510hg08pgCwcqepmh22WcLVb9QCIJr4Ftjzz/vdNpMzQoqNxSjlRuPSv4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584420015705736.9448580144157; Mon, 16 Mar 2020 21:40:15 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-oqSbsRYiMGSF2B1hHcmA6w-1; Tue, 17 Mar 2020 00:39:14 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22C3D801E5C; Tue, 17 Mar 2020 04:39:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF3BE19C7F; Tue, 17 Mar 2020 04:39:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A12F9180887A; Tue, 17 Mar 2020 04:39:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cb3r012348 for ; Tue, 17 Mar 2020 00:38:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id D66E1100EBA4; Tue, 17 Mar 2020 04:38:37 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FC1010027A1; Tue, 17 Mar 2020 04:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584420014; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VaAFoqm52YsUqliURiVgvfFDyJQgBEAq3P+1a98RGJ4=; b=g38KGVCJ7YcqcG2PAtaZpRGSuhRr6u1bspfIQIuf8T4tYAHds5AV8Mm20kH63xfUTAiylH PpiFl2U5NPd3oq9wnQaYzvS0ed+prKCQ6cybOcbsDgxPW7kOD0bU924o+YB2y1LMvYy6eE KTdek7fsTh92Xp9WtSEfFszmS+nozTo= X-MC-Unique: oqSbsRYiMGSF2B1hHcmA6w-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 05/10] block/dirty-bitmap: switch _next_dirty_area and _next_zero to int64_t Date: Tue, 17 Mar 2020 00:38:14 -0400 Message-Id: <20200317043819.20197-6-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We are going to introduce bdrv_dirty_bitmap_next_dirty so that same variable may be used to store its return value and to be its parameter, so it would int64_t. Similarly, we are going to refactor hbitmap_next_dirty_area to use hbitmap_next_dirty together with hbitmap_next_zero, therefore we want hbitmap_next_zero parameter type to be int64_t too. So, for convenience update all parameters of *_next_zero and *_next_dirty_area to be int64_t. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20200205112041.6003-6-vsementsov@virtuozzo.com Signed-off-by: John Snow --- include/block/dirty-bitmap.h | 6 +++--- include/qemu/hbitmap.h | 7 +++---- block/dirty-bitmap.c | 6 +++--- nbd/server.c | 2 +- tests/test-hbitmap.c | 36 ++++++++++++++++++------------------ util/hbitmap.c | 13 ++++++++----- 6 files changed, 36 insertions(+), 34 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index e2b20ecab9..27c72cc56a 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -105,10 +105,10 @@ for (bitmap =3D bdrv_dirty_bitmap_first(bs); bitmap; \ bitmap =3D bdrv_dirty_bitmap_next(bitmap)) =20 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp= ); -int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et, - uint64_t bytes); +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, + int64_t bytes); bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, - uint64_t *offset, uint64_t *bytes); + int64_t *offset, int64_t *bytes); BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, Error **errp); =20 diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index df922d8517..b6e85f3d5d 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -304,10 +304,10 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitma= p *hb, uint64_t first); * @hb: The HBitmap to operate on * @start: The bit to start from. * @count: Number of bits to proceed. If @start+@count > bitmap size, the = whole - * bitmap is looked through. You can use UINT64_MAX as @count to search up= to + * bitmap is looked through. You can use INT64_MAX as @count to search up = to * the bitmap end. */ -int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t coun= t); +int64_t hbitmap_next_zero(const HBitmap *hb, int64_t start, int64_t count); =20 /* hbitmap_next_dirty_area: * @hb: The HBitmap to operate on @@ -322,8 +322,7 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t s= tart, uint64_t count); * @offset and @bytes appropriately. Otherwise returns false and leaves @o= ffset * and @bytes unchanged. */ -bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_t *start, - uint64_t *count); +bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount); =20 /** * hbitmap_iter_next: diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 7039e82520..af9f5411a6 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -860,14 +860,14 @@ char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap = *bitmap, Error **errp) return hbitmap_sha256(bitmap->bitmap, errp); } =20 -int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offs= et, - uint64_t bytes) +int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, + int64_t bytes) { return hbitmap_next_zero(bitmap->bitmap, offset, bytes); } =20 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, - uint64_t *offset, uint64_t *bytes) + int64_t *offset, int64_t *bytes) { return hbitmap_next_dirty_area(bitmap->bitmap, offset, bytes); } diff --git a/nbd/server.c b/nbd/server.c index 11a31094ff..3106aaf3b4 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2055,7 +2055,7 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitmap= *bitmap, uint64_t offset, bool next_dirty =3D !dirty; =20 if (dirty) { - end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin, UINT64_MAX); + end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin, INT64_MAX); } else { bdrv_set_dirty_iter(it, begin); end =3D bdrv_dirty_iter_next(it); diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index aeaa0b3f22..9d210dc18c 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -817,8 +817,8 @@ static void test_hbitmap_iter_and_reset(TestHBitmapData= *data, } =20 static void test_hbitmap_next_zero_check_range(TestHBitmapData *data, - uint64_t start, - uint64_t count) + int64_t start, + int64_t count) { int64_t ret1 =3D hbitmap_next_zero(data->hb, start, count); int64_t ret2 =3D start; @@ -837,7 +837,7 @@ static void test_hbitmap_next_zero_check_range(TestHBit= mapData *data, =20 static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t st= art) { - test_hbitmap_next_zero_check_range(data, start, UINT64_MAX); + test_hbitmap_next_zero_check_range(data, start, INT64_MAX); } =20 static void test_hbitmap_next_zero_do(TestHBitmapData *data, int granulari= ty) @@ -905,11 +905,11 @@ static void test_hbitmap_next_zero_after_truncate(Tes= tHBitmapData *data, } =20 static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data, - uint64_t offset, - uint64_t count) + int64_t offset, + int64_t count) { - uint64_t off1, off2; - uint64_t len1 =3D 0, len2; + int64_t off1, off2; + int64_t len1 =3D 0, len2; bool ret1, ret2; int64_t end; =20 @@ -945,24 +945,24 @@ static void test_hbitmap_next_dirty_area_do(TestHBitm= apData *data, int granularity) { hbitmap_test_init(data, L3, granularity); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); test_hbitmap_next_dirty_area_check(data, 0, 1); test_hbitmap_next_dirty_area_check(data, L3 - 1, 1); =20 hbitmap_set(data->hb, L2, 1); test_hbitmap_next_dirty_area_check(data, 0, 1); test_hbitmap_next_dirty_area_check(data, 0, L2); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); - test_hbitmap_next_dirty_area_check(data, L2 - 1, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 - 1, INT64_MAX); test_hbitmap_next_dirty_area_check(data, L2 - 1, 1); test_hbitmap_next_dirty_area_check(data, L2 - 1, 2); test_hbitmap_next_dirty_area_check(data, L2 - 1, 3); - test_hbitmap_next_dirty_area_check(data, L2, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2, INT64_MAX); test_hbitmap_next_dirty_area_check(data, L2, 1); test_hbitmap_next_dirty_area_check(data, L2 + 1, 1); =20 hbitmap_set(data->hb, L2 + 5, L1); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); test_hbitmap_next_dirty_area_check(data, L2 - 2, 8); test_hbitmap_next_dirty_area_check(data, L2 + 1, 5); test_hbitmap_next_dirty_area_check(data, L2 + 1, 3); @@ -974,16 +974,16 @@ static void test_hbitmap_next_dirty_area_do(TestHBitm= apData *data, test_hbitmap_next_dirty_area_check(data, L2 + 1, 0); =20 hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); - test_hbitmap_next_dirty_area_check(data, L2, UINT64_MAX); - test_hbitmap_next_dirty_area_check(data, L2 + 1, UINT64_MAX); - test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1 - 1, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 + 1, INT64_MAX); + test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1 - 1, INT64_MAX); test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1, 5); test_hbitmap_next_dirty_area_check(data, L2 * 2 - L1, L1 + 1); test_hbitmap_next_dirty_area_check(data, L2 * 2, L2); =20 hbitmap_set(data->hb, 0, L3); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); } =20 static void test_hbitmap_next_dirty_area_0(TestHBitmapData *data, @@ -1010,7 +1010,7 @@ static void test_hbitmap_next_dirty_area_after_trunca= te(TestHBitmapData *data, hbitmap_test_init(data, L1, 0); hbitmap_test_truncate_impl(data, L1 * 2); hbitmap_set(data->hb, L1 + 1, 1); - test_hbitmap_next_dirty_area_check(data, 0, UINT64_MAX); + test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); } =20 int main(int argc, char **argv) diff --git a/util/hbitmap.c b/util/hbitmap.c index b6d4b99a06..df22f06be6 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -193,7 +193,7 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap = *hb, uint64_t first) } } =20 -int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start, uint64_t coun= t) +int64_t hbitmap_next_zero(const HBitmap *hb, int64_t start, int64_t count) { size_t pos =3D (start >> hb->granularity) >> BITS_PER_LEVEL; unsigned long *last_lev =3D hb->levels[HBITMAP_LEVELS - 1]; @@ -202,6 +202,8 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t s= tart, uint64_t count) uint64_t end_bit, sz; int64_t res; =20 + assert(start >=3D 0 && count >=3D 0); + if (start >=3D hb->orig_size || count =3D=3D 0) { return -1; } @@ -244,14 +246,15 @@ int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t= start, uint64_t count) return res; } =20 -bool hbitmap_next_dirty_area(const HBitmap *hb, uint64_t *start, - uint64_t *count) +bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount) { HBitmapIter hbi; int64_t firt_dirty_off, area_end; uint32_t granularity =3D 1UL << hb->granularity; uint64_t end; =20 + assert(*start >=3D 0 && *count >=3D 0); + if (*start >=3D hb->orig_size || *count =3D=3D 0) { return false; } @@ -834,8 +837,8 @@ bool hbitmap_can_merge(const HBitmap *a, const HBitmap = *b) */ static void hbitmap_sparse_merge(HBitmap *dst, const HBitmap *src) { - uint64_t offset =3D 0; - uint64_t count =3D src->orig_size; + int64_t offset =3D 0; + int64_t count =3D src->orig_size; =20 while (hbitmap_next_dirty_area(src, &offset, &count)) { hbitmap_set(dst, offset, count); --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584419947; cv=none; d=zohomail.com; s=zohoarc; b=m/nWL8Hie/xLGYd56agFX2eKfeSbaNTUaUUE/bgPAJDoJGgJshPm3zXG41vrsvPJpOPdacz/uuhL4+Noi0L8C+hj7+pEgTSEY3TYlPLds/6rNVmW3RJrU62oFpYaksFwBpQToW93g4D5+dR9nBYct+zCNm9usLMu3mHa94g0zi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584419947; h=Content-Type: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=LncJ/BC9kCGucJRhLcuktA7p5kTX1f+tStirinx1uFo=; b=gduV2Sf6wUD5d4BM0tRFLaDrVEBQLL9NMt/r0bYzMWsl/BJPPzwQDrDXsHz5GK1xqwb3n8zaY7rCq/ML3Aiq6TeZ6BxAS8zInZXQklhxF2u8fOWk6zXDrLk+W/eTtTj1EzpLEPboJW7MY2eAlnkp45OondIDgBrqgIVq2TpMJFo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584419947378562.6934650496764; Mon, 16 Mar 2020 21:39:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-367--6DzakrVPQOTMBCng37aZw-1; Tue, 17 Mar 2020 00:39:04 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78234801E53; Tue, 17 Mar 2020 04:38:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5098619C58; Tue, 17 Mar 2020 04:38:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0D86818089CD; Tue, 17 Mar 2020 04:38:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cg8w012361 for ; Tue, 17 Mar 2020 00:38:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 61E4A100E7E3; Tue, 17 Mar 2020 04:38:42 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F1EF1001B07; Tue, 17 Mar 2020 04:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584419946; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LncJ/BC9kCGucJRhLcuktA7p5kTX1f+tStirinx1uFo=; b=BG256yH9+9RdYvYrzlfuyuEP9pL6ir6dG52/Vh1XBbDyGEC6r1H/l1Q8FNVvKvBkj5dgxI tOiT1erGbDVjvRhsyCxJ+pj21AEbTfMnKpcmvwxOlarU3zZO5MpLG2LU+rWvSbC3QfoVQ6 D2OQvsyjLwMZAktV164XVAMdIVANsLs= X-MC-Unique: -6DzakrVPQOTMBCng37aZw-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 06/10] block/dirty-bitmap: add _next_dirty API Date: Tue, 17 Mar 2020 00:38:15 -0400 Message-Id: <20200317043819.20197-7-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy We have bdrv_dirty_bitmap_next_zero, let's add corresponding bdrv_dirty_bitmap_next_dirty, which is more comfortable to use than bitmap iterators in some cases. For test modify test_hbitmap_next_zero_check_range to check both next_zero and next_dirty and add some new checks. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20200205112041.6003-7-vsementsov@virtuozzo.com Signed-off-by: John Snow --- include/block/dirty-bitmap.h | 2 + include/qemu/hbitmap.h | 13 ++++ block/dirty-bitmap.c | 6 ++ tests/test-hbitmap.c | 130 ++++++++++++++++++++--------------- util/hbitmap.c | 60 ++++++++-------- 5 files changed, 126 insertions(+), 85 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 27c72cc56a..b1f0de12db 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -105,6 +105,8 @@ for (bitmap =3D bdrv_dirty_bitmap_first(bs); bitmap; \ bitmap =3D bdrv_dirty_bitmap_next(bitmap)) =20 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp= ); +int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offs= et, + int64_t bytes); int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, int64_t bytes); bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index b6e85f3d5d..6e9ae51ed3 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -297,6 +297,19 @@ void hbitmap_free(HBitmap *hb); */ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap *hb, uint64_t first= ); =20 +/* + * hbitmap_next_dirty: + * + * Find next dirty bit within selected range. If not found, return -1. + * + * @hb: The HBitmap to operate on + * @start: The bit to start from. + * @count: Number of bits to proceed. If @start+@count > bitmap size, the = whole + * bitmap is looked through. You can use INT64_MAX as @count to search up = to + * the bitmap end. + */ +int64_t hbitmap_next_dirty(const HBitmap *hb, int64_t start, int64_t count= ); + /* hbitmap_next_zero: * * Find next not dirty bit within selected range. If not found, return -1. diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index af9f5411a6..1b14c8eb26 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -860,6 +860,12 @@ char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *= bitmap, Error **errp) return hbitmap_sha256(bitmap->bitmap, errp); } =20 +int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offs= et, + int64_t bytes) +{ + return hbitmap_next_dirty(bitmap->bitmap, offset, bytes); +} + int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, int64_t bytes) { diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index 9d210dc18c..8905b8a351 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -816,92 +816,108 @@ static void test_hbitmap_iter_and_reset(TestHBitmapD= ata *data, hbitmap_iter_next(&hbi); } =20 -static void test_hbitmap_next_zero_check_range(TestHBitmapData *data, - int64_t start, - int64_t count) +static void test_hbitmap_next_x_check_range(TestHBitmapData *data, + int64_t start, + int64_t count) { - int64_t ret1 =3D hbitmap_next_zero(data->hb, start, count); - int64_t ret2 =3D start; + int64_t next_zero =3D hbitmap_next_zero(data->hb, start, count); + int64_t next_dirty =3D hbitmap_next_dirty(data->hb, start, count); + int64_t next; int64_t end =3D start >=3D data->size || data->size - start < count ? data->size : start + count; + bool first_bit =3D hbitmap_get(data->hb, start); =20 - for ( ; ret2 < end && hbitmap_get(data->hb, ret2); ret2++) { + for (next =3D start; + next < end && hbitmap_get(data->hb, next) =3D=3D first_bit; + next++) + { ; } - if (ret2 =3D=3D end) { - ret2 =3D -1; + + if (next =3D=3D end) { + next =3D -1; } =20 - g_assert_cmpint(ret1, =3D=3D, ret2); + g_assert_cmpint(next_dirty, =3D=3D, first_bit ? start : next); + g_assert_cmpint(next_zero, =3D=3D, first_bit ? next : start); } =20 -static void test_hbitmap_next_zero_check(TestHBitmapData *data, int64_t st= art) +static void test_hbitmap_next_x_check(TestHBitmapData *data, int64_t start) { - test_hbitmap_next_zero_check_range(data, start, INT64_MAX); + test_hbitmap_next_x_check_range(data, start, INT64_MAX); } =20 -static void test_hbitmap_next_zero_do(TestHBitmapData *data, int granulari= ty) +static void test_hbitmap_next_x_do(TestHBitmapData *data, int granularity) { hbitmap_test_init(data, L3, granularity); - test_hbitmap_next_zero_check(data, 0); - test_hbitmap_next_zero_check(data, L3 - 1); - test_hbitmap_next_zero_check_range(data, 0, 1); - test_hbitmap_next_zero_check_range(data, L3 - 1, 1); + test_hbitmap_next_x_check(data, 0); + test_hbitmap_next_x_check(data, L3 - 1); + test_hbitmap_next_x_check_range(data, 0, 1); + test_hbitmap_next_x_check_range(data, L3 - 1, 1); =20 hbitmap_set(data->hb, L2, 1); - test_hbitmap_next_zero_check(data, 0); - test_hbitmap_next_zero_check(data, L2 - 1); - test_hbitmap_next_zero_check(data, L2); - test_hbitmap_next_zero_check(data, L2 + 1); - test_hbitmap_next_zero_check_range(data, 0, 1); - test_hbitmap_next_zero_check_range(data, 0, L2); - test_hbitmap_next_zero_check_range(data, L2 - 1, 1); - test_hbitmap_next_zero_check_range(data, L2 - 1, 2); - test_hbitmap_next_zero_check_range(data, L2, 1); - test_hbitmap_next_zero_check_range(data, L2 + 1, 1); + test_hbitmap_next_x_check(data, 0); + test_hbitmap_next_x_check(data, L2 - 1); + test_hbitmap_next_x_check(data, L2); + test_hbitmap_next_x_check(data, L2 + 1); + test_hbitmap_next_x_check_range(data, 0, 1); + test_hbitmap_next_x_check_range(data, 0, L2); + test_hbitmap_next_x_check_range(data, L2 - 1, 1); + test_hbitmap_next_x_check_range(data, L2 - 1, 2); + test_hbitmap_next_x_check_range(data, L2, 1); + test_hbitmap_next_x_check_range(data, L2 + 1, 1); =20 hbitmap_set(data->hb, L2 + 5, L1); - test_hbitmap_next_zero_check(data, 0); - test_hbitmap_next_zero_check(data, L2 + 1); - test_hbitmap_next_zero_check(data, L2 + 2); - test_hbitmap_next_zero_check(data, L2 + 5); - test_hbitmap_next_zero_check(data, L2 + L1 - 1); - test_hbitmap_next_zero_check(data, L2 + L1); - test_hbitmap_next_zero_check_range(data, L2, 6); - test_hbitmap_next_zero_check_range(data, L2 + 1, 3); - test_hbitmap_next_zero_check_range(data, L2 + 4, L1); - test_hbitmap_next_zero_check_range(data, L2 + 5, L1); + test_hbitmap_next_x_check(data, 0); + test_hbitmap_next_x_check(data, L2 - L1); + test_hbitmap_next_x_check(data, L2 + 1); + test_hbitmap_next_x_check(data, L2 + 2); + test_hbitmap_next_x_check(data, L2 + 5); + test_hbitmap_next_x_check(data, L2 + L1 - 1); + test_hbitmap_next_x_check(data, L2 + L1); + test_hbitmap_next_x_check(data, L2 + L1 + 1); + test_hbitmap_next_x_check_range(data, L2 - 2, L1); + test_hbitmap_next_x_check_range(data, L2, 4); + test_hbitmap_next_x_check_range(data, L2, 6); + test_hbitmap_next_x_check_range(data, L2 + 1, 3); + test_hbitmap_next_x_check_range(data, L2 + 4, L1); + test_hbitmap_next_x_check_range(data, L2 + 5, L1); + test_hbitmap_next_x_check_range(data, L2 + 5 + L1 - 1, 1); + test_hbitmap_next_x_check_range(data, L2 + 5 + L1, 1); + test_hbitmap_next_x_check_range(data, L2 + 5 + L1 + 1, 1); =20 hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2); - test_hbitmap_next_zero_check(data, L2 * 2 - L1); - test_hbitmap_next_zero_check(data, L2 * 2 - 2); - test_hbitmap_next_zero_check(data, L2 * 2 - 1); - test_hbitmap_next_zero_check(data, L2 * 2); - test_hbitmap_next_zero_check(data, L3 - 1); - test_hbitmap_next_zero_check_range(data, L2 * 2 - L1, L1 + 1); - test_hbitmap_next_zero_check_range(data, L2 * 2, L2); + test_hbitmap_next_x_check(data, L2 * 2 - L1); + test_hbitmap_next_x_check(data, L2 * 2 - 2); + test_hbitmap_next_x_check(data, L2 * 2 - 1); + test_hbitmap_next_x_check(data, L2 * 2); + test_hbitmap_next_x_check(data, L2 * 2 + 1); + test_hbitmap_next_x_check(data, L2 * 2 + L1); + test_hbitmap_next_x_check(data, L3 - 1); + test_hbitmap_next_x_check_range(data, L2 * 2 - L1, L1 + 1); + test_hbitmap_next_x_check_range(data, L2 * 2, L2); =20 hbitmap_set(data->hb, 0, L3); - test_hbitmap_next_zero_check(data, 0); + test_hbitmap_next_x_check(data, 0); } =20 -static void test_hbitmap_next_zero_0(TestHBitmapData *data, const void *un= used) +static void test_hbitmap_next_x_0(TestHBitmapData *data, const void *unuse= d) { - test_hbitmap_next_zero_do(data, 0); + test_hbitmap_next_x_do(data, 0); } =20 -static void test_hbitmap_next_zero_4(TestHBitmapData *data, const void *un= used) +static void test_hbitmap_next_x_4(TestHBitmapData *data, const void *unuse= d) { - test_hbitmap_next_zero_do(data, 4); + test_hbitmap_next_x_do(data, 4); } =20 -static void test_hbitmap_next_zero_after_truncate(TestHBitmapData *data, - const void *unused) +static void test_hbitmap_next_x_after_truncate(TestHBitmapData *data, + const void *unused) { hbitmap_test_init(data, L1, 0); hbitmap_test_truncate_impl(data, L1 * 2); hbitmap_set(data->hb, 0, L1); - test_hbitmap_next_zero_check(data, 0); + test_hbitmap_next_x_check(data, 0); } =20 static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data, @@ -1068,12 +1084,12 @@ int main(int argc, char **argv) hbitmap_test_add("/hbitmap/iter/iter_and_reset", test_hbitmap_iter_and_reset); =20 - hbitmap_test_add("/hbitmap/next_zero/next_zero_0", - test_hbitmap_next_zero_0); - hbitmap_test_add("/hbitmap/next_zero/next_zero_4", - test_hbitmap_next_zero_4); - hbitmap_test_add("/hbitmap/next_zero/next_zero_after_truncate", - test_hbitmap_next_zero_after_truncate); + hbitmap_test_add("/hbitmap/next_zero/next_x_0", + test_hbitmap_next_x_0); + hbitmap_test_add("/hbitmap/next_zero/next_x_4", + test_hbitmap_next_x_4); + hbitmap_test_add("/hbitmap/next_zero/next_x_after_truncate", + test_hbitmap_next_x_after_truncate); =20 hbitmap_test_add("/hbitmap/next_dirty_area/next_dirty_area_0", test_hbitmap_next_dirty_area_0); diff --git a/util/hbitmap.c b/util/hbitmap.c index df22f06be6..883ca48fa6 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -193,6 +193,30 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap= *hb, uint64_t first) } } =20 +int64_t hbitmap_next_dirty(const HBitmap *hb, int64_t start, int64_t count) +{ + HBitmapIter hbi; + int64_t first_dirty_off; + uint64_t end; + + assert(start >=3D 0 && count >=3D 0); + + if (start >=3D hb->orig_size || count =3D=3D 0) { + return -1; + } + + end =3D count > hb->orig_size - start ? hb->orig_size : start + count; + + hbitmap_iter_init(&hbi, hb, start); + first_dirty_off =3D hbitmap_iter_next(&hbi); + + if (first_dirty_off < 0 || first_dirty_off >=3D end) { + return -1; + } + + return MAX(start, first_dirty_off); +} + int64_t hbitmap_next_zero(const HBitmap *hb, int64_t start, int64_t count) { size_t pos =3D (start >> hb->granularity) >> BITS_PER_LEVEL; @@ -248,40 +272,20 @@ int64_t hbitmap_next_zero(const HBitmap *hb, int64_t = start, int64_t count) =20 bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount) { - HBitmapIter hbi; - int64_t firt_dirty_off, area_end; - uint32_t granularity =3D 1UL << hb->granularity; - uint64_t end; + int64_t area_start, area_end; =20 - assert(*start >=3D 0 && *count >=3D 0); - - if (*start >=3D hb->orig_size || *count =3D=3D 0) { + area_start =3D hbitmap_next_dirty(hb, *start, *count); + if (area_start < 0) { return false; } =20 - end =3D *count > hb->orig_size - *start ? hb->orig_size : *start + *co= unt; - - hbitmap_iter_init(&hbi, hb, *start); - firt_dirty_off =3D hbitmap_iter_next(&hbi); - - if (firt_dirty_off < 0 || firt_dirty_off >=3D end) { - return false; + area_end =3D hbitmap_next_zero(hb, area_start, *start + *count - area_= start); + if (area_end < 0) { + area_end =3D MIN(hb->orig_size, *start + *count); } =20 - if (firt_dirty_off + granularity >=3D end) { - area_end =3D end; - } else { - area_end =3D hbitmap_next_zero(hb, firt_dirty_off + granularity, - end - firt_dirty_off - granularity); - if (area_end < 0) { - area_end =3D end; - } - } - - if (firt_dirty_off > *start) { - *start =3D firt_dirty_off; - } - *count =3D area_end - *start; + *start =3D area_start; + *count =3D area_end - area_start; =20 return true; } --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584420076; cv=none; d=zohomail.com; s=zohoarc; b=VRgp6cfj4b9i7AxvmkoWbheXwarKseWeOBuhmGNyriHGVztjNR9ssm4zNn6RZf9S2puBomKGZiWEshdIIb6EXPk4Ab21oQ2hEuw3+kVSN7yWRomNDsXlyUq/LjavdRRcn7iryWBzkzmJhR8/CPLC7IW3roJNwMoW0aoa2fX/D8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584420076; h=Content-Type: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=hJmvqTqXqTMPCSVQr1qy1e1SoPh13NTfRknUTlZehjg=; b=MeuT0HxYmdne1jfkUqJo3tBD3S8nIBu6xdf0Gqixf5aGhfMQnc7a9o6QLxY2+xsbNoPet4UgCbVMnaSLJUIVqzbjv6TnWuQatbmFa+TQF3iHf4sTLFtSqNRAZV2XWjRytZP3owseGcuMGngSwtsYYzbNV1Xxoxhyc0x4J3c0OgU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584420076304242.02825849526687; Mon, 16 Mar 2020 21:41:16 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-jYo68iLeOgq3YxTzs1_aXQ-1; Tue, 17 Mar 2020 00:39:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCF6A8010EC; Tue, 17 Mar 2020 04:39:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92DC95D9C9; Tue, 17 Mar 2020 04:39:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2946718089D8; Tue, 17 Mar 2020 04:39:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cmYS012375 for ; Tue, 17 Mar 2020 00:38:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 83D201036B47; Tue, 17 Mar 2020 04:38:48 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 911EB10016EB; Tue, 17 Mar 2020 04:38:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584420075; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=hJmvqTqXqTMPCSVQr1qy1e1SoPh13NTfRknUTlZehjg=; b=EfN7wkRh7PKVDwbeQUfU75ru3L+qneb/NmanwMtQbf9N4yeMsX902Uw2NG7q/j+NW+Lv8E LpPrU6cOUX9JxrdPE9ZWy6Sko8sQuxdD8Cn6HiujNPFNKZCB9GLLCX7FLnSz6BZ/Qtxsuz FqrvyuHP5PZtbzYggdFcx3kjhTGWZjI= X-MC-Unique: jYo68iLeOgq3YxTzs1_aXQ-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 07/10] block/dirty-bitmap: improve _next_dirty_area API Date: Tue, 17 Mar 2020 00:38:16 -0400 Message-Id: <20200317043819.20197-8-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Firstly, _next_dirty_area is for scenarios when we may contiguously search for next dirty area inside some limited region, so it is more comfortable to specify "end" which should not be recalculated on each iteration. Secondly, let's add a possibility to limit resulting area size, not limiting searching area. This will be used in NBD code in further commit. (Note that now bdrv_dirty_bitmap_next_dirty_area is unused) Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20200205112041.6003-8-vsementsov@virtuozzo.com Signed-off-by: John Snow --- include/block/dirty-bitmap.h | 3 ++- include/qemu/hbitmap.h | 23 ++++++++++-------- block/dirty-bitmap.c | 6 +++-- tests/test-hbitmap.c | 45 +++++++++++++++++++++++------------- util/hbitmap.c | 44 +++++++++++++++++++++-------------- 5 files changed, 75 insertions(+), 46 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index b1f0de12db..8a10029418 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -110,7 +110,8 @@ int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *b= itmap, int64_t offset, int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offse= t, int64_t bytes); bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, - int64_t *offset, int64_t *bytes); + int64_t start, int64_t end, int64_t max_dirty_count, + int64_t *dirty_start, int64_t *dirty_count); BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, Error **errp); =20 diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 6e9ae51ed3..5e71b6d6f7 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -324,18 +324,21 @@ int64_t hbitmap_next_zero(const HBitmap *hb, int64_t = start, int64_t count); =20 /* hbitmap_next_dirty_area: * @hb: The HBitmap to operate on - * @start: in-out parameter. - * in: the offset to start from - * out: (if area found) start of found area - * @count: in-out parameter. - * in: length of requested region - * out: length of found area + * @start: the offset to start from + * @end: end of requested area + * @max_dirty_count: limit for out parameter dirty_count + * @dirty_start: on success: start of found area + * @dirty_count: on success: length of found area * - * If dirty area found within [@start, @start + @count), returns true and = sets - * @offset and @bytes appropriately. Otherwise returns false and leaves @o= ffset - * and @bytes unchanged. + * If dirty area found within [@start, @end), returns true and sets + * @dirty_start and @dirty_count appropriately. @dirty_count will not exce= ed + * @max_dirty_count. + * If dirty area was not found, returns false and leaves @dirty_start and + * @dirty_count unchanged. */ -bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount); +bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end, + int64_t max_dirty_count, + int64_t *dirty_start, int64_t *dirty_count); =20 /** * hbitmap_iter_next: diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 1b14c8eb26..063793e316 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -873,9 +873,11 @@ int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *b= itmap, int64_t offset, } =20 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, - int64_t *offset, int64_t *bytes) + int64_t start, int64_t end, int64_t max_dirty_count, + int64_t *dirty_start, int64_t *dirty_count) { - return hbitmap_next_dirty_area(bitmap->bitmap, offset, bytes); + return hbitmap_next_dirty_area(bitmap->bitmap, start, end, max_dirty_c= ount, + dirty_start, dirty_count); } =20 /** diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index 8905b8a351..b6726cf76b 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -920,18 +920,19 @@ static void test_hbitmap_next_x_after_truncate(TestHB= itmapData *data, test_hbitmap_next_x_check(data, 0); } =20 -static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data, - int64_t offset, - int64_t count) +static void test_hbitmap_next_dirty_area_check_limited(TestHBitmapData *da= ta, + int64_t offset, + int64_t count, + int64_t max_dirty) { int64_t off1, off2; int64_t len1 =3D 0, len2; bool ret1, ret2; int64_t end; =20 - off1 =3D offset; - len1 =3D count; - ret1 =3D hbitmap_next_dirty_area(data->hb, &off1, &len1); + ret1 =3D hbitmap_next_dirty_area(data->hb, + offset, count =3D=3D INT64_MAX ? INT64_MAX : offset + count, m= ax_dirty, + &off1, &len1); =20 end =3D offset > data->size || data->size - offset < count ? data->siz= e : offset + co= unt; @@ -940,21 +941,25 @@ static void test_hbitmap_next_dirty_area_check(TestHB= itmapData *data, ; } =20 - for (len2 =3D 1; off2 + len2 < end && hbitmap_get(data->hb, off2 + len= 2); - len2++) { + for (len2 =3D 1; (off2 + len2 < end && len2 < max_dirty && + hbitmap_get(data->hb, off2 + len2)); len2++) + { ; } =20 ret2 =3D off2 < end; - if (!ret2) { - /* leave unchanged */ - off2 =3D offset; - len2 =3D count; - } - g_assert_cmpint(ret1, =3D=3D, ret2); - g_assert_cmpint(off1, =3D=3D, off2); - g_assert_cmpint(len1, =3D=3D, len2); + + if (ret2) { + g_assert_cmpint(off1, =3D=3D, off2); + g_assert_cmpint(len1, =3D=3D, len2); + } +} + +static void test_hbitmap_next_dirty_area_check(TestHBitmapData *data, + int64_t offset, int64_t cou= nt) +{ + test_hbitmap_next_dirty_area_check_limited(data, offset, count, INT64_= MAX); } =20 static void test_hbitmap_next_dirty_area_do(TestHBitmapData *data, @@ -964,6 +969,7 @@ static void test_hbitmap_next_dirty_area_do(TestHBitmap= Data *data, test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); test_hbitmap_next_dirty_area_check(data, 0, 1); test_hbitmap_next_dirty_area_check(data, L3 - 1, 1); + test_hbitmap_next_dirty_area_check_limited(data, 0, INT64_MAX, 1); =20 hbitmap_set(data->hb, L2, 1); test_hbitmap_next_dirty_area_check(data, 0, 1); @@ -976,6 +982,8 @@ static void test_hbitmap_next_dirty_area_do(TestHBitmap= Data *data, test_hbitmap_next_dirty_area_check(data, L2, INT64_MAX); test_hbitmap_next_dirty_area_check(data, L2, 1); test_hbitmap_next_dirty_area_check(data, L2 + 1, 1); + test_hbitmap_next_dirty_area_check_limited(data, 0, INT64_MAX, 1); + test_hbitmap_next_dirty_area_check_limited(data, L2 - 1, 2, 1); =20 hbitmap_set(data->hb, L2 + 5, L1); test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); @@ -988,6 +996,8 @@ static void test_hbitmap_next_dirty_area_do(TestHBitmap= Data *data, test_hbitmap_next_dirty_area_check(data, L2 + L1, L1); test_hbitmap_next_dirty_area_check(data, L2, 0); test_hbitmap_next_dirty_area_check(data, L2 + 1, 0); + test_hbitmap_next_dirty_area_check_limited(data, L2 + 3, INT64_MAX, 3); + test_hbitmap_next_dirty_area_check_limited(data, L2 + 3, 7, 10); =20 hbitmap_set(data->hb, L2 * 2, L3 - L2 * 2); test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); @@ -997,6 +1007,9 @@ static void test_hbitmap_next_dirty_area_do(TestHBitma= pData *data, test_hbitmap_next_dirty_area_check(data, L2 + 5 + L1, 5); test_hbitmap_next_dirty_area_check(data, L2 * 2 - L1, L1 + 1); test_hbitmap_next_dirty_area_check(data, L2 * 2, L2); + test_hbitmap_next_dirty_area_check_limited(data, L2 * 2 + 1, INT64_MAX= , 5); + test_hbitmap_next_dirty_area_check_limited(data, L2 * 2 + 1, 10, 5); + test_hbitmap_next_dirty_area_check_limited(data, L2 * 2 + 1, 2, 5); =20 hbitmap_set(data->hb, 0, L3); test_hbitmap_next_dirty_area_check(data, 0, INT64_MAX); diff --git a/util/hbitmap.c b/util/hbitmap.c index 883ca48fa6..305b894a63 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -270,22 +270,33 @@ int64_t hbitmap_next_zero(const HBitmap *hb, int64_t = start, int64_t count) return res; } =20 -bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t *start, int64_t *c= ount) +bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end, + int64_t max_dirty_count, + int64_t *dirty_start, int64_t *dirty_count) { - int64_t area_start, area_end; + int64_t next_zero; =20 - area_start =3D hbitmap_next_dirty(hb, *start, *count); - if (area_start < 0) { + assert(start >=3D 0 && end >=3D 0 && max_dirty_count > 0); + + end =3D MIN(end, hb->orig_size); + if (start >=3D end) { return false; } =20 - area_end =3D hbitmap_next_zero(hb, area_start, *start + *count - area_= start); - if (area_end < 0) { - area_end =3D MIN(hb->orig_size, *start + *count); + start =3D hbitmap_next_dirty(hb, start, end - start); + if (start < 0) { + return false; + } + + end =3D start + MIN(end - start, max_dirty_count); + + next_zero =3D hbitmap_next_zero(hb, start, end - start); + if (next_zero >=3D 0) { + end =3D next_zero; } =20 - *start =3D area_start; - *count =3D area_end - area_start; + *dirty_start =3D start; + *dirty_count =3D end - start; =20 return true; } @@ -841,16 +852,15 @@ bool hbitmap_can_merge(const HBitmap *a, const HBitma= p *b) */ static void hbitmap_sparse_merge(HBitmap *dst, const HBitmap *src) { - int64_t offset =3D 0; - int64_t count =3D src->orig_size; + int64_t offset; + int64_t count; =20 - while (hbitmap_next_dirty_area(src, &offset, &count)) { + for (offset =3D 0; + hbitmap_next_dirty_area(src, offset, src->orig_size, INT64_MAX, + &offset, &count); + offset +=3D count) + { hbitmap_set(dst, offset, count); - offset +=3D count; - if (offset >=3D src->orig_size) { - break; - } - count =3D src->orig_size - offset; } } =20 --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584419960; cv=none; d=zohomail.com; s=zohoarc; b=WWsLJuu9qyDUWsxsFkvEbtfVD+0df5PUFZ71APGNbHXbCwjHhVDzkfMiCz23tqMf54Q8p22eT3BBPRYtgjtiT7i0OjXKLb9RR2rOyVmV2diQ/Xu3DZsYUwyBUDqem9K/oRdTPDIvjTpzAgjKBUCrvkPBj6OUIQgADULwLUwnr0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584419960; h=Content-Type: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=W2SZloJALWARRXQrRWIcseEswJ8GCx7hIkZZF9kViZ0=; b=Y7LQQ3ZjOPaMom1qg7IyOxjwWrpXDGPjSJrkMGcSqprsH9x+g++Ootp71mlkdX1DwJz+OrC3oPOl9w+dbYJNESqKKvFJjzMPV1VpykX7Bl7ic+WD7VbvKWxgVsVmphqZGvCHT5YtjAig3ubFstmkKmzf0Rsm79ld8cw6C+FSW60= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584419960453658.6890531466089; Mon, 16 Mar 2020 21:39:20 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-68-9SLSWJofOJqQ_qowv2dE3w-1; Tue, 17 Mar 2020 00:39:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 487BF107ACC4; Tue, 17 Mar 2020 04:39:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E53810016EB; Tue, 17 Mar 2020 04:39:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C62261802030; Tue, 17 Mar 2020 04:39:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cp3S012385 for ; Tue, 17 Mar 2020 00:38:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3DAB310027AB; Tue, 17 Mar 2020 04:38:51 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8C851036B3B; Tue, 17 Mar 2020 04:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584419959; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=W2SZloJALWARRXQrRWIcseEswJ8GCx7hIkZZF9kViZ0=; b=GQ1x2yXEFK10/kntUCe/jiRJ/KI9dUSbHPjQwCe6wXZiuqRWPn5+mYaaVhidvRyzvts39a Qk8HDqWe7BfVYtjqe2ffAQ3EoQ+1hyY1KeCqhLK9wHf0aJEW20gqam5V8J22nwOzwwC6Tb khPR/XLvXlvhxgB8MN4qfoLv/4GRoiw= X-MC-Unique: 9SLSWJofOJqQ_qowv2dE3w-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 08/10] nbd/server: introduce NBDExtentArray Date: Tue, 17 Mar 2020 00:38:17 -0400 Message-Id: <20200317043819.20197-9-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Introduce NBDExtentArray class, to handle extents list creation in more controlled way and with fewer OUT parameters in functions. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-id: 20200205112041.6003-9-vsementsov@virtuozzo.com Signed-off-by: John Snow --- nbd/server.c | 210 +++++++++++++++++++++++++++++---------------------- 1 file changed, 118 insertions(+), 92 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 3106aaf3b4..f90bb33a75 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1909,27 +1909,98 @@ static int coroutine_fn nbd_co_send_sparse_read(NBD= Client *client, return ret; } =20 +typedef struct NBDExtentArray { + NBDExtent *extents; + unsigned int nb_alloc; + unsigned int count; + uint64_t total_length; + bool can_add; + bool converted_to_be; +} NBDExtentArray; + +static NBDExtentArray *nbd_extent_array_new(unsigned int nb_alloc) +{ + NBDExtentArray *ea =3D g_new0(NBDExtentArray, 1); + + ea->nb_alloc =3D nb_alloc; + ea->extents =3D g_new(NBDExtent, nb_alloc); + ea->can_add =3D true; + + return ea; +} + +static void nbd_extent_array_free(NBDExtentArray *ea) +{ + g_free(ea->extents); + g_free(ea); +} +G_DEFINE_AUTOPTR_CLEANUP_FUNC(NBDExtentArray, nbd_extent_array_free); + +/* Further modifications of the array after conversion are abandoned */ +static void nbd_extent_array_convert_to_be(NBDExtentArray *ea) +{ + int i; + + assert(!ea->converted_to_be); + ea->can_add =3D false; + ea->converted_to_be =3D true; + + for (i =3D 0; i < ea->count; i++) { + ea->extents[i].flags =3D cpu_to_be32(ea->extents[i].flags); + ea->extents[i].length =3D cpu_to_be32(ea->extents[i].length); + } +} + /* - * Populate @extents from block status. Update @bytes to be the actual - * length encoded (which may be smaller than the original), and update - * @nb_extents to the number of extents used. - * - * Returns zero on success and -errno on bdrv_block_status_above failure. + * Add extent to NBDExtentArray. If extent can't be added (no available sp= ace), + * return -1. + * For safety, when returning -1 for the first time, .can_add is set to fa= lse, + * further call to nbd_extent_array_add() will crash. + * (to avoid the situation, when after failing to add an extent (returned = -1), + * user miss this failure and add another extent, which is successfully ad= ded + * (array is full, but new extent may be squashed into the last one), then= we + * have invalid array with skipped extent) */ +static int nbd_extent_array_add(NBDExtentArray *ea, + uint32_t length, uint32_t flags) +{ + assert(ea->can_add); + + if (!length) { + return 0; + } + + /* Extend previous extent if flags are the same */ + if (ea->count > 0 && flags =3D=3D ea->extents[ea->count - 1].flags) { + uint64_t sum =3D (uint64_t)length + ea->extents[ea->count - 1].len= gth; + + if (sum <=3D UINT32_MAX) { + ea->extents[ea->count - 1].length =3D sum; + ea->total_length +=3D length; + return 0; + } + } + + if (ea->count >=3D ea->nb_alloc) { + ea->can_add =3D false; + return -1; + } + + ea->total_length +=3D length; + ea->extents[ea->count] =3D (NBDExtent) {.length =3D length, .flags =3D= flags}; + ea->count++; + + return 0; +} + static int blockstatus_to_extents(BlockDriverState *bs, uint64_t offset, - uint64_t *bytes, NBDExtent *extents, - unsigned int *nb_extents) + uint64_t bytes, NBDExtentArray *ea) { - uint64_t remaining_bytes =3D *bytes; - NBDExtent *extent =3D extents, *extents_end =3D extents + *nb_extents; - bool first_extent =3D true; - - assert(*nb_extents); - while (remaining_bytes) { + while (bytes) { uint32_t flags; int64_t num; - int ret =3D bdrv_block_status_above(bs, NULL, offset, remaining_by= tes, - &num, NULL, NULL); + int ret =3D bdrv_block_status_above(bs, NULL, offset, bytes, &num, + NULL, NULL); =20 if (ret < 0) { return ret; @@ -1938,60 +2009,37 @@ static int blockstatus_to_extents(BlockDriverState = *bs, uint64_t offset, flags =3D (ret & BDRV_BLOCK_ALLOCATED ? 0 : NBD_STATE_HOLE) | (ret & BDRV_BLOCK_ZERO ? NBD_STATE_ZERO : 0); =20 - if (first_extent) { - extent->flags =3D flags; - extent->length =3D num; - first_extent =3D false; - } else if (flags =3D=3D extent->flags) { - /* extend current extent */ - extent->length +=3D num; - } else { - if (extent + 1 =3D=3D extents_end) { - break; - } - - /* start new extent */ - extent++; - extent->flags =3D flags; - extent->length =3D num; + if (nbd_extent_array_add(ea, num, flags) < 0) { + return 0; } + offset +=3D num; - remaining_bytes -=3D num; + bytes -=3D num; } =20 - extents_end =3D extent + 1; - - for (extent =3D extents; extent < extents_end; extent++) { - extent->flags =3D cpu_to_be32(extent->flags); - extent->length =3D cpu_to_be32(extent->length); - } - - *bytes -=3D remaining_bytes; - *nb_extents =3D extents_end - extents; - return 0; } =20 -/* nbd_co_send_extents +/* + * nbd_co_send_extents * - * @length is only for tracing purposes (and may be smaller or larger - * than the client's original request). @last controls whether - * NBD_REPLY_FLAG_DONE is sent. @extents should already be in - * big-endian format. + * @ea is converted to BE by the function + * @last controls whether NBD_REPLY_FLAG_DONE is sent. */ static int nbd_co_send_extents(NBDClient *client, uint64_t handle, - NBDExtent *extents, unsigned int nb_extents, - uint64_t length, bool last, - uint32_t context_id, Error **errp) + NBDExtentArray *ea, + bool last, uint32_t context_id, Error **err= p) { NBDStructuredMeta chunk; - struct iovec iov[] =3D { {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, - {.iov_base =3D extents, .iov_len =3D nb_extents * sizeof(extents[0= ])} + {.iov_base =3D ea->extents, .iov_len =3D ea->count * sizeof(ea->ex= tents[0])} }; =20 - trace_nbd_co_send_extents(handle, nb_extents, context_id, length, last= ); + nbd_extent_array_convert_to_be(ea); + + trace_nbd_co_send_extents(handle, ea->count, context_id, ea->total_len= gth, + last); set_be_chunk(&chunk.h, last ? NBD_REPLY_FLAG_DONE : 0, NBD_REPLY_TYPE_BLOCK_STATUS, handle, sizeof(chunk) - sizeof(chunk.h) + iov[1].iov_len); @@ -2009,39 +2057,27 @@ static int nbd_co_send_block_status(NBDClient *clie= nt, uint64_t handle, { int ret; unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; - NBDExtent *extents =3D g_new(NBDExtent, nb_extents); - uint64_t final_length =3D length; + g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); =20 - ret =3D blockstatus_to_extents(bs, offset, &final_length, extents, - &nb_extents); + ret =3D blockstatus_to_extents(bs, offset, length, ea); if (ret < 0) { - g_free(extents); return nbd_co_send_structured_error( client, handle, -ret, "can't get block status", errp); } =20 - ret =3D nbd_co_send_extents(client, handle, extents, nb_extents, - final_length, last, context_id, errp); - - g_free(extents); - - return ret; + return nbd_co_send_extents(client, handle, ea, last, context_id, errp); } =20 /* - * Populate @extents from a dirty bitmap. Unless @dont_fragment, the - * final extent may exceed the original @length. Store in @length the - * byte length encoded (which may be smaller or larger than the - * original), and return the number of extents used. + * Populate @ea from a dirty bitmap. Unless @dont_fragment, the + * final extent may exceed the original @length. */ -static unsigned int bitmap_to_extents(BdrvDirtyBitmap *bitmap, uint64_t of= fset, - uint64_t *length, NBDExtent *extents, - unsigned int nb_extents, - bool dont_fragment) +static void bitmap_to_extents(BdrvDirtyBitmap *bitmap, + uint64_t offset, uint64_t length, + NBDExtentArray *ea, bool dont_fragment) { uint64_t begin =3D offset, end =3D offset; - uint64_t overall_end =3D offset + *length; - unsigned int i =3D 0; + uint64_t overall_end =3D offset + length; BdrvDirtyBitmapIter *it; bool dirty; =20 @@ -2050,8 +2086,7 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitmap= *bitmap, uint64_t offset, it =3D bdrv_dirty_iter_new(bitmap); dirty =3D bdrv_dirty_bitmap_get_locked(bitmap, offset); =20 - assert(begin < overall_end && nb_extents); - while (begin < overall_end && i < nb_extents) { + while (begin < overall_end) { bool next_dirty =3D !dirty; =20 if (dirty) { @@ -2071,9 +2106,10 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitma= p *bitmap, uint64_t offset, end =3D overall_end; } =20 - extents[i].length =3D cpu_to_be32(end - begin); - extents[i].flags =3D cpu_to_be32(dirty ? NBD_STATE_DIRTY : 0); - i++; + if (nbd_extent_array_add(ea, end - begin, + dirty ? NBD_STATE_DIRTY : 0) < 0) { + break; + } begin =3D end; dirty =3D next_dirty; } @@ -2083,8 +2119,6 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitmap= *bitmap, uint64_t offset, bdrv_dirty_bitmap_unlock(bitmap); =20 assert(offset < end); - *length =3D end - offset; - return i; } =20 static int nbd_co_send_bitmap(NBDClient *client, uint64_t handle, @@ -2092,20 +2126,12 @@ static int nbd_co_send_bitmap(NBDClient *client, ui= nt64_t handle, uint32_t length, bool dont_fragment, bool la= st, uint32_t context_id, Error **errp) { - int ret; unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; - NBDExtent *extents =3D g_new(NBDExtent, nb_extents); - uint64_t final_length =3D length; + g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); =20 - nb_extents =3D bitmap_to_extents(bitmap, offset, &final_length, extent= s, - nb_extents, dont_fragment); + bitmap_to_extents(bitmap, offset, length, ea, dont_fragment); =20 - ret =3D nbd_co_send_extents(client, handle, extents, nb_extents, - final_length, last, context_id, errp); - - g_free(extents); - - return ret; + return nbd_co_send_extents(client, handle, ea, last, context_id, errp); } =20 /* nbd_co_receive_request --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584419954; cv=none; d=zohomail.com; s=zohoarc; b=UJmte/g6tLgfYcr5ix5KgEk8cYeFpTjZdW7O4beH8NWFugbbZB8oPnDK6CQ4UMkShJEX22S+WLjY9o2g3ZYAvS/wjjmP299OLzVrkaPTZe56YBHxEUHD7hVjXAmCh4i7oDFyiH4WE4gefRkAmyDvY9MTimSCgrA+IPRDBghM4Ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584419954; h=Content-Type: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=7S4pvEvRq43tAOJ+VoWTNYoKkV9GHiGO1EgDeCec5QM=; b=XgfTKcFlEIOO0lYBUo0YL6BRqrRnxkjJdk4LlVNajGunCaSpT7ucL1Vz8BdIHZZzjja0C2YZzV9Q9MGYooMqEx1KrvTK+FTnzqDg+Kl5L5MSBa0pDKtq7cWrHp3HqbXUssLCFXf7j/OkBV+WBG685EBsm9PvMTmZU2BZUjpa6uM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1584419954165765.3231252211546; Mon, 16 Mar 2020 21:39:14 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-30-mZk0FYwGMziQStTXzhwNmw-1; Tue, 17 Mar 2020 00:39:10 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4EDA1100550E; Tue, 17 Mar 2020 04:39:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 223DE10016EB; Tue, 17 Mar 2020 04:39:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A6C2687002; Tue, 17 Mar 2020 04:39:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4cr9N012393 for ; Tue, 17 Mar 2020 00:38:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6A01110027B9; Tue, 17 Mar 2020 04:38:53 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D7CD1009ABB; Tue, 17 Mar 2020 04:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584419953; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7S4pvEvRq43tAOJ+VoWTNYoKkV9GHiGO1EgDeCec5QM=; b=azZsI1X87aSWsAgnG6yAQrhjAY0eLMLD8RnIrbgmO9QsSFA2gFS807vWhldrnB7L9TzOxz FXyGGE7X0DtK/TXdropkFO8cX6EqDNMf4/Ss2SwMITpfnE3DJr7BwGZvbIqoRlBwVK0rys o1youhc/07JdFWbo7ghZa76vL/IVgKA= X-MC-Unique: mZk0FYwGMziQStTXzhwNmw-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 09/10] nbd/server: use bdrv_dirty_bitmap_next_dirty_area Date: Tue, 17 Mar 2020 00:38:18 -0400 Message-Id: <20200317043819.20197-10-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Use bdrv_dirty_bitmap_next_dirty_area for bitmap_to_extents. Since bdrv_dirty_bitmap_next_dirty_area is very accurate in its interface, we'll never exceed requested region with last chunk. So, we don't need dont_fragment, and bitmap_to_extents() interface becomes clean enough to not require any comment. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Message-id: 20200205112041.6003-10-vsementsov@virtuozzo.com Signed-off-by: John Snow --- nbd/server.c | 59 +++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index f90bb33a75..02b1ed0801 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2068,57 +2068,36 @@ static int nbd_co_send_block_status(NBDClient *clie= nt, uint64_t handle, return nbd_co_send_extents(client, handle, ea, last, context_id, errp); } =20 -/* - * Populate @ea from a dirty bitmap. Unless @dont_fragment, the - * final extent may exceed the original @length. - */ +/* Populate @ea from a dirty bitmap. */ static void bitmap_to_extents(BdrvDirtyBitmap *bitmap, uint64_t offset, uint64_t length, - NBDExtentArray *ea, bool dont_fragment) + NBDExtentArray *es) { - uint64_t begin =3D offset, end =3D offset; - uint64_t overall_end =3D offset + length; - BdrvDirtyBitmapIter *it; - bool dirty; + int64_t start, dirty_start, dirty_count; + int64_t end =3D offset + length; + bool full =3D false; =20 bdrv_dirty_bitmap_lock(bitmap); =20 - it =3D bdrv_dirty_iter_new(bitmap); - dirty =3D bdrv_dirty_bitmap_get_locked(bitmap, offset); - - while (begin < overall_end) { - bool next_dirty =3D !dirty; - - if (dirty) { - end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin, INT64_MAX); - } else { - bdrv_set_dirty_iter(it, begin); - end =3D bdrv_dirty_iter_next(it); - } - if (end =3D=3D -1 || end - begin > UINT32_MAX) { - /* Cap to an aligned value < 4G beyond begin. */ - end =3D MIN(bdrv_dirty_bitmap_size(bitmap), - begin + UINT32_MAX + 1 - - bdrv_dirty_bitmap_granularity(bitmap)); - next_dirty =3D dirty; - } - if (dont_fragment && end > overall_end) { - end =3D overall_end; - } - - if (nbd_extent_array_add(ea, end - begin, - dirty ? NBD_STATE_DIRTY : 0) < 0) { + for (start =3D offset; + bdrv_dirty_bitmap_next_dirty_area(bitmap, start, end, INT32_MAX, + &dirty_start, &dirty_count); + start =3D dirty_start + dirty_count) + { + if ((nbd_extent_array_add(es, dirty_start - start, 0) < 0) || + (nbd_extent_array_add(es, dirty_count, NBD_STATE_DIRTY) < 0)) + { + full =3D true; break; } - begin =3D end; - dirty =3D next_dirty; } =20 - bdrv_dirty_iter_free(it); + if (!full) { + /* last non dirty extent */ + nbd_extent_array_add(es, end - start, 0); + } =20 bdrv_dirty_bitmap_unlock(bitmap); - - assert(offset < end); } =20 static int nbd_co_send_bitmap(NBDClient *client, uint64_t handle, @@ -2129,7 +2108,7 @@ static int nbd_co_send_bitmap(NBDClient *client, uint= 64_t handle, unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); =20 - bitmap_to_extents(bitmap, offset, length, ea, dont_fragment); + bitmap_to_extents(bitmap, offset, length, ea); =20 return nbd_co_send_extents(client, handle, ea, last, context_id, errp); } --=20 2.21.1 From nobody Sun Apr 28 20:52:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584420005; cv=none; d=zohomail.com; s=zohoarc; b=OTSWC1Y3iB5TKNQ0IUnQUziObksGHfGMJCeWVsfWxgJL7erWgDREIHenUQ4Gtnu5aHBj319Zbqkz5TWLq2H3jXWILrmg5tG7TzAX2C2GgbR0swabm/gSf3B8EFOhnFhwAMWYyk8gKS5bA97iUGZd3/6aCG0XNz9s3zItX+b+Zvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584420005; h=Content-Type: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=JHxH1i/K0GH7hBo2Xl83uRZs9D8rNYlhtL+6rGnwWgY=; b=iWZk3NI4qYvu7n9xoQvsJegjsHk+4LmQ72ovk/TebcLUKr4bNVNqiZuQfnZxOl/zaEf8UrxPsXEXIog7IpfJYKtjZTe4fpXEjnRvKdaYpqQkRzxrGY+wG024a6bHssb8lQ7i5lz8+Agx0tvd2ZWctfZtFTpPTRxOBGF1ZSfMddk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584420005538660.9094116554322; Mon, 16 Mar 2020 21:40:05 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-88-oho-B4u5M6WcU33SxpQaOA-1; Tue, 17 Mar 2020 00:39:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 911C713FA; Tue, 17 Mar 2020 04:39:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69B9560C84; Tue, 17 Mar 2020 04:39:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1A60D87003; Tue, 17 Mar 2020 04:39:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02H4ctXV012406 for ; Tue, 17 Mar 2020 00:38:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8348010027B0; Tue, 17 Mar 2020 04:38:55 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96D9A10016EB; Tue, 17 Mar 2020 04:38:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584420004; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JHxH1i/K0GH7hBo2Xl83uRZs9D8rNYlhtL+6rGnwWgY=; b=gNHF2x5lTFb/JsjaUb2BKh7tfviIeBdyQvCloJeA9qM2NJsAosUD/rquzy49XuDdM8agrs 6o6lureVSmR3iokBdyJoJNUvVD10QqizlgOmv3t/DOe/ArDeuvz41daUOrc1qhicj7xLuP 1ZHNRL+qI6heI0NVOL7j6l59D7t008c= X-MC-Unique: oho-B4u5M6WcU33SxpQaOA-1 From: John Snow To: qemu-devel@nongnu.org, Peter Maydell , jsnow@redhat.com Subject: [PULL 10/10] block/qcow2-bitmap: use bdrv_dirty_bitmap_next_dirty Date: Tue, 17 Mar 2020 00:38:19 -0400 Message-Id: <20200317043819.20197-11-jsnow@redhat.com> In-Reply-To: <20200317043819.20197-1-jsnow@redhat.com> References: <20200317043819.20197-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, "Dr. David Alan Gilbert" , Stefan Hajnoczi , Max Reitz X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy store_bitmap_data() loop does bdrv_set_dirty_iter() on each iteration, which means that we actually don't need iterator itself and we can use simpler bitmap API. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20200205112041.6003-11-vsementsov@virtuozzo.com Signed-off-by: John Snow --- block/qcow2-bitmap.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 8cccc2c9f3..cb06954b4a 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1288,7 +1288,6 @@ static uint64_t *store_bitmap_data(BlockDriverState *= bs, uint64_t bm_size =3D bdrv_dirty_bitmap_size(bitmap); const char *bm_name =3D bdrv_dirty_bitmap_name(bitmap); uint8_t *buf =3D NULL; - BdrvDirtyBitmapIter *dbi; uint64_t *tb; uint64_t tb_size =3D size_to_clusters(s, @@ -1307,12 +1306,14 @@ static uint64_t *store_bitmap_data(BlockDriverState= *bs, return NULL; } =20 - dbi =3D bdrv_dirty_iter_new(bitmap); buf =3D g_malloc(s->cluster_size); limit =3D bytes_covered_by_bitmap_cluster(s, bitmap); assert(DIV_ROUND_UP(bm_size, limit) =3D=3D tb_size); =20 - while ((offset =3D bdrv_dirty_iter_next(dbi)) >=3D 0) { + offset =3D 0; + while ((offset =3D bdrv_dirty_bitmap_next_dirty(bitmap, offset, INT64_= MAX)) + >=3D 0) + { uint64_t cluster =3D offset / limit; uint64_t end, write_size; int64_t off; @@ -1355,23 +1356,17 @@ static uint64_t *store_bitmap_data(BlockDriverState= *bs, goto fail; } =20 - if (end >=3D bm_size) { - break; - } - - bdrv_set_dirty_iter(dbi, end); + offset =3D end; } =20 *bitmap_table_size =3D tb_size; g_free(buf); - bdrv_dirty_iter_free(dbi); =20 return tb; =20 fail: clear_bitmap_table(bs, tb, tb_size); g_free(buf); - bdrv_dirty_iter_free(dbi); g_free(tb); =20 return NULL; --=20 2.21.1