On Fri, 08/11 15:28, Fam Zheng wrote: > On Thu, 08/10 08:58, Eric Blake wrote: > > On 08/10/2017 03:01 AM, Fam Zheng wrote: > > > + if (total_size) { > > > + int64_t zero_size = MIN(BDRV_SECTOR_SIZE, total_size); > > > + uint8_t *buf; > > > > Since BDRV_SECTOR_SIZE is small enough to stack-allocate, you could skip > > the malloc by doing: > > > > uint8_t buf[BDRV_SECTOR_SIZE] = ""; > > > > > + if (lseek(fd, 0, SEEK_SET) == -1) { > > > + ret = -errno; > > > + } else { > > > + buf = g_malloc0(zero_size); > > > + ret = qemu_write_full(fd, buf, zero_size); > > > > Instead of doing lseek + qemu_write_full, can we just use > > qemu_pwritev(fd, &iov, 1, 0) with an iov set up to point to the > > appropriate amount of buf? > > Neat, will update.
For stack-allocation yes, but qemu_write_full turns out to be better because of short write handling. So I'll keep it in v2. Fam