1 | The following changes since commit 6338c30111d596d955e6bc933a82184a0b910c43: | 1 | The following changes since commit 66547f416a61e0cb711dc76821890242432ba193: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'm68k-for-7.2-pull-request' of https://github.com/vivier/qemu-m68k into staging (2022-09-21 13:12:36 -0400) | 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 f16d15c9276bd8f501f861c39cbd4adc812d0c1d: | 9 | for you to fetch changes up to 1c38fe69e2b8a05c1762b122292fa7e3662f06fd: |
10 | 10 | ||
11 | virtiofsd: use g_date_time_get_microsecond to get subsecond (2022-09-22 13:13:47 -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 | Yusuke Okada (1): | 20 | Hanna Czenczek (1): |
19 | virtiofsd: use g_date_time_get_microsecond to get subsecond | 21 | block: Fix pad_request's request restriction |
20 | 22 | ||
21 | tools/virtiofsd/passthrough_ll.c | 7 +++++-- | 23 | Sam Li (1): |
22 | 1 file changed, 5 insertions(+), 2 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.37.3 | 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 |
New patch | |||
---|---|---|---|
1 | From: Stefano Garzarella <sgarzare@redhat.com> | ||
1 | 2 | ||
3 | This is in preparation for the next patch, where for virtio-blk | ||
4 | drivers we need to handle the failure of blkio_connect(). | ||
5 | |||
6 | Let's also rename the *_open() functions to *_connect() to make | ||
7 | the code reflect the changes applied. | ||
8 | |||
9 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
10 | Message-id: 20230727161020.84213-2-sgarzare@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | ||
13 | block/blkio.c | 71 ++++++++++++++++++++++++++++++--------------------- | ||
14 | 1 file changed, 42 insertions(+), 29 deletions(-) | ||
15 | |||
16 | diff --git a/block/blkio.c b/block/blkio.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block/blkio.c | ||
19 | +++ b/block/blkio.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size) | ||
21 | } | ||
22 | } | ||
23 | |||
24 | -static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags, | ||
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 | } | ||
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 | + } | ||
41 | + | ||
42 | return 0; | ||
43 | } | ||
44 | |||
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; | ||
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; | ||
61 | + } | ||
62 | + | ||
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 | } | ||
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 | + } | ||
83 | + | ||
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; | ||
89 | } | ||
90 | |||
91 | + if (!(flags & BDRV_O_RDWR)) { | ||
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 | + } | ||
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 | - } | ||
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); | ||
144 | -- | ||
145 | 2.41.0 | 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: Yusuke Okada <okada.yusuke@jp.fujitsu.com> | 1 | From: Stefano Garzarella <sgarzare@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The "%f" specifier in g_date_time_format() is only available in glib | 3 | Setting the `fd` property fails with virtio-blk-* libblkio drivers |
4 | 2.65.2 or later. If combined with older glib, the function returns null | 4 | that do not support fd passing since |
5 | and the timestamp displayed as "(null)". | 5 | https://gitlab.com/libblkio/libblkio/-/merge_requests/208. |
6 | 6 | ||
7 | For backward compatibility, g_date_time_get_microsecond should be used | 7 | Getting the `fd` property, on the other hand, always succeeds for |
8 | to retrieve subsecond. | 8 | virtio-blk-* libblkio drivers even when they don't support fd passing. |
9 | 9 | ||
10 | In this patch the g_date_time_format() leaves subsecond field as "%06d" | 10 | This patch switches to setting the `fd` property because it is a |
11 | and let next snprintf to format with g_date_time_get_microsecond. | 11 | better mechanism for probing fd passing support than getting the `fd` |
12 | property. | ||
12 | 13 | ||
13 | Signed-off-by: Yusuke Okada <okada.yusuke@jp.fujitsu.com> | 14 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> |
14 | Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> | 15 | Message-id: 20230727161020.84213-5-sgarzare@redhat.com |
15 | Message-id: 20220818184618.2205172-1-yokada.996@gmail.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
17 | --- | 17 | --- |
18 | tools/virtiofsd/passthrough_ll.c | 7 +++++-- | 18 | block/blkio.c | 2 +- |
19 | 1 file changed, 5 insertions(+), 2 deletions(-) | 19 | 1 file changed, 1 insertion(+), 1 deletion(-) |
20 | 20 | ||
21 | diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c | 21 | diff --git a/block/blkio.c b/block/blkio.c |
22 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/tools/virtiofsd/passthrough_ll.c | 23 | --- a/block/blkio.c |
24 | +++ b/tools/virtiofsd/passthrough_ll.c | 24 | +++ b/block/blkio.c |
25 | @@ -XXX,XX +XXX,XX @@ static void setup_nofile_rlimit(unsigned long rlimit_nofile) | 25 | @@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, |
26 | static void log_func(enum fuse_log_level level, const char *fmt, va_list ap) | 26 | return -EINVAL; |
27 | { | ||
28 | g_autofree char *localfmt = NULL; | ||
29 | + char buf[64]; | ||
30 | |||
31 | if (current_log_level < level) { | ||
32 | return; | ||
33 | @@ -XXX,XX +XXX,XX @@ static void log_func(enum fuse_log_level level, const char *fmt, va_list ap) | ||
34 | fmt); | ||
35 | } else { | ||
36 | g_autoptr(GDateTime) now = g_date_time_new_now_utc(); | ||
37 | - g_autofree char *nowstr = g_date_time_format(now, "%Y-%m-%d %H:%M:%S.%f%z"); | ||
38 | + g_autofree char *nowstr = g_date_time_format(now, | ||
39 | + "%Y-%m-%d %H:%M:%S.%%06d%z"); | ||
40 | + snprintf(buf, 64, nowstr, g_date_time_get_microsecond(now)); | ||
41 | localfmt = g_strdup_printf("[%s] [ID: %08ld] %s", | ||
42 | - nowstr, syscall(__NR_gettid), fmt); | ||
43 | + buf, syscall(__NR_gettid), fmt); | ||
44 | } | ||
45 | fmt = localfmt; | ||
46 | } | 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 | |||
47 | -- | 34 | -- |
48 | 2.37.3 | 35 | 2.41.0 | diff view generated by jsdifflib |