Resolve symlinks to underlying block devices

When checking for holders on a block device, ensure that any
by-uuid or by-dname provided paths are resolved to the underlying
block device when searching for holders.

Change-Id: If0e1fbc62bfe7d0f9e21db9bfdeee761060de846
Closes-Bug: 1782439
This commit is contained in:
James Page 2018-07-27 13:13:45 +01:00
parent afdd9a974d
commit 0e1be87d68
1 changed files with 4 additions and 2 deletions

View File

@ -1699,8 +1699,10 @@ def is_mapped_luks_device(dev):
:param: dev: A full path to a block device to be checked
:returns: boolean: indicates whether a device is mapped
"""
_, dirs, _ = next(os.walk('/sys/class/block/{}/holders/'
.format(os.path.basename(dev))))
_, dirs, _ = next(os.walk(
'/sys/class/block/{}/holders/'
.format(os.path.basename(os.path.realpath(dev))))
)
is_held = len(dirs) > 0
return is_held and is_luks_device(dev)