1
The following changes since commit 887cba855bb6ff4775256f7968409281350b568c:
1
The following changes since commit 66547f416a61e0cb711dc76821890242432ba193:
2
2
3
configure: Fix cross-building for RISCV host (v5) (2023-07-11 17:56:09 +0100)
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
https://gitlab.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 75dcb4d790bbe5327169fd72b185960ca58e2fa6:
9
for you to fetch changes up to 1c38fe69e2b8a05c1762b122292fa7e3662f06fd:
10
10
11
virtio-blk: fix host notifier issues during dataplane start/stop (2023-07-12 15:20:32 -0400)
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
Please include these bug fixes in QEMU 8.1. Thanks!
17
16
----------------------------------------------------------------
18
----------------------------------------------------------------
17
19
18
Stefan Hajnoczi (1):
20
Hanna Czenczek (1):
19
virtio-blk: fix host notifier issues during dataplane start/stop
21
block: Fix pad_request's request restriction
20
22
21
hw/block/dataplane/virtio-blk.c | 67 +++++++++++++++++++--------------
23
Sam Li (1):
22
1 file changed, 38 insertions(+), 29 deletions(-)
24
block/file-posix: fix g_file_get_contents return path
25
26
Stefano Garzarella (6):
27
block/blkio: enable the completion eventfd
28
block/blkio: do not use open flags in qemu_open()
29
block/blkio: move blkio_connect() in the drivers functions
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(-)
23
38
24
--
39
--
25
2.40.1
40
2.41.0
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
New patch
1
From: Stefano Garzarella <sgarzare@redhat.com>
1
2
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.
6
7
In all these cases we cannot open the path in read-only mode,
8
when the `read-only` option of blockdev is on, because the exchange
9
of IOCTL commands for example will fail.
10
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
20
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
21
---
22
block/blkio.c | 21 ++++++++++++---------
23
1 file changed, 12 insertions(+), 9 deletions(-)
24
25
diff --git a/block/blkio.c b/block/blkio.c
26
index XXXXXXX..XXXXXXX 100644
27
--- a/block/blkio.c
28
+++ b/block/blkio.c
29
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs,
30
* layer through the "/dev/fdset/N" special path.
31
*/
32
if (fd_supported) {
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
}
57
--
58
2.41.0
59
60
diff view generated by jsdifflib
New patch
1
From: Sam Li <faithilikerun@gmail.com>
1
2
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.
6
7
This issue was found by Matthew Rosato using virtio-blk-{pci,ccw} backed
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
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
---
17
block/file-posix.c | 6 ++----
18
1 file changed, 2 insertions(+), 4 deletions(-)
19
20
diff --git a/block/file-posix.c b/block/file-posix.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/block/file-posix.c
23
+++ b/block/file-posix.c
24
@@ -XXX,XX +XXX,XX @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)
25
static int get_sysfs_str_val(struct stat *st, const char *attribute,
26
char **val) {
27
g_autofree char *sysfspath = NULL;
28
- int ret;
29
size_t len;
30
31
if (!S_ISBLK(st->st_mode)) {
32
@@ -XXX,XX +XXX,XX @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,
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;
40
}
41
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;
48
}
49
#endif
50
51
--
52
2.41.0
53
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 main loop thread can consume 100% CPU when using --device
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
virtio-blk-pci,iothread=<iothread>. ppoll() constantly returns but
3
reading virtqueue host notifiers fails with EAGAIN. The file descriptors
4
are stale and remain registered with the AioContext because of bugs in
5
the virtio-blk dataplane start/stop code.
6
2
7
The problem is that the dataplane start/stop code involves drain
3
This is in preparation for the next patch, where for virtio-blk
8
operations, which call virtio_blk_drained_begin() and
4
drivers we need to handle the failure of blkio_connect().
9
virtio_blk_drained_end() at points where the host notifier is not
10
operational:
11
- In virtio_blk_data_plane_start(), blk_set_aio_context() drains after
12
vblk->dataplane_started has been set to true but the host notifier has
13
not been attached yet.
14
- In virtio_blk_data_plane_stop(), blk_drain() and blk_set_aio_context()
15
drain after the host notifier has already been detached but with
16
vblk->dataplane_started still set to true.
17
5
18
I would like to simplify ->ioeventfd_start/stop() to avoid interactions
6
Let's also rename the *_open() functions to *_connect() to make
19
with drain entirely, but couldn't find a way to do that. Instead, this
7
the code reflect the changes applied.
20
patch accepts the fragile nature of the code and reorders it so that
21
vblk->dataplane_started is false during drain operations. This way the
22
virtio_blk_drained_begin() and virtio_blk_drained_end() calls don't
23
touch the host notifier. The result is that
24
virtio_blk_data_plane_start() and virtio_blk_data_plane_stop() have
25
complete control over the host notifier and stale file descriptors are
26
no longer left in the AioContext.
27
8
28
This patch fixes the 100% CPU consumption in the main loop thread and
9
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
29
correctly moves host notifier processing to the IOThread.
10
Message-id: 20230727161020.84213-2-sgarzare@redhat.com
30
31
Fixes: 1665d9326fd2 ("virtio-blk: implement BlockDevOps->drained_begin()")
32
Reported-by: Lukáš Doktor <ldoktor@redhat.com>
33
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34
Tested-by: Lukas Doktor <ldoktor@redhat.com>
35
Message-id: 20230704151527.193586-1-stefanha@redhat.com
36
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
37
---
12
---
38
hw/block/dataplane/virtio-blk.c | 67 +++++++++++++++++++--------------
13
block/blkio.c | 71 ++++++++++++++++++++++++++++++---------------------
39
1 file changed, 38 insertions(+), 29 deletions(-)
14
1 file changed, 42 insertions(+), 29 deletions(-)
40
15
41
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
16
diff --git a/block/blkio.c b/block/blkio.c
42
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
43
--- a/hw/block/dataplane/virtio-blk.c
18
--- a/block/blkio.c
44
+++ b/hw/block/dataplane/virtio-blk.c
19
+++ b/block/blkio.c
45
@@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
20
@@ -XXX,XX +XXX,XX @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size)
46
47
memory_region_transaction_commit();
48
49
- /*
50
- * These fields are visible to the IOThread so we rely on implicit barriers
51
- * in aio_context_acquire() on the write side and aio_notify_accept() on
52
- * the read side.
53
- */
54
- s->starting = false;
55
- vblk->dataplane_started = true;
56
trace_virtio_blk_data_plane_start(s);
57
58
old_context = blk_get_aio_context(s->conf->conf.blk);
59
@@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
60
event_notifier_set(virtio_queue_get_host_notifier(vq));
61
}
21
}
62
63
+ /*
64
+ * These fields must be visible to the IOThread when it processes the
65
+ * virtqueue, otherwise it will think dataplane has not started yet.
66
+ *
67
+ * Make sure ->dataplane_started is false when blk_set_aio_context() is
68
+ * called above so that draining does not cause the host notifier to be
69
+ * detached/attached prematurely.
70
+ */
71
+ s->starting = false;
72
+ vblk->dataplane_started = true;
73
+ smp_wmb(); /* paired with aio_notify_accept() on the read side */
74
+
75
/* Get this show started by hooking up our callbacks */
76
if (!blk_in_drain(s->conf->conf.blk)) {
77
aio_context_acquire(s->ctx);
78
@@ -XXX,XX +XXX,XX @@ int virtio_blk_data_plane_start(VirtIODevice *vdev)
79
fail_guest_notifiers:
80
vblk->dataplane_disabled = true;
81
s->starting = false;
82
- vblk->dataplane_started = true;
83
return -ENOSYS;
84
}
22
}
85
23
86
@@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
24
-static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags,
87
aio_wait_bh_oneshot(s->ctx, virtio_blk_data_plane_stop_bh, s);
25
- Error **errp)
26
+static int blkio_io_uring_connect(BlockDriverState *bs, QDict *options,
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
}
88
}
33
}
89
34
90
+ /*
35
+ ret = blkio_connect(s->blkio);
91
+ * Batch all the host notifiers in a single transaction to avoid
36
+ if (ret < 0) {
92
+ * quadratic time complexity in address_space_update_ioeventfds().
37
+ error_setg_errno(errp, -ret, "blkio_connect failed: %s",
93
+ */
38
+ blkio_get_error_msg());
94
+ memory_region_transaction_begin();
39
+ return ret;
95
+
96
+ for (i = 0; i < nvqs; i++) {
97
+ virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
98
+ }
40
+ }
99
+
41
+
100
+ /*
42
return 0;
101
+ * The transaction expects the ioeventfds to be open when it
43
}
102
+ * commits. Do it now, before the cleanup loop.
44
103
+ */
45
-static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags,
104
+ memory_region_transaction_commit();
46
- Error **errp)
105
+
47
+static int blkio_nvme_io_uring_connect(BlockDriverState *bs, QDict *options,
106
+ for (i = 0; i < nvqs; i++) {
48
+ int flags, Error **errp)
107
+ virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
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;
54
}
55
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;
108
+ }
61
+ }
109
+
62
+
110
+ /*
63
return 0;
111
+ * Set ->dataplane_started to false before draining so that host notifiers
64
}
112
+ * are not detached/attached anymore.
65
113
+ */
66
-static int blkio_virtio_blk_common_open(BlockDriverState *bs,
114
+ vblk->dataplane_started = false;
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
}
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
+ }
115
+
83
+
116
aio_context_acquire(s->ctx);
84
qdict_del(options, "path");
117
85
118
/* Wait for virtio_blk_dma_restart_bh() and in flight I/O to complete */
86
return 0;
119
@@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev)
87
@@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
120
88
return ret;
121
aio_context_release(s->ctx);
89
}
122
90
123
- /*
91
+ if (!(flags & BDRV_O_RDWR)) {
124
- * Batch all the host notifiers in a single transaction to avoid
92
+ ret = blkio_set_bool(s->blkio, "read-only", true);
125
- * quadratic time complexity in address_space_update_ioeventfds().
93
+ if (ret < 0) {
126
- */
94
+ error_setg_errno(errp, -ret, "failed to set read-only: %s",
127
- memory_region_transaction_begin();
95
+ blkio_get_error_msg());
128
-
96
+ blkio_destroy(&s->blkio);
129
- for (i = 0; i < nvqs; i++) {
97
+ return ret;
130
- virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), i, false);
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();
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
- }
131
- }
132
-
132
-
133
- /*
133
- ret = blkio_connect(s->blkio);
134
- * The transaction expects the ioeventfds to be open when it
134
- if (ret < 0) {
135
- * commits. Do it now, before the cleanup loop.
135
- error_setg_errno(errp, -ret, "blkio_connect failed: %s",
136
- */
136
- blkio_get_error_msg());
137
- memory_region_transaction_commit();
137
- blkio_destroy(&s->blkio);
138
-
138
- return ret;
139
- for (i = 0; i < nvqs; i++) {
140
- virtio_bus_cleanup_host_notifier(VIRTIO_BUS(qbus), i);
141
- }
139
- }
142
-
140
-
143
qemu_bh_cancel(s->bh);
141
ret = blkio_get_bool(s->blkio,
144
notify_guest_bh(s); /* final chance to notify guest */
142
"needs-mem-regions",
145
143
&s->needs_mem_regions);
146
/* Clean up guest notifier (irq) */
147
k->set_guest_notifiers(qbus->parent, nvqs, false);
148
149
- vblk->dataplane_started = false;
150
s->stopping = false;
151
}
152
--
144
--
153
2.40.1
145
2.41.0
154
155
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