From nobody Mon Feb 9 04:30:02 2026 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 1553060509440917.1288613630159; Tue, 19 Mar 2019 22:41:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EC1A307EA8C; Wed, 20 Mar 2019 05:41:47 +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 62FB069281; Wed, 20 Mar 2019 05:41:47 +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 29044180338D; Wed, 20 Mar 2019 05:41:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2K5fT9W017250 for ; Wed, 20 Mar 2019 01:41:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6DD1D17797; Wed, 20 Mar 2019 05:41:29 +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 0D62417795; Wed, 20 Mar 2019 05:41:28 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 20 Mar 2019 00:40:58 -0500 Message-Id: <20190320054105.17689-10-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.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com Subject: [libvirt] [PATCH 09/16] snapshot: Refactor list filtering 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 20 Mar 2019 05:41:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Separate the algorithm for which list members to vist (which is generic and can be shared with checkpoints, provided that checkpoints pick the same bit values for some of its flags) from the decision on which members to return (which is specific to snapshots). The typedef for the callback function feels a bit heavy here, but will make it easier to move the common portions in a later patch. Signed-off-by: Eric Blake Reviewed-by: John Ferlan --- src/conf/virdomainsnapshotobjlist.h | 4 ++ src/conf/virdomainsnapshotobjlist.c | 60 ++++++++++++++++++----------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/conf/virdomainsnapshotobjlist.h b/src/conf/virdomainsnapsh= otobjlist.h index c13a0b4026..c7d4d265cb 100644 --- a/src/conf/virdomainsnapshotobjlist.h +++ b/src/conf/virdomainsnapshotobjlist.h @@ -27,6 +27,10 @@ # include "virdomainsnapshotobj.h" # include "virbuffer.h" +/* Filter that returns true if a given snapshot matches the filter flags */ +typedef bool (*virDomainSnapshotObjListFilter)(virDomainSnapshotObjPtr obj, + unsigned int flags); + virDomainSnapshotObjListPtr virDomainSnapshotObjListNew(void); void virDomainSnapshotObjListFree(virDomainSnapshotObjListPtr snapshots); diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapsh= otobjlist.c index ec670ff5c2..cd3ea569e3 100644 --- a/src/conf/virdomainsnapshotobjlist.c +++ b/src/conf/virdomainsnapshotobjlist.c @@ -260,6 +260,38 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(vir= DomainSnapshotObjListPtr s } /* Snapshot Obj List functions */ +static bool +virDomainSnapshotFilter(virDomainSnapshotObjPtr obj, + unsigned int flags) +{ + virDomainSnapshotDefPtr def =3D virDomainSnapshotObjGetDef(obj); + + /* Caller has already sanitized flags and performed filtering on + * DESCENDANTS and LEAVES. */ + if (flags & VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS) { + if (!(flags & VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE) && + def->state =3D=3D VIR_DOMAIN_SNAPSHOT_SHUTOFF) + return false; + if (!(flags & VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY) && + def->state =3D=3D VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT) + return false; + if (!(flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE) && + def->state !=3D VIR_DOMAIN_SNAPSHOT_SHUTOFF && + def->state !=3D VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT) + return false; + } + + if ((flags & VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL) && + virDomainSnapshotIsExternal(obj)) + return false; + if ((flags & VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL) && + !virDomainSnapshotIsExternal(obj)) + return false; + + return true; +} + + static void virDomainSnapshotObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED) @@ -292,12 +324,14 @@ virDomainSnapshotObjListFree(virDomainSnapshotObjList= Ptr snapshots) VIR_FREE(snapshots); } + struct virDomainSnapshotNameData { char **const names; int maxnames; unsigned int flags; int count; bool error; + virDomainSnapshotObjListFilter filter; }; static int virDomainSnapshotObjListCopyNames(void *payload, @@ -316,26 +350,7 @@ static int virDomainSnapshotObjListCopyNames(void *pay= load, if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES) && !obj->nchild= ren) return 0; - if (data->flags & VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS) { - virDomainSnapshotDefPtr def =3D virDomainSnapshotObjGetDef(obj); - - if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE) && - def->state =3D=3D VIR_DOMAIN_SNAPSHOT_SHUTOFF) - return 0; - if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY) && - def->state =3D=3D VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT) - return 0; - if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE) && - def->state !=3D VIR_DOMAIN_SNAPSHOT_SHUTOFF && - def->state !=3D VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT) - return 0; - } - - if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL) && - virDomainSnapshotIsExternal(obj)) - return 0; - if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL) && - !virDomainSnapshotIsExternal(obj)) + if (data->filter(obj, data->flags)) return 0; if (data->names && data->count < data->maxnames && @@ -350,11 +365,12 @@ static int virDomainSnapshotObjListCopyNames(void *pa= yload, int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots, virDomainSnapshotObjPtr from, - char **const names, int maxnames, + char **const names, + int maxnames, unsigned int flags) { struct virDomainSnapshotNameData data =3D { names, maxnames, flags, 0, - false }; + false, virDomainSnapshotFilt= er }; size_t i; if (!from) { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list