[virt-tools-list] [virt-manager PATCH 2/2] diskbackend: get a proper size of existing block device while cloning

Pavel Hrdina phrdina at redhat.com
Thu Oct 19 07:31:49 UTC 2017


On Wed, Oct 18, 2017 at 05:22:08PM -0400, Cole Robinson wrote:
> On 10/03/2017 11:09 AM, Pavel Hrdina wrote:
> > We cannot use os.statvfs() if the clone disk is a block device because
> > it gets stats about filesystem which in this case is "devtmpfs" mounted
> > as "/dev".
> > 
> > As a workaround we can seek to the end of the block device to get
> > the actual size.
> > 
> > Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1450908
> > 
> > Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> > ---
> >  virtinst/diskbackend.py | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> > 
> > diff --git a/virtinst/diskbackend.py b/virtinst/diskbackend.py
> > index de745f4d..c63a621f 100644
> > --- a/virtinst/diskbackend.py
> > +++ b/virtinst/diskbackend.py
> > @@ -387,8 +387,13 @@ class CloneStorageCreator(_StorageCreator):
> >      def is_size_conflict(self):
> >          ret = False
> >          msg = None
> > -        vfs = os.statvfs(os.path.dirname(self._path))
> > -        avail = vfs[statvfs.F_FRSIZE] * vfs[statvfs.F_BAVAIL]
> > +        if self.get_dev_type() == "block":
> > +            fd = os.open(self._path, os.O_RDONLY)
> > +            avail = os.lseek(fd, 0, os.SEEK_END)
> > +            os.close(fd)
> 
> This idiom is already tracked in the _stat_disk helper, can we reuse that?

Definitely, for some reason I missed that.  Thanks for review, I've
pushed it with this fixed.

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20171019/2711e014/attachment.sig>


More information about the virt-tools-list mailing list