diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py index 282b8315c..c2cd85f52 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