osdep: warn if opening a file O_DIRECT on tmpfs fails
cover osdep: warn if opening a file O_DIRECT on tmpfs fails
Deepak C Shetty <[email protected]> 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
Signature · 1 line
1.8.3.1
PATCH 1/2 stubs: add error_report()
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.
--- stubs/Makefile.objs | 1 + stubs/error-report.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 stubs/error-report.c
stubs/Makefile.objs +1 -0
@@ -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
stubs/error-report.c new file +12 -0
@@ -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" ); +}
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 1/2] stubs: add error_report()
Quoted 34 lines · 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 <[email protected]>--- stubs/Makefile.objs | 1 + stubs/error-report.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 stubs/error-report.cstubs/Makefile.objs +1
-0@@ -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.ostubs/error-report.c new file +2
-0@@ -0,0 +1,12 @@ +#include <stdio.h> +#include "qemu/error-report.h"
stubs/error-report.c line 12
Quoted 10 lines
stubs/error-report.c new file +10
-0+ +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?
Re: [Qemu-devel] [PATCH 1/2] stubs: add error_report()
Quoted 42 lines · Markus Armbruster
Quoted 40 lines · 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 <[email protected]>--- stubs/Makefile.objs | 1 + stubs/error-report.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 stubs/error-report.cstubs/Makefile.objs +1
-0@@ -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.ostubs/error-report.c new file +8
-0@@ -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);
Quoted 8 lines
stubs/error-report.c line 12
Quoted 4 lines
stubs/error-report.c new file +4
-0+vfprintf (stderr, fmt, ap); +va_end (ap); +fprintf (stderr,"\n" ); +}We already have a monitor stubs (
mon-set-error.cmon-printf.c...) so we can useerror_report()in utility programs. Why doesn't that suffice here?
Good idea. I'll resend with util/qemu-error.o linked in.
Stefan
PATCH 2/2 osdep: warn if opening a file O_DIRECT on tmpfs fails
In reply to Stefan HajnocziPrint 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 <[email protected]> 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.
--- util/osdep.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
util/osdep.c +19 -0
@@ -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; }
Signature · 1 line
1.8.3.1