1
The following changes since commit 711c0418c8c1ce3a24346f058b001c4c5a2f0f81:
1
The following changes since commit 66547f416a61e0cb711dc76821890242432ba193:
2
2
3
Merge remote-tracking branch 'remotes/philmd/tags/mips-20210702' into staging (2021-07-04 14:04:12 +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 9f460c64e13897117f35ffb61f6f5e0102cabc70:
9
for you to fetch changes up to 1c38fe69e2b8a05c1762b122292fa7e3662f06fd:
10
10
11
block/io: Merge discard request alignments (2021-07-06 14:28:55 +0100)
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
Akihiko Odaki (3):
20
Hanna Czenczek (1):
19
block/file-posix: Optimize for macOS
21
block: Fix pad_request's request restriction
20
block: Add backend_defaults property
21
block/io: Merge discard request alignments
22
22
23
Stefan Hajnoczi (2):
23
Sam Li (1):
24
util/async: add a human-readable name to BHs for debugging
24
block/file-posix: fix g_file_get_contents return path
25
util/async: print leaked BH name when AioContext finalizes
26
25
27
include/block/aio.h | 31 ++++++++++++++++++++++---
26
Stefano Garzarella (6):
28
include/hw/block/block.h | 3 +++
27
block/blkio: enable the completion eventfd
29
include/qemu/main-loop.h | 4 +++-
28
block/blkio: do not use open flags in qemu_open()
30
block/file-posix.c | 27 ++++++++++++++++++++--
29
block/blkio: move blkio_connect() in the drivers functions
31
block/io.c | 2 ++
30
block/blkio: retry blkio_connect() if it fails using `fd`
32
hw/block/block.c | 42 ++++++++++++++++++++++++++++++----
31
block/blkio: fall back on using `path` when `fd` setting fails
33
tests/unit/ptimer-test-stubs.c | 2 +-
32
block/blkio: use blkio_set_int("fd") to check fd support
34
util/async.c | 25 ++++++++++++++++----
33
35
util/main-loop.c | 4 ++--
34
block/blkio.c | 132 ++++++++++++++++++++++++++++++---------------
36
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++
35
block/file-posix.c | 6 +--
37
10 files changed, 161 insertions(+), 17 deletions(-)
36
block/io.c | 8 ++-
37
3 files changed, 97 insertions(+), 49 deletions(-)
38
38
39
--
39
--
40
2.31.1
40
2.41.0
41
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
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
1
From: Sam Li <faithilikerun@gmail.com>
2
2
3
This commit introduces "punch hole" operation and optimizes transfer
3
The g_file_get_contents() function returns a g_boolean. If it fails, the
4
block size for macOS.
4
returned value will be 0 instead of -1. Solve the issue by skipping
5
assigning ret value.
5
6
6
Thanks to Konstantin Nazarov for detailed analysis of a flaw in an
7
This issue was found by Matthew Rosato using virtio-blk-{pci,ccw} backed
7
old version of this change:
8
by an NVMe partition e.g. /dev/nvme0n1p1 on s390x.
8
https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3654667
9
9
10
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
10
Signed-off-by: Sam Li <faithilikerun@gmail.com>
11
Message-id: 20210705130458.97642-1-akihiko.odaki@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
12
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
---
16
---
14
block/file-posix.c | 27 +++++++++++++++++++++++++--
17
block/file-posix.c | 6 ++----
15
1 file changed, 25 insertions(+), 2 deletions(-)
18
1 file changed, 2 insertions(+), 4 deletions(-)
16
19
17
diff --git a/block/file-posix.c b/block/file-posix.c
20
diff --git a/block/file-posix.c b/block/file-posix.c
18
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
19
--- a/block/file-posix.c
22
--- a/block/file-posix.c
20
+++ b/block/file-posix.c
23
+++ b/block/file-posix.c
21
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)
22
#if defined(HAVE_HOST_BLOCK_DEVICE)
25
static int get_sysfs_str_val(struct stat *st, const char *attribute,
23
#include <paths.h>
26
char **val) {
24
#include <sys/param.h>
27
g_autofree char *sysfspath = NULL;
25
+#include <sys/mount.h>
28
- int ret;
26
#include <IOKit/IOKitLib.h>
29
size_t len;
27
#include <IOKit/IOBSD.h>
30
28
#include <IOKit/storage/IOMediaBSDClient.h>
31
if (!S_ISBLK(st->st_mode)) {
29
@@ -XXX,XX +XXX,XX @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
32
@@ -XXX,XX +XXX,XX @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,
30
return;
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;
31
}
40
}
32
41
33
+#if defined(__APPLE__) && (__MACH__)
42
@@ -XXX,XX +XXX,XX @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,
34
+ struct statfs buf;
43
if (*(p + len - 1) == '\n') {
35
+
44
*(p + len - 1) = '\0';
36
+ if (!fstatfs(s->fd, &buf)) {
37
+ bs->bl.opt_transfer = buf.f_iosize;
38
+ bs->bl.pdiscard_alignment = buf.f_bsize;
39
+ }
40
+#endif
41
+
42
if (bs->sg || S_ISBLK(st.st_mode)) {
43
int ret = hdev_get_max_hw_transfer(s->fd, &st);
44
45
@@ -XXX,XX +XXX,XX @@ out:
46
}
45
}
46
- return ret;
47
+ return 0;
47
}
48
}
48
49
+#if defined(CONFIG_FALLOCATE) || defined(BLKZEROOUT) || defined(BLKDISCARD)
50
static int translate_err(int err)
51
{
52
if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP ||
53
@@ -XXX,XX +XXX,XX @@ static int translate_err(int err)
54
}
55
return err;
56
}
57
+#endif
58
59
#ifdef CONFIG_FALLOCATE
60
static int do_fallocate(int fd, int mode, off_t offset, off_t len)
61
@@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque)
62
}
63
} while (errno == EINTR);
64
65
- ret = -errno;
66
+ ret = translate_err(-errno);
67
#endif
49
#endif
68
} else {
50
69
#ifdef CONFIG_FALLOCATE_PUNCH_HOLE
70
ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
71
aiocb->aio_offset, aiocb->aio_nbytes);
72
+ ret = translate_err(-errno);
73
+#elif defined(__APPLE__) && (__MACH__)
74
+ fpunchhole_t fpunchhole;
75
+ fpunchhole.fp_flags = 0;
76
+ fpunchhole.reserved = 0;
77
+ fpunchhole.fp_offset = aiocb->aio_offset;
78
+ fpunchhole.fp_length = aiocb->aio_nbytes;
79
+ if (fcntl(s->fd, F_PUNCHHOLE, &fpunchhole) == -1) {
80
+ ret = errno == ENODEV ? -ENOTSUP : -errno;
81
+ } else {
82
+ ret = 0;
83
+ }
84
#endif
85
}
86
87
- ret = translate_err(ret);
88
if (ret == -ENOTSUP) {
89
s->has_discard = false;
90
}
91
--
51
--
92
2.31.1
52
2.41.0
93
53
54
diff view generated by jsdifflib
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
1
From: Hanna Czenczek <hreitz@redhat.com>
2
2
3
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
3
bdrv_pad_request() relies on requests' lengths not to exceed SIZE_MAX,
4
Message-id: 20210705130458.97642-3-akihiko.odaki@gmail.com
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>
5
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
31
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
6
---
32
---
7
block/io.c | 2 ++
33
block/io.c | 8 ++++++--
8
1 file changed, 2 insertions(+)
34
1 file changed, 6 insertions(+), 2 deletions(-)
9
35
10
diff --git a/block/io.c b/block/io.c
36
diff --git a/block/io.c b/block/io.c
11
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
12
--- a/block/io.c
38
--- a/block/io.c
13
+++ b/block/io.c
39
+++ b/block/io.c
14
@@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll)
40
@@ -XXX,XX +XXX,XX @@ static int bdrv_pad_request(BlockDriverState *bs,
15
41
int sliced_niov;
16
static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src)
42
size_t sliced_head, sliced_tail;
17
{
43
18
+ dst->pdiscard_alignment = MAX(dst->pdiscard_alignment,
44
- bdrv_check_qiov_request(*offset, *bytes, *qiov, *qiov_offset, &error_abort);
19
+ src->pdiscard_alignment);
45
+ /* Should have been checked by the caller already */
20
dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer);
46
+ ret = bdrv_check_request32(*offset, *bytes, *qiov, *qiov_offset);
21
dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer);
47
+ if (ret < 0) {
22
dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer,
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);
23
--
62
--
24
2.31.1
63
2.41.0
25
diff view generated by jsdifflib
1
From: Akihiko Odaki <akihiko.odaki@gmail.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
backend_defaults property allow users to control if default block
3
This is in preparation for the next patch, where for virtio-blk
4
properties should be decided with backend information.
4
drivers we need to handle the failure of blkio_connect().
5
5
6
If it is off, any backend information will be discarded, which is
6
Let's also rename the *_open() functions to *_connect() to make
7
suitable if you plan to perform live migration to a different disk backend.
7
the code reflect the changes applied.
8
8
9
If it is on, a block device may utilize backend information more
9
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
10
aggressively.
10
Message-id: 20230727161020.84213-2-sgarzare@redhat.com
11
12
By default, it is auto, which uses backend information for block
13
sizes and ignores the others, which is consistent with the older
14
versions.
15
16
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
17
Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com
18
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
19
---
12
---
20
include/hw/block/block.h | 3 +++
13
block/blkio.c | 71 ++++++++++++++++++++++++++++++---------------------
21
hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++----
14
1 file changed, 42 insertions(+), 29 deletions(-)
22
tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++
23
3 files changed, 79 insertions(+), 4 deletions(-)
24
15
25
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
16
diff --git a/block/blkio.c b/block/blkio.c
26
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
27
--- a/include/hw/block/block.h
18
--- a/block/blkio.c
28
+++ b/include/hw/block/block.h
19
+++ b/block/blkio.c
29
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size)
30
21
}
31
typedef struct BlockConf {
32
BlockBackend *blk;
33
+ OnOffAuto backend_defaults;
34
uint32_t physical_block_size;
35
uint32_t logical_block_size;
36
uint32_t min_io_size;
37
@@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf)
38
}
22
}
39
23
40
#define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \
24
-static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags,
41
+ DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \
25
- Error **errp)
42
+ _conf.backend_defaults, ON_OFF_AUTO_AUTO), \
26
+static int blkio_io_uring_connect(BlockDriverState *bs, QDict *options,
43
DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
27
+ int flags, Error **errp)
44
_conf.logical_block_size), \
45
DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
46
diff --git a/hw/block/block.c b/hw/block/block.c
47
index XXXXXXX..XXXXXXX 100644
48
--- a/hw/block/block.c
49
+++ b/hw/block/block.c
50
@@ -XXX,XX +XXX,XX @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp)
51
{
28
{
52
BlockBackend *blk = conf->blk;
29
const char *filename = qdict_get_str(options, "filename");
53
BlockSizes blocksizes;
30
BDRVBlkioState *s = bs->opaque;
54
- int backend_ret;
31
@@ -XXX,XX +XXX,XX @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags,
55
+ BlockDriverState *bs;
56
+ bool use_blocksizes;
57
+ bool use_bs;
58
+
59
+ switch (conf->backend_defaults) {
60
+ case ON_OFF_AUTO_AUTO:
61
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
62
+ use_bs = false;
63
+ break;
64
+
65
+ case ON_OFF_AUTO_ON:
66
+ use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes);
67
+ bs = blk_bs(blk);
68
+ use_bs = bs;
69
+ break;
70
+
71
+ case ON_OFF_AUTO_OFF:
72
+ use_blocksizes = false;
73
+ use_bs = false;
74
+ break;
75
+
76
+ default:
77
+ abort();
78
+ }
79
80
- backend_ret = blk_probe_blocksizes(blk, &blocksizes);
81
/* fill in detected values if they are not defined via qemu command line */
82
if (!conf->physical_block_size) {
83
- if (!backend_ret) {
84
+ if (use_blocksizes) {
85
conf->physical_block_size = blocksizes.phys;
86
} else {
87
conf->physical_block_size = BDRV_SECTOR_SIZE;
88
}
32
}
89
}
33
}
90
if (!conf->logical_block_size) {
34
91
- if (!backend_ret) {
35
+ ret = blkio_connect(s->blkio);
92
+ if (use_blocksizes) {
36
+ if (ret < 0) {
93
conf->logical_block_size = blocksizes.log;
37
+ error_setg_errno(errp, -ret, "blkio_connect failed: %s",
94
} else {
38
+ blkio_get_error_msg());
95
conf->logical_block_size = BDRV_SECTOR_SIZE;
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,
96
}
74
}
97
}
75
}
98
+ if (use_bs) {
76
99
+ if (!conf->opt_io_size) {
77
+ ret = blkio_connect(s->blkio);
100
+ conf->opt_io_size = bs->bl.opt_transfer;
78
+ if (ret < 0) {
101
+ }
79
+ error_setg_errno(errp, -ret, "blkio_connect failed: %s",
102
+ if (conf->discard_granularity == -1) {
80
+ blkio_get_error_msg());
103
+ if (bs->bl.pdiscard_alignment) {
81
+ return ret;
104
+ conf->discard_granularity = bs->bl.pdiscard_alignment;
82
+ }
105
+ } else if (bs->bl.request_alignment != 1) {
83
+
106
+ conf->discard_granularity = bs->bl.request_alignment;
84
qdict_del(options, "path");
107
+ }
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;
108
+ }
98
+ }
109
+ }
99
+ }
110
100
+
111
if (conf->logical_block_size > conf->physical_block_size) {
101
if (strcmp(blkio_driver, "io_uring") == 0) {
112
error_setg(errp,
102
- ret = blkio_io_uring_open(bs, options, flags, errp);
113
diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out
103
+ ret = blkio_io_uring_connect(bs, options, flags, errp);
114
index XXXXXXX..XXXXXXX 100644
104
} else if (strcmp(blkio_driver, "nvme-io_uring") == 0) {
115
--- a/tests/qemu-iotests/172.out
105
- ret = blkio_nvme_io_uring(bs, options, flags, errp);
116
+++ b/tests/qemu-iotests/172.out
106
+ ret = blkio_nvme_io_uring_connect(bs, options, flags, errp);
117
@@ -XXX,XX +XXX,XX @@ Testing:
107
} else if (strcmp(blkio_driver, "virtio-blk-vfio-pci") == 0) {
118
dev: floppy, id ""
108
- ret = blkio_virtio_blk_common_open(bs, options, flags, errp);
119
unit = 0 (0x0)
109
+ ret = blkio_virtio_blk_connect(bs, options, flags, errp);
120
drive = "floppy0"
110
} else if (strcmp(blkio_driver, "virtio-blk-vhost-user") == 0) {
121
+ backend_defaults = "auto"
111
- ret = blkio_virtio_blk_common_open(bs, options, flags, errp);
122
logical_block_size = 512 (512 B)
112
+ ret = blkio_virtio_blk_connect(bs, options, flags, errp);
123
physical_block_size = 512 (512 B)
113
} else if (strcmp(blkio_driver, "virtio-blk-vhost-vdpa") == 0) {
124
min_io_size = 0 (0 B)
114
- ret = blkio_virtio_blk_common_open(bs, options, flags, errp);
125
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2
115
+ ret = blkio_virtio_blk_connect(bs, options, flags, errp);
126
dev: floppy, id ""
116
} else {
127
unit = 0 (0x0)
117
g_assert_not_reached();
128
drive = "floppy0"
118
}
129
+ backend_defaults = "auto"
119
@@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
130
logical_block_size = 512 (512 B)
120
return ret;
131
physical_block_size = 512 (512 B)
121
}
132
min_io_size = 0 (0 B)
122
133
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
123
- if (!(flags & BDRV_O_RDWR)) {
134
dev: floppy, id ""
124
- ret = blkio_set_bool(s->blkio, "read-only", true);
135
unit = 1 (0x1)
125
- if (ret < 0) {
136
drive = "floppy1"
126
- error_setg_errno(errp, -ret, "failed to set read-only: %s",
137
+ backend_defaults = "auto"
127
- blkio_get_error_msg());
138
logical_block_size = 512 (512 B)
128
- blkio_destroy(&s->blkio);
139
physical_block_size = 512 (512 B)
129
- return ret;
140
min_io_size = 0 (0 B)
130
- }
141
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2
131
- }
142
dev: floppy, id ""
132
-
143
unit = 0 (0x0)
133
- ret = blkio_connect(s->blkio);
144
drive = "floppy0"
134
- if (ret < 0) {
145
+ backend_defaults = "auto"
135
- error_setg_errno(errp, -ret, "blkio_connect failed: %s",
146
logical_block_size = 512 (512 B)
136
- blkio_get_error_msg());
147
physical_block_size = 512 (512 B)
137
- blkio_destroy(&s->blkio);
148
min_io_size = 0 (0 B)
138
- return ret;
149
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
139
- }
150
dev: floppy, id ""
140
-
151
unit = 1 (0x1)
141
ret = blkio_get_bool(s->blkio,
152
drive = "floppy1"
142
"needs-mem-regions",
153
+ backend_defaults = "auto"
143
&s->needs_mem_regions);
154
logical_block_size = 512 (512 B)
155
physical_block_size = 512 (512 B)
156
min_io_size = 0 (0 B)
157
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2
158
dev: floppy, id ""
159
unit = 0 (0x0)
160
drive = "floppy0"
161
+ backend_defaults = "auto"
162
logical_block_size = 512 (512 B)
163
physical_block_size = 512 (512 B)
164
min_io_size = 0 (0 B)
165
@@ -XXX,XX +XXX,XX @@ Testing: -fdb
166
dev: floppy, id ""
167
unit = 1 (0x1)
168
drive = "floppy1"
169
+ backend_defaults = "auto"
170
logical_block_size = 512 (512 B)
171
physical_block_size = 512 (512 B)
172
min_io_size = 0 (0 B)
173
@@ -XXX,XX +XXX,XX @@ Testing: -fdb
174
dev: floppy, id ""
175
unit = 0 (0x0)
176
drive = "floppy0"
177
+ backend_defaults = "auto"
178
logical_block_size = 512 (512 B)
179
physical_block_size = 512 (512 B)
180
min_io_size = 0 (0 B)
181
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2
182
dev: floppy, id ""
183
unit = 0 (0x0)
184
drive = "floppy0"
185
+ backend_defaults = "auto"
186
logical_block_size = 512 (512 B)
187
physical_block_size = 512 (512 B)
188
min_io_size = 0 (0 B)
189
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
190
dev: floppy, id ""
191
unit = 1 (0x1)
192
drive = "floppy1"
193
+ backend_defaults = "auto"
194
logical_block_size = 512 (512 B)
195
physical_block_size = 512 (512 B)
196
min_io_size = 0 (0 B)
197
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1
198
dev: floppy, id ""
199
unit = 0 (0x0)
200
drive = "floppy0"
201
+ backend_defaults = "auto"
202
logical_block_size = 512 (512 B)
203
physical_block_size = 512 (512 B)
204
min_io_size = 0 (0 B)
205
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t
206
dev: floppy, id ""
207
unit = 1 (0x1)
208
drive = "floppy1"
209
+ backend_defaults = "auto"
210
logical_block_size = 512 (512 B)
211
physical_block_size = 512 (512 B)
212
min_io_size = 0 (0 B)
213
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t
214
dev: floppy, id ""
215
unit = 0 (0x0)
216
drive = "floppy0"
217
+ backend_defaults = "auto"
218
logical_block_size = 512 (512 B)
219
physical_block_size = 512 (512 B)
220
min_io_size = 0 (0 B)
221
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0
222
dev: floppy, id ""
223
unit = 0 (0x0)
224
drive = "none0"
225
+ backend_defaults = "auto"
226
logical_block_size = 512 (512 B)
227
physical_block_size = 512 (512 B)
228
min_io_size = 0 (0 B)
229
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1
230
dev: floppy, id ""
231
unit = 1 (0x1)
232
drive = "none0"
233
+ backend_defaults = "auto"
234
logical_block_size = 512 (512 B)
235
physical_block_size = 512 (512 B)
236
min_io_size = 0 (0 B)
237
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
238
dev: floppy, id ""
239
unit = 1 (0x1)
240
drive = "none1"
241
+ backend_defaults = "auto"
242
logical_block_size = 512 (512 B)
243
physical_block_size = 512 (512 B)
244
min_io_size = 0 (0 B)
245
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco
246
dev: floppy, id ""
247
unit = 0 (0x0)
248
drive = "none0"
249
+ backend_defaults = "auto"
250
logical_block_size = 512 (512 B)
251
physical_block_size = 512 (512 B)
252
min_io_size = 0 (0 B)
253
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
254
dev: floppy, id ""
255
unit = 1 (0x1)
256
drive = "none0"
257
+ backend_defaults = "auto"
258
logical_block_size = 512 (512 B)
259
physical_block_size = 512 (512 B)
260
min_io_size = 0 (0 B)
261
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
262
dev: floppy, id ""
263
unit = 0 (0x0)
264
drive = "floppy0"
265
+ backend_defaults = "auto"
266
logical_block_size = 512 (512 B)
267
physical_block_size = 512 (512 B)
268
min_io_size = 0 (0 B)
269
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
270
dev: floppy, id ""
271
unit = 1 (0x1)
272
drive = "none0"
273
+ backend_defaults = "auto"
274
logical_block_size = 512 (512 B)
275
physical_block_size = 512 (512 B)
276
min_io_size = 0 (0 B)
277
@@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
278
dev: floppy, id ""
279
unit = 0 (0x0)
280
drive = "floppy0"
281
+ backend_defaults = "auto"
282
logical_block_size = 512 (512 B)
283
physical_block_size = 512 (512 B)
284
min_io_size = 0 (0 B)
285
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
286
dev: floppy, id ""
287
unit = 0 (0x0)
288
drive = "none0"
289
+ backend_defaults = "auto"
290
logical_block_size = 512 (512 B)
291
physical_block_size = 512 (512 B)
292
min_io_size = 0 (0 B)
293
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
294
dev: floppy, id ""
295
unit = 1 (0x1)
296
drive = "floppy1"
297
+ backend_defaults = "auto"
298
logical_block_size = 512 (512 B)
299
physical_block_size = 512 (512 B)
300
min_io_size = 0 (0 B)
301
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
302
dev: floppy, id ""
303
unit = 0 (0x0)
304
drive = "none0"
305
+ backend_defaults = "auto"
306
logical_block_size = 512 (512 B)
307
physical_block_size = 512 (512 B)
308
min_io_size = 0 (0 B)
309
@@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl
310
dev: floppy, id ""
311
unit = 1 (0x1)
312
drive = "floppy1"
313
+ backend_defaults = "auto"
314
logical_block_size = 512 (512 B)
315
physical_block_size = 512 (512 B)
316
min_io_size = 0 (0 B)
317
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
318
dev: floppy, id ""
319
unit = 1 (0x1)
320
drive = "none0"
321
+ backend_defaults = "auto"
322
logical_block_size = 512 (512 B)
323
physical_block_size = 512 (512 B)
324
min_io_size = 0 (0 B)
325
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
326
dev: floppy, id ""
327
unit = 0 (0x0)
328
drive = "floppy0"
329
+ backend_defaults = "auto"
330
logical_block_size = 512 (512 B)
331
physical_block_size = 512 (512 B)
332
min_io_size = 0 (0 B)
333
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
334
dev: floppy, id ""
335
unit = 1 (0x1)
336
drive = "none0"
337
+ backend_defaults = "auto"
338
logical_block_size = 512 (512 B)
339
physical_block_size = 512 (512 B)
340
min_io_size = 0 (0 B)
341
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q
342
dev: floppy, id ""
343
unit = 0 (0x0)
344
drive = "floppy0"
345
+ backend_defaults = "auto"
346
logical_block_size = 512 (512 B)
347
physical_block_size = 512 (512 B)
348
min_io_size = 0 (0 B)
349
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device
350
dev: floppy, id ""
351
unit = 0 (0x0)
352
drive = "none0"
353
+ backend_defaults = "auto"
354
logical_block_size = 512 (512 B)
355
physical_block_size = 512 (512 B)
356
min_io_size = 0 (0 B)
357
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy
358
dev: floppy, id ""
359
unit = 0 (0x0)
360
drive = ""
361
+ backend_defaults = "auto"
362
logical_block_size = 512 (512 B)
363
physical_block_size = 512 (512 B)
364
min_io_size = 0 (0 B)
365
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=120
366
dev: floppy, id ""
367
unit = 0 (0x0)
368
drive = ""
369
+ backend_defaults = "auto"
370
logical_block_size = 512 (512 B)
371
physical_block_size = 512 (512 B)
372
min_io_size = 0 (0 B)
373
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=144
374
dev: floppy, id ""
375
unit = 0 (0x0)
376
drive = ""
377
+ backend_defaults = "auto"
378
logical_block_size = 512 (512 B)
379
physical_block_size = 512 (512 B)
380
min_io_size = 0 (0 B)
381
@@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=288
382
dev: floppy, id ""
383
unit = 0 (0x0)
384
drive = ""
385
+ backend_defaults = "auto"
386
logical_block_size = 512 (512 B)
387
physical_block_size = 512 (512 B)
388
min_io_size = 0 (0 B)
389
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t
390
dev: floppy, id ""
391
unit = 0 (0x0)
392
drive = "none0"
393
+ backend_defaults = "auto"
394
logical_block_size = 512 (512 B)
395
physical_block_size = 512 (512 B)
396
min_io_size = 0 (0 B)
397
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t
398
dev: floppy, id ""
399
unit = 0 (0x0)
400
drive = "none0"
401
+ backend_defaults = "auto"
402
logical_block_size = 512 (512 B)
403
physical_block_size = 512 (512 B)
404
min_io_size = 0 (0 B)
405
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical
406
dev: floppy, id ""
407
unit = 0 (0x0)
408
drive = "none0"
409
+ backend_defaults = "auto"
410
logical_block_size = 512 (512 B)
411
physical_block_size = 512 (512 B)
412
min_io_size = 0 (0 B)
413
@@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica
414
dev: floppy, id ""
415
unit = 0 (0x0)
416
drive = "none0"
417
+ backend_defaults = "auto"
418
logical_block_size = 512 (512 B)
419
physical_block_size = 512 (512 B)
420
min_io_size = 0 (0 B)
421
--
144
--
422
2.31.1
145
2.41.0
423
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
1
BHs must be deleted before the AioContext is finalized. If not, it's a
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
bug and probably indicates that some part of the program still expects
3
the BH to run in the future. That can lead to memory leaks, inconsistent
4
state, or just hangs.
5
2
6
Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize()
3
qemu_open() fails if called with an unix domain socket in this way:
7
is difficult to debug because the assertion failure contains no
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
8
information about the BH!
9
5
10
Use the QEMUBH name field added in the previous patch to show a useful
6
Since virtio-blk-vhost-user does not support fd passing, let`s always fall back
11
error when a leaked BH is detected.
7
on using `path` if we fail the fd passing.
12
8
13
Suggested-by: Eric Ernst <eric.g.ernst@gmail.com>
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
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Message-Id: <20210414200247.917496-3-stefanha@redhat.com>
16
---
14
---
17
util/async.c | 16 ++++++++++++++--
15
block/blkio.c | 20 ++++++++++----------
18
1 file changed, 14 insertions(+), 2 deletions(-)
16
1 file changed, 10 insertions(+), 10 deletions(-)
19
17
20
diff --git a/util/async.c b/util/async.c
18
diff --git a/block/blkio.c b/block/blkio.c
21
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
22
--- a/util/async.c
20
--- a/block/blkio.c
23
+++ b/util/async.c
21
+++ b/block/blkio.c
24
@@ -XXX,XX +XXX,XX @@ aio_ctx_finalize(GSource *source)
22
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
25
assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list));
23
* In order to open the device read-only, we are using the `read-only`
26
24
* property of the libblkio driver in blkio_file_open().
27
while ((bh = aio_bh_dequeue(&ctx->bh_list, &flags))) {
25
*/
28
- /* qemu_bh_delete() must have been called on BHs in this AioContext */
26
- fd = qemu_open(path, O_RDWR, errp);
29
- assert(flags & BH_DELETED);
27
+ fd = qemu_open(path, O_RDWR, NULL);
30
+ /*
28
if (fd < 0) {
31
+ * qemu_bh_delete() must have been called on BHs in this AioContext. In
29
- return -EINVAL;
32
+ * many cases memory leaks, hangs, or inconsistent state occur when a
30
+ fd_supported = false;
33
+ * BH is leaked because something still expects it to run.
31
+ } else {
34
+ *
32
+ ret = blkio_set_int(s->blkio, "fd", fd);
35
+ * If you hit this, fix the lifecycle of the BH so that
33
+ if (ret < 0) {
36
+ * qemu_bh_delete() and any associated cleanup is called before the
34
+ fd_supported = false;
37
+ * AioContext is finalized.
35
+ qemu_close(fd);
38
+ */
36
+ }
39
+ if (unlikely(!(flags & BH_DELETED))) {
37
}
40
+ fprintf(stderr, "%s: BH '%s' leaked, aborting...\n",
38
+ }
41
+ __func__, bh->name);
39
42
+ abort();
40
- ret = blkio_set_int(s->blkio, "fd", fd);
43
+ }
41
- if (ret < 0) {
44
42
- error_setg_errno(errp, -ret, "failed to set fd: %s",
45
g_free(bh);
43
- blkio_get_error_msg());
46
}
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",
47
--
52
--
48
2.31.1
53
2.41.0
49
diff view generated by jsdifflib
1
It can be difficult to debug issues with BHs in production environments.
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
Although BHs can usually be identified by looking up their ->cb()
3
function pointer, this requires debug information for the program. It is
4
also not possible to print human-readable diagnostics about BHs because
5
they have no identifier.
6
2
7
This patch adds a name to each BH. The name is not unique per instance
3
Setting the `fd` property fails with virtio-blk-* libblkio drivers
8
but differentiates between cb() functions, which is usually enough. It's
4
that do not support fd passing since
9
done by changing aio_bh_new() and friends to macros that stringify cb.
5
https://gitlab.com/libblkio/libblkio/-/merge_requests/208.
10
6
11
The next patch will use the name field when reporting leaked BHs.
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.
12
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
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
15
Message-Id: <20210414200247.917496-2-stefanha@redhat.com>
16
---
17
---
17
include/block/aio.h | 31 ++++++++++++++++++++++++++++---
18
block/blkio.c | 2 +-
18
include/qemu/main-loop.h | 4 +++-
19
1 file changed, 1 insertion(+), 1 deletion(-)
19
tests/unit/ptimer-test-stubs.c | 2 +-
20
util/async.c | 9 +++++++--
21
util/main-loop.c | 4 ++--
22
5 files changed, 41 insertions(+), 9 deletions(-)
23
20
24
diff --git a/include/block/aio.h b/include/block/aio.h
21
diff --git a/block/blkio.c b/block/blkio.c
25
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
26
--- a/include/block/aio.h
23
--- a/block/blkio.c
27
+++ b/include/block/aio.h
24
+++ b/block/blkio.c
28
@@ -XXX,XX +XXX,XX @@ void aio_context_acquire(AioContext *ctx);
25
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
29
/* Relinquish ownership of the AioContext. */
26
return -EINVAL;
30
void aio_context_release(AioContext *ctx);
27
}
31
28
32
+/**
29
- if (blkio_get_int(s->blkio, "fd", &fd) == 0) {
33
+ * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will
30
+ if (blkio_set_int(s->blkio, "fd", -1) == 0) {
34
+ * run only once and as soon as possible.
31
fd_supported = true;
35
+ *
32
}
36
+ * @name: A human-readable identifier for debugging purposes.
33
37
+ */
38
+void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
39
+ const char *name);
40
+
41
/**
42
* aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run
43
* only once and as soon as possible.
44
+ *
45
+ * A convenience wrapper for aio_bh_schedule_oneshot_full() that uses cb as the
46
+ * name string.
47
*/
48
-void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
49
+#define aio_bh_schedule_oneshot(ctx, cb, opaque) \
50
+ aio_bh_schedule_oneshot_full((ctx), (cb), (opaque), (stringify(cb)))
51
52
/**
53
- * aio_bh_new: Allocate a new bottom half structure.
54
+ * aio_bh_new_full: Allocate a new bottom half structure.
55
*
56
* Bottom halves are lightweight callbacks whose invocation is guaranteed
57
* to be wait-free, thread-safe and signal-safe. The #QEMUBH structure
58
* is opaque and must be allocated prior to its use.
59
+ *
60
+ * @name: A human-readable identifier for debugging purposes.
61
*/
62
-QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
63
+QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
64
+ const char *name);
65
+
66
+/**
67
+ * aio_bh_new: Allocate a new bottom half structure
68
+ *
69
+ * A convenience wrapper for aio_bh_new_full() that uses the cb as the name
70
+ * string.
71
+ */
72
+#define aio_bh_new(ctx, cb, opaque) \
73
+ aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb)))
74
75
/**
76
* aio_notify: Force processing of pending events.
77
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
78
index XXXXXXX..XXXXXXX 100644
79
--- a/include/qemu/main-loop.h
80
+++ b/include/qemu/main-loop.h
81
@@ -XXX,XX +XXX,XX @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms);
82
83
void qemu_fd_register(int fd);
84
85
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque);
86
+#define qemu_bh_new(cb, opaque) \
87
+ qemu_bh_new_full((cb), (opaque), (stringify(cb)))
88
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name);
89
void qemu_bh_schedule_idle(QEMUBH *bh);
90
91
enum {
92
diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c
93
index XXXXXXX..XXXXXXX 100644
94
--- a/tests/unit/ptimer-test-stubs.c
95
+++ b/tests/unit/ptimer-test-stubs.c
96
@@ -XXX,XX +XXX,XX @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
97
return deadline;
98
}
99
100
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
101
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
102
{
103
QEMUBH *bh = g_new(QEMUBH, 1);
104
105
diff --git a/util/async.c b/util/async.c
106
index XXXXXXX..XXXXXXX 100644
107
--- a/util/async.c
108
+++ b/util/async.c
109
@@ -XXX,XX +XXX,XX @@ enum {
110
111
struct QEMUBH {
112
AioContext *ctx;
113
+ const char *name;
114
QEMUBHFunc *cb;
115
void *opaque;
116
QSLIST_ENTRY(QEMUBH) next;
117
@@ -XXX,XX +XXX,XX @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags)
118
return bh;
119
}
120
121
-void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
122
+void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb,
123
+ void *opaque, const char *name)
124
{
125
QEMUBH *bh;
126
bh = g_new(QEMUBH, 1);
127
@@ -XXX,XX +XXX,XX @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
128
.ctx = ctx,
129
.cb = cb,
130
.opaque = opaque,
131
+ .name = name,
132
};
133
aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT);
134
}
135
136
-QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
137
+QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque,
138
+ const char *name)
139
{
140
QEMUBH *bh;
141
bh = g_new(QEMUBH, 1);
142
@@ -XXX,XX +XXX,XX @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
143
.ctx = ctx,
144
.cb = cb,
145
.opaque = opaque,
146
+ .name = name,
147
};
148
return bh;
149
}
150
diff --git a/util/main-loop.c b/util/main-loop.c
151
index XXXXXXX..XXXXXXX 100644
152
--- a/util/main-loop.c
153
+++ b/util/main-loop.c
154
@@ -XXX,XX +XXX,XX @@ void main_loop_wait(int nonblocking)
155
156
/* Functions to operate on the main QEMU AioContext. */
157
158
-QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
159
+QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name)
160
{
161
- return aio_bh_new(qemu_aio_context, cb, opaque);
162
+ return aio_bh_new_full(qemu_aio_context, cb, opaque, name);
163
}
164
165
/*
166
--
34
--
167
2.31.1
35
2.41.0
168
diff view generated by jsdifflib