]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: Rename file for virDomainMomentObj
authorEric Blake <eblake@redhat.com>
Fri, 22 Mar 2019 04:46:26 +0000 (23:46 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 22 Mar 2019 06:18:34 +0000 (01:18 -0500)
Now that we have made virDomainMomentObj sufficiently generic to
support both snapshots and checkpoints, it is time to rename the file
that it lives in. The split between a generic object and a list of the
generic objects doesn't buy us as much, so it will be easier to stick
all the moment list code in one file, with more code moving in the
next patch.  The changes during the move are fairly minor, although it
is worth pointing out that the log/error messages for the new file
report that they are from "domain", since the file will eventually be
shared by both "domain snapshot" and "domain checkpoint".

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/conf/Makefile.inc.am
src/conf/virdomainmomentobjlist.c [new file with mode: 0644]
src/conf/virdomainmomentobjlist.h [new file with mode: 0644]
src/conf/virdomainsnapshotobj.c [deleted file]
src/conf/virdomainsnapshotobj.h [deleted file]
src/conf/virdomainsnapshotobjlist.h
src/libvirt_private.syms

index d2ff8be8fd8fb74406a56e67a2d55a4d2ffaed8b..6eb64db9de684c34f6d3e1df3a7f40abac66e4e0 100644 (file)
@@ -31,8 +31,8 @@ DOMAIN_CONF_SOURCES = \
        conf/virconftypes.h \
        conf/virdomainobjlist.c \
        conf/virdomainobjlist.h \
-       conf/virdomainsnapshotobj.c \
-       conf/virdomainsnapshotobj.h \
+       conf/virdomainmomentobjlist.c \
+       conf/virdomainmomentobjlist.h \
        conf/virdomainsnapshotobjlist.c \
        conf/virdomainsnapshotobjlist.h \
        $(NULL)
diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentobjlist.c
new file mode 100644 (file)
index 0000000..209f924
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * virdomainmomentobjlist.c: handle snapshot/checkpoint 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
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "internal.h"
+#include "virdomainmomentobjlist.h"
+#include "virlog.h"
+#include "virerror.h"
+#include "virstring.h"
+#include "moment_conf.h"
+
+#define VIR_FROM_THIS VIR_FROM_DOMAIN
+
+VIR_LOG_INIT("conf.virdomainmomentobjlist");
+
+/* Run iter(data) on all direct children of moment, while ignoring all
+ * other entries in moments.  Return the number of children
+ * visited.  No particular ordering is guaranteed.  */
+int
+virDomainMomentForEachChild(virDomainMomentObjPtr moment,
+                            virHashIterator iter,
+                            void *data)
+{
+    virDomainMomentObjPtr child = moment->first_child;
+
+    while (child) {
+        virDomainMomentObjPtr next = child->sibling;
+        (iter)(child, child->def->name, data);
+        child = next;
+    }
+
+    return moment->nchildren;
+}
+
+struct moment_act_on_descendant {
+    int number;
+    virHashIterator iter;
+    void *data;
+};
+
+static int
+virDomainMomentActOnDescendant(void *payload,
+                               const void *name,
+                               void *data)
+{
+    virDomainMomentObjPtr obj = payload;
+    struct moment_act_on_descendant *curr = data;
+
+    (curr->iter)(payload, name, curr->data);
+    curr->number += 1 + virDomainMomentForEachDescendant(obj,
+                                                         curr->iter,
+                                                         curr->data);
+    return 0;
+}
+
+/* Run iter(data) on all descendants of moment, while ignoring all
+ * other entries in moments.  Return the number of descendants
+ * visited.  The visit is guaranteed to be topological, but no
+ * particular order between siblings is guaranteed.  */
+int
+virDomainMomentForEachDescendant(virDomainMomentObjPtr moment,
+                                 virHashIterator iter,
+                                 void *data)
+{
+    struct moment_act_on_descendant act;
+
+    act.number = 0;
+    act.iter = iter;
+    act.data = data;
+    virDomainMomentForEachChild(moment,
+                                virDomainMomentActOnDescendant, &act);
+
+    return act.number;
+}
+
+
+/* Prepare to reparent or delete moment, 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
+virDomainMomentDropParent(virDomainMomentObjPtr moment)
+{
+    virDomainMomentObjPtr prev = NULL;
+    virDomainMomentObjPtr curr = NULL;
+
+    moment->parent->nchildren--;
+    curr = moment->parent->first_child;
+    while (curr != moment) {
+        if (!curr) {
+            VIR_WARN("inconsistent moment relations");
+            return;
+        }
+        prev = curr;
+        curr = curr->sibling;
+    }
+    if (prev)
+        prev->sibling = moment->sibling;
+    else
+        moment->parent->first_child = moment->sibling;
+    moment->parent = NULL;
+    moment->sibling = NULL;
+}
+
+
+/* Update @moment to no longer have children. */
+void
+virDomainMomentDropChildren(virDomainMomentObjPtr moment)
+{
+    moment->nchildren = 0;
+    moment->first_child = NULL;
+}
+
+
+/* Add @moment to @parent's list of children. */
+void
+virDomainMomentSetParent(virDomainMomentObjPtr moment,
+                         virDomainMomentObjPtr parent)
+{
+    moment->parent = parent;
+    parent->nchildren++;
+    moment->sibling = parent->first_child;
+    parent->first_child = moment;
+}
+
+
+/* Take all children of @from and convert them into children of @to. */
+void
+virDomainMomentMoveChildren(virDomainMomentObjPtr from,
+                            virDomainMomentObjPtr to)
+{
+    virDomainMomentObjPtr child;
+    virDomainMomentObjPtr last;
+
+    if (!from->first_child)
+        return;
+    for (child = from->first_child; child; child = child->sibling) {
+        child->parent = to;
+        if (!child->sibling)
+            last = child;
+    }
+    to->nchildren += from->nchildren;
+    last->sibling = to->first_child;
+    to->first_child = from->first_child;
+    from->nchildren = 0;
+    from->first_child = NULL;
+}
diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentobjlist.h
new file mode 100644 (file)
index 0000000..dceb55f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * virdomainmomentobjlist.h: handle a tree of moment 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
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBVIRT_VIRDOMAINMOMENTOBJLIST_H
+# define LIBVIRT_VIRDOMAINMOMENTOBJLIST_H
+
+# include "internal.h"
+# include "virconftypes.h"
+# include "virhash.h"
+
+/* Struct that allows tracing hierarchical relationships between
+ * multiple virDomainMoment objects. The opaque type
+ * virDomainMomentObjList then maintains both a hash of these structs
+ * (for quick lookup by name) and a metaroot (which is the parent of
+ * all user-visible roots), so that all other objects always have a
+ * valid parent object; the tree structure is currently maintained via
+ * a linked list. */
+struct _virDomainMomentObj {
+    /* Public field */
+    virDomainMomentDefPtr def; /* non-NULL except for metaroot */
+
+    /* Private fields, use accessors instead */
+    virDomainMomentObjPtr parent; /* non-NULL except for metaroot, before
+                                     virDomainMomentUpdateRelations, or
+                                     after virDomainMomentDropParent */
+    virDomainMomentObjPtr sibling; /* NULL if last child of parent */
+    size_t nchildren;
+    virDomainMomentObjPtr first_child; /* NULL if no children */
+};
+
+int virDomainMomentForEachChild(virDomainMomentObjPtr moment,
+                                virHashIterator iter,
+                                void *data);
+int virDomainMomentForEachDescendant(virDomainMomentObjPtr moment,
+                                     virHashIterator iter,
+                                     void *data);
+void virDomainMomentDropParent(virDomainMomentObjPtr moment);
+void virDomainMomentDropChildren(virDomainMomentObjPtr moment);
+void virDomainMomentMoveChildren(virDomainMomentObjPtr from,
+                                 virDomainMomentObjPtr to);
+void virDomainMomentSetParent(virDomainMomentObjPtr moment,
+                              virDomainMomentObjPtr parent);
+
+#endif /* LIBVIRT_VIRDOMAINMOMENTOBJLIST_H */
diff --git a/src/conf/virdomainsnapshotobj.c b/src/conf/virdomainsnapshotobj.c
deleted file mode 100644 (file)
index d4f5f60..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include "internal.h"
-#include "virdomainsnapshotobj.h"
-#include "snapshot_conf.h"
-#include "virdomainsnapshotobjlist.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 moment, while ignoring all
- * other entries in moments.  Return the number of children
- * visited.  No particular ordering is guaranteed.  */
-int
-virDomainMomentForEachChild(virDomainMomentObjPtr moment,
-                            virHashIterator iter,
-                            void *data)
-{
-    virDomainMomentObjPtr child = moment->first_child;
-
-    while (child) {
-        virDomainMomentObjPtr next = child->sibling;
-        (iter)(child, child->def->name, data);
-        child = next;
-    }
-
-    return moment->nchildren;
-}
-
-struct moment_act_on_descendant {
-    int number;
-    virHashIterator iter;
-    void *data;
-};
-
-static int
-virDomainMomentActOnDescendant(void *payload,
-                               const void *name,
-                               void *data)
-{
-    virDomainMomentObjPtr obj = payload;
-    struct moment_act_on_descendant *curr = data;
-
-    (curr->iter)(payload, name, curr->data);
-    curr->number += 1 + virDomainMomentForEachDescendant(obj,
-                                                           curr->iter,
-                                                           curr->data);
-    return 0;
-}
-
-/* Run iter(data) on all descendants of moment, while ignoring all
- * other entries in moments.  Return the number of descendants
- * visited.  The visit is guaranteed to be topological, but no
- * particular order between siblings is guaranteed.  */
-int
-virDomainMomentForEachDescendant(virDomainMomentObjPtr moment,
-                                 virHashIterator iter,
-                                 void *data)
-{
-    struct moment_act_on_descendant act;
-
-    act.number = 0;
-    act.iter = iter;
-    act.data = data;
-    virDomainMomentForEachChild(moment,
-                                virDomainMomentActOnDescendant, &act);
-
-    return act.number;
-}
-
-
-/* Prepare to reparent or delete moment, 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
-virDomainMomentDropParent(virDomainMomentObjPtr moment)
-{
-    virDomainMomentObjPtr prev = NULL;
-    virDomainMomentObjPtr curr = NULL;
-
-    moment->parent->nchildren--;
-    curr = moment->parent->first_child;
-    while (curr != moment) {
-        if (!curr) {
-            VIR_WARN("inconsistent snapshot relations");
-            return;
-        }
-        prev = curr;
-        curr = curr->sibling;
-    }
-    if (prev)
-        prev->sibling = moment->sibling;
-    else
-        moment->parent->first_child = moment->sibling;
-    moment->parent = NULL;
-    moment->sibling = NULL;
-}
-
-
-/* Update @moment to no longer have children. */
-void
-virDomainMomentDropChildren(virDomainMomentObjPtr moment)
-{
-    moment->nchildren = 0;
-    moment->first_child = NULL;
-}
-
-
-/* Add @moment to @parent's list of children. */
-void
-virDomainMomentSetParent(virDomainMomentObjPtr moment,
-                         virDomainMomentObjPtr parent)
-{
-    moment->parent = parent;
-    parent->nchildren++;
-    moment->sibling = parent->first_child;
-    parent->first_child = moment;
-}
-
-
-/* Take all children of @from and convert them into children of @to. */
-void
-virDomainMomentMoveChildren(virDomainMomentObjPtr from,
-                            virDomainMomentObjPtr to)
-{
-    virDomainMomentObjPtr child;
-    virDomainMomentObjPtr last;
-
-    if (!from->first_child)
-        return;
-    for (child = from->first_child; child; child = child->sibling) {
-        child->parent = to;
-        if (!child->sibling)
-            last = child;
-    }
-    to->nchildren += from->nchildren;
-    last->sibling = to->first_child;
-    to->first_child = from->first_child;
-    from->nchildren = 0;
-    from->first_child = NULL;
-}
diff --git a/src/conf/virdomainsnapshotobj.h b/src/conf/virdomainsnapshotobj.h
deleted file mode 100644 (file)
index b18df0e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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
- * <http://www.gnu.org/licenses/>.
- */
-
-#ifndef LIBVIRT_VIRDOMAINSNAPSHOTOBJ_H
-# define LIBVIRT_VIRDOMAINSNAPSHOTOBJ_H
-
-# include "internal.h"
-# include "virconftypes.h"
-# include "virhash.h"
-
-struct _virDomainMomentObj {
-    virDomainMomentDefPtr def; /* non-NULL except for metaroot */
-
-    virDomainMomentObjPtr parent; /* non-NULL except for metaroot, before
-                                     virDomainSnapshotUpdateRelations, or
-                                     after virDomainMomentDropParent */
-    virDomainMomentObjPtr sibling; /* NULL if last child of parent */
-    size_t nchildren;
-    virDomainMomentObjPtr first_child; /* NULL if no children */
-};
-
-
-int virDomainMomentForEachChild(virDomainMomentObjPtr moment,
-                                virHashIterator iter,
-                                void *data);
-int virDomainMomentForEachDescendant(virDomainMomentObjPtr moment,
-                                     virHashIterator iter,
-                                     void *data);
-void virDomainMomentDropParent(virDomainMomentObjPtr moment);
-void virDomainMomentDropChildren(virDomainMomentObjPtr moment);
-void virDomainMomentMoveChildren(virDomainMomentObjPtr from,
-                                 virDomainMomentObjPtr to);
-void virDomainMomentSetParent(virDomainMomentObjPtr moment,
-                              virDomainMomentObjPtr parent);
-
-#endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJ_H */
index e504e40465b22849857dae6e94c148c867087240..7398a5c331c0c62086c2d7a75371089734a145a2 100644 (file)
@@ -24,7 +24,7 @@
 # define LIBVIRT_VIRDOMAINSNAPSHOTOBJLIST_H
 
 # include "internal.h"
-# include "virdomainsnapshotobj.h"
+# include "virdomainmomentobjlist.h"
 # include "virbuffer.h"
 
 /* Filter that returns true if a given moment matches the filter flags */
index eef215bc31b4a4dc0f651076df269786a4c7226d..bf5625fbf44ae129737388df8b9001d5667e4c0b 100644 (file)
@@ -960,6 +960,15 @@ virChrdevFree;
 virChrdevOpen;
 
 
+# conf/virdomainmomentobjlist.h
+virDomainMomentDropChildren;
+virDomainMomentDropParent;
+virDomainMomentForEachChild;
+virDomainMomentForEachDescendant;
+virDomainMomentMoveChildren;
+virDomainMomentSetParent;
+
+
 # conf/virdomainobjlist.h
 virDomainObjListAdd;
 virDomainObjListCollect;
@@ -979,15 +988,6 @@ virDomainObjListRemoveLocked;
 virDomainObjListRename;
 
 
-# conf/virdomainsnapshotobj.h
-virDomainMomentDropChildren;
-virDomainMomentDropParent;
-virDomainMomentForEachChild;
-virDomainMomentForEachDescendant;
-virDomainMomentMoveChildren;
-virDomainMomentSetParent;
-
-
 # conf/virdomainsnapshotobjlist.h
 virDomainListSnapshots;
 virDomainSnapshotAssignDef;