1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-13 08:58:33 +03:00

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.
This commit is contained in:
Nikolay Shirokovskiy 2017-09-07 10:44:15 +03:00 committed by Michal Privoznik
parent f830e371ef
commit 776b9ac594

View 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;
}