diff options
Diffstat (limited to 'meta/recipes-core/volatile-binds/files')
-rwxr-xr-x | meta/recipes-core/volatile-binds/files/mount-copybind | 29 | ||||
-rw-r--r-- | meta/recipes-core/volatile-binds/files/volatile-binds.service.in | 7 |
2 files changed, 32 insertions, 4 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 | ||
6 | if [ $# -lt 2 ]; then | 9 | if [ $# -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 |
50 | elif [ -f "$mountpoint" ]; then | 71 | elif [ -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 | ||
56 | fi | 83 | fi |
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] |
2 | Description=Bind mount volatile @where@ | 2 | Description=Bind mount volatile @where@ |
3 | DefaultDependencies=false | 3 | DefaultDependencies=no |
4 | Before=local-fs.target | 4 | Before=local-fs.target |
5 | RequiresMountsFor=@whatparent@ @whereparent@ | 5 | RequiresMountsFor=@whatparent@ @whereparent@ |
6 | ConditionPathIsReadWrite=@whatparent@ | 6 | ConditionPathIsReadWrite=|@whatparent@ |
7 | ConditionPathExists=|!@whatparent@ | ||
7 | ConditionPathExists=@where@ | 8 | ConditionPathExists=@where@ |
8 | ConditionPathIsReadWrite=!@where@ | 9 | ConditionPathIsReadWrite=!@where@ |
9 | 10 | ||
10 | [Service] | 11 | [Service] |
11 | Type=oneshot | 12 | Type=oneshot |
12 | RemainAfterExit=Yes | 13 | RemainAfterExit=Yes |
13 | TimeoutSec=0 | 14 | Environment=MOUNT_COPYBIND_AVOID_OVERLAYFS=@avoid_overlayfs@ |
14 | ExecStart=/sbin/mount-copybind @what@ @where@ | 15 | ExecStart=/sbin/mount-copybind @what@ @where@ |
15 | ExecStop=/bin/umount @where@ | 16 | ExecStop=/bin/umount @where@ |
16 | 17 | ||