From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Stefan Hajnoczi <stefanha@redhat.com>,
Hanna Reitz <hreitz@redhat.com>,
qemu-block@nongnu.org, Richard Henderson <rth@twiddle.net>,
Stefano Garzarella <sgarzare@redhat.com>
Subject: [PULL for-8.1 1/2] block/blkio: close the fd when blkio_connect() fails
Date: Thu, 3 Aug 2023 11:55:44 -0400 [thread overview]
Message-ID: <20230803155545.2349984-2-stefanha@redhat.com> (raw)
In-Reply-To: <20230803155545.2349984-1-stefanha@redhat.com>
From: Stefano Garzarella <sgarzare@redhat.com>
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>
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
Message-id: 20230803082825.25293-2-sgarzare@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/blkio.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/block/blkio.c b/block/blkio.c
index 8e7ce42c79..baba2f0b67 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -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.
--
2.41.0
next prev parent reply other threads:[~2023-08-03 15:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 15:55 [PULL for-8.1 0/2] Block patches Stefan Hajnoczi
2023-08-03 15:55 ` Stefan Hajnoczi [this message]
2023-08-03 15:55 ` [PULL for-8.1 2/2] block/blkio: add more comments on the fd passing handling Stefan Hajnoczi
2023-08-04 1:47 ` [PULL for-8.1 0/2] Block patches Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230803155545.2349984-2-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=sgarzare@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).