mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-08 05:26:58 +02:00
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 <vapier@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
905f6164a1
commit
2a97059dfc
@ -95,7 +95,11 @@ function ensure_mounted {
|
|||||||
|
|
||||||
local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")"
|
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
|
# Attempt to make the mountpoint as the user. This depends on the
|
||||||
# fact that all mountpoints that should be owned by root are
|
# fact that all mountpoints that should be owned by root are
|
||||||
# already present.
|
# already present.
|
||||||
@ -105,7 +109,8 @@ function ensure_mounted {
|
|||||||
debug mount ${mount_args} "${source}" "${mounted_path}"
|
debug mount ${mount_args} "${source}" "${mounted_path}"
|
||||||
sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \
|
sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \
|
||||||
die "Could not mount ${source} on ${mounted_path}"
|
die "Could not mount ${source} on ${mounted_path}"
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function env_sync_proc {
|
function env_sync_proc {
|
||||||
@ -219,6 +224,7 @@ function setup_env {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
debug "Mounting chroot environment."
|
debug "Mounting chroot environment."
|
||||||
|
MOUNT_CACHE=$(mount)
|
||||||
ensure_mounted none "-t proc" /proc
|
ensure_mounted none "-t proc" /proc
|
||||||
ensure_mounted none "-t sysfs" /sys
|
ensure_mounted none "-t sysfs" /sys
|
||||||
ensure_mounted /dev "--bind" /dev
|
ensure_mounted /dev "--bind" /dev
|
||||||
|
Loading…
Reference in New Issue
Block a user