From 2a97059dfc7fc4b682012ce3f60d24c658169151 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 20 Sep 2011 22:49:01 -0400 Subject: [PATCH] cros_sdk: add a mount cache to avoid multiple execs Since we grab a lock before mounting anything, we know that the relevant list of mounts won't change (since we haven't changed it yet). So we can cache the output of `mount` and re-use that in every subsequent check. BUG=None TEST=`cros_sdk --enter` still works with simultaneous runs TEST=`cros_sdk --enter -- ls` still works Change-Id: I27c98c923761fb777686632fe6e6604ca543cfb6 Reviewed-on: http://gerrit.chromium.org/gerrit/8030 Commit-Ready: Mike Frysinger Reviewed-by: Mike Frysinger Tested-by: Mike Frysinger --- sdk_lib/enter_chroot.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index fff5e4e62e..69f62e5436 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -95,7 +95,11 @@ function ensure_mounted { local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")" - if [ -z "$(mount | grep -F "on ${mounted_path} ")" ]; then + case ${MOUNT_CACHE} in + *" on ${mounted_path} "*) + # Already mounted! + ;; + *) # Attempt to make the mountpoint as the user. This depends on the # fact that all mountpoints that should be owned by root are # already present. @@ -105,7 +109,8 @@ function ensure_mounted { debug mount ${mount_args} "${source}" "${mounted_path}" sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \ die "Could not mount ${source} on ${mounted_path}" - fi + ;; + esac } function env_sync_proc { @@ -219,6 +224,7 @@ function setup_env { fi debug "Mounting chroot environment." + MOUNT_CACHE=$(mount) ensure_mounted none "-t proc" /proc ensure_mounted none "-t sysfs" /sys ensure_mounted /dev "--bind" /dev