Imported Upstream version 1.2.5
[archive/platform/upstream/libvirt.git] / src / conf / snapshot_conf.h
1 /*
2  * snapshot_conf.h: domain snapshot XML processing
3  *
4  * Copyright (C) 2006-2014 Red Hat, Inc.
5  * Copyright (C) 2006-2008 Daniel P. Berrange
6  *
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.
11  *
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.
16  *
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/>.
20  *
21  * Author: Eric Blake <eblake@redhat.com>
22  */
23
24 #ifndef __SNAPSHOT_CONF_H
25 # define __SNAPSHOT_CONF_H
26
27 # include "internal.h"
28 # include "domain_conf.h"
29
30 /* Items related to snapshot state */
31
32 typedef enum {
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,
37
38     VIR_DOMAIN_SNAPSHOT_LOCATION_LAST
39 } virDomainSnapshotLocation;
40
41 typedef enum {
42     /* Inherit the VIR_DOMAIN_* states from virDomainState.  */
43     VIR_DOMAIN_DISK_SNAPSHOT = VIR_DOMAIN_LAST,
44     VIR_DOMAIN_SNAPSHOT_STATE_LAST
45 } virDomainSnapshotState;
46
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 */
54
55     virStorageSource src; /* new wrapper file when snapshot is external */
56 };
57
58 /* Stores the complete snapshot metadata */
59 typedef struct _virDomainSnapshotDef virDomainSnapshotDef;
60 typedef virDomainSnapshotDef *virDomainSnapshotDefPtr;
61 struct _virDomainSnapshotDef {
62     /* Public XML.  */
63     char *name;
64     char *description;
65     char *parent;
66     long long creationTime; /* in seconds */
67     int state; /* virDomainSnapshotState */
68
69     int memory; /* virDomainMemorySnapshot */
70     char *file; /* memory state file when snapshot is external */
71
72     size_t ndisks; /* should not exceed dom->ndisks */
73     virDomainSnapshotDiskDef *disks;
74
75     virDomainDefPtr dom;
76
77     /* Internal use.  */
78     bool current; /* At most one snapshot in the list should have this set */
79 };
80
81 struct _virDomainSnapshotObj {
82     virDomainSnapshotDefPtr def; /* non-NULL except for metaroot */
83
84     virDomainSnapshotObjPtr parent; /* non-NULL except for metaroot, before
85                                        virDomainSnapshotUpdateRelations, or
86                                        after virDomainSnapshotDropParent */
87     virDomainSnapshotObjPtr sibling; /* NULL if last child of parent */
88     size_t nchildren;
89     virDomainSnapshotObjPtr first_child; /* NULL if no children */
90 };
91
92 virDomainSnapshotObjListPtr virDomainSnapshotObjListNew(void);
93 void virDomainSnapshotObjListFree(virDomainSnapshotObjListPtr snapshots);
94
95 typedef enum {
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;
101
102 virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
103                                                         virCapsPtr caps,
104                                                         virDomainXMLOptionPtr xmlopt,
105                                                         unsigned int expectedVirtTypes,
106                                                         unsigned int flags);
107 virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml,
108                                                       xmlNodePtr root,
109                                                       virCapsPtr caps,
110                                                       virDomainXMLOptionPtr xmlopt,
111                                                       unsigned int expectedVirtTypes,
112                                                       unsigned int flags);
113 void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
114 char *virDomainSnapshotDefFormat(const char *domain_uuid,
115                                  virDomainSnapshotDefPtr def,
116                                  unsigned int flags,
117                                  int internal);
118 int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot,
119                                 int default_snapshot,
120                                 bool require_match);
121 virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr snapshots,
122                                                    virDomainSnapshotDefPtr def);
123
124 int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
125                                      virDomainSnapshotObjPtr from,
126                                      char **const names, int maxnames,
127                                      unsigned int flags);
128 int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
129                                 virDomainSnapshotObjPtr from,
130                                 unsigned int flags);
131 virDomainSnapshotObjPtr virDomainSnapshotFindByName(virDomainSnapshotObjListPtr snapshots,
132                                                     const char *name);
133 void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
134                                     virDomainSnapshotObjPtr snapshot);
135 int virDomainSnapshotForEach(virDomainSnapshotObjListPtr snapshots,
136                              virHashIterator iter,
137                              void *data);
138 int virDomainSnapshotForEachChild(virDomainSnapshotObjPtr snapshot,
139                                   virHashIterator iter,
140                                   void *data);
141 int virDomainSnapshotForEachDescendant(virDomainSnapshotObjPtr snapshot,
142                                        virHashIterator iter,
143                                        void *data);
144 int virDomainSnapshotUpdateRelations(virDomainSnapshotObjListPtr snapshots);
145 void virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot);
146
147 # define VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA           \
148                (VIR_DOMAIN_SNAPSHOT_LIST_METADATA     | \
149                 VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA)
150
151 # define VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES             \
152                (VIR_DOMAIN_SNAPSHOT_LIST_LEAVES       | \
153                 VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES)
154
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)
159
160 # define VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION           \
161                (VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL     | \
162                 VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)
163
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)
169
170 int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
171                            virDomainSnapshotObjPtr from,
172                            virDomainPtr dom,
173                            virDomainSnapshotPtr **snaps,
174                            unsigned int flags);
175
176 bool virDomainSnapshotDefIsExternal(virDomainSnapshotDefPtr def);
177 bool virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap);
178
179 int virDomainSnapshotRedefinePrep(virDomainPtr domain,
180                                   virDomainObjPtr vm,
181                                   virDomainSnapshotDefPtr *def,
182                                   virDomainSnapshotObjPtr *snap,
183                                   bool *update_current,
184                                   unsigned int flags);
185
186 VIR_ENUM_DECL(virDomainSnapshotLocation)
187 VIR_ENUM_DECL(virDomainSnapshotState)
188
189 #endif /* __SNAPSHOT_CONF_H */