Skip to content

Commit

Permalink
Add cache support to the LVMLogicalVolumeDevice class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vpodzime committed Jun 12, 2015
1 parent 13d390d commit 7c64dff
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions blivet/devices/lvm.py
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c64dff

Please sign in to comment.