2 * snapshot_conf.h: domain snapshot XML processing
4 * Copyright (C) 2006-2014 Red Hat, Inc.
5 * Copyright (C) 2006-2008 Daniel P. Berrange
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see
19 * <http://www.gnu.org/licenses/>.
21 * Author: Eric Blake <eblake@redhat.com>
24 #ifndef __SNAPSHOT_CONF_H
25 # define __SNAPSHOT_CONF_H
27 # include "internal.h"
28 # include "domain_conf.h"
30 /* Items related to snapshot state */
33 VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT = 0,
34 VIR_DOMAIN_SNAPSHOT_LOCATION_NONE,
35 VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL,
36 VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL,
38 VIR_DOMAIN_SNAPSHOT_LOCATION_LAST
39 } virDomainSnapshotLocation;
42 /* Inherit the VIR_DOMAIN_* states from virDomainState. */
43 VIR_DOMAIN_DISK_SNAPSHOT = VIR_DOMAIN_LAST,
44 VIR_DOMAIN_SNAPSHOT_STATE_LAST
45 } virDomainSnapshotState;
47 /* Stores disk-snapshot information */
48 typedef struct _virDomainSnapshotDiskDef virDomainSnapshotDiskDef;
49 typedef virDomainSnapshotDiskDef *virDomainSnapshotDiskDefPtr;
50 struct _virDomainSnapshotDiskDef {
51 char *name; /* name matching the <target dev='...' of the domain */
52 int index; /* index within snapshot->dom->disks that matches name */
53 int snapshot; /* virDomainSnapshotLocation */
55 virStorageSource src; /* new wrapper file when snapshot is external */
58 /* Stores the complete snapshot metadata */
59 typedef struct _virDomainSnapshotDef virDomainSnapshotDef;
60 typedef virDomainSnapshotDef *virDomainSnapshotDefPtr;
61 struct _virDomainSnapshotDef {
66 long long creationTime; /* in seconds */
67 int state; /* virDomainSnapshotState */
69 int memory; /* virDomainMemorySnapshot */
70 char *file; /* memory state file when snapshot is external */
72 size_t ndisks; /* should not exceed dom->ndisks */
73 virDomainSnapshotDiskDef *disks;
78 bool current; /* At most one snapshot in the list should have this set */
81 struct _virDomainSnapshotObj {
82 virDomainSnapshotDefPtr def; /* non-NULL except for metaroot */
84 virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before
85 virDomainSnapshotUpdateRelations, or
86 after virDomainSnapshotDropParent */
87 virDomainSnapshotObjPtr sibling; /* NULL if last child of parent */
89 virDomainSnapshotObjPtr first_child; /* NULL if no children */
92 virDomainSnapshotObjListPtr virDomainSnapshotObjListNew(void);
93 void virDomainSnapshotObjListFree(virDomainSnapshotObjListPtr snapshots);
96 VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE = 1 << 0,
97 VIR_DOMAIN_SNAPSHOT_PARSE_DISKS = 1 << 1,
98 VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL = 1 << 2,
99 VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE = 1 << 3,
100 } virDomainSnapshotParseFlags;
102 virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
104 virDomainXMLOptionPtr xmlopt,
105 unsigned int expectedVirtTypes,
107 virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml,
110 virDomainXMLOptionPtr xmlopt,
111 unsigned int expectedVirtTypes,
113 void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
114 char *virDomainSnapshotDefFormat(const char *domain_uuid,
115 virDomainSnapshotDefPtr def,
118 int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot,
119 int default_snapshot,
121 virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr snapshots,
122 virDomainSnapshotDefPtr def);
124 int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
125 virDomainSnapshotObjPtr from,
126 char **const names, int maxnames,
128 int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
129 virDomainSnapshotObjPtr from,
131 virDomainSnapshotObjPtr virDomainSnapshotFindByName(virDomainSnapshotObjListPtr snapshots,
133 void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
134 virDomainSnapshotObjPtr snapshot);
135 int virDomainSnapshotForEach(virDomainSnapshotObjListPtr snapshots,
136 virHashIterator iter,
138 int virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot,
139 virHashIterator iter,
141 int virDomainSnapshotForEachDescendant(virDomainSnapshotObjPtr snapshot,
142 virHashIterator iter,
144 int virDomainSnapshotUpdateRelations(virDomainSnapshotObjListPtr snapshots);
145 void virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot);
147 # define VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA \
148 (VIR_DOMAIN_SNAPSHOT_LIST_METADATA | \
149 VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA)
151 # define VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES \
152 (VIR_DOMAIN_SNAPSHOT_LIST_LEAVES | \
153 VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES)
155 # define VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS \
156 (VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE | \
157 VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE | \
158 VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY)
160 # define VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION \
161 (VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL | \
162 VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)
164 # define VIR_DOMAIN_SNAPSHOT_FILTERS_ALL \
165 (VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA | \
166 VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES | \
167 VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS | \
168 VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION)
170 int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
171 virDomainSnapshotObjPtr from,
173 virDomainSnapshotPtr **snaps,
176 bool virDomainSnapshotDefIsExternal(virDomainSnapshotDefPtr def);
177 bool virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap);
179 int virDomainSnapshotRedefinePrep(virDomainPtr domain,
181 virDomainSnapshotDefPtr *def,
182 virDomainSnapshotObjPtr *snap,
183 bool *update_current,
186 VIR_ENUM_DECL(virDomainSnapshotLocation)
187 VIR_ENUM_DECL(virDomainSnapshotState)
189 #endif /* __SNAPSHOT_CONF_H */