|
1 | 1 | __author__ = 'desultory' |
2 | | -__version__ = '4.16.2' |
| 2 | +__version__ = '4.16.3' |
3 | 3 |
|
4 | 4 | from pathlib import Path |
5 | 5 | from zenlib.util import contains, pretty_print |
@@ -205,7 +205,7 @@ def get_mounts_info(self) -> None: |
205 | 205 |
|
206 | 206 |
|
207 | 207 | @contains('hostonly', "Skipping blkid autodetection, hostonly mode is enabled.", log_level=30) |
208 | | -def get_blkid_info(self, device=None) -> str: |
| 208 | +def get_blkid_info(self, device=None) -> dict: |
209 | 209 | """ |
210 | 210 | Gets the blkid info for all devices if no device is passed. |
211 | 211 | Gets the blkid info for the passed device if a device is passed. |
@@ -233,6 +233,7 @@ def get_blkid_info(self, device=None) -> str: |
233 | 233 | raise ValueError("[%s] Failed to parse blkid info: %s" % (device, info)) |
234 | 234 |
|
235 | 235 | self.logger.debug("Blkid info: %s" % pretty_print(self['_blkid_info'])) |
| 236 | + return self['_blkid_info'][device] if device else self['_blkid_info'] |
236 | 237 |
|
237 | 238 |
|
238 | 239 | @contains('init_target', 'init_target must be set', raise_exception=True) |
@@ -327,11 +328,17 @@ def _autodetect_dm(self, mountpoint, device=None) -> None: |
327 | 328 | self.logger.debug("Mount is not a device mapper mount: %s" % source_device) |
328 | 329 | return |
329 | 330 |
|
| 331 | + device_name = source_device.split('/')[-1] |
330 | 332 | if source_device not in self['_blkid_info']: |
331 | | - device_name = source_device.split('/')[-1] |
332 | | - mapped_device = f'/dev/mapper/{device_name}' |
333 | | - if mapped_device not in self['_blkid_info']: |
334 | | - raise FileNotFoundError("[%s] No blkid info for virtual device: %s" % (mountpoint, device_name)) |
| 333 | + if device_name in self['_dm_info']: |
| 334 | + if f'/dev/{device_name}' in self['_blkid_info']: |
| 335 | + source_device = f'/dev/{device_name}' |
| 336 | + elif f'/dev/mapper/{device_name}' in self['_blkid_info']: |
| 337 | + source_device = f'/dev/mapper/{device_name}' |
| 338 | + elif not get_blkid_info(self, source_device): |
| 339 | + raise FileNotFoundError("[%s] No blkid info for virtual device: %s" % (mountpoint, source_device)) |
| 340 | + else: |
| 341 | + raise ValueError("[%s] No blkid info for virtual device: %s" % (mountpoint, source_device)) |
335 | 342 |
|
336 | 343 | self.logger.info("[%s] Detected virtual block device: %s" % (mountpoint, source_device)) |
337 | 344 | source_device = Path(source_device) |
|
0 commit comments