From: Nikolay Shirokovskiy Date: Thu, 7 Sep 2017 07:44:15 +0000 (+0300) Subject: iohelper: reduce zero-out in align case X-Git-Tag: v3.8.0-rc1~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=776b9ac594b6a1e4afc924826c6e9cb5474e8e27;p=thirdparty%2Flibvirt.git iohelper: reduce zero-out in align case 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. --- diff --git a/src/util/iohelper.c b/src/util/iohelper.c index 1896fd362a..fe15a92e6c 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; }