2 # overlayfs specific common functions.
6 # helper function to do the actual overlayfs mount operation
14 $MOUNT_PROG -t overlay -o lowerdir=$lowerdir -o upperdir=$upperdir \
15 -o workdir=$workdir `_common_dev_mount_options $*`
18 # Mount with same options/mnt/dev of scratch mount, but optionally
19 # with different lower/upper/work dirs
20 _overlay_scratch_mount_dirs()
27 _overlay_mount_dirs $lowerdir $upperdir $workdir \
28 $* $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT
35 mkdir -p $dir/$OVL_UPPER
36 mkdir -p $dir/$OVL_LOWER
37 mkdir -p $dir/$OVL_WORK
38 mkdir -p $dir/$OVL_MNT
41 # Given a base fs dir, set up overlay directories and mount on the given mnt.
42 # The dir is used as the mount device so it can be seen from df or mount
49 _supports_filetype $dir || _notrun "upper fs needs to support d_type"
53 _overlay_mount_dirs $dir/$OVL_LOWER $dir/$OVL_UPPER $dir/$OVL_WORK \
65 if [ -z "$dev" -o -z "$mnt" ] || \
66 _check_mounted_on $devname $dev $mntname $mnt; then
67 # no base fs or already mounted
69 elif [ $? -ne 1 ]; then
70 # base fs mounted but not on mount point
77 _overlay_base_test_mount()
79 _overlay_base_mount OVL_BASE_TEST_DEV OVL_BASE_TEST_DIR \
80 "$OVL_BASE_TEST_DEV" "$OVL_BASE_TEST_DIR" \
81 $TEST_FS_MOUNT_OPTS $SELINUX_MOUNT_OPTIONS
86 _overlay_base_test_mount && \
87 _overlay_mount $OVL_BASE_TEST_DIR $TEST_DIR $*
90 _overlay_base_scratch_mount()
92 _overlay_base_mount OVL_BASE_SCRATCH_DEV OVL_BASE_SCRATCH_MNT \
93 "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT" \
94 $OVL_BASE_MOUNT_OPTIONS $SELINUX_MOUNT_OPTIONS
97 _overlay_scratch_mount()
99 _overlay_base_scratch_mount && \
100 _overlay_mount $OVL_BASE_SCRATCH_MNT $SCRATCH_MNT $*
103 _overlay_base_unmount()
108 [ -n "$dev" -a -n "$mnt" ] || return 0
113 _overlay_test_unmount()
115 $UMOUNT_PROG $TEST_DIR
116 _overlay_base_unmount "$OVL_BASE_TEST_DEV" "$OVL_BASE_TEST_DIR"
119 _overlay_scratch_unmount()
121 $UMOUNT_PROG $SCRATCH_MNT
122 _overlay_base_unmount "$OVL_BASE_SCRATCH_DEV" "$OVL_BASE_SCRATCH_MNT"
125 # Check that a specific overlayfs feature is supported
126 __check_scratch_overlay_feature()
130 # overalyfs features (e.g. redirect_dir, index) are
131 # configurable from Kconfig (the build default), by module
132 # parameter (the system default) and per mount by mount
133 # option ${feature}=[on|off].
135 # If the module parameter does not exist then there is no
136 # point in checking the mount option.
137 local default=`_get_fs_module_param ${feature}`
138 [ "$default" = Y ] || [ "$default" = N ] || \
139 _notrun "feature '${feature}' not supported by ${FSTYP}"
141 # Check options to be sure. For example, Overlayfs will fallback to
142 # index=off if underlying fs does not support file handles.
143 # Overlayfs only displays mount option if it differs from the default.
144 # Overlayfs may enable the feature, but fallback to read-only mount.
145 ((( [ "$default" = N ] && _fs_options $SCRATCH_DEV | grep -q "${feature}=on" ) || \
146 ( [ "$default" = Y ] && ! _fs_options $SCRATCH_DEV | grep -q "${feature}=off" )) && \
147 touch $SCRATCH_MNT/foo 2>/dev/null ) || \
148 _notrun "${FSTYP} feature '${feature}' cannot be enabled on ${SCRATCH_DEV}"
151 # Require a set of overlayfs features
152 _require_scratch_overlay_features()
154 local features=( $* )
157 for feature in ${features[*]}; do
158 opts+=",${feature}=on"
161 _scratch_mkfs > /dev/null 2>&1
162 _scratch_mount -o $opts || \
163 _notrun "overlay options '$opts' cannot be enabled on ${SCRATCH_DEV}"
165 for feature in ${features[*]}; do
166 __check_scratch_overlay_feature ${feature}
172 # Helper function to check underlying dirs of overlay filesystem
180 [[ ! -x "$FSCK_OVERLAY_PROG" ]] && return 0
182 $FSCK_OVERLAY_PROG -o lowerdir=$lowerdir -o upperdir=$upperdir \
183 -o workdir=$workdir $*