]>
Commit | Line | Data |
---|---|---|
cbf9030a DM |
1 | Index: new/blockdev.c |
2 | =================================================================== | |
e549ff74 DM |
3 | --- new.orig/blockdev.c 2014-07-16 11:10:45.000000000 +0200 |
4 | +++ new/blockdev.c 2014-07-16 11:25:41.000000000 +0200 | |
fbe817e2 | 5 | @@ -44,6 +44,7 @@ |
cbf9030a DM |
6 | #include "qmp-commands.h" |
7 | #include "trace.h" | |
8 | #include "sysemu/arch_init.h" | |
9 | +#include "vma.h" | |
10 | ||
11 | static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); | |
12 | ||
e549ff74 | 13 | @@ -1546,7 +1547,6 @@ |
cbf9030a DM |
14 | } |
15 | } | |
16 | ||
81300c8b DM |
17 | - |
18 | static void eject_device(BlockDriverState *bs, int force, Error **errp) | |
19 | { | |
fbe817e2 | 20 | if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_EJECT, errp)) { |
e549ff74 | 21 | @@ -1871,6 +1871,437 @@ |
81300c8b DM |
22 | bdrv_put_ref_bh_schedule(bs); |
23 | } | |
24 | ||
cbf9030a DM |
25 | +/* PVE backup related function */ |
26 | + | |
27 | +static struct PVEBackupState { | |
28 | + Error *error; | |
29 | + bool cancel; | |
30 | + uuid_t uuid; | |
31 | + char uuid_str[37]; | |
32 | + int64_t speed; | |
33 | + time_t start_time; | |
34 | + time_t end_time; | |
35 | + char *backup_file; | |
36 | + VmaWriter *vmaw; | |
37 | + GList *di_list; | |
38 | + size_t total; | |
39 | + size_t transferred; | |
40 | + size_t zero_bytes; | |
41 | +} backup_state; | |
42 | + | |
43 | +typedef struct PVEBackupDevInfo { | |
44 | + BlockDriverState *bs; | |
e72ed697 | 45 | + size_t size; |
cbf9030a DM |
46 | + uint8_t dev_id; |
47 | + //bool started; | |
48 | + bool completed; | |
49 | +} PVEBackupDevInfo; | |
50 | + | |
51 | +static void pvebackup_run_next_job(void); | |
52 | + | |
e72ed697 DM |
53 | +static int pvebackup_dump_cb(void *opaque, BlockDriverState *target, |
54 | + int64_t sector_num, int n_sectors, | |
55 | + unsigned char *buf) | |
cbf9030a DM |
56 | +{ |
57 | + PVEBackupDevInfo *di = opaque; | |
58 | + | |
e72ed697 DM |
59 | + if (sector_num & 0x7f) { |
60 | + if (!backup_state.error) { | |
61 | + error_setg(&backup_state.error, | |
62 | + "got unaligned write inside backup dump " | |
63 | + "callback (sector %ld)", sector_num); | |
64 | + } | |
65 | + return -1; // not aligned to cluster size | |
66 | + } | |
cbf9030a | 67 | + |
e72ed697 DM |
68 | + int64_t cluster_num = sector_num >> 7; |
69 | + int size = n_sectors * BDRV_SECTOR_SIZE; | |
cbf9030a | 70 | + |
e72ed697 | 71 | + int ret = -1; |
cbf9030a | 72 | + |
e72ed697 DM |
73 | + if (backup_state.vmaw) { |
74 | + size_t zero_bytes = 0; | |
75 | + ret = vma_writer_write(backup_state.vmaw, di->dev_id, cluster_num, | |
76 | + buf, &zero_bytes); | |
77 | + backup_state.zero_bytes += zero_bytes; | |
78 | + } else { | |
79 | + ret = size; | |
80 | + if (!buf) { | |
81 | + backup_state.zero_bytes += size; | |
cbf9030a DM |
82 | + } |
83 | + } | |
84 | + | |
e72ed697 DM |
85 | + backup_state.transferred += size; |
86 | + | |
87 | + return ret; | |
cbf9030a DM |
88 | +} |
89 | + | |
90 | +static void pvebackup_cleanup(void) | |
91 | +{ | |
b38014b6 DM |
92 | + backup_state.end_time = time(NULL); |
93 | + | |
cbf9030a | 94 | + if (backup_state.vmaw) { |
cbf9030a | 95 | + Error *local_err = NULL; |
cbf9030a DM |
96 | + vma_writer_close(backup_state.vmaw, &local_err); |
97 | + error_propagate(&backup_state.error, local_err); | |
98 | + backup_state.vmaw = NULL; | |
99 | + } | |
100 | + | |
101 | + if (backup_state.di_list) { | |
102 | + GList *l = backup_state.di_list; | |
103 | + while (l) { | |
104 | + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data; | |
105 | + l = g_list_next(l); | |
106 | + g_free(di); | |
107 | + } | |
108 | + g_list_free(backup_state.di_list); | |
109 | + backup_state.di_list = NULL; | |
110 | + } | |
111 | +} | |
112 | + | |
113 | +static void pvebackup_complete_cb(void *opaque, int ret) | |
114 | +{ | |
115 | + PVEBackupDevInfo *di = opaque; | |
116 | + | |
117 | + assert(backup_state.vmaw); | |
118 | + | |
119 | + di->completed = true; | |
81300c8b | 120 | + |
be73ac8a DM |
121 | + if (ret < 0 && !backup_state.error) { |
122 | + error_setg(&backup_state.error, "job failed with err %d - %s", | |
123 | + ret, strerror(-ret)); | |
124 | + } | |
125 | + | |
81300c8b DM |
126 | + BlockDriverState *bs = di->bs; |
127 | + | |
b07588bd | 128 | + di->bs = NULL; |
cbf9030a DM |
129 | + |
130 | + vma_writer_close_stream(backup_state.vmaw, di->dev_id); | |
131 | + | |
81300c8b DM |
132 | + block_job_cb(bs, ret); |
133 | + | |
cbf9030a DM |
134 | + if (!backup_state.cancel) { |
135 | + pvebackup_run_next_job(); | |
136 | + } | |
137 | +} | |
138 | + | |
0c5f6a91 | 139 | +static void pvebackup_cancel(void *opaque) |
cbf9030a DM |
140 | +{ |
141 | + backup_state.cancel = true; | |
142 | + | |
143 | + if (!backup_state.error) { | |
144 | + error_setg(&backup_state.error, "backup cancelled"); | |
145 | + } | |
146 | + | |
147 | + /* drain all i/o (awake jobs waiting for aio) */ | |
148 | + bdrv_drain_all(); | |
149 | + | |
cbf9030a DM |
150 | + GList *l = backup_state.di_list; |
151 | + while (l) { | |
152 | + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data; | |
153 | + l = g_list_next(l); | |
e72ed697 | 154 | + if (!di->completed && di->bs) { |
b07588bd DM |
155 | + BlockJob *job = di->bs->job; |
156 | + if (job) { | |
157 | + if (!di->completed) { | |
158 | + block_job_cancel_sync(job); | |
159 | + } | |
cbf9030a DM |
160 | + } |
161 | + } | |
162 | + } | |
163 | + | |
164 | + pvebackup_cleanup(); | |
165 | +} | |
166 | + | |
167 | +void qmp_backup_cancel(Error **errp) | |
168 | +{ | |
0c5f6a91 DM |
169 | + Coroutine *co = qemu_coroutine_create(pvebackup_cancel); |
170 | + qemu_coroutine_enter(co, NULL); | |
171 | + | |
172 | + while (backup_state.vmaw) { | |
e549ff74 DM |
173 | + /* vma writer use main aio context */ |
174 | + aio_poll(qemu_get_aio_context(), true); | |
0c5f6a91 | 175 | + } |
cbf9030a DM |
176 | +} |
177 | + | |
178 | +static void pvebackup_run_next_job(void) | |
179 | +{ | |
180 | + GList *l = backup_state.di_list; | |
181 | + while (l) { | |
182 | + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data; | |
183 | + l = g_list_next(l); | |
b07588bd DM |
184 | + if (!di->completed && di->bs && di->bs->job) { |
185 | + BlockJob *job = di->bs->job; | |
bd240f3b | 186 | + if (block_job_is_paused(job)) { |
cbf9030a DM |
187 | + bool cancel = backup_state.error || backup_state.cancel; |
188 | + if (cancel) { | |
bd240f3b | 189 | + block_job_cancel(job); |
cbf9030a | 190 | + } else { |
bd240f3b | 191 | + block_job_resume(job); |
cbf9030a DM |
192 | + } |
193 | + } | |
194 | + return; | |
195 | + } | |
196 | + } | |
197 | + | |
198 | + pvebackup_cleanup(); | |
199 | +} | |
200 | + | |
201 | +char *qmp_backup(const char *backup_file, bool has_format, | |
202 | + BackupFormat format, | |
203 | + bool has_config_file, const char *config_file, | |
204 | + bool has_devlist, const char *devlist, | |
205 | + bool has_speed, int64_t speed, Error **errp) | |
206 | +{ | |
207 | + BlockDriverState *bs; | |
208 | + Error *local_err = NULL; | |
209 | + uuid_t uuid; | |
210 | + VmaWriter *vmaw = NULL; | |
211 | + gchar **devs = NULL; | |
212 | + GList *di_list = NULL; | |
213 | + GList *l; | |
214 | + | |
215 | + if (backup_state.di_list) { | |
216 | + error_set(errp, ERROR_CLASS_GENERIC_ERROR, | |
217 | + "previous backup not finished"); | |
218 | + return NULL; | |
219 | + } | |
220 | + | |
221 | + /* Todo: try to auto-detect format based on file name */ | |
222 | + format = has_format ? format : BACKUP_FORMAT_VMA; | |
223 | + | |
224 | + if (format != BACKUP_FORMAT_VMA) { | |
225 | + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "unknown backup format"); | |
226 | + return NULL; | |
227 | + } | |
228 | + | |
229 | + if (has_devlist) { | |
230 | + devs = g_strsplit_set(devlist, ",;:", -1); | |
231 | + | |
232 | + gchar **d = devs; | |
233 | + while (d && *d) { | |
234 | + bs = bdrv_find(*d); | |
235 | + if (bs) { | |
236 | + if (bdrv_is_read_only(bs)) { | |
237 | + error_set(errp, QERR_DEVICE_IS_READ_ONLY, *d); | |
238 | + goto err; | |
239 | + } | |
240 | + if (!bdrv_is_inserted(bs)) { | |
241 | + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, *d); | |
242 | + goto err; | |
243 | + } | |
244 | + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1); | |
245 | + di->bs = bs; | |
246 | + di_list = g_list_append(di_list, di); | |
247 | + } else { | |
248 | + error_set(errp, QERR_DEVICE_NOT_FOUND, *d); | |
249 | + goto err; | |
250 | + } | |
251 | + d++; | |
252 | + } | |
253 | + | |
254 | + } else { | |
255 | + | |
256 | + bs = NULL; | |
257 | + while ((bs = bdrv_next(bs))) { | |
258 | + | |
259 | + if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) { | |
260 | + continue; | |
261 | + } | |
262 | + | |
263 | + PVEBackupDevInfo *di = g_new0(PVEBackupDevInfo, 1); | |
264 | + di->bs = bs; | |
265 | + di_list = g_list_append(di_list, di); | |
266 | + } | |
267 | + } | |
268 | + | |
269 | + if (!di_list) { | |
270 | + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "empty device list"); | |
271 | + goto err; | |
272 | + } | |
273 | + | |
e72ed697 DM |
274 | + size_t total = 0; |
275 | + | |
cbf9030a DM |
276 | + l = di_list; |
277 | + while (l) { | |
278 | + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data; | |
279 | + l = g_list_next(l); | |
fbe817e2 | 280 | + if (bdrv_op_is_blocked(di->bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) { |
cbf9030a DM |
281 | + goto err; |
282 | + } | |
e72ed697 DM |
283 | + |
284 | + ssize_t size = bdrv_getlength(di->bs); | |
285 | + if (size < 0) { | |
286 | + error_setg_errno(errp, -di->size, "bdrv_getlength failed"); | |
287 | + goto err; | |
288 | + } | |
289 | + di->size = size; | |
290 | + total += size; | |
cbf9030a DM |
291 | + } |
292 | + | |
293 | + uuid_generate(uuid); | |
294 | + | |
295 | + vmaw = vma_writer_create(backup_file, uuid, &local_err); | |
296 | + if (!vmaw) { | |
fbe817e2 | 297 | + if (local_err) { |
cbf9030a DM |
298 | + error_propagate(errp, local_err); |
299 | + } | |
300 | + goto err; | |
301 | + } | |
302 | + | |
303 | + /* register all devices for vma writer */ | |
304 | + l = di_list; | |
305 | + while (l) { | |
306 | + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data; | |
307 | + l = g_list_next(l); | |
308 | + | |
cbf9030a | 309 | + const char *devname = bdrv_get_device_name(di->bs); |
e72ed697 | 310 | + di->dev_id = vma_writer_register_stream(vmaw, devname, di->size); |
cbf9030a DM |
311 | + if (di->dev_id <= 0) { |
312 | + error_set(errp, ERROR_CLASS_GENERIC_ERROR, | |
313 | + "register_stream failed"); | |
314 | + goto err; | |
315 | + } | |
316 | + } | |
317 | + | |
318 | + /* add configuration file to archive */ | |
319 | + if (has_config_file) { | |
320 | + char *cdata = NULL; | |
321 | + gsize clen = 0; | |
322 | + GError *err = NULL; | |
323 | + if (!g_file_get_contents(config_file, &cdata, &clen, &err)) { | |
324 | + error_setg(errp, "unable to read file '%s'", config_file); | |
325 | + goto err; | |
326 | + } | |
327 | + | |
328 | + const char *basename = g_path_get_basename(config_file); | |
329 | + if (vma_writer_add_config(vmaw, basename, cdata, clen) != 0) { | |
330 | + error_setg(errp, "unable to add config data to vma archive"); | |
331 | + g_free(cdata); | |
332 | + goto err; | |
333 | + } | |
334 | + g_free(cdata); | |
335 | + } | |
336 | + | |
337 | + /* initialize global backup_state now */ | |
338 | + | |
339 | + backup_state.cancel = false; | |
340 | + | |
341 | + if (backup_state.error) { | |
342 | + error_free(backup_state.error); | |
343 | + backup_state.error = NULL; | |
344 | + } | |
345 | + | |
346 | + backup_state.speed = (has_speed && speed > 0) ? speed : 0; | |
347 | + | |
348 | + backup_state.start_time = time(NULL); | |
349 | + backup_state.end_time = 0; | |
350 | + | |
351 | + if (backup_state.backup_file) { | |
352 | + g_free(backup_state.backup_file); | |
353 | + } | |
354 | + backup_state.backup_file = g_strdup(backup_file); | |
355 | + | |
356 | + backup_state.vmaw = vmaw; | |
357 | + | |
358 | + uuid_copy(backup_state.uuid, uuid); | |
359 | + uuid_unparse_lower(uuid, backup_state.uuid_str); | |
360 | + | |
361 | + backup_state.di_list = di_list; | |
362 | + | |
e72ed697 DM |
363 | + backup_state.total = total; |
364 | + backup_state.transferred = 0; | |
365 | + backup_state.zero_bytes = 0; | |
cbf9030a DM |
366 | + |
367 | + /* start all jobs (paused state) */ | |
368 | + l = di_list; | |
369 | + while (l) { | |
370 | + PVEBackupDevInfo *di = (PVEBackupDevInfo *)l->data; | |
371 | + l = g_list_next(l); | |
372 | + | |
373 | + backup_start(di->bs, NULL, speed, MIRROR_SYNC_MODE_FULL, | |
374 | + BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT, | |
bd240f3b DM |
375 | + pvebackup_dump_cb, pvebackup_complete_cb, di, |
376 | + true, &local_err); | |
cbf9030a DM |
377 | + if (local_err != NULL) { |
378 | + error_setg(&backup_state.error, "backup_job_create failed"); | |
0c5f6a91 | 379 | + pvebackup_cancel(NULL); |
cbf9030a DM |
380 | + } |
381 | + } | |
382 | + | |
383 | + if (!backup_state.error) { | |
384 | + pvebackup_run_next_job(); // run one job | |
385 | + } | |
386 | + | |
387 | + return g_strdup(backup_state.uuid_str); | |
388 | + | |
389 | +err: | |
390 | + | |
391 | + l = di_list; | |
392 | + while (l) { | |
393 | + g_free(l->data); | |
394 | + l = g_list_next(l); | |
395 | + } | |
396 | + g_list_free(di_list); | |
397 | + | |
398 | + if (devs) { | |
399 | + g_strfreev(devs); | |
400 | + } | |
401 | + | |
402 | + if (vmaw) { | |
403 | + Error *err = NULL; | |
404 | + vma_writer_close(vmaw, &err); | |
405 | + unlink(backup_file); | |
406 | + } | |
407 | + | |
408 | + return NULL; | |
409 | +} | |
410 | + | |
411 | +BackupStatus *qmp_query_backup(Error **errp) | |
412 | +{ | |
413 | + BackupStatus *info = g_malloc0(sizeof(*info)); | |
414 | + | |
415 | + if (!backup_state.start_time) { | |
416 | + /* not started, return {} */ | |
417 | + return info; | |
418 | + } | |
419 | + | |
420 | + info->has_status = true; | |
421 | + info->has_start_time = true; | |
422 | + info->start_time = backup_state.start_time; | |
423 | + | |
424 | + if (backup_state.backup_file) { | |
425 | + info->has_backup_file = true; | |
426 | + info->backup_file = g_strdup(backup_state.backup_file); | |
427 | + } | |
428 | + | |
429 | + info->has_uuid = true; | |
430 | + info->uuid = g_strdup(backup_state.uuid_str); | |
431 | + | |
432 | + if (backup_state.end_time) { | |
433 | + if (backup_state.error) { | |
434 | + info->status = g_strdup("error"); | |
435 | + info->has_errmsg = true; | |
436 | + info->errmsg = g_strdup(error_get_pretty(backup_state.error)); | |
437 | + } else { | |
438 | + info->status = g_strdup("done"); | |
439 | + } | |
440 | + info->has_end_time = true; | |
441 | + info->end_time = backup_state.end_time; | |
442 | + } else { | |
443 | + info->status = g_strdup("active"); | |
444 | + } | |
445 | + | |
cbf9030a DM |
446 | + info->has_total = true; |
447 | + info->total = backup_state.total; | |
448 | + info->has_zero_bytes = true; | |
449 | + info->zero_bytes = backup_state.zero_bytes; | |
450 | + info->has_transferred = true; | |
451 | + info->transferred = backup_state.transferred; | |
452 | + | |
453 | + return info; | |
454 | +} | |
81300c8b | 455 | + |
e549ff74 DM |
456 | void qmp_block_stream(const char *device, |
457 | bool has_base, const char *base, | |
458 | bool has_backing_file, const char *backing_file, | |
cbf9030a DM |
459 | Index: new/hmp-commands.hx |
460 | =================================================================== | |
e549ff74 DM |
461 | --- new.orig/hmp-commands.hx 2014-07-16 10:22:25.000000000 +0200 |
462 | +++ new/hmp-commands.hx 2014-07-16 11:17:01.000000000 +0200 | |
9a1821d4 | 463 | @@ -88,6 +88,35 @@ |
cbf9030a DM |
464 | Copy data from a backing file into a block device. |
465 | ETEXI | |
466 | ||
467 | + { | |
468 | + .name = "backup", | |
469 | + .args_type = "backupfile:s,speed:o?,devlist:s?", | |
470 | + .params = "backupfile [speed [devlist]]", | |
471 | + .help = "create a VM Backup.", | |
472 | + .mhandler.cmd = hmp_backup, | |
473 | + }, | |
474 | + | |
475 | +STEXI | |
476 | +@item backup | |
477 | +@findex backup | |
478 | +Create a VM backup. | |
479 | +ETEXI | |
480 | + | |
481 | + { | |
482 | + .name = "backup_cancel", | |
483 | + .args_type = "", | |
484 | + .params = "", | |
485 | + .help = "cancel the current VM backup", | |
486 | + .mhandler.cmd = hmp_backup_cancel, | |
487 | + }, | |
488 | + | |
489 | +STEXI | |
490 | +@item backup_cancel | |
491 | +@findex backup_cancel | |
492 | +Cancel the current VM backup. | |
493 | + | |
494 | +ETEXI | |
495 | + | |
496 | { | |
497 | .name = "block_job_set_speed", | |
498 | .args_type = "device:B,speed:o", | |
fbe817e2 | 499 | @@ -1764,6 +1793,8 @@ |
cbf9030a DM |
500 | show CPU statistics |
501 | @item info usernet | |
502 | show user network stack connection states | |
503 | +@item info backup | |
504 | +show backup status | |
505 | @item info migrate | |
506 | show migration status | |
507 | @item info migrate_capabilities | |
508 | Index: new/hmp.c | |
509 | =================================================================== | |
e549ff74 DM |
510 | --- new.orig/hmp.c 2014-07-16 10:22:25.000000000 +0200 |
511 | +++ new/hmp.c 2014-07-16 11:17:01.000000000 +0200 | |
512 | @@ -137,6 +137,44 @@ | |
cbf9030a DM |
513 | qapi_free_MouseInfoList(mice_list); |
514 | } | |
515 | ||
516 | +void hmp_info_backup(Monitor *mon, const QDict *qdict) | |
517 | +{ | |
518 | + BackupStatus *info; | |
519 | + | |
520 | + info = qmp_query_backup(NULL); | |
521 | + if (info->has_status) { | |
522 | + if (info->has_errmsg) { | |
523 | + monitor_printf(mon, "Backup status: %s - %s\n", | |
524 | + info->status, info->errmsg); | |
525 | + } else { | |
526 | + monitor_printf(mon, "Backup status: %s\n", info->status); | |
527 | + } | |
528 | + } | |
219f966c | 529 | + |
cbf9030a | 530 | + if (info->has_backup_file) { |
219f966c DM |
531 | + monitor_printf(mon, "Start time: %s", ctime(&info->start_time)); |
532 | + if (info->end_time) { | |
533 | + monitor_printf(mon, "End time: %s", ctime(&info->end_time)); | |
534 | + } | |
535 | + | |
cbf9030a DM |
536 | + int per = (info->has_total && info->total && |
537 | + info->has_transferred && info->transferred) ? | |
538 | + (info->transferred * 100)/info->total : 0; | |
539 | + int zero_per = (info->has_total && info->total && | |
540 | + info->has_zero_bytes && info->zero_bytes) ? | |
541 | + (info->zero_bytes * 100)/info->total : 0; | |
542 | + monitor_printf(mon, "Backup file: %s\n", info->backup_file); | |
543 | + monitor_printf(mon, "Backup uuid: %s\n", info->uuid); | |
544 | + monitor_printf(mon, "Total size: %zd\n", info->total); | |
545 | + monitor_printf(mon, "Transferred bytes: %zd (%d%%)\n", | |
546 | + info->transferred, per); | |
547 | + monitor_printf(mon, "Zero bytes: %zd (%d%%)\n", | |
548 | + info->zero_bytes, zero_per); | |
549 | + } | |
550 | + | |
551 | + qapi_free_BackupStatus(info); | |
552 | +} | |
553 | + | |
554 | void hmp_info_migrate(Monitor *mon, const QDict *qdict) | |
555 | { | |
556 | MigrationInfo *info; | |
e549ff74 | 557 | @@ -1210,6 +1248,29 @@ |
219f966c | 558 | |
cbf9030a DM |
559 | hmp_handle_error(mon, &error); |
560 | } | |
219f966c | 561 | + |
cbf9030a DM |
562 | +void hmp_backup_cancel(Monitor *mon, const QDict *qdict) |
563 | +{ | |
219f966c | 564 | + Error *error = NULL; |
cbf9030a | 565 | + |
219f966c | 566 | + qmp_backup_cancel(&error); |
cbf9030a | 567 | + |
219f966c | 568 | + hmp_handle_error(mon, &error); |
cbf9030a DM |
569 | +} |
570 | + | |
571 | +void hmp_backup(Monitor *mon, const QDict *qdict) | |
572 | +{ | |
219f966c DM |
573 | + Error *error = NULL; |
574 | + | |
575 | + const char *backup_file = qdict_get_str(qdict, "backupfile"); | |
cbf9030a DM |
576 | + const char *devlist = qdict_get_try_str(qdict, "devlist"); |
577 | + int64_t speed = qdict_get_try_int(qdict, "speed", 0); | |
578 | + | |
cbf9030a | 579 | + qmp_backup(backup_file, true, BACKUP_FORMAT_VMA, false, NULL, !!devlist, |
219f966c | 580 | + devlist, qdict_haskey(qdict, "speed"), speed, &error); |
cbf9030a | 581 | + |
219f966c | 582 | + hmp_handle_error(mon, &error); |
cbf9030a | 583 | +} |
219f966c | 584 | |
cbf9030a DM |
585 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) |
586 | { | |
cbf9030a DM |
587 | Index: new/hmp.h |
588 | =================================================================== | |
e549ff74 DM |
589 | --- new.orig/hmp.h 2014-07-16 10:22:25.000000000 +0200 |
590 | +++ new/hmp.h 2014-07-16 11:17:01.000000000 +0200 | |
fbe817e2 | 591 | @@ -29,6 +29,7 @@ |
cbf9030a DM |
592 | void hmp_info_migrate(Monitor *mon, const QDict *qdict); |
593 | void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict); | |
594 | void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict); | |
595 | +void hmp_info_backup(Monitor *mon, const QDict *qdict); | |
596 | void hmp_info_cpus(Monitor *mon, const QDict *qdict); | |
597 | void hmp_info_block(Monitor *mon, const QDict *qdict); | |
598 | void hmp_info_blockstats(Monitor *mon, const QDict *qdict); | |
fbe817e2 | 599 | @@ -70,6 +71,8 @@ |
cbf9030a DM |
600 | void hmp_change(Monitor *mon, const QDict *qdict); |
601 | void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict); | |
602 | void hmp_block_stream(Monitor *mon, const QDict *qdict); | |
603 | +void hmp_backup(Monitor *mon, const QDict *qdict); | |
604 | +void hmp_backup_cancel(Monitor *mon, const QDict *qdict); | |
605 | void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict); | |
606 | void hmp_block_job_cancel(Monitor *mon, const QDict *qdict); | |
607 | void hmp_block_job_pause(Monitor *mon, const QDict *qdict); | |
608 | Index: new/monitor.c | |
609 | =================================================================== | |
e549ff74 DM |
610 | --- new.orig/monitor.c 2014-07-16 10:22:25.000000000 +0200 |
611 | +++ new/monitor.c 2014-07-16 11:17:01.000000000 +0200 | |
612 | @@ -2848,6 +2848,13 @@ | |
cbf9030a DM |
613 | }, |
614 | #endif | |
615 | { | |
616 | + .name = "backup", | |
617 | + .args_type = "", | |
618 | + .params = "", | |
619 | + .help = "show backup status", | |
620 | + .mhandler.cmd = hmp_info_backup, | |
621 | + }, | |
622 | + { | |
623 | .name = "migrate", | |
624 | .args_type = "", | |
625 | .params = "", | |
626 | Index: new/qapi-schema.json | |
627 | =================================================================== | |
e549ff74 DM |
628 | --- new.orig/qapi-schema.json 2014-07-16 10:22:25.000000000 +0200 |
629 | +++ new/qapi-schema.json 2014-07-16 11:17:01.000000000 +0200 | |
630 | @@ -349,6 +349,95 @@ | |
cbf9030a DM |
631 | ## |
632 | { 'command': 'query-events', 'returns': ['EventInfo'] } | |
633 | ||
634 | +# @BackupStatus: | |
635 | +# | |
636 | +# Detailed backup status. | |
637 | +# | |
638 | +# @status: #optional string describing the current backup status. | |
639 | +# This can be 'active', 'done', 'error'. If this field is not | |
640 | +# returned, no backup process has been initiated | |
641 | +# | |
642 | +# @errmsg: #optional error message (only returned if status is 'error') | |
643 | +# | |
644 | +# @total: #optional total amount of bytes involved in the backup process | |
645 | +# | |
646 | +# @transferred: #optional amount of bytes already backed up. | |
647 | +# | |
648 | +# @zero-bytes: #optional amount of 'zero' bytes detected. | |
649 | +# | |
650 | +# @start-time: #optional time (epoch) when backup job started. | |
651 | +# | |
652 | +# @end-time: #optional time (epoch) when backup job finished. | |
653 | +# | |
654 | +# @backupfile: #optional backup file name | |
655 | +# | |
656 | +# @uuid: #optional uuid for this backup job | |
657 | +# | |
658 | +## | |
659 | +{ 'type': 'BackupStatus', | |
660 | + 'data': {'*status': 'str', '*errmsg': 'str', '*total': 'int', | |
661 | + '*transferred': 'int', '*zero-bytes': 'int', | |
662 | + '*start-time': 'int', '*end-time': 'int', | |
663 | + '*backup-file': 'str', '*uuid': 'str' } } | |
664 | + | |
665 | +## | |
666 | +# @BackupFormat | |
667 | +# | |
668 | +# An enumeration of supported backup formats. | |
669 | +# | |
670 | +# @vma: Proxmox vma backup format | |
671 | +## | |
672 | +{ 'enum': 'BackupFormat', | |
673 | + 'data': [ 'vma' ] } | |
674 | + | |
675 | +## | |
676 | +# @backup: | |
677 | +# | |
678 | +# Starts a VM backup. | |
679 | +# | |
680 | +# @backup-file: the backup file name | |
681 | +# | |
682 | +# @format: format of the backup file | |
683 | +# | |
684 | +# @config-filename: #optional name of a configuration file to include into | |
685 | +# the backup archive. | |
686 | +# | |
687 | +# @speed: #optional the maximum speed, in bytes per second | |
688 | +# | |
689 | +# @devlist: #optional list of block device names (separated by ',', ';' | |
690 | +# or ':'). By default the backup includes all writable block devices. | |
691 | +# | |
692 | +# Returns: the uuid of the backup job | |
693 | +# | |
694 | +## | |
695 | +{ 'command': 'backup', 'data': { 'backup-file': 'str', | |
696 | + '*format': 'BackupFormat', | |
697 | + '*config-file': 'str', | |
698 | + '*devlist': 'str', '*speed': 'int' }, | |
699 | + 'returns': 'str' } | |
700 | + | |
701 | +## | |
702 | +# @query-backup | |
703 | +# | |
704 | +# Returns information about current/last backup task. | |
705 | +# | |
706 | +# Returns: @BackupStatus | |
707 | +# | |
708 | +## | |
709 | +{ 'command': 'query-backup', 'returns': 'BackupStatus' } | |
710 | + | |
711 | +## | |
712 | +# @backup-cancel | |
713 | +# | |
714 | +# Cancel the current executing backup process. | |
715 | +# | |
716 | +# Returns: nothing on success | |
717 | +# | |
718 | +# Notes: This command succeeds even if there is no backup process running. | |
719 | +# | |
720 | +## | |
721 | +{ 'command': 'backup-cancel' } | |
722 | + | |
723 | ## | |
724 | # @MigrationStats | |
725 | # | |
726 | Index: new/qmp-commands.hx | |
727 | =================================================================== | |
e549ff74 DM |
728 | --- new.orig/qmp-commands.hx 2014-07-16 10:22:25.000000000 +0200 |
729 | +++ new/qmp-commands.hx 2014-07-16 11:17:01.000000000 +0200 | |
730 | @@ -1098,6 +1098,24 @@ | |
cbf9030a DM |
731 | EQMP |
732 | ||
733 | { | |
734 | + .name = "backup", | |
735 | + .args_type = "backup-file:s,format:s?,config-file:F?,speed:o?,devlist:s?", | |
736 | + .mhandler.cmd_new = qmp_marshal_input_backup, | |
737 | + }, | |
738 | + | |
739 | + { | |
740 | + .name = "backup-cancel", | |
741 | + .args_type = "", | |
742 | + .mhandler.cmd_new = qmp_marshal_input_backup_cancel, | |
743 | + }, | |
744 | + | |
745 | + { | |
746 | + .name = "query-backup", | |
747 | + .args_type = "", | |
748 | + .mhandler.cmd_new = qmp_marshal_input_query_backup, | |
749 | + }, | |
750 | + | |
751 | + { | |
752 | .name = "block-job-set-speed", | |
753 | .args_type = "device:B,speed:o", | |
754 | .mhandler.cmd_new = qmp_marshal_input_block_job_set_speed, |