1 /*
2  * snapshot_conf.h: domain snapshot XML processing
3  *
4  * Copyright (C) 2006-2019 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 
22 #pragma once
23 
24 #include "internal.h"
25 #include "domain_conf.h"
26 #include "moment_conf.h"
27 #include "virenum.h"
28 
29 /* Items related to snapshot state */
30 
31 typedef enum {
32     VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT = 0,
33     VIR_DOMAIN_SNAPSHOT_LOCATION_NONE,
34     VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL,
35     VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL,
36 
37     VIR_DOMAIN_SNAPSHOT_LOCATION_LAST
38 } virDomainSnapshotLocation;
39 
40 /**
41  * This enum has to map all known domain states from the public enum
42  * virDomainState, before adding one additional state possible only
43  * for snapshots.
44  */
45 typedef enum {
46     /* Mapped to public enum */
47     VIR_DOMAIN_SNAPSHOT_NOSTATE = VIR_DOMAIN_NOSTATE,
48     VIR_DOMAIN_SNAPSHOT_RUNNING = VIR_DOMAIN_RUNNING,
49     VIR_DOMAIN_SNAPSHOT_BLOCKED = VIR_DOMAIN_BLOCKED,
50     VIR_DOMAIN_SNAPSHOT_PAUSED = VIR_DOMAIN_PAUSED,
51     VIR_DOMAIN_SNAPSHOT_SHUTDOWN = VIR_DOMAIN_SHUTDOWN,
52     VIR_DOMAIN_SNAPSHOT_SHUTOFF = VIR_DOMAIN_SHUTOFF,
53     VIR_DOMAIN_SNAPSHOT_CRASHED = VIR_DOMAIN_CRASHED,
54     VIR_DOMAIN_SNAPSHOT_PMSUSPENDED = VIR_DOMAIN_PMSUSPENDED,
55     /* Additional enum values local to snapshots */
56     VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT,
57     VIR_DOMAIN_SNAPSHOT_LAST
58 } virDomainSnapshotState;
59 G_STATIC_ASSERT((int)VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT == VIR_DOMAIN_LAST);
60 
61 /* Stores disk-snapshot information */
62 typedef struct _virDomainSnapshotDiskDef virDomainSnapshotDiskDef;
63 struct _virDomainSnapshotDiskDef {
64     char *name;     /* name matching the <target dev='...' of the domain */
65     int snapshot;   /* virDomainSnapshotLocation */
66 
67     /* details of wrapper external file. src is always non-NULL.
68      * XXX optimize this to allow NULL for internal snapshots? */
69     virStorageSource *src;
70 };
71 
72 void
73 virDomainSnapshotDiskDefFree(virDomainSnapshotDiskDef *disk);
74 
75 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSnapshotDiskDef, virDomainSnapshotDiskDefFree);
76 
77 /* Stores the complete snapshot metadata */
78 struct _virDomainSnapshotDef {
79     virDomainMomentDef parent;
80 
81     /* Additional public XML.  */
82     int state; /* virDomainSnapshotState */
83 
84     int memory; /* virDomainMemorySnapshot */
85     char *memorysnapshotfile; /* memory state file when snapshot is external */
86 
87     size_t ndisks; /* should not exceed dom->ndisks */
88     virDomainSnapshotDiskDef *disks;
89 
90     virObject *cookie;
91 };
92 
93 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSnapshotDef, virObjectUnref);
94 
95 
96 typedef enum {
97     VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE = 1 << 0,
98     VIR_DOMAIN_SNAPSHOT_PARSE_DISKS    = 1 << 1,
99     VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL = 1 << 2,
100     VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE  = 1 << 3,
101     VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE = 1 << 4,
102 } virDomainSnapshotParseFlags;
103 
104 typedef enum {
105     VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE   = 1 << 0,
106     VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL = 1 << 1,
107     VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT  = 1 << 2,
108 } virDomainSnapshotFormatFlags;
109 
110 unsigned int virDomainSnapshotFormatConvertXMLFlags(unsigned int flags);
111 
112 virDomainSnapshotDef *virDomainSnapshotDefParseString(const char *xmlStr,
113                                                       virDomainXMLOption *xmlopt,
114                                                       void *parseOpaque,
115                                                       bool *current,
116                                                       unsigned int flags);
117 virDomainSnapshotDef *virDomainSnapshotDefParseNode(xmlDocPtr xml,
118                                                     xmlNodePtr root,
119                                                     virDomainXMLOption *xmlopt,
120                                                     void *parseOpaque,
121                                                     bool *current,
122                                                     unsigned int flags);
123 virDomainSnapshotDef *virDomainSnapshotDefNew(void);
124 char *virDomainSnapshotDefFormat(const char *uuidstr,
125                                  virDomainSnapshotDef *def,
126                                  virDomainXMLOption *xmlopt,
127                                  unsigned int flags);
128 int virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapshot,
129                                 int default_snapshot,
130                                 bool require_match);
131 
132 bool virDomainSnapshotDefIsExternal(virDomainSnapshotDef *def);
133 bool virDomainSnapshotIsExternal(virDomainMomentObj *snap);
134 
135 int virDomainSnapshotRedefinePrep(virDomainObj *vm,
136                                   virDomainSnapshotDef **def,
137                                   virDomainMomentObj **snap,
138                                   virDomainXMLOption *xmlopt,
139                                   unsigned int flags);
140 
141 int virDomainSnapshotRedefineValidate(virDomainSnapshotDef *def,
142                                       const unsigned char *domain_uuid,
143                                       virDomainMomentObj *other,
144                                       virDomainXMLOption *xmlopt,
145                                       unsigned int flags);
146 
147 VIR_ENUM_DECL(virDomainSnapshotLocation);
148 VIR_ENUM_DECL(virDomainSnapshotState);
149