]> xenbits.xensource.com Git - libvirt.git/commitdiff
iohelper: reduce zero-out in align case
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Thu, 7 Sep 2017 07:44:15 +0000 (10:44 +0300)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 19 Sep 2017 09:37:24 +0000 (11:37 +0200)
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

index 1896fd362a17d8b54383867b8c1e9248613a400b..fe15a92e6cc2656903cad5b14d8f58749025c040 100644 (file)
@@ -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;
             }