Skip to content

Commit

Permalink
Merge pull request #149 from vpodzime/master-lvm_cache
Browse files Browse the repository at this point in the history
Make blivet aware of internal LVs
  • Loading branch information
vpodzime committed Jun 18, 2015
2 parents 5d78a39 + 86748b3 commit 7afac66
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 129 deletions.
5 changes: 2 additions & 3 deletions blivet/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,8 @@ def lvs(self):
does not necessarily reflect the actual on-disk state of the
system's disks.
"""
lvs = self.devicetree.getDevicesByType("lvmlv")
lvs.sort(key=lambda d: d.name)
return lvs
lvs = (d for d in self.devices if d.type in ("lvmlv", "lvmthinpool", "lvmthinlv"))
return sorted(lvs, key=lambda d: d.name)

@property
def thinlvs(self):
Expand Down
53 changes: 53 additions & 0 deletions blivet/devicelibs/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# Author(s): Dave Lehman <dlehman@redhat.com>
#

import re

from collections import namedtuple
from gi.repository import BlockDev as blockdev

Expand Down Expand Up @@ -115,3 +117,54 @@ def lvm_cc_removeFilterRejectRegexp(regexp):
def lvm_cc_resetFilter():
config_args_data["filterRejects"] = []
config_args_data["filterAccepts"] = []

def determine_parent_lv(vg_name, internal_lv, lvs):
"""Try to determine which of the lvs is the parent of the internal_lv
:param str vg_name: name of the VG the internal_lv and lvs belong to
:type internal_lv: :class:`~.devices.lvm.LMVInternalLogicalVolumeDevice`
:type lvs: :class:`~.devices.lvm.LMVLogicalVolumeDevice`
"""
# try name matching first (fast, cheap, often works)
for lv in lvs:
if internal_lv.lvname == lv.lvname:
# skip the internal_lv itself
continue

# check if the lv's name is the name of the internal LV without the suffix
# e.g. 'pool' and 'pool_tmeta'
if re.match(lv.lvname+internal_lv.name_suffix+"$", internal_lv.lvname):
return lv

# now try checking relations between LVs
for lv in lvs:
# cache pools are internal LVs of cached LVs
try:
pool_name = blockdev.lvm.cache_pool_name(vg_name, lv.lvname)
except blockdev.LVMError:
# cannot determine, just go on
pass
else:
if pool_name == internal_lv.lvname:
return lv

# pools have internal data and metadata LVs
try:
data_lv_name = blockdev.lvm.data_lv_name(vg_name, lv.lvname)
except blockdev.LVMError:
# cannot determine, just go on
pass
else:
if data_lv_name == internal_lv.lvname:
return lv
try:
metadata_lv_name = blockdev.lvm.metadata_lv_name(vg_name, lv.lvname)
except blockdev.LVMError:
# cannot determine, just go on
pass
else:
if metadata_lv_name == internal_lv.lvname:
return lv

return None

0 comments on commit 7afac66

Please sign in to comment.