1 | The following changes since commit ab08440a4ee09032d1a9cb22fdcab23bc7e1c656: | 1 | The following changes since commit 887cba855bb6ff4775256f7968409281350b568c: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180702' into staging (2018-07-02 17:57:46 +0100) | 3 | configure: Fix cross-building for RISCV host (v5) (2023-07-11 17:56:09 +0100) |
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://gitlab.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 75dcb4d790bbe5327169fd72b185960ca58e2fa6: |
10 | 10 | ||
11 | backup: Use copy offloading (2018-07-02 23:23:45 -0400) | 11 | virtio-blk: fix host notifier issues during dataplane start/stop (2023-07-12 15:20:32 -0400) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block backup patches | 14 | Pull request |
15 | |||
15 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
16 | 17 | ||
17 | Fam Zheng (3): | 18 | Stefan Hajnoczi (1): |
18 | block: Fix parameter checking in bdrv_co_copy_range_internal | 19 | virtio-blk: fix host notifier issues during dataplane start/stop |
19 | block: Honour BDRV_REQ_NO_SERIALISING in copy range | ||
20 | backup: Use copy offloading | ||
21 | 20 | ||
22 | block/backup.c | 150 ++++++++++++++++++++++++++++++------------ | 21 | hw/block/dataplane/virtio-blk.c | 67 +++++++++++++++++++-------------- |
23 | block/io.c | 35 +++++----- | 22 | 1 file changed, 38 insertions(+), 29 deletions(-) |
24 | block/trace-events | 1 + | ||
25 | include/block/block.h | 5 +- | ||
26 | 4 files changed, 132 insertions(+), 59 deletions(-) | ||
27 | 23 | ||
28 | -- | 24 | -- |
29 | 2.17.1 | 25 | 2.40.1 |
30 | |||
31 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Fam Zheng <famz@redhat.com> | ||
2 | 1 | ||
3 | src may be NULL if BDRV_REQ_ZERO_WRITE flag is set, in this case only | ||
4 | check dst and dst->bs. This bug was introduced when moving in the | ||
5 | request tracking code from bdrv_co_copy_range, in 37aec7d75eb. | ||
6 | |||
7 | This especially fixes the possible segfault when initializing src_bs | ||
8 | with a NULL src. | ||
9 | |||
10 | Signed-off-by: Fam Zheng <famz@redhat.com> | ||
11 | Message-id: 20180703023758.14422-2-famz@redhat.com | ||
12 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
13 | Signed-off-by: Jeff Cody <jcody@redhat.com> | ||
14 | --- | ||
15 | block/io.c | 29 +++++++++++++++-------------- | ||
16 | 1 file changed, 15 insertions(+), 14 deletions(-) | ||
17 | |||
18 | diff --git a/block/io.c b/block/io.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/io.c | ||
21 | +++ b/block/io.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src, | ||
23 | bool recurse_src) | ||
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 | } | ||
34 | - ret = bdrv_check_byte_request(src->bs, src_offset, bytes); | ||
35 | - if (ret) { | ||
36 | - return ret; | ||
37 | - } | ||
38 | - | ||
39 | ret = bdrv_check_byte_request(dst->bs, dst_offset, bytes); | ||
40 | if (ret) { | ||
41 | 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 | } | ||
45 | |||
46 | + if (!src || !src->bs) { | ||
47 | + return -ENOMEDIUM; | ||
48 | + } | ||
49 | + ret = bdrv_check_byte_request(src->bs, src_offset, bytes); | ||
50 | + if (ret) { | ||
51 | + return ret; | ||
52 | + } | ||
53 | + | ||
54 | if (!src->bs->drv->bdrv_co_copy_range_from | ||
55 | || !dst->bs->drv->bdrv_co_copy_range_to | ||
56 | || src->bs->encrypted || dst->bs->encrypted) { | ||
57 | return -ENOTSUP; | ||
58 | } | ||
59 | - bdrv_inc_in_flight(src_bs); | ||
60 | - bdrv_inc_in_flight(dst_bs); | ||
61 | - tracked_request_begin(&src_req, src_bs, src_offset, | ||
62 | + bdrv_inc_in_flight(src->bs); | ||
63 | + bdrv_inc_in_flight(dst->bs); | ||
64 | + tracked_request_begin(&src_req, src->bs, src_offset, | ||
65 | bytes, BDRV_TRACKED_READ); | ||
66 | - tracked_request_begin(&dst_req, dst_bs, dst_offset, | ||
67 | + tracked_request_begin(&dst_req, dst->bs, dst_offset, | ||
68 | bytes, BDRV_TRACKED_WRITE); | ||
69 | |||
70 | wait_serialising_requests(&src_req); | ||
71 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_copy_range_internal(BdrvChild *src, | ||
72 | } | ||
73 | tracked_request_end(&src_req); | ||
74 | tracked_request_end(&dst_req); | ||
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 | -- | ||
83 | 2.17.1 | ||
84 | |||
85 | 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 | The main loop thread can consume 100% CPU when using --device |
---|---|---|---|
2 | virtio-blk-pci,iothread=<iothread>. ppoll() constantly returns but | ||
3 | reading virtqueue host notifiers fails with EAGAIN. The file descriptors | ||
4 | are stale and remain registered with the AioContext because of bugs in | ||
5 | the virtio-blk dataplane start/stop code. | ||
2 | 6 | ||
3 | The implementation is similar to the 'qemu-img convert'. In the | 7 | The problem is that the dataplane start/stop code involves drain |
4 | beginning of the job, offloaded copy is attempted. If it fails, further | 8 | operations, which call virtio_blk_drained_begin() and |
5 | I/O will go through the existing bounce buffer code path. | 9 | virtio_blk_drained_end() at points where the host notifier is not |
10 | operational: | ||
11 | - In virtio_blk_data_plane_start(), blk_set_aio_context() drains after | ||
12 | vblk->dataplane_started has been set to true but the host notifier has | ||
13 | not been attached yet. | ||
14 | - In virtio_blk_data_plane_stop(), blk_drain() and blk_set_aio_context() | ||
15 | drain after the host notifier has already been detached but with | ||
16 | vblk->dataplane_started still set to true. | ||
6 | 17 | ||
7 | Then, as Kevin pointed out, both this and qemu-img convert can benefit | 18 | I would like to simplify ->ioeventfd_start/stop() to avoid interactions |
8 | from a local check if one request fails because of, for example, the | 19 | with drain entirely, but couldn't find a way to do that. Instead, this |
9 | offset is beyond EOF, but another may well be accepted by the protocol | 20 | patch accepts the fragile nature of the code and reorders it so that |
10 | layer. This will be implemented separately. | 21 | vblk->dataplane_started is false during drain operations. This way the |
22 | virtio_blk_drained_begin() and virtio_blk_drained_end() calls don't | ||
23 | touch the host notifier. The result is that | ||
24 | virtio_blk_data_plane_start() and virtio_blk_data_plane_stop() have | ||
25 | complete control over the host notifier and stale file descriptors are | ||
26 | no longer left in the AioContext. | ||
11 | 27 | ||
12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 28 | This patch fixes the 100% CPU consumption in the main loop thread and |
13 | Signed-off-by: Fam Zheng <famz@redhat.com> | 29 | correctly moves host notifier processing to the IOThread. |
14 | Message-id: 20180703023758.14422-4-famz@redhat.com | 30 | |
15 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 31 | Fixes: 1665d9326fd2 ("virtio-blk: implement BlockDevOps->drained_begin()") |
32 | Reported-by: Lukáš Doktor <ldoktor@redhat.com> | ||
33 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
34 | Tested-by: Lukas Doktor <ldoktor@redhat.com> | ||
35 | Message-id: 20230704151527.193586-1-stefanha@redhat.com | ||
36 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | --- | 37 | --- |
17 | block/backup.c | 150 ++++++++++++++++++++++++++++++++------------- | 38 | hw/block/dataplane/virtio-blk.c | 67 +++++++++++++++++++-------------- |
18 | block/trace-events | 1 + | 39 | 1 file changed, 38 insertions(+), 29 deletions(-) |
19 | 2 files changed, 110 insertions(+), 41 deletions(-) | ||
20 | 40 | ||
21 | diff --git a/block/backup.c b/block/backup.c | 41 | diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c |
22 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/block/backup.c | 43 | --- a/hw/block/dataplane/virtio-blk.c |
24 | +++ b/block/backup.c | 44 | +++ b/hw/block/dataplane/virtio-blk.c |
25 | @@ -XXX,XX +XXX,XX @@ typedef struct BackupBlockJob { | 45 | @@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) |
26 | QLIST_HEAD(, CowRequest) inflight_reqs; | 46 | |
27 | 47 | memory_region_transaction_commit(); | |
28 | HBitmap *copy_bitmap; | 48 | |
29 | + bool use_copy_range; | 49 | - /* |
30 | + int64_t copy_range_size; | 50 | - * These fields are visible to the IOThread so we rely on implicit barriers |
31 | } BackupBlockJob; | 51 | - * in aio_context_acquire() on the write side and aio_notify_accept() on |
32 | 52 | - * the read side. | |
33 | static const BlockJobDriver backup_job_driver; | 53 | - */ |
34 | @@ -XXX,XX +XXX,XX @@ static void cow_request_end(CowRequest *req) | 54 | - s->starting = false; |
35 | qemu_co_queue_restart_all(&req->wait_queue); | 55 | - vblk->dataplane_started = true; |
56 | trace_virtio_blk_data_plane_start(s); | ||
57 | |||
58 | old_context = blk_get_aio_context(s->conf->conf.blk); | ||
59 | @@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) | ||
60 | event_notifier_set(virtio_queue_get_host_notifier(vq)); | ||
61 | } | ||
62 | |||
63 | + /* | ||
64 | + * These fields must be visible to the IOThread when it processes the | ||
65 | + * virtqueue, otherwise it will think dataplane has not started yet. | ||
66 | + * | ||
67 | + * Make sure ->dataplane_started is false when blk_set_aio_context() is | ||
68 | + * called above so that draining does not cause the host notifier to be | ||
69 | + * detached/attached prematurely. | ||
70 | + */ | ||
71 | + s->starting = false; | ||
72 | + vblk->dataplane_started = true; | ||
73 | + smp_wmb(); /* paired with aio_notify_accept() on the read side */ | ||
74 | + | ||
75 | /* Get this show started by hooking up our callbacks */ | ||
76 | if (!blk_in_drain(s->conf->conf.blk)) { | ||
77 | aio_context_acquire(s->ctx); | ||
78 | @@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) | ||
79 | fail_guest_notifiers: | ||
80 | vblk->dataplane_disabled = true; | ||
81 | s->starting = false; | ||
82 | - vblk->dataplane_started = true; | ||
83 | return -ENOSYS; | ||
36 | } | 84 | } |
37 | 85 | ||
38 | +/* Copy range to target with a bounce buffer and return the bytes copied. If | 86 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) |
39 | + * error occured, return a negative error number */ | 87 | aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s); |
40 | +static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job, | 88 | } |
41 | + int64_t start, | 89 | |
42 | + int64_t end, | 90 | + /* |
43 | + bool is_write_notifier, | 91 | + * Batch all the host notifiers in a single transaction to avoid |
44 | + bool *error_is_read, | 92 | + * quadratic time complexity in address_space_update_ioeventfds(). |
45 | + void **bounce_buffer) | 93 | + */ |
46 | +{ | 94 | + memory_region_transaction_begin(); |
47 | + int ret; | ||
48 | + struct iovec iov; | ||
49 | + QEMUIOVector qiov; | ||
50 | + BlockBackend *blk = job->common.blk; | ||
51 | + int nbytes; | ||
52 | + | 95 | + |
53 | + hbitmap_reset(job->copy_bitmap, start / job->cluster_size, 1); | 96 | + for (i = 0; i < nvqs; i++) { |
54 | + nbytes = MIN(job->cluster_size, job->len - start); | 97 | + virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); |
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 | + } | 98 | + } |
71 | + | 99 | + |
72 | + if (qemu_iovec_is_zero(&qiov)) { | 100 | + /* |
73 | + ret = blk_co_pwrite_zeroes(job->target, start, | 101 | + * The transaction expects the ioeventfds to be open when it |
74 | + qiov.size, BDRV_REQ_MAY_UNMAP); | 102 | + * commits. Do it now, before the cleanup loop. |
75 | + } else { | 103 | + */ |
76 | + ret = blk_co_pwritev(job->target, start, | 104 | + memory_region_transaction_commit(); |
77 | + qiov.size, &qiov, | 105 | + |
78 | + job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); | 106 | + for (i = 0; i < nvqs; i++) { |
79 | + } | 107 | + virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); |
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 | + } | 108 | + } |
87 | + | 109 | + |
88 | + return nbytes; | 110 | + /* |
89 | +fail: | 111 | + * Set ->dataplane_started to false before draining so that host notifiers |
90 | + hbitmap_set(job->copy_bitmap, start / job->cluster_size, 1); | 112 | + * are not detached/attached anymore. |
91 | + return ret; | 113 | + */ |
114 | + vblk->dataplane_started = false; | ||
92 | + | 115 | + |
93 | +} | 116 | aio_context_acquire(s->ctx); |
94 | + | 117 | |
95 | +/* Copy range to target and return the bytes copied. If error occured, return a | 118 | /* Wait for virtio_blk_dma_restart_bh() and in flight I/O to complete */ |
96 | + * negative error number. */ | 119 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) |
97 | +static int coroutine_fn backup_cow_with_offload(BackupBlockJob *job, | 120 | |
98 | + int64_t start, | 121 | aio_context_release(s->ctx); |
99 | + int64_t end, | 122 | |
100 | + bool is_write_notifier) | 123 | - /* |
101 | +{ | 124 | - * Batch all the host notifiers in a single transaction to avoid |
102 | + int ret; | 125 | - * quadratic time complexity in address_space_update_ioeventfds(). |
103 | + int nr_clusters; | 126 | - */ |
104 | + BlockBackend *blk = job->common.blk; | 127 | - memory_region_transaction_begin(); |
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 | - | 128 | - |
158 | - if (!bounce_buffer) { | 129 | - for (i = 0; i < nvqs; i++) { |
159 | - bounce_buffer = blk_blockalign(blk, job->cluster_size); | 130 | - virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false); |
160 | - } | 131 | - } |
161 | - iov.iov_base = bounce_buffer; | ||
162 | - iov.iov_len = n; | ||
163 | - qemu_iovec_init_external(&bounce_qiov, &iov, 1); | ||
164 | - | 132 | - |
165 | - ret = blk_co_preadv(blk, start, bounce_qiov.size, &bounce_qiov, | 133 | - /* |
166 | - is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0); | 134 | - * The transaction expects the ioeventfds to be open when it |
167 | - if (ret < 0) { | 135 | - * commits. Do it now, before the cleanup loop. |
168 | - trace_backup_do_cow_read_fail(job, start, ret); | 136 | - */ |
169 | - if (error_is_read) { | 137 | - memory_region_transaction_commit(); |
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 | - | 138 | - |
180 | - if (buffer_is_zero(iov.iov_base, iov.iov_len)) { | 139 | - for (i = 0; i < nvqs; i++) { |
181 | - ret = blk_co_pwrite_zeroes(job->target, start, | 140 | - virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i); |
182 | - bounce_qiov.size, BDRV_REQ_MAY_UNMAP); | 141 | - } |
183 | - } else { | 142 | - |
184 | - ret = blk_co_pwritev(job->target, start, | 143 | qemu_bh_cancel(s->bh); |
185 | - bounce_qiov.size, &bounce_qiov, | 144 | notify_guest_bh(s); /* final chance to notify guest */ |
186 | - job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0); | 145 | |
187 | + if (!job->use_copy_range) { | 146 | /* Clean up guest notifier (irq) */ |
188 | + ret = backup_cow_with_bounce_buffer(job, start, end, is_write_notifier, | 147 | k->set_guest_notifiers(qbus->parent, nvqs, false); |
189 | + error_is_read, &bounce_buffer); | 148 | |
190 | } | 149 | - vblk->dataplane_started = false; |
191 | if (ret < 0) { | 150 | s->stopping = false; |
192 | - trace_backup_do_cow_write_fail(job, start, ret); | 151 | } |
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 | -- | 152 | -- |
242 | 2.17.1 | 153 | 2.40.1 |
243 | 154 | ||
244 | 155 | diff view generated by jsdifflib |