From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Deepak C Shetty <deepakcs@linux.vnet.ibm.com>,
Markus Armbruster <armbru@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v2 2/2] osdep: warn if opening a file O_DIRECT on tmpfs fails
Date: Wed, 21 Aug 2013 15:16:39 +0200 [thread overview]
Message-ID: <1377090999-18217-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1377090999-18217-1-git-send-email-stefanha@redhat.com>
Print a warning when opening a file O_DIRECT on tmpfs fails. This saves
users a lot of time trying to figure out the EINVAL error.
Daniel P. Berrange <berrange@redhat.com> suggested opening the file
without O_DIRECT as a portable way to check whether the file system
supports O_DIRECT. That gets messy when flags contains O_CREAT since
we'd create a file but return an error - or a race condition if we try
to unlink the file. It's simpler to check the file system type.
Reported-by: Deepak C Shetty <deepakcs@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
util/osdep.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/util/osdep.c b/util/osdep.c
index 685c8ae..446a1dc 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -30,6 +30,11 @@
#include <unistd.h>
#include <fcntl.h>
+#ifdef __linux__
+#include <sys/vfs.h>
+#include <linux/magic.h>
+#endif
+
/* Needed early for CONFIG_BSD etc. */
#include "config-host.h"
@@ -207,6 +212,20 @@ int qemu_open(const char *name, int flags, ...)
}
#endif
+#ifdef __linux__
+ /* It is not possible to open files O_DIRECT on tmpfs. Provide a hint that
+ * this may be the case (of course it could change in future kernel
+ * versions).
+ */
+ if (ret == -1 && errno == EINVAL && (flags & O_DIRECT)) {
+ struct statfs st;
+ if (statfs(name, &st) == 0 && st.f_type == TMPFS_MAGIC) {
+ error_report("tmpfs file systems may not support O_DIRECT");
+ }
+ errno = EINVAL; /* in case it was clobbered */
+ }
+#endif /* __linux__ */
+
return ret;
}
--
1.8.3.1
next prev parent reply other threads:[~2013-08-21 13:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-21 13:16 [Qemu-devel] [PATCH v2 0/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Stefan Hajnoczi
2013-08-21 13:16 ` [Qemu-devel] [PATCH v2 1/2] libcacard: link against qemu-error.o for error_report() Stefan Hajnoczi
2013-08-21 13:16 ` Stefan Hajnoczi [this message]
2013-08-21 14:08 ` [Qemu-devel] [PATCH v2 2/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Markus Armbruster
2013-08-21 19:48 ` Doug Goldstein
2013-08-21 15:13 ` Eric Blake
2013-08-21 19:04 ` Eric Blake
2013-08-21 14:09 ` [Qemu-devel] [PATCH v2 0/2] " 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=1377090999-18217-3-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=armbru@redhat.com \
--cc=deepakcs@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--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).