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

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

 



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@xxxxxxxxxx>
---
 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)
+        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:
-- 
2.13.6

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux