[master 12/12] Add cache support to the LVMLogicalVolumeDevice class

vpodzime installerbot-noreply at redhat.com
Fri Jun 12 13:58:12 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

This way LVMLogicalVolumeDevice can report whether they are cached, provide
information related to their cache and attach cache pool to themselves so that
they become cached.
---
 blivet/devices/lvm.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
index 282b831..c2cd85f 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -532,6 +532,7 @@ def __init__(self, name, parents=None, size=None, uuid=None, segType=None,
 
         self._metaDataSize = Size(0)
         self._internal_lvs = []
+        self._cache = None
 
     def _check_parents(self):
         """Check that this device has parents as expected"""
@@ -854,6 +855,28 @@ def removeInternalLV(self, int_lv):
                                                                                        self.name)
             raise ValueError(msg)
 
+    @property
+    def cached(self):
+        return bool(self.cache)
+
+    @property
+    def cache(self):
+        if self.exists and not self._cache:
+            # check if we have a cache pool internal LV
+            pool = None
+            for lv in self._internal_lvs:
+                if isinstance(lv, LVMCachePoolLogicalVolumeDevice):
+                    pool = lv
+
+            self._cache = LVMCache(self, size=pool.size, exists=True)
+
+        return self._cache
+
+    def attach_cache(self, cache_pool_lv):
+        blockdev.lvm.cache_attach(self.vg.name, self.lvname, cache_pool_lv.lvname)
+        self._cache = LVMCache(self, size=cache_pool_lv.size, exists=True)
+
+
 @add_metaclass(abc.ABCMeta)
 class LVMInternalLogicalVolumeDevice(LVMLogicalVolumeDevice):
     """Abstract base class for internal LVs


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


More information about the anaconda-patches mailing list