[master 1/1] Use COW device to get actual size of LVM snapshots

vojtechtrefny installerbot-noreply at redhat.com
Wed May 13 10:38:46 UTC 2015


From: Vojtech Trefny <vtrefny at redhat.com>

Override readCurrentSize of LVM old-style snapshots to check size
on COW device instead of snapshot device. (The latter one reports
snapshot to be same size as the LV.)

Signed-off-by: Vojtech Trefny <vtrefny at redhat.com>
---
 blivet/devices/lvm.py | 16 ++++++++++++++++
 blivet/util.py        | 12 ++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
index d7526e4..4d54a61 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -24,6 +24,7 @@
 import abc
 import pprint
 import re
+import os
 from gi.repository import BlockDev as blockdev
 
 # device backend modules
@@ -39,6 +40,7 @@
 import logging
 log = logging.getLogger("blivet")
 
+from .lib import LINUX_SECTOR_SIZE
 from .device import Device
 from .storage import StorageDevice
 from .container import ContainerDevice
@@ -966,6 +968,20 @@ def dependsOn(self, dep):
         return (self.origin == dep or
                 super(LVMSnapShotBase, self).dependsOn(dep))
 
+    def readCurrentSize(self):
+        log_method_call(self, exists=self.exists, path=self.path,
+                        sysfsPath=self.sysfsPath)
+        size = Size(0)
+        if self.exists and os.path.exists(self.path) and \
+           os.path.isdir(self.sysfsPath):
+            cowSysfsPath = util.get_cow_sysfs_path(self.path, self.sysfsPath)
+
+            if os.path.exists(cowSysfsPath) and os.path.isdir(cowSysfsPath):
+                blocks = int(util.get_sysfs_attr(cowSysfsPath, "size"))
+                size = Size(blocks * LINUX_SECTOR_SIZE)
+
+        return size
+
 class LVMThinPoolDevice(LVMLogicalVolumeDevice):
     """ An LVM Thin Pool """
     _type = "lvmthinpool"
diff --git a/blivet/util.py b/blivet/util.py
index cedc83a..ea5750f 100644
--- a/blivet/util.py
+++ b/blivet/util.py
@@ -226,6 +226,18 @@ def get_sysfs_path_by_name(dev_node, class_name="block"):
         raise RuntimeError("get_sysfs_path_by_name: Could not find sysfs path "
                            "for '%s' (it is not at '%s')" % (dev_node, dev_path))
 
+def get_cow_sysfs_path(dev_path, dev_sysfsPath):
+    """ Return sysfs path of cow device for a given lvm snapshot.
+    """
+
+    cow_path = dev_path + "-cow"
+    if not os.path.islink(cow_path):
+        raise RuntimeError("get_cow_sysfs_path: Could not find cow device for" %
+                            (dev_path))
+
+    dm_name = os.path.basename(os.path.realpath(cow_path))
+    return os.path.join(os.path.split(dev_sysfsPath)[0], dm_name)
+
 ##
 ## SELinux functions
 ##


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/73c08553ae53a8024a87d97b1056479675b5748d


More information about the anaconda-patches mailing list