[PATCH 3/4] iohelper: reduce zero-out in align case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We only need to zero-out bytes that will be written.
May be we even don't need to zero-out at all because
of immediate truncate.
---
 src/util/iohelper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index 1896fd3..fe15a92 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -120,10 +120,11 @@ runIO(const char *path, int fd, int oflags)
 
         /* handle last write size align in direct case */
         if (got < buflen && direct && fdout == fd) {
-            memset(buf + got, 0, buflen - got);
-            got = (got + alignMask) & ~alignMask;
+            ssize_t aligned_got = (got + alignMask) & ~alignMask;
 
-            if (safewrite(fdout, buf, got) < 0) {
+            memset(buf + got, 0, aligned_got - got);
+
+            if (safewrite(fdout, buf, aligned_got) < 0) {
                 virReportSystemError(errno, _("Unable to write %s"), fdoutname);
                 goto cleanup;
             }
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux