qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10?] file-posix: Clear out fi


From: Fam Zheng
Subject: Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10?] file-posix: Clear out first sector in hdev_create
Date: Fri, 11 Aug 2017 15:44:35 +0800
User-agent: Mutt/1.8.3 (2017-05-23)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]