Block patches
The following changes since commit 9ba37026fcf6b7f3f096c0cca3e1e7307802486b:
Update version for v8.1.0-rc2 release (2023-08-02 08:22:45 -0700)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to 9b06d0d076271d76e5384d767ef94a676f0a9efd:
block/blkio: add more comments on the fd passing handling (2023-08-03 11:28:43 -0400)
----------------------------------------------------------------
Pull request
Fix for an fd leak in the blkio block driver.
----------------------------------------------------------------
Stefano Garzarella (2):
block/blkio: close the fd when blkio_connect() fails block/blkio: add more comments on the fd passing handling
block/blkio.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
Signature · 1 line
2.41.0
[PULL for-8.1 2/2] block/blkio: add more comments on the fd passing handling
From: Stefano Garzarella <[email protected]>
As Hanna pointed out, it is not clear in the code why qemu_open() can fail, and why blkio_set_int("fd") is not enough to discover the fd property support.
Let's fix them by adding more details in the code comments.
Message-id: [email protected]
--- block/blkio.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
block/blkio.c +12 -3
@@ -713,6 +713,12 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,*/ fd =qemu_open (path,O_RDWR ,NULL );if (fd <0 ) { +/* +* qemu_open() can fail if the user specifies a path that is not +* a file or device, for example in the case of Unix Domain Socket +* for the virtio-blk-vhost-user driver. In such cases let's have +* libblkio open the path directly. +*/ fd_supported = false; }else { ret =blkio_set_int (s->blkio,"fd" , fd);
@@ -741,9 +747,12 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, }/* -* If the libblkio driver doesn't support the `fd` property, blkio_connect() -* will fail with -EINVAL. So let's try calling blkio_connect() again by -* directly setting `path`. +* Before https://gitlab.com/libblkio/libblkio/-/merge_requests/208 +* (libblkio <= v1.3.0), setting the `fd` property is not enough to check +* whether the driver supports the `fd` property or not. In that case, +* blkio_connect() will fail with -EINVAL. +* So let's try calling blkio_connect() again by directly setting `path` +* to cover this scenario. */ if (fd_supported && ret == -EINVAL ) {/*
Signature · 1 line
2.41.0
[PULL for-8.1 1/2] block/blkio: close the fd when blkio_connect() fails
In reply to Stefan HajnocziFrom: Stefano Garzarella <[email protected]>
libblkio drivers take ownership of fd only after a successful blkio_connect(), so if it fails, we are still the owners.
Message-id: [email protected]
--- block/blkio.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
block/blkio.c +8 -3
@@ -678,7 +678,7 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,const char *path =qdict_get_try_str (options,"path" );BDRVBlkioState *s = bs->opaque;bool fd_supported = false; -int fd, ret; +int fd =-1 , ret;if (!path) {error_setg (errp,"missing 'path' option" );
@@ -719,6 +719,7 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options,if (ret <0 ) { fd_supported = false;qemu_close (fd); + fd =-1 ; } } }
@@ -733,14 +734,18 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs, QDict *options, } ret =blkio_connect (s->blkio); +if (ret <0 && fd >=0 ) { +/* Failed to give the FD to libblkio, close it */ +qemu_close (fd); + fd =-1 ; + } +/* * If the libblkio driver doesn't support the `fd` property, blkio_connect() * will fail with -EINVAL. So let's try calling blkio_connect() again by * directly setting `path`. */ if (fd_supported && ret == -EINVAL ) { -qemu_close (fd); -/* * We need to clear the `fd` property we set previously by setting * it to -1.
Signature · 1 line
2.41.0
Richard Henderson
AppliedQuoted 8 lines · Stefan Hajnoczi
The following changes since commit
9ba37026fcf6b7f3f096c0cca3e1e7307802486b:Update version for v8.1.0-rc2 release (2023-08-02 08:22:45 -0700)are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
Quoted 8 lines
for you to fetch changes up to
9b06d0d076271d76e5384d767ef94a676f0a9efd:block/blkio: add more comments on the fd passing handling (2023-08-03 11:28:43 -0400)
----------------------------------------------------------------
Pull requestFix for an fd leak in the blkio block driver.
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.
r~