]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0024-PVE-backup-introduce-vma-archive-format.patch
ab8b00c0dec84c29159211909c270b4c18c39c82
[pve-qemu.git] / debian / patches / pve / 0024-PVE-backup-introduce-vma-archive-format.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Wed, 2 Aug 2017 13:51:02 +0200
4 Subject: [PATCH] PVE: backup: introduce vma archive format
5
6 TODO: Move to a libvma block backend.
7 ---
8 MAINTAINERS | 6 +
9 block/Makefile.objs | 3 +
10 block/vma.c | 424 ++++++++++++++++++++++++++++++++++++++++
11 blockdev.c | 536 +++++++++++++++++++++++++++++++++++++++++++++++++++
12 configure | 29 +++
13 hmp-commands-info.hx | 13 ++
14 hmp-commands.hx | 31 +++
15 hmp.c | 63 ++++++
16 hmp.h | 3 +
17 qapi/block-core.json | 109 ++++++++++-
18 qapi/common.json | 13 ++
19 qapi/misc.json | 13 --
20 12 files changed, 1229 insertions(+), 14 deletions(-)
21 create mode 100644 block/vma.c
22
23 diff --git a/MAINTAINERS b/MAINTAINERS
24 index 666e936812..299a73cd86 100644
25 --- a/MAINTAINERS
26 +++ b/MAINTAINERS
27 @@ -2140,6 +2140,12 @@ L: qemu-block@nongnu.org
28 S: Supported
29 F: block/vvfat.c
30
31 +VMA
32 +M: Wolfgang Bumiller <w.bumiller@proxmox.com>.
33 +L: pve-devel@proxmox.com
34 +S: Supported
35 +F: block/vma.c
36 +
37 Image format fuzzer
38 M: Stefan Hajnoczi <stefanha@redhat.com>
39 L: qemu-block@nongnu.org
40 diff --git a/block/Makefile.objs b/block/Makefile.objs
41 index c00f0b32d6..abfd0f69d7 100644
42 --- a/block/Makefile.objs
43 +++ b/block/Makefile.objs
44 @@ -24,6 +24,7 @@ block-obj-$(CONFIG_RBD) += rbd.o
45 block-obj-$(CONFIG_GLUSTERFS) += gluster.o
46 block-obj-$(CONFIG_VXHS) += vxhs.o
47 block-obj-$(CONFIG_LIBSSH2) += ssh.o
48 +block-obj-$(CONFIG_VMA) += vma.o
49 block-obj-y += accounting.o dirty-bitmap.o
50 block-obj-y += write-threshold.o
51 block-obj-y += backup.o
52 @@ -52,3 +53,5 @@ qcow.o-libs := -lz
53 linux-aio.o-libs := -laio
54 parallels.o-cflags := $(LIBXML2_CFLAGS)
55 parallels.o-libs := $(LIBXML2_LIBS)
56 +vma.o-cflags := $(VMA_CFLAGS)
57 +vma.o-libs := $(VMA_LIBS)
58 diff --git a/block/vma.c b/block/vma.c
59 new file mode 100644
60 index 0000000000..7151514f94
61 --- /dev/null
62 +++ b/block/vma.c
63 @@ -0,0 +1,424 @@
64 +/*
65 + * VMA archive backend for QEMU, container object
66 + *
67 + * Copyright (C) 2017 Proxmox Server Solutions GmbH
68 + *
69 + * This work is licensed under the terms of the GNU GPL, version 2 or later.
70 + * See the COPYING file in the top-level directory.
71 + *
72 + */
73 +#include <vma/vma.h>
74 +
75 +#include "qemu/osdep.h"
76 +#include "qemu/uuid.h"
77 +#include "qemu-common.h"
78 +#include "qapi/error.h"
79 +#include "qapi/qmp/qerror.h"
80 +#include "qapi/qmp/qstring.h"
81 +#include "qom/object.h"
82 +#include "qom/object_interfaces.h"
83 +#include "block/block_int.h"
84 +
85 +/* exported interface */
86 +void vma_object_add_config_file(Object *obj, const char *name,
87 + const char *contents, size_t len,
88 + Error **errp);
89 +
90 +#define TYPE_VMA_OBJECT "vma"
91 +#define VMA_OBJECT(obj) \
92 + OBJECT_CHECK(VMAObjectState, (obj), TYPE_VMA_OBJECT)
93 +#define VMA_OBJECT_GET_CLASS(obj) \
94 + OBJECT_GET_CLASS(VMAObjectClass, (obj), TYPE_VMA_OBJECT)
95 +
96 +typedef struct VMAObjectClass {
97 + ObjectClass parent_class;
98 +} VMAObjectClass;
99 +
100 +typedef struct VMAObjectState {
101 + Object parent;
102 +
103 + char *filename;
104 +
105 + QemuUUID uuid;
106 + bool blocked;
107 + VMAWriter *vma;
108 + QemuMutex mutex;
109 +} VMAObjectState;
110 +
111 +static VMAObjectState *vma_by_id(const char *name)
112 +{
113 + Object *container;
114 + Object *obj;
115 +
116 + container = object_get_objects_root();
117 + obj = object_resolve_path_component(container, name);
118 +
119 + return VMA_OBJECT(obj);
120 +}
121 +
122 +static void vma_object_class_complete(UserCreatable *uc, Error **errp)
123 +{
124 + int rc;
125 + VMAObjectState *vo = VMA_OBJECT(uc);
126 + VMAObjectClass *voc = VMA_OBJECT_GET_CLASS(uc);
127 + (void)!vo;
128 + (void)!voc;
129 +
130 + if (!vo->filename) {
131 + error_setg(errp, "Parameter 'filename' is required");
132 + return;
133 + }
134 +
135 + rc = VMAWriter_fopen(vo->filename, &vo->vma);
136 + if (rc < 0) {
137 + error_setg_errno(errp, -rc, "failed to create VMA archive");
138 + return;
139 + }
140 +
141 + rc = VMAWriter_set_uuid(vo->vma, vo->uuid.data, sizeof(vo->uuid.data));
142 + if (rc < 0) {
143 + error_setg_errno(errp, -rc, "failed to set UUID of VMA archive");
144 + return;
145 + }
146 +
147 + qemu_mutex_init(&vo->mutex);
148 +}
149 +
150 +static bool vma_object_can_be_deleted(UserCreatable *uc, Error **errp)
151 +{
152 + //VMAObjectState *vo = VMA_OBJECT(uc);
153 + //if (!vo->vma) {
154 + // return true;
155 + //}
156 + //return false;
157 + return true;
158 +}
159 +
160 +static void vma_object_class_init(ObjectClass *oc, void *data)
161 +{
162 + UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
163 +
164 + ucc->can_be_deleted = vma_object_can_be_deleted;
165 + ucc->complete = vma_object_class_complete;
166 +}
167 +
168 +static char *vma_object_get_filename(Object *obj, Error **errp)
169 +{
170 + VMAObjectState *vo = VMA_OBJECT(obj);
171 +
172 + return g_strdup(vo->filename);
173 +}
174 +
175 +static void vma_object_set_filename(Object *obj, const char *str, Error **errp)
176 +{
177 + VMAObjectState *vo = VMA_OBJECT(obj);
178 +
179 + if (vo->vma) {
180 + error_setg(errp, "filename cannot be changed after creation");
181 + return;
182 + }
183 +
184 + g_free(vo->filename);
185 + vo->filename = g_strdup(str);
186 +}
187 +
188 +static char *vma_object_get_uuid(Object *obj, Error **errp)
189 +{
190 + VMAObjectState *vo = VMA_OBJECT(obj);
191 +
192 + return qemu_uuid_unparse_strdup(&vo->uuid);
193 +}
194 +
195 +static void vma_object_set_uuid(Object *obj, const char *str, Error **errp)
196 +{
197 + VMAObjectState *vo = VMA_OBJECT(obj);
198 +
199 + if (vo->vma) {
200 + error_setg(errp, "uuid cannot be changed after creation");
201 + return;
202 + }
203 +
204 + qemu_uuid_parse(str, &vo->uuid);
205 +}
206 +
207 +static bool vma_object_get_blocked(Object *obj, Error **errp)
208 +{
209 + VMAObjectState *vo = VMA_OBJECT(obj);
210 +
211 + return vo->blocked;
212 +}
213 +
214 +static void vma_object_set_blocked(Object *obj, bool blocked, Error **errp)
215 +{
216 + VMAObjectState *vo = VMA_OBJECT(obj);
217 +
218 + (void)errp;
219 +
220 + vo->blocked = blocked;
221 +}
222 +
223 +void vma_object_add_config_file(Object *obj, const char *name,
224 + const char *contents, size_t len,
225 + Error **errp)
226 +{
227 + int rc;
228 + VMAObjectState *vo = VMA_OBJECT(obj);
229 +
230 + if (!vo || !vo->vma) {
231 + error_setg(errp, "not a valid vma object to add config files to");
232 + return;
233 + }
234 +
235 + rc = VMAWriter_addConfigFile(vo->vma, name, contents, len);
236 + if (rc < 0) {
237 + error_setg_errno(errp, -rc, "failed to add config file to VMA");
238 + return;
239 + }
240 +}
241 +
242 +static void vma_object_init(Object *obj)
243 +{
244 + VMAObjectState *vo = VMA_OBJECT(obj);
245 + (void)!vo;
246 +
247 + object_property_add_str(obj, "filename",
248 + vma_object_get_filename, vma_object_set_filename,
249 + NULL);
250 + object_property_add_str(obj, "uuid",
251 + vma_object_get_uuid, vma_object_set_uuid,
252 + NULL);
253 + object_property_add_bool(obj, "blocked",
254 + vma_object_get_blocked, vma_object_set_blocked,
255 + NULL);
256 +}
257 +
258 +static void vma_object_finalize(Object *obj)
259 +{
260 + VMAObjectState *vo = VMA_OBJECT(obj);
261 + VMAObjectClass *voc = VMA_OBJECT_GET_CLASS(obj);
262 + (void)!voc;
263 +
264 + qemu_mutex_destroy(&vo->mutex);
265 +
266 + VMAWriter_destroy(vo->vma, true);
267 + g_free(vo->filename);
268 +}
269 +
270 +static const TypeInfo vma_object_info = {
271 + .name = TYPE_VMA_OBJECT,
272 + .parent = TYPE_OBJECT,
273 + .class_size = sizeof(VMAObjectClass),
274 + .class_init = vma_object_class_init,
275 + .instance_size = sizeof(VMAObjectState),
276 + .instance_init = vma_object_init,
277 + .instance_finalize = vma_object_finalize,
278 + .interfaces = (InterfaceInfo[]) {
279 + { TYPE_USER_CREATABLE },
280 + { }
281 + }
282 +};
283 +
284 +static void register_types(void)
285 +{
286 + type_register_static(&vma_object_info);
287 +}
288 +
289 +type_init(register_types);
290 +
291 +typedef struct {
292 + VMAObjectState *vma_obj;
293 + char *name;
294 + size_t device_id;
295 + uint64_t byte_size;
296 +} BDRVVMAState;
297 +
298 +static void qemu_vma_parse_filename(const char *filename, QDict *options,
299 + Error **errp)
300 +{
301 + char *sep;
302 +
303 + sep = strchr(filename, '/');
304 + if (!sep || sep == filename) {
305 + error_setg(errp, "VMA filename should be <vma-object>/<device-name>");
306 + return;
307 + }
308 +
309 + qdict_put(options, "vma", qstring_from_substr(filename, 0, sep-filename-1));
310 +
311 + while (*sep && *sep == '/')
312 + ++sep;
313 + if (!*sep) {
314 + error_setg(errp, "missing device name\n");
315 + return;
316 + }
317 +
318 + qdict_put(options, "name", qstring_from_str(sep));
319 +}
320 +
321 +static QemuOptsList runtime_opts = {
322 + .name = "vma-drive",
323 + .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
324 + .desc = {
325 + {
326 + .name = "vma",
327 + .type = QEMU_OPT_STRING,
328 + .help = "VMA Object name",
329 + },
330 + {
331 + .name = "name",
332 + .type = QEMU_OPT_STRING,
333 + .help = "VMA device name",
334 + },
335 + {
336 + .name = BLOCK_OPT_SIZE,
337 + .type = QEMU_OPT_SIZE,
338 + .help = "Virtual disk size"
339 + },
340 + { /* end of list */ }
341 + },
342 +};
343 +static int qemu_vma_open(BlockDriverState *bs, QDict *options, int flags,
344 + Error **errp)
345 +{
346 + Error *local_err = NULL;
347 + BDRVVMAState *s = bs->opaque;
348 + QemuOpts *opts;
349 + const char *vma_id, *device_name;
350 + ssize_t dev_id;
351 + int64_t bytes = 0;
352 + int ret;
353 +
354 + opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
355 + qemu_opts_absorb_qdict(opts, options, &local_err);
356 + if (local_err) {
357 + error_propagate(errp, local_err);
358 + ret = -EINVAL;
359 + goto failed_opts;
360 + }
361 +
362 + bytes = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
363 + BDRV_SECTOR_SIZE);
364 +
365 + vma_id = qemu_opt_get(opts, "vma");
366 + device_name = qemu_opt_get(opts, "name");
367 +
368 + VMAObjectState *vma = vma_by_id(vma_id);
369 + if (!vma) {
370 + ret = -EINVAL;
371 + error_setg(errp, "no such VMA object: %s", vma_id);
372 + goto failed_opts;
373 + }
374 +
375 + dev_id = VMAWriter_findDevice(vma->vma, device_name);
376 + if (dev_id >= 0) {
377 + error_setg(errp, "drive already exists in VMA object");
378 + ret = -EIO;
379 + goto failed_opts;
380 + }
381 +
382 + dev_id = VMAWriter_addDevice(vma->vma, device_name, (uint64_t)bytes);
383 + if (dev_id < 0) {
384 + error_setg_errno(errp, -dev_id, "failed to add VMA device");
385 + ret = -EIO;
386 + goto failed_opts;
387 + }
388 +
389 + object_ref(OBJECT(vma));
390 + s->vma_obj = vma;
391 + s->name = g_strdup(device_name);
392 + s->device_id = (size_t)dev_id;
393 + s->byte_size = bytes;
394 +
395 + ret = 0;
396 +
397 +failed_opts:
398 + qemu_opts_del(opts);
399 + return ret;
400 +}
401 +
402 +static void qemu_vma_close(BlockDriverState *bs)
403 +{
404 + BDRVVMAState *s = bs->opaque;
405 +
406 + (void)VMAWriter_finishDevice(s->vma_obj->vma, s->device_id);
407 + object_unref(OBJECT(s->vma_obj));
408 +
409 + g_free(s->name);
410 +}
411 +
412 +static int64_t qemu_vma_getlength(BlockDriverState *bs)
413 +{
414 + BDRVVMAState *s = bs->opaque;
415 +
416 + return s->byte_size;
417 +}
418 +
419 +static coroutine_fn int qemu_vma_co_writev(BlockDriverState *bs,
420 + int64_t sector_num,
421 + int nb_sectors,
422 + QEMUIOVector *qiov)
423 +{
424 + size_t i;
425 + ssize_t rc;
426 + BDRVVMAState *s = bs->opaque;
427 + VMAObjectState *vo = s->vma_obj;
428 + off_t offset = sector_num * BDRV_SECTOR_SIZE;
429 +
430 + qemu_mutex_lock(&vo->mutex);
431 + if (vo->blocked) {
432 + return -EPERM;
433 + }
434 + for (i = 0; i != qiov->niov; ++i) {
435 + const struct iovec *v = &qiov->iov[i];
436 + size_t blocks = v->iov_len / VMA_BLOCK_SIZE;
437 + if (blocks * VMA_BLOCK_SIZE != v->iov_len) {
438 + return -EIO;
439 + }
440 + rc = VMAWriter_writeBlocks(vo->vma, s->device_id,
441 + v->iov_base, blocks, offset);
442 + if (errno) {
443 + return -errno;
444 + }
445 + if (rc != blocks) {
446 + return -EIO;
447 + }
448 + offset += v->iov_len;
449 + }
450 + qemu_mutex_unlock(&vo->mutex);
451 + return 0;
452 +}
453 +
454 +static int qemu_vma_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
455 +{
456 + bdi->cluster_size = VMA_CLUSTER_SIZE;
457 + bdi->unallocated_blocks_are_zero = true;
458 + bdi->can_write_zeroes_with_unmap = false;
459 + return 0;
460 +}
461 +
462 +static BlockDriver bdrv_vma_drive = {
463 + .format_name = "vma-drive",
464 + .instance_size = sizeof(BDRVVMAState),
465 +
466 +#if 0
467 + .bdrv_create = qemu_vma_create,
468 + .create_opts = &qemu_vma_create_opts,
469 +#endif
470 +
471 + .bdrv_parse_filename = qemu_vma_parse_filename,
472 + .bdrv_file_open = qemu_vma_open,
473 +
474 + .bdrv_close = qemu_vma_close,
475 + .bdrv_has_zero_init = bdrv_has_zero_init_1,
476 + .bdrv_getlength = qemu_vma_getlength,
477 + .bdrv_get_info = qemu_vma_get_info,
478 +
479 + .bdrv_co_writev = qemu_vma_co_writev,
480 +};
481 +
482 +static void bdrv_vma_init(void)
483 +{
484 + bdrv_register(&bdrv_vma_drive);
485 +}
486 +
487 +block_init(bdrv_vma_init);
488 diff --git a/blockdev.c b/blockdev.c
489 index d5eb6b62ca..4f18d3c3d7 100644
490 --- a/blockdev.c
491 +++ b/blockdev.c
492 @@ -31,11 +31,13 @@
493 */
494
495 #include "qemu/osdep.h"
496 +#include "qemu/uuid.h"
497 #include "sysemu/block-backend.h"
498 #include "sysemu/blockdev.h"
499 #include "hw/block/block.h"
500 #include "block/blockjob.h"
501 #include "block/qdict.h"
502 +#include "block/blockjob_int.h"
503 #include "block/throttle-groups.h"
504 #include "monitor/monitor.h"
505 #include "qemu/error-report.h"
506 @@ -44,6 +46,7 @@
507 #include "qapi/qapi-commands-block.h"
508 #include "qapi/qapi-commands-transaction.h"
509 #include "qapi/qapi-visit-block-core.h"
510 +#include "qapi/qapi-types-misc.h"
511 #include "qapi/qmp/qdict.h"
512 #include "qapi/qmp/qnum.h"
513 #include "qapi/qmp/qstring.h"
514 @@ -3220,6 +3223,539 @@ out:
515 aio_context_release(aio_context);
516 }
517
518 +/* PVE backup related function */
519 +
520 +static struct PVEBackupState {
521 + Error *error;
522 + bool cancel;
523 + QemuUUID uuid;
524 + char uuid_str[37];
525 + int64_t speed;
526 + time_t start_time;
527 + time_t end_time;
528 + char *backup_file;
529 + Object *vmaobj;
530 + GList *di_list;
531 + size_t next_job;
532 + size_t total;
533 + size_t transferred;
534 + size_t zero_bytes;
535 + QemuMutex backup_mutex;
536 + bool backup_mutex_initialized;
537 +} backup_state;
538 +
539 +typedef struct PVEBackupDevInfo {
540 + BlockDriverState *bs;
541 + size_t size;
542 + uint8_t dev_id;
543 + bool completed;
544 + char targetfile[PATH_MAX];
545 + BlockDriverState *target;
546 +} PVEBackupDevInfo;
547 +
548 +static void pvebackup_run_next_job(void);
549 +
550 +static void pvebackup_cleanup(void)
551 +{
552 + qemu_mutex_lock(&backup_state.backup_mutex);
553 + // Avoid race between block jobs and backup-cancel command:
554 + if (!backup_state.vmaw) {
555 + qemu_mutex_unlock(&backup_state.backup_mutex);
556 + return;
557 + }
558 +
559 + backup_state.end_time = time(NULL);
560 +
561 + if (backup_state.vmaobj) {
562 + object_unparent(backup_state.vmaobj);
563 + backup_state.vmaobj = NULL;
564 + }
565 +
566 + g_list_free(backup_state.di_list);
567 + backup_state.di_list = NULL;
568 + qemu_mutex_unlock(&backup_state.backup_mutex);
569 +}
570 +
571 +static void pvebackup_complete_cb(void *opaque, int ret)
572 +{
573 + // This always runs in the main loop
574 +
575 + PVEBackupDevInfo *di = opaque;
576 +
577 + di->completed = true;
578 +
579 + if (ret < 0 && !backup_state.error) {
580 + error_setg(&backup_state.error, "job failed with err %d - %s",
581 + ret, strerror(-ret));
582 + }
583 +
584 + di->bs = NULL;
585 + di->target = NULL;
586 +
587 + if (backup_state.vmaobj) {
588 + object_unparent(backup_state.vmaobj);
589 + backup_state.vmaobj = NULL;
590 + }
591 +
592 + // remove self from job queue
593 + qemu_mutex_lock(&backup_state.backup_mutex);
594 + backup_state.di_list = g_list_remove(backup_state.di_list, di);
595 + g_free(di);
596 + qemu_mutex_unlock(&backup_state.backup_mutex);
597 +
598 + if (!backup_state.cancel) {
599 + pvebackup_run_next_job();
600 + }
601 +}
602 +
603 +static void pvebackup_cancel(void *opaque)
604 +{
605 + backup_state.cancel = true;
606 + qemu_mutex_lock(&backup_state.backup_mutex);
607 + // Avoid race between block jobs and backup-cancel command:
608 + if (!backup_state.vmaw) {
609 + qemu_mutex_unlock(&backup_state.backup_mutex);
610 + return;
611 + }
612 +
613 + if (!backup_state.error) {
614 + error_setg(&backup_state.error, "backup cancelled");
615 + }
616 +
617 + if (backup_state.vmaobj) {
618 + Error *err;
619 + /* make sure vma writer does not block anymore */
620 + if (!object_set_props(backup_state.vmaobj, &err, "blocked", "yes", NULL)) {
621 + if (err) {
622 + error_report_err(err);
623 + }
624 + }
625 + }
626 +
627 + GList *l = backup_state.di_list;
628 + while (l) {
629 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
630 + l = g_list_next(l);
631 + if (!di->completed && di->bs) {
632 + BlockJob *job = di->bs->job;
633 + if (job) {
634 + AioContext *aio_context = blk_get_aio_context(job->blk);
635 + aio_context_acquire(aio_context);
636 + if (!di->completed) {
637 + job_cancel(&job->job, false);
638 + }
639 + aio_context_release(aio_context);
640 + }
641 + }
642 + }
643 +
644 + qemu_mutex_unlock(&backup_state.backup_mutex);
645 + pvebackup_cleanup();
646 +}
647 +
648 +void qmp_backup_cancel(Error **errp)
649 +{
650 + if (!backup_state.backup_mutex_initialized)
651 + return;
652 + Coroutine *co = qemu_coroutine_create(pvebackup_cancel, NULL);
653 + qemu_coroutine_enter(co);
654 +
655 + while (backup_state.vmaobj) {
656 + /* FIXME: Find something better for this */
657 + aio_poll(qemu_get_aio_context(), true);
658 + }
659 +}
660 +
661 +void vma_object_add_config_file(Object *obj, const char *name,
662 + const char *contents, size_t len,
663 + Error **errp);
664 +static int config_to_vma(const char *file, BackupFormat format,
665 + Object *vmaobj,
666 + const char *backup_dir,
667 + Error **errp)
668 +{
669 + char *cdata = NULL;
670 + gsize clen = 0;
671 + GError *err = NULL;
672 + if (!g_file_get_contents(file, &cdata, &clen, &err)) {
673 + error_setg(errp, "unable to read file '%s'", file);
674 + return 1;
675 + }
676 +
677 + char *basename = g_path_get_basename(file);
678 +
679 + if (format == BACKUP_FORMAT_VMA) {
680 + vma_object_add_config_file(vmaobj, basename, cdata, clen, errp);
681 + } else if (format == BACKUP_FORMAT_DIR) {
682 + char config_path[PATH_MAX];
683 + snprintf(config_path, PATH_MAX, "%s/%s", backup_dir, basename);
684 + if (!g_file_set_contents(config_path, cdata, clen, &err)) {
685 + error_setg(errp, "unable to write config file '%s'", config_path);
686 + g_free(cdata);
687 + g_free(basename);
688 + return 1;
689 + }
690 + }
691 +
692 + g_free(basename);
693 + g_free(cdata);
694 + return 0;
695 +}
696 +
697 +static void pvebackup_run_next_job(void)
698 +{
699 + qemu_mutex_lock(&backup_state.backup_mutex);
700 +
701 + GList *next = g_list_nth(backup_state.di_list, backup_state.next_job);
702 + while (next) {
703 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)next->data;
704 + backup_state.next_job++;
705 + if (!di->completed && di->bs && di->bs->job) {
706 + BlockJob *job = di->bs->job;
707 + AioContext *aio_context = blk_get_aio_context(job->blk);
708 + aio_context_acquire(aio_context);
709 + qemu_mutex_unlock(&backup_state.backup_mutex);
710 + if (backup_state.error || backup_state.cancel) {
711 + job_cancel_sync(job);
712 + } else {
713 + job_resume(job);
714 + }
715 + aio_context_release(aio_context);
716 + return;
717 + }
718 + next = g_list_next(next);
719 + }
720 + qemu_mutex_unlock(&backup_state.backup_mutex);
721 +
722 + // no more jobs, run the cleanup
723 + pvebackup_cleanup();
724 +}
725 +
726 +UuidInfo *qmp_backup(const char *backup_file, bool has_format,
727 + BackupFormat format,
728 + bool has_config_file, const char *config_file,
729 + bool has_firewall_file, const char *firewall_file,
730 + bool has_devlist, const char *devlist,
731 + bool has_speed, int64_t speed, Error **errp)
732 +{
733 + BlockBackend *blk;
734 + BlockDriverState *bs = NULL;
735 + const char *backup_dir = NULL;
736 + Error *local_err = NULL;
737 + QemuUUID uuid;
738 + gchar **devs = NULL;
739 + GList *di_list = NULL;
740 + GList *l;
741 + UuidInfo *uuid_info;
742 + BlockJob *job;
743 +
744 + if (!backup_state.backup_mutex_initialized) {
745 + qemu_mutex_init(&backup_state.backup_mutex);
746 + backup_state.backup_mutex_initialized = true;
747 + }
748 +
749 + if (backup_state.di_list || backup_state.vmaobj) {
750 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
751 + "previous backup not finished");
752 + return NULL;
753 + }
754 +
755 + /* Todo: try to auto-detect format based on file name */
756 + format = has_format ? format : BACKUP_FORMAT_VMA;
757 +
758 + if (has_devlist) {
759 + devs = g_strsplit_set(devlist, ",;:", -1);
760 +
761 + gchar **d = devs;
762 + while (d && *d) {
763 + blk = blk_by_name(*d);
764 + if (blk) {
765 + bs = blk_bs(blk);
766 + if (bdrv_is_read_only(bs)) {
767 + error_setg(errp, "Node '%s' is read only", *d);
768 + goto err;
769 + }
770 + if (!bdrv_is_inserted(bs)) {
771 + error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, *d);
772 + goto err;
773 + }
774 + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
775 + di->bs = bs;
776 + di_list = g_list_append(di_list, di);
777 + } else {
778 + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
779 + "Device '%s' not found", *d);
780 + goto err;
781 + }
782 + d++;
783 + }
784 +
785 + } else {
786 + BdrvNextIterator it;
787 +
788 + bs = NULL;
789 + for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
790 + if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
791 + continue;
792 + }
793 +
794 + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1);
795 + di->bs = bs;
796 + di_list = g_list_append(di_list, di);
797 + }
798 + }
799 +
800 + if (!di_list) {
801 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "empty device list");
802 + goto err;
803 + }
804 +
805 + size_t total = 0;
806 +
807 + l = di_list;
808 + while (l) {
809 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
810 + l = g_list_next(l);
811 + if (bdrv_op_is_blocked(di->bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
812 + goto err;
813 + }
814 +
815 + ssize_t size = bdrv_getlength(di->bs);
816 + if (size < 0) {
817 + error_setg_errno(errp, -di->size, "bdrv_getlength failed");
818 + goto err;
819 + }
820 + di->size = size;
821 + total += size;
822 + }
823 +
824 + qemu_uuid_generate(&uuid);
825 +
826 + if (format == BACKUP_FORMAT_VMA) {
827 + char uuidstr[UUID_FMT_LEN+1];
828 + qemu_uuid_unparse(&uuid, uuidstr);
829 + uuidstr[UUID_FMT_LEN] = 0;
830 + backup_state.vmaobj =
831 + object_new_with_props("vma", object_get_objects_root(),
832 + "vma-backup-obj", &local_err,
833 + "filename", backup_file,
834 + "uuid", uuidstr,
835 + NULL);
836 + if (!backup_state.vmaobj) {
837 + if (local_err) {
838 + error_propagate(errp, local_err);
839 + }
840 + goto err;
841 + }
842 +
843 + l = di_list;
844 + while (l) {
845 + QDict *options = qdict_new();
846 +
847 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
848 + l = g_list_next(l);
849 +
850 + const char *devname = bdrv_get_device_name(di->bs);
851 + snprintf(di->targetfile, PATH_MAX, "vma-backup-obj/%s.raw", devname);
852 +
853 + qdict_put(options, "driver", qstring_from_str("vma-drive"));
854 + qdict_put(options, "size", qint_from_int(di->size));
855 + di->target = bdrv_open(di->targetfile, NULL, options, BDRV_O_RDWR, &local_err);
856 + if (!di->target) {
857 + error_propagate(errp, local_err);
858 + goto err;
859 + }
860 + }
861 + } else if (format == BACKUP_FORMAT_DIR) {
862 + if (mkdir(backup_file, 0640) != 0) {
863 + error_setg_errno(errp, errno, "can't create directory '%s'\n",
864 + backup_file);
865 + goto err;
866 + }
867 + backup_dir = backup_file;
868 +
869 + l = di_list;
870 + while (l) {
871 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
872 + l = g_list_next(l);
873 +
874 + const char *devname = bdrv_get_device_name(di->bs);
875 + snprintf(di->targetfile, PATH_MAX, "%s/%s.raw", backup_dir, devname);
876 +
877 + int flags = BDRV_O_RDWR;
878 + bdrv_img_create(di->targetfile, "raw", NULL, NULL, NULL,
879 + di->size, flags, false, &local_err);
880 + if (local_err) {
881 + error_propagate(errp, local_err);
882 + goto err;
883 + }
884 +
885 + di->target = bdrv_open(di->targetfile, NULL, NULL, flags, &local_err);
886 + if (!di->target) {
887 + error_propagate(errp, local_err);
888 + goto err;
889 + }
890 + }
891 + } else {
892 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format");
893 + goto err;
894 + }
895 +
896 + /* add configuration file to archive */
897 + if (has_config_file) {
898 + if(config_to_vma(config_file, format, backup_state.vmaobj, backup_dir, errp) != 0) {
899 + goto err;
900 + }
901 + }
902 +
903 + /* add firewall file to archive */
904 + if (has_firewall_file) {
905 + if(config_to_vma(firewall_file, format, backup_state.vmaobj, backup_dir, errp) != 0) {
906 + goto err;
907 + }
908 + }
909 + /* initialize global backup_state now */
910 +
911 + backup_state.cancel = false;
912 +
913 + if (backup_state.error) {
914 + error_free(backup_state.error);
915 + backup_state.error = NULL;
916 + }
917 +
918 + backup_state.speed = (has_speed && speed > 0) ? speed : 0;
919 +
920 + backup_state.start_time = time(NULL);
921 + backup_state.end_time = 0;
922 +
923 + if (backup_state.backup_file) {
924 + g_free(backup_state.backup_file);
925 + }
926 + backup_state.backup_file = g_strdup(backup_file);
927 +
928 + memcpy(&backup_state.uuid, &uuid, sizeof(uuid));
929 + qemu_uuid_unparse(&uuid, backup_state.uuid_str);
930 +
931 + qemu_mutex_lock(&backup_state.backup_mutex);
932 + backup_state.di_list = di_list;
933 + backup_state.next_job = 0;
934 +
935 + backup_state.total = total;
936 + backup_state.transferred = 0;
937 + backup_state.zero_bytes = 0;
938 +
939 + /* start all jobs (paused state) */
940 + l = di_list;
941 + while (l) {
942 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
943 + l = g_list_next(l);
944 +
945 + job = backup_job_create(NULL, di->bs, di->target, speed, MIRROR_SYNC_MODE_FULL, NULL,
946 + false, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
947 + JOB_DEFAULT,
948 + pvebackup_complete_cb, di, 2, NULL, &local_err);
949 + if (di->target) {
950 + bdrv_unref(di->target);
951 + di->target = NULL;
952 + }
953 + if (!job || local_err != NULL) {
954 + error_setg(&backup_state.error, "backup_job_create failed");
955 + pvebackup_cancel(NULL);
956 + } else {
957 + job_start(&job->job);
958 + }
959 + }
960 +
961 + qemu_mutex_unlock(&backup_state.backup_mutex);
962 +
963 + if (!backup_state.error) {
964 + pvebackup_run_next_job(); // run one job
965 + }
966 +
967 + uuid_info = g_malloc0(sizeof(*uuid_info));
968 + uuid_info->UUID = g_strdup(backup_state.uuid_str);
969 +
970 + return uuid_info;
971 +
972 +err:
973 +
974 + l = di_list;
975 + while (l) {
976 + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data;
977 + l = g_list_next(l);
978 +
979 + if (di->target) {
980 + bdrv_unref(di->target);
981 + }
982 +
983 + if (di->targetfile[0]) {
984 + unlink(di->targetfile);
985 + }
986 + g_free(di);
987 + }
988 + g_list_free(di_list);
989 +
990 + if (devs) {
991 + g_strfreev(devs);
992 + }
993 +
994 + if (backup_state.vmaobj) {
995 + object_unparent(backup_state.vmaobj);
996 + backup_state.vmaobj = NULL;
997 + }
998 +
999 + if (backup_dir) {
1000 + rmdir(backup_dir);
1001 + }
1002 +
1003 + return NULL;
1004 +}
1005 +
1006 +BackupStatus *qmp_query_backup(Error **errp)
1007 +{
1008 + BackupStatus *info = g_malloc0(sizeof(*info));
1009 +
1010 + if (!backup_state.start_time) {
1011 + /* not started, return {} */
1012 + return info;
1013 + }
1014 +
1015 + info->has_status = true;
1016 + info->has_start_time = true;
1017 + info->start_time = backup_state.start_time;
1018 +
1019 + if (backup_state.backup_file) {
1020 + info->has_backup_file = true;
1021 + info->backup_file = g_strdup(backup_state.backup_file);
1022 + }
1023 +
1024 + info->has_uuid = true;
1025 + info->uuid = g_strdup(backup_state.uuid_str);
1026 +
1027 + if (backup_state.end_time) {
1028 + if (backup_state.error) {
1029 + info->status = g_strdup("error");
1030 + info->has_errmsg = true;
1031 + info->errmsg = g_strdup(error_get_pretty(backup_state.error));
1032 + } else {
1033 + info->status = g_strdup("done");
1034 + }
1035 + info->has_end_time = true;
1036 + info->end_time = backup_state.end_time;
1037 + } else {
1038 + info->status = g_strdup("active");
1039 + }
1040 +
1041 + info->has_total = true;
1042 + info->total = backup_state.total;
1043 + info->has_zero_bytes = true;
1044 + info->zero_bytes = backup_state.zero_bytes;
1045 + info->has_transferred = true;
1046 + info->transferred = backup_state.transferred;
1047 +
1048 + return info;
1049 +}
1050 +
1051 void qmp_block_stream(bool has_job_id, const char *job_id, const char *device,
1052 bool has_base, const char *base,
1053 bool has_base_node, const char *base_node,
1054 diff --git a/configure b/configure
1055 index 2a7796ea80..601c1f44f9 100755
1056 --- a/configure
1057 +++ b/configure
1058 @@ -475,6 +475,7 @@ vxhs=""
1059 libxml2=""
1060 docker="no"
1061 debug_mutex="no"
1062 +vma=""
1063
1064 # cross compilers defaults, can be overridden with --cross-cc-ARCH
1065 cross_cc_aarch64="aarch64-linux-gnu-gcc"
1066 @@ -1435,6 +1436,10 @@ for opt do
1067 ;;
1068 --disable-debug-mutex) debug_mutex=no
1069 ;;
1070 + --enable-vma) vma=yes
1071 + ;;
1072 + --disable-vma) vma=no
1073 + ;;
1074 *)
1075 echo "ERROR: unknown option $opt"
1076 echo "Try '$0 --help' for more information"
1077 @@ -1710,6 +1715,7 @@ disabled with --disable-FEATURE, default is enabled if available:
1078 vhost-user vhost-user support
1079 capstone capstone disassembler support
1080 debug-mutex mutex debugging support
1081 + vma VMA archive backend
1082
1083 NOTE: The object files are built at the place where configure is launched
1084 EOF
1085 @@ -4124,6 +4130,22 @@ EOF
1086 fi
1087
1088 ##########################################
1089 +# vma probe
1090 +if test "$vma" != "no" ; then
1091 + if $pkg_config --exact-version=0.1.0 vma; then
1092 + vma="yes"
1093 + vma_cflags=$($pkg_config --cflags vma)
1094 + vma_libs=$($pkg_config --libs vma)
1095 + else
1096 + if test "$vma" = "yes" ; then
1097 + feature_not_found "VMA Archive backend support" \
1098 + "Install libvma devel"
1099 + fi
1100 + vma="no"
1101 + fi
1102 +fi
1103 +
1104 +##########################################
1105 # signalfd probe
1106 signalfd="no"
1107 cat > $TMPC << EOF
1108 @@ -6010,6 +6032,7 @@ echo "replication support $replication"
1109 echo "VxHS block device $vxhs"
1110 echo "capstone $capstone"
1111 echo "docker $docker"
1112 +echo "VMA support $vma"
1113
1114 if test "$sdl_too_old" = "yes"; then
1115 echo "-> Your SDL version is too old - please upgrade to have SDL support"
1116 @@ -6496,6 +6519,12 @@ if test "$usb_redir" = "yes" ; then
1117 echo "USB_REDIR_LIBS=$usb_redir_libs" >> $config_host_mak
1118 fi
1119
1120 +if test "$vma" = "yes" ; then
1121 + echo "CONFIG_VMA=y" >> $config_host_mak
1122 + echo "VMA_CFLAGS=$vma_cflags" >> $config_host_mak
1123 + echo "VMA_LIBS=$vma_libs" >> $config_host_mak
1124 +fi
1125 +
1126 if test "$opengl" = "yes" ; then
1127 echo "CONFIG_OPENGL=y" >> $config_host_mak
1128 echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
1129 diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
1130 index 42c148fdc9..277e140092 100644
1131 --- a/hmp-commands-info.hx
1132 +++ b/hmp-commands-info.hx
1133 @@ -502,6 +502,19 @@ STEXI
1134 Show CPU statistics.
1135 ETEXI
1136
1137 + {
1138 + .name = "backup",
1139 + .args_type = "",
1140 + .params = "",
1141 + .help = "show backup status",
1142 + .cmd = hmp_info_backup,
1143 + },
1144 +
1145 +STEXI
1146 +@item info backup
1147 +show backup status
1148 +ETEXI
1149 +
1150 #if defined(CONFIG_SLIRP)
1151 {
1152 .name = "usernet",
1153 diff --git a/hmp-commands.hx b/hmp-commands.hx
1154 index a6f0720442..956cbf04b9 100644
1155 --- a/hmp-commands.hx
1156 +++ b/hmp-commands.hx
1157 @@ -107,6 +107,37 @@ STEXI
1158 Copy data from a backing file into a block device.
1159 ETEXI
1160
1161 + {
1162 + .name = "backup",
1163 + .args_type = "directory:-d,backupfile:s,speed:o?,devlist:s?",
1164 + .params = "[-d] backupfile [speed [devlist]]",
1165 + .help = "create a VM Backup."
1166 + "\n\t\t\t Use -d to dump data into a directory instead"
1167 + "\n\t\t\t of using VMA format.",
1168 + .cmd = hmp_backup,
1169 + },
1170 +
1171 +STEXI
1172 +@item backup
1173 +@findex backup
1174 +Create a VM backup.
1175 +ETEXI
1176 +
1177 + {
1178 + .name = "backup_cancel",
1179 + .args_type = "",
1180 + .params = "",
1181 + .help = "cancel the current VM backup",
1182 + .cmd = hmp_backup_cancel,
1183 + },
1184 +
1185 +STEXI
1186 +@item backup_cancel
1187 +@findex backup_cancel
1188 +Cancel the current VM backup.
1189 +
1190 +ETEXI
1191 +
1192 {
1193 .name = "block_job_set_speed",
1194 .args_type = "device:B,speed:o",
1195 diff --git a/hmp.c b/hmp.c
1196 index 7c975f3ead..8d659e20f6 100644
1197 --- a/hmp.c
1198 +++ b/hmp.c
1199 @@ -166,6 +166,44 @@ void hmp_info_mice(Monitor *mon, const QDict *qdict)
1200 qapi_free_MouseInfoList(mice_list);
1201 }
1202
1203 +void hmp_info_backup(Monitor *mon, const QDict *qdict)
1204 +{
1205 + BackupStatus *info;
1206 +
1207 + info = qmp_query_backup(NULL);
1208 + if (info->has_status) {
1209 + if (info->has_errmsg) {
1210 + monitor_printf(mon, "Backup status: %s - %s\n",
1211 + info->status, info->errmsg);
1212 + } else {
1213 + monitor_printf(mon, "Backup status: %s\n", info->status);
1214 + }
1215 + }
1216 +
1217 + if (info->has_backup_file) {
1218 + monitor_printf(mon, "Start time: %s", ctime(&info->start_time));
1219 + if (info->end_time) {
1220 + monitor_printf(mon, "End time: %s", ctime(&info->end_time));
1221 + }
1222 +
1223 + int per = (info->has_total && info->total &&
1224 + info->has_transferred && info->transferred) ?
1225 + (info->transferred * 100)/info->total : 0;
1226 + int zero_per = (info->has_total && info->total &&
1227 + info->has_zero_bytes && info->zero_bytes) ?
1228 + (info->zero_bytes * 100)/info->total : 0;
1229 + monitor_printf(mon, "Backup file: %s\n", info->backup_file);
1230 + monitor_printf(mon, "Backup uuid: %s\n", info->uuid);
1231 + monitor_printf(mon, "Total size: %zd\n", info->total);
1232 + monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n",
1233 + info->transferred, per);
1234 + monitor_printf(mon, "Zero bytes: %zd (%d%%)\n",
1235 + info->zero_bytes, zero_per);
1236 + }
1237 +
1238 + qapi_free_BackupStatus(info);
1239 +}
1240 +
1241 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
1242 {
1243 MigrationInfo *info;
1244 @@ -1899,6 +1937,31 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)
1245 hmp_handle_error(mon, &error);
1246 }
1247
1248 +void hmp_backup_cancel(Monitor *mon, const QDict *qdict)
1249 +{
1250 + Error *error = NULL;
1251 +
1252 + qmp_backup_cancel(&error);
1253 +
1254 + hmp_handle_error(mon, &error);
1255 +}
1256 +
1257 +void hmp_backup(Monitor *mon, const QDict *qdict)
1258 +{
1259 + Error *error = NULL;
1260 +
1261 + int dir = qdict_get_try_bool(qdict, "directory", 0);
1262 + const char *backup_file = qdict_get_str(qdict, "backupfile");
1263 + const char *devlist = qdict_get_try_str(qdict, "devlist");
1264 + int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1265 +
1266 + qmp_backup(backup_file, true, dir ? BACKUP_FORMAT_DIR : BACKUP_FORMAT_VMA,
1267 + false, NULL, false, NULL, !!devlist,
1268 + devlist, qdict_haskey(qdict, "speed"), speed, &error);
1269 +
1270 + hmp_handle_error(mon, &error);
1271 +}
1272 +
1273 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1274 {
1275 Error *error = NULL;
1276 diff --git a/hmp.h b/hmp.h
1277 index 98bb7a44db..853f233195 100644
1278 --- a/hmp.h
1279 +++ b/hmp.h
1280 @@ -29,6 +29,7 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict);
1281 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict);
1282 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict);
1283 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict);
1284 +void hmp_info_backup(Monitor *mon, const QDict *qdict);
1285 void hmp_info_cpus(Monitor *mon, const QDict *qdict);
1286 void hmp_info_block(Monitor *mon, const QDict *qdict);
1287 void hmp_info_blockstats(Monitor *mon, const QDict *qdict);
1288 @@ -86,6 +87,8 @@ void hmp_eject(Monitor *mon, const QDict *qdict);
1289 void hmp_change(Monitor *mon, const QDict *qdict);
1290 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict);
1291 void hmp_block_stream(Monitor *mon, const QDict *qdict);
1292 +void hmp_backup(Monitor *mon, const QDict *qdict);
1293 +void hmp_backup_cancel(Monitor *mon, const QDict *qdict);
1294 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
1295 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
1296 void hmp_block_job_pause(Monitor *mon, const QDict *qdict);
1297 diff --git a/qapi/block-core.json b/qapi/block-core.json
1298 index 5b9084a394..9c3c2d4917 100644
1299 --- a/qapi/block-core.json
1300 +++ b/qapi/block-core.json
1301 @@ -718,6 +718,97 @@
1302
1303
1304 ##
1305 +# @BackupStatus:
1306 +#
1307 +# Detailed backup status.
1308 +#
1309 +# @status: string describing the current backup status.
1310 +# This can be 'active', 'done', 'error'. If this field is not
1311 +# returned, no backup process has been initiated
1312 +#
1313 +# @errmsg: error message (only returned if status is 'error')
1314 +#
1315 +# @total: total amount of bytes involved in the backup process
1316 +#
1317 +# @transferred: amount of bytes already backed up.
1318 +#
1319 +# @zero-bytes: amount of 'zero' bytes detected.
1320 +#
1321 +# @start-time: time (epoch) when backup job started.
1322 +#
1323 +# @end-time: time (epoch) when backup job finished.
1324 +#
1325 +# @backup-file: backup file name
1326 +#
1327 +# @uuid: uuid for this backup job
1328 +#
1329 +##
1330 +{ 'struct': 'BackupStatus',
1331 + 'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int',
1332 + '*transferred': 'int', '*zero-bytes': 'int',
1333 + '*start-time': 'int', '*end-time': 'int',
1334 + '*backup-file': 'str', '*uuid': 'str' } }
1335 +
1336 +##
1337 +# @BackupFormat:
1338 +#
1339 +# An enumeration of supported backup formats.
1340 +#
1341 +# @vma: Proxmox vma backup format
1342 +##
1343 +{ 'enum': 'BackupFormat',
1344 + 'data': [ 'vma', 'dir' ] }
1345 +
1346 +##
1347 +# @backup:
1348 +#
1349 +# Starts a VM backup.
1350 +#
1351 +# @backup-file: the backup file name
1352 +#
1353 +# @format: format of the backup file
1354 +#
1355 +# @config-file: a configuration file to include into
1356 +# the backup archive.
1357 +#
1358 +# @speed: the maximum speed, in bytes per second
1359 +#
1360 +# @devlist: list of block device names (separated by ',', ';'
1361 +# or ':'). By default the backup includes all writable block devices.
1362 +#
1363 +# Returns: the uuid of the backup job
1364 +#
1365 +##
1366 +{ 'command': 'backup', 'data': { 'backup-file': 'str',
1367 + '*format': 'BackupFormat',
1368 + '*config-file': 'str',
1369 + '*firewall-file': 'str',
1370 + '*devlist': 'str', '*speed': 'int' },
1371 + 'returns': 'UuidInfo' }
1372 +
1373 +##
1374 +# @query-backup:
1375 +#
1376 +# Returns information about current/last backup task.
1377 +#
1378 +# Returns: @BackupStatus
1379 +#
1380 +##
1381 +{ 'command': 'query-backup', 'returns': 'BackupStatus' }
1382 +
1383 +##
1384 +# @backup-cancel:
1385 +#
1386 +# Cancel the current executing backup process.
1387 +#
1388 +# Returns: nothing on success
1389 +#
1390 +# Notes: This command succeeds even if there is no backup process running.
1391 +#
1392 +##
1393 +{ 'command': 'backup-cancel' }
1394 +
1395 +##
1396 # @BlockDeviceTimedStats:
1397 #
1398 # Statistics of a block device during a given interval of time.
1399 @@ -2549,7 +2640,7 @@
1400 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks',
1401 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qcow',
1402 'qcow2', 'qed', 'quorum', 'raw', 'rbd', 'replication', 'sheepdog',
1403 - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] }
1404 + 'ssh', 'throttle', 'vdi', 'vhdx', 'vma-drive', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] }
1405
1406 ##
1407 # @BlockdevOptionsFile:
1408 @@ -3550,6 +3641,21 @@
1409 '*tls-creds': 'str' } }
1410
1411 ##
1412 +# @BlockdevOptionsVMADrive:
1413 +#
1414 +# Driver specific block device options for VMA Drives
1415 +#
1416 +# @filename: vma-drive path
1417 +#
1418 +# @size: drive size in bytes
1419 +#
1420 +# Since: 2.9
1421 +##
1422 +{ 'struct': 'BlockdevOptionsVMADrive',
1423 + 'data': { 'filename': 'str',
1424 + 'size': 'int' } }
1425 +
1426 +##
1427 # @BlockdevOptionsThrottle:
1428 #
1429 # Driver specific block device options for the throttle driver
1430 @@ -3633,6 +3739,7 @@
1431 'throttle': 'BlockdevOptionsThrottle',
1432 'vdi': 'BlockdevOptionsGenericFormat',
1433 'vhdx': 'BlockdevOptionsGenericFormat',
1434 + 'vma-drive': 'BlockdevOptionsVMADrive',
1435 'vmdk': 'BlockdevOptionsGenericCOWFormat',
1436 'vpc': 'BlockdevOptionsGenericFormat',
1437 'vvfat': 'BlockdevOptionsVVFAT',
1438 diff --git a/qapi/common.json b/qapi/common.json
1439 index c367adc4b6..070b7b52c8 100644
1440 --- a/qapi/common.json
1441 +++ b/qapi/common.json
1442 @@ -149,3 +149,16 @@
1443 'ppc64', 'ppcemb', 'riscv32', 'riscv64', 's390x', 'sh4',
1444 'sh4eb', 'sparc', 'sparc64', 'tricore', 'unicore32',
1445 'x86_64', 'xtensa', 'xtensaeb' ] }
1446 +
1447 +##
1448 +# @UuidInfo:
1449 +#
1450 +# Guest UUID information (Universally Unique Identifier).
1451 +#
1452 +# @UUID: the UUID of the guest
1453 +#
1454 +# Since: 0.14.0
1455 +#
1456 +# Notes: If no UUID was specified for the guest, a null UUID is returned.
1457 +##
1458 +{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} }
1459 diff --git a/qapi/misc.json b/qapi/misc.json
1460 index b6ad5f028d..3dd5117fc3 100644
1461 --- a/qapi/misc.json
1462 +++ b/qapi/misc.json
1463 @@ -275,19 +275,6 @@
1464 { 'command': 'query-kvm', 'returns': 'KvmInfo' }
1465
1466 ##
1467 -# @UuidInfo:
1468 -#
1469 -# Guest UUID information (Universally Unique Identifier).
1470 -#
1471 -# @UUID: the UUID of the guest
1472 -#
1473 -# Since: 0.14.0
1474 -#
1475 -# Notes: If no UUID was specified for the guest, a null UUID is returned.
1476 -##
1477 -{ 'struct': 'UuidInfo', 'data': {'UUID': 'str'} }
1478 -
1479 -##
1480 # @query-uuid:
1481 #
1482 # Query the guest UUID information.
1483 --
1484 2.11.0
1485