From nobody Sat Apr 20 06:29:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553228742145644.798156418657; Thu, 21 Mar 2019 21:25:42 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B81F0C04FFF7; Fri, 22 Mar 2019 04:25: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 6BF935D9C5; Fri, 22 Mar 2019 04:25:35 +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 088BA1803389; Fri, 22 Mar 2019 04:25:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2M4PRml012900 for ; Fri, 22 Mar 2019 00:25:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id B69F1608A4; Fri, 22 Mar 2019 04:25:27 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-65.phx2.redhat.com [10.3.116.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43E0560857; Fri, 22 Mar 2019 04:25:25 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Thu, 21 Mar 2019 23:25:24 -0500 Message-Id: <20190322042524.32568-1-eblake@redhat.com> In-Reply-To: <20190320054105.17689-1-eblake@redhat.com> References: <20190320054105.17689-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com Subject: [libvirt] [PATCH 14.5/16] snapshot: Make virDomainMomentObjListGetNames more generic 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: , Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 22 Mar 2019 04:25:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Rather than hard-coding the snapshot filter bit values into the generic code, add another layer of indirection: callers must map which of their public filter bits correspond to supported moment bits, then pass two separate flags (the ones translated for moment code to operate on, and the remaining ones for the filter callback to operate on). Signed-off-by: Eric Blake Reviewed-by: John Ferlan --- I realized I don't have to mess with matching public API bits at all. But if I'm smart, the bit values I choose for checkpoints will match the internal ones supported by moments, so that only the snapshot code has to do the mapping. src/conf/virdomainmomentobjlist.h | 32 ++++++++++++++++++++++++++-- src/conf/virdomainmomentobjlist.c | 33 +++++++++++++++-------------- src/conf/virdomainsnapshotobjlist.c | 29 +++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentob= jlist.h index 89a0df5a24..b67af24bba 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -70,12 +70,40 @@ void virDomainMomentObjListFree(virDomainMomentObjListP= tr moments); virDomainMomentObjPtr virDomainMomentAssignDef(virDomainMomentObjListPtr m= oments, virDomainMomentDefPtr def); +/* Various enum bits that map to public API filters. Note that the + * values of the internal bits are not necessarily the same as the + * public ones. */ +typedef enum { + VIR_DOMAIN_MOMENT_LIST_ROOTS =3D (1 << 0), + VIR_DOMAIN_MOMENT_LIST_DESCENDANTS =3D (1 << 0), + VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL =3D (1 << 1), + VIR_DOMAIN_MOMENT_LIST_LEAVES =3D (1 << 2), + VIR_DOMAIN_MOMENT_LIST_NO_LEAVES =3D (1 << 3), + VIR_DOMAIN_MOMENT_LIST_METADATA =3D (1 << 4), + VIR_DOMAIN_MOMENT_LIST_NO_METADATA =3D (1 << 5), +} virDomainMomentFilters; + +# define VIR_DOMAIN_MOMENT_FILTERS_METADATA \ + (VIR_DOMAIN_MOMENT_LIST_METADATA | \ + VIR_DOMAIN_MOMENT_LIST_NO_METADATA) + +# define VIR_DOMAIN_MOMENT_FILTERS_LEAVES \ + (VIR_DOMAIN_MOMENT_LIST_LEAVES | \ + VIR_DOMAIN_MOMENT_LIST_NO_LEAVES) + +# define VIR_DOMAIN_MOMENT_FILTERS_ALL \ + (VIR_DOMAIN_MOMENT_LIST_ROOTS | \ + VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL | \ + VIR_DOMAIN_MOMENT_FILTERS_METADATA | \ + VIR_DOMAIN_MOMENT_FILTERS_LEAVES) + int virDomainMomentObjListGetNames(virDomainMomentObjListPtr moments, virDomainMomentObjPtr from, char **const names, int maxnames, - unsigned int flags, - virDomainMomentObjListFilter filter); + unsigned int moment_flags, + virDomainMomentObjListFilter filter, + unsigned int filter_flags); virDomainMomentObjPtr virDomainMomentFindByName(virDomainMomentObjListPtr = moments, const char *name); int virDomainMomentObjListSize(virDomainMomentObjListPtr moments); diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentob= jlist.c index 46bd3e448a..94b927746a 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -281,6 +281,7 @@ struct virDomainMomentNameData { int count; bool error; virDomainMomentObjListFilter filter; + unsigned int filter_flags; }; @@ -295,13 +296,12 @@ static int virDomainMomentObjListCopyNames(void *payl= oad, return 0; /* Caller already sanitized flags. Filtering on DESCENDANTS was * done by choice of iteration in the caller. */ - /* TODO: Create VIR_DOMAIN_MOMENT_LIST names */ - if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) && obj->nchildren) + if ((data->flags & VIR_DOMAIN_MOMENT_LIST_LEAVES) && obj->nchildren) return 0; - if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES) && !obj->nchild= ren) + if ((data->flags & VIR_DOMAIN_MOMENT_LIST_NO_LEAVES) && !obj->nchildre= n) return 0; - if (!data->filter(obj, data->flags)) + if (!data->filter(obj, data->filter_flags)) return 0; if (data->names && data->count < data->maxnames && @@ -320,25 +320,26 @@ virDomainMomentObjListGetNames(virDomainMomentObjList= Ptr moments, char **const names, int maxnames, unsigned int flags, - virDomainMomentObjListFilter filter) + virDomainMomentObjListFilter filter, + unsigned int filter_flags) { struct virDomainMomentNameData data =3D { names, maxnames, flags, 0, - false, filter }; + false, filter, filter_flags }; size_t i; + virCheckFlags(VIR_DOMAIN_MOMENT_FILTERS_ALL, -1); if (!from) { /* LIST_ROOTS and LIST_DESCENDANTS have the same bit value, * but opposite semantics. Toggle here to get the correct * traversal on the metaroot. */ - /* TODO: Create VIR_DOMAIN_MOMENT_LIST names */ - flags ^=3D VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; + flags ^=3D VIR_DOMAIN_MOMENT_LIST_ROOTS; from =3D &moments->metaroot; } /* We handle LIST_ROOT/LIST_DESCENDANTS and LIST_TOPOLOGICAL directly, * mask those bits out to determine when we must use the filter callba= ck. */ - data.flags &=3D ~(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | - VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL); + data.flags &=3D ~(VIR_DOMAIN_MOMENT_LIST_DESCENDANTS | + VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL); /* If this common code is being used, we assume that all moments * have metadata, and thus can handle METADATA up front as an @@ -346,21 +347,21 @@ virDomainMomentObjListGetNames(virDomainMomentObjList= Ptr moments, * add the ability to track qcow2 internal snapshots without the * use of metadata, in which case this check should move into the * filter callback. */ - if ((data.flags & VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA) =3D=3D - VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA) + if ((data.flags & VIR_DOMAIN_MOMENT_FILTERS_METADATA) =3D=3D + VIR_DOMAIN_MOMENT_LIST_NO_METADATA) return 0; - data.flags &=3D ~VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA; + data.flags &=3D ~VIR_DOMAIN_MOMENT_FILTERS_METADATA; - if (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) { + if (flags & VIR_DOMAIN_MOMENT_LIST_DESCENDANTS) { /* We could just always do a topological visit; but it is * possible to optimize for less stack usage and time when a * simpler full hashtable visit or counter will do. */ if (from->def || (names && - (flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL))) + (flags & VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL))) virDomainMomentForEachDescendant(from, virDomainMomentObjListCopyNam= es, &data); - else if (names || data.flags) + else if (names || data.flags || filter_flags) virHashForEach(moments->objs, virDomainMomentObjListCopyNames, &data); else diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapsh= otobjlist.c index 52887add46..0e38e1585e 100644 --- a/src/conf/virdomainsnapshotobjlist.c +++ b/src/conf/virdomainsnapshotobjlist.c @@ -279,6 +279,31 @@ virDomainSnapshotObjListGetNames(virDomainSnapshotObjL= istPtr snapshots, int maxnames, unsigned int flags) { + /* Convert public flags into common flags */ + unsigned int moment_flags =3D 0; + struct { int snap_flag; int moment_flag; } map[] =3D { + { VIR_DOMAIN_SNAPSHOT_LIST_ROOTS, + VIR_DOMAIN_MOMENT_LIST_ROOTS, }, + { VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL, + VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL, }, + { VIR_DOMAIN_SNAPSHOT_LIST_LEAVES, + VIR_DOMAIN_MOMENT_LIST_LEAVES, }, + { VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES, + VIR_DOMAIN_MOMENT_LIST_NO_LEAVES, }, + { VIR_DOMAIN_SNAPSHOT_LIST_METADATA, + VIR_DOMAIN_MOMENT_LIST_METADATA, }, + { VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA, + VIR_DOMAIN_MOMENT_LIST_NO_METADATA, }, + }; + size_t i; + + for (i =3D 0; i < ARRAY_CARDINALITY(map); i++) { + if (flags & map[i].snap_flag) { + flags &=3D ~map[i].snap_flag; + moment_flags |=3D map[i].moment_flag; + } + } + /* For ease of coding the visitor, it is easier to zero each group * where all of the bits are set. */ if ((flags & VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES) =3D=3D @@ -291,8 +316,8 @@ virDomainSnapshotObjListGetNames(virDomainSnapshotObjLi= stPtr snapshots, VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION) flags &=3D ~VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION; return virDomainMomentObjListGetNames(snapshots->base, from, names, - maxnames, flags, - virDomainSnapshotFilter); + maxnames, moment_flags, + virDomainSnapshotFilter, flags); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list