summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/volatile-binds/files/mount-copybind
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/volatile-binds/files/mount-copybind')
-rwxr-xr-xmeta/recipes-core/volatile-binds/files/mount-copybind29
1 files changed, 28 insertions, 1 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