From nobody Mon Feb 9 13:36:44 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 1552626176830762.5191560159133; Thu, 14 Mar 2019 22:02:56 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 3C0853070263; Fri, 15 Mar 2019 05:02:55 +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 1525860FE5; Fri, 15 Mar 2019 05:02:55 +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 CF9B2181A265; Fri, 15 Mar 2019 05:02:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2F52eZU010765 for ; Fri, 15 Mar 2019 01:02:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 149BE5D75E; Fri, 15 Mar 2019 05:02:40 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 839555D6A6; Fri, 15 Mar 2019 05:02:39 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Fri, 15 Mar 2019 00:02:28 -0500 Message-Id: <20190315050233.10782-4-eblake@redhat.com> In-Reply-To: <20190315050233.10782-1-eblake@redhat.com> References: <20190315050233.10782-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com, jsnow@redhat.com Subject: [libvirt] [PATCH v6 3/8] snapshot: Break out virDomainSnapshotObj into its own file 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 15 Mar 2019 05:02:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" snapshot_conf.h was mixing three separate types: the snapshot definition, the snapshot object, and the snapshot object list. Separate out the snapshot object code into its own file, which includes moving a typedef to avoid circular inclusions. Mostly straight code motion, although I fixed a comment along the way. Signed-off-by: Eric Blake Reviewed-by: J=C3=A1n Tomko --- src/conf/snapshot_conf.h | 20 +----- src/conf/virconftypes.h | 3 + src/conf/virdomainsnapshotobj.h | 50 +++++++++++++ src/conf/Makefile.inc.am | 2 + src/conf/snapshot_conf.c | 85 ---------------------- src/conf/virdomainsnapshotobj.c | 122 ++++++++++++++++++++++++++++++++ src/libvirt_private.syms | 9 ++- 7 files changed, 184 insertions(+), 107 deletions(-) create mode 100644 src/conf/virdomainsnapshotobj.h create mode 100644 src/conf/virdomainsnapshotobj.c diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 6d79dbb0da..444de05a71 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -24,6 +24,7 @@ # include "internal.h" # include "domain_conf.h" +# include "virdomainsnapshotobj.h" /* Items related to snapshot state */ @@ -71,8 +72,6 @@ struct _virDomainSnapshotDiskDef { }; /* Stores the complete snapshot metadata */ -typedef struct _virDomainSnapshotDef virDomainSnapshotDef; -typedef virDomainSnapshotDef *virDomainSnapshotDefPtr; struct _virDomainSnapshotDef { /* Public XML. */ char *name; @@ -95,16 +94,6 @@ struct _virDomainSnapshotDef { bool current; /* At most one snapshot in the list should have this set= */ }; -struct _virDomainSnapshotObj { - virDomainSnapshotDefPtr def; /* non-NULL except for metaroot */ - - virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before - virDomainSnapshotUpdateRelations, or - after virDomainSnapshotDropParent */ - virDomainSnapshotObjPtr sibling; /* NULL if last child of parent */ - size_t nchildren; - virDomainSnapshotObjPtr first_child; /* NULL if no children */ -}; virDomainSnapshotObjListPtr virDomainSnapshotObjListNew(void); void virDomainSnapshotObjListFree(virDomainSnapshotObjListPtr snapshots); @@ -172,14 +161,7 @@ void virDomainSnapshotObjListRemove(virDomainSnapshotO= bjListPtr snapshots, int virDomainSnapshotForEach(virDomainSnapshotObjListPtr snapshots, virHashIterator iter, void *data); -int virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot, - virHashIterator iter, - void *data); -int virDomainSnapshotForEachDescendant(virDomainSnapshotObjPtr snapshot, - virHashIterator iter, - void *data); int virDomainSnapshotUpdateRelations(virDomainSnapshotObjListPtr snapshots= ); -void virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot); # define VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA \ (VIR_DOMAIN_SNAPSHOT_LIST_METADATA | \ diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index c4896ff769..a271c4e7f7 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -215,6 +215,9 @@ typedef virDomainShmemDef *virDomainShmemDefPtr; typedef struct _virDomainSmartcardDef virDomainSmartcardDef; typedef virDomainSmartcardDef *virDomainSmartcardDefPtr; +typedef struct _virDomainSnapshotDef virDomainSnapshotDef; +typedef virDomainSnapshotDef *virDomainSnapshotDefPtr; + typedef struct _virDomainSnapshotObj virDomainSnapshotObj; typedef virDomainSnapshotObj *virDomainSnapshotObjPtr; diff --git a/src/conf/virdomainsnapshotobj.h b/src/conf/virdomainsnapshotob= j.h new file mode 100644 index 0000000000..957f1b2ea8 --- /dev/null +++ b/src/conf/virdomainsnapshotobj.h @@ -0,0 +1,50 @@ +/* + * virdomainsnapshotobj.h: handle snapshot objects + * (derived from snapshot_conf.h) + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef LIBVIRT_VIRDOMAINSNAPSHOTOBJ_H +# define LIBVIRT_VIRDOMAINSNAPSHOTOBJ_H + +# include "internal.h" +# include "virconftypes.h" +# include "virhash.h" + +struct _virDomainSnapshotObj { + virDomainSnapshotDefPtr def; /* non-NULL except for metaroot */ + + virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before + virDomainSnapshotUpdateRelations, or + after virDomainSnapshotDropParent */ + virDomainSnapshotObjPtr sibling; /* NULL if last child of parent */ + size_t nchildren; + virDomainSnapshotObjPtr first_child; /* NULL if no children */ +}; + + +int virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot, + virHashIterator iter, + void *data); +int virDomainSnapshotForEachDescendant(virDomainSnapshotObjPtr snapshot, + virHashIterator iter, + void *data); +void virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot); + +#endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJ_H */ diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index 64d4436c6b..be941ee7e2 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -29,6 +29,8 @@ DOMAIN_CONF_SOURCES =3D \ conf/virconftypes.h \ conf/virdomainobjlist.c \ conf/virdomainobjlist.h \ + conf/virdomainsnapshotobj.c \ + conf/virdomainsnapshotobj.h \ $(NULL) OBJECT_EVENT_SOURCES =3D \ diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index e2c91a5072..3b0e527bb2 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -1299,64 +1299,6 @@ virDomainSnapshotForEach(virDomainSnapshotObjListPtr= snapshots, return virHashForEach(snapshots->objs, iter, data); } -/* Run iter(data) on all direct children of snapshot, while ignoring all - * other entries in snapshots. Return the number of children - * visited. No particular ordering is guaranteed. */ -int -virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot, - virHashIterator iter, - void *data) -{ - virDomainSnapshotObjPtr child =3D snapshot->first_child; - - while (child) { - virDomainSnapshotObjPtr next =3D child->sibling; - (iter)(child, child->def->name, data); - child =3D next; - } - - return snapshot->nchildren; -} - -struct snapshot_act_on_descendant { - int number; - virHashIterator iter; - void *data; -}; - -static int -virDomainSnapshotActOnDescendant(void *payload, - const void *name, - void *data) -{ - virDomainSnapshotObjPtr obj =3D payload; - struct snapshot_act_on_descendant *curr =3D data; - - (curr->iter)(payload, name, curr->data); - curr->number +=3D 1 + virDomainSnapshotForEachDescendant(obj, - curr->iter, - curr->data); - return 0; -} - -/* Run iter(data) on all descendants of snapshot, while ignoring all - * other entries in snapshots. Return the number of descendants - * visited. No particular ordering is guaranteed. */ -int -virDomainSnapshotForEachDescendant(virDomainSnapshotObjPtr snapshot, - virHashIterator iter, - void *data) -{ - struct snapshot_act_on_descendant act; - - act.number =3D 0; - act.iter =3D iter; - act.data =3D data; - virDomainSnapshotForEachChild(snapshot, - virDomainSnapshotActOnDescendant, &act); - - return act.number; -} /* Struct and callback function used as a hash table callback; each call * inspects the pre-existing snapshot->def->parent field, and adjusts @@ -1416,33 +1358,6 @@ virDomainSnapshotUpdateRelations(virDomainSnapshotOb= jListPtr snapshots) return act.err; } -/* Prepare to reparent or delete snapshot, by removing it from its - * current listed parent. Note that when bulk removing all children - * of a parent, it is faster to just 0 the count rather than calling - * this function on each child. */ -void -virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot) -{ - virDomainSnapshotObjPtr prev =3D NULL; - virDomainSnapshotObjPtr curr =3D NULL; - - snapshot->parent->nchildren--; - curr =3D snapshot->parent->first_child; - while (curr !=3D snapshot) { - if (!curr) { - VIR_WARN("inconsistent snapshot relations"); - return; - } - prev =3D curr; - curr =3D curr->sibling; - } - if (prev) - prev->sibling =3D snapshot->sibling; - else - snapshot->parent->first_child =3D snapshot->sibling; - snapshot->parent =3D NULL; - snapshot->sibling =3D NULL; -} int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots, diff --git a/src/conf/virdomainsnapshotobj.c b/src/conf/virdomainsnapshotob= j.c new file mode 100644 index 0000000000..487f0cc702 --- /dev/null +++ b/src/conf/virdomainsnapshotobj.c @@ -0,0 +1,122 @@ +/* + * virdomainsnapshotobj.c: handle snapshot objects + * (derived from snapshot_conf.c) + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "internal.h" +#include "virdomainsnapshotobj.h" +#include "snapshot_conf.h" +#include "virlog.h" +#include "virerror.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_SNAPSHOT + +VIR_LOG_INIT("conf.virdomainsnapshotobj"); + +/* Run iter(data) on all direct children of snapshot, while ignoring all + * other entries in snapshots. Return the number of children + * visited. No particular ordering is guaranteed. */ +int +virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot, + virHashIterator iter, + void *data) +{ + virDomainSnapshotObjPtr child =3D snapshot->first_child; + + while (child) { + virDomainSnapshotObjPtr next =3D child->sibling; + (iter)(child, child->def->name, data); + child =3D next; + } + + return snapshot->nchildren; +} + +struct snapshot_act_on_descendant { + int number; + virHashIterator iter; + void *data; +}; + +static int +virDomainSnapshotActOnDescendant(void *payload, + const void *name, + void *data) +{ + virDomainSnapshotObjPtr obj =3D payload; + struct snapshot_act_on_descendant *curr =3D data; + + (curr->iter)(payload, name, curr->data); + curr->number +=3D 1 + virDomainSnapshotForEachDescendant(obj, + curr->iter, + curr->data); + return 0; +} + +/* Run iter(data) on all descendants of snapshot, while ignoring all + * other entries in snapshots. Return the number of descendants + * visited. The visit is guaranteed to be topological, but no + * particular order between siblings is guaranteed. */ +int +virDomainSnapshotForEachDescendant(virDomainSnapshotObjPtr snapshot, + virHashIterator iter, + void *data) +{ + struct snapshot_act_on_descendant act; + + act.number =3D 0; + act.iter =3D iter; + act.data =3D data; + virDomainSnapshotForEachChild(snapshot, + virDomainSnapshotActOnDescendant, &act); + + return act.number; +} + + +/* Prepare to reparent or delete snapshot, by removing it from its + * current listed parent. Note that when bulk removing all children + * of a parent, it is faster to just 0 the count rather than calling + * this function on each child. */ +void +virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot) +{ + virDomainSnapshotObjPtr prev =3D NULL; + virDomainSnapshotObjPtr curr =3D NULL; + + snapshot->parent->nchildren--; + curr =3D snapshot->parent->first_child; + while (curr !=3D snapshot) { + if (!curr) { + VIR_WARN("inconsistent snapshot relations"); + return; + } + prev =3D curr; + curr =3D curr->sibling; + } + if (prev) + prev->sibling =3D snapshot->sibling; + else + snapshot->parent->first_child =3D snapshot->sibling; + snapshot->parent =3D NULL; + snapshot->sibling =3D NULL; +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9582b72262..d775fe8551 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -890,11 +890,8 @@ virDomainSnapshotDefFormat; virDomainSnapshotDefFree; virDomainSnapshotDefIsExternal; virDomainSnapshotDefParseString; -virDomainSnapshotDropParent; virDomainSnapshotFindByName; virDomainSnapshotForEach; -virDomainSnapshotForEachChild; -virDomainSnapshotForEachDescendant; virDomainSnapshotFormatConvertXMLFlags; virDomainSnapshotIsExternal; virDomainSnapshotLocationTypeFromString; @@ -992,6 +989,12 @@ virDomainObjListRemoveLocked; virDomainObjListRename; +# conf/virdomainsnapshotobj.h +virDomainSnapshotDropParent; +virDomainSnapshotForEachChild; +virDomainSnapshotForEachDescendant; + + # conf/virinterfaceobj.h virInterfaceObjEndAPI; virInterfaceObjGetDef; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list