mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 00:59:48 +00:00
overlayfs: all overlays unit
Application can depend on several overlayfs mount points. Provide a systemd unit application can depend on to make sure all overlays are mounted before it is started to avoid any race conditions (From OE-Core rev: b38e194db0c6825f28c56123cf88af94d3f52beb) Signed-off-by: Bruno Knittel <Bruno.Knittel@bruker.com> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
d81238da57
commit
9c8ea9dcf1
@@ -37,6 +37,8 @@ REQUIRED_DISTRO_FEATURES += "systemd overlayfs"
|
|||||||
inherit systemd features_check
|
inherit systemd features_check
|
||||||
|
|
||||||
python do_create_overlayfs_units() {
|
python do_create_overlayfs_units() {
|
||||||
|
from oe.overlayfs import mountUnitName
|
||||||
|
|
||||||
CreateDirsUnitTemplate = """[Unit]
|
CreateDirsUnitTemplate = """[Unit]
|
||||||
Description=Overlayfs directories setup
|
Description=Overlayfs directories setup
|
||||||
Requires={DATA_MOUNT_UNIT}
|
Requires={DATA_MOUNT_UNIT}
|
||||||
@@ -65,10 +67,23 @@ Options=lowerdir={LOWERDIR},upperdir={DATA_MOUNT_POINT}/upper{LOWERDIR},workdir=
|
|||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
"""
|
||||||
|
AllOverlaysTemplate = """[Unit]
|
||||||
|
Description=Groups all overlays required by {PN} in one unit
|
||||||
|
After={ALL_OVERLAYFS_UNITS}
|
||||||
|
Requires={ALL_OVERLAYFS_UNITS}
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/bin/true
|
||||||
|
RemainAfterExit=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=local-fs.target
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def prepareUnits(data, lower):
|
def prepareUnits(data, lower):
|
||||||
from oe.overlayfs import mountUnitName, helperUnitName
|
from oe.overlayfs import helperUnitName
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
'DATA_MOUNT_POINT': data,
|
'DATA_MOUNT_POINT': data,
|
||||||
@@ -83,10 +98,27 @@ WantedBy=multi-user.target
|
|||||||
with open(os.path.join(d.getVar('WORKDIR'), helperUnitName(lower)), 'w') as f:
|
with open(os.path.join(d.getVar('WORKDIR'), helperUnitName(lower)), 'w') as f:
|
||||||
f.write(CreateDirsUnitTemplate.format(**args))
|
f.write(CreateDirsUnitTemplate.format(**args))
|
||||||
|
|
||||||
|
def prepareGlobalUnit(dependentUnits):
|
||||||
|
from oe.overlayfs import allOverlaysUnitName
|
||||||
|
args = {
|
||||||
|
'ALL_OVERLAYFS_UNITS': " ".join(dependentUnits),
|
||||||
|
'PN': d.getVar('PN')
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(os.path.join(d.getVar('WORKDIR'), allOverlaysUnitName(d)), 'w') as f:
|
||||||
|
f.write(AllOverlaysTemplate.format(**args))
|
||||||
|
|
||||||
|
mountUnitList = []
|
||||||
overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
|
overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
|
||||||
for mountPoint in overlayMountPoints:
|
for mountPoint in overlayMountPoints:
|
||||||
for lower in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
|
for lower in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
|
||||||
prepareUnits(d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint), lower)
|
prepareUnits(d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint), lower)
|
||||||
|
mountUnitList.append(mountUnitName(lower))
|
||||||
|
|
||||||
|
# set up one unit, which depends on all mount units, so users can set
|
||||||
|
# only one dependency in their units to make sure software starts
|
||||||
|
# when all overlays are mounted
|
||||||
|
prepareGlobalUnit(mountUnitList)
|
||||||
}
|
}
|
||||||
|
|
||||||
# we need to generate file names early during parsing stage
|
# we need to generate file names early during parsing stage
|
||||||
@@ -95,7 +127,7 @@ python () {
|
|||||||
|
|
||||||
unitList = unitFileList(d)
|
unitList = unitFileList(d)
|
||||||
for unit in unitList:
|
for unit in unitList:
|
||||||
d.appendVar('SYSTEMD_SERVICE:' + d.getVar('PN'), ' ' + unit);
|
d.appendVar('SYSTEMD_SERVICE:' + d.getVar('PN'), ' ' + unit)
|
||||||
d.appendVar('FILES:' + d.getVar('PN'), ' ' + strForBash(unit))
|
d.appendVar('FILES:' + d.getVar('PN'), ' ' + strForBash(unit))
|
||||||
|
|
||||||
d.setVar('OVERLAYFS_UNIT_LIST', ' '.join([strForBash(s) for s in unitList]))
|
d.setVar('OVERLAYFS_UNIT_LIST', ' '.join([strForBash(s) for s in unitList]))
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ def escapeSystemdUnitName(path):
|
|||||||
def strForBash(s):
|
def strForBash(s):
|
||||||
return s.replace('\\', '\\\\')
|
return s.replace('\\', '\\\\')
|
||||||
|
|
||||||
|
def allOverlaysUnitName(d):
|
||||||
|
return d.getVar('PN') + '-overlays.service'
|
||||||
|
|
||||||
def mountUnitName(unit):
|
def mountUnitName(unit):
|
||||||
return escapeSystemdUnitName(unit) + '.mount'
|
return escapeSystemdUnitName(unit) + '.mount'
|
||||||
|
|
||||||
@@ -39,5 +42,7 @@ def unitFileList(d):
|
|||||||
fileList.append(mountUnitName(path))
|
fileList.append(mountUnitName(path))
|
||||||
fileList.append(helperUnitName(path))
|
fileList.append(helperUnitName(path))
|
||||||
|
|
||||||
|
fileList.append(allOverlaysUnitName(d))
|
||||||
|
|
||||||
return fileList
|
return fileList
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user