diff --git a/probert/lvm.py b/probert/lvm.py index 46d675a..77847ed 100644 --- a/probert/lvm.py +++ b/probert/lvm.py @@ -196,6 +196,8 @@ async def probe(context=None, **kw): older LVM2 stacks, the LVM probe may be incomplete. """ # scan and activate lvm vgs/lvs + # TODO it feels like the activation code should be moved to + # Storage.activate_devices. lvm_scan() activate_volgroups() diff --git a/probert/nvme.py b/probert/nvme.py index 22895f4..4ce6a86 100644 --- a/probert/nvme.py +++ b/probert/nvme.py @@ -13,10 +13,11 @@ # along with this program. If not, see . import logging +import subprocess import pyudev -from probert.utils import udev_get_attributes +from probert.utils import arun, udev_get_attributes log = logging.getLogger('probert.nvme') @@ -32,3 +33,11 @@ async def probe(context=None, **kw): nvme_controllers[controller.sys_name] = props return nvme_controllers + + +async def connect_nbft() -> None: + cmd = ['nvme', 'connect-all', '--nbft'] + try: + await arun(cmd) + except (subprocess.CalledProcessError, FileNotFoundError): + log.error('Failed to run cmd: %s', cmd) diff --git a/probert/storage.py b/probert/storage.py index 16f2202..2ad8942 100644 --- a/probert/storage.py +++ b/probert/storage.py @@ -230,6 +230,10 @@ async def probe(self, probe_types=None, *, parallelize=False): print('Unavilable probe types: %s' % not_avail) return self.results + # Run operations that have side-effects, before we start reading udev + # cache. + await self.activate_devices() + probed_data = {} async def run_probe(ptype): @@ -250,3 +254,20 @@ async def run_probe(ptype): self.results = probed_data return probed_data + + async def activate_devices(probe_types: list[str]) -> None: + """Before querying udev, we want to let it know of the existence of + some block devices (which may not be currently visible). This includes + connecting to NVMe drives using the NVMe/TCP protocol, but also + activating LVM VGs to make LVM LVs visible. + Typically, commands must be run in a specific order to make all the + devices visible; so running the commands in the code of the probes + themselves (which run in an undefined order) feels wrong. + Ideally, the code of the probes should have no side effect, and we + should move operations that have side effect here.""" + if "nvme" in probe_types: + await nvme.connect_nbft() + + # TODO we should probably move the LVM VG activation code here ; so + # that blockdev, filesystem_sizing, OS detection and other probes + # include information about LVs.