diff --git a/devices/org.osbuild.lvm2.lv b/devices/org.osbuild.lvm2.lv index 2f8fe4f4f..1d5933695 100755 --- a/devices/org.osbuild.lvm2.lv +++ b/devices/org.osbuild.lvm2.lv @@ -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): @@ -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, diff --git a/devices/test/test_lv.py b/devices/test/test_lv.py new file mode 100644 index 000000000..20d2a4775 --- /dev/null +++ b/devices/test/test_lv.py @@ -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