1
The following changes since commit ca61fa4b803e5d0abaf6f1ceb690f23bb78a4def:
1
The following changes since commit 9ba37026fcf6b7f3f096c0cca3e1e7307802486b:
2
2
3
Merge remote-tracking branch 'remotes/quic/tags/pull-hex-20211006' into staging (2021-10-06 12:11:14 -0700)
3
Update version for v8.1.0-rc2 release (2023-08-02 08:22:45 -0700)
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 1cc7eada97914f090125e588497986f6f7900514:
9
for you to fetch changes up to 9b06d0d076271d76e5384d767ef94a676f0a9efd:
10
10
11
iothread: use IOThreadParamInfo in iothread_[set|get]_param() (2021-10-07 15:29:50 +0100)
11
block/blkio: add more comments on the fd passing handling (2023-08-03 11:28:43 -0400)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Pull request
14
Pull request
15
15
16
Fix for an fd leak in the blkio block driver.
17
16
----------------------------------------------------------------
18
----------------------------------------------------------------
17
19
18
Stefano Garzarella (2):
20
Stefano Garzarella (2):
19
iothread: rename PollParamInfo to IOThreadParamInfo
21
block/blkio: close the fd when blkio_connect() fails
20
iothread: use IOThreadParamInfo in iothread_[set|get]_param()
22
block/blkio: add more comments on the fd passing handling
21
23
22
iothread.c | 28 +++++++++++++++-------------
24
block/blkio.c | 28 +++++++++++++++++++++-------
23
1 file changed, 15 insertions(+), 13 deletions(-)
25
1 file changed, 21 insertions(+), 7 deletions(-)
24
26
25
--
27
--
26
2.31.1
28
2.41.0
27
28
29
diff view generated by jsdifflib
1
From: Stefano Garzarella <sgarzare@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
Commit 0445409d74 ("iothread: generalize
3
libblkio drivers take ownership of `fd` only after a successful
4
iothread_set_param/iothread_get_param") moved common code to set and
4
blkio_connect(), so if it fails, we are still the owners.
5
get IOThread parameters in two new functions.
6
5
7
These functions are called inside callbacks, so we don't need to use an
6
Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for virtio-blk")
8
opaque pointer. Let's replace `void *opaque` parameter with
7
Suggested-by: Hanna Czenczek <hreitz@redhat.com>
9
`IOThreadParamInfo *info`.
10
11
Suggested-by: Kevin Wolf <kwolf@redhat.com>
12
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
8
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
14
Message-id: 20210727145936.147032-3-sgarzare@redhat.com
10
Message-id: 20230803082825.25293-2-sgarzare@redhat.com
15
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
16
---
12
---
17
iothread.c | 18 ++++++++++--------
13
block/blkio.c | 11 ++++++++---
18
1 file changed, 10 insertions(+), 8 deletions(-)
14
1 file changed, 8 insertions(+), 3 deletions(-)
19
15
20
diff --git a/iothread.c b/iothread.c
16
diff --git a/block/blkio.c b/block/blkio.c
21
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
22
--- a/iothread.c
18
--- a/block/blkio.c
23
+++ b/iothread.c
19
+++ b/block/blkio.c
24
@@ -XXX,XX +XXX,XX @@ static IOThreadParamInfo aio_max_batch_info = {
20
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
25
};
21
const char *path = qdict_get_try_str(options, "path");
26
22
BDRVBlkioState *s = bs->opaque;
27
static void iothread_get_param(Object *obj, Visitor *v,
23
bool fd_supported = false;
28
- const char *name, void *opaque, Error **errp)
24
- int fd, ret;
29
+ const char *name, IOThreadParamInfo *info, Error **errp)
25
+ int fd = -1, ret;
30
{
26
31
IOThread *iothread = IOTHREAD(obj);
27
if (!path) {
32
- IOThreadParamInfo *info = opaque;
28
error_setg(errp, "missing 'path' option");
33
int64_t *field = (void *)iothread + info->offset;
29
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
34
30
if (ret < 0) {
35
visit_type_int64(v, name, field, errp);
31
fd_supported = false;
36
}
32
qemu_close(fd);
37
33
+ fd = -1;
38
static bool iothread_set_param(Object *obj, Visitor *v,
34
}
39
- const char *name, void *opaque, Error **errp)
35
}
40
+ const char *name, IOThreadParamInfo *info, Error **errp)
41
{
42
IOThread *iothread = IOTHREAD(obj);
43
- IOThreadParamInfo *info = opaque;
44
int64_t *field = (void *)iothread + info->offset;
45
int64_t value;
46
47
@@ -XXX,XX +XXX,XX @@ static bool iothread_set_param(Object *obj, Visitor *v,
48
static void iothread_get_poll_param(Object *obj, Visitor *v,
49
const char *name, void *opaque, Error **errp)
50
{
51
+ IOThreadParamInfo *info = opaque;
52
53
- iothread_get_param(obj, v, name, opaque, errp);
54
+ iothread_get_param(obj, v, name, info, errp);
55
}
56
57
static void iothread_set_poll_param(Object *obj, Visitor *v,
58
const char *name, void *opaque, Error **errp)
59
{
60
IOThread *iothread = IOTHREAD(obj);
61
+ IOThreadParamInfo *info = opaque;
62
63
- if (!iothread_set_param(obj, v, name, opaque, errp)) {
64
+ if (!iothread_set_param(obj, v, name, info, errp)) {
65
return;
66
}
36
}
67
37
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
68
@@ -XXX,XX +XXX,XX @@ static void iothread_set_poll_param(Object *obj, Visitor *v,
69
static void iothread_get_aio_param(Object *obj, Visitor *v,
70
const char *name, void *opaque, Error **errp)
71
{
72
+ IOThreadParamInfo *info = opaque;
73
74
- iothread_get_param(obj, v, name, opaque, errp);
75
+ iothread_get_param(obj, v, name, info, errp);
76
}
77
78
static void iothread_set_aio_param(Object *obj, Visitor *v,
79
const char *name, void *opaque, Error **errp)
80
{
81
IOThread *iothread = IOTHREAD(obj);
82
+ IOThreadParamInfo *info = opaque;
83
84
- if (!iothread_set_param(obj, v, name, opaque, errp)) {
85
+ if (!iothread_set_param(obj, v, name, info, errp)) {
86
return;
87
}
38
}
88
39
40
ret = blkio_connect(s->blkio);
41
+ if (ret < 0 && fd >= 0) {
42
+ /* Failed to give the FD to libblkio, close it */
43
+ qemu_close(fd);
44
+ fd = -1;
45
+ }
46
+
47
/*
48
* If the libblkio driver doesn't support the `fd` property, blkio_connect()
49
* will fail with -EINVAL. So let's try calling blkio_connect() again by
50
* directly setting `path`.
51
*/
52
if (fd_supported && ret == -EINVAL) {
53
- qemu_close(fd);
54
-
55
/*
56
* We need to clear the `fd` property we set previously by setting
57
* it to -1.
89
--
58
--
90
2.31.1
59
2.41.0
91
92
diff view generated by jsdifflib
1
From: Stefano Garzarella <sgarzare@redhat.com>
1
From: Stefano Garzarella <sgarzare@redhat.com>
2
2
3
Commit 1793ad0247 ("iothread: add aio-max-batch parameter") added
3
As Hanna pointed out, it is not clear in the code why qemu_open()
4
a new parameter (aio-max-batch) to IOThread and used PollParamInfo
4
can fail, and why blkio_set_int("fd") is not enough to discover
5
structure to handle it.
5
the `fd` property support.
6
6
7
Since it is not a parameter of the polling mechanism, we rename the
7
Let's fix them by adding more details in the code comments.
8
structure to a more generic IOThreadParamInfo.
9
8
10
Suggested-by: Kevin Wolf <kwolf@redhat.com>
9
Suggested-by: Hanna Czenczek <hreitz@redhat.com>
10
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
11
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
11
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
12
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Message-id: 20230803082825.25293-3-sgarzare@redhat.com
13
Message-id: 20210727145936.147032-2-sgarzare@redhat.com
14
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
13
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
15
---
14
---
16
iothread.c | 14 +++++++-------
15
block/blkio.c | 15 ++++++++++++---
17
1 file changed, 7 insertions(+), 7 deletions(-)
16
1 file changed, 12 insertions(+), 3 deletions(-)
18
17
19
diff --git a/iothread.c b/iothread.c
18
diff --git a/block/blkio.c b/block/blkio.c
20
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
21
--- a/iothread.c
20
--- a/block/blkio.c
22
+++ b/iothread.c
21
+++ b/block/blkio.c
23
@@ -XXX,XX +XXX,XX @@ static void iothread_complete(UserCreatable *obj, Error **errp)
22
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
24
typedef struct {
23
*/
25
const char *name;
24
fd = qemu_open(path, O_RDWR, NULL);
26
ptrdiff_t offset; /* field's byte offset in IOThread struct */
25
if (fd < 0) {
27
-} PollParamInfo;
26
+ /*
28
+} IOThreadParamInfo;
27
+ * qemu_open() can fail if the user specifies a path that is not
29
28
+ * a file or device, for example in the case of Unix Domain Socket
30
-static PollParamInfo poll_max_ns_info = {
29
+ * for the virtio-blk-vhost-user driver. In such cases let's have
31
+static IOThreadParamInfo poll_max_ns_info = {
30
+ * libblkio open the path directly.
32
"poll-max-ns", offsetof(IOThread, poll_max_ns),
31
+ */
33
};
32
fd_supported = false;
34
-static PollParamInfo poll_grow_info = {
33
} else {
35
+static IOThreadParamInfo poll_grow_info = {
34
ret = blkio_set_int(s->blkio, "fd", fd);
36
"poll-grow", offsetof(IOThread, poll_grow),
35
@@ -XXX,XX +XXX,XX @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,
37
};
36
}
38
-static PollParamInfo poll_shrink_info = {
37
39
+static IOThreadParamInfo poll_shrink_info = {
38
/*
40
"poll-shrink", offsetof(IOThread, poll_shrink),
39
- * If the libblkio driver doesn't support the `fd` property, blkio_connect()
41
};
40
- * will fail with -EINVAL. So let's try calling blkio_connect() again by
42
-static PollParamInfo aio_max_batch_info = {
41
- * directly setting `path`.
43
+static IOThreadParamInfo aio_max_batch_info = {
42
+ * Before https://gitlab.com/libblkio/libblkio/-/merge_requests/208
44
"aio-max-batch", offsetof(IOThread, aio_max_batch),
43
+ * (libblkio <= v1.3.0), setting the `fd` property is not enough to check
45
};
44
+ * whether the driver supports the `fd` property or not. In that case,
46
45
+ * blkio_connect() will fail with -EINVAL.
47
@@ -XXX,XX +XXX,XX @@ static void iothread_get_param(Object *obj, Visitor *v,
46
+ * So let's try calling blkio_connect() again by directly setting `path`
48
const char *name, void *opaque, Error **errp)
47
+ * to cover this scenario.
49
{
48
*/
50
IOThread *iothread = IOTHREAD(obj);
49
if (fd_supported && ret == -EINVAL) {
51
- PollParamInfo *info = opaque;
50
/*
52
+ IOThreadParamInfo *info = opaque;
53
int64_t *field = (void *)iothread + info->offset;
54
55
visit_type_int64(v, name, field, errp);
56
@@ -XXX,XX +XXX,XX @@ static bool iothread_set_param(Object *obj, Visitor *v,
57
const char *name, void *opaque, Error **errp)
58
{
59
IOThread *iothread = IOTHREAD(obj);
60
- PollParamInfo *info = opaque;
61
+ IOThreadParamInfo *info = opaque;
62
int64_t *field = (void *)iothread + info->offset;
63
int64_t value;
64
65
--
51
--
66
2.31.1
52
2.41.0
67
68
diff view generated by jsdifflib