Blame 0006-rootfs-block-avoid-remount-when-options-don-t-change.patch

Harald Hoyer ab65ae
From 6625b74e90a0b6918c90c408215e76719e459883 Mon Sep 17 00:00:00 2001
Harald Hoyer ab65ae
From: Daniel Drake <dsd@laptop.org>
Harald Hoyer ab65ae
Date: Wed, 11 Apr 2012 23:00:43 +0100
Harald Hoyer ab65ae
Subject: [PATCH] rootfs-block: avoid remount when options don't change
Harald Hoyer ab65ae
Harald Hoyer ab65ae
Mounting, unmounting and then mounting a disk partition takes some
Harald Hoyer ab65ae
time.
Harald Hoyer ab65ae
Harald Hoyer ab65ae
On embedded systems such as OLPC XO where we disable fsck and fstab
Harald Hoyer ab65ae
reading, the root options are not going to change throughout the
Harald Hoyer ab65ae
mount_root() function, so remounting is time consuming and without
Harald Hoyer ab65ae
change.
Harald Hoyer ab65ae
Harald Hoyer ab65ae
Detect and optimize for this case so that the filesystem is only
Harald Hoyer ab65ae
mounted once.
Harald Hoyer ab65ae
---
Harald Hoyer ab65ae
 modules.d/95rootfs-block/mount-root.sh |   12 ++++++++----
Harald Hoyer ab65ae
 1 file changed, 8 insertions(+), 4 deletions(-)
Harald Hoyer ab65ae
Harald Hoyer ab65ae
diff --git a/modules.d/95rootfs-block/mount-root.sh b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer ab65ae
index 2c89431..aef99ae 100755
Harald Hoyer ab65ae
--- a/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer ab65ae
+++ b/modules.d/95rootfs-block/mount-root.sh
Harald Hoyer ab65ae
@@ -98,20 +98,24 @@ mount_root() {
Harald Hoyer ab65ae
     # them; rflags is guaranteed to not be empty
Harald Hoyer ab65ae
     rflags="${rootopts:+"${rootopts},"}${rflags}"
Harald Hoyer ab65ae
 
Harald Hoyer ab65ae
-    umount "$NEWROOT"
Harald Hoyer ab65ae
-
Harald Hoyer ab65ae
     # backslashes are treated as escape character in fstab
Harald Hoyer ab65ae
     # esc_root=$(echo ${root#block:} | sed 's,\\,\\\\,g')
Harald Hoyer ab65ae
     # printf '%s %s %s %s 1 1 \n' "$esc_root" "$NEWROOT" "$rootfs" "$rflags" >/etc/fstab
Harald Hoyer ab65ae
 
Harald Hoyer ab65ae
+    ran_fsck=0
Harald Hoyer ab65ae
     if [ -z "$fastboot" -a "$READONLY" != "yes" ] && ! strstr "${rflags},${rootopts}" _netdev; then
Harald Hoyer ab65ae
+        umount "$NEWROOT"
Harald Hoyer ab65ae
         fsck_single "${root#block:}" "$rootfs" "$fsckoptions"
Harald Hoyer ab65ae
         _ret=$?
Harald Hoyer ab65ae
         [ $_ret -ne 255 ] && echo $_ret >/run/initramfs/root-fsck
Harald Hoyer ab65ae
+        ran_fsck=1
Harald Hoyer ab65ae
     fi
Harald Hoyer ab65ae
 
Harald Hoyer ab65ae
-    info "Remounting ${root#block:} with -o ${rflags}"
Harald Hoyer ab65ae
-    mount -t "$rootfs" -o "$rflags" "${root#block:}" "$NEWROOT" 2>&1 | vinfo
Harald Hoyer ab65ae
+    if [ -n "$rootopts" -o "$ran_fsck" = "1" ]; then
Harald Hoyer ab65ae
+        info "Remounting ${root#block:} with -o ${rflags}"
Harald Hoyer ab65ae
+        umount "$NEWROOT" &>/dev/null
Harald Hoyer ab65ae
+        mount -t "$rootfs" -o "$rflags" "${root#block:}" "$NEWROOT" 2>&1 | vinfo
Harald Hoyer ab65ae
+    fi
Harald Hoyer ab65ae
 
Harald Hoyer ab65ae
     [ -f "$NEWROOT"/forcefsck ] && rm -f "$NEWROOT"/forcefsck 2>/dev/null
Harald Hoyer ab65ae
     [ -f "$NEWROOT"/.autofsck ] && rm -f "$NEWROOT"/.autofsck 2>/dev/null