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

Cole Robinson crobinso at redhat.com
Wed Oct 18 21:22:08 UTC 2017


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?

- Cole

> +        else:
> +            vfs = os.statvfs(os.path.dirname(self._path))
> +            avail = vfs[statvfs.F_FRSIZE] * vfs[statvfs.F_BAVAIL]
>          need = long(self._size * 1024 * 1024 * 1024)
>          if need > avail:
>              if self._sparse:
> 




More information about the virt-tools-list mailing list