libblkio drivers take ownership of `fd` only after a successful
blkio_connect(), so if it fails, we are still the owners.
Fixes: cad2ccc395 ("block/blkio: use qemu_open() to support fd passing for
virtio-blk")
Suggested-by: Hanna Czenczek <[email protected]>
Signed-off-by: Stefano Garzarella <[email protected]>
---
block/blkio.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/block/blkio.c b/block/blkio.c
index 8e7ce42c79..2d53a865e7 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -739,6 +739,7 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs,
QDict *options,
* directly setting `path`.
*/
if (fd_supported && ret == -EINVAL) {
+ fd_supported = false;
qemu_close(fd);
/*
@@ -763,6 +764,14 @@ static int blkio_virtio_blk_connect(BlockDriverState *bs,
QDict *options,
}
if (ret < 0) {
+ if (fd_supported) {
+ /*
+ * libblkio drivers take ownership of `fd` only after a successful
+ * blkio_connect(), so if it fails, we are still the owners.
+ */
+ qemu_close(fd);
+ }
+
error_setg_errno(errp, -ret, "blkio_connect failed: %s",
blkio_get_error_msg());
return ret;
--
2.41.0