Skip to content

Commit

Permalink
devices: create /dev/mapper/<logical-volume> as well
Browse files Browse the repository at this point in the history
When we create the device node inside the buildroot so far it's
very minimal - just `/dev/{vg}-{lv}` with the appopriate major/minor.

However when mount runs it will create a mapper device with the
same major/minor under `/dev/mapper/{escaped(vg)}-{escaped(lv)}`
and use that to mount the actual filesystem. Without this additional
device findmnt will not be able to detect the udev attributes of
the source (as the source is just missing from /dev).

This commit create the right mapper in the same way that we
create the non-mapper device node.
  • Loading branch information
mvo5 committed Aug 26, 2024
1 parent 31176aa commit 506b264
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion devices/org.osbuild.lvm2.lv
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ SCHEMA = """
"volume": {
"type": "string",
"description": "Logical volume to active"
}
},
}
"""


def escaped_lv_mapper_name(vg, lv: str) -> str:
"""
Return the name of the mapper device under /dev/mapper/ for the given vg, lv
"""
# see also lvm2:libdm/libdm-string.c:dm_build_dm_name() at
# https://github.com/lvmteam/lvm2/blob/v2_03_26/libdm/libdm-string.c#L325
return f'{vg.replace("-", "--")}-{lv.replace("-", "--")}'


class LVService(devices.DeviceService):

def __init__(self, args):
Expand Down Expand Up @@ -198,6 +207,11 @@ class LVService(devices.DeviceService):

os.makedirs(os.path.join(devpath, vg), exist_ok=True) # type: ignore
self.ensure_device_node(fullpath, major, minor)
# also create the device under the mapper dir as this is what
# findmnt will need to get the uuid of the filesystem
os.makedirs(os.path.join(devpath, "mapper"), exist_ok=True)
mapper_path = os.path.join(devpath, "mapper", escaped_lv_mapper_name(vg, lv))
self.ensure_device_node(mapper_path, major, minor)

data = {
"path": devname,
Expand Down
8 changes: 8 additions & 0 deletions devices/test/test_lv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/python3

DEVICES_NAME = "org.osbuild.lvm2.lv"


def test_lvm2_escaped_lv_mapper_name(devices_module):
expected = "1d2b2150--8de2--4b68--b387--f9bc709190e8-lvroot"
assert devices_module.escaped_lv_mapper_name("1d2b2150-8de2-4b68-b387-f9bc709190e8", "lvroot") == expected

0 comments on commit 506b264

Please sign in to comment.