Use bcond for with python3, allow it on RHEL > 7 (mhroncok)

Conditionalize the Python 2 subpackage and don't build it on EL > 7 and Fedora > 28 (mhroncok)
Add experimental support for NVDIMM. (vtrefny)
This commit is contained in:
David Lehman 2018-04-02 15:06:24 -04:00
parent 7be317fbf7
commit b04db7f630
7 changed files with 491 additions and 17 deletions

View File

@ -0,0 +1,28 @@
From ce4a0b07d77c81c066e05c7585fa436cfc4007bf Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Wed, 7 Feb 2018 14:35:26 +0100
Subject: [PATCH 1/7] Add NVDIMM plugin to list of requested plugins
---
blivet/__init__.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/blivet/__init__.py b/blivet/__init__.py
index 38492368..a86ce8c4 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -51,9 +51,9 @@ gi.require_version("BlockDev", "2.0")
from gi.repository import GLib
from gi.repository import BlockDev as blockdev
if arch.is_s390():
- _REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "s390"))
+ _REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "s390", "nvdimm"))
else:
- _REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm"))
+ _REQUESTED_PLUGIN_NAMES = set(("lvm", "btrfs", "swap", "crypto", "loop", "mdraid", "mpath", "dm", "nvdimm"))
_requested_plugins = blockdev.plugin_specs_from_names(_REQUESTED_PLUGIN_NAMES)
try:
--
2.14.3

View File

@ -0,0 +1,183 @@
From 037d12cf3d137e08cbb8fa698a1a9c50d20228ea Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Wed, 7 Feb 2018 14:54:40 +0100
Subject: [PATCH 2/7] Add a singleton for NVDIMM namespaces management
This currently allows changing mode of the namespace and getting
information about available namespaces.
---
blivet/static_data/__init__.py | 1 +
blivet/static_data/nvdimm.py | 152 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 153 insertions(+)
create mode 100644 blivet/static_data/nvdimm.py
diff --git a/blivet/static_data/__init__.py b/blivet/static_data/__init__.py
index 2c720af3..c5928ab4 100644
--- a/blivet/static_data/__init__.py
+++ b/blivet/static_data/__init__.py
@@ -1,3 +1,4 @@
from .lvm_info import lvs_info, pvs_info
from .luks_data import luks_data
from .mpath_info import mpath_members
+from .nvdimm import nvdimm
diff --git a/blivet/static_data/nvdimm.py b/blivet/static_data/nvdimm.py
new file mode 100644
index 00000000..0644c9f6
--- /dev/null
+++ b/blivet/static_data/nvdimm.py
@@ -0,0 +1,152 @@
+#
+# nvdimm.py - nvdimm class
+#
+# Copyright (C) 2018 Red Hat, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import gi
+gi.require_version("BlockDev", "2.0")
+gi.require_version("GLib", "2.0")
+from gi.repository import BlockDev
+from gi.repository import GLib
+
+from .. import util
+
+import logging
+log = logging.getLogger("blivet")
+
+
+class NVDIMMDependencyGuard(util.DependencyGuard):
+ error_msg = "libblockdev NVDIMM functionality not available"
+
+ def _check_avail(self):
+ try:
+ BlockDev.nvdimm_is_tech_avail(BlockDev.NVDIMMTech.NVDIMM_TECH_NAMESPACE,
+ BlockDev.NVDIMMTechMode.RECONFIGURE |
+ BlockDev.NVDIMMTechMode.QUERY |
+ BlockDev.NVDIMMTechMode.ACTIVATE_DEACTIVATE)
+ except GLib.GError:
+ return False
+ return True
+
+blockdev_nvdimm_required = NVDIMMDependencyGuard()
+
+
+class NVDIMM(object):
+ """ NVDIMM utility class.
+
+ .. warning::
+ Since this is a singleton class, calling deepcopy() on the instance
+ just returns ``self`` with no copy being created.
+ """
+
+ def __init__(self):
+ self._namespaces = None
+
+ # So that users can write nvdimm() to get the singleton instance
+ def __call__(self):
+ return self
+
+ def __deepcopy__(self, memo_dict):
+ # pylint: disable=unused-argument
+ return self
+
+ @property
+ def namespaces(self):
+ """ Dict of all NVDIMM namespaces, including dax and disabled namespaces
+ """
+ if not self._namespaces:
+ self.update_namespaces_info()
+
+ return self._namespaces
+
+ @blockdev_nvdimm_required(critical=True, eval_mode=util.EvalMode.onetime)
+ def update_namespaces_info(self):
+ """ Update information about the namespaces
+ """
+ namespaces = BlockDev.nvdimm_list_namespaces(idle=True)
+
+ self._namespaces = dict((namespace.dev, namespace) for namespace in namespaces)
+
+ def get_namespace_info(self, device):
+ """ Get namespace information for a device
+ :param str device: device name (e.g. 'pmem0') or path
+ """
+ for info in self.namespaces.values():
+ if info.blockdev == device or \
+ (device.startswith("/dev/") and info.blockdev == device[5:]):
+ return info
+
+ @blockdev_nvdimm_required(critical=True, eval_mode=util.EvalMode.onetime)
+ def enable_namespace(self, namespace):
+ """ Enable a namespace
+ :param str namespace: devname of the namespace (e.g. 'namespace0.0')
+ """
+
+ if namespace not in self.namespaces.keys():
+ raise ValueError("Namespace '%s' doesn't exist." % namespace)
+
+ BlockDev.nvdimm_namespace_enable(namespace)
+
+ # and update our namespaces info "cache"
+ self.update_namespaces_info()
+
+ @blockdev_nvdimm_required(critical=True, eval_mode=util.EvalMode.onetime)
+ def reconfigure_namespace(self, namespace, mode, **kwargs):
+ """ Change mode of the namespace
+ :param str namespace: devname of the namespace (e.g. 'namespace0.0')
+ :param str mode: new mode of the namespace (one of 'sector', 'memory', 'dax')
+ :keyword int sector_size: sector size when reconfiguring to the 'sector' mode
+ :keyword str map_location: map location when reconfiguring to the 'memory'
+ mode (one of 'mem', 'dev')
+
+ .. note::
+ This doesn't change state of the devicetree. It is necessary to
+ run reset() or populate() to make these changes visible.
+ """
+
+ if namespace not in self.namespaces.keys():
+ raise ValueError("Namespace '%s' doesn't exist." % namespace)
+
+ info = self.namespaces[namespace]
+
+ sector_size = kwargs.get("sector_size", None)
+ map_location = kwargs.get("map_location", None)
+
+ if sector_size and mode != "sector":
+ raise ValueError("Sector size cannot be set for selected mode '%s'." % mode)
+
+ if map_location and mode != "memory":
+ raise ValueError("Map location cannot be set for selected mode '%s'." % mode)
+
+ mode_t = BlockDev.nvdimm_namespace_get_mode_from_str(mode)
+
+ if sector_size:
+ extra = {"-l": str(sector_size)}
+ elif map_location:
+ extra = {"-M": map_location}
+ else:
+ extra = None
+
+ BlockDev.nvdimm_namespace_reconfigure(namespace, mode_t, info.enabled, extra)
+
+ # and update our namespaces info "cache"
+ self.update_namespaces_info()
+
+
+# Create nvdimm singleton
+nvdimm = NVDIMM()
+""" An instance of :class:`NVDIMM` """
--
2.14.3

