[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] block/blkio: close the fd when blkio_connect() fails
From: |
Stefano Garzarella |
Subject: |
[PATCH 1/2] block/blkio: close the fd when blkio_connect() fails |
Date: |
Tue, 1 Aug 2023 18:03:31 +0200 |
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 <hreitz@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
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