[libvirt] [PATCH 15/8] save: add more iohelper support for O_DIRECT

Eric Blake eblake at redhat.com
Sat Jul 16 02:48:18 UTC 2011


Constraining the problem makes the solution easier to think about.

* src/util/iohelper.c (runIO): Make read support easy.
---

Could be squashed into 6/8.

 src/util/iohelper.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index 82f62e1..f091d13 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -107,6 +107,13 @@ runIO(const char *path, int fd, int oflags, unsigned long long length)
         fdinname = path;
         fdout = STDOUT_FILENO;
         fdoutname = "stdout";
+        /* To make the implementation simpler, we give up on any
+         * attempt to use O_DIRECT in a non-trivial manner.  */
+        if (direct && ((end = lseek(fd, 0, SEEK_CUR)) != 0 || length)) {
+            virReportSystemError(end < 0 ? errno : EINVAL, "%s",
+                                 _("O_DIRECT read needs entire seekable file"));
+            goto cleanup;
+        }
         break;
     case O_WRONLY:
         fdin = STDIN_FILENO;
@@ -117,7 +124,7 @@ runIO(const char *path, int fd, int oflags, unsigned long long length)
          * attempt to use O_DIRECT in a non-trivial manner.  */
         if (direct && (end = lseek(fd, 0, SEEK_END)) != 0) {
             virReportSystemError(end < 0 ? errno : EINVAL, "%s",
-                                 _("O_DIRECT needs empty seekable file"));
+                                 _("O_DIRECT write needs empty seekable file"));
             goto cleanup;
         }
         break;
-- 
1.7.4.4




More information about the libvir-list mailing list