]>
Commit | Line | Data |
---|---|---|
68a30562 | 1 | From eeedbc0558580dcb28d4e82b567ea980b24c9cd3 Mon Sep 17 00:00:00 2001 |
ca0fe5f5 WB |
2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> |
3 | Date: Wed, 9 Dec 2015 16:51:23 +0100 | |
68a30562 | 4 | Subject: [PATCH 27/41] vma: add firewall |
ca0fe5f5 WB |
5 | |
6 | --- | |
7 | blockdev.c | 78 ++++++++++++++++++++++++++++++++++---------------------- | |
8 | hmp.c | 2 +- | |
9 | qapi-schema.json | 1 + | |
10 | qmp-commands.hx | 2 +- | |
11 | 4 files changed, 51 insertions(+), 32 deletions(-) | |
12 | ||
13 | diff --git a/blockdev.c b/blockdev.c | |
68a30562 | 14 | index 2371cf3..bbb1502 100644 |
ca0fe5f5 WB |
15 | --- a/blockdev.c |
16 | +++ b/blockdev.c | |
68a30562 | 17 | @@ -3157,6 +3157,44 @@ void qmp_backup_cancel(Error **errp) |
ca0fe5f5 WB |
18 | } |
19 | } | |
20 | ||
21 | +static int config_to_vma(const char *file, BackupFormat format, | |
22 | + const char *backup_dir, VmaWriter *vmaw, | |
23 | + Error **errp) | |
24 | +{ | |
25 | + char *cdata = NULL; | |
26 | + gsize clen = 0; | |
27 | + GError *err = NULL; | |
28 | + if (!g_file_get_contents(file, &cdata, &clen, &err)) { | |
29 | + error_setg(errp, "unable to read file '%s'", file); | |
30 | + return 1; | |
31 | + } | |
32 | + | |
33 | + char *basename = g_path_get_basename(file); | |
34 | + | |
35 | + if (format == BACKUP_FORMAT_VMA) { | |
36 | + if (vma_writer_add_config(vmaw, basename, cdata, clen) != 0) { | |
37 | + error_setg(errp, "unable to add %s config data to vma archive", file); | |
38 | + g_free(cdata); | |
39 | + g_free(basename); | |
40 | + return 1; | |
41 | + } | |
42 | + } else if (format == BACKUP_FORMAT_DIR) { | |
43 | + char config_path[PATH_MAX]; | |
44 | + snprintf(config_path, PATH_MAX, "%s/%s", backup_dir, basename); | |
45 | + if (!g_file_set_contents(config_path, cdata, clen, &err)) { | |
46 | + error_setg(errp, "unable to write config file '%s'", config_path); | |
47 | + g_free(cdata); | |
48 | + g_free(basename); | |
49 | + return 1; | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + g_free(basename); | |
54 | + g_free(cdata); | |
55 | + | |
56 | + return 0; | |
57 | +} | |
58 | + | |
68a30562 | 59 | bool block_job_should_pause(BlockJob *job); |
ca0fe5f5 WB |
60 | static void pvebackup_run_next_job(void) |
61 | { | |
68a30562 | 62 | @@ -3184,6 +3222,7 @@ static void pvebackup_run_next_job(void) |
ca0fe5f5 WB |
63 | UuidInfo *qmp_backup(const char *backup_file, bool has_format, |
64 | BackupFormat format, | |
65 | bool has_config_file, const char *config_file, | |
66 | + bool has_firewall_file, const char *firewall_file, | |
67 | bool has_devlist, const char *devlist, | |
68 | bool has_speed, int64_t speed, Error **errp) | |
69 | { | |
68a30562 | 70 | @@ -3335,38 +3374,17 @@ UuidInfo *qmp_backup(const char *backup_file, bool has_format, |
ca0fe5f5 WB |
71 | |
72 | /* add configuration file to archive */ | |
73 | if (has_config_file) { | |
74 | - char *cdata = NULL; | |
75 | - gsize clen = 0; | |
76 | - GError *err = NULL; | |
77 | - if (!g_file_get_contents(config_file, &cdata, &clen, &err)) { | |
78 | - error_setg(errp, "unable to read file '%s'", config_file); | |
79 | - goto err; | |
80 | - } | |
81 | - | |
82 | - char *basename = g_path_get_basename(config_file); | |
83 | - | |
84 | - if (format == BACKUP_FORMAT_VMA) { | |
85 | - if (vma_writer_add_config(vmaw, basename, cdata, clen) != 0) { | |
86 | - error_setg(errp, "unable to add config data to vma archive"); | |
87 | - g_free(cdata); | |
88 | - g_free(basename); | |
89 | - goto err; | |
90 | - } | |
91 | - } else if (format == BACKUP_FORMAT_DIR) { | |
92 | - char config_path[PATH_MAX]; | |
93 | - snprintf(config_path, PATH_MAX, "%s/%s", backup_dir, basename); | |
94 | - if (!g_file_set_contents(config_path, cdata, clen, &err)) { | |
95 | - error_setg(errp, "unable to write config file '%s'", config_path); | |
96 | - g_free(cdata); | |
97 | - g_free(basename); | |
98 | - goto err; | |
99 | - } | |
100 | - } | |
101 | - | |
102 | - g_free(basename); | |
103 | - g_free(cdata); | |
104 | + if(config_to_vma(config_file, format, backup_dir, vmaw, errp) != 0) { | |
105 | + goto err; | |
106 | + } | |
107 | } | |
108 | ||
109 | + /* add firewall file to archive */ | |
110 | + if (has_firewall_file) { | |
111 | + if(config_to_vma(firewall_file, format, backup_dir, vmaw, errp) != 0) { | |
112 | + goto err; | |
113 | + } | |
114 | + } | |
115 | /* initialize global backup_state now */ | |
116 | ||
117 | backup_state.cancel = false; | |
118 | diff --git a/hmp.c b/hmp.c | |
68a30562 | 119 | index 7bd319f..6c6a0ac 100644 |
ca0fe5f5 WB |
120 | --- a/hmp.c |
121 | +++ b/hmp.c | |
68a30562 | 122 | @@ -1549,7 +1549,7 @@ void hmp_backup(Monitor *mon, const QDict *qdict) |
ca0fe5f5 WB |
123 | int64_t speed = qdict_get_try_int(qdict, "speed", 0); |
124 | ||
125 | qmp_backup(backup_file, true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA, | |
126 | - false, NULL, !!devlist, | |
127 | + false, NULL, false, NULL, !!devlist, | |
128 | devlist, qdict_haskey(qdict, "speed"), speed, &error); | |
129 | ||
130 | hmp_handle_error(mon, &error); | |
131 | diff --git a/qapi-schema.json b/qapi-schema.json | |
68a30562 | 132 | index d75e932..7bb0ee0 100644 |
ca0fe5f5 WB |
133 | --- a/qapi-schema.json |
134 | +++ b/qapi-schema.json | |
6fb04df7 | 135 | @@ -420,6 +420,7 @@ |
ca0fe5f5 WB |
136 | { 'command': 'backup', 'data': { 'backup-file': 'str', |
137 | '*format': 'BackupFormat', | |
138 | '*config-file': 'str', | |
139 | + '*firewall-file': 'str', | |
140 | '*devlist': 'str', '*speed': 'int' }, | |
141 | 'returns': 'UuidInfo' } | |
142 | ||
143 | diff --git a/qmp-commands.hx b/qmp-commands.hx | |
68a30562 | 144 | index a84932a..94cfac2 100644 |
ca0fe5f5 WB |
145 | --- a/qmp-commands.hx |
146 | +++ b/qmp-commands.hx | |
68a30562 | 147 | @@ -1315,7 +1315,7 @@ EQMP |
ca0fe5f5 WB |
148 | |
149 | { | |
150 | .name = "backup", | |
151 | - .args_type = "backup-file:s,format:s?,config-file:F?,speed:o?,devlist:s?", | |
152 | + .args_type = "backup-file:s,format:s?,config-file:F?,firewall-file:F?,speed:o?,devlist:s?", | |
68a30562 | 153 | .mhandler.cmd_new = qmp_marshal_backup, |
ca0fe5f5 WB |
154 | }, |
155 | ||
156 | -- | |
157 | 2.1.4 | |
158 |