1 | The following changes since commit d992f2f1368ceb92e6bfd8efece174110f4236ff: | 1 | The following changes since commit 66547f416a61e0cb711dc76821890242432ba193: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/artyom/tags/pull-sun4v-20170226' into staging (2017-02-26 22:40:23 +0000) | 3 | block/nvme: invoke blk_io_plug_call() outside q->lock (2023-07-17 09:17:41 -0400) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/stefanha/qemu.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 1ab17f9f5c63c2798d707aeb22588e4fcc17b2cd: | 9 | for you to fetch changes up to 1c38fe69e2b8a05c1762b122292fa7e3662f06fd: |
10 | 10 | ||
11 | tests-aio-multithread: use atomic_read properly (2017-02-27 14:00:53 +0000) | 11 | block/blkio: use blkio_set_int("fd") to check fd support (2023-07-27 15:51:46 -0400) |
12 | |||
13 | ---------------------------------------------------------------- | ||
14 | Pull request | ||
15 | |||
16 | Please include these bug fixes in QEMU 8.1. Thanks! | ||
12 | 17 | ||
13 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
14 | 19 | ||
15 | ---------------------------------------------------------------- | 20 | Hanna Czenczek (1): |
21 | block: Fix pad_request's request restriction | ||
16 | 22 | ||
17 | Paolo Bonzini (4): | 23 | Sam Li (1): |
18 | curl: do not use aio_context_acquire/release | 24 | block/file-posix: fix g_file_get_contents return path |
19 | nfs: do not use aio_context_acquire/release | ||
20 | iscsi: do not use aio_context_acquire/release | ||
21 | tests-aio-multithread: use atomic_read properly | ||
22 | 25 | ||
23 | block/curl.c | 24 ++++++++----- | 26 | Stefano Garzarella (6): |
24 | block/iscsi.c | 83 ++++++++++++++++++++++++++++++++++---------- | 27 | block/blkio: enable the completion eventfd |
25 | block/nfs.c | 23 +++++++++--- | 28 | block/blkio: do not use open flags in qemu_open() |
26 | tests/test-aio-multithread.c | 4 +-- | 29 | block/blkio: move blkio_connect() in the drivers functions |
27 | 4 files changed, 100 insertions(+), 34 deletions(-) | 30 | block/blkio: retry blkio_connect() if it fails using `fd` |
31 | block/blkio: fall back on using `path` when `fd` setting fails | ||
32 | block/blkio: use blkio_set_int("fd") to check fd support | ||
33 | |||
34 | block/blkio.c | 132 ++++++++++++++++++++++++++++++--------------- | ||
35 | block/file-posix.c | 6 +-- | ||
36 | block/io.c | 8 ++- | ||
37 | 3 files changed, 97 insertions(+), 49 deletions(-) | ||
28 | 38 | ||
29 | -- | 39 | -- |
30 | 2.9.3 | 40 | 2.41.0 |
31 | |||
32 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Stefano Garzarella <sgarzare@redhat.com> | ||
1 | 2 | ||
3 | Until libblkio 1.3.0, virtio-blk drivers had completion eventfd | ||
4 | notifications enabled from the start, but from the next releases | ||
5 | this is no longer the case, so we have to explicitly enable them. | ||
6 | |||
7 | In fact, the libblkio documentation says they could be disabled, | ||
8 | so we should always enable them at the start if we want to be | ||
9 | sure to get completion eventfd notifications: | ||
10 | |||
11 | By default, the driver might not generate completion events for | ||
12 | requests so it is necessary to explicitly enable the completion | ||
13 | file descriptor before use: | ||
14 | |||
15 | void blkioq_set_completion_fd_enabled(struct blkioq *q, bool enable); | ||
16 | |||
17 | I discovered this while trying a development version of libblkio: | ||
18 | the guest kernel hangs during boot, while probing the device. | ||
19 | |||
20 | Fixes: fd66dbd424f5 ("blkio: add libblkio block driver") | ||
21 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
22 | Message-id: 20230725103744.77343-1-sgarzare@redhat.com | ||
23 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
24 | --- | ||
25 | block/blkio.c | 1 + | ||
26 | 1 file changed, 1 insertion(+) | ||
27 | |||
28 | diff --git a/block/blkio.c b/block/blkio.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/block/blkio.c | ||
31 | +++ b/block/blkio.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, | ||
33 | QLIST_INIT(&s->bounce_bufs); | ||
34 | s->blkioq = blkio_get_queue(s->blkio, 0); | ||
35 | s->completion_fd = blkioq_get_completion_fd(s->blkioq); | ||
36 | + blkioq_set_completion_fd_enabled(s->blkioq, true); | ||
37 | |||
38 | blkio_attach_aio_context(bs, bdrv_get_aio_context(bs)); | ||
39 | return 0; | ||
40 | -- | ||
41 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Now that all bottom halves and callbacks take care of taking the | 3 | qemu_open() in blkio_virtio_blk_common_open() is used to open the |
4 | AioContext lock, we can migrate some users away from it and to a | 4 | character device (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or in |
5 | specific QemuMutex or CoMutex. | 5 | the future eventually the unix socket. |
6 | 6 | ||
7 | Protect libnfs calls with a QemuMutex. Callbacks are invoked | 7 | In all these cases we cannot open the path in read-only mode, |
8 | using bottom halves, so we don't even have to drop it around | 8 | when the `read-only` option of blockdev is on, because the exchange |
9 | callback invocations. | 9 | of IOCTL commands for example will fail. |
10 | 10 | ||
11 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 11 | In order to open the device read-only, we have to use the `read-only` |
12 | Message-id: 20170222180725.28611-3-pbonzini@redhat.com | 12 | property of the libblkio driver as we already do in blkio_file_open(). |
13 | |||
14 | Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") | ||
15 | Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2225439 | ||
16 | Reported-by: Qing Wang <qinwang@redhat.com> | ||
17 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
18 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
19 | Message-id: 20230726074807.14041-1-sgarzare@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
14 | --- | 21 | --- |
15 | block/nfs.c | 23 +++++++++++++++++++---- | 22 | block/blkio.c | 21 ++++++++++++--------- |
16 | 1 file changed, 19 insertions(+), 4 deletions(-) | 23 | 1 file changed, 12 insertions(+), 9 deletions(-) |
17 | 24 | ||
18 | diff --git a/block/nfs.c b/block/nfs.c | 25 | diff --git a/block/blkio.c b/block/blkio.c |
19 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/block/nfs.c | 27 | --- a/block/blkio.c |
21 | +++ b/block/nfs.c | 28 | +++ b/block/blkio.c |
22 | @@ -XXX,XX +XXX,XX @@ typedef struct NFSClient { | 29 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs, |
23 | int events; | 30 | * layer through the "/dev/fdset/N" special path. |
24 | bool has_zero_init; | 31 | */ |
25 | AioContext *aio_context; | 32 | if (fd_supported) { |
26 | + QemuMutex mutex; | 33 | - int open_flags; |
27 | blkcnt_t st_blocks; | 34 | - |
28 | bool cache_used; | 35 | - if (flags & BDRV_O_RDWR) { |
29 | NFSServer *server; | 36 | - open_flags = O_RDWR; |
30 | @@ -XXX,XX +XXX,XX @@ static void nfs_parse_filename(const char *filename, QDict *options, | 37 | - } else { |
31 | static void nfs_process_read(void *arg); | 38 | - open_flags = O_RDONLY; |
32 | static void nfs_process_write(void *arg); | 39 | - } |
33 | 40 | - | |
34 | +/* Called with QemuMutex held. */ | 41 | - fd = qemu_open(path, open_flags, errp); |
35 | static void nfs_set_events(NFSClient *client) | 42 | + /* |
36 | { | 43 | + * `path` can contain the path of a character device |
37 | int ev = nfs_which_events(client->context); | 44 | + * (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or a unix socket. |
38 | @@ -XXX,XX +XXX,XX @@ static void nfs_process_read(void *arg) | 45 | + * |
39 | { | 46 | + * So, we should always open it with O_RDWR flag, also if BDRV_O_RDWR |
40 | NFSClient *client = arg; | 47 | + * is not set in the open flags, because the exchange of IOCTL commands |
41 | 48 | + * for example will fail. | |
42 | - aio_context_acquire(client->aio_context); | 49 | + * |
43 | + qemu_mutex_lock(&client->mutex); | 50 | + * In order to open the device read-only, we are using the `read-only` |
44 | nfs_service(client->context, POLLIN); | 51 | + * property of the libblkio driver in blkio_file_open(). |
45 | nfs_set_events(client); | 52 | + */ |
46 | - aio_context_release(client->aio_context); | 53 | + fd = qemu_open(path, O_RDWR, errp); |
47 | + qemu_mutex_unlock(&client->mutex); | 54 | if (fd < 0) { |
48 | } | 55 | return -EINVAL; |
49 | |||
50 | static void nfs_process_write(void *arg) | ||
51 | { | ||
52 | NFSClient *client = arg; | ||
53 | |||
54 | - aio_context_acquire(client->aio_context); | ||
55 | + qemu_mutex_lock(&client->mutex); | ||
56 | nfs_service(client->context, POLLOUT); | ||
57 | nfs_set_events(client); | ||
58 | - aio_context_release(client->aio_context); | ||
59 | + qemu_mutex_unlock(&client->mutex); | ||
60 | } | ||
61 | |||
62 | static void nfs_co_init_task(BlockDriverState *bs, NFSRPC *task) | ||
63 | @@ -XXX,XX +XXX,XX @@ static void nfs_co_generic_bh_cb(void *opaque) | ||
64 | aio_co_wake(task->co); | ||
65 | } | ||
66 | |||
67 | +/* Called (via nfs_service) with QemuMutex held. */ | ||
68 | static void | ||
69 | nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, | ||
70 | void *private_data) | ||
71 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset, | ||
72 | nfs_co_init_task(bs, &task); | ||
73 | task.iov = iov; | ||
74 | |||
75 | + qemu_mutex_lock(&client->mutex); | ||
76 | if (nfs_pread_async(client->context, client->fh, | ||
77 | offset, bytes, nfs_co_generic_cb, &task) != 0) { | ||
78 | + qemu_mutex_unlock(&client->mutex); | ||
79 | return -ENOMEM; | ||
80 | } | ||
81 | |||
82 | nfs_set_events(client); | ||
83 | + qemu_mutex_unlock(&client->mutex); | ||
84 | while (!task.complete) { | ||
85 | qemu_coroutine_yield(); | ||
86 | } | ||
87 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset, | ||
88 | buf = iov->iov[0].iov_base; | ||
89 | } | ||
90 | |||
91 | + qemu_mutex_lock(&client->mutex); | ||
92 | if (nfs_pwrite_async(client->context, client->fh, | ||
93 | offset, bytes, buf, | ||
94 | nfs_co_generic_cb, &task) != 0) { | ||
95 | + qemu_mutex_unlock(&client->mutex); | ||
96 | if (my_buffer) { | ||
97 | g_free(buf); | ||
98 | } | 56 | } |
99 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset, | ||
100 | } | ||
101 | |||
102 | nfs_set_events(client); | ||
103 | + qemu_mutex_unlock(&client->mutex); | ||
104 | while (!task.complete) { | ||
105 | qemu_coroutine_yield(); | ||
106 | } | ||
107 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn nfs_co_flush(BlockDriverState *bs) | ||
108 | |||
109 | nfs_co_init_task(bs, &task); | ||
110 | |||
111 | + qemu_mutex_lock(&client->mutex); | ||
112 | if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, | ||
113 | &task) != 0) { | ||
114 | + qemu_mutex_unlock(&client->mutex); | ||
115 | return -ENOMEM; | ||
116 | } | ||
117 | |||
118 | nfs_set_events(client); | ||
119 | + qemu_mutex_unlock(&client->mutex); | ||
120 | while (!task.complete) { | ||
121 | qemu_coroutine_yield(); | ||
122 | } | ||
123 | @@ -XXX,XX +XXX,XX @@ static void nfs_file_close(BlockDriverState *bs) | ||
124 | { | ||
125 | NFSClient *client = bs->opaque; | ||
126 | nfs_client_close(client); | ||
127 | + qemu_mutex_destroy(&client->mutex); | ||
128 | } | ||
129 | |||
130 | static NFSServer *nfs_config(QDict *options, Error **errp) | ||
131 | @@ -XXX,XX +XXX,XX @@ static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags, | ||
132 | if (ret < 0) { | ||
133 | return ret; | ||
134 | } | ||
135 | + qemu_mutex_init(&client->mutex); | ||
136 | bs->total_sectors = ret; | ||
137 | ret = 0; | ||
138 | return ret; | ||
139 | @@ -XXX,XX +XXX,XX @@ static int nfs_has_zero_init(BlockDriverState *bs) | ||
140 | return client->has_zero_init; | ||
141 | } | ||
142 | |||
143 | +/* Called (via nfs_service) with QemuMutex held. */ | ||
144 | static void | ||
145 | nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data, | ||
146 | void *private_data) | ||
147 | -- | 57 | -- |
148 | 2.9.3 | 58 | 2.41.0 |
149 | 59 | ||
150 | 60 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Sam Li <faithilikerun@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | nodes[id].next is written by other threads. If atomic_read is not used | 3 | The g_file_get_contents() function returns a g_boolean. If it fails, the |
4 | (matching atomic_set in mcs_mutex_lock!) the compiler can optimize the | 4 | returned value will be 0 instead of -1. Solve the issue by skipping |
5 | whole "if" away! | 5 | assigning ret value. |
6 | 6 | ||
7 | Reported-by: Alex Bennée <alex.bennee@linaro.org> | 7 | This issue was found by Matthew Rosato using virtio-blk-{pci,ccw} backed |
8 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 8 | by an NVMe partition e.g. /dev/nvme0n1p1 on s390x. |
9 | Tested-by: Greg Kurz <groug@kaod.org> | 9 | |
10 | Message-id: 20170227111726.9237-1-pbonzini@redhat.com | 10 | Signed-off-by: Sam Li <faithilikerun@gmail.com> |
11 | Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> | ||
12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
14 | Message-id: 20230727115844.8480-1-faithilikerun@gmail.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 16 | --- |
13 | tests/test-aio-multithread.c | 4 ++-- | 17 | block/file-posix.c | 6 ++---- |
14 | 1 file changed, 2 insertions(+), 2 deletions(-) | 18 | 1 file changed, 2 insertions(+), 4 deletions(-) |
15 | 19 | ||
16 | diff --git a/tests/test-aio-multithread.c b/tests/test-aio-multithread.c | 20 | diff --git a/block/file-posix.c b/block/file-posix.c |
17 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/test-aio-multithread.c | 22 | --- a/block/file-posix.c |
19 | +++ b/tests/test-aio-multithread.c | 23 | +++ b/block/file-posix.c |
20 | @@ -XXX,XX +XXX,XX @@ static void mcs_mutex_lock(void) | 24 | @@ -XXX,XX +XXX,XX @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st) |
21 | static void mcs_mutex_unlock(void) | 25 | static int get_sysfs_str_val(struct stat *st, const char *attribute, |
22 | { | 26 | char **val) { |
23 | int next; | 27 | g_autofree char *sysfspath = NULL; |
24 | - if (nodes[id].next == -1) { | 28 | - int ret; |
25 | + if (atomic_read(&nodes[id].next) == -1) { | 29 | size_t len; |
26 | if (atomic_read(&mutex_head) == id && | 30 | |
27 | atomic_cmpxchg(&mutex_head, id, -1) == id) { | 31 | if (!S_ISBLK(st->st_mode)) { |
28 | /* Last item in the list, exit. */ | 32 | @@ -XXX,XX +XXX,XX @@ static int get_sysfs_str_val(struct stat *st, const char *attribute, |
29 | @@ -XXX,XX +XXX,XX @@ static void mcs_mutex_unlock(void) | 33 | sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", |
34 | major(st->st_rdev), minor(st->st_rdev), | ||
35 | attribute); | ||
36 | - ret = g_file_get_contents(sysfspath, val, &len, NULL); | ||
37 | - if (ret == -1) { | ||
38 | + if (!g_file_get_contents(sysfspath, val, &len, NULL)) { | ||
39 | return -ENOENT; | ||
30 | } | 40 | } |
31 | 41 | ||
32 | /* Wake up the next in line. */ | 42 | @@ -XXX,XX +XXX,XX @@ static int get_sysfs_str_val(struct stat *st, const char *attribute, |
33 | - next = nodes[id].next; | 43 | if (*(p + len - 1) == '\n') { |
34 | + next = atomic_read(&nodes[id].next); | 44 | *(p + len - 1) = '\0'; |
35 | nodes[next].locked = 0; | 45 | } |
36 | qemu_futex_wake(&nodes[next].locked, 1); | 46 | - return ret; |
47 | + return 0; | ||
37 | } | 48 | } |
49 | #endif | ||
50 | |||
38 | -- | 51 | -- |
39 | 2.9.3 | 52 | 2.41.0 |
40 | 53 | ||
41 | 54 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Hanna Czenczek <hreitz@redhat.com> | ||
1 | 2 | ||
3 | bdrv_pad_request() relies on requests' lengths not to exceed SIZE_MAX, | ||
4 | which bdrv_check_qiov_request() does not guarantee. | ||
5 | |||
6 | bdrv_check_request32() however will guarantee this, and both of | ||
7 | bdrv_pad_request()'s callers (bdrv_co_preadv_part() and | ||
8 | bdrv_co_pwritev_part()) already run it before calling | ||
9 | bdrv_pad_request(). Therefore, bdrv_pad_request() can safely call | ||
10 | bdrv_check_request32() without expecting error, too. | ||
11 | |||
12 | In effect, this patch will not change guest-visible behavior. It is a | ||
13 | clean-up to tighten a condition to match what is guaranteed by our | ||
14 | callers, and which exists purely to show clearly why the subsequent | ||
15 | assertion (`assert(*bytes <= SIZE_MAX)`) is always true. | ||
16 | |||
17 | Note there is a difference between the interfaces of | ||
18 | bdrv_check_qiov_request() and bdrv_check_request32(): The former takes | ||
19 | an errp, the latter does not, so we can no longer just pass | ||
20 | &error_abort. Instead, we need to check the returned value. While we | ||
21 | do expect success (because the callers have already run this function), | ||
22 | an assert(ret == 0) is not much simpler than just to return an error if | ||
23 | it occurs, so let us handle errors by returning them up the stack now. | ||
24 | |||
25 | Reported-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | Signed-off-by: Hanna Czenczek <hreitz@redhat.com> | ||
27 | Message-id: 20230714085938.202730-1-hreitz@redhat.com | ||
28 | Fixes: 18743311b829cafc1737a5f20bc3248d5f91ee2a | ||
29 | ("block: Collapse padded I/O vecs exceeding IOV_MAX") | ||
30 | Signed-off-by: Hanna Czenczek <hreitz@redhat.com> | ||
31 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
32 | --- | ||
33 | block/io.c | 8 ++++++-- | ||
34 | 1 file changed, 6 insertions(+), 2 deletions(-) | ||
35 | |||
36 | diff --git a/block/io.c b/block/io.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/block/io.c | ||
39 | +++ b/block/io.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static int bdrv_pad_request(BlockDriverState *bs, | ||
41 | int sliced_niov; | ||
42 | size_t sliced_head, sliced_tail; | ||
43 | |||
44 | - bdrv_check_qiov_request(*offset, *bytes, *qiov, *qiov_offset, &error_abort); | ||
45 | + /* Should have been checked by the caller already */ | ||
46 | + ret = bdrv_check_request32(*offset, *bytes, *qiov, *qiov_offset); | ||
47 | + if (ret < 0) { | ||
48 | + return ret; | ||
49 | + } | ||
50 | |||
51 | if (!bdrv_init_padding(bs, *offset, *bytes, write, pad)) { | ||
52 | if (padded) { | ||
53 | @@ -XXX,XX +XXX,XX @@ static int bdrv_pad_request(BlockDriverState *bs, | ||
54 | &sliced_head, &sliced_tail, | ||
55 | &sliced_niov); | ||
56 | |||
57 | - /* Guaranteed by bdrv_check_qiov_request() */ | ||
58 | + /* Guaranteed by bdrv_check_request32() */ | ||
59 | assert(*bytes <= SIZE_MAX); | ||
60 | ret = bdrv_create_padded_qiov(bs, pad, sliced_iov, sliced_niov, | ||
61 | sliced_head, *bytes); | ||
62 | -- | ||
63 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Now that all bottom halves and callbacks take care of taking the | 3 | This is in preparation for the next patch, where for virtio-blk |
4 | AioContext lock, we can migrate some users away from it and to a | 4 | drivers we need to handle the failure of blkio_connect(). |
5 | specific QemuMutex or CoMutex. | ||
6 | 5 | ||
7 | Protect libiscsi calls with a QemuMutex. Callbacks are invoked | 6 | Let's also rename the *_open() functions to *_connect() to make |
8 | using bottom halves, so we don't even have to drop it around | 7 | the code reflect the changes applied. |
9 | callback invocations. | ||
10 | 8 | ||
11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> |
12 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 10 | Message-id: 20230727161020.84213-2-sgarzare@redhat.com |
13 | Message-id: 20170222180725.28611-4-pbonzini@redhat.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
15 | --- | 12 | --- |
16 | block/iscsi.c | 83 +++++++++++++++++++++++++++++++++++++++++++++-------------- | 13 | block/blkio.c | 71 ++++++++++++++++++++++++++++++--------------------- |
17 | 1 file changed, 64 insertions(+), 19 deletions(-) | 14 | 1 file changed, 42 insertions(+), 29 deletions(-) |
18 | 15 | ||
19 | diff --git a/block/iscsi.c b/block/iscsi.c | 16 | diff --git a/block/blkio.c b/block/blkio.c |
20 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/block/iscsi.c | 18 | --- a/block/blkio.c |
22 | +++ b/block/iscsi.c | 19 | +++ b/block/blkio.c |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct IscsiLun { | 20 | @@ -XXX,XX +XXX,XX @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size) |
24 | int events; | 21 | } |
25 | QEMUTimer *nop_timer; | ||
26 | QEMUTimer *event_timer; | ||
27 | + QemuMutex mutex; | ||
28 | struct scsi_inquiry_logical_block_provisioning lbp; | ||
29 | struct scsi_inquiry_block_limits bl; | ||
30 | unsigned char *zeroblock; | ||
31 | @@ -XXX,XX +XXX,XX @@ static int iscsi_translate_sense(struct scsi_sense *sense) | ||
32 | return ret; | ||
33 | } | 22 | } |
34 | 23 | ||
35 | +/* Called (via iscsi_service) with QemuMutex held. */ | 24 | -static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, |
36 | static void | 25 | - Error **errp) |
37 | iscsi_co_generic_cb(struct iscsi_context *iscsi, int status, | 26 | +static int blkio_io_uring_connect(BlockDriverState *bs, QDict *options, |
38 | void *command_data, void *opaque) | 27 | + int flags, Error **errp) |
39 | @@ -XXX,XX +XXX,XX @@ static const AIOCBInfo iscsi_aiocb_info = { | ||
40 | static void iscsi_process_read(void *arg); | ||
41 | static void iscsi_process_write(void *arg); | ||
42 | |||
43 | +/* Called with QemuMutex held. */ | ||
44 | static void | ||
45 | iscsi_set_events(IscsiLun *iscsilun) | ||
46 | { | 28 | { |
47 | @@ -XXX,XX +XXX,XX @@ iscsi_process_read(void *arg) | 29 | const char *filename = qdict_get_str(options, "filename"); |
48 | IscsiLun *iscsilun = arg; | 30 | BDRVBlkioState *s = bs->opaque; |
49 | struct iscsi_context *iscsi = iscsilun->iscsi; | 31 | @@ -XXX,XX +XXX,XX @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, |
50 | |||
51 | - aio_context_acquire(iscsilun->aio_context); | ||
52 | + qemu_mutex_lock(&iscsilun->mutex); | ||
53 | iscsi_service(iscsi, POLLIN); | ||
54 | iscsi_set_events(iscsilun); | ||
55 | - aio_context_release(iscsilun->aio_context); | ||
56 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
57 | } | ||
58 | |||
59 | static void | ||
60 | @@ -XXX,XX +XXX,XX @@ iscsi_process_write(void *arg) | ||
61 | IscsiLun *iscsilun = arg; | ||
62 | struct iscsi_context *iscsi = iscsilun->iscsi; | ||
63 | |||
64 | - aio_context_acquire(iscsilun->aio_context); | ||
65 | + qemu_mutex_lock(&iscsilun->mutex); | ||
66 | iscsi_service(iscsi, POLLOUT); | ||
67 | iscsi_set_events(iscsilun); | ||
68 | - aio_context_release(iscsilun->aio_context); | ||
69 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
70 | } | ||
71 | |||
72 | static int64_t sector_lun2qemu(int64_t sector, IscsiLun *iscsilun) | ||
73 | @@ -XXX,XX +XXX,XX @@ iscsi_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors, | ||
74 | uint64_t lba; | ||
75 | uint32_t num_sectors; | ||
76 | bool fua = flags & BDRV_REQ_FUA; | ||
77 | + int r = 0; | ||
78 | |||
79 | if (fua) { | ||
80 | assert(iscsilun->dpofua); | ||
81 | @@ -XXX,XX +XXX,XX @@ iscsi_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors, | ||
82 | lba = sector_qemu2lun(sector_num, iscsilun); | ||
83 | num_sectors = sector_qemu2lun(nb_sectors, iscsilun); | ||
84 | iscsi_co_init_iscsitask(iscsilun, &iTask); | ||
85 | + qemu_mutex_lock(&iscsilun->mutex); | ||
86 | retry: | ||
87 | if (iscsilun->use_16_for_rw) { | ||
88 | #if LIBISCSI_API_VERSION >= (20160603) | ||
89 | @@ -XXX,XX +XXX,XX @@ retry: | ||
90 | #endif | ||
91 | while (!iTask.complete) { | ||
92 | iscsi_set_events(iscsilun); | ||
93 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
94 | qemu_coroutine_yield(); | ||
95 | + qemu_mutex_lock(&iscsilun->mutex); | ||
96 | } | ||
97 | |||
98 | if (iTask.task != NULL) { | ||
99 | @@ -XXX,XX +XXX,XX @@ retry: | ||
100 | |||
101 | if (iTask.status != SCSI_STATUS_GOOD) { | ||
102 | iscsi_allocmap_set_invalid(iscsilun, sector_num, nb_sectors); | ||
103 | - return iTask.err_code; | ||
104 | + r = iTask.err_code; | ||
105 | + goto out_unlock; | ||
106 | } | ||
107 | |||
108 | iscsi_allocmap_set_allocated(iscsilun, sector_num, nb_sectors); | ||
109 | |||
110 | - return 0; | ||
111 | +out_unlock: | ||
112 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
113 | + return r; | ||
114 | } | ||
115 | |||
116 | |||
117 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, | ||
118 | goto out; | ||
119 | } | ||
120 | |||
121 | + qemu_mutex_lock(&iscsilun->mutex); | ||
122 | retry: | ||
123 | if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun, | ||
124 | sector_qemu2lun(sector_num, iscsilun), | ||
125 | 8 + 16, iscsi_co_generic_cb, | ||
126 | &iTask) == NULL) { | ||
127 | ret = -ENOMEM; | ||
128 | - goto out; | ||
129 | + goto out_unlock; | ||
130 | } | ||
131 | |||
132 | while (!iTask.complete) { | ||
133 | iscsi_set_events(iscsilun); | ||
134 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
135 | qemu_coroutine_yield(); | ||
136 | + qemu_mutex_lock(&iscsilun->mutex); | ||
137 | } | ||
138 | |||
139 | if (iTask.do_retry) { | ||
140 | @@ -XXX,XX +XXX,XX @@ retry: | ||
141 | * because the device is busy or the cmd is not | ||
142 | * supported) we pretend all blocks are allocated | ||
143 | * for backwards compatibility */ | ||
144 | - goto out; | ||
145 | + goto out_unlock; | ||
146 | } | ||
147 | |||
148 | lbas = scsi_datain_unmarshall(iTask.task); | ||
149 | if (lbas == NULL) { | ||
150 | ret = -EIO; | ||
151 | - goto out; | ||
152 | + goto out_unlock; | ||
153 | } | ||
154 | |||
155 | lbasd = &lbas->descriptors[0]; | ||
156 | |||
157 | if (sector_qemu2lun(sector_num, iscsilun) != lbasd->lba) { | ||
158 | ret = -EIO; | ||
159 | - goto out; | ||
160 | + goto out_unlock; | ||
161 | } | ||
162 | |||
163 | *pnum = sector_lun2qemu(lbasd->num_blocks, iscsilun); | ||
164 | @@ -XXX,XX +XXX,XX @@ retry: | ||
165 | if (*pnum > nb_sectors) { | ||
166 | *pnum = nb_sectors; | ||
167 | } | ||
168 | +out_unlock: | ||
169 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
170 | out: | ||
171 | if (iTask.task != NULL) { | ||
172 | scsi_free_scsi_task(iTask.task); | ||
173 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn iscsi_co_readv(BlockDriverState *bs, | ||
174 | num_sectors = sector_qemu2lun(nb_sectors, iscsilun); | ||
175 | |||
176 | iscsi_co_init_iscsitask(iscsilun, &iTask); | ||
177 | + qemu_mutex_lock(&iscsilun->mutex); | ||
178 | retry: | ||
179 | if (iscsilun->use_16_for_rw) { | ||
180 | #if LIBISCSI_API_VERSION >= (20160603) | ||
181 | @@ -XXX,XX +XXX,XX @@ retry: | ||
182 | #endif | ||
183 | while (!iTask.complete) { | ||
184 | iscsi_set_events(iscsilun); | ||
185 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
186 | qemu_coroutine_yield(); | ||
187 | + qemu_mutex_lock(&iscsilun->mutex); | ||
188 | } | ||
189 | |||
190 | if (iTask.task != NULL) { | ||
191 | @@ -XXX,XX +XXX,XX @@ retry: | ||
192 | iTask.complete = 0; | ||
193 | goto retry; | ||
194 | } | ||
195 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
196 | |||
197 | if (iTask.status != SCSI_STATUS_GOOD) { | ||
198 | return iTask.err_code; | ||
199 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn iscsi_co_flush(BlockDriverState *bs) | ||
200 | struct IscsiTask iTask; | ||
201 | |||
202 | iscsi_co_init_iscsitask(iscsilun, &iTask); | ||
203 | + qemu_mutex_lock(&iscsilun->mutex); | ||
204 | retry: | ||
205 | if (iscsi_synchronizecache10_task(iscsilun->iscsi, iscsilun->lun, 0, 0, 0, | ||
206 | 0, iscsi_co_generic_cb, &iTask) == NULL) { | ||
207 | @@ -XXX,XX +XXX,XX @@ retry: | ||
208 | |||
209 | while (!iTask.complete) { | ||
210 | iscsi_set_events(iscsilun); | ||
211 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
212 | qemu_coroutine_yield(); | ||
213 | + qemu_mutex_lock(&iscsilun->mutex); | ||
214 | } | ||
215 | |||
216 | if (iTask.task != NULL) { | ||
217 | @@ -XXX,XX +XXX,XX @@ retry: | ||
218 | iTask.complete = 0; | ||
219 | goto retry; | ||
220 | } | ||
221 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
222 | |||
223 | if (iTask.status != SCSI_STATUS_GOOD) { | ||
224 | return iTask.err_code; | ||
225 | @@ -XXX,XX +XXX,XX @@ retry: | ||
226 | } | ||
227 | |||
228 | #ifdef __linux__ | ||
229 | +/* Called (via iscsi_service) with QemuMutex held. */ | ||
230 | static void | ||
231 | iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status, | ||
232 | void *command_data, void *opaque) | ||
233 | @@ -XXX,XX +XXX,XX @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, | ||
234 | acb->task->expxferlen = acb->ioh->dxfer_len; | ||
235 | |||
236 | data.size = 0; | ||
237 | + qemu_mutex_lock(&iscsilun->mutex); | ||
238 | if (acb->task->xfer_dir == SCSI_XFER_WRITE) { | ||
239 | if (acb->ioh->iovec_count == 0) { | ||
240 | data.data = acb->ioh->dxferp; | ||
241 | @@ -XXX,XX +XXX,XX @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, | ||
242 | iscsi_aio_ioctl_cb, | ||
243 | (data.size > 0) ? &data : NULL, | ||
244 | acb) != 0) { | ||
245 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
246 | scsi_free_scsi_task(acb->task); | ||
247 | qemu_aio_unref(acb); | ||
248 | return NULL; | ||
249 | @@ -XXX,XX +XXX,XX @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, | ||
250 | } | ||
251 | |||
252 | iscsi_set_events(iscsilun); | ||
253 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
254 | |||
255 | return &acb->common; | ||
256 | } | ||
257 | @@ -XXX,XX +XXX,XX @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) | ||
258 | IscsiLun *iscsilun = bs->opaque; | ||
259 | struct IscsiTask iTask; | ||
260 | struct unmap_list list; | ||
261 | + int r = 0; | ||
262 | |||
263 | if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { | ||
264 | return -ENOTSUP; | ||
265 | @@ -XXX,XX +XXX,XX @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) | ||
266 | list.num = count / iscsilun->block_size; | ||
267 | |||
268 | iscsi_co_init_iscsitask(iscsilun, &iTask); | ||
269 | + qemu_mutex_lock(&iscsilun->mutex); | ||
270 | retry: | ||
271 | if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1, | ||
272 | iscsi_co_generic_cb, &iTask) == NULL) { | ||
273 | - return -ENOMEM; | ||
274 | + r = -ENOMEM; | ||
275 | + goto out_unlock; | ||
276 | } | ||
277 | |||
278 | while (!iTask.complete) { | ||
279 | iscsi_set_events(iscsilun); | ||
280 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
281 | qemu_coroutine_yield(); | ||
282 | + qemu_mutex_lock(&iscsilun->mutex); | ||
283 | } | ||
284 | |||
285 | if (iTask.task != NULL) { | ||
286 | @@ -XXX,XX +XXX,XX @@ retry: | ||
287 | /* the target might fail with a check condition if it | ||
288 | is not happy with the alignment of the UNMAP request | ||
289 | we silently fail in this case */ | ||
290 | - return 0; | ||
291 | + goto out_unlock; | ||
292 | } | ||
293 | |||
294 | if (iTask.status != SCSI_STATUS_GOOD) { | ||
295 | - return iTask.err_code; | ||
296 | + r = iTask.err_code; | ||
297 | + goto out_unlock; | ||
298 | } | ||
299 | |||
300 | iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, | ||
301 | count >> BDRV_SECTOR_BITS); | ||
302 | |||
303 | - return 0; | ||
304 | +out_unlock: | ||
305 | + qemu_mutex_unlock(&iscsilun->mutex); | ||
306 | + return r; | ||
307 | } | ||
308 | |||
309 | static int | ||
310 | @@ -XXX,XX +XXX,XX @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, | ||
311 | uint64_t lba; | ||
312 | uint32_t nb_blocks; | ||
313 | bool use_16_for_ws = iscsilun->use_16_for_rw; | ||
314 | + int r = 0; | ||
315 | |||
316 | if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { | ||
317 | return -ENOTSUP; | ||
318 | @@ -XXX,XX +XXX,XX @@ coroutine_fn iscsi_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, | ||
319 | } | 32 | } |
320 | } | 33 | } |
321 | 34 | ||
322 | + qemu_mutex_lock(&iscsilun->mutex); | 35 | + ret = blkio_connect(s->blkio); |
323 | iscsi_co_init_iscsitask(iscsilun, &iTask); | 36 | + if (ret < 0) { |
324 | retry: | 37 | + error_setg_errno(errp, -ret, "blkio_connect failed: %s", |
325 | if (use_16_for_ws) { | 38 | + blkio_get_error_msg()); |
326 | @@ -XXX,XX +XXX,XX @@ retry: | 39 | + return ret; |
327 | 40 | + } | |
328 | while (!iTask.complete) { | 41 | + |
329 | iscsi_set_events(iscsilun); | 42 | return 0; |
330 | + qemu_mutex_unlock(&iscsilun->mutex); | 43 | } |
331 | qemu_coroutine_yield(); | 44 | |
332 | + qemu_mutex_lock(&iscsilun->mutex); | 45 | -static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags, |
46 | - Error **errp) | ||
47 | +static int blkio_nvme_io_uring_connect(BlockDriverState *bs, QDict *options, | ||
48 | + int flags, Error **errp) | ||
49 | { | ||
50 | const char *path = qdict_get_try_str(options, "path"); | ||
51 | BDRVBlkioState *s = bs->opaque; | ||
52 | @@ -XXX,XX +XXX,XX @@ static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags, | ||
53 | return -EINVAL; | ||
333 | } | 54 | } |
334 | 55 | ||
335 | if (iTask.status == SCSI_STATUS_CHECK_CONDITION && | 56 | + ret = blkio_connect(s->blkio); |
336 | @@ -XXX,XX +XXX,XX @@ retry: | 57 | + if (ret < 0) { |
337 | /* WRITE SAME is not supported by the target */ | 58 | + error_setg_errno(errp, -ret, "blkio_connect failed: %s", |
338 | iscsilun->has_write_same = false; | 59 | + blkio_get_error_msg()); |
339 | scsi_free_scsi_task(iTask.task); | 60 | + return ret; |
340 | - return -ENOTSUP; | 61 | + } |
341 | + r = -ENOTSUP; | 62 | + |
342 | + goto out_unlock; | 63 | return 0; |
64 | } | ||
65 | |||
66 | -static int blkio_virtio_blk_common_open(BlockDriverState *bs, | ||
67 | - QDict *options, int flags, Error **errp) | ||
68 | +static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, | ||
69 | + int flags, Error **errp) | ||
70 | { | ||
71 | const char *path = qdict_get_try_str(options, "path"); | ||
72 | BDRVBlkioState *s = bs->opaque; | ||
73 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs, | ||
74 | } | ||
343 | } | 75 | } |
344 | 76 | ||
345 | if (iTask.task != NULL) { | 77 | + ret = blkio_connect(s->blkio); |
346 | @@ -XXX,XX +XXX,XX @@ retry: | 78 | + if (ret < 0) { |
347 | if (iTask.status != SCSI_STATUS_GOOD) { | 79 | + error_setg_errno(errp, -ret, "blkio_connect failed: %s", |
348 | iscsi_allocmap_set_invalid(iscsilun, offset >> BDRV_SECTOR_BITS, | 80 | + blkio_get_error_msg()); |
349 | count >> BDRV_SECTOR_BITS); | 81 | + return ret; |
350 | - return iTask.err_code; | 82 | + } |
351 | + r = iTask.err_code; | 83 | + |
352 | + goto out_unlock; | 84 | qdict_del(options, "path"); |
85 | |||
86 | return 0; | ||
87 | @@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, | ||
88 | return ret; | ||
353 | } | 89 | } |
354 | 90 | ||
355 | if (flags & BDRV_REQ_MAY_UNMAP) { | 91 | + if (!(flags & BDRV_O_RDWR)) { |
356 | @@ -XXX,XX +XXX,XX @@ retry: | 92 | + ret = blkio_set_bool(s->blkio, "read-only", true); |
357 | count >> BDRV_SECTOR_BITS); | 93 | + if (ret < 0) { |
94 | + error_setg_errno(errp, -ret, "failed to set read-only: %s", | ||
95 | + blkio_get_error_msg()); | ||
96 | + blkio_destroy(&s->blkio); | ||
97 | + return ret; | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | if (strcmp(blkio_driver, "io_uring") == 0) { | ||
102 | - ret = blkio_io_uring_open(bs, options, flags, errp); | ||
103 | + ret = blkio_io_uring_connect(bs, options, flags, errp); | ||
104 | } else if (strcmp(blkio_driver, "nvme-io_uring") == 0) { | ||
105 | - ret = blkio_nvme_io_uring(bs, options, flags, errp); | ||
106 | + ret = blkio_nvme_io_uring_connect(bs, options, flags, errp); | ||
107 | } else if (strcmp(blkio_driver, "virtio-blk-vfio-pci") == 0) { | ||
108 | - ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
109 | + ret = blkio_virtio_blk_connect(bs, options, flags, errp); | ||
110 | } else if (strcmp(blkio_driver, "virtio-blk-vhost-user") == 0) { | ||
111 | - ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
112 | + ret = blkio_virtio_blk_connect(bs, options, flags, errp); | ||
113 | } else if (strcmp(blkio_driver, "virtio-blk-vhost-vdpa") == 0) { | ||
114 | - ret = blkio_virtio_blk_common_open(bs, options, flags, errp); | ||
115 | + ret = blkio_virtio_blk_connect(bs, options, flags, errp); | ||
116 | } else { | ||
117 | g_assert_not_reached(); | ||
358 | } | 118 | } |
359 | 119 | @@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, | |
360 | - return 0; | 120 | return ret; |
361 | +out_unlock: | 121 | } |
362 | + qemu_mutex_unlock(&iscsilun->mutex); | 122 | |
363 | + return r; | 123 | - if (!(flags & BDRV_O_RDWR)) { |
364 | } | 124 | - ret = blkio_set_bool(s->blkio, "read-only", true); |
365 | 125 | - if (ret < 0) { | |
366 | static void apply_chap(struct iscsi_context *iscsi, QemuOpts *opts, | 126 | - error_setg_errno(errp, -ret, "failed to set read-only: %s", |
367 | @@ -XXX,XX +XXX,XX @@ static void iscsi_nop_timed_event(void *opaque) | 127 | - blkio_get_error_msg()); |
368 | { | 128 | - blkio_destroy(&s->blkio); |
369 | IscsiLun *iscsilun = opaque; | 129 | - return ret; |
370 | 130 | - } | |
371 | - aio_context_acquire(iscsilun->aio_context); | 131 | - } |
372 | + qemu_mutex_lock(&iscsilun->mutex); | 132 | - |
373 | if (iscsi_get_nops_in_flight(iscsilun->iscsi) >= MAX_NOP_FAILURES) { | 133 | - ret = blkio_connect(s->blkio); |
374 | error_report("iSCSI: NOP timeout. Reconnecting..."); | 134 | - if (ret < 0) { |
375 | iscsilun->request_timed_out = true; | 135 | - error_setg_errno(errp, -ret, "blkio_connect failed: %s", |
376 | @@ -XXX,XX +XXX,XX @@ static void iscsi_nop_timed_event(void *opaque) | 136 | - blkio_get_error_msg()); |
377 | iscsi_set_events(iscsilun); | 137 | - blkio_destroy(&s->blkio); |
378 | 138 | - return ret; | |
379 | out: | 139 | - } |
380 | - aio_context_release(iscsilun->aio_context); | 140 | - |
381 | + qemu_mutex_unlock(&iscsilun->mutex); | 141 | ret = blkio_get_bool(s->blkio, |
382 | } | 142 | "needs-mem-regions", |
383 | 143 | &s->needs_mem_regions); | |
384 | static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp) | ||
385 | @@ -XXX,XX +XXX,XX @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, | ||
386 | scsi_free_scsi_task(task); | ||
387 | task = NULL; | ||
388 | |||
389 | + qemu_mutex_init(&iscsilun->mutex); | ||
390 | iscsi_attach_aio_context(bs, iscsilun->aio_context); | ||
391 | |||
392 | /* Guess the internal cluster (page) size of the iscsi target by the means | ||
393 | @@ -XXX,XX +XXX,XX @@ static void iscsi_close(BlockDriverState *bs) | ||
394 | iscsi_destroy_context(iscsi); | ||
395 | g_free(iscsilun->zeroblock); | ||
396 | iscsi_allocmap_free(iscsilun); | ||
397 | + qemu_mutex_destroy(&iscsilun->mutex); | ||
398 | memset(iscsilun, 0, sizeof(IscsiLun)); | ||
399 | } | ||
400 | |||
401 | -- | 144 | -- |
402 | 2.9.3 | 145 | 2.41.0 |
403 | |||
404 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Stefano Garzarella <sgarzare@redhat.com> | ||
1 | 2 | ||
3 | libblkio 1.3.0 added support of "fd" property for virtio-blk-vhost-vdpa | ||
4 | driver. In QEMU, starting from commit cad2ccc395 ("block/blkio: use | ||
5 | qemu_open() to support fd passing for virtio-blk") we are using | ||
6 | `blkio_get_int(..., "fd")` to check if the "fd" property is supported | ||
7 | for all the virtio-blk-* driver. | ||
8 | |||
9 | Unfortunately that property is also available for those driver that do | ||
10 | not support it, such as virtio-blk-vhost-user. | ||
11 | |||
12 | So, `blkio_get_int()` is not enough to check whether the driver supports | ||
13 | the `fd` property or not. This is because the virito-blk common libblkio | ||
14 | driver only checks whether or not `fd` is set during `blkio_connect()` | ||
15 | and fails with -EINVAL for those transports that do not support it | ||
16 | (all except vhost-vdpa for now). | ||
17 | |||
18 | So let's handle the `blkio_connect()` failure, retrying it using `path` | ||
19 | directly. | ||
20 | |||
21 | Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") | ||
22 | Suggested-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
23 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
24 | Message-id: 20230727161020.84213-3-sgarzare@redhat.com | ||
25 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
26 | --- | ||
27 | block/blkio.c | 29 +++++++++++++++++++++++++++++ | ||
28 | 1 file changed, 29 insertions(+) | ||
29 | |||
30 | diff --git a/block/blkio.c b/block/blkio.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/block/blkio.c | ||
33 | +++ b/block/blkio.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, | ||
35 | } | ||
36 | |||
37 | ret = blkio_connect(s->blkio); | ||
38 | + /* | ||
39 | + * If the libblkio driver doesn't support the `fd` property, blkio_connect() | ||
40 | + * will fail with -EINVAL. So let's try calling blkio_connect() again by | ||
41 | + * directly setting `path`. | ||
42 | + */ | ||
43 | + if (fd_supported && ret == -EINVAL) { | ||
44 | + qemu_close(fd); | ||
45 | + | ||
46 | + /* | ||
47 | + * We need to clear the `fd` property we set previously by setting | ||
48 | + * it to -1. | ||
49 | + */ | ||
50 | + ret = blkio_set_int(s->blkio, "fd", -1); | ||
51 | + if (ret < 0) { | ||
52 | + error_setg_errno(errp, -ret, "failed to set fd: %s", | ||
53 | + blkio_get_error_msg()); | ||
54 | + return ret; | ||
55 | + } | ||
56 | + | ||
57 | + ret = blkio_set_str(s->blkio, "path", path); | ||
58 | + if (ret < 0) { | ||
59 | + error_setg_errno(errp, -ret, "failed to set path: %s", | ||
60 | + blkio_get_error_msg()); | ||
61 | + return ret; | ||
62 | + } | ||
63 | + | ||
64 | + ret = blkio_connect(s->blkio); | ||
65 | + } | ||
66 | + | ||
67 | if (ret < 0) { | ||
68 | error_setg_errno(errp, -ret, "blkio_connect failed: %s", | ||
69 | blkio_get_error_msg()); | ||
70 | -- | ||
71 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Stefano Garzarella <sgarzare@redhat.com> | ||
1 | 2 | ||
3 | qemu_open() fails if called with an unix domain socket in this way: | ||
4 | -blockdev node-name=drive0,driver=virtio-blk-vhost-user,path=vhost-user-blk.sock,cache.direct=on: Could not open 'vhost-user-blk.sock': No such device or address | ||
5 | |||
6 | Since virtio-blk-vhost-user does not support fd passing, let`s always fall back | ||
7 | on using `path` if we fail the fd passing. | ||
8 | |||
9 | Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk") | ||
10 | Reported-by: Qing Wang <qinwang@redhat.com> | ||
11 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
12 | Message-id: 20230727161020.84213-4-sgarzare@redhat.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | ||
15 | block/blkio.c | 20 ++++++++++---------- | ||
16 | 1 file changed, 10 insertions(+), 10 deletions(-) | ||
17 | |||
18 | diff --git a/block/blkio.c b/block/blkio.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/blkio.c | ||
21 | +++ b/block/blkio.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, | ||
23 | * In order to open the device read-only, we are using the `read-only` | ||
24 | * property of the libblkio driver in blkio_file_open(). | ||
25 | */ | ||
26 | - fd = qemu_open(path, O_RDWR, errp); | ||
27 | + fd = qemu_open(path, O_RDWR, NULL); | ||
28 | if (fd < 0) { | ||
29 | - return -EINVAL; | ||
30 | + fd_supported = false; | ||
31 | + } else { | ||
32 | + ret = blkio_set_int(s->blkio, "fd", fd); | ||
33 | + if (ret < 0) { | ||
34 | + fd_supported = false; | ||
35 | + qemu_close(fd); | ||
36 | + } | ||
37 | } | ||
38 | + } | ||
39 | |||
40 | - ret = blkio_set_int(s->blkio, "fd", fd); | ||
41 | - if (ret < 0) { | ||
42 | - error_setg_errno(errp, -ret, "failed to set fd: %s", | ||
43 | - blkio_get_error_msg()); | ||
44 | - qemu_close(fd); | ||
45 | - return ret; | ||
46 | - } | ||
47 | - } else { | ||
48 | + if (!fd_supported) { | ||
49 | ret = blkio_set_str(s->blkio, "path", path); | ||
50 | if (ret < 0) { | ||
51 | error_setg_errno(errp, -ret, "failed to set path: %s", | ||
52 | -- | ||
53 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Now that all bottom halves and callbacks take care of taking the | 3 | Setting the `fd` property fails with virtio-blk-* libblkio drivers |
4 | AioContext lock, we can migrate some users away from it and to a | 4 | that do not support fd passing since |
5 | specific QemuMutex or CoMutex. | 5 | https://gitlab.com/libblkio/libblkio/-/merge_requests/208. |
6 | 6 | ||
7 | Protect BDRVCURLState access with a QemuMutex. | 7 | Getting the `fd` property, on the other hand, always succeeds for |
8 | virtio-blk-* libblkio drivers even when they don't support fd passing. | ||
8 | 9 | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | This patch switches to setting the `fd` property because it is a |
10 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | 11 | better mechanism for probing fd passing support than getting the `fd` |
11 | Message-id: 20170222180725.28611-2-pbonzini@redhat.com | 12 | property. |
13 | |||
14 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
15 | Message-id: 20230727161020.84213-5-sgarzare@redhat.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | --- | 17 | --- |
14 | block/curl.c | 24 +++++++++++++++--------- | 18 | block/blkio.c | 2 +- |
15 | 1 file changed, 15 insertions(+), 9 deletions(-) | 19 | 1 file changed, 1 insertion(+), 1 deletion(-) |
16 | 20 | ||
17 | diff --git a/block/curl.c b/block/curl.c | 21 | diff --git a/block/blkio.c b/block/blkio.c |
18 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/curl.c | 23 | --- a/block/blkio.c |
20 | +++ b/block/curl.c | 24 | +++ b/block/blkio.c |
21 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVCURLState { | 25 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, |
22 | char *cookie; | 26 | return -EINVAL; |
23 | bool accept_range; | ||
24 | AioContext *aio_context; | ||
25 | + QemuMutex mutex; | ||
26 | char *username; | ||
27 | char *password; | ||
28 | char *proxyusername; | ||
29 | @@ -XXX,XX +XXX,XX @@ static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len, | ||
30 | return FIND_RET_NONE; | ||
31 | } | ||
32 | |||
33 | +/* Called with s->mutex held. */ | ||
34 | static void curl_multi_check_completion(BDRVCURLState *s) | ||
35 | { | ||
36 | int msgs_in_queue; | ||
37 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_check_completion(BDRVCURLState *s) | ||
38 | continue; | ||
39 | } | ||
40 | |||
41 | + qemu_mutex_unlock(&s->mutex); | ||
42 | acb->common.cb(acb->common.opaque, -EPROTO); | ||
43 | + qemu_mutex_lock(&s->mutex); | ||
44 | qemu_aio_unref(acb); | ||
45 | state->acb[i] = NULL; | ||
46 | } | ||
47 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_check_completion(BDRVCURLState *s) | ||
48 | } | 27 | } |
49 | } | 28 | |
50 | 29 | - if (blkio_get_int(s->blkio, "fd", &fd) == 0) { | |
51 | +/* Called with s->mutex held. */ | 30 | + if (blkio_set_int(s->blkio, "fd", -1) == 0) { |
52 | static void curl_multi_do_locked(CURLState *s) | 31 | fd_supported = true; |
53 | { | ||
54 | CURLSocket *socket, *next_socket; | ||
55 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_do(void *arg) | ||
56 | { | ||
57 | CURLState *s = (CURLState *)arg; | ||
58 | |||
59 | - aio_context_acquire(s->s->aio_context); | ||
60 | + qemu_mutex_lock(&s->s->mutex); | ||
61 | curl_multi_do_locked(s); | ||
62 | - aio_context_release(s->s->aio_context); | ||
63 | + qemu_mutex_unlock(&s->s->mutex); | ||
64 | } | ||
65 | |||
66 | static void curl_multi_read(void *arg) | ||
67 | { | ||
68 | CURLState *s = (CURLState *)arg; | ||
69 | |||
70 | - aio_context_acquire(s->s->aio_context); | ||
71 | + qemu_mutex_lock(&s->s->mutex); | ||
72 | curl_multi_do_locked(s); | ||
73 | curl_multi_check_completion(s->s); | ||
74 | - aio_context_release(s->s->aio_context); | ||
75 | + qemu_mutex_unlock(&s->s->mutex); | ||
76 | } | ||
77 | |||
78 | static void curl_multi_timeout_do(void *arg) | ||
79 | @@ -XXX,XX +XXX,XX @@ static void curl_multi_timeout_do(void *arg) | ||
80 | return; | ||
81 | } | 32 | } |
82 | 33 | ||
83 | - aio_context_acquire(s->aio_context); | ||
84 | + qemu_mutex_lock(&s->mutex); | ||
85 | curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running); | ||
86 | |||
87 | curl_multi_check_completion(s); | ||
88 | - aio_context_release(s->aio_context); | ||
89 | + qemu_mutex_unlock(&s->mutex); | ||
90 | #else | ||
91 | abort(); | ||
92 | #endif | ||
93 | @@ -XXX,XX +XXX,XX @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags, | ||
94 | curl_easy_cleanup(state->curl); | ||
95 | state->curl = NULL; | ||
96 | |||
97 | + qemu_mutex_init(&s->mutex); | ||
98 | curl_attach_aio_context(bs, bdrv_get_aio_context(bs)); | ||
99 | |||
100 | qemu_opts_del(opts); | ||
101 | @@ -XXX,XX +XXX,XX @@ static void curl_readv_bh_cb(void *p) | ||
102 | CURLAIOCB *acb = p; | ||
103 | BlockDriverState *bs = acb->common.bs; | ||
104 | BDRVCURLState *s = bs->opaque; | ||
105 | - AioContext *ctx = bdrv_get_aio_context(bs); | ||
106 | |||
107 | size_t start = acb->sector_num * BDRV_SECTOR_SIZE; | ||
108 | size_t end; | ||
109 | |||
110 | - aio_context_acquire(ctx); | ||
111 | + qemu_mutex_lock(&s->mutex); | ||
112 | |||
113 | // In case we have the requested data already (e.g. read-ahead), | ||
114 | // we can just call the callback and be done. | ||
115 | @@ -XXX,XX +XXX,XX @@ static void curl_readv_bh_cb(void *p) | ||
116 | curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running); | ||
117 | |||
118 | out: | ||
119 | - aio_context_release(ctx); | ||
120 | + qemu_mutex_unlock(&s->mutex); | ||
121 | if (ret != -EINPROGRESS) { | ||
122 | acb->common.cb(acb->common.opaque, ret); | ||
123 | qemu_aio_unref(acb); | ||
124 | @@ -XXX,XX +XXX,XX @@ static void curl_close(BlockDriverState *bs) | ||
125 | |||
126 | DPRINTF("CURL: Close\n"); | ||
127 | curl_detach_aio_context(bs); | ||
128 | + qemu_mutex_destroy(&s->mutex); | ||
129 | |||
130 | g_free(s->cookie); | ||
131 | g_free(s->url); | ||
132 | -- | 34 | -- |
133 | 2.9.3 | 35 | 2.41.0 |
134 | |||
135 | diff view generated by jsdifflib |