1 | The following changes since commit ab08440a4ee09032d1a9cb22fdcab23bc7e1c656: | 1 | The following changes since commit 346ed3151f1c43e72c40cb55b392a1d4cface62c: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180702' into staging (2018-07-02 17:57:46 +0100) | 3 | Merge remote-tracking branch 'remotes/awilliam/tags/vfio-update-20200206.0' into staging (2020-02-07 11:52:15 +0000) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request | 7 | https://github.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 9ded4a0114968e98b41494fc035ba14f84cdf700: | 9 | for you to fetch changes up to 11a18c84db4a71497d3d40769688a01b6f64b2ad: |
10 | 10 | ||
11 | backup: Use copy offloading (2018-07-02 23:23:45 -0400) | 11 | hw/core: Allow setting 'virtio-blk-device.scsi' property on OSX host (2020-02-07 16:49:39 +0000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block backup patches | 14 | Pull request |
15 | |||
15 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
16 | 17 | ||
17 | Fam Zheng (3): | 18 | Philippe Mathieu-Daudé (1): |
18 | block: Fix parameter checking in bdrv_co_copy_range_internal | 19 | hw/core: Allow setting 'virtio-blk-device.scsi' property on OSX host |
19 | block: Honour BDRV_REQ_NO_SERIALISING in copy range | ||
20 | backup: Use copy offloading | ||
21 | 20 | ||
22 | block/backup.c | 150 ++++++++++++++++++++++++++++++------------ | 21 | Vladimir Sementsov-Ogievskiy (1): |
23 | block/io.c | 35 +++++----- | 22 | block: fix crash on zero-length unaligned write and read |
24 | block/trace-events | 1 + | 23 | |
25 | include/block/block.h | 5 +- | 24 | block/io.c | 28 +++++++++++++++++++++++++++- |
26 | 4 files changed, 132 insertions(+), 59 deletions(-) | 25 | hw/core/machine.c | 3 ++- |
26 | 2 files changed, 29 insertions(+), 2 deletions(-) | ||
27 | 27 | ||
28 | -- | 28 | -- |
29 | 2.17.1 | 29 | 2.24.1 |
30 | 30 | ||
31 | 31 | diff view generated by jsdifflib |
1 | From: Fam Zheng <famz@redhat.com> | 1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | src may be NULL if BDRV_REQ_ZERO_WRITE flag is set, in this case only | 3 | Commit 7a3f542fbd "block/io: refactor padding" occasionally dropped |
4 | check dst and dst->bs. This bug was introduced when moving in the | 4 | aligning for zero-length request: bdrv_init_padding() blindly return |
5 | request tracking code from bdrv_co_copy_range, in 37aec7d75eb. | 5 | false if bytes == 0, like there is nothing to align. |
6 | 6 | ||
7 | This especially fixes the possible segfault when initializing src_bs | 7 | This leads the following command to crash: |
8 | with a NULL src. | ||
9 | 8 | ||
10 | Signed-off-by: Fam Zheng <famz@redhat.com> | 9 | ./qemu-io --image-opts -c 'write 1 0' \ |
11 | Message-id: 20180703023758.14422-2-famz@redhat.com | 10 | driver=blkdebug,align=512,image.driver=null-co,image.size=512 |
12 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 11 | |
13 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 12 | >> qemu-io: block/io.c:1955: bdrv_aligned_pwritev: Assertion |
13 | `(offset & (align - 1)) == 0' failed. | ||
14 | >> Aborted (core dumped) | ||
15 | |||
16 | Prior to 7a3f542fbd we does aligning of such zero requests. Instead of | ||
17 | recovering this behavior let's just do nothing on such requests as it | ||
18 | is useless. | ||
19 | |||
20 | Note that driver may have special meaning of zero-length reqeusts, like | ||
21 | qcow2_co_pwritev_compressed_part, so we can't skip any zero-length | ||
22 | operation. But for unaligned ones, we can't pass it to driver anyway. | ||
23 | |||
24 | This commit also fixes crash in iotest 80 running with -nocache: | ||
25 | |||
26 | ./check -nocache -qcow2 80 | ||
27 | |||
28 | which crashes on same assertion due to trying to read empty extra data | ||
29 | in qcow2_do_read_snapshots(). | ||
30 | |||
31 | Cc: qemu-stable@nongnu.org # v4.2 | ||
32 | Fixes: 7a3f542fbd | ||
33 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
34 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
35 | Message-id: 20200206164245.17781-1-vsementsov@virtuozzo.com | ||
36 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | 37 | --- |
15 | block/io.c | 29 +++++++++++++++-------------- | 38 | block/io.c | 28 +++++++++++++++++++++++++++- |
16 | 1 file changed, 15 insertions(+), 14 deletions(-) | 39 | 1 file changed, 27 insertions(+), 1 deletion(-) |
17 | 40 | ||
18 | diff --git a/block/io.c b/block/io.c | 41 | diff --git a/block/io.c b/block/io.c |
19 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/block/io.c | 43 | --- a/block/io.c |
21 | +++ b/block/io.c | 44 | +++ b/block/io.c |
22 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src, | 45 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_init_padding(BlockDriverState *bs, |
23 | bool recurse_src) | 46 | pad->tail = align - pad->tail; |
24 | { | ||
25 | BdrvTrackedRequest src_req, dst_req; | ||
26 | - BlockDriverState *src_bs = src->bs; | ||
27 | - BlockDriverState *dst_bs = dst->bs; | ||
28 | int ret; | ||
29 | |||
30 | - if (!src || !dst || !src->bs || !dst->bs) { | ||
31 | + if (!dst || !dst->bs) { | ||
32 | return -ENOMEDIUM; | ||
33 | } | 47 | } |
34 | - ret = bdrv_check_byte_request(src->bs, src_offset, bytes); | 48 | |
35 | - if (ret) { | 49 | - if ((!pad->head && !pad->tail) || !bytes) { |
36 | - return ret; | 50 | + if (!pad->head && !pad->tail) { |
37 | - } | 51 | return false; |
38 | - | 52 | } |
39 | ret = bdrv_check_byte_request(dst->bs, dst_offset, bytes); | 53 | |
40 | if (ret) { | 54 | + assert(bytes); /* Nothing good in aligning zero-length requests */ |
55 | + | ||
56 | sum = pad->head + bytes + pad->tail; | ||
57 | pad->buf_len = (sum > align && pad->head && pad->tail) ? 2 * align : align; | ||
58 | pad->buf = qemu_blockalign(bs, pad->buf_len); | ||
59 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, | ||
41 | return ret; | 60 | return ret; |
42 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src, | ||
43 | return bdrv_co_pwrite_zeroes(dst, dst_offset, bytes, flags); | ||
44 | } | 61 | } |
45 | 62 | ||
46 | + if (!src || !src->bs) { | 63 | + if (bytes == 0 && !QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)) { |
47 | + return -ENOMEDIUM; | 64 | + /* |
48 | + } | 65 | + * Aligning zero request is nonsense. Even if driver has special meaning |
49 | + ret = bdrv_check_byte_request(src->bs, src_offset, bytes); | 66 | + * of zero-length (like qcow2_co_pwritev_compressed_part), we can't pass |
50 | + if (ret) { | 67 | + * it to driver due to request_alignment. |
51 | + return ret; | 68 | + * |
69 | + * Still, no reason to return an error if someone do unaligned | ||
70 | + * zero-length read occasionally. | ||
71 | + */ | ||
72 | + return 0; | ||
52 | + } | 73 | + } |
53 | + | 74 | + |
54 | if (!src->bs->drv->bdrv_co_copy_range_from | 75 | bdrv_inc_in_flight(bs); |
55 | || !dst->bs->drv->bdrv_co_copy_range_to | 76 | |
56 | || src->bs->encrypted || dst->bs->encrypted) { | 77 | /* Don't do copy-on-read if we read data before write operation */ |
78 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, | ||
57 | return -ENOTSUP; | 79 | return -ENOTSUP; |
58 | } | 80 | } |
59 | - bdrv_inc_in_flight(src_bs); | 81 | |
60 | - bdrv_inc_in_flight(dst_bs); | 82 | + if (bytes == 0 && !QEMU_IS_ALIGNED(offset, bs->bl.request_alignment)) { |
61 | - tracked_request_begin(&src_req, src_bs, src_offset, | 83 | + /* |
62 | + bdrv_inc_in_flight(src->bs); | 84 | + * Aligning zero request is nonsense. Even if driver has special meaning |
63 | + bdrv_inc_in_flight(dst->bs); | 85 | + * of zero-length (like qcow2_co_pwritev_compressed_part), we can't pass |
64 | + tracked_request_begin(&src_req, src->bs, src_offset, | 86 | + * it to driver due to request_alignment. |
65 | bytes, BDRV_TRACKED_READ); | 87 | + * |
66 | - tracked_request_begin(&dst_req, dst_bs, dst_offset, | 88 | + * Still, no reason to return an error if someone do unaligned |
67 | + tracked_request_begin(&dst_req, dst->bs, dst_offset, | 89 | + * zero-length write occasionally. |
68 | bytes, BDRV_TRACKED_WRITE); | 90 | + */ |
69 | 91 | + return 0; | |
70 | wait_serialising_requests(&src_req); | 92 | + } |
71 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src, | 93 | + |
72 | } | 94 | bdrv_inc_in_flight(bs); |
73 | tracked_request_end(&src_req); | 95 | /* |
74 | tracked_request_end(&dst_req); | 96 | * Align write if necessary by performing a read-modify-write cycle. |
75 | - bdrv_dec_in_flight(src_bs); | ||
76 | - bdrv_dec_in_flight(dst_bs); | ||
77 | + bdrv_dec_in_flight(src->bs); | ||
78 | + bdrv_dec_in_flight(dst->bs); | ||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | -- | 97 | -- |
83 | 2.17.1 | 98 | 2.24.1 |
84 | 99 | ||
85 | 100 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Fam Zheng <famz@redhat.com> | ||
2 | 1 | ||
3 | This semantics is needed by drive-backup so implement it before using | ||
4 | this API there. | ||
5 | |||
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Signed-off-by: Fam Zheng <famz@redhat.com> | ||
8 | Message-id: 20180703023758.14422-3-famz@redhat.com | ||
9 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
10 | --- | ||
11 | block/io.c | 6 ++++-- | ||
12 | include/block/block.h | 5 +++-- | ||
13 | 2 files changed, 7 insertions(+), 4 deletions(-) | ||
14 | |||
15 | diff --git a/block/io.c b/block/io.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/io.c | ||
18 | +++ b/block/io.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src, | ||
20 | tracked_request_begin(&dst_req, dst->bs, dst_offset, | ||
21 | bytes, BDRV_TRACKED_WRITE); | ||
22 | |||
23 | - wait_serialising_requests(&src_req); | ||
24 | - wait_serialising_requests(&dst_req); | ||
25 | + if (!(flags & BDRV_REQ_NO_SERIALISING)) { | ||
26 | + wait_serialising_requests(&src_req); | ||
27 | + wait_serialising_requests(&dst_req); | ||
28 | + } | ||
29 | if (recurse_src) { | ||
30 | ret = src->bs->drv->bdrv_co_copy_range_from(src->bs, | ||
31 | src, src_offset, | ||
32 | diff --git a/include/block/block.h b/include/block/block.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/include/block/block.h | ||
35 | +++ b/include/block/block.h | ||
36 | @@ -XXX,XX +XXX,XX @@ void bdrv_unregister_buf(BlockDriverState *bs, void *host); | ||
37 | * @dst: Destination child to copy data to | ||
38 | * @dst_offset: offset in @dst image to write data | ||
39 | * @bytes: number of bytes to copy | ||
40 | - * @flags: request flags. Must be one of: | ||
41 | - * 0 - actually read data from src; | ||
42 | + * @flags: request flags. Supported flags: | ||
43 | * BDRV_REQ_ZERO_WRITE - treat the @src range as zero data and do zero | ||
44 | * write on @dst as if bdrv_co_pwrite_zeroes is | ||
45 | * called. Used to simplify caller code, or | ||
46 | * during BlockDriver.bdrv_co_copy_range_from() | ||
47 | * recursion. | ||
48 | + * BDRV_REQ_NO_SERIALISING - do not serialize with other overlapping | ||
49 | + * requests currently in flight. | ||
50 | * | ||
51 | * Returns: 0 if succeeded; negative error code if failed. | ||
52 | **/ | ||
53 | -- | ||
54 | 2.17.1 | ||
55 | |||
56 | diff view generated by jsdifflib |
1 | From: Fam Zheng <famz@redhat.com> | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The implementation is similar to the 'qemu-img convert'. In the | 3 | Commit ed65fd1a2750 ("virtio-blk: switch off scsi-passthrough by |
4 | beginning of the job, offloaded copy is attempted. If it fails, further | 4 | default") changed the default value of the 'scsi' property of |
5 | I/O will go through the existing bounce buffer code path. | 5 | virtio-blk, which is only available on Linux hosts. It also added |
6 | an unconditional compat entry for 2.4 or earlier machines. | ||
6 | 7 | ||
7 | Then, as Kevin pointed out, both this and qemu-img convert can benefit | 8 | Trying to set this property on a pre-2.5 machine on OSX, we get: |
8 | from a local check if one request fails because of, for example, the | ||
9 | offset is beyond EOF, but another may well be accepted by the protocol | ||
10 | layer. This will be implemented separately. | ||
11 | 9 | ||
12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Unexpected error in object_property_find() at qom/object.c:1201: |
13 | Signed-off-by: Fam Zheng <famz@redhat.com> | 11 | qemu-system-x86_64: -device virtio-blk-pci,id=scsi0,drive=drive0: can't apply global virtio-blk-device.scsi=true: Property '.scsi' not found |
14 | Message-id: 20180703023758.14422-4-famz@redhat.com | 12 | |
15 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 13 | Fix this error by marking the property optional. |
14 | |||
15 | Fixes: ed65fd1a27 ("virtio-blk: switch off scsi-passthrough by default") | ||
16 | Suggested-by: Cornelia Huck <cohuck@redhat.com> | ||
17 | Reviewed-by: Cornelia Huck <cohuck@redhat.com> | ||
18 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
19 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | ||
20 | Message-id: 20200207001404.1739-1-philmd@redhat.com | ||
21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | --- | 22 | --- |
17 | block/backup.c | 150 ++++++++++++++++++++++++++++++++------------- | 23 | hw/core/machine.c | 3 ++- |
18 | block/trace-events | 1 + | 24 | 1 file changed, 2 insertions(+), 1 deletion(-) |
19 | 2 files changed, 110 insertions(+), 41 deletions(-) | ||
20 | 25 | ||
21 | diff --git a/block/backup.c b/block/backup.c | 26 | diff --git a/hw/core/machine.c b/hw/core/machine.c |
22 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/block/backup.c | 28 | --- a/hw/core/machine.c |
24 | +++ b/block/backup.c | 29 | +++ b/hw/core/machine.c |
25 | @@ -XXX,XX +XXX,XX @@ typedef struct BackupBlockJob { | 30 | @@ -XXX,XX +XXX,XX @@ GlobalProperty hw_compat_2_5[] = { |
26 | QLIST_HEAD(, CowRequest) inflight_reqs; | 31 | const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5); |
27 | 32 | ||
28 | HBitmap *copy_bitmap; | 33 | GlobalProperty hw_compat_2_4[] = { |
29 | + bool use_copy_range; | 34 | - { "virtio-blk-device", "scsi", "true" }, |
30 | + int64_t copy_range_size; | 35 | + /* Optional because the 'scsi' property is Linux-only */ |
31 | } BackupBlockJob; | 36 | + { "virtio-blk-device", "scsi", "true", .optional = true }, |
32 | 37 | { "e1000", "extra_mac_registers", "off" }, | |
33 | static const BlockJobDriver backup_job_driver; | 38 | { "virtio-pci", "x-disable-pcie", "on" }, |
34 | @@ -XXX,XX +XXX,XX @@ static void cow_request_end(CowRequest *req) | 39 | { "virtio-pci", "migrate-extra", "off" }, |
35 | qemu_co_queue_restart_all(&req->wait_queue); | ||
36 | } | ||
37 | |||
38 | +/* Copy range to target with a bounce buffer and return the bytes copied. If | ||
39 | + * error occured, return a negative error number */ | ||
40 | +static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job, | ||
41 | + int64_t start, | ||
42 | + int64_t end, | ||
43 | + bool is_write_notifier, | ||
44 | + bool *error_is_read, | ||
45 | + void **bounce_buffer) | ||
46 | +{ | ||
47 | + int ret; | ||
48 | + struct iovec iov; | ||
49 | + QEMUIOVector qiov; | ||
50 | + BlockBackend *blk = job->common.blk; | ||
51 | + int nbytes; | ||
52 | + | ||
53 | + hbitmap_reset(job->copy_bitmap, start / job->cluster_size, 1); | ||
54 | + nbytes = MIN(job->cluster_size, job->len - start); | ||
55 | + if (!*bounce_buffer) { | ||
56 | + *bounce_buffer = blk_blockalign(blk, job->cluster_size); | ||
57 | + } | ||
58 | + iov.iov_base = *bounce_buffer; | ||
59 | + iov.iov_len = nbytes; | ||
60 | + qemu_iovec_init_external(&qiov, &iov, 1); | ||
61 | + | ||
62 | + ret = blk_co_preadv(blk, start, qiov.size, &qiov, | ||
63 | + is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0); | ||
64 | + if (ret < 0) { | ||
65 | + trace_backup_do_cow_read_fail(job, start, ret); | ||
66 | + if (error_is_read) { | ||
67 | + *error_is_read = true; | ||
68 | + } | ||
69 | + goto fail; | ||
70 | + } | ||
71 | + | ||
72 | + if (qemu_iovec_is_zero(&qiov)) { | ||
73 | + ret = blk_co_pwrite_zeroes(job->target, start, | ||
74 | + qiov.size, BDRV_REQ_MAY_UNMAP); | ||
75 | + } else { | ||
76 | + ret = blk_co_pwritev(job->target, start, | ||
77 | + qiov.size, &qiov, | ||
78 | + job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); | ||
79 | + } | ||
80 | + if (ret < 0) { | ||
81 | + trace_backup_do_cow_write_fail(job, start, ret); | ||
82 | + if (error_is_read) { | ||
83 | + *error_is_read = false; | ||
84 | + } | ||
85 | + goto fail; | ||
86 | + } | ||
87 | + | ||
88 | + return nbytes; | ||
89 | +fail: | ||
90 | + hbitmap_set(job->copy_bitmap, start / job->cluster_size, 1); | ||
91 | + return ret; | ||
92 | + | ||
93 | +} | ||
94 | + | ||
95 | +/* Copy range to target and return the bytes copied. If error occured, return a | ||
96 | + * negative error number. */ | ||
97 | +static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job, | ||
98 | + int64_t start, | ||
99 | + int64_t end, | ||
100 | + bool is_write_notifier) | ||
101 | +{ | ||
102 | + int ret; | ||
103 | + int nr_clusters; | ||
104 | + BlockBackend *blk = job->common.blk; | ||
105 | + int nbytes; | ||
106 | + | ||
107 | + assert(QEMU_IS_ALIGNED(job->copy_range_size, job->cluster_size)); | ||
108 | + nbytes = MIN(job->copy_range_size, end - start); | ||
109 | + nr_clusters = DIV_ROUND_UP(nbytes, job->cluster_size); | ||
110 | + hbitmap_reset(job->copy_bitmap, start / job->cluster_size, | ||
111 | + nr_clusters); | ||
112 | + ret = blk_co_copy_range(blk, start, job->target, start, nbytes, | ||
113 | + is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0); | ||
114 | + if (ret < 0) { | ||
115 | + trace_backup_do_cow_copy_range_fail(job, start, ret); | ||
116 | + hbitmap_set(job->copy_bitmap, start / job->cluster_size, | ||
117 | + nr_clusters); | ||
118 | + return ret; | ||
119 | + } | ||
120 | + | ||
121 | + return nbytes; | ||
122 | +} | ||
123 | + | ||
124 | static int coroutine_fn backup_do_cow(BackupBlockJob *job, | ||
125 | int64_t offset, uint64_t bytes, | ||
126 | bool *error_is_read, | ||
127 | bool is_write_notifier) | ||
128 | { | ||
129 | - BlockBackend *blk = job->common.blk; | ||
130 | CowRequest cow_request; | ||
131 | - struct iovec iov; | ||
132 | - QEMUIOVector bounce_qiov; | ||
133 | - void *bounce_buffer = NULL; | ||
134 | int ret = 0; | ||
135 | int64_t start, end; /* bytes */ | ||
136 | - int n; /* bytes */ | ||
137 | + void *bounce_buffer = NULL; | ||
138 | |||
139 | qemu_co_rwlock_rdlock(&job->flush_rwlock); | ||
140 | |||
141 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job, | ||
142 | wait_for_overlapping_requests(job, start, end); | ||
143 | cow_request_begin(&cow_request, job, start, end); | ||
144 | |||
145 | - for (; start < end; start += job->cluster_size) { | ||
146 | + while (start < end) { | ||
147 | if (!hbitmap_get(job->copy_bitmap, start / job->cluster_size)) { | ||
148 | trace_backup_do_cow_skip(job, start); | ||
149 | + start += job->cluster_size; | ||
150 | continue; /* already copied */ | ||
151 | } | ||
152 | - hbitmap_reset(job->copy_bitmap, start / job->cluster_size, 1); | ||
153 | |||
154 | trace_backup_do_cow_process(job, start); | ||
155 | |||
156 | - n = MIN(job->cluster_size, job->len - start); | ||
157 | - | ||
158 | - if (!bounce_buffer) { | ||
159 | - bounce_buffer = blk_blockalign(blk, job->cluster_size); | ||
160 | - } | ||
161 | - iov.iov_base = bounce_buffer; | ||
162 | - iov.iov_len = n; | ||
163 | - qemu_iovec_init_external(&bounce_qiov, &iov, 1); | ||
164 | - | ||
165 | - ret = blk_co_preadv(blk, start, bounce_qiov.size, &bounce_qiov, | ||
166 | - is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0); | ||
167 | - if (ret < 0) { | ||
168 | - trace_backup_do_cow_read_fail(job, start, ret); | ||
169 | - if (error_is_read) { | ||
170 | - *error_is_read = true; | ||
171 | + if (job->use_copy_range) { | ||
172 | + ret = backup_cow_with_offload(job, start, end, is_write_notifier); | ||
173 | + if (ret < 0) { | ||
174 | + job->use_copy_range = false; | ||
175 | } | ||
176 | - hbitmap_set(job->copy_bitmap, start / job->cluster_size, 1); | ||
177 | - goto out; | ||
178 | } | ||
179 | - | ||
180 | - if (buffer_is_zero(iov.iov_base, iov.iov_len)) { | ||
181 | - ret = blk_co_pwrite_zeroes(job->target, start, | ||
182 | - bounce_qiov.size, BDRV_REQ_MAY_UNMAP); | ||
183 | - } else { | ||
184 | - ret = blk_co_pwritev(job->target, start, | ||
185 | - bounce_qiov.size, &bounce_qiov, | ||
186 | - job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); | ||
187 | + if (!job->use_copy_range) { | ||
188 | + ret = backup_cow_with_bounce_buffer(job, start, end, is_write_notifier, | ||
189 | + error_is_read, &bounce_buffer); | ||
190 | } | ||
191 | if (ret < 0) { | ||
192 | - trace_backup_do_cow_write_fail(job, start, ret); | ||
193 | - if (error_is_read) { | ||
194 | - *error_is_read = false; | ||
195 | - } | ||
196 | - hbitmap_set(job->copy_bitmap, start / job->cluster_size, 1); | ||
197 | - goto out; | ||
198 | + break; | ||
199 | } | ||
200 | |||
201 | /* Publish progress, guest I/O counts as progress too. Note that the | ||
202 | * offset field is an opaque progress value, it is not a disk offset. | ||
203 | */ | ||
204 | - job->bytes_read += n; | ||
205 | - job_progress_update(&job->common.job, n); | ||
206 | + start += ret; | ||
207 | + job->bytes_read += ret; | ||
208 | + job_progress_update(&job->common.job, ret); | ||
209 | + ret = 0; | ||
210 | } | ||
211 | |||
212 | -out: | ||
213 | if (bounce_buffer) { | ||
214 | qemu_vfree(bounce_buffer); | ||
215 | } | ||
216 | @@ -XXX,XX +XXX,XX @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, | ||
217 | } else { | ||
218 | job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size); | ||
219 | } | ||
220 | + job->use_copy_range = true; | ||
221 | + job->copy_range_size = MIN_NON_ZERO(blk_get_max_transfer(job->common.blk), | ||
222 | + blk_get_max_transfer(job->target)); | ||
223 | + job->copy_range_size = MAX(job->cluster_size, | ||
224 | + QEMU_ALIGN_UP(job->copy_range_size, | ||
225 | + job->cluster_size)); | ||
226 | |||
227 | /* Required permissions are already taken with target's blk_new() */ | ||
228 | block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, | ||
229 | diff --git a/block/trace-events b/block/trace-events | ||
230 | index XXXXXXX..XXXXXXX 100644 | ||
231 | --- a/block/trace-events | ||
232 | +++ b/block/trace-events | ||
233 | @@ -XXX,XX +XXX,XX @@ backup_do_cow_skip(void *job, int64_t start) "job %p start %"PRId64 | ||
234 | backup_do_cow_process(void *job, int64_t start) "job %p start %"PRId64 | ||
235 | backup_do_cow_read_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" | ||
236 | backup_do_cow_write_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" | ||
237 | +backup_do_cow_copy_range_fail(void *job, int64_t start, int ret) "job %p start %"PRId64" ret %d" | ||
238 | |||
239 | # blockdev.c | ||
240 | qmp_block_job_cancel(void *job) "job %p" | ||
241 | -- | 40 | -- |
242 | 2.17.1 | 41 | 2.24.1 |
243 | 42 | ||
244 | 43 | diff view generated by jsdifflib |