1 | The following changes since commit f6b06fcceef465de0cf2514c9f76fe0192896781: | 1 | The following changes since commit 66547f416a61e0cb711dc76821890242432ba193: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190121-pull-request' into staging (2019-01-23 17:57:47 +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 8595685986152334b1ec28c78cb0e5e855d56b54: | 9 | for you to fetch changes up to 1c38fe69e2b8a05c1762b122292fa7e3662f06fd: |
10 | 10 | ||
11 | qemu-coroutine-sleep: drop CoSleepCB (2019-01-24 10:05:16 +0000) | 11 | block/blkio: use blkio_set_int("fd") to check fd support (2023-07-27 15:51:46 -0400) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | Changelog: No user-visible changes. | 16 | Please include these bug fixes in QEMU 8.1. Thanks! |
17 | 17 | ||
18 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
19 | 19 | ||
20 | Stefan Hajnoczi (2): | 20 | Hanna Czenczek (1): |
21 | throttle-groups: fix restart coroutine iothread race | 21 | block: Fix pad_request's request restriction |
22 | iotests: add 238 for throttling tgm unregister iothread segfault | ||
23 | 22 | ||
24 | Vladimir Sementsov-Ogievskiy (1): | 23 | Sam Li (1): |
25 | qemu-coroutine-sleep: drop CoSleepCB | 24 | block/file-posix: fix g_file_get_contents return path |
26 | 25 | ||
27 | include/block/throttle-groups.h | 5 ++++ | 26 | Stefano Garzarella (6): |
28 | block/throttle-groups.c | 9 +++++++ | 27 | block/blkio: enable the completion eventfd |
29 | util/qemu-coroutine-sleep.c | 27 +++++++------------ | 28 | block/blkio: do not use open flags in qemu_open() |
30 | tests/qemu-iotests/238 | 47 +++++++++++++++++++++++++++++++++ | 29 | block/blkio: move blkio_connect() in the drivers functions |
31 | tests/qemu-iotests/238.out | 6 +++++ | 30 | block/blkio: retry blkio_connect() if it fails using `fd` |
32 | tests/qemu-iotests/group | 1 + | 31 | block/blkio: fall back on using `path` when `fd` setting fails |
33 | 6 files changed, 78 insertions(+), 17 deletions(-) | 32 | block/blkio: use blkio_set_int("fd") to check fd support |
34 | create mode 100755 tests/qemu-iotests/238 | 33 | |
35 | create mode 100644 tests/qemu-iotests/238.out | 34 | block/blkio.c | 132 ++++++++++++++++++++++++++++++--------------- |
35 | block/file-posix.c | 6 +-- | ||
36 | block/io.c | 8 ++- | ||
37 | 3 files changed, 97 insertions(+), 49 deletions(-) | ||
36 | 38 | ||
37 | -- | 39 | -- |
38 | 2.20.1 | 40 | 2.41.0 |
39 | |||
40 | 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 | Hot-unplug a scsi-hd using an iothread. The previous patch fixes a | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | segfault in this scenario. | ||
3 | 2 | ||
4 | This patch adds a regression test. | 3 | qemu_open() in blkio_virtio_blk_common_open() is used to open the |
4 | character device (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or in | ||
5 | the future eventually the unix socket. | ||
5 | 6 | ||
6 | Suggested-by: Alberto Garcia <berto@igalia.com> | 7 | In all these cases we cannot open the path in read-only mode, |
7 | Suggested-by: Kevin Wolf <kwolf@redhat.com> | 8 | when the `read-only` option of blockdev is on, because the exchange |
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | of IOCTL commands for example will fail. |
9 | Reviewed-by: Alberto Garcia <berto@igalia.com> | 10 | |
10 | Message-id: 20190114133257.30299-3-stefanha@redhat.com | 11 | In order to open the device read-only, we have to use the `read-only` |
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 | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 21 | --- |
13 | tests/qemu-iotests/238 | 47 ++++++++++++++++++++++++++++++++++++++ | 22 | block/blkio.c | 21 ++++++++++++--------- |
14 | tests/qemu-iotests/238.out | 6 +++++ | 23 | 1 file changed, 12 insertions(+), 9 deletions(-) |
15 | tests/qemu-iotests/group | 1 + | ||
16 | 3 files changed, 54 insertions(+) | ||
17 | create mode 100755 tests/qemu-iotests/238 | ||
18 | create mode 100644 tests/qemu-iotests/238.out | ||
19 | 24 | ||
20 | diff --git a/tests/qemu-iotests/238 b/tests/qemu-iotests/238 | 25 | diff --git a/block/blkio.c b/block/blkio.c |
21 | new file mode 100755 | ||
22 | index XXXXXXX..XXXXXXX | ||
23 | --- /dev/null | ||
24 | +++ b/tests/qemu-iotests/238 | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | +#!/usr/bin/env python | ||
27 | +# | ||
28 | +# Regression test for throttle group member unregister segfault with iothread | ||
29 | +# | ||
30 | +# Copyright (c) 2019 Red Hat, Inc. | ||
31 | +# | ||
32 | +# This program is free software; you can redistribute it and/or modify | ||
33 | +# it under the terms of the GNU General Public License as published by | ||
34 | +# the Free Software Foundation; either version 2 of the License, or | ||
35 | +# (at your option) any later version. | ||
36 | +# | ||
37 | +# This program is distributed in the hope that it will be useful, | ||
38 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
39 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
40 | +# GNU General Public License for more details. | ||
41 | +# | ||
42 | +# You should have received a copy of the GNU General Public License | ||
43 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
44 | +# | ||
45 | + | ||
46 | +import sys | ||
47 | +import os | ||
48 | +import iotests | ||
49 | +from iotests import log | ||
50 | + | ||
51 | +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts')) | ||
52 | + | ||
53 | +from qemu import QEMUMachine | ||
54 | + | ||
55 | +if iotests.qemu_default_machine == 's390-ccw-virtio': | ||
56 | + virtio_scsi_device = 'virtio-scsi-ccw' | ||
57 | +else: | ||
58 | + virtio_scsi_device = 'virtio-scsi-pci' | ||
59 | + | ||
60 | +vm = QEMUMachine(iotests.qemu_prog) | ||
61 | +vm.add_args('-machine', 'accel=kvm') | ||
62 | +vm.launch() | ||
63 | + | ||
64 | +log(vm.qmp('blockdev-add', node_name='hd0', driver='null-co')) | ||
65 | +log(vm.qmp('object-add', qom_type='iothread', id='iothread0')) | ||
66 | +log(vm.qmp('device_add', id='scsi0', driver=virtio_scsi_device, iothread='iothread0')) | ||
67 | +log(vm.qmp('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')) | ||
68 | +log(vm.qmp('block_set_io_throttle', id='scsi-hd0', bps=0, bps_rd=0, bps_wr=0, | ||
69 | + iops=1000, iops_rd=0, iops_wr=0, conv_keys=False)) | ||
70 | +log(vm.qmp('device_del', id='scsi-hd0')) | ||
71 | + | ||
72 | +vm.shutdown() | ||
73 | diff --git a/tests/qemu-iotests/238.out b/tests/qemu-iotests/238.out | ||
74 | new file mode 100644 | ||
75 | index XXXXXXX..XXXXXXX | ||
76 | --- /dev/null | ||
77 | +++ b/tests/qemu-iotests/238.out | ||
78 | @@ -XXX,XX +XXX,XX @@ | ||
79 | +{"return": {}} | ||
80 | +{"return": {}} | ||
81 | +{"return": {}} | ||
82 | +{"return": {}} | ||
83 | +{"return": {}} | ||
84 | +{"return": {}} | ||
85 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
86 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
87 | --- a/tests/qemu-iotests/group | 27 | --- a/block/blkio.c |
88 | +++ b/tests/qemu-iotests/group | 28 | +++ b/block/blkio.c |
89 | @@ -XXX,XX +XXX,XX @@ | 29 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs, |
90 | 234 auto quick migration | 30 | * layer through the "/dev/fdset/N" special path. |
91 | 235 auto quick | 31 | */ |
92 | 236 auto quick | 32 | if (fd_supported) { |
93 | +238 auto quick | 33 | - int open_flags; |
34 | - | ||
35 | - if (flags & BDRV_O_RDWR) { | ||
36 | - open_flags = O_RDWR; | ||
37 | - } else { | ||
38 | - open_flags = O_RDONLY; | ||
39 | - } | ||
40 | - | ||
41 | - fd = qemu_open(path, open_flags, errp); | ||
42 | + /* | ||
43 | + * `path` can contain the path of a character device | ||
44 | + * (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or a unix socket. | ||
45 | + * | ||
46 | + * So, we should always open it with O_RDWR flag, also if BDRV_O_RDWR | ||
47 | + * is not set in the open flags, because the exchange of IOCTL commands | ||
48 | + * for example will fail. | ||
49 | + * | ||
50 | + * In order to open the device read-only, we are using the `read-only` | ||
51 | + * property of the libblkio driver in blkio_file_open(). | ||
52 | + */ | ||
53 | + fd = qemu_open(path, O_RDWR, errp); | ||
54 | if (fd < 0) { | ||
55 | return -EINVAL; | ||
56 | } | ||
94 | -- | 57 | -- |
95 | 2.20.1 | 58 | 2.41.0 |
96 | 59 | ||
97 | 60 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Sam Li <faithilikerun@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Drop CoSleepCB structure. It's actually unused. | 3 | The g_file_get_contents() function returns a g_boolean. If it fails, the |
4 | returned value will be 0 instead of -1. Solve the issue by skipping | ||
5 | assigning ret value. | ||
4 | 6 | ||
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 7 | This issue was found by Matthew Rosato using virtio-blk-{pci,ccw} backed |
6 | Message-id: 20190122143113.20331-1-vsementsov@virtuozzo.com | 8 | by an NVMe partition e.g. /dev/nvme0n1p1 on s390x. |
9 | |||
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 | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | --- | 16 | --- |
9 | util/qemu-coroutine-sleep.c | 27 ++++++++++----------------- | 17 | block/file-posix.c | 6 ++---- |
10 | 1 file changed, 10 insertions(+), 17 deletions(-) | 18 | 1 file changed, 2 insertions(+), 4 deletions(-) |
11 | 19 | ||
12 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | 20 | diff --git a/block/file-posix.c b/block/file-posix.c |
13 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/util/qemu-coroutine-sleep.c | 22 | --- a/block/file-posix.c |
15 | +++ b/util/qemu-coroutine-sleep.c | 23 | +++ b/block/file-posix.c |
16 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st) |
17 | #include "qemu/timer.h" | 25 | static int get_sysfs_str_val(struct stat *st, const char *attribute, |
18 | #include "block/aio.h" | 26 | char **val) { |
19 | 27 | g_autofree char *sysfspath = NULL; | |
20 | -typedef struct CoSleepCB { | 28 | - int ret; |
21 | - QEMUTimer *ts; | 29 | size_t len; |
22 | - Coroutine *co; | 30 | |
23 | -} CoSleepCB; | 31 | if (!S_ISBLK(st->st_mode)) { |
24 | - | 32 | @@ -XXX,XX +XXX,XX @@ static int get_sysfs_str_val(struct stat *st, const char *attribute, |
25 | static void co_sleep_cb(void *opaque) | 33 | sysfspath = g_strdup_printf("/sys/dev/block/%u:%u/queue/%s", |
26 | { | 34 | major(st->st_rdev), minor(st->st_rdev), |
27 | - CoSleepCB *sleep_cb = opaque; | 35 | attribute); |
28 | + Coroutine *co = opaque; | 36 | - ret = g_file_get_contents(sysfspath, val, &len, NULL); |
29 | 37 | - if (ret == -1) { | |
30 | /* Write of schedule protected by barrier write in aio_co_schedule */ | 38 | + if (!g_file_get_contents(sysfspath, val, &len, NULL)) { |
31 | - atomic_set(&sleep_cb->co->scheduled, NULL); | 39 | return -ENOENT; |
32 | - aio_co_wake(sleep_cb->co); | 40 | } |
33 | + atomic_set(&co->scheduled, NULL); | 41 | |
34 | + aio_co_wake(co); | 42 | @@ -XXX,XX +XXX,XX @@ static int get_sysfs_str_val(struct stat *st, const char *attribute, |
43 | if (*(p + len - 1) == '\n') { | ||
44 | *(p + len - 1) = '\0'; | ||
45 | } | ||
46 | - return ret; | ||
47 | + return 0; | ||
35 | } | 48 | } |
36 | 49 | #endif | |
37 | void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | 50 | |
38 | { | ||
39 | AioContext *ctx = qemu_get_current_aio_context(); | ||
40 | - CoSleepCB sleep_cb = { | ||
41 | - .co = qemu_coroutine_self(), | ||
42 | - }; | ||
43 | + QEMUTimer *ts; | ||
44 | + Coroutine *co = qemu_coroutine_self(); | ||
45 | |||
46 | - const char *scheduled = atomic_cmpxchg(&sleep_cb.co->scheduled, NULL, | ||
47 | - __func__); | ||
48 | + const char *scheduled = atomic_cmpxchg(&co->scheduled, NULL, __func__); | ||
49 | if (scheduled) { | ||
50 | fprintf(stderr, | ||
51 | "%s: Co-routine was already scheduled in '%s'\n", | ||
52 | __func__, scheduled); | ||
53 | abort(); | ||
54 | } | ||
55 | - sleep_cb.ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &sleep_cb); | ||
56 | - timer_mod(sleep_cb.ts, qemu_clock_get_ns(type) + ns); | ||
57 | + ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, co); | ||
58 | + timer_mod(ts, qemu_clock_get_ns(type) + ns); | ||
59 | qemu_coroutine_yield(); | ||
60 | - timer_del(sleep_cb.ts); | ||
61 | - timer_free(sleep_cb.ts); | ||
62 | + timer_del(ts); | ||
63 | + timer_free(ts); | ||
64 | } | ||
65 | -- | 51 | -- |
66 | 2.20.1 | 52 | 2.41.0 |
67 | 53 | ||
68 | 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 | The following QMP command leads to a crash when iothreads are used: | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | { 'execute': 'device_del', 'arguments': {'id': 'data'} } | 3 | This is in preparation for the next patch, where for virtio-blk |
4 | drivers we need to handle the failure of blkio_connect(). | ||
4 | 5 | ||
5 | The backtrace involves the queue restart coroutine where | 6 | Let's also rename the *_open() functions to *_connect() to make |
6 | tgm->throttle_state is a NULL pointer because | 7 | the code reflect the changes applied. |
7 | throttle_group_unregister_tgm() has already been called: | ||
8 | 8 | ||
9 | (gdb) bt full | 9 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> |
10 | #0 0x00005585a7a3b378 in qemu_mutex_lock_impl (mutex=0xffffffffffffffd0, file=0x5585a7bb3d54 "block/throttle-groups.c", line=412) at util/qemu-thread-posix.c:64 | 10 | Message-id: 20230727161020.84213-2-sgarzare@redhat.com |
11 | err = <optimized out> | ||
12 | __PRETTY_FUNCTION__ = "qemu_mutex_lock_impl" | ||
13 | __func__ = "qemu_mutex_lock_impl" | ||
14 | #1 0x00005585a79be074 in throttle_group_restart_queue_entry (opaque=0x5585a9de4eb0) at block/throttle-groups.c:412 | ||
15 | _f = <optimized out> | ||
16 | data = 0x5585a9de4eb0 | ||
17 | tgm = 0x5585a9079440 | ||
18 | ts = 0x0 | ||
19 | tg = 0xffffffffffffff98 | ||
20 | is_write = false | ||
21 | empty_queue = 255 | ||
22 | |||
23 | This coroutine should not execute in the iothread after the throttle | ||
24 | group member has been unregistered! | ||
25 | |||
26 | The root cause is that the device_del code path schedules the restart | ||
27 | coroutine in the iothread while holding the AioContext lock. Therefore | ||
28 | the iothread cannot execute the coroutine until after device_del | ||
29 | releases the lock - by this time it's too late. | ||
30 | |||
31 | This patch adds a reference count to ThrottleGroupMember so we can | ||
32 | synchronously wait for restart coroutines to complete. Once they are | ||
33 | done it is safe to unregister the ThrottleGroupMember. | ||
34 | |||
35 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
36 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
37 | Message-id: 20190114133257.30299-2-stefanha@redhat.com | ||
38 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
39 | --- | 12 | --- |
40 | include/block/throttle-groups.h | 5 +++++ | 13 | block/blkio.c | 71 ++++++++++++++++++++++++++++++--------------------- |
41 | block/throttle-groups.c | 9 +++++++++ | 14 | 1 file changed, 42 insertions(+), 29 deletions(-) |
42 | 2 files changed, 14 insertions(+) | ||
43 | 15 | ||
44 | diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h | 16 | diff --git a/block/blkio.c b/block/blkio.c |
45 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/include/block/throttle-groups.h | 18 | --- a/block/blkio.c |
47 | +++ b/include/block/throttle-groups.h | 19 | +++ b/block/blkio.c |
48 | @@ -XXX,XX +XXX,XX @@ typedef struct ThrottleGroupMember { | 20 | @@ -XXX,XX +XXX,XX @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size) |
49 | */ | 21 | } |
50 | unsigned int io_limits_disabled; | 22 | } |
51 | 23 | ||
52 | + /* Number of pending throttle_group_restart_queue_entry() coroutines. | 24 | -static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, |
53 | + * Accessed with atomic operations. | 25 | - Error **errp) |
54 | + */ | 26 | +static int blkio_io_uring_connect(BlockDriverState *bs, QDict *options, |
55 | + unsigned int restart_pending; | 27 | + int flags, Error **errp) |
28 | { | ||
29 | const char *filename = qdict_get_str(options, "filename"); | ||
30 | BDRVBlkioState *s = bs->opaque; | ||
31 | @@ -XXX,XX +XXX,XX @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, | ||
32 | } | ||
33 | } | ||
34 | |||
35 | + ret = blkio_connect(s->blkio); | ||
36 | + if (ret < 0) { | ||
37 | + error_setg_errno(errp, -ret, "blkio_connect failed: %s", | ||
38 | + blkio_get_error_msg()); | ||
39 | + return ret; | ||
40 | + } | ||
56 | + | 41 | + |
57 | /* The following fields are protected by the ThrottleGroup lock. | 42 | return 0; |
58 | * See the ThrottleGroup documentation for details. | 43 | } |
59 | * throttle_state tells us if I/O limits are configured. */ | 44 | |
60 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | 45 | -static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags, |
61 | index XXXXXXX..XXXXXXX 100644 | 46 | - Error **errp) |
62 | --- a/block/throttle-groups.c | 47 | +static int blkio_nvme_io_uring_connect(BlockDriverState *bs, QDict *options, |
63 | +++ b/block/throttle-groups.c | 48 | + int flags, Error **errp) |
64 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) | 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; | ||
65 | } | 54 | } |
66 | 55 | ||
67 | g_free(data); | 56 | + ret = blkio_connect(s->blkio); |
57 | + if (ret < 0) { | ||
58 | + error_setg_errno(errp, -ret, "blkio_connect failed: %s", | ||
59 | + blkio_get_error_msg()); | ||
60 | + return ret; | ||
61 | + } | ||
68 | + | 62 | + |
69 | + atomic_dec(&tgm->restart_pending); | 63 | return 0; |
70 | + aio_wait_kick(); | ||
71 | } | 64 | } |
72 | 65 | ||
73 | static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write) | 66 | -static int blkio_virtio_blk_common_open(BlockDriverState *bs, |
74 | @@ -XXX,XX +XXX,XX @@ static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write | 67 | - QDict *options, int flags, Error **errp) |
75 | * be no timer pending on this tgm at this point */ | 68 | +static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, |
76 | assert(!timer_pending(tgm->throttle_timers.timers[is_write])); | 69 | + int flags, Error **errp) |
77 | 70 | { | |
78 | + atomic_inc(&tgm->restart_pending); | 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 | } | ||
75 | } | ||
76 | |||
77 | + ret = blkio_connect(s->blkio); | ||
78 | + if (ret < 0) { | ||
79 | + error_setg_errno(errp, -ret, "blkio_connect failed: %s", | ||
80 | + blkio_get_error_msg()); | ||
81 | + return ret; | ||
82 | + } | ||
79 | + | 83 | + |
80 | co = qemu_coroutine_create(throttle_group_restart_queue_entry, rd); | 84 | qdict_del(options, "path"); |
81 | aio_co_enter(tgm->aio_context, co); | 85 | |
82 | } | 86 | return 0; |
83 | @@ -XXX,XX +XXX,XX @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm, | 87 | @@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, |
84 | 88 | return ret; | |
85 | tgm->throttle_state = ts; | ||
86 | tgm->aio_context = ctx; | ||
87 | + atomic_set(&tgm->restart_pending, 0); | ||
88 | |||
89 | qemu_mutex_lock(&tg->lock); | ||
90 | /* If the ThrottleGroup is new set this ThrottleGroupMember as the token */ | ||
91 | @@ -XXX,XX +XXX,XX @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) | ||
92 | return; | ||
93 | } | 89 | } |
94 | 90 | ||
95 | + /* Wait for throttle_group_restart_queue_entry() coroutines to finish */ | 91 | + if (!(flags & BDRV_O_RDWR)) { |
96 | + AIO_WAIT_WHILE(tgm->aio_context, atomic_read(&tgm->restart_pending) > 0); | 92 | + ret = blkio_set_bool(s->blkio, "read-only", true); |
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 | + } | ||
97 | + | 100 | + |
98 | qemu_mutex_lock(&tg->lock); | 101 | if (strcmp(blkio_driver, "io_uring") == 0) { |
99 | for (i = 0; i < 2; i++) { | 102 | - ret = blkio_io_uring_open(bs, options, flags, errp); |
100 | assert(tgm->pending_reqs[i] == 0); | 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(); | ||
118 | } | ||
119 | @@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags, | ||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | - if (!(flags & BDRV_O_RDWR)) { | ||
124 | - ret = blkio_set_bool(s->blkio, "read-only", true); | ||
125 | - if (ret < 0) { | ||
126 | - error_setg_errno(errp, -ret, "failed to set read-only: %s", | ||
127 | - blkio_get_error_msg()); | ||
128 | - blkio_destroy(&s->blkio); | ||
129 | - return ret; | ||
130 | - } | ||
131 | - } | ||
132 | - | ||
133 | - ret = blkio_connect(s->blkio); | ||
134 | - if (ret < 0) { | ||
135 | - error_setg_errno(errp, -ret, "blkio_connect failed: %s", | ||
136 | - blkio_get_error_msg()); | ||
137 | - blkio_destroy(&s->blkio); | ||
138 | - return ret; | ||
139 | - } | ||
140 | - | ||
141 | ret = blkio_get_bool(s->blkio, | ||
142 | "needs-mem-regions", | ||
143 | &s->needs_mem_regions); | ||
101 | -- | 144 | -- |
102 | 2.20.1 | 145 | 2.41.0 |
103 | |||
104 | 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 |
New patch | |||
---|---|---|---|
1 | From: Stefano Garzarella <sgarzare@redhat.com> | ||
1 | 2 | ||
3 | Setting the `fd` property fails with virtio-blk-* libblkio drivers | ||
4 | that do not support fd passing since | ||
5 | https://gitlab.com/libblkio/libblkio/-/merge_requests/208. | ||
6 | |||
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. | ||
9 | |||
10 | This patch switches to setting the `fd` property because it is a | ||
11 | better mechanism for probing fd passing support than getting the `fd` | ||
12 | property. | ||
13 | |||
14 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
15 | Message-id: 20230727161020.84213-5-sgarzare@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | --- | ||
18 | block/blkio.c | 2 +- | ||
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
20 | |||
21 | diff --git a/block/blkio.c b/block/blkio.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/block/blkio.c | ||
24 | +++ b/block/blkio.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, | ||
26 | return -EINVAL; | ||
27 | } | ||
28 | |||
29 | - if (blkio_get_int(s->blkio, "fd", &fd) == 0) { | ||
30 | + if (blkio_set_int(s->blkio, "fd", -1) == 0) { | ||
31 | fd_supported = true; | ||
32 | } | ||
33 | |||
34 | -- | ||
35 | 2.41.0 | diff view generated by jsdifflib |