]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0030-PVE-Backup-Proxmox-backup-patches-for-QEMU.patch
drop patch for custom get_link_status QMP command
[pve-qemu.git] / debian / patches / pve / 0030-PVE-Backup-Proxmox-backup-patches-for-QEMU.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Dietmar Maurer <dietmar@proxmox.com>
3 Date: Mon, 6 Apr 2020 12:16:59 +0200
4 Subject: [PATCH] PVE-Backup: Proxmox backup patches for QEMU
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 For PBS, using dirty bitmaps is supported via QEMU's
10 MIRROR_SYNC_MODE_BITMAP. When the feature is used, the data-write
11 callback is only executed for any changed chunks, the PBS rust code
12 will reuse chunks from the previous index for everything it doesn't
13 receive if reuse_index is true. On error or cancellation, all dirty
14 bitmaps are removed to ensure consistency.
15
16 By using a JobTxn, we can sync dirty bitmaps only when *all* jobs were
17 successful - meaning we don't need to remove them when the backup
18 fails, since QEMU's BITMAP_SYNC_MODE_ON_SUCCESS will now handle that
19 for us. A sequential transaction is used, so drives will be backed up
20 one after the other.
21
22 The backup and backup-cancel QMP calls are coroutines. This has the
23 benefit that calls are asynchronous to the main loop, i.e. long
24 running operations like connecting to a PBS server will no longer hang
25 the VM.
26
27 backup_job_create() and job_cancel_sync() cannot be run from a
28 coroutine and requires an acuqired AioContext, so the job creation and
29 canceling are extracted as bottom halves and called from the
30 respective QMP coroutines.
31
32 To communicate the finishing state, a dedicated property is used for
33 query-backup: 'finishing'. A dedicated state is explicitly not used,
34 since that would break compatibility with older qemu-server versions.
35
36 The first call to job_cancel_sync() will cancel and free all jobs in
37 the transaction, but it is necessary to pick a job that is:
38 1. still referenced. For this, there is a job_ref directly after job
39 creation paired with a job_unref in cleanup paths.
40 2. not yet finalized. In job_cancel_bh(), the first job that's not
41 completed yet is used. This is not necessarily the first job in the
42 list, because pvebackup_co_complete_stream() might not yet have
43 removed a completed job when job_cancel_bh() runs. Why even bother
44 with the bottom half at all and not use job_cancel() in
45 qmp_backup_cancel() directly? The reason is that qmp_backup_cancel()
46 is a coroutine, so it will hang when reaching AIO_WAIT_WHILE() and
47 job_cancel() might end up calling that.
48
49 Regarding BackupPerf performance settings. For now, only the
50 max-workers setting is exposed, because:
51 1. use-copy-range would need to be implemented in backup-dump and the
52 feature was actually turned off by default in QEMU itself, because it
53 didn't provide the expected benefit, see commit 6a30f663d4 ("qapi:
54 backup: disable copy_range by default").
55 2. max-chunk: enforced to be at least the backup cluster size (4 MiB
56 for PBS) and otherwise maximum of source and target cluster size.
57 And block-copy has a maximum buffer size of 1 MiB, so setting a larger
58 max-chunk doesn't even have an effect. To make the setting sensibly
59 usable the check would need to be removed and optionally the
60 block-copy max buffer size would need to be bumped. I tried doing just
61 that, and tested different source/target combinations with different
62 max-chunk settings, but there were no noticable improvements over the
63 default "unlimited" (resulting in 1 MiB for block-copy).
64
65 Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
66 [SR: Add dirty-bitmap tracking for incremental backups
67 Add query_proxmox_support and query-pbs-bitmap-info QMP calls
68 Use a transaction to synchronize job states
69 Co-routine and async-related improvements
70 Improve finishing backups/cleanups
71 Various other improvements]
72 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
73 [FG: add master key support]
74 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
75 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
76 [WB: add PBS namespace support]
77 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
78 [FE: add new force parameter to job_cancel_sync calls
79 adapt for new job lock mechanism replacing AioContext locks
80 adapt to QAPI changes
81 improve canceling
82 allow passing max-workers setting]
83 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
84 ---
85 block/meson.build | 5 +
86 block/monitor/block-hmp-cmds.c | 40 ++
87 blockdev.c | 1 +
88 hmp-commands-info.hx | 14 +
89 hmp-commands.hx | 31 +
90 include/monitor/hmp.h | 3 +
91 meson.build | 1 +
92 monitor/hmp-cmds.c | 72 +++
93 proxmox-backup-client.c | 146 +++++
94 proxmox-backup-client.h | 60 ++
95 pve-backup.c | 1097 ++++++++++++++++++++++++++++++++
96 qapi/block-core.json | 226 +++++++
97 qapi/common.json | 13 +
98 qapi/machine.json | 15 +-
99 14 files changed, 1711 insertions(+), 13 deletions(-)
100 create mode 100644 proxmox-backup-client.c
101 create mode 100644 proxmox-backup-client.h
102 create mode 100644 pve-backup.c
103
104 diff --git a/block/meson.build b/block/meson.build
105 index f580f95395..5bcebb934b 100644
106 --- a/block/meson.build
107 +++ b/block/meson.build
108 @@ -49,6 +49,11 @@ block_ss.add(files(
109 ), zstd, zlib, gnutls)
110
111 block_ss.add(files('../vma-writer.c'), libuuid)
112 +block_ss.add(files(
113 + '../proxmox-backup-client.c',
114 + '../pve-backup.c',
115 +), libproxmox_backup_qemu)
116 +
117
118 softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c'))
119 softmmu_ss.add(files('block-ram-registrar.c'))
120 diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
121 index ca2599de44..636509b83e 100644
122 --- a/block/monitor/block-hmp-cmds.c
123 +++ b/block/monitor/block-hmp-cmds.c
124 @@ -1029,3 +1029,43 @@ void hmp_change_medium(Monitor *mon, const char *device, const char *target,
125 qmp_blockdev_change_medium(device, NULL, target, arg, true, force,
126 !!read_only, read_only_mode, errp);
127 }
128 +
129 +void coroutine_fn hmp_backup_cancel(Monitor *mon, const QDict *qdict)
130 +{
131 + Error *error = NULL;
132 +
133 + qmp_backup_cancel(&error);
134 +
135 + hmp_handle_error(mon, error);
136 +}
137 +
138 +void coroutine_fn hmp_backup(Monitor *mon, const QDict *qdict)
139 +{
140 + Error *error = NULL;
141 +
142 + int dir = qdict_get_try_bool(qdict, "directory", 0);
143 + const char *backup_file = qdict_get_str(qdict, "backupfile");
144 + const char *devlist = qdict_get_try_str(qdict, "devlist");
145 + int64_t speed = qdict_get_try_int(qdict, "speed", 0);
146 +
147 + qmp_backup(
148 + backup_file,
149 + NULL, // PBS password
150 + NULL, // PBS keyfile
151 + NULL, // PBS key_password
152 + NULL, // PBS master_keyfile
153 + NULL, // PBS fingerprint
154 + NULL, // PBS backup-ns
155 + NULL, // PBS backup-id
156 + false, 0, // PBS backup-time
157 + false, false, // PBS use-dirty-bitmap
158 + false, false, // PBS compress
159 + false, false, // PBS encrypt
160 + true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
161 + NULL, NULL,
162 + devlist, qdict_haskey(qdict, "speed"), speed,
163 + false, 0, // BackupPerf max-workers
164 + &error);
165 +
166 + hmp_handle_error(mon, error);
167 +}
168 diff --git a/blockdev.c b/blockdev.c
169 index 9a010f3a86..b9505c95d3 100644
170 --- a/blockdev.c
171 +++ b/blockdev.c
172 @@ -37,6 +37,7 @@
173 #include "block/blockjob.h"
174 #include "block/dirty-bitmap.h"
175 #include "block/qdict.h"
176 +#include "block/blockjob_int.h"
177 #include "block/throttle-groups.h"
178 #include "monitor/monitor.h"
179 #include "qemu/error-report.h"
180 diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
181 index a166bff3d5..4b75966c2e 100644
182 --- a/hmp-commands-info.hx
183 +++ b/hmp-commands-info.hx
184 @@ -486,6 +486,20 @@ SRST
185 Show the current VM UUID.
186 ERST
187
188 +
189 + {
190 + .name = "backup",
191 + .args_type = "",
192 + .params = "",
193 + .help = "show backup status",
194 + .cmd = hmp_info_backup,
195 + },
196 +
197 +SRST
198 + ``info backup``
199 + Show backup status.
200 +ERST
201 +
202 #if defined(CONFIG_SLIRP)
203 {
204 .name = "usernet",
205 diff --git a/hmp-commands.hx b/hmp-commands.hx
206 index b66d7fc4ab..896430dae8 100644
207 --- a/hmp-commands.hx
208 +++ b/hmp-commands.hx
209 @@ -101,6 +101,37 @@ ERST
210 SRST
211 ``block_stream``
212 Copy data from a backing file into a block device.
213 +ERST
214 +
215 + {
216 + .name = "backup",
217 + .args_type = "directory:-d,backupfile:s,speed:o?,devlist:s?",
218 + .params = "[-d] backupfile [speed [devlist]]",
219 + .help = "create a VM Backup."
220 + "\n\t\t\t Use -d to dump data into a directory instead"
221 + "\n\t\t\t of using VMA format.",
222 + .cmd = hmp_backup,
223 + .coroutine = true,
224 + },
225 +
226 +SRST
227 +``backup``
228 + Create a VM backup.
229 +ERST
230 +
231 + {
232 + .name = "backup_cancel",
233 + .args_type = "",
234 + .params = "",
235 + .help = "cancel the current VM backup",
236 + .cmd = hmp_backup_cancel,
237 + .coroutine = true,
238 + },
239 +
240 +SRST
241 +``backup_cancel``
242 + Cancel the current VM backup.
243 +
244 ERST
245
246 {
247 diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
248 index c012bad741..2e504db706 100644
249 --- a/include/monitor/hmp.h
250 +++ b/include/monitor/hmp.h
251 @@ -32,6 +32,7 @@ void hmp_info_savevm(Monitor *mon, const QDict *qdict);
252 void hmp_info_migrate(Monitor *mon, const QDict *qdict);
253 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict);
254 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict);
255 +void hmp_info_backup(Monitor *mon, const QDict *qdict);
256 void hmp_info_cpus(Monitor *mon, const QDict *qdict);
257 void hmp_info_vnc(Monitor *mon, const QDict *qdict);
258 void hmp_info_spice(Monitor *mon, const QDict *qdict);
259 @@ -84,6 +85,8 @@ void hmp_change_vnc(Monitor *mon, const char *device, const char *target,
260 void hmp_change_medium(Monitor *mon, const char *device, const char *target,
261 const char *arg, const char *read_only, bool force,
262 Error **errp);
263 +void hmp_backup(Monitor *mon, const QDict *qdict);
264 +void hmp_backup_cancel(Monitor *mon, const QDict *qdict);
265 void hmp_migrate(Monitor *mon, const QDict *qdict);
266 void hmp_device_add(Monitor *mon, const QDict *qdict);
267 void hmp_device_del(Monitor *mon, const QDict *qdict);
268 diff --git a/meson.build b/meson.build
269 index 603cdb97bb..d307d8eabf 100644
270 --- a/meson.build
271 +++ b/meson.build
272 @@ -1528,6 +1528,7 @@ keyutils = dependency('libkeyutils', required: false,
273 has_gettid = cc.has_function('gettid')
274
275 libuuid = cc.find_library('uuid', required: true)
276 +libproxmox_backup_qemu = cc.find_library('proxmox_backup_qemu', required: true)
277
278 # libselinux
279 selinux = dependency('libselinux',
280 diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
281 index 435f9334f9..9a67e544ce 100644
282 --- a/monitor/hmp-cmds.c
283 +++ b/monitor/hmp-cmds.c
284 @@ -21,6 +21,7 @@
285 #include "qemu/help_option.h"
286 #include "monitor/monitor-internal.h"
287 #include "qapi/error.h"
288 +#include "qapi/qapi-commands-block-core.h"
289 #include "qapi/qapi-commands-control.h"
290 #include "qapi/qapi-commands-migration.h"
291 #include "qapi/qapi-commands-misc.h"
292 @@ -144,6 +145,77 @@ void hmp_sync_profile(Monitor *mon, const QDict *qdict)
293 }
294 }
295
296 +void hmp_info_backup(Monitor *mon, const QDict *qdict)
297 +{
298 + BackupStatus *info;
299 + PBSBitmapInfoList *bitmap_info;
300 +
301 + info = qmp_query_backup(NULL);
302 +
303 + if (!info) {
304 + monitor_printf(mon, "Backup status: not initialized\n");
305 + return;
306 + }
307 +
308 + if (info->status) {
309 + if (info->errmsg) {
310 + monitor_printf(mon, "Backup status: %s - %s\n",
311 + info->status, info->errmsg);
312 + } else {
313 + monitor_printf(mon, "Backup status: %s\n", info->status);
314 + }
315 + }
316 +
317 + if (info->backup_file) {
318 + monitor_printf(mon, "Start time: %s", ctime(&info->start_time));
319 + if (info->end_time) {
320 + monitor_printf(mon, "End time: %s", ctime(&info->end_time));
321 + }
322 +
323 + monitor_printf(mon, "Backup file: %s\n", info->backup_file);
324 + monitor_printf(mon, "Backup uuid: %s\n", info->uuid);
325 +
326 + if (!(info->has_total && info->total)) {
327 + // this should not happen normally
328 + monitor_printf(mon, "Total size: %d\n", 0);
329 + } else {
330 + size_t total_or_dirty = info->total;
331 + bitmap_info = qmp_query_pbs_bitmap_info(NULL);
332 +
333 + while (bitmap_info) {
334 + monitor_printf(mon, "Drive %s:\n",
335 + bitmap_info->value->drive);
336 + monitor_printf(mon, " bitmap action: %s\n",
337 + PBSBitmapAction_str(bitmap_info->value->action));
338 + monitor_printf(mon, " size: %zd\n",
339 + bitmap_info->value->size);
340 + monitor_printf(mon, " dirty: %zd\n",
341 + bitmap_info->value->dirty);
342 + bitmap_info = bitmap_info->next;
343 + }
344 +
345 + qapi_free_PBSBitmapInfoList(bitmap_info);
346 +
347 + int zero_per = (info->has_zero_bytes && info->zero_bytes) ?
348 + (info->zero_bytes * 100)/info->total : 0;
349 + monitor_printf(mon, "Total size: %zd\n", info->total);
350 + int trans_per = (info->transferred * 100)/total_or_dirty;
351 + monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
352 + info->transferred, trans_per);
353 + monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
354 + info->zero_bytes, zero_per);
355 +
356 + if (info->has_reused) {
357 + int reused_per = (info->reused * 100)/total_or_dirty;
358 + monitor_printf(mon, "Reused bytes: %zd (%d%%)\n",
359 + info->reused, reused_per);
360 + }
361 + }
362 + }
363 +
364 + qapi_free_BackupStatus(info);
365 +}
366 +
367 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
368 {
369 Error *err = NULL;
370 diff --git a/proxmox-backup-client.c b/proxmox-backup-client.c
371 new file mode 100644
372 index 0000000000..0923037dec
373 --- /dev/null
374 +++ b/proxmox-backup-client.c
375 @@ -0,0 +1,146 @@
376 +#include "proxmox-backup-client.h"
377 +#include "qemu/main-loop.h"
378 +#include "block/aio-wait.h"
379 +#include "qapi/error.h"
380 +
381 +/* Proxmox Backup Server client bindings using coroutines */
382 +
383 +// This is called from another thread, so we use aio_co_schedule()
384 +static void proxmox_backup_schedule_wake(void *data) {
385 + CoCtxData *waker = (CoCtxData *)data;
386 + aio_co_schedule(waker->ctx, waker->co);
387 +}
388 +
389 +int coroutine_fn
390 +proxmox_backup_co_connect(ProxmoxBackupHandle *pbs, Error **errp)
391 +{
392 + Coroutine *co = qemu_coroutine_self();
393 + AioContext *ctx = qemu_get_current_aio_context();
394 + CoCtxData waker = { .co = co, .ctx = ctx };
395 + char *pbs_err = NULL;
396 + int pbs_res = -1;
397 +
398 + proxmox_backup_connect_async(pbs, proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
399 + qemu_coroutine_yield();
400 + if (pbs_res < 0) {
401 + if (errp) error_setg(errp, "backup connect failed: %s", pbs_err ? pbs_err : "unknown error");
402 + if (pbs_err) proxmox_backup_free_error(pbs_err);
403 + }
404 + return pbs_res;
405 +}
406 +
407 +int coroutine_fn
408 +proxmox_backup_co_add_config(
409 + ProxmoxBackupHandle *pbs,
410 + const char *name,
411 + const uint8_t *data,
412 + uint64_t size,
413 + Error **errp)
414 +{
415 + Coroutine *co = qemu_coroutine_self();
416 + AioContext *ctx = qemu_get_current_aio_context();
417 + CoCtxData waker = { .co = co, .ctx = ctx };
418 + char *pbs_err = NULL;
419 + int pbs_res = -1;
420 +
421 + proxmox_backup_add_config_async(
422 + pbs, name, data, size ,proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
423 + qemu_coroutine_yield();
424 + if (pbs_res < 0) {
425 + if (errp) error_setg(errp, "backup add_config %s failed: %s", name, pbs_err ? pbs_err : "unknown error");
426 + if (pbs_err) proxmox_backup_free_error(pbs_err);
427 + }
428 + return pbs_res;
429 +}
430 +
431 +int coroutine_fn
432 +proxmox_backup_co_register_image(
433 + ProxmoxBackupHandle *pbs,
434 + const char *device_name,
435 + uint64_t size,
436 + bool incremental,
437 + Error **errp)
438 +{
439 + Coroutine *co = qemu_coroutine_self();
440 + AioContext *ctx = qemu_get_current_aio_context();
441 + CoCtxData waker = { .co = co, .ctx = ctx };
442 + char *pbs_err = NULL;
443 + int pbs_res = -1;
444 +
445 + proxmox_backup_register_image_async(
446 + pbs, device_name, size, incremental, proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
447 + qemu_coroutine_yield();
448 + if (pbs_res < 0) {
449 + if (errp) error_setg(errp, "backup register image failed: %s", pbs_err ? pbs_err : "unknown error");
450 + if (pbs_err) proxmox_backup_free_error(pbs_err);
451 + }
452 + return pbs_res;
453 +}
454 +
455 +int coroutine_fn
456 +proxmox_backup_co_finish(
457 + ProxmoxBackupHandle *pbs,
458 + Error **errp)
459 +{
460 + Coroutine *co = qemu_coroutine_self();
461 + AioContext *ctx = qemu_get_current_aio_context();
462 + CoCtxData waker = { .co = co, .ctx = ctx };
463 + char *pbs_err = NULL;
464 + int pbs_res = -1;
465 +
466 + proxmox_backup_finish_async(
467 + pbs, proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
468 + qemu_coroutine_yield();
469 + if (pbs_res < 0) {
470 + if (errp) error_setg(errp, "backup finish failed: %s", pbs_err ? pbs_err : "unknown error");
471 + if (pbs_err) proxmox_backup_free_error(pbs_err);
472 + }
473 + return pbs_res;
474 +}
475 +
476 +int coroutine_fn
477 +proxmox_backup_co_close_image(
478 + ProxmoxBackupHandle *pbs,
479 + uint8_t dev_id,
480 + Error **errp)
481 +{
482 + Coroutine *co = qemu_coroutine_self();
483 + AioContext *ctx = qemu_get_current_aio_context();
484 + CoCtxData waker = { .co = co, .ctx = ctx };
485 + char *pbs_err = NULL;
486 + int pbs_res = -1;
487 +
488 + proxmox_backup_close_image_async(
489 + pbs, dev_id, proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
490 + qemu_coroutine_yield();
491 + if (pbs_res < 0) {
492 + if (errp) error_setg(errp, "backup close image failed: %s", pbs_err ? pbs_err : "unknown error");
493 + if (pbs_err) proxmox_backup_free_error(pbs_err);
494 + }
495 + return pbs_res;
496 +}
497 +
498 +int coroutine_fn
499 +proxmox_backup_co_write_data(
500 + ProxmoxBackupHandle *pbs,
501 + uint8_t dev_id,
502 + const uint8_t *data,
503 + uint64_t offset,
504 + uint64_t size,
505 + Error **errp)
506 +{
507 + Coroutine *co = qemu_coroutine_self();
508 + AioContext *ctx = qemu_get_current_aio_context();
509 + CoCtxData waker = { .co = co, .ctx = ctx };
510 + char *pbs_err = NULL;
511 + int pbs_res = -1;
512 +
513 + proxmox_backup_write_data_async(
514 + pbs, dev_id, data, offset, size, proxmox_backup_schedule_wake, &waker, &pbs_res, &pbs_err);
515 + qemu_coroutine_yield();
516 + if (pbs_res < 0) {
517 + if (errp) error_setg(errp, "backup write data failed: %s", pbs_err ? pbs_err : "unknown error");
518 + if (pbs_err) proxmox_backup_free_error(pbs_err);
519 + }
520 + return pbs_res;
521 +}
522 diff --git a/proxmox-backup-client.h b/proxmox-backup-client.h
523 new file mode 100644
524 index 0000000000..8cbf645b2c
525 --- /dev/null
526 +++ b/proxmox-backup-client.h
527 @@ -0,0 +1,60 @@
528 +#ifndef PROXMOX_BACKUP_CLIENT_H
529 +#define PROXMOX_BACKUP_CLIENT_H
530 +
531 +#include "qemu/osdep.h"
532 +#include "qemu/coroutine.h"
533 +#include "proxmox-backup-qemu.h"
534 +
535 +typedef struct CoCtxData {
536 + Coroutine *co;
537 + AioContext *ctx;
538 + void *data;
539 +} CoCtxData;
540 +
541 +// FIXME: Remove once coroutines are supported for QMP
542 +void block_on_coroutine_fn(CoroutineEntry *entry, void *entry_arg);
543 +
544 +int coroutine_fn
545 +proxmox_backup_co_connect(
546 + ProxmoxBackupHandle *pbs,
547 + Error **errp);
548 +
549 +int coroutine_fn
550 +proxmox_backup_co_add_config(
551 + ProxmoxBackupHandle *pbs,
552 + const char *name,
553 + const uint8_t *data,
554 + uint64_t size,
555 + Error **errp);
556 +
557 +int coroutine_fn
558 +proxmox_backup_co_register_image(
559 + ProxmoxBackupHandle *pbs,
560 + const char *device_name,
561 + uint64_t size,
562 + bool incremental,
563 + Error **errp);
564 +
565 +
566 +int coroutine_fn
567 +proxmox_backup_co_finish(
568 + ProxmoxBackupHandle *pbs,
569 + Error **errp);
570 +
571 +int coroutine_fn
572 +proxmox_backup_co_close_image(
573 + ProxmoxBackupHandle *pbs,
574 + uint8_t dev_id,
575 + Error **errp);
576 +
577 +int coroutine_fn
578 +proxmox_backup_co_write_data(
579 + ProxmoxBackupHandle *pbs,
580 + uint8_t dev_id,
581 + const uint8_t *data,
582 + uint64_t offset,
583 + uint64_t size,
584 + Error **errp);
585 +
586 +
587 +#endif /* PROXMOX_BACKUP_CLIENT_H */
588 diff --git a/pve-backup.c b/pve-backup.c
589 new file mode 100644
590 index 0000000000..dd72ee0ed6
591 --- /dev/null
592 +++ b/pve-backup.c
593 @@ -0,0 +1,1097 @@
594 +#include "proxmox-backup-client.h"
595 +#include "vma.h"
596 +
597 +#include "qemu/osdep.h"
598 +#include "qemu/module.h"
599 +#include "sysemu/block-backend.h"
600 +#include "sysemu/blockdev.h"
601 +#include "block/block_int-global-state.h"
602 +#include "block/blockjob.h"
603 +#include "block/dirty-bitmap.h"
604 +#include "qapi/qapi-commands-block.h"
605 +#include "qapi/qmp/qerror.h"
606 +#include "qemu/cutils.h"
607 +
608 +#include <proxmox-backup-qemu.h>
609 +
610 +/* PVE backup state and related function */
611 +
612 +/*
613 + * Note: A resume from a qemu_coroutine_yield can happen in a different thread,
614 + * so you may not use normal mutexes within coroutines:
615 + *
616 + * ---bad-example---
617 + * qemu_rec_mutex_lock(lock)
618 + * ...
619 + * qemu_coroutine_yield() // wait for something
620 + * // we are now inside a different thread
621 + * qemu_rec_mutex_unlock(lock) // Crash - wrong thread!!
622 + * ---end-bad-example--
623 + *
624 + * ==> Always use CoMutext inside coroutines.
625 + * ==> Never acquire/release AioContext withing coroutines (because that use QemuRecMutex)
626 + *
627 + */
628 +
629 +const char *PBS_BITMAP_NAME = "pbs-incremental-dirty-bitmap";
630 +
631 +static struct PVEBackupState {
632 + struct {
633 + // Everything accessed from qmp_backup_query command is protected using
634 + // this lock. Do NOT hold this lock for long times, as it is sometimes
635 + // acquired from coroutines, and thus any wait time may block the guest.
636 + QemuMutex lock;
637 + Error *error;
638 + time_t start_time;
639 + time_t end_time;
640 + char *backup_file;
641 + uuid_t uuid;
642 + char uuid_str[37];
643 + size_t total;
644 + size_t dirty;
645 + size_t transferred;
646 + size_t reused;
647 + size_t zero_bytes;
648 + GList *bitmap_list;
649 + bool finishing;
650 + bool starting;
651 + } stat;
652 + int64_t speed;
653 + BackupPerf perf;
654 + VmaWriter *vmaw;
655 + ProxmoxBackupHandle *pbs;
656 + GList *di_list;
657 + JobTxn *txn;
658 + CoMutex backup_mutex;
659 + CoMutex dump_callback_mutex;
660 +} backup_state;
661 +
662 +static void pvebackup_init(void)
663 +{
664 + qemu_mutex_init(&backup_state.stat.lock);
665 + qemu_co_mutex_init(&backup_state.backup_mutex);
666 + qemu_co_mutex_init(&backup_state.dump_callback_mutex);
667 +}
668 +
669 +// initialize PVEBackupState at startup
670 +opts_init(pvebackup_init);
671 +
672 +typedef struct PVEBackupDevInfo {
673 + BlockDriverState *bs;
674 + size_t size;
675 + uint64_t block_size;
676 + uint8_t dev_id;
677 + int completed_ret; // INT_MAX if not completed
678 + char targetfile[PATH_MAX];
679 + BdrvDirtyBitmap *bitmap;
680 + BlockDriverState *target;
681 + BlockJob *job;
682 +} PVEBackupDevInfo;
683 +
684 +static void pvebackup_propagate_error(Error *err)
685 +{
686 + qemu_mutex_lock(&backup_state.stat.lock);
687 + error_propagate(&backup_state.stat.error, err);
688 + qemu_mutex_unlock(&backup_state.stat.lock);
689 +}
690 +
691 +static bool pvebackup_error_or_canceled(void)
692 +{
693 + qemu_mutex_lock(&backup_state.stat.lock);
694 + bool error_or_canceled = !!backup_state.stat.error;
695 + qemu_mutex_unlock(&backup_state.stat.lock);
696 +
697 + return error_or_canceled;
698 +}
699 +
700 +static void pvebackup_add_transfered_bytes(size_t transferred, size_t zero_bytes, size_t reused)
701 +{
702 + qemu_mutex_lock(&backup_state.stat.lock);
703 + backup_state.stat.zero_bytes += zero_bytes;
704 + backup_state.stat.transferred += transferred;
705 + backup_state.stat.reused += reused;
706 + qemu_mutex_unlock(&backup_state.stat.lock);
707 +}
708 +
709 +// This may get called from multiple coroutines in multiple io-threads
710 +// Note1: this may get called after job_cancel()
711 +static int coroutine_fn
712 +pvebackup_co_dump_pbs_cb(
713 + void *opaque,
714 + uint64_t start,
715 + uint64_t bytes,
716 + const void *pbuf)
717 +{
718 + assert(qemu_in_coroutine());
719 +
720 + const uint64_t size = bytes;
721 + const unsigned char *buf = pbuf;
722 + PVEBackupDevInfo *di = opaque;
723 +
724 + assert(backup_state.pbs);
725 + assert(buf);
726 +
727 + Error *local_err = NULL;
728 + int pbs_res = -1;
729 +
730 + bool is_zero_block = size == di->block_size && buffer_is_zero(buf, size);
731 +
732 + qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
733 +
734 + // avoid deadlock if job is cancelled
735 + if (pvebackup_error_or_canceled()) {
736 + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
737 + return -1;
738 + }
739 +
740 + uint64_t transferred = 0;
741 + uint64_t reused = 0;
742 + while (transferred < size) {
743 + uint64_t left = size - transferred;
744 + uint64_t to_transfer = left < di->block_size ? left : di->block_size;
745 +
746 + pbs_res = proxmox_backup_co_write_data(backup_state.pbs, di->dev_id,
747 + is_zero_block ? NULL : buf + transferred, start + transferred,
748 + to_transfer, &local_err);
749 + transferred += to_transfer;
750 +
751 + if (pbs_res < 0) {
752 + pvebackup_propagate_error(local_err);
753 + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
754 + return pbs_res;
755 + }
756 +
757 + reused += pbs_res == 0 ? to_transfer : 0;
758 + }
759 +
760 + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
761 + pvebackup_add_transfered_bytes(size, is_zero_block ? size : 0, reused);
762 +
763 + return size;
764 +}
765 +
766 +// This may get called from multiple coroutines in multiple io-threads
767 +static int coroutine_fn
768 +pvebackup_co_dump_vma_cb(
769 + void *opaque,
770 + uint64_t start,
771 + uint64_t bytes,
772 + const void *pbuf)
773 +{
774 + assert(qemu_in_coroutine());
775 +
776 + const uint64_t size = bytes;
777 + const unsigned char *buf = pbuf;
778 + PVEBackupDevInfo *di = opaque;
779 +
780 + int ret = -1;
781 +
782 + assert(backup_state.vmaw);
783 + assert(buf);
784 +
785 + uint64_t remaining = size;
786 +
787 + uint64_t cluster_num = start / VMA_CLUSTER_SIZE;
788 + if ((cluster_num * VMA_CLUSTER_SIZE) != start) {
789 + Error *local_err = NULL;
790 + error_setg(&local_err,
791 + "got unaligned write inside backup dump "
792 + "callback (sector %ld)", start);
793 + pvebackup_propagate_error(local_err);
794 + return -1; // not aligned to cluster size
795 + }
796 +
797 + while (remaining > 0) {
798 + qemu_co_mutex_lock(&backup_state.dump_callback_mutex);
799 + // avoid deadlock if job is cancelled
800 + if (pvebackup_error_or_canceled()) {
801 + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
802 + return -1;
803 + }
804 +
805 + size_t zero_bytes = 0;
806 + ret = vma_writer_write(backup_state.vmaw, di->dev_id, cluster_num, buf, &zero_bytes);
807 + qemu_co_mutex_unlock(&backup_state.dump_callback_mutex);
808 +
809 + ++cluster_num;
810 + buf += VMA_CLUSTER_SIZE;
811 + if (ret < 0) {
812 + Error *local_err = NULL;
813 + vma_writer_error_propagate(backup_state.vmaw, &local_err);
814 + pvebackup_propagate_error(local_err);
815 + return ret;
816 + } else {
817 + if (remaining >= VMA_CLUSTER_SIZE) {
818 + assert(ret == VMA_CLUSTER_SIZE);
819 + pvebackup_add_transfered_bytes(VMA_CLUSTER_SIZE, zero_bytes, 0);
820 + remaining -= VMA_CLUSTER_SIZE;
821 + } else {
822 + assert(ret == remaining);
823 + pvebackup_add_transfered_bytes(remaining, zero_bytes, 0);
824 + remaining = 0;
825 + }
826 + }
827 + }
828 +
829 + return size;
830 +}
831 +
832 +// assumes the caller holds backup_mutex
833 +static void coroutine_fn pvebackup_co_cleanup(void)
834 +{
835 + assert(qemu_in_coroutine());
836 +
837 + qemu_mutex_lock(&backup_state.stat.lock);
838 + backup_state.stat.finishing = true;
839 + qemu_mutex_unlock(&backup_state.stat.lock);
840 +
841 + if (backup_state.vmaw) {
842 + Error *local_err = NULL;
843 + vma_writer_close(backup_state.vmaw, &local_err);
844 +
845 + if (local_err != NULL) {
846 + pvebackup_propagate_error(local_err);
847 + }
848 +
849 + backup_state.vmaw = NULL;
850 + }
851 +
852 + if (backup_state.pbs) {
853 + if (!pvebackup_error_or_canceled()) {
854 + Error *local_err = NULL;
855 + proxmox_backup_co_finish(backup_state.pbs, &local_err);
856 + if (local_err != NULL) {
857 + pvebackup_propagate_error(local_err);
858 + }
859 + }
860 +
861 + proxmox_backup_disconnect(backup_state.pbs);
862 + backup_state.pbs = NULL;
863 + }
864 +
865 + g_list_free(backup_state.di_list);
866 + backup_state.di_list = NULL;
867 +
868 + qemu_mutex_lock(&backup_state.stat.lock);
869 + backup_state.stat.end_time = time(NULL);
870 + backup_state.stat.finishing = false;
871 + qemu_mutex_unlock(&backup_state.stat.lock);
872 +}
873 +
874 +static void coroutine_fn pvebackup_co_complete_stream(void *opaque)
875 +{
876 + PVEBackupDevInfo *di = opaque;
877 + int ret = di->completed_ret;
878 +
879 + qemu_mutex_lock(&backup_state.stat.lock);
880 + bool starting = backup_state.stat.starting;
881 + qemu_mutex_unlock(&backup_state.stat.lock);
882 + if (starting) {
883 + /* in 'starting' state, no tasks have been run yet, meaning we can (and
884 + * must) skip all cleanup, as we don't know what has and hasn't been
885 + * initialized yet. */
886 + return;
887 + }
888 +
889 + qemu_co_mutex_lock(&backup_state.backup_mutex);
890 +
891 + if (ret < 0) {
892 + Error *local_err = NULL;
893 + error_setg(&local_err, "job failed with err %d - %s", ret, strerror(-ret));
894 + pvebackup_propagate_error(local_err);
895 + }
896 +
897 + di->bs = NULL;
898 +
899 + assert(di->target == NULL);
900 +
901 + bool error_or_canceled = pvebackup_error_or_canceled();
902 +
903 + if (backup_state.vmaw) {
904 + vma_writer_close_stream(backup_state.vmaw, di->dev_id);
905 + }
906 +
907 + if (backup_state.pbs && !error_or_canceled) {
908 + Error *local_err = NULL;
909 + proxmox_backup_co_close_image(backup_state.pbs, di->dev_id, &local_err);
910 + if (local_err != NULL) {
911 + pvebackup_propagate_error(local_err);
912 + }
913 + }
914 +
915 + if (di->job) {
916 + WITH_JOB_LOCK_GUARD() {
917 + job_unref_locked(&di->job->job);
918 + di->job = NULL;
919 + }
920 + }
921 +
922 + // remove self from job list
923 + backup_state.di_list = g_list_remove(backup_state.di_list, di);
924 +
925 + g_free(di);
926 +
927 + /* call cleanup if we're the last job */
928 + if (!g_list_first(backup_state.di_list)) {
929 + pvebackup_co_cleanup();
930 + }
931 +
932 + qemu_co_mutex_unlock(&backup_state.backup_mutex);
933 +}
934 +
935 +static void pvebackup_complete_cb(void *opaque, int ret)
936 +{
937 + PVEBackupDevInfo *di = opaque;
938 + di->completed_ret = ret;
939 +
940 + /*
941 + * Schedule stream cleanup in async coroutine. close_image and finish might
942 + * take a while, so we can't block on them here. This way it also doesn't
943 + * matter if we're already running in a coroutine or not.
944 + * Note: di is a pointer to an entry in the global backup_state struct, so
945 + * it stays valid.
946 + */
947 + Coroutine *co = qemu_coroutine_create(pvebackup_co_complete_stream, di);
948 + aio_co_enter(qemu_get_aio_context(), co);
949 +}
950 +
951 +/*
952 + * job_cancel(_sync) does not like to be called from coroutines, so defer to
953 + * main loop processing via a bottom half. Assumes that caller holds
954 + * backup_mutex.
955 + */
956 +static void job_cancel_bh(void *opaque) {
957 + CoCtxData *data = (CoCtxData*)opaque;
958 +
959 + /*
960 + * Be careful to pick a valid job to cancel:
961 + * 1. job_cancel_sync() does not expect the job to be finalized already.
962 + * 2. job_exit() might run between scheduling and running job_cancel_bh()
963 + * and pvebackup_co_complete_stream() might not have removed the job from
964 + * the list yet (in fact, cannot, because it waits for the backup_mutex).
965 + * Requiring !job_is_completed() ensures that no finalized job is picked.
966 + */
967 + GList *bdi = g_list_first(backup_state.di_list);
968 + while (bdi) {
969 + if (bdi->data) {
970 + BlockJob *bj = ((PVEBackupDevInfo *)bdi->data)->job;
971 + if (bj) {
972 + Job *job = &bj->job;
973 + WITH_JOB_LOCK_GUARD() {
974 + if (!job_is_completed_locked(job)) {
975 + job_cancel_sync_locked(job, true);
976 + /*
977 + * It's enough to cancel one job in the transaction, the
978 + * rest will follow automatically.
979 + */
980 + break;
981 + }
982 + }
983 + }
984 + }
985 + bdi = g_list_next(bdi);
986 + }
987 +
988 + aio_co_enter(data->ctx, data->co);
989 +}
990 +
991 +void coroutine_fn qmp_backup_cancel(Error **errp)
992 +{
993 + Error *cancel_err = NULL;
994 + error_setg(&cancel_err, "backup canceled");
995 + pvebackup_propagate_error(cancel_err);
996 +
997 + qemu_co_mutex_lock(&backup_state.backup_mutex);
998 +
999 + if (backup_state.vmaw) {
1000 + /* make sure vma writer does not block anymore */
1001 + vma_writer_set_error(backup_state.vmaw, "backup canceled");
1002 + }
1003 +
1004 + if (backup_state.pbs) {
1005 + proxmox_backup_abort(backup_state.pbs, "backup canceled");
1006 + }
1007 +
1008 + CoCtxData data = {
1009 + .ctx = qemu_get_current_aio_context(),
1010 + .co = qemu_coroutine_self(),
1011 + };
1012 + aio_bh_schedule_oneshot(data.ctx, job_cancel_bh, &data);
1013 + qemu_coroutine_yield();
1014 +
1015 + qemu_co_mutex_unlock(&backup_state.backup_mutex);
1016 +}
1017 +
1018 +// assumes the caller holds backup_mutex
1019 +static int coroutine_fn pvebackup_co_add_config(
1020 + const char *file,
1021 + const char *name,
1022 + BackupFormat format,
1023 + const char *backup_dir,
1024 + VmaWriter *vmaw,
1025 + ProxmoxBackupHandle *pbs,
1026 + Error **errp)
1027 +{
1028 + int res = 0;
1029 +
1030 + char *cdata = NULL;
1031 + gsize clen = 0;
1032 + GError *err = NULL;
1033 + if (!g_file_get_contents(file, &cdata, &clen, &err)) {
1034 + error_setg(errp, "unable to read file '%s'", file);
1035 + return 1;
1036 + }
1037 +
1038 + char *basename = g_path_get_basename(file);
1039 + if (name == NULL) name = basename;
1040 +
1041 + if (format == BACKUP_FORMAT_VMA) {
1042 + if (vma_writer_add_config(vmaw, name, cdata, clen) != 0) {
1043 + error_setg(errp, "unable to add %s config data to vma archive", file);
1044 + goto err;
1045 + }
1046 + } else if (format == BACKUP_FORMAT_PBS) {
1047 + if (proxmox_backup_co_add_config(pbs, name, (unsigned char *)cdata, clen, errp) < 0)
1048 + goto err;
1049 + } else if (format == BACKUP_FORMAT_DIR) {
1050 + char config_path[PATH_MAX];
1051 + snprintf(config_path, PATH_MAX, "%s/%s", backup_dir, name);
1052 + if (!g_file_set_contents(config_path, cdata, clen, &err)) {
1053 + error_setg(errp, "unable to write config file '%s'", config_path);
1054 + goto err;
1055 + }
1056 + }
1057 +
1058 + out:
1059 + g_free(basename);
1060 + g_free(cdata);
1061 + return res;
1062 +
1063 + err:
1064 + res = -1;
1065 + goto out;
1066 +}
1067 +
1068 +/*
1069 + * backup_job_create can *not* be run from a coroutine (and requires an
1070 + * acquired AioContext), so this can't either.
1071 + * The caller is responsible that backup_mutex is held nonetheless.
1072 + */
1073 +static void create_backup_jobs_bh(void *opaque) {
1074 +
1075 + assert(!qemu_in_coroutine());
1076 +
1077 + CoCtxData *data = (CoCtxData*)opaque;
1078 + Error **errp = (Error**)data->data;
1079 +
1080 + Error *local_err = NULL;
1081 +
1082 + /* create job transaction to synchronize bitmap commit and cancel all
1083 + * jobs in case one errors */
1084 + if (backup_state.txn) {
1085 + job_txn_unref(backup_state.txn);
1086 + }
1087 + backup_state.txn = job_txn_new_seq();
1088 +
1089 + /* create and start all jobs (paused state) */
1090 + GList *l = backup_state.di_list;
1091 + while (l) {
1092 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
1093 + l = g_list_next(l);
1094 +
1095 + assert(di->target != NULL);
1096 +
1097 + MirrorSyncMode sync_mode = MIRROR_SYNC_MODE_FULL;
1098 + BitmapSyncMode bitmap_mode = BITMAP_SYNC_MODE_NEVER;
1099 + if (di->bitmap) {
1100 + sync_mode = MIRROR_SYNC_MODE_BITMAP;
1101 + bitmap_mode = BITMAP_SYNC_MODE_ON_SUCCESS;
1102 + }
1103 + AioContext *aio_context = bdrv_get_aio_context(di->bs);
1104 + aio_context_acquire(aio_context);
1105 +
1106 + BlockJob *job = backup_job_create(
1107 + NULL, di->bs, di->target, backup_state.speed, sync_mode, di->bitmap,
1108 + bitmap_mode, false, NULL, &backup_state.perf, BLOCKDEV_ON_ERROR_REPORT,
1109 + BLOCKDEV_ON_ERROR_REPORT, JOB_DEFAULT, pvebackup_complete_cb, di, backup_state.txn,
1110 + &local_err);
1111 +
1112 + aio_context_release(aio_context);
1113 +
1114 + di->job = job;
1115 + if (job) {
1116 + WITH_JOB_LOCK_GUARD() {
1117 + job_ref_locked(&job->job);
1118 + }
1119 + }
1120 +
1121 + if (!job || local_err) {
1122 + error_setg(errp, "backup_job_create failed: %s",
1123 + local_err ? error_get_pretty(local_err) : "null");
1124 + break;
1125 + }
1126 +
1127 + bdrv_unref(di->target);
1128 + di->target = NULL;
1129 + }
1130 +
1131 + if (*errp) {
1132 + /*
1133 + * It's enough to cancel one job in the transaction, the rest will
1134 + * follow automatically.
1135 + */
1136 + bool canceled = false;
1137 + l = backup_state.di_list;
1138 + while (l) {
1139 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
1140 + l = g_list_next(l);
1141 +
1142 + if (di->target) {
1143 + bdrv_unref(di->target);
1144 + di->target = NULL;
1145 + }
1146 +
1147 + if (di->job) {
1148 + WITH_JOB_LOCK_GUARD() {
1149 + if (!canceled) {
1150 + job_cancel_sync_locked(&di->job->job, true);
1151 + canceled = true;
1152 + }
1153 + job_unref_locked(&di->job->job);
1154 + di->job = NULL;
1155 + }
1156 + }
1157 + }
1158 + }
1159 +
1160 + /* return */
1161 + aio_co_enter(data->ctx, data->co);
1162 +}
1163 +
1164 +UuidInfo coroutine_fn *qmp_backup(
1165 + const char *backup_file,
1166 + const char *password,
1167 + const char *keyfile,
1168 + const char *key_password,
1169 + const char *master_keyfile,
1170 + const char *fingerprint,
1171 + const char *backup_ns,
1172 + const char *backup_id,
1173 + bool has_backup_time, int64_t backup_time,
1174 + bool has_use_dirty_bitmap, bool use_dirty_bitmap,
1175 + bool has_compress, bool compress,
1176 + bool has_encrypt, bool encrypt,
1177 + bool has_format, BackupFormat format,
1178 + const char *config_file,
1179 + const char *firewall_file,
1180 + const char *devlist,
1181 + bool has_speed, int64_t speed,
1182 + bool has_max_workers, int64_t max_workers,
1183 + Error **errp)
1184 +{
1185 + assert(qemu_in_coroutine());
1186 +
1187 + qemu_co_mutex_lock(&backup_state.backup_mutex);
1188 +
1189 + BlockBackend *blk;
1190 + BlockDriverState *bs = NULL;
1191 + const char *backup_dir = NULL;
1192 + Error *local_err = NULL;
1193 + uuid_t uuid;
1194 + VmaWriter *vmaw = NULL;
1195 + ProxmoxBackupHandle *pbs = NULL;
1196 + gchar **devs = NULL;
1197 + GList *di_list = NULL;
1198 + GList *l;
1199 + UuidInfo *uuid_info;
1200 +
1201 + const char *config_name = "qemu-server.conf";
1202 + const char *firewall_name = "qemu-server.fw";
1203 +
1204 + if (backup_state.di_list) {
1205 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
1206 + "previous backup not finished");
1207 + qemu_co_mutex_unlock(&backup_state.backup_mutex);
1208 + return NULL;
1209 + }
1210 +
1211 + /* Todo: try to auto-detect format based on file name */
1212 + format = has_format ? format : BACKUP_FORMAT_VMA;
1213 +
1214 + if (devlist) {
1215 + devs = g_strsplit_set(devlist, ",;:", -1);
1216 +
1217 + gchar **d = devs;
1218 + while (d && *d) {
1219 + blk = blk_by_name(*d);
1220 + if (blk) {
1221 + bs = blk_bs(blk);
1222 + if (!bdrv_co_is_inserted(bs)) {
1223 + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
1224 + goto err;
1225 + }
1226 + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
1227 + di->bs = bs;
1228 + di_list = g_list_append(di_list, di);
1229 + } else {
1230 + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
1231 + "Device '%s' not found", *d);
1232 + goto err;
1233 + }
1234 + d++;
1235 + }
1236 +
1237 + } else {
1238 + BdrvNextIterator it;
1239 +
1240 + bs = NULL;
1241 + for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
1242 + if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs)) {
1243 + continue;
1244 + }
1245 +
1246 + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
1247 + di->bs = bs;
1248 + di_list = g_list_append(di_list, di);
1249 + }
1250 + }
1251 +
1252 + if (!di_list) {
1253 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
1254 + goto err;
1255 + }
1256 +
1257 + size_t total = 0;
1258 +
1259 + l = di_list;
1260 + while (l) {
1261 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
1262 + l = g_list_next(l);
1263 + if (bdrv_op_is_blocked(di->bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
1264 + goto err;
1265 + }
1266 +
1267 + ssize_t size = bdrv_getlength(di->bs);
1268 + if (size < 0) {
1269 + error_setg_errno(errp, -size, "bdrv_getlength failed");
1270 + goto err;
1271 + }
1272 + di->size = size;
1273 + total += size;
1274 +
1275 + di->completed_ret = INT_MAX;
1276 + }
1277 +
1278 + uuid_generate(uuid);
1279 +
1280 + qemu_mutex_lock(&backup_state.stat.lock);
1281 + backup_state.stat.reused = 0;
1282 +
1283 + /* clear previous backup's bitmap_list */
1284 + if (backup_state.stat.bitmap_list) {
1285 + GList *bl = backup_state.stat.bitmap_list;
1286 + while (bl) {
1287 + g_free(((PBSBitmapInfo *)bl->data)->drive);
1288 + g_free(bl->data);
1289 + bl = g_list_next(bl);
1290 + }
1291 + g_list_free(backup_state.stat.bitmap_list);
1292 + backup_state.stat.bitmap_list = NULL;
1293 + }
1294 +
1295 + if (format == BACKUP_FORMAT_PBS) {
1296 + if (!password) {
1297 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'password'");
1298 + goto err_mutex;
1299 + }
1300 + if (!backup_id) {
1301 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-id'");
1302 + goto err_mutex;
1303 + }
1304 + if (!has_backup_time) {
1305 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "missing parameter 'backup-time'");
1306 + goto err_mutex;
1307 + }
1308 +
1309 + int dump_cb_block_size = PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE; // Hardcoded (4M)
1310 + firewall_name = "fw.conf";
1311 +
1312 + char *pbs_err = NULL;
1313 + pbs = proxmox_backup_new_ns(
1314 + backup_file,
1315 + backup_ns,
1316 + backup_id,
1317 + backup_time,
1318 + dump_cb_block_size,
1319 + password,
1320 + keyfile,
1321 + key_password,
1322 + master_keyfile,
1323 + has_compress ? compress : true,
1324 + has_encrypt ? encrypt : !!keyfile,
1325 + fingerprint,
1326 + &pbs_err);
1327 +
1328 + if (!pbs) {
1329 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
1330 + "proxmox_backup_new failed: %s", pbs_err);
1331 + proxmox_backup_free_error(pbs_err);
1332 + goto err_mutex;
1333 + }
1334 +
1335 + int connect_result = proxmox_backup_co_connect(pbs, errp);
1336 + if (connect_result < 0)
1337 + goto err_mutex;
1338 +
1339 + /* register all devices */
1340 + l = di_list;
1341 + while (l) {
1342 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
1343 + l = g_list_next(l);
1344 +
1345 + di->block_size = dump_cb_block_size;
1346 +
1347 + const char *devname = bdrv_get_device_name(di->bs);
1348 + PBSBitmapAction action = PBS_BITMAP_ACTION_NOT_USED;
1349 + size_t dirty = di->size;
1350 +
1351 + BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(di->bs, PBS_BITMAP_NAME);
1352 + bool expect_only_dirty = false;
1353 +
1354 + if (has_use_dirty_bitmap && use_dirty_bitmap) {
1355 + if (bitmap == NULL) {
1356 + bitmap = bdrv_create_dirty_bitmap(di->bs, dump_cb_block_size, PBS_BITMAP_NAME, errp);
1357 + if (!bitmap) {
1358 + goto err_mutex;
1359 + }
1360 + action = PBS_BITMAP_ACTION_NEW;
1361 + } else {
1362 + expect_only_dirty = proxmox_backup_check_incremental(pbs, devname, di->size) != 0;
1363 + }
1364 +
1365 + if (expect_only_dirty) {
1366 + /* track clean chunks as reused */
1367 + dirty = MIN(bdrv_get_dirty_count(bitmap), di->size);
1368 + backup_state.stat.reused += di->size - dirty;
1369 + action = PBS_BITMAP_ACTION_USED;
1370 + } else {
1371 + /* mark entire bitmap as dirty to make full backup */
1372 + bdrv_set_dirty_bitmap(bitmap, 0, di->size);
1373 + if (action != PBS_BITMAP_ACTION_NEW) {
1374 + action = PBS_BITMAP_ACTION_INVALID;
1375 + }
1376 + }
1377 + di->bitmap = bitmap;
1378 + } else {
1379 + /* after a full backup the old dirty bitmap is invalid anyway */
1380 + if (bitmap != NULL) {
1381 + bdrv_release_dirty_bitmap(bitmap);
1382 + action = PBS_BITMAP_ACTION_NOT_USED_REMOVED;
1383 + }
1384 + }
1385 +
1386 + int dev_id = proxmox_backup_co_register_image(pbs, devname, di->size, expect_only_dirty, errp);
1387 + if (dev_id < 0) {
1388 + goto err_mutex;
1389 + }
1390 +
1391 + if (!(di->target = bdrv_backup_dump_create(dump_cb_block_size, di->size, pvebackup_co_dump_pbs_cb, di, errp))) {
1392 + goto err_mutex;
1393 + }
1394 +
1395 + di->dev_id = dev_id;
1396 +
1397 + PBSBitmapInfo *info = g_malloc(sizeof(*info));
1398 + info->drive = g_strdup(devname);
1399 + info->action = action;
1400 + info->size = di->size;
1401 + info->dirty = dirty;
1402 + backup_state.stat.bitmap_list = g_list_append(backup_state.stat.bitmap_list, info);
1403 + }
1404 + } else if (format == BACKUP_FORMAT_VMA) {
1405 + vmaw = vma_writer_create(backup_file, uuid, &local_err);
1406 + if (!vmaw) {
1407 + if (local_err) {
1408 + error_propagate(errp, local_err);
1409 + }
1410 + goto err_mutex;
1411 + }
1412 +
1413 + /* register all devices for vma writer */
1414 + l = di_list;
1415 + while (l) {
1416 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
1417 + l = g_list_next(l);
1418 +
1419 + if (!(di->target = bdrv_backup_dump_create(VMA_CLUSTER_SIZE, di->size, pvebackup_co_dump_vma_cb, di, errp))) {
1420 + goto err_mutex;
1421 + }
1422 +
1423 + const char *devname = bdrv_get_device_name(di->bs);
1424 + di->dev_id = vma_writer_register_stream(vmaw, devname, di->size);
1425 + if (di->dev_id <= 0) {
1426 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
1427 + "register_stream failed");
1428 + goto err_mutex;
1429 + }
1430 + }
1431 + } else if (format == BACKUP_FORMAT_DIR) {
1432 + if (mkdir(backup_file, 0640) != 0) {
1433 + error_setg_errno(errp, errno, "can't create directory '%s'\n",
1434 + backup_file);
1435 + goto err_mutex;
1436 + }
1437 + backup_dir = backup_file;
1438 +
1439 + l = di_list;
1440 + while (l) {
1441 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
1442 + l = g_list_next(l);
1443 +
1444 + const char *devname = bdrv_get_device_name(di->bs);
1445 + snprintf(di->targetfile, PATH_MAX, "%s/%s.raw", backup_dir, devname);
1446 +
1447 + int flags = BDRV_O_RDWR;
1448 + bdrv_img_create(di->targetfile, "raw", NULL, NULL, NULL,
1449 + di->size, flags, false, &local_err);
1450 + if (local_err) {
1451 + error_propagate(errp, local_err);
1452 + goto err_mutex;
1453 + }
1454 +
1455 + di->target = bdrv_co_open(di->targetfile, NULL, NULL, flags, &local_err);
1456 + if (!di->target) {
1457 + error_propagate(errp, local_err);
1458 + goto err_mutex;
1459 + }
1460 + }
1461 + } else {
1462 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
1463 + goto err_mutex;
1464 + }
1465 +
1466 +
1467 + /* add configuration file to archive */
1468 + if (config_file) {
1469 + if (pvebackup_co_add_config(config_file, config_name, format, backup_dir,
1470 + vmaw, pbs, errp) != 0) {
1471 + goto err_mutex;
1472 + }
1473 + }
1474 +
1475 + /* add firewall file to archive */
1476 + if (firewall_file) {
1477 + if (pvebackup_co_add_config(firewall_file, firewall_name, format, backup_dir,
1478 + vmaw, pbs, errp) != 0) {
1479 + goto err_mutex;
1480 + }
1481 + }
1482 + /* initialize global backup_state now */
1483 + /* note: 'reused' and 'bitmap_list' are initialized earlier */
1484 +
1485 + if (backup_state.stat.error) {
1486 + error_free(backup_state.stat.error);
1487 + backup_state.stat.error = NULL;
1488 + }
1489 +
1490 + backup_state.stat.start_time = time(NULL);
1491 + backup_state.stat.end_time = 0;
1492 +
1493 + if (backup_state.stat.backup_file) {
1494 + g_free(backup_state.stat.backup_file);
1495 + }
1496 + backup_state.stat.backup_file = g_strdup(backup_file);
1497 +
1498 + uuid_copy(backup_state.stat.uuid, uuid);
1499 + uuid_unparse_lower(uuid, backup_state.stat.uuid_str);
1500 + char *uuid_str = g_strdup(backup_state.stat.uuid_str);
1501 +
1502 + backup_state.stat.total = total;
1503 + backup_state.stat.dirty = total - backup_state.stat.reused;
1504 + backup_state.stat.transferred = 0;
1505 + backup_state.stat.zero_bytes = 0;
1506 + backup_state.stat.finishing = false;
1507 + backup_state.stat.starting = true;
1508 +
1509 + qemu_mutex_unlock(&backup_state.stat.lock);
1510 +
1511 + backup_state.speed = (has_speed && speed > 0) ? speed : 0;
1512 +
1513 + backup_state.perf = (BackupPerf){ .max_workers = 16 };
1514 + if (has_max_workers) {
1515 + backup_state.perf.max_workers = max_workers;
1516 + }
1517 +
1518 + backup_state.vmaw = vmaw;
1519 + backup_state.pbs = pbs;
1520 +
1521 + backup_state.di_list = di_list;
1522 +
1523 + uuid_info = g_malloc0(sizeof(*uuid_info));
1524 + uuid_info->UUID = uuid_str;
1525 +
1526 + /* Run create_backup_jobs_bh outside of coroutine (in BH) but keep
1527 + * backup_mutex locked. This is fine, a CoMutex can be held across yield
1528 + * points, and we'll release it as soon as the BH reschedules us.
1529 + */
1530 + CoCtxData waker = {
1531 + .co = qemu_coroutine_self(),
1532 + .ctx = qemu_get_current_aio_context(),
1533 + .data = &local_err,
1534 + };
1535 + aio_bh_schedule_oneshot(waker.ctx, create_backup_jobs_bh, &waker);
1536 + qemu_coroutine_yield();
1537 +
1538 + if (local_err) {
1539 + error_propagate(errp, local_err);
1540 + goto err;
1541 + }
1542 +
1543 + qemu_co_mutex_unlock(&backup_state.backup_mutex);
1544 +
1545 + qemu_mutex_lock(&backup_state.stat.lock);
1546 + backup_state.stat.starting = false;
1547 + qemu_mutex_unlock(&backup_state.stat.lock);
1548 +
1549 + /* start the first job in the transaction */
1550 + job_txn_start_seq(backup_state.txn);
1551 +
1552 + return uuid_info;
1553 +
1554 +err_mutex:
1555 + qemu_mutex_unlock(&backup_state.stat.lock);
1556 +
1557 +err:
1558 +
1559 + l = di_list;
1560 + while (l) {
1561 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
1562 + l = g_list_next(l);
1563 +
1564 + if (di->target) {
1565 + bdrv_co_unref(di->target);
1566 + }
1567 +
1568 + if (di->targetfile[0]) {
1569 + unlink(di->targetfile);
1570 + }
1571 + g_free(di);
1572 + }
1573 + g_list_free(di_list);
1574 + backup_state.di_list = NULL;
1575 +
1576 + if (devs) {
1577 + g_strfreev(devs);
1578 + }
1579 +
1580 + if (vmaw) {
1581 + Error *err = NULL;
1582 + vma_writer_close(vmaw, &err);
1583 + unlink(backup_file);
1584 + }
1585 +
1586 + if (pbs) {
1587 + proxmox_backup_disconnect(pbs);
1588 + backup_state.pbs = NULL;
1589 + }
1590 +
1591 + if (backup_dir) {
1592 + rmdir(backup_dir);
1593 + }
1594 +
1595 + qemu_co_mutex_unlock(&backup_state.backup_mutex);
1596 + return NULL;
1597 +}
1598 +
1599 +BackupStatus *qmp_query_backup(Error **errp)
1600 +{
1601 + BackupStatus *info = g_malloc0(sizeof(*info));
1602 +
1603 + qemu_mutex_lock(&backup_state.stat.lock);
1604 +
1605 + if (!backup_state.stat.start_time) {
1606 + /* not started, return {} */
1607 + qemu_mutex_unlock(&backup_state.stat.lock);
1608 + return info;
1609 + }
1610 +
1611 + info->has_start_time = true;
1612 + info->start_time = backup_state.stat.start_time;
1613 +
1614 + if (backup_state.stat.backup_file) {
1615 + info->backup_file = g_strdup(backup_state.stat.backup_file);
1616 + }
1617 +
1618 + info->uuid = g_strdup(backup_state.stat.uuid_str);
1619 +
1620 + if (backup_state.stat.end_time) {
1621 + if (backup_state.stat.error) {
1622 + info->status = g_strdup("error");
1623 + info->errmsg = g_strdup(error_get_pretty(backup_state.stat.error));
1624 + } else {
1625 + info->status = g_strdup("done");
1626 + }
1627 + info->has_end_time = true;
1628 + info->end_time = backup_state.stat.end_time;
1629 + } else {
1630 + info->status = g_strdup("active");
1631 + }
1632 +
1633 + info->has_total = true;
1634 + info->total = backup_state.stat.total;
1635 + info->has_dirty = true;
1636 + info->dirty = backup_state.stat.dirty;
1637 + info->has_zero_bytes = true;
1638 + info->zero_bytes = backup_state.stat.zero_bytes;
1639 + info->has_transferred = true;
1640 + info->transferred = backup_state.stat.transferred;
1641 + info->has_reused = true;
1642 + info->reused = backup_state.stat.reused;
1643 + info->finishing = backup_state.stat.finishing;
1644 +
1645 + qemu_mutex_unlock(&backup_state.stat.lock);
1646 +
1647 + return info;
1648 +}
1649 +
1650 +PBSBitmapInfoList *qmp_query_pbs_bitmap_info(Error **errp)
1651 +{
1652 + PBSBitmapInfoList *head = NULL, **p_next = &head;
1653 +
1654 + qemu_mutex_lock(&backup_state.stat.lock);
1655 +
1656 + GList *l = backup_state.stat.bitmap_list;
1657 + while (l) {
1658 + PBSBitmapInfo *info = (PBSBitmapInfo *)l->data;
1659 + l = g_list_next(l);
1660 +
1661 + /* clone bitmap info to avoid auto free after QMP marshalling */
1662 + PBSBitmapInfo *info_ret = g_malloc0(sizeof(*info_ret));
1663 + info_ret->drive = g_strdup(info->drive);
1664 + info_ret->action = info->action;
1665 + info_ret->size = info->size;
1666 + info_ret->dirty = info->dirty;
1667 +
1668 + PBSBitmapInfoList *info_list = g_malloc0(sizeof(*info_list));
1669 + info_list->value = info_ret;
1670 +
1671 + *p_next = info_list;
1672 + p_next = &info_list->next;
1673 + }
1674 +
1675 + qemu_mutex_unlock(&backup_state.stat.lock);
1676 +
1677 + return head;
1678 +}
1679 +
1680 +ProxmoxSupportStatus *qmp_query_proxmox_support(Error **errp)
1681 +{
1682 + ProxmoxSupportStatus *ret = g_malloc0(sizeof(*ret));
1683 + ret->pbs_library_version = g_strdup(proxmox_backup_qemu_version());
1684 + ret->pbs_dirty_bitmap = true;
1685 + ret->pbs_dirty_bitmap_savevm = true;
1686 + ret->query_bitmap_info = true;
1687 + ret->pbs_masterkey = true;
1688 + ret->backup_max_workers = true;
1689 + return ret;
1690 +}
1691 diff --git a/qapi/block-core.json b/qapi/block-core.json
1692 index 542add004b..4ec70acf95 100644
1693 --- a/qapi/block-core.json
1694 +++ b/qapi/block-core.json
1695 @@ -835,6 +835,232 @@
1696 { 'command': 'query-block', 'returns': ['BlockInfo'],
1697 'allow-preconfig': true }
1698
1699 +##
1700 +# @BackupStatus:
1701 +#
1702 +# Detailed backup status.
1703 +#
1704 +# @status: string describing the current backup status.
1705 +# This can be 'active', 'done', 'error'. If this field is not
1706 +# returned, no backup process has been initiated
1707 +#
1708 +# @errmsg: error message (only returned if status is 'error')
1709 +#
1710 +# @total: total amount of bytes involved in the backup process
1711 +#
1712 +# @dirty: with incremental mode (PBS) this is the amount of bytes involved
1713 +# in the backup process which are marked dirty.
1714 +#
1715 +# @transferred: amount of bytes already backed up.
1716 +#
1717 +# @reused: amount of bytes reused due to deduplication.
1718 +#
1719 +# @zero-bytes: amount of 'zero' bytes detected.
1720 +#
1721 +# @start-time: time (epoch) when backup job started.
1722 +#
1723 +# @end-time: time (epoch) when backup job finished.
1724 +#
1725 +# @backup-file: backup file name
1726 +#
1727 +# @uuid: uuid for this backup job
1728 +#
1729 +# @finishing: if status='active' and finishing=true, then the backup process is
1730 +# waiting for the target to finish.
1731 +#
1732 +##
1733 +{ 'struct': 'BackupStatus',
1734 + 'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', '*dirty': 'int',
1735 + '*transferred': 'int', '*zero-bytes': 'int', '*reused': 'int',
1736 + '*start-time': 'int', '*end-time': 'int',
1737 + '*backup-file': 'str', '*uuid': 'str', 'finishing': 'bool' } }
1738 +
1739 +##
1740 +# @BackupFormat:
1741 +#
1742 +# An enumeration of supported backup formats.
1743 +#
1744 +# @vma: Proxmox vma backup format
1745 +##
1746 +{ 'enum': 'BackupFormat',
1747 + 'data': [ 'vma', 'dir', 'pbs' ] }
1748 +
1749 +##
1750 +# @backup:
1751 +#
1752 +# Starts a VM backup.
1753 +#
1754 +# @backup-file: the backup file name
1755 +#
1756 +# @format: format of the backup file
1757 +#
1758 +# @config-file: a configuration file to include into
1759 +# the backup archive.
1760 +#
1761 +# @speed: the maximum speed, in bytes per second
1762 +#
1763 +# @devlist: list of block device names (separated by ',', ';'
1764 +# or ':'). By default the backup includes all writable block devices.
1765 +#
1766 +# @password: backup server passsword (required for format 'pbs')
1767 +#
1768 +# @keyfile: keyfile used for encryption (optional for format 'pbs')
1769 +#
1770 +# @key-password: password for keyfile (optional for format 'pbs')
1771 +#
1772 +# @master-keyfile: PEM-formatted master public keyfile (optional for format 'pbs')
1773 +#
1774 +# @fingerprint: server cert fingerprint (optional for format 'pbs')
1775 +#
1776 +# @backup-ns: backup namespace (required for format 'pbs')
1777 +#
1778 +# @backup-id: backup ID (required for format 'pbs')
1779 +#
1780 +# @backup-time: backup timestamp (Unix epoch, required for format 'pbs')
1781 +#
1782 +# @use-dirty-bitmap: use dirty bitmap to detect incremental changes since last job (optional for format 'pbs')
1783 +#
1784 +# @compress: use compression (optional for format 'pbs', defaults to true)
1785 +#
1786 +# @encrypt: use encryption ((optional for format 'pbs', defaults to true if there is a keyfile)
1787 +#
1788 +# @max-workers: see @BackupPerf for details. Default 16.
1789 +#
1790 +# Returns: the uuid of the backup job
1791 +#
1792 +##
1793 +{ 'command': 'backup', 'data': { 'backup-file': 'str',
1794 + '*password': 'str',
1795 + '*keyfile': 'str',
1796 + '*key-password': 'str',
1797 + '*master-keyfile': 'str',
1798 + '*fingerprint': 'str',
1799 + '*backup-ns': 'str',
1800 + '*backup-id': 'str',
1801 + '*backup-time': 'int',
1802 + '*use-dirty-bitmap': 'bool',
1803 + '*compress': 'bool',
1804 + '*encrypt': 'bool',
1805 + '*format': 'BackupFormat',
1806 + '*config-file': 'str',
1807 + '*firewall-file': 'str',
1808 + '*devlist': 'str',
1809 + '*speed': 'int',
1810 + '*max-workers': 'int' },
1811 + 'returns': 'UuidInfo', 'coroutine': true }
1812 +
1813 +##
1814 +# @query-backup:
1815 +#
1816 +# Returns information about current/last backup task.
1817 +#
1818 +# Returns: @BackupStatus
1819 +#
1820 +##
1821 +{ 'command': 'query-backup', 'returns': 'BackupStatus' }
1822 +
1823 +##
1824 +# @backup-cancel:
1825 +#
1826 +# Cancel the current executing backup process.
1827 +#
1828 +# Returns: nothing on success
1829 +#
1830 +# Notes: This command succeeds even if there is no backup process running.
1831 +#
1832 +##
1833 +{ 'command': 'backup-cancel', 'coroutine': true }
1834 +
1835 +##
1836 +# @ProxmoxSupportStatus:
1837 +#
1838 +# Contains info about supported features added by Proxmox.
1839 +#
1840 +# @pbs-dirty-bitmap: True if dirty-bitmap-incremental backups to PBS are
1841 +# supported.
1842 +#
1843 +# @query-bitmap-info: True if the 'query-pbs-bitmap-info' QMP call is supported.
1844 +#
1845 +# @pbs-dirty-bitmap-savevm: True if 'dirty-bitmaps' migration capability can
1846 +# safely be set for savevm-async.
1847 +#
1848 +# @pbs-masterkey: True if the QMP backup call supports the 'master_keyfile'
1849 +# parameter.
1850 +#
1851 +# @pbs-library-version: Running version of libproxmox-backup-qemu0 library.
1852 +#
1853 +##
1854 +{ 'struct': 'ProxmoxSupportStatus',
1855 + 'data': { 'pbs-dirty-bitmap': 'bool',
1856 + 'query-bitmap-info': 'bool',
1857 + 'pbs-dirty-bitmap-savevm': 'bool',
1858 + 'pbs-masterkey': 'bool',
1859 + 'pbs-library-version': 'str',
1860 + 'backup-max-workers': 'bool' } }
1861 +
1862 +##
1863 +# @query-proxmox-support:
1864 +#
1865 +# Returns information about supported features added by Proxmox.
1866 +#
1867 +# Returns: @ProxmoxSupportStatus
1868 +#
1869 +##
1870 +{ 'command': 'query-proxmox-support', 'returns': 'ProxmoxSupportStatus' }
1871 +
1872 +##
1873 +# @PBSBitmapAction:
1874 +#
1875 +# An action taken on a dirty-bitmap when a backup job was started.
1876 +#
1877 +# @not-used: Bitmap mode was not enabled.
1878 +#
1879 +# @not-used-removed: Bitmap mode was not enabled, but a bitmap from a
1880 +# previous backup still existed and was removed.
1881 +#
1882 +# @new: A new bitmap was attached to the drive for this backup.
1883 +#
1884 +# @used: An existing bitmap will be used to only backup changed data.
1885 +#
1886 +# @invalid: A bitmap existed, but had to be cleared since it's associated
1887 +# base snapshot did not match the base given for the current job or
1888 +# the crypt mode has changed.
1889 +#
1890 +##
1891 +{ 'enum': 'PBSBitmapAction',
1892 + 'data': ['not-used', 'not-used-removed', 'new', 'used', 'invalid'] }
1893 +
1894 +##
1895 +# @PBSBitmapInfo:
1896 +#
1897 +# Contains information about dirty bitmaps used for each drive in a PBS backup.
1898 +#
1899 +# @drive: The underlying drive.
1900 +#
1901 +# @action: The action that was taken when the backup started.
1902 +#
1903 +# @size: The total size of the drive.
1904 +#
1905 +# @dirty: How much of the drive is considered dirty and will be backed up,
1906 +# or 'size' if everything will be.
1907 +#
1908 +##
1909 +{ 'struct': 'PBSBitmapInfo',
1910 + 'data': { 'drive': 'str', 'action': 'PBSBitmapAction', 'size': 'int',
1911 + 'dirty': 'int' } }
1912 +
1913 +##
1914 +# @query-pbs-bitmap-info:
1915 +#
1916 +# Returns information about dirty bitmaps used on the most recently started
1917 +# backup. Returns nothing when the last backup was not using PBS or if no
1918 +# backup occured in this session.
1919 +#
1920 +# Returns: @PBSBitmapInfo
1921 +#
1922 +##
1923 +{ 'command': 'query-pbs-bitmap-info', 'returns': ['PBSBitmapInfo'] }
1924 +
1925 ##
1926 # @BlockDeviceTimedStats:
1927 #
1928 diff --git a/qapi/common.json b/qapi/common.json
1929 index 356db3f670..aae8a3b682 100644
1930 --- a/qapi/common.json
1931 +++ b/qapi/common.json
1932 @@ -206,3 +206,16 @@
1933 ##
1934 { 'struct': 'HumanReadableText',
1935 'data': { 'human-readable-text': 'str' } }
1936 +
1937 +##
1938 +# @UuidInfo:
1939 +#
1940 +# Guest UUID information (Universally Unique Identifier).
1941 +#
1942 +# @UUID: the UUID of the guest
1943 +#
1944 +# Since: 0.14.0
1945 +#
1946 +# Notes: If no UUID was specified for the guest, a null UUID is returned.
1947 +##
1948 +{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} }
1949 diff --git a/qapi/machine.json b/qapi/machine.json
1950 index 47f3facdb2..46760978ae 100644
1951 --- a/qapi/machine.json
1952 +++ b/qapi/machine.json
1953 @@ -4,6 +4,8 @@
1954 # This work is licensed under the terms of the GNU GPL, version 2 or later.
1955 # See the COPYING file in the top-level directory.
1956
1957 +{ 'include': 'common.json' }
1958 +
1959 ##
1960 # = Machines
1961 ##
1962 @@ -228,19 +230,6 @@
1963 ##
1964 { 'command': 'query-target', 'returns': 'TargetInfo' }
1965
1966 -##
1967 -# @UuidInfo:
1968 -#
1969 -# Guest UUID information (Universally Unique Identifier).
1970 -#
1971 -# @UUID: the UUID of the guest
1972 -#
1973 -# Since: 0.14
1974 -#
1975 -# Notes: If no UUID was specified for the guest, a null UUID is returned.
1976 -##
1977 -{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} }
1978 -
1979 ##
1980 # @query-uuid:
1981 #