On Thu, Aug 22, 2013 at 11:29:03AM +0200, Stefan Hajnoczi wrote: > Print a warning when opening a file O_DIRECT fails with EINVAL. This > saves users a lot of time trying to figure out the EINVAL error, which > is typical when attempting to open a file O_DIRECT on Linux tmpfs. > > Reported-by: Deepak C Shetty <deepa...@linux.vnet.ibm.com> > Signed-off-by: Stefan Hajnoczi <stefa...@redhat.com> > --- > util/osdep.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/util/osdep.c b/util/osdep.c > index 685c8ae..62072b4 100644 > --- a/util/osdep.c > +++ b/util/osdep.c > @@ -207,6 +207,13 @@ int qemu_open(const char *name, int flags, ...) > } > #endif > > +#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 */ > + } > +#endif /* O_DIRECT */ > + > return ret; > } > > -- > 1.8.3.1 > >
What about putting something similar in error_setg_file_open(), in util/error.c? There are other occasions when O_DIRECT causes a file open to fail (e.g. live snapshots with 'cache=none' to a tmpfs filesystem). That would give additional info then for QMP commands. Of course, it would then be necessary to also pass the open flags (or other equivalent info) to error_setg_file_open().