osdep: warn if open(O_DIRECT) on fails with EINVAL
authorStefan Hajnoczi <stefanha@redhat.com>
Thu, 22 Aug 2013 09:29:03 +0000 (11:29 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Wed, 18 Sep 2013 13:34:51 +0000 (15:34 +0200)
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 <deepakcs@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
util/osdep.c

index 685c8ae..62072b4 100644 (file)
@@ -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;
 }