From: Vratislav Podzimek <vpodzime(a)redhat.com>
All LVs are now instances of a single class. The type is determined by the
properties of the object like its segment type, whether it has a parent LV
(internal LVs) or an origin (snapshots). Thus we need to make sure the right
values are passed in all the places we create LV objects.
---
blivet/blivet.py | 16 +++++++---------
blivet/devicefactory.py | 4 ++--
blivet/devices/__init__.py | 2 +-
blivet/devices/lvm.py | 1 +
blivet/partitioning.py | 2 +-
blivet/populator/helpers/lvm.py | 32 +++++++++++++-------------------
6 files changed, 25 insertions(+), 32 deletions(-)
diff --git a/blivet/blivet.py b/blivet/blivet.py
index 19ff1b3..3ab3bf3 100644
--- a/blivet/blivet.py
+++ b/blivet/blivet.py
@@ -32,7 +32,7 @@
from .storage_log import log_method_call, log_exception_info
from .devices import BTRFSDevice, BTRFSSubVolumeDevice, BTRFSVolumeDevice
-from .devices import LVMLogicalVolumeDevice, LVMThinLogicalVolumeDevice,
LVMThinPoolDevice, LVMVolumeGroupDevice
+from .devices import LVMLogicalVolumeDevice, LVMVolumeGroupDevice
from .devices import MDRaidArrayDevice, PartitionDevice, TmpFSDevice,
device_path_to_name
from .deviceaction import ActionCreateDevice, ActionCreateFormat, ActionDestroyDevice
from .deviceaction import ActionDestroyFormat, ActionResizeDevice, ActionResizeFormat
@@ -916,6 +916,11 @@ def new_lv(self, *args, **kwargs):
else:
vg = parent
+ if thin_volume:
+ kwargs["seg_type"] = "thin"
+ if thin_pool:
+ kwargs["seg_type"] = "thin-pool"
+
mountpoint = kwargs.pop("mountpoint", None)
if 'fmt_type' in kwargs:
kwargs["fmt"] = get_format(kwargs.pop("fmt_type"),
@@ -956,14 +961,7 @@ def new_lv(self, *args, **kwargs):
if cache_req:
raise ValueError("Creating cached thin volumes and pools is not
supported")
- if thin_pool:
- device_class = LVMThinPoolDevice
- elif thin_volume:
- device_class = LVMThinLogicalVolumeDevice
- else:
- device_class = LVMLogicalVolumeDevice
-
- return device_class(name, *args, **kwargs)
+ return LVMLogicalVolumeDevice(name, *args, **kwargs)
def new_btrfs(self, *args, **kwargs):
""" Return a new BTRFSVolumeDevice or BRFSSubVolumeDevice.
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
index 1fbfb01..771329d 100644
--- a/blivet/devicefactory.py
+++ b/blivet/devicefactory.py
@@ -23,7 +23,7 @@
from .storage_log import log_method_call
from .errors import DeviceFactoryError, StorageError
from .devices import BTRFSDevice, DiskDevice
-from .devices import LUKSDevice, LVMLogicalVolumeDevice, LVMThinPoolDevice
+from .devices import LUKSDevice, LVMLogicalVolumeDevice
from .devices import PartitionDevice, MDRaidArrayDevice
from .formats import get_format
from .devicelibs import btrfs
@@ -70,7 +70,7 @@ def is_supported_device_type(device_type):
elif device_type == DEVICE_TYPE_DISK:
devices = [DiskDevice]
elif device_type in (DEVICE_TYPE_LVM, DEVICE_TYPE_LVM_THINP):
- devices = [LVMLogicalVolumeDevice, LVMThinPoolDevice]
+ devices = [LVMLogicalVolumeDevice]
elif device_type == DEVICE_TYPE_PARTITION:
devices = [PartitionDevice]
elif device_type == DEVICE_TYPE_MD:
diff --git a/blivet/devices/__init__.py b/blivet/devices/__init__.py
index 4f697ca..0b75b78 100644
--- a/blivet/devices/__init__.py
+++ b/blivet/devices/__init__.py
@@ -26,7 +26,7 @@
from .partition import PartitionDevice
from .dm import DMDevice, DMLinearDevice, DMCryptDevice
from .luks import LUKSDevice
-from .lvm import LVMVolumeGroupDevice, LVMLogicalVolumeDevice, LVMSnapShotDevice,
LVMThinPoolDevice, LVMThinLogicalVolumeDevice, LVMThinSnapShotDevice
+from .lvm import LVMVolumeGroupDevice, LVMLogicalVolumeDevice
from .md import MDBiosRaidArrayDevice, MDContainerDevice, MDRaidArrayDevice
from .btrfs import BTRFSDevice, BTRFSVolumeDevice, BTRFSSubVolumeDevice,
BTRFSSnapShotDevice
from .file import FileDevice, DirectoryDevice, SparseFileDevice
diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
index 7d6b329..556375e 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -995,6 +995,7 @@ def parent_lv(self, parent_lv):
self._parent_lv = parent_lv
if self._parent_lv:
self._parent_lv.add_internal_lv(self)
+ self._vg = self._parent_lv.vg
@property
@util.requires_property("is_internal_lv")
diff --git a/blivet/partitioning.py b/blivet/partitioning.py
index dfbd218..298f94c 100644
--- a/blivet/partitioning.py
+++ b/blivet/partitioning.py
@@ -1473,7 +1473,7 @@ class ThinPoolChunk(VGChunk):
def __init__(self, pool, requests=None):
"""
:param pool: the thin pool whose free space this chunk represents
- :type pool: :class:`~.devices.LVMThinPoolDevice`
+ :type pool: :class:`~.devices.LVMLogicalVolumeDevice`
:keyword requests: list of requests to add initially
:type requests: list of :class:`LVRequest`
"""
diff --git a/blivet/populator/helpers/lvm.py b/blivet/populator/helpers/lvm.py
index ff18ea0..aad680f 100644
--- a/blivet/populator/helpers/lvm.py
+++ b/blivet/populator/helpers/lvm.py
@@ -27,9 +27,7 @@
from ... import udev
from ...devicelibs import lvm
-from ...devices import LVMVolumeGroupDevice, LVMLogicalVolumeDevice, LVMSnapShotDevice
-from ...devices import LVMThinPoolDevice, LVMThinSnapShotDevice,
LVMThinLogicalVolumeDevice
-from ...devices.lvm import get_internal_lv_class
+from ...devices.lvm import LVMVolumeGroupDevice, LVMLogicalVolumeDevice,
LVMInternalLVtype
from ...errors import DeviceTreeError, DuplicateVGError
from ...flags import flags
from ...size import Size
@@ -147,7 +145,6 @@ def add_lv(lv):
lv_size = Size(lv.size)
lv_type = lv.segtype
- lv_class = LVMLogicalVolumeDevice
lv_parents = [vg_device]
lv_kwargs = {}
name = "%s-%s" % (vg_name, lv_name)
@@ -175,7 +172,6 @@ def add_lv(lv):
origin = self._devicetree.get_device_by_name(origin_device_name)
lv_kwargs["origin"] = origin
- lv_class = LVMSnapShotDevice
elif lv_attr[0] == 'v':
# skip vorigins
return
@@ -187,7 +183,8 @@ def add_lv(lv):
return
elif lv_attr[0] == 't':
# thin pool
- lv_class = LVMThinPoolDevice
+ # nothing to do here
+ pass
elif lv_attr[0] == 'V':
# thin volume
pool_name = blockdev.lvm.thlvpoolname(vg_name, lv_name)
@@ -200,9 +197,6 @@ def add_lv(lv):
add_required_lv(origin_device_name, "failed to locate origin
lv")
origin = self._devicetree.get_device_by_name(origin_device_name)
lv_kwargs["origin"] = origin
- lv_class = LVMThinSnapShotDevice
- else:
- lv_class = LVMThinLogicalVolumeDevice
lv_parents = [self._devicetree.get_device_by_name(pool_device_name)]
elif lv_name.endswith(']'):
@@ -222,9 +216,9 @@ def add_lv(lv):
lv_dev = self._devicetree.get_device_by_uuid(lv_uuid)
if lv_dev is None:
- lv_device = lv_class(lv_name, parents=lv_parents,
- uuid=lv_uuid, size=lv_size, seg_type=lv_type,
- exists=True, **lv_kwargs)
+ lv_device = LVMLogicalVolumeDevice(lv_name, parents=lv_parents,
+ uuid=lv_uuid, size=lv_size,
seg_type=lv_type,
+ exists=True, **lv_kwargs)
self._devicetree._add_device(lv_device)
if flags.installer_mode:
lv_device.setup()
@@ -249,17 +243,18 @@ def create_internal_lv(lv):
lv_uuid = lv.uuid
lv_attr = lv.attr
lv_size = Size(lv.size)
- lv_type = lv.segtype
+ seg_type = lv.segtype
- matching_cls = get_internal_lv_class(lv_attr)
- if matching_cls is None:
- raise DeviceTreeError("No internal LV class supported for type
'%s'" % lv_attr[0])
+ lv_type = LVMInternalLVtype.get_type(lv_attr, lv_name)
+ if lv_type is LVMInternalLVtype.unknown:
+ raise DeviceTreeError("Internal LVs of type '%s' are not
supported" % lv_attr[0])
# strip the "[]"s marking the LV as internal
lv_name = lv_name.strip("[]")
# don't know the parent LV yet, will be set later
- new_lv = matching_cls(lv_name, vg_device, parent_lv=None, size=lv_size,
uuid=lv_uuid, exists=True, seg_type=lv_type)
+ new_lv = LVMLogicalVolumeDevice(lv_name, vg_device, parent_lv=None,
int_type=lv_type,
+ size=lv_size, uuid=lv_uuid, exists=True,
seg_type=seg_type)
if new_lv.status:
new_lv.update_sysfs_path()
new_lv.update_size()
@@ -299,8 +294,7 @@ def create_internal_lv(lv):
orphan_lvs[full_name] = new_lv
all_lvs.append(new_lv)
- # assign parents to internal LVs (and vice versa, see
- # :class:`~.devices.lvm.LVMInternalLogicalVolumeDevice`)
+ # assign parents to internal LVs (and vice versa)
for lv in orphan_lvs.values():
parent_lv = lvm.determine_parent_lv(vg_name, lv, all_lvs)
if parent_lv:
--
To view this commit on github, visit
https://github.com/rhinstaller/blivet/commit/78ddcfb5c4b583c8eaadfcdeb18e...