qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] osdep: warn if opening a file O_DIRECT on tmpfs fails
@ 2013-08-21 12:26 Stefan Hajnoczi
  2013-08-21 12:26 ` [Qemu-devel] [PATCH 1/2] stubs: add error_report() Stefan Hajnoczi
  2013-08-21 12:26 ` [Qemu-devel] [PATCH 2/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Stefan Hajnoczi
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-08-21 12:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Deepak C Shetty, Stefan Hajnoczi

Deepak C Shetty <deepakcs@linux.vnet.ibm.com> tried to open an image file
O_DIRECT on tmpfs and received EINVAL.  This error is too generic, making it
hard to figure out that the problem is -drive ...,cache=none on tmpfs.

Add a warning when opening a file O_DIRECT on tmpfs fails.

Stefan Hajnoczi (2):
  stubs: add error_report()
  osdep: warn if opening a file O_DIRECT on tmpfs fails

 stubs/Makefile.objs  |  1 +
 stubs/error-report.c | 12 ++++++++++++
 util/osdep.c         | 19 +++++++++++++++++++
 3 files changed, 32 insertions(+)
 create mode 100644 stubs/error-report.c

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/2] stubs: add error_report()
  2013-08-21 12:26 [Qemu-devel] [PATCH 0/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Stefan Hajnoczi
@ 2013-08-21 12:26 ` Stefan Hajnoczi
  2013-08-21 13:04   ` Markus Armbruster
  2013-08-21 12:26 ` [Qemu-devel] [PATCH 2/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Stefan Hajnoczi
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-08-21 12:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Deepak C Shetty, Stefan Hajnoczi

The error report function is preferred over fprintf(stderr, ...) since
it prints to the current monitor, if any.

Add a stub error_report() implementation that just prints to stderr.
This is suitable in environments where there is no QEMU monitor, such as
libcacard.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 stubs/Makefile.objs  |  1 +
 stubs/error-report.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 stubs/error-report.c

diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index f306cba..f84d597 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -3,6 +3,7 @@ stub-obj-y += clock-warp.o
 stub-obj-y += cpu-get-clock.o
 stub-obj-y += cpu-get-icount.o
 stub-obj-y += dump.o
+stub-obj-y += error-report.o
 stub-obj-y += fdset-add-fd.o
 stub-obj-y += fdset-find-fd.o
 stub-obj-y += fdset-get-fd.o
diff --git a/stubs/error-report.c b/stubs/error-report.c
new file mode 100644
index 0000000..e39d0a9
--- /dev/null
+++ b/stubs/error-report.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include "qemu/error-report.h"
+
+void error_report(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    fprintf(stderr, "\n");
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/2] osdep: warn if opening a file O_DIRECT on tmpfs fails
  2013-08-21 12:26 [Qemu-devel] [PATCH 0/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Stefan Hajnoczi
  2013-08-21 12:26 ` [Qemu-devel] [PATCH 1/2] stubs: add error_report() Stefan Hajnoczi
@ 2013-08-21 12:26 ` Stefan Hajnoczi
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-08-21 12:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Deepak C Shetty, Stefan Hajnoczi

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] stubs: add error_report()
  2013-08-21 12:26 ` [Qemu-devel] [PATCH 1/2] stubs: add error_report() Stefan Hajnoczi
@ 2013-08-21 13:04   ` Markus Armbruster
  2013-08-21 13:15     ` Stefan Hajnoczi
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2013-08-21 13:04 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, Deepak C Shetty, qemu-devel

Stefan Hajnoczi <stefanha@redhat.com> writes:

> The error report function is preferred over fprintf(stderr, ...) since
> it prints to the current monitor, if any.
>
> Add a stub error_report() implementation that just prints to stderr.
> This is suitable in environments where there is no QEMU monitor, such as
> libcacard.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  stubs/Makefile.objs  |  1 +
>  stubs/error-report.c | 12 ++++++++++++
>  2 files changed, 13 insertions(+)
>  create mode 100644 stubs/error-report.c
>
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index f306cba..f84d597 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -3,6 +3,7 @@ stub-obj-y += clock-warp.o
>  stub-obj-y += cpu-get-clock.o
>  stub-obj-y += cpu-get-icount.o
>  stub-obj-y += dump.o
> +stub-obj-y += error-report.o
>  stub-obj-y += fdset-add-fd.o
>  stub-obj-y += fdset-find-fd.o
>  stub-obj-y += fdset-get-fd.o
> diff --git a/stubs/error-report.c b/stubs/error-report.c
> new file mode 100644
> index 0000000..e39d0a9
> --- /dev/null
> +++ b/stubs/error-report.c
> @@ -0,0 +1,12 @@
> +#include <stdio.h>
> +#include "qemu/error-report.h"
> +
> +void error_report(const char *fmt, ...)
> +{
> +    va_list ap;
> +
> +    va_start(ap, fmt);
> +    vfprintf(stderr, fmt, ap);
> +    va_end(ap);
> +    fprintf(stderr, "\n");
> +}

We already have a monitor stubs (mon-set-error.c mon-printf.c ...) so we
can use error_report() in utility programs.  Why doesn't that suffice
here?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] stubs: add error_report()
  2013-08-21 13:04   ` Markus Armbruster
@ 2013-08-21 13:15     ` Stefan Hajnoczi
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-08-21 13:15 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, Deepak C Shetty, qemu-devel, Stefan Hajnoczi