View File

@ -0,0 +1,29 @@
From a14bf252c554c026215a69851c8649f705edaa5d Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Wed, 7 Feb 2018 14:56:13 +0100
Subject: [PATCH 3/7] Add a function for identifying NVDIMM namespaces
---
blivet/udev.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/blivet/udev.py b/blivet/udev.py
index 6936a230..69e12357 100644
--- a/blivet/udev.py
+++ b/blivet/udev.py
@@ -914,3 +914,12 @@ def device_get_fcoe_identifier(info):
if device_is_fcoe(info) and len(path_components) >= 4 and \
path_components[2] == 'fc':
return path_components[3]
+
+
+def device_is_nvdimm_namespace(info):
+ if info.get("DEVTYPE") != "disk":
+ return False
+
+ devname = info.get("DEVNAME", "")
+ ninfo = blockdev.nvdimm_namespace_get_devname(devname)
+ return ninfo is not None
--
2.14.3

View File

@ -0,0 +1,100 @@
From 6ae475fb80cdf1dd7f527ed0b952c613a5825ec3 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Wed, 7 Feb 2018 14:58:12 +0100
Subject: [PATCH 4/7] Add 'NVDIMMNamespaceDevice' device representing NVDIMM
namespaces
---
blivet/devices/__init__.py | 2 +-
blivet/devices/disk.py | 51 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/blivet/devices/__init__.py b/blivet/devices/__init__.py
index 5bae1cbe..aaad30c3 100644
--- a/blivet/devices/__init__.py
+++ b/blivet/devices/__init__.py
@@ -22,7 +22,7 @@
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 .disk import DiskDevice, DiskFile, DMRaidArrayDevice, MultipathDevice, iScsiDiskDevice, FcoeDiskDevice, DASDDevice, ZFCPDiskDevice, NVDIMMNamespaceDevice
from .partition import PartitionDevice
from .dm import DMDevice, DMLinearDevice, DMCryptDevice, DM_MAJORS
from .luks import LUKSDevice
diff --git a/blivet/devices/disk.py b/blivet/devices/disk.py
index 26448640..dc796cf0 100644
--- a/blivet/devices/disk.py
+++ b/blivet/devices/disk.py
@@ -63,7 +63,7 @@ class DiskDevice(StorageDevice):
def __init__(self, name, fmt=None,
size=None, major=None, minor=None, sysfs_path='',
parents=None, serial=None, vendor="", model="", bus="", wwn=None,
- exists=True):
+ uuid=None, exists=True):
"""
:param name: the device name (generally a device node's basename)
:type name: str
@@ -96,7 +96,7 @@ class DiskDevice(StorageDevice):
major=major, minor=minor, exists=exists,
sysfs_path=sysfs_path, parents=parents,
serial=serial, model=model,
- vendor=vendor, bus=bus)
+ vendor=vendor, bus=bus, uuid=uuid)
self.wwn = wwn or None
@@ -660,3 +660,50 @@ class DASDDevice(DiskDevice):
":".join(opts))])
else:
return set(["rd.dasd=%s" % self.busid])
+
+
+class NVDIMMNamespaceDevice(DiskDevice):
+
+ """ Non-volatile memory namespace """
+ _type = "nvdimm"
+
+ def __init__(self, device, **kwargs):
+ """
+ :param name: the device name (generally a device node's basename)
+ :type name: str
+ :keyword exists: does this device exist?
+ :type exists: bool
+ :keyword size: the device's size
+ :type size: :class:`~.size.Size`
+ :keyword parents: a list of parent devices
+ :type parents: list of :class:`StorageDevice`
+ :keyword format: this device's formatting
+ :type format: :class:`~.formats.DeviceFormat` or a subclass of it
+ :keyword mode: mode of the namespace
+ :type mode: str
+ :keyword devname: name of the namespace (e.g. 'namespace0.0')
+ :type devname: str
+ :keyword sector_size: sector size of the namespace in sector mode
+ :type sector_size: str
+ """
+ self.mode = kwargs.pop("mode")
+ self.devname = kwargs.pop("devname")
+ self.sector_size = kwargs.pop("sector_size")
+
+ DiskDevice.__init__(self, device, **kwargs)
+
+ def __repr__(self):
+ s = DiskDevice.__repr__(self)
+ s += (" mode = %(mode)s devname = %(devname)s" %
+ {"mode": self.mode,
+ "devname": self.devname})
+ if self.sector_size:
+ s += (" sector size = %(sector_size)s" % {"sector_size": self.sector_size})
+ return s
+
+ @property
+ def description(self):
+ return "NVDIMM namespace %(devname)s in %(mode)s mode exported as %(path)s" \
+ % {'devname': self.devname,
+ 'mode': self.mode,
+ 'path': self.path}
--
2.14.3

View File

@ -0,0 +1,69 @@
From 5251f696f0bd8a68efde2df7c4dc948c4494ac60 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Wed, 7 Feb 2018 15:00:25 +0100
Subject: [PATCH 5/7] Add populator helper for NVDIMM namespaces
Helper for adding block-like NVDIMM namespaces to the devicetree.
---
blivet/populator/helpers/__init__.py | 2 +-
blivet/populator/helpers/disk.py | 27 ++++++++++++++++++++++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/blivet/populator/helpers/__init__.py b/blivet/populator/helpers/__init__.py
index 861426c6..dd23475a 100644
--- a/blivet/populator/helpers/__init__.py
+++ b/blivet/populator/helpers/__init__.py
@@ -6,7 +6,7 @@ from .formatpopulator import FormatPopulator
from .btrfs import BTRFSFormatPopulator
from .boot import AppleBootFormatPopulator, EFIFormatPopulator, MacEFIFormatPopulator
-from .disk import DiskDevicePopulator, iScsiDevicePopulator, FCoEDevicePopulator, MDBiosRaidDevicePopulator, DASDDevicePopulator, ZFCPDevicePopulator
+from .disk import DiskDevicePopulator, iScsiDevicePopulator, FCoEDevicePopulator, MDBiosRaidDevicePopulator, DASDDevicePopulator, ZFCPDevicePopulator, NVDIMMNamespaceDevicePopulator
from .disklabel import DiskLabelFormatPopulator
from .dm import DMDevicePopulator
from .dmraid import DMRaidFormatPopulator
diff --git a/blivet/populator/helpers/disk.py b/blivet/populator/helpers/disk.py
index e2757b12..ae4a7d28 100644
--- a/blivet/populator/helpers/disk.py
+++ b/blivet/populator/helpers/disk.py
@@ -28,7 +28,7 @@ from gi.repository import BlockDev as blockdev
from ... import udev
from ... import util
from ...devices import DASDDevice, DiskDevice, FcoeDiskDevice, iScsiDiskDevice
-from ...devices import MDBiosRaidArrayDevice, ZFCPDiskDevice
+from ...devices import MDBiosRaidArrayDevice, ZFCPDiskDevice, NVDIMMNamespaceDevice
from ...devices import device_path_to_name
from ...storage_log import log_method_call
from .devicepopulator import DevicePopulator
@@ -214,3 +214,28 @@ class ZFCPDevicePopulator(DiskDevicePopulator):
log.info("%s is a zfcp device", udev.device_get_name(self.data))
return kwargs
+
+
+class NVDIMMNamespaceDevicePopulator(DiskDevicePopulator):
+ priority = 20
+
+ _device_class = NVDIMMNamespaceDevice
+
+ @classmethod
+ def match(cls, data):
+ return (super(NVDIMMNamespaceDevicePopulator, NVDIMMNamespaceDevicePopulator).match(data) and
+ udev.device_is_nvdimm_namespace(data))
+
+ def _get_kwargs(self):
+ kwargs = super(NVDIMMNamespaceDevicePopulator, self)._get_kwargs()
+
+ from ...static_data import nvdimm
+ ninfo = nvdimm.get_namespace_info(self.data.get("DEVNAME"))
+
+ kwargs["mode"] = blockdev.nvdimm_namespace_get_mode_str(ninfo.mode)
+ kwargs["devname"] = ninfo.dev
+ kwargs["uuid"] = ninfo.uuid
+ kwargs["sector_size"] = ninfo.sector_size
+
+ log.info("%s is an NVDIMM namespace device", udev.device_get_name(self.data))
+ return kwargs
--
2.14.3

View File

@ -0,0 +1,40 @@
From d4792dd0d2824eedbcf8cd8d28434ed8f6e938dc Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Tue, 13 Mar 2018 14:46:32 +0100
Subject: [PATCH 7/7] Add 'nvdimm' tag for NVDIMM namespaces
---
blivet/devices/disk.py | 4 ++++
blivet/devices/lib.py | 1 +
2 files changed, 5 insertions(+)
diff --git a/blivet/devices/disk.py b/blivet/devices/disk.py
index dc796cf0..9021126c 100644
--- a/blivet/devices/disk.py
+++ b/blivet/devices/disk.py
@@ -692,6 +692,10 @@ class NVDIMMNamespaceDevice(DiskDevice):
DiskDevice.__init__(self, device, **kwargs)
+ self._clear_local_tags()
+ self.tags.add(Tags.local)
+ self.tags.add(Tags.nvdimm)
+
def __repr__(self):
s = DiskDevice.__repr__(self)
s += (" mode = %(mode)s devname = %(devname)s" %
diff --git a/blivet/devices/lib.py b/blivet/devices/lib.py
index 70b769a4..021f2cfd 100644
--- a/blivet/devices/lib.py
+++ b/blivet/devices/lib.py
@@ -31,6 +31,7 @@ LINUX_SECTOR_SIZE = Size(512)
class Tags(str, Enum):
"""Tags that describe various classes of disk."""
local = 'local'
+ nvdimm = 'nvdimm'
remote = 'remote'
removable = 'removable'
ssd = 'ssd'
--
2.14.3

View File

@ -1,10 +1,19 @@
%define is_rhel 0%{?rhel} != 0
# python3 is not available on RHEL
%if %{is_rhel}
%define with_python3 0
# python3 is not available on RHEL <=7
%if %{is_rhel} && 0%{?rhel} <= 7
# disable python3 by default
%bcond_with python3
%else
%define with_python3 1
%bcond_without python3
%endif
# python2 is not available on RHEL > 7 and not needed on Fedora > 28
%if 0%{?rhel} > 7 || 0%{?fedora} > 28
# disable python2 by default
%bcond_with python2
%else
%bcond_without python2
%endif
Summary: A python module for system storage configuration
@ -14,7 +23,7 @@ Version: 3.0.0
%global prerelease .b1
# prerelease, if defined, should be something like .a1, .b1, .b2.dev1, or .c2
Release: 0.6%{?prerelease}%{?dist}
Release: 0.7%{?prerelease}%{?dist}
Epoch: 1
License: LGPLv2+
Group: System Environment/Libraries
@ -26,6 +35,13 @@ Patch1: 0002-Do-not-try-to-update-potfile-during-make-all.patch
Patch2: 0003-Allow-device-specification-by-node-to-udev.get_devic.patch
Patch3: 0004-Don-t-use-a-wwn-kwarg-for-MDBiosRaidArrayDevice-1557.patch
Patch4: 0001-Add-NVDIMM-plugin-to-list-of-requested-plugins.patch
Patch5: 0002-Add-a-singleton-for-NVDIMM-namespaces-management.patch
Patch6: 0003-Add-a-function-for-identifying-NVDIMM-namespaces.patch
Patch7: 0004-Add-NVDIMMNamespaceDevice-device-representing-NVDIMM.patch
Patch8: 0005-Add-populator-helper-for-NVDIMM-namespaces.patch
Patch10: 0007-Add-nvdimm-tag-for-NVDIMM-namespaces.patch
# Versions of required components (done so we make sure the buildrequires
# match the requires versions of things).
%global partedver 1.8.1
@ -53,7 +69,7 @@ Conflicts: python3-blivet < 1:2.0.0
The %{realname}-data package provides data files required by the %{realname}
python module.
%if %{with_python3}
%if %{with python3}
%package -n python3-%{realname}
Summary: A python3 package for examining and modifying storage configuration.
@ -79,13 +95,20 @@ Requires: systemd-udev
Requires: %{realname}-data = %{epoch}:%{version}-%{release}
Obsoletes: blivet-data < 1:2.0.0
%if %{without python2}
Obsoletes: python2-blivet < 1:3.0.0-0.6
Obsoletes: python-blivet < 1:3.0.0-0.6
%else
Obsoletes: python-blivet < 1:2.0.0
%endif
%description -n python3-%{realname}
The python3-%{realname} is a python3 package for examining and modifying storage
configuration.
%endif
%if %{with python2}
%package -n python2-%{realname}
Summary: A python2 package for examining and modifying storage configuration.
@ -128,23 +151,18 @@ Obsoletes: python-blivet < 1:2.0.0
%description -n python2-%{realname}
The python2-%{realname} is a python2 package for examining and modifying storage
configuration.
%endif
%prep
%autosetup -n %{realname}-%{realversion} -p1
%build
make PYTHON=%{__python2}
%if %{with_python3}
make PYTHON=%{__python3}
%endif
%{?with_python2:make PYTHON=%{__python2}}
%{?with_python3:make PYTHON=%{__python3}}
%install
make PYTHON=%{__python2} DESTDIR=%{buildroot} install
%if %{with_python3}
make PYTHON=%{__python3} DESTDIR=%{buildroot} install
%endif
%{?with_python2:make PYTHON=%{__python2} DESTDIR=%{buildroot} install}
%{?with_python3:make PYTHON=%{__python3} DESTDIR=%{buildroot} install}
%find_lang %{realname}
@ -154,12 +172,14 @@ make PYTHON=%{__python3} DESTDIR=%{buildroot} install
%{_libexecdir}/*
%{_unitdir}/*
%if %{with python2}
%files -n python2-%{realname}
%license COPYING
%doc README ChangeLog examples
%{python2_sitelib}/*
%endif
%if %{with_python3}
%if %{with python3}
%files -n python3-%{realname}
%license COPYING
%doc README ChangeLog examples
@ -167,6 +187,11 @@ make PYTHON=%{__python3} DESTDIR=%{buildroot} install
%endif
%changelog
* Mon Apr 02 2018 David Lehman <dlehman@redhat.com> - 1:3.0.0-0.7.b1
- Use bcond for with python3, allow it on RHEL > 7 (mhroncok)
- Conditionalize the Python 2 subpackage and don't build it on EL > 7 and Fedora > 28 (mhroncok)
- Add experimental support for NVDIMM. (vtrefny)
* Tue Mar 20 2018 David Lehman <dlehman@redhat.com> - 1:3.0.0-0.6.b1
- Don't use a 'wwn' kwarg for MDBiosRaidArrayDevice (#1557957) (awilliam)