From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "P J P" <ppandit@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
qemu-block@nongnu.org, "Max Reitz" <mreitz@redhat.com>
Subject: [PATCH 1/3] util: validate whether O_DIRECT is supported after failure
Date: Wed, 1 Jul 2020 17:05:07 +0100 [thread overview]
Message-ID: <20200701160509.1523847-2-berrange@redhat.com> (raw)
In-Reply-To: <20200701160509.1523847-1-berrange@redhat.com>
Currently we suggest that a filesystem may not support O_DIRECT after
seeing an EINVAL. Other things can cause EINVAL though, so it is better
to do an explicit check, and then report a definitive error message.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
util/osdep.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/util/osdep.c b/util/osdep.c
index 4829c07ff6..4bdbe81cec 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -342,8 +342,17 @@ int qemu_open(const char *name, int flags, ...)
#ifdef O_DIRECT
if (ret == -1 && errno == EINVAL && (flags & O_DIRECT)) {
- error_report("file system may not support O_DIRECT");
- errno = EINVAL; /* in case it was clobbered */
+ int newflags = flags & ~O_DIRECT;
+# ifdef O_CLOEXEC
+ ret = open(name, newflags | O_CLOEXEC, mode);
+# else
+ ret = open(name, newflags, mode);
+# endif
+ if (ret != -1) {
+ close(ret);
+ error_report("file system does not support O_DIRECT");
+ errno = EINVAL;
+ }
}
#endif /* O_DIRECT */
--
2.26.2
next prev parent reply other threads:[~2020-07-01 16:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-01 16:05 [PATCH 0/3] block: improve error reporting for unsupported O_DIRECT Daniel P. Berrangé
2020-07-01 16:05 ` Daniel P. Berrangé [this message]
2020-07-02 10:10 ` [PATCH 1/3] util: validate whether O_DIRECT is supported after failure Philippe Mathieu-Daudé
2020-07-01 16:05 ` [PATCH 2/3] util: support detailed error reporting for qemu_open Daniel P. Berrangé
2020-07-02 5:13 ` Markus Armbruster
2020-07-02 9:30 ` Daniel P. Berrangé
2020-07-01 16:05 ` [PATCH 3/3] block: switch to use qemu_open_err for improved errors Daniel P. Berrangé
2020-07-01 16:58 ` [PATCH 0/3] block: improve error reporting for unsupported O_DIRECT no-reply
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=20200701160509.1523847-2-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=ppandit@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).