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-copybind36
-rw-r--r--meta/recipes-core/volatile-binds/files/volatile-binds.service.in7
-rw-r--r--meta/recipes-core/volatile-binds/volatile-binds.bb36
3 files changed, 56 insertions, 23 deletions
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind
index e32e675308..5885880534 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,21 +34,42 @@ 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
37 overlay_workdir="${spec%/*}/.${spec##*/}-work" 47 overlay_workdir="${spec%/*}/.${spec##*/}-work"
38 mkdir "${overlay_workdir}" 48 if [ "$MOUNT_COPYBIND_AVOID_OVERLAYFS" != 1 ]; then
49 mkdir "${overlay_workdir}"
50 fi
39 51
40 # Try to mount using overlay, which is must faster than copying files. 52 # Try to mount using overlay, which is much faster than copying files.
41 # If that fails, fall back to slower copy. 53 # 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 54 if command -v selinuxenabled > /dev/null 2>&1; then
55 if selinuxenabled; then
56 mountcontext=",rootcontext=$(matchpathcon -n "$mountpoint")"
57 fi
58 fi
59 if [ "$MOUNT_COPYBIND_AVOID_OVERLAYFS" = 1 ] || ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir""$mountcontext" "$mountpoint" > /dev/null 2>&1; then
60 rm -rf "$overlay_workdir"
43 61
44 if [ "$specdir_existed" != "yes" ]; then 62 if [ "$specdir_existed" != "yes" ]; then
45 cp -aPR "$mountpoint"/. "$spec/" 63 cp -aPR "$mountpoint"/. "$spec/"
46 fi 64 fi
47 65
48 mount -o "bind$options" "$spec" "$mountpoint" 66 mount -o "bind$options" "$spec" "$mountpoint"
67 # restore the selinux context.
68 if command -v selinuxenabled > /dev/null 2>&1; then
69 if selinuxenabled; then
70 restorecon -R "$mountpoint"
71 fi
72 fi
49 fi 73 fi
50elif [ -f "$mountpoint" ]; then 74elif [ -f "$mountpoint" ]; then
51 if [ ! -f "$spec" ]; then 75 if [ ! -f "$spec" ]; then
@@ -53,4 +77,10 @@ elif [ -f "$mountpoint" ]; then
53 fi 77 fi
54 78
55 mount -o "bind$options" "$spec" "$mountpoint" 79 mount -o "bind$options" "$spec" "$mountpoint"
80 # restore the selinux context.
81 if command -v selinuxenabled > /dev/null 2>&1; then
82 if selinuxenabled; then
83 restorecon -R "$mountpoint"
84 fi
85 fi
56fi 86fi
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..857bcc93ff 100644
--- a/meta/recipes-core/volatile-binds/volatile-binds.bb
+++ b/meta/recipes-core/volatile-binds/volatile-binds.bb
@@ -9,17 +9,17 @@ SRC_URI = "\
9 file://volatile-binds.service.in \ 9 file://volatile-binds.service.in \
10" 10"
11 11
12S = "${WORKDIR}" 12S = "${UNPACKDIR}"
13 13
14inherit allarch systemd features_check 14inherit allarch systemd features_check
15 15
16REQUIRED_DISTRO_FEATURES = "systemd" 16REQUIRED_DISTRO_FEATURES = "systemd"
17 17
18VOLATILE_BINDS ?= "\ 18VOLATILE_BINDS ?= "\
19 /var/volatile/lib /var/lib\n\ 19 ${localstatedir}/volatile/lib ${localstatedir}/lib\n\
20 /var/volatile/cache /var/cache\n\ 20 ${localstatedir}/volatile/cache ${localstatedir}/cache\n\
21 /var/volatile/spool /var/spool\n\ 21 ${localstatedir}/volatile/spool ${localstatedir}/spool\n\
22 /var/volatile/srv /srv\n\ 22 ${localstatedir}/volatile/srv /srv\n\
23" 23"
24VOLATILE_BINDS[type] = "list" 24VOLATILE_BINDS[type] = "list"
25VOLATILE_BINDS[separator] = "\n" 25VOLATILE_BINDS[separator] = "\n"
@@ -33,9 +33,12 @@ def volatile_systemd_services(d):
33 services.append("%s.service" % what[1:].replace("/", "-")) 33 services.append("%s.service" % what[1:].replace("/", "-"))
34 return " ".join(services) 34 return " ".join(services)
35 35
36SYSTEMD_SERVICE_${PN} = "${@volatile_systemd_services(d)}" 36SYSTEMD_SERVICE:${PN} = "${@volatile_systemd_services(d)}"
37 37
38FILES_${PN} += "${systemd_unitdir}/system/*.service ${servicedir}" 38FILES:${PN} += "${systemd_system_unitdir}/*.service ${servicedir}"
39
40# Set to 1 to forcibly skip OverlayFS, and default to copy+bind
41AVOID_OVERLAYFS = "0"
39 42
40do_compile () { 43do_compile () {
41 while read spec mountpoint; do 44 while read spec mountpoint; do
@@ -43,39 +46,38 @@ do_compile () {
43 continue 46 continue
44 fi 47 fi
45 48
46 servicefile="${spec#/}" 49 servicefile="$(echo "${spec#/}" | tr / -).service"
47 servicefile="$(echo "$servicefile" | tr / -).service" 50 [ "$mountpoint" != ${localstatedir}/lib ] || var_lib_servicefile=$servicefile
48 sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \ 51 sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \
49 -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \ 52 -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \
53 -e "s#@avoid_overlayfs@#${@d.getVar('AVOID_OVERLAYFS')}#g" \
50 volatile-binds.service.in >$servicefile 54 volatile-binds.service.in >$servicefile
51 done <<END 55 done <<END
52${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")} 56${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")}
53END 57END
54 58
55 if [ -e var-volatile-lib.service ]; then 59 if [ -e "$var_lib_servicefile" ]; then
56 # As the seed is stored under /var/lib, ensure that this service runs 60 # As the seed is stored under /var/lib, ensure that this service runs
57 # after the volatile /var/lib is mounted. 61 # after the volatile /var/lib is mounted.
58 sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \ 62 sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \
59 -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \ 63 -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \
60 var-volatile-lib.service 64 "$var_lib_servicefile"
61 fi 65 fi
62} 66}
63do_compile[dirs] = "${WORKDIR}"
64 67
65do_install () { 68do_install () {
66 install -d ${D}${base_sbindir} 69 install -d ${D}${base_sbindir}
67 install -d ${D}${servicedir} 70 install -d ${D}${servicedir}
68 install -m 0755 mount-copybind ${D}${base_sbindir}/ 71 install -m 0755 mount-copybind ${D}${base_sbindir}/
69 72
70 install -d ${D}${systemd_unitdir}/system 73 install -d ${D}${systemd_system_unitdir}
71 for service in ${SYSTEMD_SERVICE_${PN}}; do 74 for service in ${SYSTEMD_SERVICE:${PN}}; do
72 install -m 0644 $service ${D}${systemd_unitdir}/system/ 75 install -m 0644 $service ${D}${systemd_system_unitdir}/
73 done 76 done
74 77
75 # Suppress attempts to process some tmpfiles that are not temporary. 78 # Suppress attempts to process some tmpfiles that are not temporary.
76 # 79 #
77 install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache 80 install -d ${D}${sysconfdir}/tmpfiles.d ${D}${localstatedir}/cache
78 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf 81 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf
79 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf 82 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf
80} 83}
81do_install[dirs] = "${WORKDIR}"