On Wed, Aug 21, 2013 at 03:04:02PM +0200, Markus Armbruster wrote:
> Stefan Hajnoczi <stefanha@redhat.com> writes:
> 
> > The error report function is preferred over fprintf(stderr, ...) since
> > it prints to the current monitor, if any.
> >
> > Add a stub error_report() implementation that just prints to stderr.
> > This is suitable in environments where there is no QEMU monitor, such as
> > libcacard.
> >
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> >  stubs/Makefile.objs  |  1 +
> >  stubs/error-report.c | 12 ++++++++++++
> >  2 files changed, 13 insertions(+)
> >  create mode 100644 stubs/error-report.c
> >
> > diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> > index f306cba..f84d597 100644
> > --- a/stubs/Makefile.objs
> > +++ b/stubs/Makefile.objs
> > @@ -3,6 +3,7 @@ stub-obj-y += clock-warp.o
> >  stub-obj-y += cpu-get-clock.o
> >  stub-obj-y += cpu-get-icount.o
> >  stub-obj-y += dump.o
> > +stub-obj-y += error-report.o
> >  stub-obj-y += fdset-add-fd.o
> >  stub-obj-y += fdset-find-fd.o
> >  stub-obj-y += fdset-get-fd.o
> > diff --git a/stubs/error-report.c b/stubs/error-report.c
> > new file mode 100644
> > index 0000000..e39d0a9
> > --- /dev/null
> > +++ b/stubs/error-report.c
> > @@ -0,0 +1,12 @@
> > +#include <stdio.h>
> > +#include "qemu/error-report.h"
> > +
> > +void error_report(const char *fmt, ...)
> > +{
> > +    va_list ap;
> > +
> > +    va_start(ap, fmt);
> > +    vfprintf(stderr, fmt, ap);
> > +    va_end(ap);
> > +    fprintf(stderr, "\n");
> > +}
> 
> We already have a monitor stubs (mon-set-error.c mon-printf.c ...) so we
> can use error_report() in utility programs.  Why doesn't that suffice
> here?

Good idea.  I'll resend with util/qemu-error.o linked in.

Stefan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-08-21 13:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-21 12:26 [Qemu-devel] [PATCH 0/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Stefan Hajnoczi
2013-08-21 12:26 ` [Qemu-devel] [PATCH 1/2] stubs: add error_report() Stefan Hajnoczi
2013-08-21 13:04   ` Markus Armbruster
2013-08-21 13:15     ` Stefan Hajnoczi
2013-08-21 12:26 ` [Qemu-devel] [PATCH 2/2] osdep: warn if opening a file O_DIRECT on tmpfs fails Stefan Hajnoczi

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).