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