2019-03-15 01:03:40 +00:00
|
|
|
/*
|
2019-03-22 04:46:26 +00:00
|
|
|
* virdomainmomentobjlist.h: handle a tree of moment objects
|
2019-03-15 01:03:40 +00:00
|
|
|
* (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/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#pragma once
|
2019-03-15 01:03:40 +00:00
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "virconftypes.h"
|
|
|
|
#include "virhash.h"
|
2019-03-15 01:03:40 +00:00
|
|
|
|
2019-03-22 05:39:02 +00:00
|
|
|
/* Filter that returns true if a given moment matches the filter flags */
|
|
|
|
typedef bool (*virDomainMomentObjListFilter)(virDomainMomentObjPtr obj,
|
|
|
|
unsigned int flags);
|
|
|
|
|
2019-03-22 04:46:26 +00:00
|
|
|
/* 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. */
|
2019-03-22 04:45:25 +00:00
|
|
|
struct _virDomainMomentObj {
|
2019-03-22 04:46:26 +00:00
|
|
|
/* Public field */
|
2019-03-22 04:44:33 +00:00
|
|
|
virDomainMomentDefPtr def; /* non-NULL except for metaroot */
|
2019-03-15 01:03:40 +00:00
|
|
|
|
2019-03-22 04:46:26 +00:00
|
|
|
/* Private fields, use accessors instead */
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr parent; /* non-NULL except for metaroot, before
|
2019-03-22 04:46:26 +00:00
|
|
|
virDomainMomentUpdateRelations, or
|
2019-03-22 04:45:25 +00:00
|
|
|
after virDomainMomentDropParent */
|
|
|
|
virDomainMomentObjPtr sibling; /* NULL if last child of parent */
|
2019-03-15 01:03:40 +00:00
|
|
|
size_t nchildren;
|
2019-03-22 04:45:25 +00:00
|
|
|
virDomainMomentObjPtr first_child; /* NULL if no children */
|
2019-03-15 01:03:40 +00:00
|
|
|
};
|
|
|
|
|
2019-03-22 04:45:25 +00:00
|
|
|
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);
|
2019-07-24 03:26:05 +00:00
|
|
|
void virDomainMomentLinkParent(virDomainMomentObjListPtr moments,
|
|
|
|
virDomainMomentObjPtr moment);
|
2019-03-15 01:03:40 +00:00
|
|
|
|
2019-03-22 05:39:02 +00:00
|
|
|
virDomainMomentObjListPtr virDomainMomentObjListNew(void);
|
|
|
|
void virDomainMomentObjListFree(virDomainMomentObjListPtr moments);
|
|
|
|
|
|
|
|
virDomainMomentObjPtr virDomainMomentAssignDef(virDomainMomentObjListPtr moments,
|
|
|
|
virDomainMomentDefPtr def);
|
|
|
|
|
2019-03-22 04:17:01 +00:00
|
|
|
/* Various enum bits that map to public API filters. Note that the
|
backup: Introduce virDomainCheckpoint APIs
Introduce a bunch of new public APIs related to backup checkpoints.
Checkpoints are modeled heavily after virDomainSnapshotPtr (both
represent a point in time of the guest), although a snapshot exists
with the intent of rolling back to that state, while a checkpoint
exists to make it possible to create an incremental backup at a later
time. We may have a future hypervisor that can completely manage
checkpoints without libvirt metadata, but the first two planned
hypervisors (qemu and test) both always use libvirt for tracking
metadata relations between checkpoints, so for now, I've deferred
the counterpart of virDomainSnapshotHasMetadata for a separate
API addition at a later date if there is ever a need for it.
Note that until we allow snapshots and checkpoints to exist
simultaneously on the same domain (although the actual prevention of
this will be in a separate patch for the sake of an easier revert down
the road), that it is not possible to branch out to create more than
one checkpoint child to a given parent, although it may become
possible later when we revert to a snapshot that coincides with a
checkpoint. This also means that for now, the decision of which
checkpoint becomes the parent of a newly created one is the only
checkpoint with no child (so while there are APIs for dealing with a
current snapshot, we do not need those for checkpoints). We may end
up exposing a notion of a current checkpoint later, but it's easier to
add stuff when proven needed than to blindly support it now and wish
we hadn't exposed it.
The following map shows the API relations to snapshots, with new APIs
on the right:
Operate on a domain object to create/redefine a child:
virDomainSnapshotCreateXML virDomainCheckpointCreateXML
Operate on a child object for lifetime management:
virDomainSnapshotDelete virDomainCheckpointDelete
virDomainSnapshotFree virDomainCheckpointFree
virDomainSnapshotRef virDomainCheckpointRef
Operate on a child object to learn more about it:
virDomainSnapshotGetXMLDesc virDomainCheckpointGetXMLDesc
virDomainSnapshotGetConnect virDomainCheckpointGetConnect
virDomainSnapshotGetDomain virDomainCheckpointGetDomain
virDomainSnapshotGetName virDomainCheckpiontGetName
virDomainSnapshotGetParent virDomainCheckpiontGetParent
virDomainSnapshotHasMetadata (deferred for later)
virDomainSnapshotIsCurrent (no counterpart, see note above)
Operate on a domain object to list all children:
virDomainSnapshotNum (no counterparts, these are the old
virDomainSnapshotListNames racy interfaces)
virDomainSnapshotListAllSnapshots virDomainListAllCheckpoints
Operate on a child object to list descendents:
virDomainSnapshotNumChildren (no counterparts, these are the old
virDomainSnapshotListChildrenNames racy interfaces)
virDomainSnapshotListAllChildren virDomainCheckpointListAllChildren
Operate on a domain to locate a particular child:
virDomainSnapshotLookupByName virDomainCheckpointLookupByName
virDomainSnapshotCurrent (no counterpart, see note above)
virDomainHasCurrentSnapshot (no counterpart, old racy interface)
Operate on a snapshot to roll back to earlier state:
virDomainSnapshotRevert (no counterpart, instead checkpoints
are used in incremental backups via
XML to virDomainBackupBegin)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-03-13 19:35:26 +00:00
|
|
|
* values of the internal bits are not the same as the public ones for
|
|
|
|
* snapshot, however, this list should be kept in sync with the public
|
|
|
|
* ones for checkpoint. */
|
2019-03-22 04:17:01 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_ROOTS = (1 << 0),
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_DESCENDANTS = (1 << 0),
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL = (1 << 1),
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_LEAVES = (1 << 2),
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_NO_LEAVES = (1 << 3),
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_METADATA = (1 << 4),
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_NO_METADATA = (1 << 5),
|
|
|
|
} virDomainMomentFilters;
|
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#define VIR_DOMAIN_MOMENT_FILTERS_METADATA \
|
2019-03-22 04:17:01 +00:00
|
|
|
(VIR_DOMAIN_MOMENT_LIST_METADATA | \
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_NO_METADATA)
|
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#define VIR_DOMAIN_MOMENT_FILTERS_LEAVES \
|
2019-03-22 04:17:01 +00:00
|
|
|
(VIR_DOMAIN_MOMENT_LIST_LEAVES | \
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_NO_LEAVES)
|
|
|
|
|
2019-06-07 20:20:21 +00:00
|
|
|
#define VIR_DOMAIN_MOMENT_FILTERS_ALL \
|
2019-03-22 04:17:01 +00:00
|
|
|
(VIR_DOMAIN_MOMENT_LIST_ROOTS | \
|
|
|
|
VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL | \
|
|
|
|
VIR_DOMAIN_MOMENT_FILTERS_METADATA | \
|
|
|
|
VIR_DOMAIN_MOMENT_FILTERS_LEAVES)
|
|
|
|
|
2019-03-22 05:39:02 +00:00
|
|
|
int virDomainMomentObjListGetNames(virDomainMomentObjListPtr moments,
|
|
|
|
virDomainMomentObjPtr from,
|
|
|
|
char **const names,
|
|
|
|
int maxnames,
|
2019-03-22 04:17:01 +00:00
|
|
|
unsigned int moment_flags,
|
|
|
|
virDomainMomentObjListFilter filter,
|
|
|
|
unsigned int filter_flags);
|
2019-03-22 05:39:02 +00:00
|
|
|
virDomainMomentObjPtr virDomainMomentFindByName(virDomainMomentObjListPtr moments,
|
|
|
|
const char *name);
|
|
|
|
int virDomainMomentObjListSize(virDomainMomentObjListPtr moments);
|
|
|
|
virDomainMomentObjPtr virDomainMomentGetCurrent(virDomainMomentObjListPtr moments);
|
|
|
|
const char *virDomainMomentGetCurrentName(virDomainMomentObjListPtr moments);
|
|
|
|
void virDomainMomentSetCurrent(virDomainMomentObjListPtr moments,
|
|
|
|
virDomainMomentObjPtr moment);
|
|
|
|
bool virDomainMomentObjListRemove(virDomainMomentObjListPtr moments,
|
|
|
|
virDomainMomentObjPtr moment);
|
|
|
|
void virDomainMomentObjListRemoveAll(virDomainMomentObjListPtr moments);
|
|
|
|
int virDomainMomentForEach(virDomainMomentObjListPtr moments,
|
|
|
|
virHashIterator iter,
|
|
|
|
void *data);
|
|
|
|
int virDomainMomentUpdateRelations(virDomainMomentObjListPtr moments);
|
2019-07-06 02:07:43 +00:00
|
|
|
int virDomainMomentCheckCycles(virDomainMomentObjListPtr list,
|
|
|
|
virDomainMomentDefPtr def,
|
|
|
|
const char *domname);
|
backup: Allow for lists of checkpoint objects
Create a new file for managing a list of checkpoint objects, borrowing
heavily from existing virDomainSnapshotObjList paradigms.
Note that while snapshots definitely have a use case for multiple
children to a single parent (create a base snapshot, create a child
snapshot, revert to the base, then create another child snapshot),
it's harder to predict how checkpoints will play out with reverting to
prior points in time. Thus, in initial use, given a list of
checkpoints, you never have more than one child, and we can treat the
most-recent leaf node as the parent of the next node creation, without
having to expose a notion of a current node in XML or public API.
However, as the snapshot machinery is already generic, it is easier to
reuse the generic machinery that tracks relations between domain
moments than it is to open-code a new list-management scheme just for
checkpoints (hence, we still have internal functions related to a
current checkpoint, even though that has no observable effect
externally, as well as the addition of a function to easily find the
lone leaf in the list to use as the current checkpoint).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-07-19 02:24:54 +00:00
|
|
|
virDomainMomentObjPtr virDomainMomentFindLeaf(virDomainMomentObjListPtr list);
|