1 /*
2  * backup_conf.h: domain backup XML processing
3  *                 (based on domain_conf.h)
4  *
5  * Copyright (C) 2006-2019 Red Hat, Inc.
6  * Copyright (C) 2006-2008 Daniel P. Berrange
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library.  If not, see
20  * <http://www.gnu.org/licenses/>.
21  */
22 
23 #pragma once
24 
25 #include "internal.h"
26 #include "virconftypes.h"
27 
28 /* Items related to incremental backup state */
29 
30 typedef enum {
31     VIR_DOMAIN_BACKUP_TYPE_DEFAULT = 0,
32     VIR_DOMAIN_BACKUP_TYPE_PUSH,
33     VIR_DOMAIN_BACKUP_TYPE_PULL,
34 
35     VIR_DOMAIN_BACKUP_TYPE_LAST
36 } virDomainBackupType;
37 
38 typedef enum {
39     VIR_DOMAIN_BACKUP_DISK_STATE_NONE = 0,
40     VIR_DOMAIN_BACKUP_DISK_STATE_RUNNING,
41     VIR_DOMAIN_BACKUP_DISK_STATE_COMPLETE,
42     VIR_DOMAIN_BACKUP_DISK_STATE_FAILED,
43     VIR_DOMAIN_BACKUP_DISK_STATE_CANCELLING,
44     VIR_DOMAIN_BACKUP_DISK_STATE_CANCELLED,
45     VIR_DOMAIN_BACKUP_DISK_STATE_LAST
46 } virDomainBackupDiskState;
47 
48 
49 typedef enum {
50     VIR_DOMAIN_BACKUP_DISK_BACKUP_MODE_DEFAULT = 0,
51     VIR_DOMAIN_BACKUP_DISK_BACKUP_MODE_FULL,
52     VIR_DOMAIN_BACKUP_DISK_BACKUP_MODE_INCREMENTAL,
53 
54     VIR_DOMAIN_BACKUP_DISK_BACKUP_MODE_LAST
55 } virDomainBackupDiskBackupMode;
56 
57 
58 /* Stores disk-backup information */
59 typedef struct _virDomainBackupDiskDef virDomainBackupDiskDef;
60 struct _virDomainBackupDiskDef {
61     char *name;     /* name matching the <target dev='...' of the domain */
62     virTristateBool backup; /* whether backup is requested */
63     virDomainBackupDiskBackupMode backupmode;
64     char *incremental; /* name of the starting point checkpoint of an incremental backup */
65     char *exportname; /* name of the NBD export for pull mode backup */
66     char *exportbitmap; /* name of the bitmap exposed in NBD for pull mode backup */
67 
68     /* details of target for push-mode, or of the scratch file for pull-mode */
69     virStorageSource *store;
70 
71     /* internal data */
72     virDomainBackupDiskState state;
73 };
74 
75 /* Stores the complete backup metadata */
76 typedef struct _virDomainBackupDef virDomainBackupDef;
77 struct _virDomainBackupDef {
78     /* Public XML.  */
79     int type; /* virDomainBackupType */
80     char *incremental;
81     virStorageNetHostDef *server; /* only when type == PULL */
82     virTristateBool tls; /* use TLS for NBD */
83 
84     size_t ndisks; /* should not exceed dom->ndisks */
85     virDomainBackupDiskDef *disks;
86 
87     /* internal data */
88 
89     /* NBD TLS internals */
90     char *tlsAlias;
91     char *tlsSecretAlias;
92 
93     /* statistic totals for completed disks */
94     unsigned long long push_transferred;
95     unsigned long long push_total;
96     unsigned long long pull_tmp_used;
97     unsigned long long pull_tmp_total;
98 
99     char *errmsg; /* error message of failed sub-blockjob */
100 
101     unsigned int apiFlags; /* original flags used when starting the job */
102 };
103 
104 typedef enum {
105     VIR_DOMAIN_BACKUP_PARSE_INTERNAL = 1 << 0,
106 } virDomainBackupParseFlags;
107 
108 virDomainBackupDef *
109 virDomainBackupDefParseString(const char *xmlStr,
110                               virDomainXMLOption *xmlopt,
111                               unsigned int flags);
112 
113 virDomainBackupDef *
114 virDomainBackupDefParseNode(xmlDocPtr xml,
115                             xmlNodePtr root,
116                             virDomainXMLOption *xmlopt,
117                             unsigned int flags);
118 void
119 virDomainBackupDefFree(virDomainBackupDef *def);
120 
121 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainBackupDef, virDomainBackupDefFree);
122 
123 int
124 virDomainBackupDefFormat(virBuffer *buf,
125                          virDomainBackupDef *def,
126                          bool internal,
127                          virDomainXMLOption *xmlopt);
128 int
129 virDomainBackupAlignDisks(virDomainBackupDef *backup,
130                           virDomainDef *dom,
131                           const char *suffix);
132