Skip to content

Commit aade837

Browse files
committed
improve logging and virtual block device detection behavior
Signed-off-by: Zen <[email protected]>
1 parent 518b8d1 commit aade837

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/ugrd/fs/mounts.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '4.15.7'
2+
__version__ = '4.16.0'
33

44
from pathlib import Path
55
from zenlib.util import contains, pretty_print
@@ -307,26 +307,30 @@ def _get_device_id(device: str) -> str:
307307

308308

309309
@contains('hostonly', "Skipping device mapper autodetection, hostonly mode is disabled.", log_level=30)
310-
def _autodetect_dm(self, mountpoint) -> None:
310+
def _autodetect_dm(self, mountpoint, device=None) -> None:
311311
"""
312312
Autodetects device mapper config given a mountpoint.
313+
Uses the passed device if the mountpoint is not found in self['_mounts'], and is passed.
313314
Ensures it's a device mapper mount, then autodetects the mount type.
314315
315316
Adds kmods to the autodetect list based on the mount source.
316317
"""
317-
if mountpoint in self['_mounts']:
318+
if device:
319+
self.logger.debug("[%s] Using provided device for mount autodetection: %s" % (mountpoint, device))
320+
source_device = device
321+
elif mountpoint in self['_mounts']:
318322
source_device = self['_mounts'][mountpoint]['device']
319323
else:
320-
source_device = "/dev/mapper/" + self['_dm_info'][mountpoint.split('/')[-1]]['name']
321-
322-
if not source_device or source_device not in self['_blkid_info']:
323-
raise FileNotFoundError("[%s] No blkdid info for dm device: %s" % (mountpoint, source_device))
324+
raise FileNotFoundError("Mountpoint not found in host mounts: %s" % mountpoint)
324325

325-
if not source_device.startswith('/dev/mapper') and not source_device.startswith('/dev/dm-'):
326+
if not any(source_device.startswith(prefix) for prefix in ['/dev/mapper', '/dev/dm-', '/dev/md']):
326327
self.logger.debug("Mount is not a device mapper mount: %s" % source_device)
327328
return
328329

329-
self.logger.info("Detected a device mapper mount: %s" % source_device)
330+
if source_device not in self['_blkid_info']:
331+
raise FileNotFoundError("[%s] No blkdid info for virtual device: %s" % (mountpoint, source_device))
332+
333+
self.logger.info("[%s] Detected virtual block device: %s" % (mountpoint, source_device))
330334
source_device = Path(source_device)
331335
major, minor = _get_device_id(source_device)
332336
self.logger.debug("[%s] Major: %s, Minor: %s" % (source_device, major, minor))
@@ -363,8 +367,9 @@ def _autodetect_dm(self, mountpoint) -> None:
363367
autodetect_mount_kmods(self, slave_source)
364368

365369
for slave in self._dm_info[dm_num]['slaves']:
370+
self.logger.warning(slave)
366371
try:
367-
_autodetect_dm(self, '/dev/' + slave)
372+
_autodetect_dm(self, mountpoint, f"/dev/{slave}")
368373
self.logger.info("[%s] Autodetected device mapper container: %s" % (source_device.name, slave))
369374
except KeyError:
370375
self.logger.debug("Slave does not appear to be a DM device: %s" % slave)

0 commit comments

Comments
 (0)