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