rootfs-block: avoid remount when options don't change

Mounting, unmounting and then mounting a disk partition takes some
time.

On embedded systems such as OLPC XO where we disable fsck and fstab
reading, the root options are not going to change throughout the
mount_root() function, so remounting is time consuming and without
change.

Detect and optimize for this case so that the filesystem is only
mounted once.
master
Daniel Drake 2012-04-11 23:00:43 +01:00 committed by Harald Hoyer
parent bd3bf2ce41
commit 6625b74e90
1 changed files with 8 additions and 4 deletions

View File

@ -98,20 +98,24 @@ mount_root() {
# them; rflags is guaranteed to not be empty # them; rflags is guaranteed to not be empty
rflags="${rootopts:+"${rootopts},"}${rflags}" rflags="${rootopts:+"${rootopts},"}${rflags}"


umount "$NEWROOT"

# backslashes are treated as escape character in fstab # backslashes are treated as escape character in fstab
# esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g') # esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g')
# printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab # printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab


ran_fsck=0
if [ -z "$fastboot" -a "$READONLY" != "yes" ] && ! strstr "${rflags},${rootopts}" _netdev; then if [ -z "$fastboot" -a "$READONLY" != "yes" ] && ! strstr "${rflags},${rootopts}" _netdev; then
umount "$NEWROOT"
fsck_single "${root#block:}" "$rootfs" "$fsckoptions" fsck_single "${root#block:}" "$rootfs" "$fsckoptions"
_ret=$? _ret=$?
[ $_ret -ne 255 ] && echo $_ret >/run/initramfs/root-fsck [ $_ret -ne 255 ] && echo $_ret >/run/initramfs/root-fsck
ran_fsck=1
fi fi


info "Remounting ${root#block:} with -o ${rflags}" if [ -n "$rootopts" -o "$ran_fsck" = "1" ]; then
mount -t "$rootfs" -o "$rflags" "${root#block:}" "$NEWROOT" 2>&1 | vinfo info "Remounting ${root#block:} with -o ${rflags}"
umount "$NEWROOT" &>/dev/null
mount -t "$rootfs" -o "$rflags" "${root#block:}" "$NEWROOT" 2>&1 | vinfo
fi


[ -f "$NEWROOT"/forcefsck ] && rm -f "$NEWROOT"/forcefsck 2>/dev/null [ -f "$NEWROOT"/forcefsck ] && rm -f "$NEWROOT"/forcefsck 2>/dev/null
[ -f "$NEWROOT"/.autofsck ] && rm -f "$NEWROOT"/.autofsck 2>/dev/null [ -f "$NEWROOT"/.autofsck ] && rm -f "$NEWROOT"/.autofsck 2>/dev/null