summaryrefslogtreecommitdiffstats
path: root/meta/classes/overlayfs.bbclass
diff options
context:
space:
mode:
authorVyacheslav Yurkov <uvv.mail@gmail.com>2021-10-17 10:08:55 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-10-30 22:31:52 +0100
commit9c8ea9dcf1ea1b5b4c5212a306a6dd89d86b1d5a (patch)
tree81bca1c066170c2226001c0efd9b4db16fa1b84a /meta/classes/overlayfs.bbclass
parentd81238da5709d16ebf9437420272f24221f2f51a (diff)
downloadpoky-9c8ea9dcf1ea1b5b4c5212a306a6dd89d86b1d5a.tar.gz
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>
Diffstat (limited to 'meta/classes/overlayfs.bbclass')
-rw-r--r--meta/classes/overlayfs.bbclass36
1 files changed, 34 insertions, 2 deletions
diff --git a/meta/classes/overlayfs.bbclass b/meta/classes/overlayfs.bbclass
index 8d9b59c9bf..9397ab44f9 100644
--- a/meta/classes/overlayfs.bbclass
+++ b/meta/classes/overlayfs.bbclass
@@ -37,6 +37,8 @@ REQUIRED_DISTRO_FEATURES += "systemd overlayfs"
37inherit systemd features_check 37inherit systemd features_check
38 38
39python do_create_overlayfs_units() { 39python do_create_overlayfs_units() {
40 from oe.overlayfs import mountUnitName
41
40 CreateDirsUnitTemplate = """[Unit] 42 CreateDirsUnitTemplate = """[Unit]
41Description=Overlayfs directories setup 43Description=Overlayfs directories setup
42Requires={DATA_MOUNT_UNIT} 44Requires={DATA_MOUNT_UNIT}
@@ -66,9 +68,22 @@ Options=lowerdir={LOWERDIR},upperdir={DATA_MOUNT_POINT}/upper{LOWERDIR},workdir=
66[Install] 68[Install]
67WantedBy=multi-user.target 69WantedBy=multi-user.target
68""" 70"""
71 AllOverlaysTemplate = """[Unit]
72Description=Groups all overlays required by {PN} in one unit
73After={ALL_OVERLAYFS_UNITS}
74Requires={ALL_OVERLAYFS_UNITS}
75
76[Service]
77Type=oneshot
78ExecStart=/bin/true
79RemainAfterExit=true
80
81[Install]
82WantedBy=local-fs.target
83"""
69 84
70 def prepareUnits(data, lower): 85 def prepareUnits(data, lower):
71 from oe.overlayfs import mountUnitName, helperUnitName 86 from oe.overlayfs import helperUnitName
72 87
73 args = { 88 args = {
74 'DATA_MOUNT_POINT': data, 89 'DATA_MOUNT_POINT': data,
@@ -83,10 +98,27 @@ WantedBy=multi-user.target
83 with open(os.path.join(d.getVar('WORKDIR'), helperUnitName(lower)), 'w') as f: 98 with open(os.path.join(d.getVar('WORKDIR'), helperUnitName(lower)), 'w') as f:
84 f.write(CreateDirsUnitTemplate.format(**args)) 99 f.write(CreateDirsUnitTemplate.format(**args))
85 100
101 def prepareGlobalUnit(dependentUnits):
102 from oe.overlayfs import allOverlaysUnitName
103 args = {
104 'ALL_OVERLAYFS_UNITS': " ".join(dependentUnits),
105 'PN': d.getVar('PN')
106 }
107
108 with open(os.path.join(d.getVar('WORKDIR'), allOverlaysUnitName(d)), 'w') as f:
109 f.write(AllOverlaysTemplate.format(**args))
110
111 mountUnitList = []
86 overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT") 112 overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
87 for mountPoint in overlayMountPoints: 113 for mountPoint in overlayMountPoints:
88 for lower in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split(): 114 for lower in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
89 prepareUnits(d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint), lower) 115 prepareUnits(d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint), lower)
116 mountUnitList.append(mountUnitName(lower))
117
118 # set up one unit, which depends on all mount units, so users can set
119 # only one dependency in their units to make sure software starts
120 # when all overlays are mounted
121 prepareGlobalUnit(mountUnitList)
90} 122}
91 123
92# we need to generate file names early during parsing stage 124# we need to generate file names early during parsing stage
@@ -95,7 +127,7 @@ python () {
95 127
96 unitList = unitFileList(d) 128 unitList = unitFileList(d)
97 for unit in unitList: 129 for unit in unitList:
98 d.appendVar('SYSTEMD_SERVICE:' + d.getVar('PN'), ' ' + unit); 130 d.appendVar('SYSTEMD_SERVICE:' + d.getVar('PN'), ' ' + unit)
99 d.appendVar('FILES:' + d.getVar('PN'), ' ' + strForBash(unit)) 131 d.appendVar('FILES:' + d.getVar('PN'), ' ' + strForBash(unit))
100 132
101 d.setVar('OVERLAYFS_UNIT_LIST', ' '.join([strForBash(s) for s in unitList])) 133 d.setVar('OVERLAYFS_UNIT_LIST', ' '.join([strForBash(s) for s in unitList]))