Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | # This file contains common functions for overlayfs and its QA check |
| 7 | |
| 8 | # this function is based on https://github.com/systemd/systemd/blob/main/src/basic/unit-name.c |
| 9 | def escapeSystemdUnitName(path): |
| 10 | escapeMap = { |
| 11 | '/': '-', |
| 12 | '-': "\\x2d", |
| 13 | '\\': "\\x5d" |
| 14 | } |
| 15 | return "".join([escapeMap.get(c, c) for c in path.strip('/')]) |
| 16 | |
| 17 | def strForBash(s): |
| 18 | return s.replace('\\', '\\\\') |
| 19 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 20 | def allOverlaysUnitName(d): |
| 21 | return d.getVar('PN') + '-overlays.service' |
| 22 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 23 | def mountUnitName(unit): |
| 24 | return escapeSystemdUnitName(unit) + '.mount' |
| 25 | |
| 26 | def helperUnitName(unit): |
| 27 | return escapeSystemdUnitName(unit) + '-create-upper-dir.service' |
| 28 | |
| 29 | def unitFileList(d): |
| 30 | fileList = [] |
| 31 | overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT") |
| 32 | |
| 33 | if not overlayMountPoints: |
| 34 | bb.fatal("A recipe uses overlayfs class but there is no OVERLAYFS_MOUNT_POINT set in your MACHINE configuration") |
| 35 | |
| 36 | # check that we have required mount points set first |
| 37 | requiredMountPoints = d.getVarFlags('OVERLAYFS_WRITABLE_PATHS') |
| 38 | for mountPoint in requiredMountPoints: |
| 39 | if mountPoint not in overlayMountPoints: |
| 40 | bb.fatal("Missing required mount point for OVERLAYFS_MOUNT_POINT[%s] in your MACHINE configuration" % mountPoint) |
| 41 | |
| 42 | for mountPoint in overlayMountPoints: |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 43 | mountPointList = d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint) |
| 44 | if not mountPointList: |
| 45 | bb.debug(1, "No mount points defined for %s flag, don't add to file list", mountPoint) |
| 46 | continue |
| 47 | for path in mountPointList.split(): |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 48 | fileList.append(mountUnitName(path)) |
| 49 | fileList.append(helperUnitName(path)) |
| 50 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 51 | fileList.append(allOverlaysUnitName(d)) |
| 52 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 53 | return fileList |
| 54 | |