|
1 | 1 | __author__ = 'desultory' |
2 | | -__version__ = '4.15.7' |
| 2 | +__version__ = '4.16.0' |
3 | 3 |
|
4 | 4 | from pathlib import Path |
5 | 5 | from zenlib.util import contains, pretty_print |
@@ -307,26 +307,30 @@ def _get_device_id(device: str) -> str: |
307 | 307 |
|
308 | 308 |
|
309 | 309 | @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: |
311 | 311 | """ |
312 | 312 | Autodetects device mapper config given a mountpoint. |
| 313 | + Uses the passed device if the mountpoint is not found in self['_mounts'], and is passed. |
313 | 314 | Ensures it's a device mapper mount, then autodetects the mount type. |
314 | 315 |
|
315 | 316 | Adds kmods to the autodetect list based on the mount source. |
316 | 317 | """ |
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']: |
318 | 322 | source_device = self['_mounts'][mountpoint]['device'] |
319 | 323 | 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) |
324 | 325 |
|
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']): |
326 | 327 | self.logger.debug("Mount is not a device mapper mount: %s" % source_device) |
327 | 328 | return |
328 | 329 |
|
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)) |
330 | 334 | source_device = Path(source_device) |
331 | 335 | major, minor = _get_device_id(source_device) |
332 | 336 | self.logger.debug("[%s] Major: %s, Minor: %s" % (source_device, major, minor)) |
@@ -363,8 +367,9 @@ def _autodetect_dm(self, mountpoint) -> None: |
363 | 367 | autodetect_mount_kmods(self, slave_source) |
364 | 368 |
|
365 | 369 | for slave in self._dm_info[dm_num]['slaves']: |
| 370 | + self.logger.warning(slave) |
366 | 371 | try: |
367 | | - _autodetect_dm(self, '/dev/' + slave) |
| 372 | + _autodetect_dm(self, mountpoint, f"/dev/{slave}") |
368 | 373 | self.logger.info("[%s] Autodetected device mapper container: %s" % (source_device.name, slave)) |
369 | 374 | except KeyError: |
370 | 375 | self.logger.debug("Slave does not appear to be a DM device: %s" % slave) |
|
0 commit comments