Skip to content

Commit

Permalink
Use relations between LVs to determine parent LV
Browse files Browse the repository at this point in the history
Thin/cache pools have internal data/metadata LVs the name of which can be
queried. Let's use this functionality to help determining the parent LV if name
matching fails.
  • Loading branch information
vpodzime committed Jun 8, 2015
1 parent 6c72c56 commit e682124
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions blivet/devicelibs/lvm.py
Expand Up @@ -126,6 +126,7 @@ def determine_parent_lv(vg_name, internal_lv, lvs):
: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
Expand All @@ -136,15 +137,31 @@ def determine_parent_lv(vg_name, internal_lv, lvs):
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)
if pool_name == internal_lv.lvname:
return lv
except blockdev.LVMError:
# doesn't have a pool
# cannot determine, just go on
pass

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

return None
2 changes: 1 addition & 1 deletion python-blivet.spec
Expand Up @@ -18,7 +18,7 @@ Source0: http://github.com/dwlehman/blivet/archive/%{realname}-%{version}.tar.gz
%define pypartedver 3.10.4
%define e2fsver 1.41.0
%define utillinuxver 2.15.1
%define libblockdevver 1.0
%define libblockdevver 1.1

BuildArch: noarch
BuildRequires: gettext
Expand Down

0 comments on commit e682124

Please sign in to comment.