qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH for-2.11 v2] file-posix: Clear out first sector


From: Fam Zheng
Subject: Re: [Qemu-devel] [PATCH for-2.11 v2] file-posix: Clear out first sector in hdev_create
Date: Fri, 8 Sep 2017 17:44:08 +0800
User-agent: Mutt/1.8.3 (2017-05-23)

On Thu, 09/07 17:07, Kevin Wolf wrote:
> > diff --git a/block/file-posix.c b/block/file-posix.c
> > index f4de022ae0..a63bbf2b90 100644
> > --- a/block/file-posix.c
> > +++ b/block/file-posix.c
> > @@ -2703,6 +2703,16 @@ static int hdev_create(const char *filename, 
> > QemuOpts *opts,
> >          ret = -ENOSPC;
> >      }
> 
> So the error paths above only set ret, but don't actually return or jump
> to the end of the function.
> 
> > +    if (total_size) {
> > +        uint8_t buf[BDRV_SECTOR_SIZE] = { 0 };
> > +        int64_t zero_size = MIN(BDRV_SECTOR_SIZE, total_size);
> > +        if (lseek(fd, 0, SEEK_SET) == -1) {
> > +            ret = -errno;
> > +        } else {
> > +            ret = qemu_write_full(fd, buf, zero_size);
> > +            ret = ret == zero_size ? 0 : -errno;
> 
> Which means that an error above (like a too small block device or using
> a regular file) can be overwritten with a success value if clearing the
> first sector works. That's probably not quite right.

You're right, will fix.

Fam



reply via email to

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