1 | The following changes since commit a0def594286d9110a6035e02eef558cf3cf5d847: | 1 | The following changes since commit fb68096da3d35e64c88cd610c1fa42766c58e92a: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-01-30 10:23:20 +0000) | 3 | Revert "tests: use memfd in vhost-user-test" (2018-02-13 09:51:52 +0000) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request | 7 | git://github.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to acf6e5f0962c4be670d4a93ede77423512521876: | 9 | for you to fetch changes up to 64b01feca991e5b19a5d750ef77cdca92b68bdbb: |
10 | 10 | ||
11 | sheepdog: reorganize check for overlapping requests (2017-02-01 00:17:20 -0500) | 11 | misc: fix spelling (2018-02-13 15:38:17 +0000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches | 14 | |
15 | ---------------------------------------------------------------- | 15 | ---------------------------------------------------------------- |
16 | 16 | ||
17 | Paolo Bonzini (5): | 17 | Fam Zheng (2): |
18 | sheepdog: remove unused cancellation support | 18 | Add a git-publish configuration file |
19 | sheepdog: reorganize coroutine flow | 19 | README: Document 'git-publish' workflow |
20 | sheepdog: do not use BlockAIOCB | ||
21 | sheepdog: simplify inflight_aio_head management | ||
22 | sheepdog: reorganize check for overlapping requests | ||
23 | 20 | ||
24 | block/sheepdog.c | 289 ++++++++++++++++--------------------------------------- | 21 | Marc-André Lureau (1): |
25 | 1 file changed, 84 insertions(+), 205 deletions(-) | 22 | misc: fix spelling |
23 | |||
24 | Stefan Hajnoczi (1): | ||
25 | vl: pause vcpus before stopping iothreads | ||
26 | |||
27 | Wolfgang Bumiller (1): | ||
28 | ratelimit: don't align wait time with slices | ||
29 | |||
30 | include/qemu/ratelimit.h | 11 ++++----- | ||
31 | util/qemu-coroutine-lock.c | 2 +- | ||
32 | vl.c | 12 ++++++++-- | ||
33 | .gitpublish | 58 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
34 | README | 31 ++++++++++++++++++++++++- | ||
35 | 5 files changed, 104 insertions(+), 10 deletions(-) | ||
36 | create mode 100644 .gitpublish | ||
26 | 37 | ||
27 | -- | 38 | -- |
28 | 2.9.3 | 39 | 2.14.3 |
29 | 40 | ||
30 | 41 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Fam Zheng <famz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Add to the list in add_aio_request and, indirectly, resend_aioreq. Inline | 3 | git-publish [1] is a convenient tool to send patches and has been |
4 | free_aio_req in the caller, it does not simply undo alloc_aio_req's job. | 4 | popular among QEMU developers. Recently it has been made available in |
5 | Fedora official repo thanks to Stefan's work. | ||
5 | 6 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 7 | One nice feature of the tool is a per-project configuration with |
7 | Message-id: 20161129113245.32724-5-pbonzini@redhat.com | 8 | profiles, especially in which the cccmd option is a handy method to |
8 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 9 | create the Cc list. |
10 | |||
11 | [1]: https://github.com/stefanha/git-publish | ||
12 | |||
13 | Signed-off-by: Fam Zheng <famz@redhat.com> | ||
14 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
15 | Message-id: 20180205054725.25634-2-famz@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | 17 | --- |
10 | block/sheepdog.c | 23 ++++++----------------- | 18 | .gitpublish | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 | 1 file changed, 6 insertions(+), 17 deletions(-) | 19 | 1 file changed, 58 insertions(+) |
20 | create mode 100644 .gitpublish | ||
12 | 21 | ||
13 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 22 | diff --git a/.gitpublish b/.gitpublish |
14 | index XXXXXXX..XXXXXXX 100644 | 23 | new file mode 100644 |
15 | --- a/block/sheepdog.c | 24 | index XXXXXXX..XXXXXXX |
16 | +++ b/block/sheepdog.c | 25 | --- /dev/null |
17 | @@ -XXX,XX +XXX,XX @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb, | 26 | +++ b/.gitpublish |
18 | return aio_req; | 27 | @@ -XXX,XX +XXX,XX @@ |
19 | } | 28 | +# |
20 | 29 | +# Common git-publish profiles that can be used to send patches to QEMU upstream. | |
21 | -static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | 30 | +# |
22 | -{ | 31 | +# See https://github.com/stefanha/git-publish for more information |
23 | - SheepdogAIOCB *acb = aio_req->aiocb; | 32 | +# |
24 | - | 33 | +[gitpublishprofile "default"] |
25 | - QLIST_REMOVE(aio_req, aio_siblings); | 34 | +base = master |
26 | - g_free(aio_req); | 35 | +prefix = PATCH |
27 | - | 36 | +to = qemu-devel@nongnu.org |
28 | - acb->nr_pending--; | 37 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null |
29 | -} | ||
30 | - | ||
31 | static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | ||
32 | QEMUIOVector *qiov, int64_t sector_num, int nb_sectors, | ||
33 | int type) | ||
34 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void reconnect_to_sdog(void *opaque) | ||
35 | while (!QLIST_EMPTY(&s->failed_aio_head)) { | ||
36 | aio_req = QLIST_FIRST(&s->failed_aio_head); | ||
37 | QLIST_REMOVE(aio_req, aio_siblings); | ||
38 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
39 | resend_aioreq(s, aio_req); | ||
40 | } | ||
41 | } | ||
42 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
43 | */ | ||
44 | s->co_recv = NULL; | ||
45 | |||
46 | + QLIST_REMOVE(aio_req, aio_siblings); | ||
47 | switch (rsp.result) { | ||
48 | case SD_RES_SUCCESS: | ||
49 | break; | ||
50 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
51 | break; | ||
52 | } | ||
53 | |||
54 | - free_aio_req(s, aio_req); | ||
55 | - if (!acb->nr_pending) { | ||
56 | + g_free(aio_req); | ||
57 | + | 38 | + |
58 | + if (!--acb->nr_pending) { | 39 | +[gitpublishprofile "rfc"] |
59 | /* | 40 | +base = master |
60 | * We've finished all requests which belong to the AIOCB, so | 41 | +prefix = RFC PATCH |
61 | * we can switch back to sd_co_readv/writev now. | 42 | +to = qemu-devel@nongnu.org |
62 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req, | 43 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null |
63 | uint64_t old_oid = aio_req->base_oid; | ||
64 | bool create = aio_req->create; | ||
65 | |||
66 | + QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
67 | + | 44 | + |
68 | if (!nr_copies) { | 45 | +[gitpublishprofile "stable"] |
69 | error_report("bug"); | 46 | +base = master |
70 | } | 47 | +prefix = PATCH |
71 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | 48 | +to = qemu-devel@nongnu.org |
72 | iov.iov_len = sizeof(s->inode); | 49 | +cc = qemu-stable@nongnu.org |
73 | aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), | 50 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null |
74 | data_len, offset, 0, false, 0, offset); | 51 | + |
75 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | 52 | +[gitpublishprofile "trivial"] |
76 | add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA); | 53 | +base = master |
77 | if (--acb->nr_pending) { | 54 | +prefix = PATCH |
78 | qemu_coroutine_yield(); | 55 | +to = qemu-devel@nongnu.org |
79 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) | 56 | +cc = qemu-trivial@nongnu.org |
80 | old_oid, | 57 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null |
81 | acb->aiocb_type == AIOCB_DISCARD_OBJ ? | 58 | + |
82 | 0 : done); | 59 | +[gitpublishprofile "block"] |
83 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | 60 | +base = master |
84 | - | 61 | +prefix = PATCH |
85 | add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov, | 62 | +to = qemu-devel@nongnu.org |
86 | acb->aiocb_type); | 63 | +cc = qemu-block@nongnu.org |
87 | done: | 64 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null |
88 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | 65 | + |
89 | acb.nr_pending++; | 66 | +[gitpublishprofile "arm"] |
90 | aio_req = alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id), | 67 | +base = master |
91 | 0, 0, 0, false, 0, 0); | 68 | +prefix = PATCH |
92 | - QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | 69 | +to = qemu-devel@nongnu.org |
93 | add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type); | 70 | +cc = qemu-arm@nongnu.org |
94 | 71 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null | |
95 | if (--acb.nr_pending) { | 72 | + |
73 | +[gitpublishprofile "s390"] | ||
74 | +base = master | ||
75 | +prefix = PATCH | ||
76 | +to = qemu-devel@nongnu.org | ||
77 | +cc = qemu-s390@nongnu.org | ||
78 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null | ||
79 | + | ||
80 | +[gitpublishprofile "ppc"] | ||
81 | +base = master | ||
82 | +prefix = PATCH | ||
83 | +to = qemu-devel@nongnu.org | ||
84 | +cc = qemu-ppc@nongnu.org | ||
85 | +cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null | ||
96 | -- | 86 | -- |
97 | 2.9.3 | 87 | 2.14.3 |
98 | 88 | ||
99 | 89 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Fam Zheng <famz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Wrap the code that was copied repeatedly in the two functions, | 3 | [Fixed s/git-profile/git-publish/ typo and s/for once/the first time/. |
4 | sd_aio_setup and sd_aio_complete. | 4 | --Stefan] |
5 | 5 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 6 | Signed-off-by: Fam Zheng <famz@redhat.com> |
7 | Message-id: 20161129113245.32724-6-pbonzini@redhat.com | 7 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
8 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 8 | Message-id: 20180205054725.25634-3-famz@redhat.com |
9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | 10 | --- |
10 | block/sheepdog.c | 66 ++++++++++++++++++++++++++------------------------------ | 11 | README | 31 ++++++++++++++++++++++++++++++- |
11 | 1 file changed, 30 insertions(+), 36 deletions(-) | 12 | 1 file changed, 30 insertions(+), 1 deletion(-) |
12 | 13 | ||
13 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 14 | diff --git a/README b/README |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/sheepdog.c | 16 | --- a/README |
16 | +++ b/block/sheepdog.c | 17 | +++ b/README |
17 | @@ -XXX,XX +XXX,XX @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb, | 18 | @@ -XXX,XX +XXX,XX @@ The QEMU source code is maintained under the GIT version control system. |
18 | return aio_req; | 19 | |
19 | } | 20 | git clone git://git.qemu.org/qemu.git |
20 | 21 | ||
21 | +static void wait_for_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *acb) | 22 | -When submitting patches, the preferred approach is to use 'git |
22 | +{ | 23 | +When submitting patches, one common approach is to use 'git |
23 | + SheepdogAIOCB *cb; | 24 | format-patch' and/or 'git send-email' to format & send the mail to the |
25 | qemu-devel@nongnu.org mailing list. All patches submitted must contain | ||
26 | a 'Signed-off-by' line from the author. Patches should follow the | ||
27 | guidelines set out in the HACKING and CODING_STYLE files. | ||
28 | |||
29 | +A 'git-publish' utility was created to make above process less | ||
30 | +cumbersome, and is highly recommended for making regular contributions, | ||
31 | +or even just for sending consecutive patch series revisions. It also | ||
32 | +requires a working 'git send-email' setup, and by default doesn't | ||
33 | +automate everything, so you may want to go through the above steps | ||
34 | +manually the first time. | ||
24 | + | 35 | + |
25 | +retry: | 36 | +For installation instructions, please go to |
26 | + QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) { | ||
27 | + if (AIOCBOverlapping(acb, cb)) { | ||
28 | + qemu_co_queue_wait(&s->overlapping_queue); | ||
29 | + goto retry; | ||
30 | + } | ||
31 | + } | ||
32 | +} | ||
33 | + | 37 | + |
34 | static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | 38 | + https://github.com/stefanha/git-publish |
35 | QEMUIOVector *qiov, int64_t sector_num, int nb_sectors, | ||
36 | int type) | ||
37 | @@ -XXX,XX +XXX,XX @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | ||
38 | acb->min_dirty_data_idx = UINT32_MAX; | ||
39 | acb->max_dirty_data_idx = 0; | ||
40 | acb->aiocb_type = type; | ||
41 | + | 39 | + |
42 | + if (type == AIOCB_FLUSH_CACHE) { | 40 | +The workflow with 'git-publish' is: |
43 | + return; | ||
44 | + } | ||
45 | + | 41 | + |
46 | + wait_for_overlapping_aiocb(s, acb); | 42 | + $ git checkout master -b my-feature |
47 | + QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings); | 43 | + $ # work on new commits, add your 'Signed-off-by' lines to each |
48 | } | 44 | + $ git publish |
49 | |||
50 | /* Return -EIO in case of error, file descriptor on success */ | ||
51 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | -static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb) | ||
56 | +static void sd_aio_complete(SheepdogAIOCB *acb) | ||
57 | { | ||
58 | - SheepdogAIOCB *cb; | ||
59 | - | ||
60 | - QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) { | ||
61 | - if (AIOCBOverlapping(aiocb, cb)) { | ||
62 | - return true; | ||
63 | - } | ||
64 | + if (acb->aiocb_type == AIOCB_FLUSH_CACHE) { | ||
65 | + return; | ||
66 | } | ||
67 | |||
68 | - QLIST_INSERT_HEAD(&s->inflight_aiocb_head, aiocb, aiocb_siblings); | ||
69 | - return false; | ||
70 | + QLIST_REMOVE(acb, aiocb_siblings); | ||
71 | + qemu_co_queue_restart_all(&acb->s->overlapping_queue); | ||
72 | } | ||
73 | |||
74 | static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
75 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
76 | } | ||
77 | |||
78 | sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA); | ||
79 | - | ||
80 | -retry: | ||
81 | - if (check_overlapping_aiocb(s, &acb)) { | ||
82 | - qemu_co_queue_wait(&s->overlapping_queue); | ||
83 | - goto retry; | ||
84 | - } | ||
85 | - | ||
86 | sd_co_rw_vector(&acb); | ||
87 | sd_write_done(&acb); | ||
88 | + sd_aio_complete(&acb); | ||
89 | |||
90 | - QLIST_REMOVE(&acb, aiocb_siblings); | ||
91 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
92 | return acb.ret; | ||
93 | } | ||
94 | |||
95 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
96 | BDRVSheepdogState *s = bs->opaque; | ||
97 | |||
98 | sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_READ_UDATA); | ||
99 | - | ||
100 | -retry: | ||
101 | - if (check_overlapping_aiocb(s, &acb)) { | ||
102 | - qemu_co_queue_wait(&s->overlapping_queue); | ||
103 | - goto retry; | ||
104 | - } | ||
105 | - | ||
106 | sd_co_rw_vector(&acb); | ||
107 | + sd_aio_complete(&acb); | ||
108 | |||
109 | - QLIST_REMOVE(&acb, aiocb_siblings); | ||
110 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
111 | return acb.ret; | ||
112 | } | ||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
115 | if (--acb.nr_pending) { | ||
116 | qemu_coroutine_yield(); | ||
117 | } | ||
118 | + | 45 | + |
119 | + sd_aio_complete(&acb); | 46 | +Your patch series will be sent and tagged as my-feature-v1 if you need to refer |
120 | return acb.ret; | 47 | +back to it in the future. |
121 | } | 48 | + |
122 | 49 | +Sending v2: | |
123 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | 50 | + |
124 | } | 51 | + $ git checkout my-feature # same topic branch |
125 | sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS, | 52 | + $ # making changes to the commits (using 'git rebase', for example) |
126 | count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ); | 53 | + $ git publish |
127 | - | 54 | + |
128 | -retry: | 55 | +Your patch series will be sent with 'v2' tag in the subject and the git tip |
129 | - if (check_overlapping_aiocb(s, &acb)) { | 56 | +will be tagged as my-feature-v2. |
130 | - qemu_co_queue_wait(&s->overlapping_queue); | 57 | + |
131 | - goto retry; | 58 | Additional information on submitting patches can be found online via |
132 | - } | 59 | the QEMU website |
133 | - | ||
134 | sd_co_rw_vector(&acb); | ||
135 | + sd_aio_complete(&acb); | ||
136 | |||
137 | - QLIST_REMOVE(&acb, aiocb_siblings); | ||
138 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
139 | return acb.ret; | ||
140 | } | ||
141 | 60 | ||
142 | -- | 61 | -- |
143 | 2.9.3 | 62 | 2.14.3 |
144 | 63 | ||
145 | 64 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | Commit dce8921b2baaf95974af8176406881872067adfa ("iothread: Stop threads |
---|---|---|---|
2 | before main() quits") introduced iothread_stop_all() to avoid the | ||
3 | following virtio-scsi assertion failure: | ||
2 | 4 | ||
3 | Delimit co_recv's lifetime clearly in aio_read_response. | 5 | assert(blk_get_aio_context(d->conf.blk) == s->ctx); |
4 | 6 | ||
5 | Do a simple qemu_coroutine_enter in aio_read_response, letting | 7 | Back then the assertion failed because when bdrv_close_all() made |
6 | sd_co_writev call sd_write_done. | 8 | d->conf.blk NULL, blk_get_aio_context() returned the global AioContext |
9 | instead of s->ctx. | ||
7 | 10 | ||
8 | Handle nr_pending in the same way in sd_co_rw_vector, | 11 | The same assertion can still fail today when vcpus submit new I/O |
9 | sd_write_done and sd_co_flush_to_disk. | 12 | requests after iothread_stop_all() has moved the BDS to the global |
13 | AioContext. | ||
10 | 14 | ||
11 | Remove sd_co_rw_vector's return value; just leave with no | 15 | This patch hardens the iothread_stop_all() approach by pausing vcpus |
12 | pending requests. | 16 | before calling iothread_stop_all(). |
13 | 17 | ||
14 | [Jeff: added missing 'return' back, spotted by Paolo after | 18 | Note that the assertion failure is a race condition. It is not possible |
15 | series was applied.] | 19 | to reproduce it reliably. |
16 | 20 | ||
17 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 21 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
22 | Message-id: 20180201110708.8080-1-stefanha@redhat.com | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
18 | --- | 24 | --- |
19 | block/sheepdog.c | 115 ++++++++++++++++++++----------------------------------- | 25 | vl.c | 12 ++++++++++-- |
20 | 1 file changed, 42 insertions(+), 73 deletions(-) | 26 | 1 file changed, 10 insertions(+), 2 deletions(-) |
21 | 27 | ||
22 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 28 | diff --git a/vl.c b/vl.c |
23 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/block/sheepdog.c | 30 | --- a/vl.c |
25 | +++ b/block/sheepdog.c | 31 | +++ b/vl.c |
26 | @@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB { | 32 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) |
27 | enum AIOCBState aiocb_type; | 33 | |
28 | 34 | main_loop(); | |
29 | Coroutine *coroutine; | 35 | replay_disable_events(); |
30 | - void (*aio_done_func)(SheepdogAIOCB *); | 36 | + |
37 | + /* The ordering of the following is delicate. Stop vcpus to prevent new | ||
38 | + * I/O requests being queued by the guest. Then stop IOThreads (this | ||
39 | + * includes a drain operation and completes all request processing). At | ||
40 | + * this point emulated devices are still associated with their IOThreads | ||
41 | + * (if any) but no longer have any work to do. Only then can we close | ||
42 | + * block devices safely because we know there is no more I/O coming. | ||
43 | + */ | ||
44 | + pause_all_vcpus(); | ||
45 | iothread_stop_all(); | ||
31 | - | 46 | - |
32 | int nr_pending; | 47 | - pause_all_vcpus(); |
33 | 48 | bdrv_close_all(); | |
34 | uint32_t min_affect_data_idx; | ||
35 | @@ -XXX,XX +XXX,XX @@ static const char * sd_strerror(int err) | ||
36 | * | ||
37 | * 1. In sd_co_rw_vector, we send the I/O requests to the server and | ||
38 | * link the requests to the inflight_list in the | ||
39 | - * BDRVSheepdogState. The function exits without waiting for | ||
40 | + * BDRVSheepdogState. The function yields while waiting for | ||
41 | * receiving the response. | ||
42 | * | ||
43 | * 2. We receive the response in aio_read_response, the fd handler to | ||
44 | - * the sheepdog connection. If metadata update is needed, we send | ||
45 | - * the write request to the vdi object in sd_write_done, the write | ||
46 | - * completion function. We switch back to sd_co_readv/writev after | ||
47 | - * all the requests belonging to the AIOCB are finished. | ||
48 | + * the sheepdog connection. We switch back to sd_co_readv/sd_writev | ||
49 | + * after all the requests belonging to the AIOCB are finished. If | ||
50 | + * needed, sd_co_writev will send another requests for the vdi object. | ||
51 | */ | ||
52 | |||
53 | static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb, | ||
54 | @@ -XXX,XX +XXX,XX @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | ||
55 | acb->nr_pending--; | ||
56 | } | ||
57 | |||
58 | -static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb) | ||
59 | -{ | ||
60 | - qemu_coroutine_enter(acb->coroutine); | ||
61 | - qemu_aio_unref(acb); | ||
62 | -} | ||
63 | - | ||
64 | static const AIOCBInfo sd_aiocb_info = { | ||
65 | .aiocb_size = sizeof(SheepdogAIOCB), | ||
66 | }; | ||
67 | @@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
68 | acb->sector_num = sector_num; | ||
69 | acb->nb_sectors = nb_sectors; | ||
70 | |||
71 | - acb->aio_done_func = NULL; | ||
72 | acb->coroutine = qemu_coroutine_self(); | ||
73 | acb->ret = 0; | ||
74 | acb->nr_pending = 0; | ||
75 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
76 | |||
77 | switch (acb->aiocb_type) { | ||
78 | case AIOCB_WRITE_UDATA: | ||
79 | - /* this coroutine context is no longer suitable for co_recv | ||
80 | - * because we may send data to update vdi objects */ | ||
81 | - s->co_recv = NULL; | ||
82 | if (!is_data_obj(aio_req->oid)) { | ||
83 | break; | ||
84 | } | ||
85 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
86 | } | ||
87 | } | ||
88 | |||
89 | + /* No more data for this aio_req (reload_inode below uses its own file | ||
90 | + * descriptor handler which doesn't use co_recv). | ||
91 | + */ | ||
92 | + s->co_recv = NULL; | ||
93 | + | 49 | + |
94 | switch (rsp.result) { | 50 | res_free(); |
95 | case SD_RES_SUCCESS: | 51 | |
96 | break; | 52 | /* vhost-user must be cleaned up before chardevs. */ |
97 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
98 | aio_req->oid = vid_to_vdi_oid(s->inode.vdi_id); | ||
99 | } | ||
100 | resend_aioreq(s, aio_req); | ||
101 | - goto out; | ||
102 | + return; | ||
103 | default: | ||
104 | acb->ret = -EIO; | ||
105 | error_report("%s", sd_strerror(rsp.result)); | ||
106 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn aio_read_response(void *opaque) | ||
107 | * We've finished all requests which belong to the AIOCB, so | ||
108 | * we can switch back to sd_co_readv/writev now. | ||
109 | */ | ||
110 | - acb->aio_done_func(acb); | ||
111 | + qemu_coroutine_enter(acb->coroutine); | ||
112 | } | ||
113 | -out: | ||
114 | - s->co_recv = NULL; | ||
115 | + | ||
116 | return; | ||
117 | + | ||
118 | err: | ||
119 | - s->co_recv = NULL; | ||
120 | reconnect_to_sdog(opaque); | ||
121 | } | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ static int sd_truncate(BlockDriverState *bs, int64_t offset) | ||
124 | /* | ||
125 | * This function is called after writing data objects. If we need to | ||
126 | * update metadata, this sends a write request to the vdi object. | ||
127 | - * Otherwise, this switches back to sd_co_readv/writev. | ||
128 | */ | ||
129 | static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
130 | { | ||
131 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
132 | mx = acb->max_dirty_data_idx; | ||
133 | if (mn <= mx) { | ||
134 | /* we need to update the vdi object. */ | ||
135 | + ++acb->nr_pending; | ||
136 | offset = sizeof(s->inode) - sizeof(s->inode.data_vdi_id) + | ||
137 | mn * sizeof(s->inode.data_vdi_id[0]); | ||
138 | data_len = (mx - mn + 1) * sizeof(s->inode.data_vdi_id[0]); | ||
139 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
140 | data_len, offset, 0, false, 0, offset); | ||
141 | QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
142 | add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA); | ||
143 | - | ||
144 | - acb->aio_done_func = sd_finish_aiocb; | ||
145 | - acb->aiocb_type = AIOCB_WRITE_UDATA; | ||
146 | - return; | ||
147 | + if (--acb->nr_pending) { | ||
148 | + qemu_coroutine_yield(); | ||
149 | + } | ||
150 | } | ||
151 | - | ||
152 | - sd_finish_aiocb(acb); | ||
153 | } | ||
154 | |||
155 | /* Delete current working VDI on the snapshot chain */ | ||
156 | @@ -XXX,XX +XXX,XX @@ out: | ||
157 | * Returns 1 when we need to wait a response, 0 when there is no sent | ||
158 | * request and -errno in error cases. | ||
159 | */ | ||
160 | -static int coroutine_fn sd_co_rw_vector(void *p) | ||
161 | +static void coroutine_fn sd_co_rw_vector(void *p) | ||
162 | { | ||
163 | SheepdogAIOCB *acb = p; | ||
164 | int ret = 0; | ||
165 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_rw_vector(void *p) | ||
166 | ret = sd_create_branch(s); | ||
167 | if (ret) { | ||
168 | acb->ret = -EIO; | ||
169 | - goto out; | ||
170 | + return; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_rw_vector(void *p) | ||
175 | idx++; | ||
176 | done += len; | ||
177 | } | ||
178 | -out: | ||
179 | - if (!--acb->nr_pending) { | ||
180 | - return acb->ret; | ||
181 | + if (--acb->nr_pending) { | ||
182 | + qemu_coroutine_yield(); | ||
183 | } | ||
184 | - return 1; | ||
185 | } | ||
186 | |||
187 | static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb) | ||
188 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
189 | } | ||
190 | |||
191 | acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
192 | - acb->aio_done_func = sd_write_done; | ||
193 | acb->aiocb_type = AIOCB_WRITE_UDATA; | ||
194 | |||
195 | retry: | ||
196 | @@ -XXX,XX +XXX,XX @@ retry: | ||
197 | goto retry; | ||
198 | } | ||
199 | |||
200 | - ret = sd_co_rw_vector(acb); | ||
201 | - if (ret <= 0) { | ||
202 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
203 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
204 | - qemu_aio_unref(acb); | ||
205 | - return ret; | ||
206 | - } | ||
207 | - | ||
208 | - qemu_coroutine_yield(); | ||
209 | + sd_co_rw_vector(acb); | ||
210 | + sd_write_done(acb); | ||
211 | |||
212 | QLIST_REMOVE(acb, aiocb_siblings); | ||
213 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
214 | - | ||
215 | - return acb->ret; | ||
216 | + ret = acb->ret; | ||
217 | + qemu_aio_unref(acb); | ||
218 | + return ret; | ||
219 | } | ||
220 | |||
221 | static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
222 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
223 | |||
224 | acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
225 | acb->aiocb_type = AIOCB_READ_UDATA; | ||
226 | - acb->aio_done_func = sd_finish_aiocb; | ||
227 | |||
228 | retry: | ||
229 | if (check_overlapping_aiocb(s, acb)) { | ||
230 | @@ -XXX,XX +XXX,XX @@ retry: | ||
231 | goto retry; | ||
232 | } | ||
233 | |||
234 | - ret = sd_co_rw_vector(acb); | ||
235 | - if (ret <= 0) { | ||
236 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
237 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
238 | - qemu_aio_unref(acb); | ||
239 | - return ret; | ||
240 | - } | ||
241 | - | ||
242 | - qemu_coroutine_yield(); | ||
243 | + sd_co_rw_vector(acb); | ||
244 | |||
245 | QLIST_REMOVE(acb, aiocb_siblings); | ||
246 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
247 | - return acb->ret; | ||
248 | + ret = acb->ret; | ||
249 | + qemu_aio_unref(acb); | ||
250 | + return ret; | ||
251 | } | ||
252 | |||
253 | static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
254 | { | ||
255 | BDRVSheepdogState *s = bs->opaque; | ||
256 | SheepdogAIOCB *acb; | ||
257 | + int ret; | ||
258 | AIOReq *aio_req; | ||
259 | |||
260 | if (s->cache_flags != SD_FLAG_CMD_CACHE) { | ||
261 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
262 | |||
263 | acb = sd_aio_setup(bs, NULL, 0, 0); | ||
264 | acb->aiocb_type = AIOCB_FLUSH_CACHE; | ||
265 | - acb->aio_done_func = sd_finish_aiocb; | ||
266 | |||
267 | + acb->nr_pending++; | ||
268 | aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), | ||
269 | 0, 0, 0, false, 0, 0); | ||
270 | QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | ||
271 | add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type); | ||
272 | |||
273 | - qemu_coroutine_yield(); | ||
274 | - return acb->ret; | ||
275 | + if (--acb->nr_pending) { | ||
276 | + qemu_coroutine_yield(); | ||
277 | + } | ||
278 | + ret = acb->ret; | ||
279 | + qemu_aio_unref(acb); | ||
280 | + return ret; | ||
281 | } | ||
282 | |||
283 | static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) | ||
284 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | ||
285 | acb = sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS, | ||
286 | count >> BDRV_SECTOR_BITS); | ||
287 | acb->aiocb_type = AIOCB_DISCARD_OBJ; | ||
288 | - acb->aio_done_func = sd_finish_aiocb; | ||
289 | |||
290 | retry: | ||
291 | if (check_overlapping_aiocb(s, acb)) { | ||
292 | @@ -XXX,XX +XXX,XX @@ retry: | ||
293 | goto retry; | ||
294 | } | ||
295 | |||
296 | - ret = sd_co_rw_vector(acb); | ||
297 | - if (ret <= 0) { | ||
298 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
299 | - qemu_co_queue_restart_all(&s->overlapping_queue); | ||
300 | - qemu_aio_unref(acb); | ||
301 | - return ret; | ||
302 | - } | ||
303 | - | ||
304 | - qemu_coroutine_yield(); | ||
305 | + sd_co_rw_vector(acb); | ||
306 | |||
307 | QLIST_REMOVE(acb, aiocb_siblings); | ||
308 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
309 | - | ||
310 | - return acb->ret; | ||
311 | + ret = acb->ret; | ||
312 | + qemu_aio_unref(acb); | ||
313 | + return ret; | ||
314 | } | ||
315 | |||
316 | static coroutine_fn int64_t | ||
317 | -- | 53 | -- |
318 | 2.9.3 | 54 | 2.14.3 |
319 | 55 | ||
320 | 56 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> |
---|---|---|---|
2 | 2 | ||
3 | Sheepdog's AIOCB are completely internal entities for a group of | 3 | It is possible for rate limited writes to keep overshooting a slice's |
4 | requests and do not need dynamic allocation. | 4 | quota by a tiny amount causing the slice-aligned waiting period to |
5 | effectively halve the rate. | ||
5 | 6 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 7 | Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com> |
7 | Message-id: 20161129113245.32724-4-pbonzini@redhat.com | 8 | Reviewed-by: Alberto Garcia <berto@igalia.com> |
8 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 9 | Message-id: 20180207071758.6818-1-w.bumiller@proxmox.com |
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | 11 | --- |
10 | block/sheepdog.c | 99 ++++++++++++++++++++++---------------------------------- | 12 | include/qemu/ratelimit.h | 11 +++++------ |
11 | 1 file changed, 39 insertions(+), 60 deletions(-) | 13 | 1 file changed, 5 insertions(+), 6 deletions(-) |
12 | 14 | ||
13 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 15 | diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/block/sheepdog.c | 17 | --- a/include/qemu/ratelimit.h |
16 | +++ b/block/sheepdog.c | 18 | +++ b/include/qemu/ratelimit.h |
17 | @@ -XXX,XX +XXX,XX @@ static inline size_t count_data_objs(const struct SheepdogInode *inode) | 19 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
18 | } while (0) | 20 | static inline int64_t ratelimit_calculate_delay(RateLimit *limit, uint64_t n) |
19 | |||
20 | typedef struct SheepdogAIOCB SheepdogAIOCB; | ||
21 | +typedef struct BDRVSheepdogState BDRVSheepdogState; | ||
22 | |||
23 | typedef struct AIOReq { | ||
24 | SheepdogAIOCB *aiocb; | ||
25 | @@ -XXX,XX +XXX,XX @@ enum AIOCBState { | ||
26 | || y->max_affect_data_idx < x->min_affect_data_idx)) | ||
27 | |||
28 | struct SheepdogAIOCB { | ||
29 | - BlockAIOCB common; | ||
30 | + BDRVSheepdogState *s; | ||
31 | |||
32 | QEMUIOVector *qiov; | ||
33 | |||
34 | @@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB { | ||
35 | QLIST_ENTRY(SheepdogAIOCB) aiocb_siblings; | ||
36 | }; | ||
37 | |||
38 | -typedef struct BDRVSheepdogState { | ||
39 | +struct BDRVSheepdogState { | ||
40 | BlockDriverState *bs; | ||
41 | AioContext *aio_context; | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVSheepdogState { | ||
44 | |||
45 | CoQueue overlapping_queue; | ||
46 | QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head; | ||
47 | -} BDRVSheepdogState; | ||
48 | +}; | ||
49 | |||
50 | typedef struct BDRVSheepdogReopenState { | ||
51 | int fd; | ||
52 | @@ -XXX,XX +XXX,XX @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | ||
53 | acb->nr_pending--; | ||
54 | } | ||
55 | |||
56 | -static const AIOCBInfo sd_aiocb_info = { | ||
57 | - .aiocb_size = sizeof(SheepdogAIOCB), | ||
58 | -}; | ||
59 | - | ||
60 | -static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
61 | - int64_t sector_num, int nb_sectors) | ||
62 | +static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, | ||
63 | + QEMUIOVector *qiov, int64_t sector_num, int nb_sectors, | ||
64 | + int type) | ||
65 | { | 21 | { |
66 | - SheepdogAIOCB *acb; | 22 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); |
67 | uint32_t object_size; | 23 | - uint64_t delay_slices; |
68 | - BDRVSheepdogState *s = bs->opaque; | 24 | + double delay_slices; |
69 | 25 | ||
70 | object_size = (UINT32_C(1) << s->inode.block_size_shift); | 26 | assert(limit->slice_quota && limit->slice_ns); |
71 | 27 | ||
72 | - acb = qemu_aio_get(&sd_aiocb_info, bs, NULL, NULL); | 28 | @@ -XXX,XX +XXX,XX @@ static inline int64_t ratelimit_calculate_delay(RateLimit *limit, uint64_t n) |
73 | + acb->s = s; | ||
74 | |||
75 | acb->qiov = qiov; | ||
76 | |||
77 | @@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
78 | |||
79 | acb->min_dirty_data_idx = UINT32_MAX; | ||
80 | acb->max_dirty_data_idx = 0; | ||
81 | - | ||
82 | - return acb; | ||
83 | + acb->aiocb_type = type; | ||
84 | } | ||
85 | |||
86 | /* Return -EIO in case of error, file descriptor on success */ | ||
87 | @@ -XXX,XX +XXX,XX @@ static int sd_truncate(BlockDriverState *bs, int64_t offset) | ||
88 | */ | ||
89 | static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) | ||
90 | { | ||
91 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
92 | + BDRVSheepdogState *s = acb->s; | ||
93 | struct iovec iov; | ||
94 | AIOReq *aio_req; | ||
95 | uint32_t offset, data_len, mn, mx; | ||
96 | @@ -XXX,XX +XXX,XX @@ out: | ||
97 | * Returns 1 when we need to wait a response, 0 when there is no sent | ||
98 | * request and -errno in error cases. | ||
99 | */ | ||
100 | -static void coroutine_fn sd_co_rw_vector(void *p) | ||
101 | +static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) | ||
102 | { | ||
103 | - SheepdogAIOCB *acb = p; | ||
104 | int ret = 0; | ||
105 | unsigned long len, done = 0, total = acb->nb_sectors * BDRV_SECTOR_SIZE; | ||
106 | unsigned long idx; | ||
107 | uint32_t object_size; | ||
108 | uint64_t oid; | ||
109 | uint64_t offset; | ||
110 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
111 | + BDRVSheepdogState *s = acb->s; | ||
112 | SheepdogInode *inode = &s->inode; | ||
113 | AIOReq *aio_req; | ||
114 | |||
115 | @@ -XXX,XX +XXX,XX @@ static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb) | ||
116 | static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
117 | int nb_sectors, QEMUIOVector *qiov) | ||
118 | { | ||
119 | - SheepdogAIOCB *acb; | ||
120 | + SheepdogAIOCB acb; | ||
121 | int ret; | ||
122 | int64_t offset = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE; | ||
123 | BDRVSheepdogState *s = bs->opaque; | ||
124 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
125 | } | ||
126 | } | ||
127 | |||
128 | - acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
129 | - acb->aiocb_type = AIOCB_WRITE_UDATA; | ||
130 | + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA); | ||
131 | |||
132 | retry: | ||
133 | - if (check_overlapping_aiocb(s, acb)) { | ||
134 | + if (check_overlapping_aiocb(s, &acb)) { | ||
135 | qemu_co_queue_wait(&s->overlapping_queue); | ||
136 | goto retry; | ||
137 | } | ||
138 | |||
139 | - sd_co_rw_vector(acb); | ||
140 | - sd_write_done(acb); | ||
141 | + sd_co_rw_vector(&acb); | ||
142 | + sd_write_done(&acb); | ||
143 | |||
144 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
145 | + QLIST_REMOVE(&acb, aiocb_siblings); | ||
146 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
147 | - ret = acb->ret; | ||
148 | - qemu_aio_unref(acb); | ||
149 | - return ret; | ||
150 | + return acb.ret; | ||
151 | } | ||
152 | |||
153 | static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
154 | int nb_sectors, QEMUIOVector *qiov) | ||
155 | { | ||
156 | - SheepdogAIOCB *acb; | ||
157 | - int ret; | ||
158 | + SheepdogAIOCB acb; | ||
159 | BDRVSheepdogState *s = bs->opaque; | ||
160 | |||
161 | - acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); | ||
162 | - acb->aiocb_type = AIOCB_READ_UDATA; | ||
163 | + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_READ_UDATA); | ||
164 | |||
165 | retry: | ||
166 | - if (check_overlapping_aiocb(s, acb)) { | ||
167 | + if (check_overlapping_aiocb(s, &acb)) { | ||
168 | qemu_co_queue_wait(&s->overlapping_queue); | ||
169 | goto retry; | ||
170 | } | ||
171 | |||
172 | - sd_co_rw_vector(acb); | ||
173 | + sd_co_rw_vector(&acb); | ||
174 | |||
175 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
176 | + QLIST_REMOVE(&acb, aiocb_siblings); | ||
177 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
178 | - ret = acb->ret; | ||
179 | - qemu_aio_unref(acb); | ||
180 | - return ret; | ||
181 | + return acb.ret; | ||
182 | } | ||
183 | |||
184 | static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) | ||
185 | { | ||
186 | BDRVSheepdogState *s = bs->opaque; | ||
187 | - SheepdogAIOCB *acb; | ||
188 | - int ret; | ||
189 | + SheepdogAIOCB acb; | ||
190 | AIOReq *aio_req; | ||
191 | |||
192 | if (s->cache_flags != SD_FLAG_CMD_CACHE) { | ||
193 | return 0; | 29 | return 0; |
194 | } | 30 | } |
195 | 31 | ||
196 | - acb = sd_aio_setup(bs, NULL, 0, 0); | 32 | - /* Quota exceeded. Calculate the next time slice we may start |
197 | - acb->aiocb_type = AIOCB_FLUSH_CACHE; | 33 | - * sending data again. */ |
198 | + sd_aio_setup(&acb, s, NULL, 0, 0, AIOCB_FLUSH_CACHE); | 34 | - delay_slices = (limit->dispatched + limit->slice_quota - 1) / |
199 | 35 | - limit->slice_quota; | |
200 | - acb->nr_pending++; | 36 | + /* Quota exceeded. Wait based on the excess amount and then start a new |
201 | - aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), | 37 | + * slice. */ |
202 | + acb.nr_pending++; | 38 | + delay_slices = (double)limit->dispatched / limit->slice_quota; |
203 | + aio_req = alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id), | 39 | limit->slice_end_time = limit->slice_start_time + |
204 | 0, 0, 0, false, 0, 0); | 40 | - delay_slices * limit->slice_ns; |
205 | QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); | 41 | + (uint64_t)(delay_slices * limit->slice_ns); |
206 | - add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type); | 42 | return limit->slice_end_time - now; |
207 | + add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type); | ||
208 | |||
209 | - if (--acb->nr_pending) { | ||
210 | + if (--acb.nr_pending) { | ||
211 | qemu_coroutine_yield(); | ||
212 | } | ||
213 | - ret = acb->ret; | ||
214 | - qemu_aio_unref(acb); | ||
215 | - return ret; | ||
216 | + return acb.ret; | ||
217 | } | 43 | } |
218 | 44 | ||
219 | static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) | ||
220 | @@ -XXX,XX +XXX,XX @@ static int sd_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, | ||
221 | static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | ||
222 | int count) | ||
223 | { | ||
224 | - SheepdogAIOCB *acb; | ||
225 | + SheepdogAIOCB acb; | ||
226 | BDRVSheepdogState *s = bs->opaque; | ||
227 | - int ret; | ||
228 | QEMUIOVector discard_iov; | ||
229 | struct iovec iov; | ||
230 | uint32_t zero = 0; | ||
231 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, | ||
232 | if (!QEMU_IS_ALIGNED(offset | count, BDRV_SECTOR_SIZE)) { | ||
233 | return -ENOTSUP; | ||
234 | } | ||
235 | - acb = sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS, | ||
236 | - count >> BDRV_SECTOR_BITS); | ||
237 | - acb->aiocb_type = AIOCB_DISCARD_OBJ; | ||
238 | + sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS, | ||
239 | + count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ); | ||
240 | |||
241 | retry: | ||
242 | - if (check_overlapping_aiocb(s, acb)) { | ||
243 | + if (check_overlapping_aiocb(s, &acb)) { | ||
244 | qemu_co_queue_wait(&s->overlapping_queue); | ||
245 | goto retry; | ||
246 | } | ||
247 | |||
248 | - sd_co_rw_vector(acb); | ||
249 | + sd_co_rw_vector(&acb); | ||
250 | |||
251 | - QLIST_REMOVE(acb, aiocb_siblings); | ||
252 | + QLIST_REMOVE(&acb, aiocb_siblings); | ||
253 | qemu_co_queue_restart_all(&s->overlapping_queue); | ||
254 | - ret = acb->ret; | ||
255 | - qemu_aio_unref(acb); | ||
256 | - return ret; | ||
257 | + return acb.ret; | ||
258 | } | ||
259 | |||
260 | static coroutine_fn int64_t | ||
261 | -- | 45 | -- |
262 | 2.9.3 | 46 | 2.14.3 |
263 | 47 | ||
264 | 48 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Marc-André Lureau <marcandre.lureau@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | SheepdogAIOCB is internal to sheepdog.c, hence it is never canceled. | 3 | s/pupulate/populate |
4 | 4 | ||
5 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 5 | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> |
6 | Message-id: 20161129113245.32724-2-pbonzini@redhat.com | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Jeff Cody <jcody@redhat.com> | 7 | Message-id: 20180208162447.10851-1-marcandre.lureau@redhat.com |
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | 9 | --- |
9 | block/sheepdog.c | 52 ---------------------------------------------------- | 10 | util/qemu-coroutine-lock.c | 2 +- |
10 | 1 file changed, 52 deletions(-) | 11 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 12 | ||
12 | diff --git a/block/sheepdog.c b/block/sheepdog.c | 13 | diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/block/sheepdog.c | 15 | --- a/util/qemu-coroutine-lock.c |
15 | +++ b/block/sheepdog.c | 16 | +++ b/util/qemu-coroutine-lock.c |
16 | @@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB { | 17 | @@ -XXX,XX +XXX,XX @@ void qemu_co_queue_run_restart(Coroutine *co) |
17 | Coroutine *coroutine; | 18 | * invalid memory. Therefore, use a temporary queue and do not touch |
18 | void (*aio_done_func)(SheepdogAIOCB *); | 19 | * the "co" coroutine as soon as you enter another one. |
19 | 20 | * | |
20 | - bool cancelable; | 21 | - * In its turn resumed "co" can pupulate "co_queue_wakeup" queue with |
21 | int nr_pending; | 22 | + * In its turn resumed "co" can populate "co_queue_wakeup" queue with |
22 | 23 | * new coroutines to be woken up. The caller, who has resumed "co", | |
23 | uint32_t min_affect_data_idx; | 24 | * will be responsible for traversing the same queue, which may cause |
24 | @@ -XXX,XX +XXX,XX @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) | 25 | * a different wakeup order but not any missing wakeups. |
25 | { | ||
26 | SheepdogAIOCB *acb = aio_req->aiocb; | ||
27 | |||
28 | - acb->cancelable = false; | ||
29 | QLIST_REMOVE(aio_req, aio_siblings); | ||
30 | g_free(aio_req); | ||
31 | |||
32 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb) | ||
33 | qemu_aio_unref(acb); | ||
34 | } | ||
35 | |||
36 | -/* | ||
37 | - * Check whether the specified acb can be canceled | ||
38 | - * | ||
39 | - * We can cancel aio when any request belonging to the acb is: | ||
40 | - * - Not processed by the sheepdog server. | ||
41 | - * - Not linked to the inflight queue. | ||
42 | - */ | ||
43 | -static bool sd_acb_cancelable(const SheepdogAIOCB *acb) | ||
44 | -{ | ||
45 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
46 | - AIOReq *aioreq; | ||
47 | - | ||
48 | - if (!acb->cancelable) { | ||
49 | - return false; | ||
50 | - } | ||
51 | - | ||
52 | - QLIST_FOREACH(aioreq, &s->inflight_aio_head, aio_siblings) { | ||
53 | - if (aioreq->aiocb == acb) { | ||
54 | - return false; | ||
55 | - } | ||
56 | - } | ||
57 | - | ||
58 | - return true; | ||
59 | -} | ||
60 | - | ||
61 | -static void sd_aio_cancel(BlockAIOCB *blockacb) | ||
62 | -{ | ||
63 | - SheepdogAIOCB *acb = (SheepdogAIOCB *)blockacb; | ||
64 | - BDRVSheepdogState *s = acb->common.bs->opaque; | ||
65 | - AIOReq *aioreq, *next; | ||
66 | - | ||
67 | - if (sd_acb_cancelable(acb)) { | ||
68 | - /* Remove outstanding requests from failed queue. */ | ||
69 | - QLIST_FOREACH_SAFE(aioreq, &s->failed_aio_head, aio_siblings, | ||
70 | - next) { | ||
71 | - if (aioreq->aiocb == acb) { | ||
72 | - free_aio_req(s, aioreq); | ||
73 | - } | ||
74 | - } | ||
75 | - | ||
76 | - assert(acb->nr_pending == 0); | ||
77 | - if (acb->common.cb) { | ||
78 | - acb->common.cb(acb->common.opaque, -ECANCELED); | ||
79 | - } | ||
80 | - sd_finish_aiocb(acb); | ||
81 | - } | ||
82 | -} | ||
83 | - | ||
84 | static const AIOCBInfo sd_aiocb_info = { | ||
85 | .aiocb_size = sizeof(SheepdogAIOCB), | ||
86 | - .cancel_async = sd_aio_cancel, | ||
87 | }; | ||
88 | |||
89 | static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
90 | @@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, | ||
91 | acb->nb_sectors = nb_sectors; | ||
92 | |||
93 | acb->aio_done_func = NULL; | ||
94 | - acb->cancelable = true; | ||
95 | acb->coroutine = qemu_coroutine_self(); | ||
96 | acb->ret = 0; | ||
97 | acb->nr_pending = 0; | ||
98 | -- | 26 | -- |
99 | 2.9.3 | 27 | 2.14.3 |
100 | 28 | ||
101 | 29 | diff view generated by jsdifflib |