Signed-off-by: Claudio Fontana <cfont...@suse.de>
---
 src/util/virfile.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index e8500704e5..770649108f 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -4776,20 +4776,14 @@ static off_t
 runIOCopy(const struct runIOParams p)
 {
     g_autofree void *base = NULL; /* Location to be freed */
-    char *buf = NULL; /* Aligned location within base */
-    size_t buflen = 1024*1024;
-    intptr_t alignMask = 64*1024 - 1;
     off_t total = 0;
+    size_t buflen = 1024*1024;
+    char *buf = virFileDirectBufferNew(&base, buflen);
 
-# if WITH_POSIX_MEMALIGN
-    if (posix_memalign(&base, alignMask + 1, buflen))
-        abort();
-    buf = base;
-# else
-    buf = g_new0(char, buflen + alignMask);
-    base = buf;
-    buf = (char *) (((intptr_t) base + alignMask) & ~alignMask);
-# endif
+    if (!buf) {
+        virReportSystemError(errno, _("Failed to allocate aligned memory in 
function %s"), __FUNCTION__);
+        return -5;
+    }
 
     while (1) {
         ssize_t got;
@@ -4801,9 +4795,7 @@ runIOCopy(const struct runIOParams p)
          * In other cases using saferead reduces number of syscalls.
          */
         if (!p.isWrite && p.isDirect) {
-            if ((got = read(p.fdin, buf, buflen)) < 0 &&
-                errno == EINTR)
-                continue;
+            got = virFileDirectRead(p.fdin, buf, buflen);
         } else {
             got = saferead(p.fdin, buf, buflen);
         }
@@ -4819,11 +4811,7 @@ runIOCopy(const struct runIOParams p)
 
         /* handle last write size align in direct case */
         if (got < buflen && p.isDirect && p.isWrite) {
-            ssize_t aligned_got = (got + alignMask) & ~alignMask;
-
-            memset(buf + got, 0, aligned_got - got);
-
-            if (safewrite(p.fdout, buf, aligned_got) < 0) {
+            if (virFileDirectWrite(p.fdout, buf, got) < 0) {
                 virReportSystemError(errno, _("Unable to write %s"), 
p.fdoutname);
                 return -3;
             }
-- 
2.26.2

Reply via email to