Received: from eggs.gnu.org ([2001:4830:134:3::10]:47363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC95h-0000Nq-9u for qemu-devel@nongnu.org; Wed, 21 Aug 2013 10:08:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VC95a-0007Qq-OF for qemu-devel@nongnu.org; Wed, 21 Aug 2013 10:08:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC95a-0007Qa-FP for qemu-devel@nongnu.org; Wed, 21 Aug 2013 10:08:46 -0400 From: Markus Armbruster References: <1377090999-18217-1-git-send-email-stefanha@redhat.com> <1377090999-18217-3-git-send-email-stefanha@redhat.com> Date: Wed, 21 Aug 2013 16:08:42 +0200 In-Reply-To: <1377090999-18217-3-git-send-email-stefanha@redhat.com> (Stefan Hajnoczi's message of "Wed, 21 Aug 2013 15:16:39 +0200") Message-ID: <87siy3xhjp.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 2/2] osdep: warn if opening a file O_DIRECT on tmpfs fails List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Kevin Wolf , Deepak C Shetty , qemu-devel@nongnu.org Stefan Hajnoczi writes: > Print a warning when opening a file O_DIRECT on tmpfs fails. This saves Only when it fails with EINVAL, actually. Suggest "on tmpfs fails with EINVAL." > users a lot of time trying to figure out the EINVAL error. > > Daniel P. Berrange 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 > Signed-off-by: Stefan Hajnoczi > --- > 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 > #include > > +#ifdef __linux__ > +#include > +#include > +#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; > } In theory, the warning could be misleading, because we can get EINVAL for reasons not related to flags & O_DIRECT. In practice, the warning probably does much more good than harm.