summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/volatile-binds
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/volatile-binds')
-rwxr-xr-xmeta/recipes-core/volatile-binds/files/mount-copybind29
-rw-r--r--meta/recipes-core/volatile-binds/files/volatile-binds.service.in7
-rw-r--r--meta/recipes-core/volatile-binds/volatile-binds.bb37
3 files changed, 52 insertions, 21 deletions
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind
index e32e675308..ddc4357615 100755
--- a/meta/recipes-core/volatile-binds/files/mount-copybind
+++ b/meta/recipes-core/volatile-binds/files/mount-copybind
@@ -2,6 +2,9 @@
2# 2#
3# Perform a bind mount, copying existing files as we do so to ensure the 3# Perform a bind mount, copying existing files as we do so to ensure the
4# overlaid path has the necessary content. 4# overlaid path has the necessary content.
5# If the target is a directory and overlayfs is available (and the environment
6# variable MOUNT_COPYBIND_AVOID_OVERLAYFS=1 is not set), then an overlay mount
7# will be attempted first.
5 8
6if [ $# -lt 2 ]; then 9if [ $# -lt 2 ]; then
7 echo >&2 "Usage: $0 spec mountpoint [OPTIONS]" 10 echo >&2 "Usage: $0 spec mountpoint [OPTIONS]"
@@ -31,6 +34,13 @@ if [ -d "$mountpoint" ]; then
31 else 34 else
32 specdir_existed=no 35 specdir_existed=no
33 mkdir "$spec" 36 mkdir "$spec"
37 # If the $spec directory is created we need to take care that
38 # the selinux context is correct
39 if command -v selinuxenabled > /dev/null 2>&1; then
40 if selinuxenabled; then
41 restorecon "$spec"
42 fi
43 fi
34 fi 44 fi
35 45
36 # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work 46 # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work
@@ -39,13 +49,24 @@ if [ -d "$mountpoint" ]; then
39 49
40 # Try to mount using overlay, which is must faster than copying files. 50 # Try to mount using overlay, which is must faster than copying files.
41 # If that fails, fall back to slower copy. 51 # If that fails, fall back to slower copy.
42 if ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir" "$mountpoint" > /dev/null 2>&1; then 52 if command -v selinuxenabled > /dev/null 2>&1; then
53 if selinuxenabled; then
54 mountcontext=",rootcontext=$(matchpathcon -n "$mountpoint")"
55 fi
56 fi
57 if [ "$MOUNT_COPYBIND_AVOID_OVERLAYFS" = 1 ] || ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir""$mountcontext" "$mountpoint" > /dev/null 2>&1; then
43 58
44 if [ "$specdir_existed" != "yes" ]; then 59 if [ "$specdir_existed" != "yes" ]; then
45 cp -aPR "$mountpoint"/. "$spec/" 60 cp -aPR "$mountpoint"/. "$spec/"
46 fi 61 fi
47 62
48 mount -o "bind$options" "$spec" "$mountpoint" 63 mount -o "bind$options" "$spec" "$mountpoint"
64 # restore the selinux context.
65 if command -v selinuxenabled > /dev/null 2>&1; then
66 if selinuxenabled; then
67 restorecon -R "$mountpoint"
68 fi
69 fi
49 fi 70 fi
50elif [ -f "$mountpoint" ]; then 71elif [ -f "$mountpoint" ]; then
51 if [ ! -f "$spec" ]; then 72 if [ ! -f "$spec" ]; then
@@ -53,4 +74,10 @@ elif [ -f "$mountpoint" ]; then
53 fi 74 fi
54 75
55 mount -o "bind$options" "$spec" "$mountpoint" 76 mount -o "bind$options" "$spec" "$mountpoint"
77 # restore the selinux context.
78 if command -v selinuxenabled > /dev/null 2>&1; then
79 if selinuxenabled; then
80 restorecon -R "$mountpoint"
81 fi
82 fi
56fi 83fi
diff --git a/meta/recipes-core/volatile-binds/files/volatile-binds.service.in b/meta/recipes-core/volatile-binds/files/volatile-binds.service.in
index e2ad39f258..5a0055bec3 100644
--- a/meta/recipes-core/volatile-binds/files/volatile-binds.service.in
+++ b/meta/recipes-core/volatile-binds/files/volatile-binds.service.in
@@ -1,16 +1,17 @@
1[Unit] 1[Unit]
2Description=Bind mount volatile @where@ 2Description=Bind mount volatile @where@
3DefaultDependencies=false 3DefaultDependencies=no
4Before=local-fs.target 4Before=local-fs.target
5RequiresMountsFor=@whatparent@ @whereparent@ 5RequiresMountsFor=@whatparent@ @whereparent@
6ConditionPathIsReadWrite=@whatparent@ 6ConditionPathIsReadWrite=|@whatparent@
7ConditionPathExists=|!@whatparent@
7ConditionPathExists=@where@ 8ConditionPathExists=@where@
8ConditionPathIsReadWrite=!@where@ 9ConditionPathIsReadWrite=!@where@
9 10
10[Service] 11[Service]
11Type=oneshot 12Type=oneshot
12RemainAfterExit=Yes 13RemainAfterExit=Yes
13TimeoutSec=0 14Environment=MOUNT_COPYBIND_AVOID_OVERLAYFS=@avoid_overlayfs@
14ExecStart=/sbin/mount-copybind @what@ @where@ 15ExecStart=/sbin/mount-copybind @what@ @where@
15ExecStop=/bin/umount @where@ 16ExecStop=/bin/umount @where@
16 17
diff --git a/meta/recipes-core/volatile-binds/volatile-binds.bb b/meta/recipes-core/volatile-binds/volatile-binds.bb
index 3c8b18291e..3597ec7356 100644
--- a/meta/recipes-core/volatile-binds/volatile-binds.bb
+++ b/meta/recipes-core/volatile-binds/volatile-binds.bb
@@ -9,17 +9,18 @@ SRC_URI = "\
9 file://volatile-binds.service.in \ 9 file://volatile-binds.service.in \
10" 10"
11 11
12S = "${WORKDIR}" 12S = "${WORKDIR}/sources"
13UNPACKDIR = "${S}"
13 14
14inherit allarch systemd features_check 15inherit allarch systemd features_check
15 16
16REQUIRED_DISTRO_FEATURES = "systemd" 17REQUIRED_DISTRO_FEATURES = "systemd"
17 18
18VOLATILE_BINDS ?= "\ 19VOLATILE_BINDS ?= "\
19 /var/volatile/lib /var/lib\n\ 20 ${localstatedir}/volatile/lib ${localstatedir}/lib\n\
20 /var/volatile/cache /var/cache\n\ 21 ${localstatedir}/volatile/cache ${localstatedir}/cache\n\
21 /var/volatile/spool /var/spool\n\ 22 ${localstatedir}/volatile/spool ${localstatedir}/spool\n\
22 /var/volatile/srv /srv\n\ 23 ${localstatedir}/volatile/srv /srv\n\
23" 24"
24VOLATILE_BINDS[type] = "list" 25VOLATILE_BINDS[type] = "list"
25VOLATILE_BINDS[separator] = "\n" 26VOLATILE_BINDS[separator] = "\n"
@@ -33,9 +34,12 @@ def volatile_systemd_services(d):
33 services.append("%s.service" % what[1:].replace("/", "-")) 34 services.append("%s.service" % what[1:].replace("/", "-"))
34 return " ".join(services) 35 return " ".join(services)
35 36
36SYSTEMD_SERVICE_${PN} = "${@volatile_systemd_services(d)}" 37SYSTEMD_SERVICE:${PN} = "${@volatile_systemd_services(d)}"
37 38
38FILES_${PN} += "${systemd_unitdir}/system/*.service ${servicedir}" 39FILES:${PN} += "${systemd_system_unitdir}/*.service ${servicedir}"
40
41# Set to 1 to forcibly skip OverlayFS, and default to copy+bind
42AVOID_OVERLAYFS = "0"
39 43
40do_compile () { 44do_compile () {
41 while read spec mountpoint; do 45 while read spec mountpoint; do
@@ -43,39 +47,38 @@ do_compile () {
43 continue 47 continue
44 fi 48 fi
45 49
46 servicefile="${spec#/}" 50 servicefile="$(echo "${spec#/}" | tr / -).service"
47 servicefile="$(echo "$servicefile" | tr / -).service" 51 [ "$mountpoint" != ${localstatedir}/lib ] || var_lib_servicefile=$servicefile
48 sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \ 52 sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \
49 -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \ 53 -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \
54 -e "s#@avoid_overlayfs@#${@d.getVar('AVOID_OVERLAYFS')}#g" \
50 volatile-binds.service.in >$servicefile 55 volatile-binds.service.in >$servicefile
51 done <<END 56 done <<END
52${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")} 57${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")}
53END 58END
54 59
55 if [ -e var-volatile-lib.service ]; then 60 if [ -e "$var_lib_servicefile" ]; then
56 # As the seed is stored under /var/lib, ensure that this service runs 61 # As the seed is stored under /var/lib, ensure that this service runs
57 # after the volatile /var/lib is mounted. 62 # after the volatile /var/lib is mounted.
58 sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \ 63 sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \
59 -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \ 64 -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \
60 var-volatile-lib.service 65 "$var_lib_servicefile"
61 fi 66 fi
62} 67}
63do_compile[dirs] = "${WORKDIR}"
64 68
65do_install () { 69do_install () {
66 install -d ${D}${base_sbindir} 70 install -d ${D}${base_sbindir}
67 install -d ${D}${servicedir} 71 install -d ${D}${servicedir}
68 install -m 0755 mount-copybind ${D}${base_sbindir}/ 72 install -m 0755 mount-copybind ${D}${base_sbindir}/
69 73
70 install -d ${D}${systemd_unitdir}/system 74 install -d ${D}${systemd_system_unitdir}
71 for service in ${SYSTEMD_SERVICE_${PN}}; do 75 for service in ${SYSTEMD_SERVICE:${PN}}; do
72 install -m 0644 $service ${D}${systemd_unitdir}/system/ 76 install -m 0644 $service ${D}${systemd_system_unitdir}/
73 done 77 done
74 78
75 # Suppress attempts to process some tmpfiles that are not temporary. 79 # Suppress attempts to process some tmpfiles that are not temporary.
76 # 80 #
77 install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache 81 install -d ${D}${sysconfdir}/tmpfiles.d ${D}${localstatedir}/cache
78 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf 82 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf
79 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf 83 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf
80} 84}
81do_install[dirs] = "${WORKDIR}"