1
The following changes since commit 6c769690ac845fa62642a5f93b4e4bd906adab95:
1
The following changes since commit 66547f416a61e0cb711dc76821890242432ba193:
2
2
3
Merge remote-tracking branch 'remotes/vsementsov/tags/pull-simplebench-2021-05-04' into staging (2021-05-21 12:02:34 +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 0a6f0c76a030710780ce10d6347a70f098024d21:
9
for you to fetch changes up to 1c38fe69e2b8a05c1762b122292fa7e3662f06fd:
10
10
11
coroutine-sleep: introduce qemu_co_sleep (2021-05-21 18:22:33 +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
(Resent due to an email preparation mistake.)
16
Please include these bug fixes in QEMU 8.1. Thanks!
17
17
18
----------------------------------------------------------------
18
----------------------------------------------------------------
19
19
20
Paolo Bonzini (6):
20
Hanna Czenczek (1):
21
coroutine-sleep: use a stack-allocated timer
21
block: Fix pad_request's request restriction
22
coroutine-sleep: disallow NULL QemuCoSleepState** argument
23
coroutine-sleep: allow qemu_co_sleep_wake that wakes nothing
24
coroutine-sleep: move timer out of QemuCoSleepState
25
coroutine-sleep: replace QemuCoSleepState pointer with struct in the
26
API
27
coroutine-sleep: introduce qemu_co_sleep
28
22
29
Philippe Mathieu-Daudé (1):
23
Sam Li (1):
30
bitops.h: Improve find_xxx_bit() documentation
24
block/file-posix: fix g_file_get_contents return path
31
25
32
Zenghui Yu (1):
26
Stefano Garzarella (6):
33
multi-process: Initialize variables declared with g_auto*
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
34
33
35
include/qemu/bitops.h | 15 ++++++--
34
block/blkio.c | 132 ++++++++++++++++++++++++++++++---------------
36
include/qemu/coroutine.h | 27 ++++++++-----
35
block/file-posix.c | 6 +--
37
block/block-copy.c | 10 ++---
36
block/io.c | 8 ++-
38
block/nbd.c | 14 +++----
37
3 files changed, 97 insertions(+), 49 deletions(-)
39
hw/remote/memory.c | 5 +--
40
hw/remote/proxy.c | 3 +-
41
util/qemu-coroutine-sleep.c | 75 +++++++++++++++++++------------------
42
7 files changed, 79 insertions(+), 70 deletions(-)
43
38
44
--
39
--
45
2.31.1
40
2.41.0
46
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
Allow using QemuCoSleep to sleep forever until woken by qemu_co_sleep_wake.
3
Until libblkio 1.3.0, virtio-blk drivers had completion eventfd
4
This makes the logic of qemu_co_sleep_ns_wakeable easy to understand.
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.
5
6
6
In the future we will introduce an API that can work even if the
7
In fact, the libblkio documentation says they could be disabled,
7
sleep and wake happen from different threads. For now, initializing
8
so we should always enable them at the start if we want to be
8
w->to_wake after timer_mod is fine because the timer can only fire in
9
sure to get completion eventfd notifications:
9
the same AioContext.
10
10
11
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
11
By default, the driver might not generate completion events for
12
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12
requests so it is necessary to explicitly enable the completion
13
Message-id: 20210517100548.28806-7-pbonzini@redhat.com
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
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
23
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
---
24
---
16
include/qemu/coroutine.h | 5 +++++
25
block/blkio.c | 1 +
17
util/qemu-coroutine-sleep.c | 26 +++++++++++++++++++-------
26
1 file changed, 1 insertion(+)
18
2 files changed, 24 insertions(+), 7 deletions(-)
19
27
20
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
28
diff --git a/block/blkio.c b/block/blkio.c
21
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
22
--- a/include/qemu/coroutine.h
30
--- a/block/blkio.c
23
+++ b/include/qemu/coroutine.h
31
+++ b/block/blkio.c
24
@@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleep {
32
@@ -XXX,XX +XXX,XX @@ static int blkio_file_open(BlockDriverState *bs, QDict *options, int flags,
25
void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
33
QLIST_INIT(&s->bounce_bufs);
26
QEMUClockType type, int64_t ns);
34
s->blkioq = blkio_get_queue(s->blkio, 0);
27
35
s->completion_fd = blkioq_get_completion_fd(s->blkioq);
28
+/**
36
+ blkioq_set_completion_fd_enabled(s->blkioq, true);
29
+ * Yield the coroutine until the next call to qemu_co_sleep_wake.
37
30
+ */
38
blkio_attach_aio_context(bs, bdrv_get_aio_context(bs));
31
+void coroutine_fn qemu_co_sleep(QemuCoSleep *w);
39
return 0;
32
+
33
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
34
{
35
QemuCoSleep w = { 0 };
36
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/util/qemu-coroutine-sleep.c
39
+++ b/util/qemu-coroutine-sleep.c
40
@@ -XXX,XX +XXX,XX @@ static void co_sleep_cb(void *opaque)
41
qemu_co_sleep_wake(w);
42
}
43
44
-void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
45
- QEMUClockType type, int64_t ns)
46
+void coroutine_fn qemu_co_sleep(QemuCoSleep *w)
47
{
48
Coroutine *co = qemu_coroutine_self();
49
- AioContext *ctx = qemu_get_current_aio_context();
50
- QEMUTimer ts;
51
52
const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL,
53
qemu_co_sleep_ns__scheduled);
54
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
55
}
56
57
w->to_wake = co;
58
- aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w),
59
- timer_mod(&ts, qemu_clock_get_ns(type) + ns);
60
qemu_coroutine_yield();
61
- timer_del(&ts);
62
63
/* w->to_wake is cleared before resuming this coroutine. */
64
assert(w->to_wake == NULL);
65
}
66
+
67
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
68
+ QEMUClockType type, int64_t ns)
69
+{
70
+ AioContext *ctx = qemu_get_current_aio_context();
71
+ QEMUTimer ts;
72
+
73
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w);
74
+ timer_mod(&ts, qemu_clock_get_ns(type) + ns);
75
+
76
+ /*
77
+ * The timer will fire in the current AiOContext, so the callback
78
+ * must happen after qemu_co_sleep yields and there is no race
79
+ * between timer_mod and qemu_co_sleep.
80
+ */
81
+ qemu_co_sleep(w);
82
+ timer_del(&ts);
83
+}
84
--
40
--
85
2.31.1
41
2.41.0
86
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
This simplification is enabled by the previous patch. Now aio_co_wake
3
qemu_open() in blkio_virtio_blk_common_open() is used to open the
4
will only be called once, therefore we do not care about a spurious
4
character device (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or in
5
firing of the timer after a qemu_co_sleep_wake.
5
the future eventually the unix socket.
6
6
7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
In all these cases we cannot open the path in read-only mode,
8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
when the `read-only` option of blockdev is on, because the exchange
9
Message-id: 20210517100548.28806-5-pbonzini@redhat.com
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
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
20
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
21
---
12
util/qemu-coroutine-sleep.c | 8 ++++----
22
block/blkio.c | 21 ++++++++++++---------
13
1 file changed, 4 insertions(+), 4 deletions(-)
23
1 file changed, 12 insertions(+), 9 deletions(-)
14
24
15
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
25
diff --git a/block/blkio.c b/block/blkio.c
16
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
17
--- a/util/qemu-coroutine-sleep.c
27
--- a/block/blkio.c
18
+++ b/util/qemu-coroutine-sleep.c
28
+++ b/block/blkio.c
19
@@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
29
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_common_open(BlockDriverState *bs,
20
30
* layer through the "/dev/fdset/N" special path.
21
struct QemuCoSleepState {
31
*/
22
Coroutine *co;
32
if (fd_supported) {
23
- QEMUTimer ts;
33
- int open_flags;
24
QemuCoSleepState **user_state_pointer;
34
-
25
};
35
- if (flags & BDRV_O_RDWR) {
26
36
- open_flags = O_RDWR;
27
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
37
- } else {
28
38
- open_flags = O_RDONLY;
29
assert(scheduled == qemu_co_sleep_ns__scheduled);
39
- }
30
*sleep_state->user_state_pointer = NULL;
40
-
31
- timer_del(&sleep_state->ts);
41
- fd = qemu_open(path, open_flags, errp);
32
aio_co_wake(sleep_state->co);
42
+ /*
33
}
43
+ * `path` can contain the path of a character device
34
}
44
+ * (e.g. /dev/vhost-vdpa-0 or /dev/vfio/vfio) or a unix socket.
35
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
45
+ *
36
QemuCoSleepState **sleep_state)
46
+ * So, we should always open it with O_RDWR flag, also if BDRV_O_RDWR
37
{
47
+ * is not set in the open flags, because the exchange of IOCTL commands
38
AioContext *ctx = qemu_get_current_aio_context();
48
+ * for example will fail.
39
+ QEMUTimer ts;
49
+ *
40
QemuCoSleepState state = {
50
+ * In order to open the device read-only, we are using the `read-only`
41
.co = qemu_coroutine_self(),
51
+ * property of the libblkio driver in blkio_file_open().
42
.user_state_pointer = sleep_state,
52
+ */
43
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
53
+ fd = qemu_open(path, O_RDWR, errp);
44
abort();
54
if (fd < 0) {
45
}
55
return -EINVAL;
46
56
}
47
- aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state);
48
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state);
49
*sleep_state = &state;
50
- timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
51
+ timer_mod(&ts, qemu_clock_get_ns(type) + ns);
52
qemu_coroutine_yield();
53
+ timer_del(&ts);
54
55
/* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
56
assert(*sleep_state == NULL);
57
--
57
--
58
2.31.1
58
2.41.0
59
59
60
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Sam Li <faithilikerun@gmail.com>
2
2
3
All callers of qemu_co_sleep_wake are checking whether they are passing
3
The g_file_get_contents() function returns a g_boolean. If it fails, the
4
a NULL argument inside the pointer-to-pointer: do the check in
4
returned value will be 0 instead of -1. Solve the issue by skipping
5
qemu_co_sleep_wake itself.
5
assigning ret value.
6
6
7
As a side effect, qemu_co_sleep_wake can be called more than once and
7
This issue was found by Matthew Rosato using virtio-blk-{pci,ccw} backed
8
it will only wake the coroutine once; after the first time, the argument
8
by an NVMe partition e.g. /dev/nvme0n1p1 on s390x.
9
will be set to NULL via *sleep_state->user_state_pointer. However, this
10
would not be safe unless co_sleep_cb keeps using the QemuCoSleepState*
11
directly, so make it go through the pointer-to-pointer instead.
12
9
13
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
10
Signed-off-by: Sam Li <faithilikerun@gmail.com>
14
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
11
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
15
Message-id: 20210517100548.28806-4-pbonzini@redhat.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
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
17
---
16
---
18
block/block-copy.c | 4 +---
17
block/file-posix.c | 6 ++----
19
block/nbd.c | 8 ++------
18
1 file changed, 2 insertions(+), 4 deletions(-)
20
util/qemu-coroutine-sleep.c | 21 ++++++++++++---------
21
3 files changed, 15 insertions(+), 18 deletions(-)
22
19
23
diff --git a/block/block-copy.c b/block/block-copy.c
20
diff --git a/block/file-posix.c b/block/file-posix.c
24
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
25
--- a/block/block-copy.c
22
--- a/block/file-posix.c
26
+++ b/block/block-copy.c
23
+++ b/block/file-posix.c
27
@@ -XXX,XX +XXX,XX @@ out:
24
@@ -XXX,XX +XXX,XX @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)
28
25
static int get_sysfs_str_val(struct stat *st, const char *attribute,
29
void block_copy_kick(BlockCopyCallState *call_state)
26
char **val) {
30
{
27
g_autofree char *sysfspath = NULL;
31
- if (call_state->sleep_state) {
28
- int ret;
32
- qemu_co_sleep_wake(call_state->sleep_state);
29
size_t len;
33
- }
30
34
+ qemu_co_sleep_wake(call_state->sleep_state);
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;
35
}
48
}
36
49
#endif
37
/*
50
38
diff --git a/block/nbd.c b/block/nbd.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/block/nbd.c
41
+++ b/block/nbd.c
42
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs)
43
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
44
45
s->drained = true;
46
- if (s->connection_co_sleep_ns_state) {
47
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
48
- }
49
+ qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
50
51
nbd_co_establish_connection_cancel(bs, false);
52
53
@@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs)
54
55
s->state = NBD_CLIENT_QUIT;
56
if (s->connection_co) {
57
- if (s->connection_co_sleep_ns_state) {
58
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
59
- }
60
+ qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
61
nbd_co_establish_connection_cancel(bs, true);
62
}
63
if (qemu_in_coroutine()) {
64
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
65
index XXXXXXX..XXXXXXX 100644
66
--- a/util/qemu-coroutine-sleep.c
67
+++ b/util/qemu-coroutine-sleep.c
68
@@ -XXX,XX +XXX,XX @@ struct QemuCoSleepState {
69
70
void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
71
{
72
- /* Write of schedule protected by barrier write in aio_co_schedule */
73
- const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
74
- qemu_co_sleep_ns__scheduled, NULL);
75
+ if (sleep_state) {
76
+ /* Write of schedule protected by barrier write in aio_co_schedule */
77
+ const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
78
+ qemu_co_sleep_ns__scheduled, NULL);
79
80
- assert(scheduled == qemu_co_sleep_ns__scheduled);
81
- *sleep_state->user_state_pointer = NULL;
82
- timer_del(&sleep_state->ts);
83
- aio_co_wake(sleep_state->co);
84
+ assert(scheduled == qemu_co_sleep_ns__scheduled);
85
+ *sleep_state->user_state_pointer = NULL;
86
+ timer_del(&sleep_state->ts);
87
+ aio_co_wake(sleep_state->co);
88
+ }
89
}
90
91
static void co_sleep_cb(void *opaque)
92
{
93
- qemu_co_sleep_wake(opaque);
94
+ QemuCoSleepState **sleep_state = opaque;
95
+ qemu_co_sleep_wake(*sleep_state);
96
}
97
98
void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
99
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
100
abort();
101
}
102
103
- aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
104
+ aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state);
105
*sleep_state = &state;
106
timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
107
qemu_coroutine_yield();
108
--
51
--
109
2.31.1
52
2.41.0
110
53
54
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Hanna Czenczek <hreitz@redhat.com>
2
2
3
Document the following functions return the bitmap size
3
bdrv_pad_request() relies on requests' lengths not to exceed SIZE_MAX,
4
if no matching bit is found:
4
which bdrv_check_qiov_request() does not guarantee.
5
5
6
- find_first_bit
6
bdrv_check_request32() however will guarantee this, and both of
7
- find_next_bit
7
bdrv_pad_request()'s callers (bdrv_co_preadv_part() and
8
- find_last_bit
8
bdrv_co_pwritev_part()) already run it before calling
9
- find_first_zero_bit
9
bdrv_pad_request(). Therefore, bdrv_pad_request() can safely call
10
- find_next_zero_bit
10
bdrv_check_request32() without expecting error, too.
11
11
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
In effect, this patch will not change guest-visible behavior. It is a
13
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
13
clean-up to tighten a condition to match what is guaranteed by our
14
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
14
callers, and which exists purely to show clearly why the subsequent
15
Message-id: 20210510200758.2623154-2-philmd@redhat.com
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>
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
31
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
17
---
32
---
18
include/qemu/bitops.h | 15 ++++++++++++---
33
block/io.c | 8 ++++++--
19
1 file changed, 12 insertions(+), 3 deletions(-)
34
1 file changed, 6 insertions(+), 2 deletions(-)
20
35
21
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
36
diff --git a/block/io.c b/block/io.c
22
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
23
--- a/include/qemu/bitops.h
38
--- a/block/io.c
24
+++ b/include/qemu/bitops.h
39
+++ b/block/io.c
25
@@ -XXX,XX +XXX,XX @@ static inline int test_bit(long nr, const unsigned long *addr)
40
@@ -XXX,XX +XXX,XX @@ static int bdrv_pad_request(BlockDriverState *bs,
26
* @addr: The address to start the search at
41
int sliced_niov;
27
* @size: The maximum size to search
42
size_t sliced_head, sliced_tail;
28
*
43
29
- * Returns the bit number of the first set bit, or size.
44
- bdrv_check_qiov_request(*offset, *bytes, *qiov, *qiov_offset, &error_abort);
30
+ * Returns the bit number of the last set bit,
45
+ /* Should have been checked by the caller already */
31
+ * or @size if there is no set bit in the bitmap.
46
+ ret = bdrv_check_request32(*offset, *bytes, *qiov, *qiov_offset);
32
*/
47
+ if (ret < 0) {
33
unsigned long find_last_bit(const unsigned long *addr,
48
+ return ret;
34
unsigned long size);
49
+ }
35
@@ -XXX,XX +XXX,XX @@ unsigned long find_last_bit(const unsigned long *addr,
50
36
* @addr: The address to base the search on
51
if (!bdrv_init_padding(bs, *offset, *bytes, write, pad)) {
37
* @offset: The bitnumber to start searching at
52
if (padded) {
38
* @size: The bitmap size in bits
53
@@ -XXX,XX +XXX,XX @@ static int bdrv_pad_request(BlockDriverState *bs,
39
+ *
54
&sliced_head, &sliced_tail,
40
+ * Returns the bit number of the next set bit,
55
&sliced_niov);
41
+ * or @size if there are no further set bits in the bitmap.
56
42
*/
57
- /* Guaranteed by bdrv_check_qiov_request() */
43
unsigned long find_next_bit(const unsigned long *addr,
58
+ /* Guaranteed by bdrv_check_request32() */
44
unsigned long size,
59
assert(*bytes <= SIZE_MAX);
45
@@ -XXX,XX +XXX,XX @@ unsigned long find_next_bit(const unsigned long *addr,
60
ret = bdrv_create_padded_qiov(bs, pad, sliced_iov, sliced_niov,
46
* @addr: The address to base the search on
61
sliced_head, *bytes);
47
* @offset: The bitnumber to start searching at
48
* @size: The bitmap size in bits
49
+ *
50
+ * Returns the bit number of the next cleared bit,
51
+ * or @size if there are no further clear bits in the bitmap.
52
*/
53
54
unsigned long find_next_zero_bit(const unsigned long *addr,
55
@@ -XXX,XX +XXX,XX @@ unsigned long find_next_zero_bit(const unsigned long *addr,
56
* @addr: The address to start the search at
57
* @size: The maximum size to search
58
*
59
- * Returns the bit number of the first set bit.
60
+ * Returns the bit number of the first set bit,
61
+ * or @size if there is no set bit in the bitmap.
62
*/
63
static inline unsigned long find_first_bit(const unsigned long *addr,
64
unsigned long size)
65
@@ -XXX,XX +XXX,XX @@ static inline unsigned long find_first_bit(const unsigned long *addr,
66
* @addr: The address to start the search at
67
* @size: The maximum size to search
68
*
69
- * Returns the bit number of the first cleared bit.
70
+ * Returns the bit number of the first cleared bit,
71
+ * or @size if there is no clear bit in the bitmap.
72
*/
73
static inline unsigned long find_first_zero_bit(const unsigned long *addr,
74
unsigned long size)
75
--
62
--
76
2.31.1
63
2.41.0
77
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
Right now, users of qemu_co_sleep_ns_wakeable are simply passing
3
This is in preparation for the next patch, where for virtio-blk
4
a pointer to QemuCoSleepState by reference to the function. But
4
drivers we need to handle the failure of blkio_connect().
5
QemuCoSleepState really is just a Coroutine*; making the
6
content of the struct public is just as efficient and lets us
7
skip the user_state_pointer indirection.
8
5
9
Since the usage is changed, take the occasion to rename the
6
Let's also rename the *_open() functions to *_connect() to make
10
struct to QemuCoSleep.
7
the code reflect the changes applied.
11
8
12
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
9
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
13
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
10
Message-id: 20230727161020.84213-2-sgarzare@redhat.com
14
Message-id: 20210517100548.28806-6-pbonzini@redhat.com
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
---
12
---
17
include/qemu/coroutine.h | 23 +++++++++++----------
13
block/blkio.c | 71 ++++++++++++++++++++++++++++++---------------------
18
block/block-copy.c | 8 ++++----
14
1 file changed, 42 insertions(+), 29 deletions(-)
19
block/nbd.c | 10 ++++-----
20
util/qemu-coroutine-sleep.c | 41 ++++++++++++++++---------------------
21
4 files changed, 39 insertions(+), 43 deletions(-)
22
15
23
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
16
diff --git a/block/blkio.c b/block/blkio.c
24
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
25
--- a/include/qemu/coroutine.h
18
--- a/block/blkio.c
26
+++ b/include/qemu/coroutine.h
19
+++ b/block/blkio.c
27
@@ -XXX,XX +XXX,XX @@ void qemu_co_rwlock_wrlock(CoRwlock *lock);
20
@@ -XXX,XX +XXX,XX @@ static void blkio_unregister_buf(BlockDriverState *bs, void *host, size_t size)
28
*/
29
void qemu_co_rwlock_unlock(CoRwlock *lock);
30
31
-typedef struct QemuCoSleepState QemuCoSleepState;
32
+typedef struct QemuCoSleep {
33
+ Coroutine *to_wake;
34
+} QemuCoSleep;
35
36
/**
37
- * Yield the coroutine for a given duration. During this yield, @sleep_state
38
- * is set to an opaque pointer, which may be used for
39
- * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the
40
- * timer fires. Don't save the obtained value to other variables and don't call
41
- * qemu_co_sleep_wake from another aio context.
42
+ * Yield the coroutine for a given duration. Initializes @w so that,
43
+ * during this yield, it can be passed to qemu_co_sleep_wake() to
44
+ * terminate the sleep.
45
*/
46
-void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
47
- QemuCoSleepState **sleep_state);
48
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
49
+ QEMUClockType type, int64_t ns);
50
+
51
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
52
{
53
- QemuCoSleepState *unused = NULL;
54
- qemu_co_sleep_ns_wakeable(type, ns, &unused);
55
+ QemuCoSleep w = { 0 };
56
+ qemu_co_sleep_ns_wakeable(&w, type, ns);
57
}
58
59
/**
60
@@ -XXX,XX +XXX,XX @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
61
* qemu_co_sleep_ns() and should be checked to be non-NULL before calling
62
* qemu_co_sleep_wake().
63
*/
64
-void qemu_co_sleep_wake(QemuCoSleepState *sleep_state);
65
+void qemu_co_sleep_wake(QemuCoSleep *w);
66
67
/**
68
* Yield until a file descriptor becomes readable
69
diff --git a/block/block-copy.c b/block/block-copy.c
70
index XXXXXXX..XXXXXXX 100644
71
--- a/block/block-copy.c
72
+++ b/block/block-copy.c
73
@@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyCallState {
74
/* State */
75
int ret;
76
bool finished;
77
- QemuCoSleepState *sleep_state;
78
+ QemuCoSleep sleep;
79
bool cancelled;
80
81
/* OUT parameters */
82
@@ -XXX,XX +XXX,XX @@ block_copy_dirty_clusters(BlockCopyCallState *call_state)
83
if (ns > 0) {
84
block_copy_task_end(task, -EAGAIN);
85
g_free(task);
86
- qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, ns,
87
- &call_state->sleep_state);
88
+ qemu_co_sleep_ns_wakeable(&call_state->sleep,
89
+ QEMU_CLOCK_REALTIME, ns);
90
continue;
91
}
92
}
93
@@ -XXX,XX +XXX,XX @@ out:
94
95
void block_copy_kick(BlockCopyCallState *call_state)
96
{
97
- qemu_co_sleep_wake(call_state->sleep_state);
98
+ qemu_co_sleep_wake(&call_state->sleep);
99
}
100
101
/*
102
diff --git a/block/nbd.c b/block/nbd.c
103
index XXXXXXX..XXXXXXX 100644
104
--- a/block/nbd.c
105
+++ b/block/nbd.c
106
@@ -XXX,XX +XXX,XX @@ typedef struct BDRVNBDState {
107
CoQueue free_sema;
108
Coroutine *connection_co;
109
Coroutine *teardown_co;
110
- QemuCoSleepState *connection_co_sleep_ns_state;
111
+ QemuCoSleep reconnect_sleep;
112
bool drained;
113
bool wait_drained_end;
114
int in_flight;
115
@@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs)
116
BDRVNBDState *s = (BDRVNBDState *)bs->opaque;
117
118
s->drained = true;
119
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
120
+ qemu_co_sleep_wake(&s->reconnect_sleep);
121
122
nbd_co_establish_connection_cancel(bs, false);
123
124
@@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs)
125
126
s->state = NBD_CLIENT_QUIT;
127
if (s->connection_co) {
128
- qemu_co_sleep_wake(s->connection_co_sleep_ns_state);
129
+ qemu_co_sleep_wake(&s->reconnect_sleep);
130
nbd_co_establish_connection_cancel(bs, true);
131
}
132
if (qemu_in_coroutine()) {
133
@@ -XXX,XX +XXX,XX @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s)
134
}
135
bdrv_inc_in_flight(s->bs);
136
} else {
137
- qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, timeout,
138
- &s->connection_co_sleep_ns_state);
139
+ qemu_co_sleep_ns_wakeable(&s->reconnect_sleep,
140
+ QEMU_CLOCK_REALTIME, timeout);
141
if (s->drained) {
142
continue;
143
}
144
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
145
index XXXXXXX..XXXXXXX 100644
146
--- a/util/qemu-coroutine-sleep.c
147
+++ b/util/qemu-coroutine-sleep.c
148
@@ -XXX,XX +XXX,XX @@
149
150
static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
151
152
-struct QemuCoSleepState {
153
+void qemu_co_sleep_wake(QemuCoSleep *w)
154
+{
155
Coroutine *co;
156
- QemuCoSleepState **user_state_pointer;
157
-};
158
159
-void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
160
-{
161
- if (sleep_state) {
162
+ co = w->to_wake;
163
+ w->to_wake = NULL;
164
+ if (co) {
165
/* Write of schedule protected by barrier write in aio_co_schedule */
166
- const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled,
167
+ const char *scheduled = qatomic_cmpxchg(&co->scheduled,
168
qemu_co_sleep_ns__scheduled, NULL);
169
170
assert(scheduled == qemu_co_sleep_ns__scheduled);
171
- *sleep_state->user_state_pointer = NULL;
172
- aio_co_wake(sleep_state->co);
173
+ aio_co_wake(co);
174
}
21
}
175
}
22
}
176
23
177
static void co_sleep_cb(void *opaque)
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)
178
{
28
{
179
- QemuCoSleepState **sleep_state = opaque;
29
const char *filename = qdict_get_str(options, "filename");
180
- qemu_co_sleep_wake(*sleep_state);
30
BDRVBlkioState *s = bs->opaque;
181
+ QemuCoSleep *w = opaque;
31
@@ -XXX,XX +XXX,XX @@ static int blkio_io_uring_open(BlockDriverState *bs, QDict *options, int flags,
182
+ qemu_co_sleep_wake(w);
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;
183
}
43
}
184
44
185
-void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
45
-static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags,
186
- QemuCoSleepState **sleep_state)
46
- Error **errp)
187
+void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w,
47
+static int blkio_nvme_io_uring_connect(BlockDriverState *bs, QDict *options,
188
+ QEMUClockType type, int64_t ns)
48
+ int flags, Error **errp)
189
{
49
{
190
+ Coroutine *co = qemu_coroutine_self();
50
const char *path = qdict_get_try_str(options, "path");
191
AioContext *ctx = qemu_get_current_aio_context();
51
BDRVBlkioState *s = bs->opaque;
192
QEMUTimer ts;
52
@@ -XXX,XX +XXX,XX @@ static int blkio_nvme_io_uring(BlockDriverState *bs, QDict *options, int flags,
193
- QemuCoSleepState state = {
53
return -EINVAL;
194
- .co = qemu_coroutine_self(),
195
- .user_state_pointer = sleep_state,
196
- };
197
198
- const char *scheduled = qatomic_cmpxchg(&state.co->scheduled, NULL,
199
- qemu_co_sleep_ns__scheduled);
200
+ const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL,
201
+ qemu_co_sleep_ns__scheduled);
202
if (scheduled) {
203
fprintf(stderr,
204
"%s: Co-routine was already scheduled in '%s'\n",
205
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
206
abort();
207
}
54
}
208
55
209
- aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state);
56
+ ret = blkio_connect(s->blkio);
210
- *sleep_state = &state;
57
+ if (ret < 0) {
211
+ w->to_wake = co;
58
+ error_setg_errno(errp, -ret, "blkio_connect failed: %s",
212
+ aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w),
59
+ blkio_get_error_msg());
213
timer_mod(&ts, qemu_clock_get_ns(type) + ns);
60
+ return ret;
214
qemu_coroutine_yield();
61
+ }
215
timer_del(&ts);
62
+
216
63
return 0;
217
- /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
218
- assert(*sleep_state == NULL);
219
+ /* w->to_wake is cleared before resuming this coroutine. */
220
+ assert(w->to_wake == NULL);
221
}
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);
222
--
144
--
223
2.31.1
145
2.41.0
224
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
Simplify the code by removing conditionals. qemu_co_sleep_ns
3
libblkio 1.3.0 added support of "fd" property for virtio-blk-vhost-vdpa
4
can simply point the argument to an on-stack temporary.
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.
5
8
6
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
9
Unfortunately that property is also available for those driver that do
7
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
10
not support it, such as virtio-blk-vhost-user.
8
Message-id: 20210517100548.28806-3-pbonzini@redhat.com
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
9
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
25
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
10
---
26
---
11
include/qemu/coroutine.h | 5 +++--
27
block/blkio.c | 29 +++++++++++++++++++++++++++++
12
util/qemu-coroutine-sleep.c | 18 +++++-------------
28
1 file changed, 29 insertions(+)
13
2 files changed, 8 insertions(+), 15 deletions(-)
14
29
15
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
30
diff --git a/block/blkio.c b/block/blkio.c
16
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
17
--- a/include/qemu/coroutine.h
32
--- a/block/blkio.c
18
+++ b/include/qemu/coroutine.h
33
+++ b/block/blkio.c
19
@@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleepState QemuCoSleepState;
34
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
20
21
/**
22
* Yield the coroutine for a given duration. During this yield, @sleep_state
23
- * (if not NULL) is set to an opaque pointer, which may be used for
24
+ * is set to an opaque pointer, which may be used for
25
* qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the
26
* timer fires. Don't save the obtained value to other variables and don't call
27
* qemu_co_sleep_wake from another aio context.
28
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
29
QemuCoSleepState **sleep_state);
30
static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
31
{
32
- qemu_co_sleep_ns_wakeable(type, ns, NULL);
33
+ QemuCoSleepState *unused = NULL;
34
+ qemu_co_sleep_ns_wakeable(type, ns, &unused);
35
}
36
37
/**
38
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/util/qemu-coroutine-sleep.c
41
+++ b/util/qemu-coroutine-sleep.c
42
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
43
qemu_co_sleep_ns__scheduled, NULL);
44
45
assert(scheduled == qemu_co_sleep_ns__scheduled);
46
- if (sleep_state->user_state_pointer) {
47
- *sleep_state->user_state_pointer = NULL;
48
- }
49
+ *sleep_state->user_state_pointer = NULL;
50
timer_del(&sleep_state->ts);
51
aio_co_wake(sleep_state->co);
52
}
53
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
54
}
35
}
55
36
56
aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
37
ret = blkio_connect(s->blkio);
57
- if (sleep_state) {
38
+ /*
58
- *sleep_state = &state;
39
+ * If the libblkio driver doesn't support the `fd` property, blkio_connect()
59
- }
40
+ * will fail with -EINVAL. So let's try calling blkio_connect() again by
60
+ *sleep_state = &state;
41
+ * directly setting `path`.
61
timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
42
+ */
62
qemu_coroutine_yield();
43
+ if (fd_supported && ret == -EINVAL) {
63
- if (sleep_state) {
44
+ qemu_close(fd);
64
- /*
65
- * Note that *sleep_state is cleared during qemu_co_sleep_wake
66
- * before resuming this coroutine.
67
- */
68
- assert(*sleep_state == NULL);
69
- }
70
+
45
+
71
+ /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */
46
+ /*
72
+ assert(*sleep_state == NULL);
47
+ * We need to clear the `fd` property we set previously by setting
73
}
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());
74
--
70
--
75
2.31.1
71
2.41.0
76
diff view generated by jsdifflib
1
From: Zenghui Yu <yuzenghui@huawei.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
Quote docs/devel/style.rst (section "Automatic memory deallocation"):
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
4
5
5
* Variables declared with g_auto* MUST always be initialized,
6
Since virtio-blk-vhost-user does not support fd passing, let`s always fall back
6
otherwise the cleanup function will use uninitialized stack memory
7
on using `path` if we fail the fd passing.
7
8
8
Initialize @name properly to get rid of the compilation error (using
9
Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk")
9
gcc-7.3.0 on CentOS):
10
Reported-by: Qing Wang <qinwang@redhat.com>
10
11
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
11
../hw/remote/proxy.c: In function 'pci_proxy_dev_realize':
12
Message-id: 20230727161020.84213-4-sgarzare@redhat.com
12
/usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be used uninitialized in this function [-Werror=maybe-uninitialized]
13
g_free (*pp);
14
^~~~~~~~~~~~
15
../hw/remote/proxy.c:350:30: note: 'name' was declared here
16
g_autofree char *name;
17
^~~~
18
19
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
20
Reviewed-by: Jagannathan Raman <jag.raman@oracle.com>
21
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22
Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com>
23
Message-id: 20210312112143.1369-1-yuzenghui@huawei.com
24
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
25
---
14
---
26
hw/remote/memory.c | 5 ++---
15
block/blkio.c | 20 ++++++++++----------
27
hw/remote/proxy.c | 3 +--
16
1 file changed, 10 insertions(+), 10 deletions(-)
28
2 files changed, 3 insertions(+), 5 deletions(-)
29
17
30
diff --git a/hw/remote/memory.c b/hw/remote/memory.c
18
diff --git a/block/blkio.c b/block/blkio.c
31
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/remote/memory.c
20
--- a/block/blkio.c
33
+++ b/hw/remote/memory.c
21
+++ b/block/blkio.c
34
@@ -XXX,XX +XXX,XX @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
22
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
35
23
* In order to open the device read-only, we are using the `read-only`
36
remote_sysmem_reset();
24
* property of the libblkio driver in blkio_file_open().
37
25
*/
38
- for (region = 0; region < msg->num_fds; region++) {
26
- fd = qemu_open(path, O_RDWR, errp);
39
- g_autofree char *name;
27
+ fd = qemu_open(path, O_RDWR, NULL);
40
+ for (region = 0; region < msg->num_fds; region++, suffix++) {
28
if (fd < 0) {
41
+ g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix);
29
- return -EINVAL;
42
subregion = g_new(MemoryRegion, 1);
30
+ fd_supported = false;
43
- name = g_strdup_printf("remote-mem-%u", suffix++);
31
+ } else {
44
memory_region_init_ram_from_fd(subregion, NULL,
32
+ ret = blkio_set_int(s->blkio, "fd", fd);
45
name, sysmem_info->sizes[region],
33
+ if (ret < 0) {
46
true, msg->fds[region],
34
+ fd_supported = false;
47
diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c
35
+ qemu_close(fd);
48
index XXXXXXX..XXXXXXX 100644
36
+ }
49
--- a/hw/remote/proxy.c
37
}
50
+++ b/hw/remote/proxy.c
38
+ }
51
@@ -XXX,XX +XXX,XX @@ static void probe_pci_info(PCIDevice *dev, Error **errp)
39
52
PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY;
40
- ret = blkio_set_int(s->blkio, "fd", fd);
53
41
- if (ret < 0) {
54
if (size) {
42
- error_setg_errno(errp, -ret, "failed to set fd: %s",
55
- g_autofree char *name;
43
- blkio_get_error_msg());
56
+ g_autofree char *name = g_strdup_printf("bar-region-%d", i);
44
- qemu_close(fd);
57
pdev->region[i].dev = pdev;
45
- return ret;
58
pdev->region[i].present = true;
46
- }
59
if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) {
47
- } else {
60
pdev->region[i].memory = true;
48
+ if (!fd_supported) {
61
}
49
ret = blkio_set_str(s->blkio, "path", path);
62
- name = g_strdup_printf("bar-region-%d", i);
50
if (ret < 0) {
63
memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev),
51
error_setg_errno(errp, -ret, "failed to set path: %s",
64
&proxy_mr_ops, &pdev->region[i],
65
name, size);
66
--
52
--
67
2.31.1
53
2.41.0
68
diff view generated by jsdifflib
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
The lifetime of the timer is well-known (it cannot outlive
3
Setting the `fd` property fails with virtio-blk-* libblkio drivers
4
qemu_co_sleep_ns_wakeable, because it's deleted by the time the
4
that do not support fd passing since
5
coroutine resumes), so it is not necessary to place it on the heap.
5
https://gitlab.com/libblkio/libblkio/-/merge_requests/208.
6
6
7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7
Getting the `fd` property, on the other hand, always succeeds for
8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
8
virtio-blk-* libblkio drivers even when they don't support fd passing.
9
Message-id: 20210517100548.28806-2-pbonzini@redhat.com
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
10
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
---
17
---
12
util/qemu-coroutine-sleep.c | 9 ++++-----
18
block/blkio.c | 2 +-
13
1 file changed, 4 insertions(+), 5 deletions(-)
19
1 file changed, 1 insertion(+), 1 deletion(-)
14
20
15
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
21
diff --git a/block/blkio.c b/block/blkio.c
16
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
17
--- a/util/qemu-coroutine-sleep.c
23
--- a/block/blkio.c
18
+++ b/util/qemu-coroutine-sleep.c
24
+++ b/block/blkio.c
19
@@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns";
25
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
20
26
return -EINVAL;
21
struct QemuCoSleepState {
22
Coroutine *co;
23
- QEMUTimer *ts;
24
+ QEMUTimer ts;
25
QemuCoSleepState **user_state_pointer;
26
};
27
28
@@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state)
29
if (sleep_state->user_state_pointer) {
30
*sleep_state->user_state_pointer = NULL;
31
}
27
}
32
- timer_del(sleep_state->ts);
28
33
+ timer_del(&sleep_state->ts);
29
- if (blkio_get_int(s->blkio, "fd", &fd) == 0) {
34
aio_co_wake(sleep_state->co);
30
+ if (blkio_set_int(s->blkio, "fd", -1) == 0) {
35
}
31
fd_supported = true;
36
37
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
38
AioContext *ctx = qemu_get_current_aio_context();
39
QemuCoSleepState state = {
40
.co = qemu_coroutine_self(),
41
- .ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state),
42
.user_state_pointer = sleep_state,
43
};
44
45
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
46
abort();
47
}
32
}
48
33
49
+ aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state);
50
if (sleep_state) {
51
*sleep_state = &state;
52
}
53
- timer_mod(state.ts, qemu_clock_get_ns(type) + ns);
54
+ timer_mod(&state.ts, qemu_clock_get_ns(type) + ns);
55
qemu_coroutine_yield();
56
if (sleep_state) {
57
/*
58
@@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
59
*/
60
assert(*sleep_state == NULL);
61
}
62
- timer_free(state.ts);
63
}
64
--
34
--
65
2.31.1
35
2.41.0
66
diff view generated by jsdifflib