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

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Thu Sep 7 07:44:15 UTC 2017


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




More information about the libvir-list mailing list