1
The following changes since commit a0def594286d9110a6035e02eef558cf3cf5d847:
1
The following changes since commit 88afdc92b644120e0182c8567e1b1d236e471b12:
2
2
3
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-01-30 10:23:20 +0000)
3
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2021-09-05 15:48:42 +0100)
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
https://gitlab.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 9bd2788f49c331b02372cc257b11e4c984d39708:
10
10
11
sheepdog: reorganize check for overlapping requests (2017-02-01 00:17:20 -0500)
11
block/nvme: Only report VFIO error on failed retry (2021-09-07 09:08:24 +0100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Block patches
14
Pull request
15
16
Userspace NVMe driver patches.
17
15
----------------------------------------------------------------
18
----------------------------------------------------------------
16
19
17
Paolo Bonzini (5):
20
Philippe Mathieu-Daudé (11):
18
sheepdog: remove unused cancellation support
21
block/nvme: Use safer trace format string
19
sheepdog: reorganize coroutine flow
22
util/vfio-helpers: Let qemu_vfio_verify_mappings() use error_report()
20
sheepdog: do not use BlockAIOCB
23
util/vfio-helpers: Replace qemu_mutex_lock() calls with
21
sheepdog: simplify inflight_aio_head management
24
QEMU_LOCK_GUARD
22
sheepdog: reorganize check for overlapping requests
25
util/vfio-helpers: Remove unreachable code in qemu_vfio_dma_map()
26
block/nvme: Have nvme_create_queue_pair() report errors consistently
27
util/vfio-helpers: Pass Error handle to qemu_vfio_dma_map()
28
util/vfio-helpers: Extract qemu_vfio_water_mark_reached()
29
util/vfio-helpers: Use error_setg in qemu_vfio_find_[fixed/temp]_iova
30
util/vfio-helpers: Simplify qemu_vfio_dma_map() returning directly
31
util/vfio-helpers: Let qemu_vfio_do_mapping() propagate Error
32
block/nvme: Only report VFIO error on failed retry
23
33
24
block/sheepdog.c | 289 ++++++++++++++++---------------------------------------
34
include/qemu/vfio-helpers.h | 2 +-
25
1 file changed, 84 insertions(+), 205 deletions(-)
35
block/nvme.c | 29 +++++++----
36
util/vfio-helpers.c | 99 ++++++++++++++++++++-----------------
37
block/trace-events | 2 +-
38
4 files changed, 76 insertions(+), 56 deletions(-)
26
39
27
--
40
--
28
2.9.3
41
2.31.1
29
42
30
43
44
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
2
3
Fix when building with -Wshorten-64-to-32:
4
5
warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
6
7
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20210902070025.197072-2-philmd@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
block/trace-events | 2 +-
13
1 file changed, 1 insertion(+), 1 deletion(-)
14
15
diff --git a/block/trace-events b/block/trace-events
16
index XXXXXXX..XXXXXXX 100644
17
--- a/block/trace-events
18
+++ b/block/trace-events
19
@@ -XXX,XX +XXX,XX @@ nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset 0x%"PRIx64" byte
20
nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset 0x%"PRIx64" bytes %"PRId64" ret %d"
21
nvme_dma_map_flush(void *s) "s %p"
22
nvme_free_req_queue_wait(void *s, unsigned q_index) "s %p q #%u"
23
-nvme_create_queue_pair(unsigned q_index, void *q, unsigned size, void *aio_context, int fd) "index %u q %p size %u aioctx %p fd %d"
24
+nvme_create_queue_pair(unsigned q_index, void *q, size_t size, void *aio_context, int fd) "index %u q %p size %zu aioctx %p fd %d"
25
nvme_free_queue_pair(unsigned q_index, void *q) "index %u q %p"
26
nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s %p cmd %p req %p qiov %p entries %d"
27
nvme_cmd_map_qiov_pages(void *s, int i, uint64_t page) "s %p page[%d] 0x%"PRIx64
28
--
29
2.31.1
30
31
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
2
3
Instead of displaying the error on stderr, use error_report()
4
which also report to the monitor.
5
6
Reviewed-by: Fam Zheng <fam@euphon.net>
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
9
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Message-id: 20210902070025.197072-3-philmd@redhat.com
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12
---
13
util/vfio-helpers.c | 4 ++--
14
1 file changed, 2 insertions(+), 2 deletions(-)
15
16
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/util/vfio-helpers.c
19
+++ b/util/vfio-helpers.c
20
@@ -XXX,XX +XXX,XX @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *s)
21
if (QEMU_VFIO_DEBUG) {
22
for (i = 0; i < s->nr_mappings - 1; ++i) {
23
if (!(s->mappings[i].host < s->mappings[i + 1].host)) {
24
- fprintf(stderr, "item %d not sorted!\n", i);
25
+ error_report("item %d not sorted!", i);
26
qemu_vfio_dump_mappings(s);
27
return false;
28
}
29
if (!(s->mappings[i].host + s->mappings[i].size <=
30
s->mappings[i + 1].host)) {
31
- fprintf(stderr, "item %d overlap with next!\n", i);
32
+ error_report("item %d overlap with next!", i);
33
qemu_vfio_dump_mappings(s);
34
return false;
35
}
36
--
37
2.31.1
38
39
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
2
3
Simplify qemu_vfio_dma_[un]map() handlers by replacing a pair of
4
qemu_mutex_lock/qemu_mutex_unlock calls by the WITH_QEMU_LOCK_GUARD
5
macro.
6
7
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20210902070025.197072-4-philmd@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
util/vfio-helpers.c | 9 +++------
13
1 file changed, 3 insertions(+), 6 deletions(-)
14
15
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/util/vfio-helpers.c
18
+++ b/util/vfio-helpers.c
19
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
20
assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
21
assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
22
trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
23
- qemu_mutex_lock(&s->lock);
24
+ QEMU_LOCK_GUARD(&s->lock);
25
mapping = qemu_vfio_find_mapping(s, host, &index);
26
if (mapping) {
27
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
28
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
29
*iova = iova0;
30
}
31
out:
32
- qemu_mutex_unlock(&s->lock);
33
return ret;
34
}
35
36
@@ -XXX,XX +XXX,XX @@ void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host)
37
}
38
39
trace_qemu_vfio_dma_unmap(s, host);
40
- qemu_mutex_lock(&s->lock);
41
+ QEMU_LOCK_GUARD(&s->lock);
42
m = qemu_vfio_find_mapping(s, host, &index);
43
if (!m) {
44
- goto out;
45
+ return;
46
}
47
qemu_vfio_undo_mapping(s, m, NULL);
48
-out:
49
- qemu_mutex_unlock(&s->lock);
50
}
51
52
static void qemu_vfio_reset(QEMUVFIOState *s)
53
--
54
2.31.1
55
56
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
2
3
qemu_vfio_add_mapping() returns a pointer to an indexed entry
4
in pre-allocated QEMUVFIOState::mappings[], thus can not be NULL.
5
Remove the pointless check.
6
7
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20210902070025.197072-5-philmd@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
12
util/vfio-helpers.c | 4 ----
13
1 file changed, 4 deletions(-)
14
15
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/util/vfio-helpers.c
18
+++ b/util/vfio-helpers.c
19
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
20
}
21
22
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
23
- if (!mapping) {
24
- ret = -ENOMEM;
25
- goto out;
26
- }
27
assert(qemu_vfio_verify_mappings(s));
28
ret = qemu_vfio_do_mapping(s, host, size, iova0);
29
if (ret) {
30
--
31
2.31.1
32
33
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
2
3
nvme_create_queue_pair() does not return a boolean value (indicating
4
eventual error) but a pointer, and is inconsistent in how it fills the
5
error handler. To fulfill callers expectations, always set an error
6
message on failure.
7
8
Reported-by: Auger Eric <eric.auger@redhat.com>
9
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
10
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Message-id: 20210902070025.197072-6-philmd@redhat.com
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
14
block/nvme.c | 3 +++
15
1 file changed, 3 insertions(+)
16
17
diff --git a/block/nvme.c b/block/nvme.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/block/nvme.c
20
+++ b/block/nvme.c
21
@@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
22
23
q = g_try_new0(NVMeQueuePair, 1);
24
if (!q) {
25
+ error_setg(errp, "Cannot allocate queue pair");
26
return NULL;
27
}
28
trace_nvme_create_queue_pair(idx, q, size, aio_context,
29
@@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
30
qemu_real_host_page_size);
31
q->prp_list_pages = qemu_try_memalign(qemu_real_host_page_size, bytes);
32
if (!q->prp_list_pages) {
33
+ error_setg(errp, "Cannot allocate PRP page list");
34
goto fail;
35
}
36
memset(q->prp_list_pages, 0, bytes);
37
@@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
38
r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes,
39
false, &prp_list_iova);
40
if (r) {
41
+ error_setg_errno(errp, -r, "Cannot map buffer for DMA");
42
goto fail;
43
}
44
q->free_req_head = -1;
45
--
46
2.31.1
47
48
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
Wrap the code that was copied repeatedly in the two functions,
3
Currently qemu_vfio_dma_map() displays errors on stderr.
4
sd_aio_setup and sd_aio_complete.
4
When using management interface, this information is simply
5
lost. Pass qemu_vfio_dma_map() an Error** handle so it can
6
propagate the error to callers.
5
7
6
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
Reviewed-by: Fam Zheng <fam@euphon.net>
7
Message-id: 20161129113245.32724-6-pbonzini@redhat.com
9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
8
Signed-off-by: Jeff Cody <jcody@redhat.com>
10
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
11
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Message-id: 20210902070025.197072-7-philmd@redhat.com
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
14
---
10
block/sheepdog.c | 66 ++++++++++++++++++++++++++------------------------------
15
include/qemu/vfio-helpers.h | 2 +-
11
1 file changed, 30 insertions(+), 36 deletions(-)
16
block/nvme.c | 22 +++++++++++-----------
17
util/vfio-helpers.c | 10 ++++++----
18
3 files changed, 18 insertions(+), 16 deletions(-)
12
19
13
diff --git a/block/sheepdog.c b/block/sheepdog.c
20
diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h
14
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
15
--- a/block/sheepdog.c
22
--- a/include/qemu/vfio-helpers.h
16
+++ b/block/sheepdog.c
23
+++ b/include/qemu/vfio-helpers.h
17
@@ -XXX,XX +XXX,XX @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb,
24
@@ -XXX,XX +XXX,XX @@ typedef struct QEMUVFIOState QEMUVFIOState;
18
return aio_req;
25
QEMUVFIOState *qemu_vfio_open_pci(const char *device, Error **errp);
26
void qemu_vfio_close(QEMUVFIOState *s);
27
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
28
- bool temporary, uint64_t *iova_list);
29
+ bool temporary, uint64_t *iova_list, Error **errp);
30
int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s);
31
void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host);
32
void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index,
33
diff --git a/block/nvme.c b/block/nvme.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/block/nvme.c
36
+++ b/block/nvme.c
37
@@ -XXX,XX +XXX,XX @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q,
38
return false;
39
}
40
memset(q->queue, 0, bytes);
41
- r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova);
42
+ r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova, errp);
43
if (r) {
44
- error_setg(errp, "Cannot map queue");
45
- return false;
46
+ error_prepend(errp, "Cannot map queue: ");
47
}
48
- return true;
49
+ return r == 0;
19
}
50
}
20
51
21
+static void wait_for_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *acb)
52
static void nvme_free_queue_pair(NVMeQueuePair *q)
22
+{
53
@@ -XXX,XX +XXX,XX @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
23
+ SheepdogAIOCB *cb;
54
qemu_co_queue_init(&q->free_req_queue);
24
+
55
q->completion_bh = aio_bh_new(aio_context, nvme_process_completion_bh, q);
25
+retry:
56
r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes,
26
+ QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) {
57
- false, &prp_list_iova);
27
+ if (AIOCBOverlapping(acb, cb)) {
58
+ false, &prp_list_iova, errp);
28
+ qemu_co_queue_wait(&s->overlapping_queue);
59
if (r) {
29
+ goto retry;
60
- error_setg_errno(errp, -r, "Cannot map buffer for DMA");
30
+ }
61
+ error_prepend(errp, "Cannot map buffer for DMA: ");
31
+ }
62
goto fail;
32
+}
63
}
33
+
64
q->free_req_head = -1;
34
static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
65
@@ -XXX,XX +XXX,XX @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
35
QEMUIOVector *qiov, int64_t sector_num, int nb_sectors,
66
error_setg(errp, "Cannot allocate buffer for identify response");
36
int type)
67
goto out;
37
@@ -XXX,XX +XXX,XX @@ static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
68
}
38
acb->min_dirty_data_idx = UINT32_MAX;
69
- r = qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova);
39
acb->max_dirty_data_idx = 0;
70
+ r = qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova, errp);
40
acb->aiocb_type = type;
71
if (r) {
41
+
72
- error_setg(errp, "Cannot map buffer for DMA");
42
+ if (type == AIOCB_FLUSH_CACHE) {
73
+ error_prepend(errp, "Cannot map buffer for DMA: ");
43
+ return;
74
goto out;
44
+ }
75
}
45
+
76
46
+ wait_for_overlapping_aiocb(s, acb);
77
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd,
47
+ QLIST_INSERT_HEAD(&s->inflight_aiocb_head, acb, aiocb_siblings);
78
try_map:
48
}
79
r = qemu_vfio_dma_map(s->vfio,
49
80
qiov->iov[i].iov_base,
50
/* Return -EIO in case of error, file descriptor on success */
81
- len, true, &iova);
51
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb)
82
+ len, true, &iova, NULL);
83
if (r == -ENOSPC) {
84
/*
85
* In addition to the -ENOMEM error, the VFIO_IOMMU_MAP_DMA
86
@@ -XXX,XX +XXX,XX @@ static void nvme_aio_unplug(BlockDriverState *bs)
87
static void nvme_register_buf(BlockDriverState *bs, void *host, size_t size)
88
{
89
int ret;
90
+ Error *local_err = NULL;
91
BDRVNVMeState *s = bs->opaque;
92
93
- ret = qemu_vfio_dma_map(s->vfio, host, size, false, NULL);
94
+ ret = qemu_vfio_dma_map(s->vfio, host, size, false, NULL, &local_err);
95
if (ret) {
96
/* FIXME: we may run out of IOVA addresses after repeated
97
* bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_unmap
98
* doesn't reclaim addresses for fixed mappings. */
99
- error_report("nvme_register_buf failed: %s", strerror(-ret));
100
+ error_reportf_err(local_err, "nvme_register_buf failed: ");
52
}
101
}
53
}
102
}
54
103
55
-static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb)
104
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
56
+static void sd_aio_complete(SheepdogAIOCB *acb)
105
index XXXXXXX..XXXXXXX 100644
106
--- a/util/vfio-helpers.c
107
+++ b/util/vfio-helpers.c
108
@@ -XXX,XX +XXX,XX @@ static void qemu_vfio_ram_block_added(RAMBlockNotifier *n, void *host,
109
size_t size, size_t max_size)
57
{
110
{
58
- SheepdogAIOCB *cb;
111
QEMUVFIOState *s = container_of(n, QEMUVFIOState, ram_notifier);
59
-
112
+ Error *local_err = NULL;
60
- QLIST_FOREACH(cb, &s->inflight_aiocb_head, aiocb_siblings) {
113
int ret;
61
- if (AIOCBOverlapping(aiocb, cb)) {
114
62
- return true;
115
trace_qemu_vfio_ram_block_added(s, host, max_size);
63
- }
116
- ret = qemu_vfio_dma_map(s, host, max_size, false, NULL);
64
+ if (acb->aiocb_type == AIOCB_FLUSH_CACHE) {
117
+ ret = qemu_vfio_dma_map(s, host, max_size, false, NULL, &local_err);
65
+ return;
118
if (ret) {
119
- error_report("qemu_vfio_dma_map(%p, %zu) failed: %s", host, max_size,
120
- strerror(-ret));
121
+ error_reportf_err(local_err,
122
+ "qemu_vfio_dma_map(%p, %zu) failed: ",
123
+ host, max_size);
66
}
124
}
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
}
125
}
73
126
74
static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
127
@@ -XXX,XX +XXX,XX @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
75
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
128
* mapping status within this area is not allowed).
76
}
129
*/
77
130
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
78
sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA);
131
- bool temporary, uint64_t *iova)
79
-
132
+ bool temporary, uint64_t *iova, Error **errp)
80
-retry:
133
{
81
- if (check_overlapping_aiocb(s, &acb)) {
134
int ret = 0;
82
- qemu_co_queue_wait(&s->overlapping_queue);
135
int index;
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
+
119
+ sd_aio_complete(&acb);
120
return acb.ret;
121
}
122
123
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset,
124
}
125
sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS,
126
count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ);
127
-
128
-retry:
129
- if (check_overlapping_aiocb(s, &acb)) {
130
- qemu_co_queue_wait(&s->overlapping_queue);
131
- goto retry;
132
- }
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
142
--
136
--
143
2.9.3
137
2.31.1
144
138
145
139
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
Add to the list in add_aio_request and, indirectly, resend_aioreq. Inline
3
Extract qemu_vfio_water_mark_reached() for readability,
4
free_aio_req in the caller, it does not simply undo alloc_aio_req's job.
4
and have it provide an error hint it its Error* handle.
5
5
6
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6
Suggested-by: Klaus Jensen <k.jensen@samsung.com>
7
Message-id: 20161129113245.32724-5-pbonzini@redhat.com
7
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
8
Signed-off-by: Jeff Cody <jcody@redhat.com>
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20210902070025.197072-8-philmd@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
11
---
10
block/sheepdog.c | 23 ++++++-----------------
12
util/vfio-helpers.c | 17 ++++++++++++++++-
11
1 file changed, 6 insertions(+), 17 deletions(-)
13
1 file changed, 16 insertions(+), 1 deletion(-)
12
14
13
diff --git a/block/sheepdog.c b/block/sheepdog.c
15
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/block/sheepdog.c
17
--- a/util/vfio-helpers.c
16
+++ b/block/sheepdog.c
18
+++ b/util/vfio-helpers.c
17
@@ -XXX,XX +XXX,XX @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb,
19
@@ -XXX,XX +XXX,XX @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
18
return aio_req;
20
return -ENOMEM;
19
}
21
}
20
22
21
-static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req)
23
+/**
22
-{
24
+ * qemu_vfio_water_mark_reached:
23
- SheepdogAIOCB *acb = aio_req->aiocb;
25
+ *
24
-
26
+ * Returns %true if high watermark has been reached, %false otherwise.
25
- QLIST_REMOVE(aio_req, aio_siblings);
27
+ */
26
- g_free(aio_req);
28
+static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size,
27
-
29
+ Error **errp)
28
- acb->nr_pending--;
30
+{
29
-}
31
+ if (s->high_water_mark - s->low_water_mark + 1 < size) {
30
-
32
+ error_setg(errp, "iova exhausted (water mark reached)");
31
static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s,
33
+ return true;
32
QEMUIOVector *qiov, int64_t sector_num, int nb_sectors,
34
+ }
33
int type)
35
+ return false;
34
@@ -XXX,XX +XXX,XX @@ static coroutine_fn void reconnect_to_sdog(void *opaque)
36
+}
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
+
37
+
58
+ if (!--acb->nr_pending) {
38
/* Map [host, host + size) area into a contiguous IOVA address space, and store
59
/*
39
* the result in @iova if not NULL. The caller need to make sure the area is
60
* We've finished all requests which belong to the AIOCB, so
40
* aligned to page size, and mustn't overlap with existing mapping areas (split
61
* we can switch back to sd_co_readv/writev now.
41
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
62
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req,
42
if (mapping) {
63
uint64_t old_oid = aio_req->base_oid;
43
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
64
bool create = aio_req->create;
44
} else {
65
45
- if (s->high_water_mark - s->low_water_mark + 1 < size) {
66
+ QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
46
+ if (qemu_vfio_water_mark_reached(s, size, errp)) {
67
+
47
ret = -ENOMEM;
68
if (!nr_copies) {
48
goto out;
69
error_report("bug");
49
}
70
}
71
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb)
72
iov.iov_len = sizeof(s->inode);
73
aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id),
74
data_len, offset, 0, false, 0, offset);
75
- QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
76
add_aio_request(s, aio_req, &iov, 1, AIOCB_WRITE_UDATA);
77
if (--acb->nr_pending) {
78
qemu_coroutine_yield();
79
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb)
80
old_oid,
81
acb->aiocb_type == AIOCB_DISCARD_OBJ ?
82
0 : done);
83
- QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
84
-
85
add_aio_request(s, aio_req, acb->qiov->iov, acb->qiov->niov,
86
acb->aiocb_type);
87
done:
88
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
89
acb.nr_pending++;
90
aio_req = alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id),
91
0, 0, 0, false, 0, 0);
92
- QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
93
add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type);
94
95
if (--acb.nr_pending) {
96
--
50
--
97
2.9.3
51
2.31.1
98
52
99
53
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
Delimit co_recv's lifetime clearly in aio_read_response.
3
Both qemu_vfio_find_fixed_iova() and qemu_vfio_find_temp_iova()
4
return an errno which is unused (or overwritten). Have them propagate
5
eventual errors to callers, returning a boolean (which is what the
6
Error API recommends, see commit e3fe3988d78 "error: Document Error
7
API usage rules" for rationale).
4
8
5
Do a simple qemu_coroutine_enter in aio_read_response, letting
9
Suggested-by: Klaus Jensen <k.jensen@samsung.com>
6
sd_co_writev call sd_write_done.
10
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
11
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Message-id: 20210902070025.197072-9-philmd@redhat.com
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
---
15
util/vfio-helpers.c | 24 ++++++++++++++----------
16
1 file changed, 14 insertions(+), 10 deletions(-)
7
17
8
Handle nr_pending in the same way in sd_co_rw_vector,
18
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
9
sd_write_done and sd_co_flush_to_disk.
10
11
Remove sd_co_rw_vector's return value; just leave with no
12
pending requests.
13
14
[Jeff: added missing 'return' back, spotted by Paolo after
15
series was applied.]
16
17
Signed-off-by: Jeff Cody <jcody@redhat.com>
18
---
19
block/sheepdog.c | 115 ++++++++++++++++++++-----------------------------------
20
1 file changed, 42 insertions(+), 73 deletions(-)
21
22
diff --git a/block/sheepdog.c b/block/sheepdog.c
23
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
24
--- a/block/sheepdog.c
20
--- a/util/vfio-helpers.c
25
+++ b/block/sheepdog.c
21
+++ b/util/vfio-helpers.c
26
@@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB {
22
@@ -XXX,XX +XXX,XX @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *s)
27
enum AIOCBState aiocb_type;
23
return true;
28
29
Coroutine *coroutine;
30
- void (*aio_done_func)(SheepdogAIOCB *);
31
-
32
int nr_pending;
33
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
}
24
}
57
25
58
-static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb)
26
-static int
59
-{
27
-qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
60
- qemu_coroutine_enter(acb->coroutine);
28
+static bool qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size,
61
- qemu_aio_unref(acb);
29
+ uint64_t *iova, Error **errp)
62
-}
30
{
63
-
31
int i;
64
static const AIOCBInfo sd_aiocb_info = {
32
65
.aiocb_size = sizeof(SheepdogAIOCB),
33
@@ -XXX,XX +XXX,XX @@ qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
66
};
34
s->usable_iova_ranges[i].end - s->low_water_mark + 1 == 0) {
67
@@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
35
*iova = s->low_water_mark;
68
acb->sector_num = sector_num;
36
s->low_water_mark += size;
69
acb->nb_sectors = nb_sectors;
37
- return 0;
70
38
+ return true;
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
}
39
}
87
}
40
}
88
41
- return -ENOMEM;
89
+ /* No more data for this aio_req (reload_inode below uses its own file
42
+ error_setg(errp, "fixed iova range not found");
90
+ * descriptor handler which doesn't use co_recv).
91
+ */
92
+ s->co_recv = NULL;
93
+
43
+
94
switch (rsp.result) {
44
+ return false;
95
case SD_RES_SUCCESS:
96
break;
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
}
45
}
122
46
123
@@ -XXX,XX +XXX,XX @@ static int sd_truncate(BlockDriverState *bs, int64_t offset)
47
-static int
124
/*
48
-qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
125
* This function is called after writing data objects. If we need to
49
+static bool qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size,
126
* update metadata, this sends a write request to the vdi object.
50
+ uint64_t *iova, Error **errp)
127
- * Otherwise, this switches back to sd_co_readv/writev.
128
*/
129
static void coroutine_fn sd_write_done(SheepdogAIOCB *acb)
130
{
51
{
131
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb)
52
int i;
132
mx = acb->max_dirty_data_idx;
53
133
if (mn <= mx) {
54
@@ -XXX,XX +XXX,XX @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
134
/* we need to update the vdi object. */
55
s->high_water_mark - s->usable_iova_ranges[i].start + 1 == 0) {
135
+ ++acb->nr_pending;
56
*iova = s->high_water_mark - size;
136
offset = sizeof(s->inode) - sizeof(s->inode.data_vdi_id) +
57
s->high_water_mark = *iova;
137
mn * sizeof(s->inode.data_vdi_id[0]);
58
- return 0;
138
data_len = (mx - mn + 1) * sizeof(s->inode.data_vdi_id[0]);
59
+ return true;
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
}
60
}
172
}
61
}
173
62
- return -ENOMEM;
174
@@ -XXX,XX +XXX,XX @@ static int coroutine_fn sd_co_rw_vector(void *p)
63
+ error_setg(errp, "temporary iova range not found");
175
idx++;
64
+
176
done += len;
65
+ return false;
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
}
66
}
186
67
187
static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb)
68
/**
188
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
69
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
189
}
70
goto out;
190
71
}
191
acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors);
72
if (!temporary) {
192
- acb->aio_done_func = sd_write_done;
73
- if (qemu_vfio_find_fixed_iova(s, size, &iova0)) {
193
acb->aiocb_type = AIOCB_WRITE_UDATA;
74
+ if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) {
194
75
ret = -ENOMEM;
195
retry:
76
goto out;
196
@@ -XXX,XX +XXX,XX @@ retry:
77
}
197
goto retry;
78
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
198
}
79
}
199
80
qemu_vfio_dump_mappings(s);
200
- ret = sd_co_rw_vector(acb);
81
} else {
201
- if (ret <= 0) {
82
- if (qemu_vfio_find_temp_iova(s, size, &iova0)) {
202
- QLIST_REMOVE(acb, aiocb_siblings);
83
+ if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
203
- qemu_co_queue_restart_all(&s->overlapping_queue);
84
ret = -ENOMEM;
204
- qemu_aio_unref(acb);
85
goto out;
205
- return ret;
86
}
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
--
87
--
318
2.9.3
88
2.31.1
319
89
320
90
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
Sheepdog's AIOCB are completely internal entities for a group of
3
To simplify qemu_vfio_dma_map():
4
requests and do not need dynamic allocation.
4
- reduce 'ret' (returned value) scope by returning errno directly,
5
- remove the goto 'out' label.
5
6
6
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
7
Message-id: 20161129113245.32724-4-pbonzini@redhat.com
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Signed-off-by: Jeff Cody <jcody@redhat.com>
9
Message-id: 20210902070025.197072-10-philmd@redhat.com
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9
---
11
---
10
block/sheepdog.c | 99 ++++++++++++++++++++++----------------------------------
12
util/vfio-helpers.c | 23 ++++++++++-------------
11
1 file changed, 39 insertions(+), 60 deletions(-)
13
1 file changed, 10 insertions(+), 13 deletions(-)
12
14
13
diff --git a/block/sheepdog.c b/block/sheepdog.c
15
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/block/sheepdog.c
17
--- a/util/vfio-helpers.c
16
+++ b/block/sheepdog.c
18
+++ b/util/vfio-helpers.c
17
@@ -XXX,XX +XXX,XX @@ static inline size_t count_data_objs(const struct SheepdogInode *inode)
19
@@ -XXX,XX +XXX,XX @@ static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size,
18
} while (0)
20
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
19
21
bool temporary, uint64_t *iova, Error **errp)
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
{
22
{
66
- SheepdogAIOCB *acb;
23
- int ret = 0;
67
uint32_t object_size;
24
int index;
68
- BDRVSheepdogState *s = bs->opaque;
25
IOVAMapping *mapping;
69
26
uint64_t iova0;
70
object_size = (UINT32_C(1) << s->inode.block_size_shift);
27
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
71
28
if (mapping) {
72
- acb = qemu_aio_get(&sd_aiocb_info, bs, NULL, NULL);
29
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
73
+ acb->s = s;
30
} else {
74
31
+ int ret;
75
acb->qiov = qiov;
32
+
76
33
if (qemu_vfio_water_mark_reached(s, size, errp)) {
77
@@ -XXX,XX +XXX,XX @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
34
- ret = -ENOMEM;
78
35
- goto out;
79
acb->min_dirty_data_idx = UINT32_MAX;
36
+ return -ENOMEM;
80
acb->max_dirty_data_idx = 0;
37
}
81
-
38
if (!temporary) {
82
- return acb;
39
if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) {
83
+ acb->aiocb_type = type;
40
- ret = -ENOMEM;
84
}
41
- goto out;
85
42
+ return -ENOMEM;
86
/* Return -EIO in case of error, file descriptor on success */
43
}
87
@@ -XXX,XX +XXX,XX @@ static int sd_truncate(BlockDriverState *bs, int64_t offset)
44
88
*/
45
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
89
static void coroutine_fn sd_write_done(SheepdogAIOCB *acb)
46
assert(qemu_vfio_verify_mappings(s));
90
{
47
ret = qemu_vfio_do_mapping(s, host, size, iova0);
91
- BDRVSheepdogState *s = acb->common.bs->opaque;
48
- if (ret) {
92
+ BDRVSheepdogState *s = acb->s;
49
+ if (ret < 0) {
93
struct iovec iov;
50
qemu_vfio_undo_mapping(s, mapping, NULL);
94
AIOReq *aio_req;
51
- goto out;
95
uint32_t offset, data_len, mn, mx;
52
+ return ret;
96
@@ -XXX,XX +XXX,XX @@ out:
53
}
97
* Returns 1 when we need to wait a response, 0 when there is no sent
54
qemu_vfio_dump_mappings(s);
98
* request and -errno in error cases.
55
} else {
99
*/
56
if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
100
-static void coroutine_fn sd_co_rw_vector(void *p)
57
- ret = -ENOMEM;
101
+static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb)
58
- goto out;
102
{
59
+ return -ENOMEM;
103
- SheepdogAIOCB *acb = p;
60
}
104
int ret = 0;
61
ret = qemu_vfio_do_mapping(s, host, size, iova0);
105
unsigned long len, done = 0, total = acb->nb_sectors * BDRV_SECTOR_SIZE;
62
- if (ret) {
106
unsigned long idx;
63
- goto out;
107
uint32_t object_size;
64
+ if (ret < 0) {
108
uint64_t oid;
65
+ return ret;
109
uint64_t offset;
66
}
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
}
67
}
126
}
68
}
127
69
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
128
- acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors);
70
if (iova) {
129
- acb->aiocb_type = AIOCB_WRITE_UDATA;
71
*iova = iova0;
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
}
72
}
138
73
-out:
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;
74
- return ret;
150
+ return acb.ret;
75
+ return 0;
151
}
76
}
152
77
153
static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num,
78
/* Reset the high watermark and free all "temporary" mappings. */
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;
194
}
195
196
- acb = sd_aio_setup(bs, NULL, 0, 0);
197
- acb->aiocb_type = AIOCB_FLUSH_CACHE;
198
+ sd_aio_setup(&acb, s, NULL, 0, 0, AIOCB_FLUSH_CACHE);
199
200
- acb->nr_pending++;
201
- aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id),
202
+ acb.nr_pending++;
203
+ aio_req = alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id),
204
0, 0, 0, false, 0, 0);
205
QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings);
206
- add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type);
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
}
218
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
--
79
--
262
2.9.3
80
2.31.1
263
81
264
82
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
2
3
Pass qemu_vfio_do_mapping() an Error* argument so it can propagate
4
any error to callers. Replace error_report() which only report
5
to the monitor by the more generic error_setg_errno().
6
7
Reviewed-by: Fam Zheng <fam@euphon.net>
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
10
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Message-id: 20210902070025.197072-11-philmd@redhat.com
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
14
util/vfio-helpers.c | 8 ++++----
15
1 file changed, 4 insertions(+), 4 deletions(-)
16
17
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/util/vfio-helpers.c
20
+++ b/util/vfio-helpers.c
21
@@ -XXX,XX +XXX,XX @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s,
22
23
/* Do the DMA mapping with VFIO. */
24
static int qemu_vfio_do_mapping(QEMUVFIOState *s, void *host, size_t size,
25
- uint64_t iova)
26
+ uint64_t iova, Error **errp)
27
{
28
struct vfio_iommu_type1_dma_map dma_map = {
29
.argsz = sizeof(dma_map),
30
@@ -XXX,XX +XXX,XX @@ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void *host, size_t size,
31
trace_qemu_vfio_do_mapping(s, host, iova, size);
32
33
if (ioctl(s->container, VFIO_IOMMU_MAP_DMA, &dma_map)) {
34
- error_report("VFIO_MAP_DMA failed: %s", strerror(errno));
35
+ error_setg_errno(errp, errno, "VFIO_MAP_DMA failed");
36
return -errno;
37
}
38
return 0;
39
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
40
41
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
42
assert(qemu_vfio_verify_mappings(s));
43
- ret = qemu_vfio_do_mapping(s, host, size, iova0);
44
+ ret = qemu_vfio_do_mapping(s, host, size, iova0, errp);
45
if (ret < 0) {
46
qemu_vfio_undo_mapping(s, mapping, NULL);
47
return ret;
48
@@ -XXX,XX +XXX,XX @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
49
if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
50
return -ENOMEM;
51
}
52
- ret = qemu_vfio_do_mapping(s, host, size, iova0);
53
+ ret = qemu_vfio_do_mapping(s, host, size, iova0, errp);
54
if (ret < 0) {
55
return ret;
56
}
57
--
58
2.31.1
59
60
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
SheepdogAIOCB is internal to sheepdog.c, hence it is never canceled.
3
We expect the first qemu_vfio_dma_map() to fail (indicating
4
DMA mappings exhaustion, see commit 15a730e7a3a). Do not
5
report the first failure as error, since we are going to
6
flush the mappings and retry.
4
7
5
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
This removes spurious error message displayed on the monitor:
6
Message-id: 20161129113245.32724-2-pbonzini@redhat.com
9
7
Signed-off-by: Jeff Cody <jcody@redhat.com>
10
(qemu) c
11
(qemu) qemu-kvm: VFIO_MAP_DMA failed: No space left on device
12
(qemu) info status
13
VM status: running
14
15
Reported-by: Tingting Mao <timao@redhat.com>
16
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
17
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
18
Message-id: 20210902070025.197072-12-philmd@redhat.com
19
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
8
---
20
---
9
block/sheepdog.c | 52 ----------------------------------------------------
21
block/nvme.c | 8 +++++++-
10
1 file changed, 52 deletions(-)
22
1 file changed, 7 insertions(+), 1 deletion(-)
11
23
12
diff --git a/block/sheepdog.c b/block/sheepdog.c
24
diff --git a/block/nvme.c b/block/nvme.c
13
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
14
--- a/block/sheepdog.c
26
--- a/block/nvme.c
15
+++ b/block/sheepdog.c
27
+++ b/block/nvme.c
16
@@ -XXX,XX +XXX,XX @@ struct SheepdogAIOCB {
28
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd,
17
Coroutine *coroutine;
29
uint64_t *pagelist = req->prp_list_page;
18
void (*aio_done_func)(SheepdogAIOCB *);
30
int i, j, r;
19
31
int entries = 0;
20
- bool cancelable;
32
+ Error *local_err = NULL, **errp = NULL;
21
int nr_pending;
33
22
34
assert(qiov->size);
23
uint32_t min_affect_data_idx;
35
assert(QEMU_IS_ALIGNED(qiov->size, s->page_size));
24
@@ -XXX,XX +XXX,XX @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req)
36
@@ -XXX,XX +XXX,XX @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd,
25
{
37
try_map:
26
SheepdogAIOCB *acb = aio_req->aiocb;
38
r = qemu_vfio_dma_map(s->vfio,
27
39
qiov->iov[i].iov_base,
28
- acb->cancelable = false;
40
- len, true, &iova, NULL);
29
QLIST_REMOVE(aio_req, aio_siblings);
41
+ len, true, &iova, errp);
30
g_free(aio_req);
42
if (r == -ENOSPC) {
31
43
/*
32
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb)
44
* In addition to the -ENOMEM error, the VFIO_IOMMU_MAP_DMA
33
qemu_aio_unref(acb);
45
@@ -XXX,XX +XXX,XX @@ try_map:
46
goto fail;
47
}
48
}
49
+ errp = &local_err;
50
+
51
goto try_map;
52
}
53
if (r) {
54
@@ -XXX,XX +XXX,XX @@ fail:
55
* because they are already mapped before calling this function; for
56
* temporary mappings, a later nvme_cmd_(un)map_qiov will reclaim by
57
* calling qemu_vfio_dma_reset_temporary when necessary. */
58
+ if (local_err) {
59
+ error_reportf_err(local_err, "Cannot map buffer for DMA: ");
60
+ }
61
return r;
34
}
62
}
35
63
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
--
64
--
99
2.9.3
65
2.31.1
100
66
101
67
diff view generated by jsdifflib