From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
qemu-block@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"P J P" <ppandit@redhat.com>, "Max Reitz" <mreitz@redhat.com>
Subject: [PATCH v2 1/3] util: validate whether O_DIRECT is supported after failure
Date: Thu, 2 Jul 2020 13:56:10 +0100 [thread overview]
Message-ID: <20200702125612.2176194-2-berrange@redhat.com> (raw)
In-Reply-To: <20200702125612.2176194-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 | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/util/osdep.c b/util/osdep.c
index 4829c07ff6..e2b7507ee2 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -332,9 +332,11 @@ int qemu_open(const char *name, int flags, ...)
}
#ifdef O_CLOEXEC
- ret = open(name, flags | O_CLOEXEC, mode);
-#else
+ flags |= O_CLOEXEC;
+#endif
ret = open(name, flags, mode);
+
+#ifndef O_CLOEXEC
if (ret >= 0) {
qemu_set_cloexec(ret);
}
@@ -342,8 +344,13 @@ 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;
+ ret = open(name, newflags, mode);
+ 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-02 12:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-02 12:56 [PATCH v2 0/3] block: improve error reporting for unsupported O_DIRECT Daniel P. Berrangé
2020-07-02 12:56 ` Daniel P. Berrangé [this message]
2020-07-02 15:29 ` [PATCH v2 1/3] util: validate whether O_DIRECT is supported after failure Philippe Mathieu-Daudé
2020-07-08 6:45 ` Markus Armbruster
2020-07-02 12:56 ` [PATCH v2 2/3] util: support detailed error reporting for qemu_open Daniel P. Berrangé
2020-07-08 6:55 ` Markus Armbruster
2020-07-02 12:56 ` [PATCH v2 3/3] block: switch to use qemu_open_err for improved errors Daniel P. Berrangé
2020-07-08 6:57 ` Markus Armbruster
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=20200702125612.2176194-2-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=f4bug@amsat.org \
--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).