Skip to content

Commit 1ae306d

Browse files
committed
get virtual block info generically, not just dm info
Signed-off-by: Zen <[email protected]>
1 parent 228d94f commit 1ae306d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/ugrd/fs/mounts.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '4.15.4'
2+
__version__ = '4.15.5'
33

44
from pathlib import Path
55
from zenlib.util import contains, pretty_print
@@ -260,13 +260,13 @@ def autodetect_init_mount(self, parent=None) -> None:
260260
autodetect_init_mount(self, parent.parent)
261261

262262

263-
def get_dm_info(self) -> dict:
263+
def get_virtual_block_info(self) -> dict:
264264
"""
265-
Populates the device mapper info.
265+
Populates the virtual block device info. (previously device mapper only)
266266
Disables device mapper autodetection if no virtual block devices are found.
267267
"""
268268
if self.get('_dm_info'):
269-
self.logger.debug("Device mapper info already set.")
269+
self.logger.debug("Virtual device info already set.")
270270
return
271271

272272
if not Path('/sys/devices/virtual/block').exists():
@@ -282,16 +282,23 @@ def get_dm_info(self) -> dict:
282282
'holders': [holder.name for holder in (dm_device / 'holders').iterdir()],
283283
'slaves': [slave.name for slave in (dm_device / 'slaves').iterdir()],
284284
'uuid': (dm_device / 'dm/uuid').read_text().strip()}
285+
if uuid := (dm_device / 'dm/uuid').read_text().strip():
286+
self['_dm_info'][dm_device.name]['uuid'] = uuid
287+
elif uuid := (dm_device / 'md/uuid').read_text().strip():
288+
self['_dm_info'][dm_device.name]['uuid'] = uuid
289+
else:
290+
raise ValueError("Failed to get virtual device uuid: %s" % dm_device.name)
291+
285292
try:
286293
self['_dm_info'][dm_device.name]['name'] = (dm_device / 'dm/name').read_text().strip()
287294
except FileNotFoundError:
288295
self.logger.warning("No device mapper name found for: %s" % dm_device.name)
289296

290297
if self['_dm_info']:
291-
self.logger.info("Found device mapper devices: %s" % ', '.join(self['_dm_info'].keys()))
292-
self.logger.debug("Device mapper info: %s" % pretty_print(self['_dm_info']))
298+
self.logger.info("Found virtual block devices: %s" % ', '.join(self['_dm_info'].keys()))
299+
self.logger.debug("Virtual block device info: %s" % pretty_print(self['_dm_info']))
293300
else:
294-
self.logger.debug("No device mapper devices found.")
301+
self.logger.debug("No virtual block devices found.")
295302

296303

297304
def _get_device_id(device: str) -> str:

src/ugrd/fs/mounts.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ late_fstab = "/etc/fstab.late"
2020
"ugrd.fs.mounts" = [ "_process_mounts_multi", "_process_late_mounts_multi", "_process_mount_timeout" ]
2121

2222
[imports.build_pre]
23-
"ugrd.fs.mounts" = [ "get_mounts_info", "get_dm_info", "get_blkid_info", "autodetect_root", "autodetect_mounts", "autodetect_root_dm" ]
23+
"ugrd.fs.mounts" = [ "get_mounts_info", "get_virtual_block_info", "get_blkid_info", "autodetect_root", "autodetect_mounts", "autodetect_root_dm" ]
2424

2525
[imports.build_tasks]
2626
"ugrd.fs.mounts" = [ "autodetect_init_mount", "export_mount_info", "export_root_target" ]

0 commit comments

Comments
 (0)