[master 17/30] Add a property indicating the type to pass to
get_format.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/populator/helpers/formatpopulator.py | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/blivet/populator/helpers/formatpopulator.py b/blivet/populator/helpers/formatpopulator.py
index b65a37f..014d6a5 100644
--- a/blivet/populator/helpers/formatpopulator.py
+++ b/blivet/populator/helpers/formatpopulator.py
@@ -78,14 +78,19 @@ def _get_kwargs(self):
"exists": True}
return kwargs
- def run(self):
- """ Create a format instance and associate it with the device instance. """
- kwargs = self._get_kwargs()
+ @property
+ def type_spec(self):
if self._type_specifier is not None:
type_spec = self._type_specifier
else:
- type_spec = udev.device_get_format(self.data)
+ type_spec = udev.device_get_format(self.data) or None
+
+ return type_spec
+ def run(self):
+ """ Create a format instance and associate it with the device instance. """
+ kwargs = self._get_kwargs()
+ type_spec = self.type_spec
try:
log.info("type detected on '%s' is '%s'", self.device.name, type_spec)
self.device.format = formats.get_format(type_spec, **kwargs)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/e3e82244a494772bef61b0e6ce06...
8 years, 3 months
[master 16/30] Add functions for resolving between block major and
device
type.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/devices/__init__.py | 6 +++---
blivet/devices/dm.py | 4 +++-
blivet/devices/lib.py | 43 ++++++++++++++++++++++++++++++++++++++-----
blivet/devices/md.py | 3 +++
4 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/blivet/devices/__init__.py b/blivet/devices/__init__.py
index 4f697ca..4bdea37 100644
--- a/blivet/devices/__init__.py
+++ b/blivet/devices/__init__.py
@@ -19,15 +19,15 @@
# Red Hat Author(s): David Lehman <dlehman(a)redhat.com>
#
-from .lib import get_device_majors, device_path_to_name, device_name_to_disk_by_path, ParentList
+from .lib import device_path_to_name, device_name_to_disk_by_path, ParentList
from .device import Device
from .storage import StorageDevice
from .disk import DiskDevice, DiskFile, DMRaidArrayDevice, MultipathDevice, iScsiDiskDevice, FcoeDiskDevice, DASDDevice, ZFCPDiskDevice
from .partition import PartitionDevice
-from .dm import DMDevice, DMLinearDevice, DMCryptDevice
+from .dm import DMDevice, DMLinearDevice, DMCryptDevice, DM_MAJORS
from .luks import LUKSDevice
from .lvm import LVMVolumeGroupDevice, LVMLogicalVolumeDevice, LVMSnapShotDevice, LVMThinPoolDevice, LVMThinLogicalVolumeDevice, LVMThinSnapShotDevice
-from .md import MDBiosRaidArrayDevice, MDContainerDevice, MDRaidArrayDevice
+from .md import MDBiosRaidArrayDevice, MDContainerDevice, MDRaidArrayDevice, MD_MAJORS
from .btrfs import BTRFSDevice, BTRFSVolumeDevice, BTRFSSubVolumeDevice, BTRFSSnapShotDevice
from .file import FileDevice, DirectoryDevice, SparseFileDevice
from .loop import LoopDevice
diff --git a/blivet/devices/dm.py b/blivet/devices/dm.py
index f76ff3a..e7efddf 100644
--- a/blivet/devices/dm.py
+++ b/blivet/devices/dm.py
@@ -37,7 +37,9 @@
log = logging.getLogger("blivet")
from .storage import StorageDevice
-from .lib import LINUX_SECTOR_SIZE
+from .lib import LINUX_SECTOR_SIZE, get_majors_by_device_type
+
+DM_MAJORS = get_majors_by_device_type("device-mapper")
class DMDevice(StorageDevice):
diff --git a/blivet/devices/lib.py b/blivet/devices/lib.py
index 5edb398..33e90e2 100644
--- a/blivet/devices/lib.py
+++ b/blivet/devices/lib.py
@@ -28,19 +28,52 @@
LINUX_SECTOR_SIZE = Size(512)
-def get_device_majors():
- majors = {}
+def _collect_device_major_data():
+ by_major = {}
+ by_device = {}
for line in open("/proc/devices").readlines():
try:
(major, device) = line.split()
except ValueError:
continue
try:
- majors[int(major)] = device
+ by_major[int(major)] = device
+ if device not in by_device:
+ by_device[device] = []
+
+ by_device[device].append(int(major))
except ValueError:
continue
- return majors
-device_majors = get_device_majors()
+ return (by_major, by_device)
+_devices_by_major, _majors_by_device = _collect_device_major_data()
+
+
+def get_majors_by_device_type(device_type):
+ """ Return a list of major numbers for the given device type.
+
+ :param str device_type: device type string (eg: 'device-mapper', 'md')
+ :rtype: list of int
+
+ .. note::
+
+ Type strings are taken directly from /proc/devices.
+
+ """
+ return _majors_by_device.get(device_type, [])
+
+
+def get_device_type_by_major(major):
+ """ Return a device-type string for the given major number.
+
+ :param int major: major number
+ :rtype: str
+
+ .. note::
+
+ Type strings are taken directly from /proc/devices.
+
+ """
+ return _devices_by_major.get(major)
def device_path_to_name(device_path):
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index 7bc2531..579126a 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -43,6 +43,9 @@
from .storage import StorageDevice
from .container import ContainerDevice
from .raid import RaidDevice
+from .lib import get_majors_by_device_type
+
+MD_MAJORS = get_majors_by_device_type("md")
class MDRaidArrayDevice(ContainerDevice, RaidDevice):
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/611f0d4b2109380981e1539f5232...
8 years, 3 months
[master 15/30] Add a flag to preserve the root device in
recursive_remove.
by dashea
From: David Lehman <dlehman(a)redhat.com>
With this flag the method will recursively clear a device without
removing it. This is the same behavior it has always had for disks.
---
blivet/devicetree.py | 5 +++--
blivet/populator/populator.py | 7 ++-----
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 1d73b69..e692330 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -204,11 +204,12 @@ def _remove_device(self, dev, force=None, modparent=True):
dev.name,
dev.id)
- def recursive_remove(self, device, actions=True):
+ def recursive_remove(self, device, actions=True, remove_device=True):
""" Remove a device after removing its dependent devices.
:param :class:`~.devices.StorageDevice` device: the device to remove
:keyword bool actions: whether to schedule actions for the removal
+ :keyword bool remove_device: whether to remove the root device
If the device is not a leaf, all of its dependents are removed
recursively until it is a leaf device. At that point the device is
@@ -249,7 +250,7 @@ def recursive_remove(self, device, actions=True):
else:
device.format = None
- if not device.is_disk:
+ if remove_device and not device.is_disk:
if actions:
self.actions.add(ActionDestroyDevice(device))
else:
diff --git a/blivet/populator/populator.py b/blivet/populator/populator.py
index efea071..4718fe8 100644
--- a/blivet/populator/populator.py
+++ b/blivet/populator/populator.py
@@ -236,13 +236,10 @@ def _clear_new_multipath_member(self, device):
return
# newly added device (eg iSCSI) could make this one a multipath member
- if device.format and device.format.type != "multipath_member":
+ if device.format.type != "multipath_member":
log.debug("%s newly detected as multipath member, dropping old format and removing kids", device.name)
# remove children from tree so that we don't stumble upon them later
- for child in device.children:
- self.recursive_remove(child, actions=False)
-
- device.format = None
+ self.recursive_remove(device, actions=False, remove_device=False)
def _mark_readonly_device(self, info, device):
# If this device is read-only, mark it as such now.
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/70d920b387af42484858ed70d507...
8 years, 3 months
[master 13/30] Remove old hack meant to remove stale metadata.
by dashea
From: David Lehman <dlehman(a)redhat.com>
There are several such mechanisms being employed elsewhere in blivet
and even in the lvm tools themselves. This should not be needed anymore.
---
blivet/formats/lvmpv.py | 6 ------
1 file changed, 6 deletions(-)
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index f0031ef..bc82612 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -117,12 +117,6 @@ def _create(self, **kwargs):
# Consider use of -Z|--zero
# -f|--force or -y|--yes may be required
-
- # lvm has issues with persistence of metadata, so here comes the
- # hammer...
- # XXX This format doesn't exist yet, so bypass the precondition checking
- # for destroy by calling _destroy directly.
- DeviceFormat._destroy(self, **kwargs)
blockdev.lvm.pvscan(self.device)
blockdev.lvm.pvcreate(self.device, data_alignment=self.data_alignment)
blockdev.lvm.pvscan(self.device)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/74a01d6e36227d9b99adb4bf4ba1...
8 years, 3 months
[master 12/30] Use wipefs to remove disklabels.
by dashea
From: David Lehman <dlehman(a)redhat.com>
libparted's clobber does not remove a protective MBR, which makes it
useless for our purposes.
---
blivet/formats/disklabel.py | 6 ------
1 file changed, 6 deletions(-)
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 9ea89a3..093ba24 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -243,12 +243,6 @@ def _create(self, **kwargs):
# other problems.
self.commit()
- def _destroy(self, **kwargs):
- """ Wipe the disklabel from the device. """
- log_method_call(self, device=self.device,
- type=self.type, status=self.status)
- self.parted_device.clobber()
-
def commit(self):
""" Commit the current partition table to disk and notify the OS. """
log_method_call(self, device=self.device,
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/90b18e78b6896aa20fdd3103dc69...
8 years, 3 months
[master 11/30] Add container_uuid r/w property to container member
format
classes.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/formats/fs.py | 8 ++++++++
blivet/formats/lvmpv.py | 8 ++++++++
blivet/formats/mdraid.py | 8 ++++++++
3 files changed, 24 insertions(+)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index cb105c4..7e0d689 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -986,6 +986,14 @@ def _pre_setup(self, **kwargs):
# Don't try to mount it if there's no mountpoint.
return bool(self.mountpoint or kwargs.get("mountpoint"))
+ @property
+ def container_uuid(self):
+ return self.vol_uuid
+
+ @container_uuid.setter
+ def container_uuid(self, uuid):
+ self.vol_uuid = uuid
+
register_device_format(BTRFS)
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index bc82612..5f1180d 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -159,4 +159,12 @@ def free(self):
def free(self, value):
self._free = value
+ @property
+ def container_uuid(self):
+ return self.vg_uuid
+
+ @container_uuid.setter
+ def container_uuid(self, uuid):
+ self.vg_uuid = uuid
+
register_device_format(LVMPhysicalVolume)
diff --git a/blivet/formats/mdraid.py b/blivet/formats/mdraid.py
index 9212c15..ee7e887 100644
--- a/blivet/formats/mdraid.py
+++ b/blivet/formats/mdraid.py
@@ -104,6 +104,14 @@ def status(self):
def hidden(self):
return super(MDRaidMember, self).hidden or self.biosraid
+ @property
+ def container_uuid(self):
+ return self.md_uuid
+
+ @container_uuid.setter
+ def container_uuid(self, uuid):
+ self.md_uuid = uuid
+
# nodmraid -> Wether to use BIOS RAID or not
# Note the anaconda cmdline has not been parsed yet when we're first imported,
# so we can not use flags.dmraid here
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/057a2892779e903b0e6e36613dbe...
8 years, 3 months
[master 10/30] Add support for passing the new size into
StorageDevice.updateSize.
by dashea
From: David Lehman <dlehman(a)redhat.com>
This is intended to be used under a very limited set of circumstances,
such as resize of inactive LVs from outside of blivet.
---
blivet/devices/btrfs.py | 2 +-
blivet/devices/container.py | 2 +-
blivet/devices/md.py | 4 ++--
blivet/devices/nfs.py | 2 +-
blivet/devices/nodev.py | 2 +-
blivet/devices/storage.py | 21 ++++++++++++++++++---
6 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/blivet/devices/btrfs.py b/blivet/devices/btrfs.py
index e2f6ee1..b50ea97 100644
--- a/blivet/devices/btrfs.py
+++ b/blivet/devices/btrfs.py
@@ -76,7 +76,7 @@ def update_sysfs_path(self):
self.sysfs_path = self.parents[0].sysfs_path
log.debug("%s sysfs_path set to %s", self.name, self.sysfs_path)
- def update_size(self):
+ def update_size(self, newsize=None):
pass
def _post_create(self):
diff --git a/blivet/devices/container.py b/blivet/devices/container.py
index 56ba301..a2419f2 100644
--- a/blivet/devices/container.py
+++ b/blivet/devices/container.py
@@ -191,5 +191,5 @@ def remove(self, member):
if member in self.parents:
self.parents.remove(member)
- def update_size(self):
+ def update_size(self, newsize=None):
pass
diff --git a/blivet/devices/md.py b/blivet/devices/md.py
index 3045de7..7bc2531 100644
--- a/blivet/devices/md.py
+++ b/blivet/devices/md.py
@@ -235,12 +235,12 @@ def size(self):
return size
- def update_size(self):
+ def update_size(self, newsize=None):
# container size is determined by the member disks, so there is nothing
# to update in that case
if self.type != "mdcontainer":
# pylint: disable=bad-super-call
- super(ContainerDevice, self).update_size()
+ super(ContainerDevice, self).update_size(newsize=newsize)
@property
def description(self):
diff --git a/blivet/devices/nfs.py b/blivet/devices/nfs.py
index 3143d7c..c5e3891 100644
--- a/blivet/devices/nfs.py
+++ b/blivet/devices/nfs.py
@@ -71,7 +71,7 @@ def destroy(self):
""" Destroy the device. """
log_method_call(self, self.name, status=self.status)
- def update_size(self):
+ def update_size(self, newsize=None):
pass
@classmethod
diff --git a/blivet/devices/nodev.py b/blivet/devices/nodev.py
index 099bf42..f612925 100644
--- a/blivet/devices/nodev.py
+++ b/blivet/devices/nodev.py
@@ -72,7 +72,7 @@ def destroy(self):
log_method_call(self, self.name, status=self.status)
self._pre_destroy()
- def update_size(self):
+ def update_size(self, newsize=None):
pass
diff --git a/blivet/devices/storage.py b/blivet/devices/storage.py
index 5b2a3fa..39cf18d 100644
--- a/blivet/devices/storage.py
+++ b/blivet/devices/storage.py
@@ -589,9 +589,24 @@ def current_size(self):
self._current_size = self.read_current_size()
return self._current_size
- def update_size(self):
- """ Update size, current_size, and target_size to actual size. """
- self._current_size = Size(0)
+ def update_size(self, newsize=None):
+ """ Update size, current_size, and target_size to actual size.
+
+ :keyword :class:`~.size.Size` newsize: new size for device
+
+ .. note::
+
+ Most callers will not pass a new size. It is for special cases
+ like outside resize of inactive LVs, which precludes updating
+ the size from /sys.
+ """
+ if newsize is None:
+ self._currentSize = Size(0)
+ elif isinstance(newsize, Size):
+ self._currentSize = newsize
+ else:
+ raise ValueError("new size must be an instance of class Size")
+
new_size = self.current_size
self._size = new_size
self._target_size = new_size # bypass setter checks
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/e8363a4b345130bb04b713245966...
8 years, 3 months
[master 9/30] Store disklabel and partition UUIDs when available.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/devices/partition.py | 5 +++--
blivet/formats/disklabel.py | 1 +
blivet/populator/helpers/disklabel.py | 1 +
blivet/populator/helpers/partition.py | 1 +
blivet/udev.py | 8 ++++++++
5 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/blivet/devices/partition.py b/blivet/devices/partition.py
index ce358e3..3a098a3 100644
--- a/blivet/devices/partition.py
+++ b/blivet/devices/partition.py
@@ -66,7 +66,7 @@ class PartitionDevice(StorageDevice):
_resizable = True
default_size = DEFAULT_PART_SIZE
- def __init__(self, name, fmt=None,
+ def __init__(self, name, fmt=None, uuid=None,
size=None, grow=False, maxsize=None, start=None, end=None,
major=None, minor=None, bootable=None,
sysfs_path='', parents=None, exists=False,
@@ -85,6 +85,7 @@ def __init__(self, name, fmt=None,
For existing partitions only:
+ :keyword str uuid: partition UUID (not filesystem UUID)
:keyword major: the device major
:type major: long
:keyword minor: the device minor
@@ -142,7 +143,7 @@ def __init__(self, name, fmt=None,
else:
size = self.default_size
- StorageDevice.__init__(self, name, fmt=fmt, size=size,
+ StorageDevice.__init__(self, name, fmt=fmt, uuid=uuid, size=size,
major=major, minor=minor, exists=exists,
sysfs_path=sysfs_path, parents=parents)
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index aa4d1ab..da28d96 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -49,6 +49,7 @@ def __init__(self, **kwargs):
"""
:keyword device: full path to the block device node
:type device: str
+ :keyword str uuid: disklabel UUID
:keyword label_type: type of disklabel to create
:type label_type: str
:keyword exists: whether the formatting exists
diff --git a/blivet/populator/helpers/disklabel.py b/blivet/populator/helpers/disklabel.py
index e9aa8b2..ed4e355 100644
--- a/blivet/populator/helpers/disklabel.py
+++ b/blivet/populator/helpers/disklabel.py
@@ -91,6 +91,7 @@ def run(self):
try:
fmt = formats.get_format("disklabel",
device=self.device.path,
+ uuid=udev.device_get_disklabel_uuid(self.data),
exists=True)
except InvalidDiskLabelError as e:
log.info("no usable disklabel on %s", self.device.name)
diff --git a/blivet/populator/helpers/partition.py b/blivet/populator/helpers/partition.py
index 4af23d7..ff6190e 100644
--- a/blivet/populator/helpers/partition.py
+++ b/blivet/populator/helpers/partition.py
@@ -105,6 +105,7 @@ def run(self):
device = None
try:
device = PartitionDevice(name, sysfs_path=sysfs_path,
+ uuid=udev.device_get_partition_uuid(self.data),
major=udev.device_get_major(self.data),
minor=udev.device_get_minor(self.data),
exists=True, parents=[disk])
diff --git a/blivet/udev.py b/blivet/udev.py
index 89121bc..39229dd 100644
--- a/blivet/udev.py
+++ b/blivet/udev.py
@@ -645,6 +645,14 @@ def device_get_disklabel_type(info):
return info.get("ID_PART_TABLE_TYPE")
+
+def device_get_disklabel_uuid(info):
+ return info.get("ID_PART_TABLE_UUID")
+
+
+def device_get_partition_uuid(info):
+ return info.get("ID_PART_ENTRY_UUID")
+
# iscsi disks' ID_PATH form depends on the driver:
# for software iscsi:
# ip-${iscsi_address}:${iscsi_port}-iscsi-${iscsi_tgtname}-lun-${lun}
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/851a49d56651c4be4e8b73b7a711...
8 years, 3 months
[master 8/30] Add a method to re-read the disklabel from disk.
by dashea
From: David Lehman <dlehman(a)redhat.com>
---
blivet/formats/disklabel.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index 093ba24..aa4d1ab 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -120,6 +120,11 @@ def dict(self):
"grain_size": self.get_alignment().grainSize})
return d
+ def update_parted_disk(self):
+ """ re-read the disklabel from the device """
+ self._parted_disk = None
+ self.update_orig_parted_disk()
+
def update_orig_parted_disk(self):
self._orig_parted_disk = self.parted_disk.duplicate()
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/50a74ce70f2ab9df6f2bb753ea18...
8 years, 3 months