]> git.proxmox.com Git - mirror_qemu.git/blob - block/backup.c
block/backup: centralize copy_bitmap initialization
[mirror_qemu.git] / block / backup.c
1 /*
2 * QEMU backup
3 *
4 * Copyright (C) 2013 Proxmox Server Solutions
5 *
6 * Authors:
7 * Dietmar Maurer (dietmar@proxmox.com)
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 *
12 */
13
14 #include "qemu/osdep.h"
15
16 #include "trace.h"
17 #include "block/block.h"
18 #include "block/block_int.h"
19 #include "block/blockjob_int.h"
20 #include "block/block_backup.h"
21 #include "qapi/error.h"
22 #include "qapi/qmp/qerror.h"
23 #include "qemu/ratelimit.h"
24 #include "qemu/cutils.h"
25 #include "sysemu/block-backend.h"
26 #include "qemu/bitmap.h"
27 #include "qemu/error-report.h"
28
29 #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16)
30
31 typedef struct CowRequest {
32 int64_t start_byte;
33 int64_t end_byte;
34 QLIST_ENTRY(CowRequest) list;
35 CoQueue wait_queue; /* coroutines blocked on this request */
36 } CowRequest;
37
38 typedef struct BackupBlockJob {
39 BlockJob common;
40 BlockBackend *target;
41
42 BdrvDirtyBitmap *sync_bitmap;
43 BdrvDirtyBitmap *copy_bitmap;
44
45 MirrorSyncMode sync_mode;
46 BitmapSyncMode bitmap_mode;
47 BlockdevOnError on_source_error;
48 BlockdevOnError on_target_error;
49 CoRwlock flush_rwlock;
50 uint64_t len;
51 uint64_t bytes_read;
52 int64_t cluster_size;
53 bool compress;
54 NotifierWithReturn before_write;
55 QLIST_HEAD(, CowRequest) inflight_reqs;
56
57 bool use_copy_range;
58 int64_t copy_range_size;
59
60 bool serialize_target_writes;
61 } BackupBlockJob;
62
63 static const BlockJobDriver backup_job_driver;
64
65 /* See if in-flight requests overlap and wait for them to complete */
66 static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job,
67 int64_t start,
68 int64_t end)
69 {
70 CowRequest *req;
71 bool retry;
72
73 do {
74 retry = false;
75 QLIST_FOREACH(req, &job->inflight_reqs, list) {
76 if (end > req->start_byte && start < req->end_byte) {
77 qemu_co_queue_wait(&req->wait_queue, NULL);
78 retry = true;
79 break;
80 }
81 }
82 } while (retry);
83 }
84
85 /* Keep track of an in-flight request */
86 static void cow_request_begin(CowRequest *req, BackupBlockJob *job,
87 int64_t start, int64_t end)
88 {
89 req->start_byte = start;
90 req->end_byte = end;
91 qemu_co_queue_init(&req->wait_queue);
92 QLIST_INSERT_HEAD(&job->inflight_reqs, req, list);
93 }
94
95 /* Forget about a completed request */
96 static void cow_request_end(CowRequest *req)
97 {
98 QLIST_REMOVE(req, list);
99 qemu_co_queue_restart_all(&req->wait_queue);
100 }
101
102 /* Copy range to target with a bounce buffer and return the bytes copied. If
103 * error occurred, return a negative error number */
104 static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,
105 int64_t start,
106 int64_t end,
107 bool is_write_notifier,
108 bool *error_is_read,
109 void **bounce_buffer)
110 {
111 int ret;
112 BlockBackend *blk = job->common.blk;
113 int nbytes;
114 int read_flags = is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0;
115 int write_flags = job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0;
116
117 assert(QEMU_IS_ALIGNED(start, job->cluster_size));
118 bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size);
119 nbytes = MIN(job->cluster_size, job->len - start);
120 if (!*bounce_buffer) {
121 *bounce_buffer = blk_blockalign(blk, job->cluster_size);
122 }
123
124 ret = blk_co_pread(blk, start, nbytes, *bounce_buffer, read_flags);
125 if (ret < 0) {
126 trace_backup_do_cow_read_fail(job, start, ret);
127 if (error_is_read) {
128 *error_is_read = true;
129 }
130 goto fail;
131 }
132
133 if (buffer_is_zero(*bounce_buffer, nbytes)) {
134 ret = blk_co_pwrite_zeroes(job->target, start,
135 nbytes, write_flags | BDRV_REQ_MAY_UNMAP);
136 } else {
137 ret = blk_co_pwrite(job->target, start,
138 nbytes, *bounce_buffer, write_flags |
139 (job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0));
140 }
141 if (ret < 0) {
142 trace_backup_do_cow_write_fail(job, start, ret);
143 if (error_is_read) {
144 *error_is_read = false;
145 }
146 goto fail;
147 }
148
149 return nbytes;
150 fail:
151 bdrv_set_dirty_bitmap(job->copy_bitmap, start, job->cluster_size);
152 return ret;
153
154 }
155
156 /* Copy range to target and return the bytes copied. If error occurred, return a
157 * negative error number. */
158 static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job,
159 int64_t start,
160 int64_t end,
161 bool is_write_notifier)
162 {
163 int ret;
164 int nr_clusters;
165 BlockBackend *blk = job->common.blk;
166 int nbytes;
167 int read_flags = is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0;
168 int write_flags = job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0;
169
170 assert(QEMU_IS_ALIGNED(job->copy_range_size, job->cluster_size));
171 assert(QEMU_IS_ALIGNED(start, job->cluster_size));
172 nbytes = MIN(job->copy_range_size, end - start);
173 nr_clusters = DIV_ROUND_UP(nbytes, job->cluster_size);
174 bdrv_reset_dirty_bitmap(job->copy_bitmap, start,
175 job->cluster_size * nr_clusters);
176 ret = blk_co_copy_range(blk, start, job->target, start, nbytes,
177 read_flags, write_flags);
178 if (ret < 0) {
179 trace_backup_do_cow_copy_range_fail(job, start, ret);
180 bdrv_set_dirty_bitmap(job->copy_bitmap, start,
181 job->cluster_size * nr_clusters);
182 return ret;
183 }
184
185 return nbytes;
186 }
187
188 static int coroutine_fn backup_do_cow(BackupBlockJob *job,
189 int64_t offset, uint64_t bytes,
190 bool *error_is_read,
191 bool is_write_notifier)
192 {
193 CowRequest cow_request;
194 int ret = 0;
195 int64_t start, end; /* bytes */
196 void *bounce_buffer = NULL;
197
198 qemu_co_rwlock_rdlock(&job->flush_rwlock);
199
200 start = QEMU_ALIGN_DOWN(offset, job->cluster_size);
201 end = QEMU_ALIGN_UP(bytes + offset, job->cluster_size);
202
203 trace_backup_do_cow_enter(job, start, offset, bytes);
204
205 wait_for_overlapping_requests(job, start, end);
206 cow_request_begin(&cow_request, job, start, end);
207
208 while (start < end) {
209 int64_t dirty_end;
210
211 if (!bdrv_dirty_bitmap_get(job->copy_bitmap, start)) {
212 trace_backup_do_cow_skip(job, start);
213 start += job->cluster_size;
214 continue; /* already copied */
215 }
216
217 dirty_end = bdrv_dirty_bitmap_next_zero(job->copy_bitmap, start,
218 (end - start));
219 if (dirty_end < 0) {
220 dirty_end = end;
221 }
222
223 trace_backup_do_cow_process(job, start);
224
225 if (job->use_copy_range) {
226 ret = backup_cow_with_offload(job, start, dirty_end,
227 is_write_notifier);
228 if (ret < 0) {
229 job->use_copy_range = false;
230 }
231 }
232 if (!job->use_copy_range) {
233 ret = backup_cow_with_bounce_buffer(job, start, dirty_end,
234 is_write_notifier,
235 error_is_read, &bounce_buffer);
236 }
237 if (ret < 0) {
238 break;
239 }
240
241 /* Publish progress, guest I/O counts as progress too. Note that the
242 * offset field is an opaque progress value, it is not a disk offset.
243 */
244 start += ret;
245 job->bytes_read += ret;
246 job_progress_update(&job->common.job, ret);
247 ret = 0;
248 }
249
250 if (bounce_buffer) {
251 qemu_vfree(bounce_buffer);
252 }
253
254 cow_request_end(&cow_request);
255
256 trace_backup_do_cow_return(job, offset, bytes, ret);
257
258 qemu_co_rwlock_unlock(&job->flush_rwlock);
259
260 return ret;
261 }
262
263 static int coroutine_fn backup_before_write_notify(
264 NotifierWithReturn *notifier,
265 void *opaque)
266 {
267 BackupBlockJob *job = container_of(notifier, BackupBlockJob, before_write);
268 BdrvTrackedRequest *req = opaque;
269
270 assert(req->bs == blk_bs(job->common.blk));
271 assert(QEMU_IS_ALIGNED(req->offset, BDRV_SECTOR_SIZE));
272 assert(QEMU_IS_ALIGNED(req->bytes, BDRV_SECTOR_SIZE));
273
274 return backup_do_cow(job, req->offset, req->bytes, NULL, true);
275 }
276
277 static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret)
278 {
279 BdrvDirtyBitmap *bm;
280 BlockDriverState *bs = blk_bs(job->common.blk);
281 bool sync = (((ret == 0) || (job->bitmap_mode == BITMAP_SYNC_MODE_ALWAYS)) \
282 && (job->bitmap_mode != BITMAP_SYNC_MODE_NEVER));
283
284 if (sync) {
285 /*
286 * We succeeded, or we always intended to sync the bitmap.
287 * Delete this bitmap and install the child.
288 */
289 bm = bdrv_dirty_bitmap_abdicate(bs, job->sync_bitmap, NULL);
290 } else {
291 /*
292 * We failed, or we never intended to sync the bitmap anyway.
293 * Merge the successor back into the parent, keeping all data.
294 */
295 bm = bdrv_reclaim_dirty_bitmap(bs, job->sync_bitmap, NULL);
296 }
297
298 assert(bm);
299
300 if (ret < 0 && job->bitmap_mode == BITMAP_SYNC_MODE_ALWAYS) {
301 /* If we failed and synced, merge in the bits we didn't copy: */
302 bdrv_dirty_bitmap_merge_internal(bm, job->copy_bitmap,
303 NULL, true);
304 }
305 }
306
307 static void backup_commit(Job *job)
308 {
309 BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
310 if (s->sync_bitmap) {
311 backup_cleanup_sync_bitmap(s, 0);
312 }
313 }
314
315 static void backup_abort(Job *job)
316 {
317 BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
318 if (s->sync_bitmap) {
319 backup_cleanup_sync_bitmap(s, -1);
320 }
321 }
322
323 static void backup_clean(Job *job)
324 {
325 BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
326 BlockDriverState *bs = blk_bs(s->common.blk);
327
328 if (s->copy_bitmap) {
329 bdrv_release_dirty_bitmap(bs, s->copy_bitmap);
330 s->copy_bitmap = NULL;
331 }
332
333 assert(s->target);
334 blk_unref(s->target);
335 s->target = NULL;
336 }
337
338 void backup_do_checkpoint(BlockJob *job, Error **errp)
339 {
340 BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
341
342 assert(block_job_driver(job) == &backup_job_driver);
343
344 if (backup_job->sync_mode != MIRROR_SYNC_MODE_NONE) {
345 error_setg(errp, "The backup job only supports block checkpoint in"
346 " sync=none mode");
347 return;
348 }
349
350 bdrv_set_dirty_bitmap(backup_job->copy_bitmap, 0, backup_job->len);
351 }
352
353 static void backup_drain(BlockJob *job)
354 {
355 BackupBlockJob *s = container_of(job, BackupBlockJob, common);
356
357 /* Need to keep a reference in case blk_drain triggers execution
358 * of backup_complete...
359 */
360 if (s->target) {
361 BlockBackend *target = s->target;
362 blk_ref(target);
363 blk_drain(target);
364 blk_unref(target);
365 }
366 }
367
368 static BlockErrorAction backup_error_action(BackupBlockJob *job,
369 bool read, int error)
370 {
371 if (read) {
372 return block_job_error_action(&job->common, job->on_source_error,
373 true, error);
374 } else {
375 return block_job_error_action(&job->common, job->on_target_error,
376 false, error);
377 }
378 }
379
380 static bool coroutine_fn yield_and_check(BackupBlockJob *job)
381 {
382 uint64_t delay_ns;
383
384 if (job_is_cancelled(&job->common.job)) {
385 return true;
386 }
387
388 /* We need to yield even for delay_ns = 0 so that bdrv_drain_all() can
389 * return. Without a yield, the VM would not reboot. */
390 delay_ns = block_job_ratelimit_get_delay(&job->common, job->bytes_read);
391 job->bytes_read = 0;
392 job_sleep_ns(&job->common.job, delay_ns);
393
394 if (job_is_cancelled(&job->common.job)) {
395 return true;
396 }
397
398 return false;
399 }
400
401 static bool bdrv_is_unallocated_range(BlockDriverState *bs,
402 int64_t offset, int64_t bytes)
403 {
404 int64_t end = offset + bytes;
405
406 while (offset < end && !bdrv_is_allocated(bs, offset, bytes, &bytes)) {
407 if (bytes == 0) {
408 return true;
409 }
410 offset += bytes;
411 bytes = end - offset;
412 }
413
414 return offset >= end;
415 }
416
417 static int coroutine_fn backup_loop(BackupBlockJob *job)
418 {
419 bool error_is_read;
420 int64_t offset;
421 BdrvDirtyBitmapIter *bdbi;
422 BlockDriverState *bs = blk_bs(job->common.blk);
423 int ret = 0;
424
425 bdbi = bdrv_dirty_iter_new(job->copy_bitmap);
426 while ((offset = bdrv_dirty_iter_next(bdbi)) != -1) {
427 if (job->sync_mode == MIRROR_SYNC_MODE_TOP &&
428 bdrv_is_unallocated_range(bs, offset, job->cluster_size))
429 {
430 bdrv_reset_dirty_bitmap(job->copy_bitmap, offset,
431 job->cluster_size);
432 continue;
433 }
434
435 do {
436 if (yield_and_check(job)) {
437 goto out;
438 }
439 ret = backup_do_cow(job, offset,
440 job->cluster_size, &error_is_read, false);
441 if (ret < 0 && backup_error_action(job, error_is_read, -ret) ==
442 BLOCK_ERROR_ACTION_REPORT)
443 {
444 goto out;
445 }
446 } while (ret < 0);
447 }
448
449 out:
450 bdrv_dirty_iter_free(bdbi);
451 return ret;
452 }
453
454 static void backup_init_copy_bitmap(BackupBlockJob *job)
455 {
456 bool ret;
457 uint64_t estimate;
458
459 if (job->sync_mode == MIRROR_SYNC_MODE_BITMAP) {
460 ret = bdrv_dirty_bitmap_merge_internal(job->copy_bitmap,
461 job->sync_bitmap,
462 NULL, true);
463 assert(ret);
464 } else {
465 bdrv_set_dirty_bitmap(job->copy_bitmap, 0, job->len);
466 }
467
468 estimate = bdrv_get_dirty_count(job->copy_bitmap);
469 job_progress_set_remaining(&job->common.job, estimate);
470 }
471
472 static int coroutine_fn backup_run(Job *job, Error **errp)
473 {
474 BackupBlockJob *s = container_of(job, BackupBlockJob, common.job);
475 BlockDriverState *bs = blk_bs(s->common.blk);
476 int ret = 0;
477
478 QLIST_INIT(&s->inflight_reqs);
479 qemu_co_rwlock_init(&s->flush_rwlock);
480
481 backup_init_copy_bitmap(s);
482
483 s->before_write.notify = backup_before_write_notify;
484 bdrv_add_before_write_notifier(bs, &s->before_write);
485
486 if (s->sync_mode == MIRROR_SYNC_MODE_NONE) {
487 /* All bits are set in copy_bitmap to allow any cluster to be copied.
488 * This does not actually require them to be copied. */
489 while (!job_is_cancelled(job)) {
490 /* Yield until the job is cancelled. We just let our before_write
491 * notify callback service CoW requests. */
492 job_yield(job);
493 }
494 } else {
495 ret = backup_loop(s);
496 }
497
498 notifier_with_return_remove(&s->before_write);
499
500 /* wait until pending backup_do_cow() calls have completed */
501 qemu_co_rwlock_wrlock(&s->flush_rwlock);
502 qemu_co_rwlock_unlock(&s->flush_rwlock);
503
504 return ret;
505 }
506
507 static const BlockJobDriver backup_job_driver = {
508 .job_driver = {
509 .instance_size = sizeof(BackupBlockJob),
510 .job_type = JOB_TYPE_BACKUP,
511 .free = block_job_free,
512 .user_resume = block_job_user_resume,
513 .drain = block_job_drain,
514 .run = backup_run,
515 .commit = backup_commit,
516 .abort = backup_abort,
517 .clean = backup_clean,
518 },
519 .drain = backup_drain,
520 };
521
522 static int64_t backup_calculate_cluster_size(BlockDriverState *target,
523 Error **errp)
524 {
525 int ret;
526 BlockDriverInfo bdi;
527
528 /*
529 * If there is no backing file on the target, we cannot rely on COW if our
530 * backup cluster size is smaller than the target cluster size. Even for
531 * targets with a backing file, try to avoid COW if possible.
532 */
533 ret = bdrv_get_info(target, &bdi);
534 if (ret == -ENOTSUP && !target->backing) {
535 /* Cluster size is not defined */
536 warn_report("The target block device doesn't provide "
537 "information about the block size and it doesn't have a "
538 "backing file. The default block size of %u bytes is "
539 "used. If the actual block size of the target exceeds "
540 "this default, the backup may be unusable",
541 BACKUP_CLUSTER_SIZE_DEFAULT);
542 return BACKUP_CLUSTER_SIZE_DEFAULT;
543 } else if (ret < 0 && !target->backing) {
544 error_setg_errno(errp, -ret,
545 "Couldn't determine the cluster size of the target image, "
546 "which has no backing file");
547 error_append_hint(errp,
548 "Aborting, since this may create an unusable destination image\n");
549 return ret;
550 } else if (ret < 0 && target->backing) {
551 /* Not fatal; just trudge on ahead. */
552 return BACKUP_CLUSTER_SIZE_DEFAULT;
553 }
554
555 return MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
556 }
557
558 BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
559 BlockDriverState *target, int64_t speed,
560 MirrorSyncMode sync_mode, BdrvDirtyBitmap *sync_bitmap,
561 BitmapSyncMode bitmap_mode,
562 bool compress,
563 BlockdevOnError on_source_error,
564 BlockdevOnError on_target_error,
565 int creation_flags,
566 BlockCompletionFunc *cb, void *opaque,
567 JobTxn *txn, Error **errp)
568 {
569 int64_t len;
570 BackupBlockJob *job = NULL;
571 int ret;
572 int64_t cluster_size;
573 BdrvDirtyBitmap *copy_bitmap = NULL;
574
575 assert(bs);
576 assert(target);
577
578 /* QMP interface protects us from these cases */
579 assert(sync_mode != MIRROR_SYNC_MODE_INCREMENTAL);
580 assert(sync_bitmap || sync_mode != MIRROR_SYNC_MODE_BITMAP);
581
582 if (bs == target) {
583 error_setg(errp, "Source and target cannot be the same");
584 return NULL;
585 }
586
587 if (!bdrv_is_inserted(bs)) {
588 error_setg(errp, "Device is not inserted: %s",
589 bdrv_get_device_name(bs));
590 return NULL;
591 }
592
593 if (!bdrv_is_inserted(target)) {
594 error_setg(errp, "Device is not inserted: %s",
595 bdrv_get_device_name(target));
596 return NULL;
597 }
598
599 if (compress && target->drv->bdrv_co_pwritev_compressed == NULL) {
600 error_setg(errp, "Compression is not supported for this drive %s",
601 bdrv_get_device_name(target));
602 return NULL;
603 }
604
605 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
606 return NULL;
607 }
608
609 if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) {
610 return NULL;
611 }
612
613 if (sync_mode == MIRROR_SYNC_MODE_BITMAP) {
614 /* If we need to write to this bitmap, check that we can: */
615 if (bitmap_mode != BITMAP_SYNC_MODE_NEVER &&
616 bdrv_dirty_bitmap_check(sync_bitmap, BDRV_BITMAP_DEFAULT, errp)) {
617 return NULL;
618 }
619
620 /* Create a new bitmap, and freeze/disable this one. */
621 if (bdrv_dirty_bitmap_create_successor(bs, sync_bitmap, errp) < 0) {
622 return NULL;
623 }
624 } else if (sync_bitmap) {
625 error_setg(errp,
626 "a bitmap was given to backup_job_create, "
627 "but it received an incompatible sync_mode (%s)",
628 MirrorSyncMode_str(sync_mode));
629 return NULL;
630 }
631
632 len = bdrv_getlength(bs);
633 if (len < 0) {
634 error_setg_errno(errp, -len, "unable to get length for '%s'",
635 bdrv_get_device_name(bs));
636 goto error;
637 }
638
639 cluster_size = backup_calculate_cluster_size(target, errp);
640 if (cluster_size < 0) {
641 goto error;
642 }
643
644 copy_bitmap = bdrv_create_dirty_bitmap(bs, cluster_size, NULL, errp);
645 if (!copy_bitmap) {
646 goto error;
647 }
648 bdrv_disable_dirty_bitmap(copy_bitmap);
649
650 /* job->len is fixed, so we can't allow resize */
651 job = block_job_create(job_id, &backup_job_driver, txn, bs,
652 BLK_PERM_CONSISTENT_READ,
653 BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE |
654 BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD,
655 speed, creation_flags, cb, opaque, errp);
656 if (!job) {
657 goto error;
658 }
659
660 /* The target must match the source in size, so no resize here either */
661 job->target = blk_new(job->common.job.aio_context,
662 BLK_PERM_WRITE,
663 BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE |
664 BLK_PERM_WRITE_UNCHANGED | BLK_PERM_GRAPH_MOD);
665 ret = blk_insert_bs(job->target, target, errp);
666 if (ret < 0) {
667 goto error;
668 }
669 blk_set_disable_request_queuing(job->target, true);
670
671 job->on_source_error = on_source_error;
672 job->on_target_error = on_target_error;
673 job->sync_mode = sync_mode;
674 job->sync_bitmap = sync_bitmap;
675 job->bitmap_mode = bitmap_mode;
676 job->compress = compress;
677
678 /* Detect image-fleecing (and similar) schemes */
679 job->serialize_target_writes = bdrv_chain_contains(target, bs);
680 job->cluster_size = cluster_size;
681 job->copy_bitmap = copy_bitmap;
682 copy_bitmap = NULL;
683 job->use_copy_range = !compress; /* compression isn't supported for it */
684 job->copy_range_size = MIN_NON_ZERO(blk_get_max_transfer(job->common.blk),
685 blk_get_max_transfer(job->target));
686 job->copy_range_size = MAX(job->cluster_size,
687 QEMU_ALIGN_UP(job->copy_range_size,
688 job->cluster_size));
689
690 /* Required permissions are already taken with target's blk_new() */
691 block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL,
692 &error_abort);
693 job->len = len;
694
695 return &job->common;
696
697 error:
698 if (copy_bitmap) {
699 assert(!job || !job->copy_bitmap);
700 bdrv_release_dirty_bitmap(bs, copy_bitmap);
701 }
702 if (sync_bitmap) {
703 bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);
704 }
705 if (job) {
706 backup_clean(&job->common.job);
707 job_early_fail(&job->common.job);
708 }
709
710 return NULL;
711 }