From b4d7c4b7b86e994c79537998ed927d3660f220fe Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 20 Sep 2011 23:24:24 -0400 Subject: [PATCH] enter_chroot: extend ensure_mounted api to use it with depot_tools The depot_tools mount code is exactly like ensure_mounted except that it prints a warning instead of dying when things can't be mounted. So take the current api and extend it slightly to support warning or dying. This also lets us re-use the existing mount cache and avoid the forks as well as clean up duplicated code. BUG=None TEST=`cros_sdk --enter` still works with simultaneous runs TEST=`cros_sdk --enter -- ls` still works Change-Id: I89336778b6aa16191e79d900a51774929cadf06b Reviewed-on: http://gerrit.chromium.org/gerrit/8031 Commit-Ready: Mike Frysinger Reviewed-by: Mike Frysinger Tested-by: Mike Frysinger --- sdk_lib/enter_chroot.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh index 8b7db51586..68d8255ffe 100755 --- a/sdk_lib/enter_chroot.sh +++ b/sdk_lib/enter_chroot.sh @@ -92,6 +92,7 @@ function ensure_mounted { local source="$1" local mount_args="$2" local target="$3" + local warn="$4" local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")" @@ -107,8 +108,14 @@ function ensure_mounted { # NB: mount_args deliberately left unquoted debug mount ${mount_args} "${source}" "${mounted_path}" - sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \ - die "Could not mount ${source} on ${mounted_path}" + if ! sudo -- mount ${mount_args} "${source}" "${mounted_path}" ; then + if [ -z "${warn}" ]; then + die "Could not mount ${source} on ${mounted_path}" + else + warn "Failed to mount ${source}; perhaps it's on NFS?" + warn "${warn}" + fi + fi ;; esac } @@ -269,17 +276,11 @@ function setup_env { fi fi - MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")" - if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then - if DEPOT_TOOLS=$(type -P gclient) ; then - DEPOT_TOOLS=${DEPOT_TOOLS%/*} # dirname - debug "Mounting depot_tools" - mkdir -p "$MOUNTED_PATH" - if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then - warn "depot_tools failed to mount; perhaps it's on NFS?" - warn "This may impact chromium build." - fi - fi + if DEPOT_TOOLS=$(type -P gclient) ; then + DEPOT_TOOLS=${DEPOT_TOOLS%/*} # dirname + debug "Mounting depot_tools" + ensure_mounted "$DEPOT_TOOLS" --bind "$INNER_DEPOT_TOOLS_ROOT" \ + "This may impact chromium build." fi # Install fuse module. Skip modprobe when possible for slight