Commit Graph

72 Commits

Author SHA1 Message Date
Mike Frysinger
286b5928c8 enter_chroot: merge multiple mount requests into a single sudo
Every invocation of `sudo` delays things, so merge all of the mounts
into a single `sudo` command when possible.  This saves over 1 second
on initial execution (out of ~4 seconds total).

BUG=None
TEST=`cros_sdk --enter true` still mounts & unmounts properly

Change-Id: Ibc66507dc21250a81207d2f940645eaebe93c79c
Reviewed-on: https://gerrit.chromium.org/gerrit/10901
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
2011-11-14 13:42:21 -08:00
Mike Frysinger
40bb0c3152 enter_chroot: ignore errors from copying user ssh files
The current code that syncs the user's ssh files from ~/.ssh/ to the
chroot assumes the user has these files in the first place.  For the
fresh user and/or install, these might not exist.  So ignore errors
from attempting to copy them.  It's not like we attempt to "recover"
anyways, and this sync is more of a "let's make things smoother" than
a "we need this to run properly".

BUG=chromium-os:15005
TEST=`mv ~/.ssh ~/.ssh.bak; mkdir ~/.ssh; cros_sdk` and see no more warnings

Change-Id: I9cac2ecad7c64c088fbdfe55377c0429b3b7ab03
Reviewed-on: https://gerrit.chromium.org/gerrit/10922
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
2011-10-31 21:49:19 -07:00
Aaron Plattner
130d363aaa Bind-mount /run if it exists
Ubuntu 11.10, for whatever reason, moved /dev/shm to /run/shm.  Since
/run is not mounted in the chroot, /dev/shm is a dangling symlink and
various things that require shared memory start failing.

If /run and /run/shm exist, bind-mount them in the chroot.

Because /run doesn't yet exist in the SDK tarballs, try to create it
(and /run/shm if necessary) as root if it and can't be created as a
normal user.

BUG=chromium-os:19871
TEST=Run cros_sdk, verify that /dev/shm has the expected contents

Change-Id: I61583c1c0d409c1234fa8d8930a9b64544c9a8e7
Reviewed-on: https://gerrit.chromium.org/gerrit/10222
Tested-by: Aaron Plattner <aplattner@nvidia.com>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: David James <davidjames@chromium.org>
2011-10-26 20:25:20 -07:00
Mike Frysinger
470be99f4f enter_chroot: try to avoid sudo when deleting sync pid file
The sync pid file is created without using sudo which means we should be
able to delete it without using sudo.  By default, run `rm` directly and
if it fails, fall back to sudo like we historically have.

BUG=None
TEST=`cros_sdk --enter true`; see pid file deleted

Change-Id: I26d898f6d594eb9ea4652335468345dd11303122
Reviewed-on: http://gerrit.chromium.org/gerrit/8644
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-10-07 08:10:29 -07:00
Mike Frysinger
0a0e6ecee3 enter_chroot: avoid multiple readlink calls on mount point
We call `readlink -f` on the chroot mount point to resolve any symlinks
in the path (since that is what `mount` records).  But the only paths
that can have symlinks are in the base chroot mount.  Everything below
that we know are not going to be symlinks (since we've set up the paths
ourselves).  So process the chroot mount point with readlink once and
reuse that value everywhere else.

BUG=None
TEST=`cros_sdk --enter true` still mounts & unmounts properly

Change-Id: Id1e734d20c0cb766f5490583b793930af77b3b14
Reviewed-on: http://gerrit.chromium.org/gerrit/8645
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-10-03 12:27:55 -07:00
Mike Frysinger
9a50b64449 enter_chroot: re-factor chrome_root mounting to use ensure_mounted
The chrome root code doesn't attempt to mount the tree if there is no
source root configured.  So re-order the code from:
 - is chrome source mounted ?
 - does a chrome source exist ?
 - mount chrome source
to the more logical:
 - does a chrome source exist ?
 - use ensure_mounted to check+mount

This lets us use the mount cache for the chrome mounting and unifies
duplicated mount/checking logic.

BUG=None
TEST=`cros_sdk --enter` still works with simultaneous runs
TEST=`cros_sdk --enter -- ls` still works

Change-Id: I7e6af9dd7f65cefa04438c2862c931f06237060a
Reviewed-on: http://gerrit.chromium.org/gerrit/8032
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-10-03 07:42:28 -07:00
Mike Frysinger
b4d7c4b7b8 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 <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-30 22:29:42 -07:00
Mike Frysinger
61e4f2855b cros_sdk: avoid useless forks
The cros_sdk tool runs a lot of helper programs which can be replaced
with bash builtins, or condensed multiple calls into a single one.  By
themselves they aren't that slow, but add them all up and run them a
whole lot, and it starts to make a difference.

External programs to bash internals:
 - dirname $f    -> ${f%/*}
 - f=$(cat $f)   -> f=$(<$f)
 - which f       -> type -P f

Simpler expressions:
 - [[ ( ... ) ]] -> [[ ... ]]
 - eval v=\$$f   -> v=${!f}

Common/clearer expressions:
 - ! var=$(cmd)  -> var=$(cmd || :)

Condensed tools:
 - sort | uniq   -> uniq -u

BUG=None
TEST=`cros_sdk --enter` still works with simultaneous runs
TEST=`cros_sdk --enter -- ls` still works

Change-Id: Ice5e5e252237082a2249990644e051895d61d1fd
Reviewed-on: http://gerrit.chromium.org/gerrit/8029
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-30 08:53:31 -07:00
Mike Frysinger
7f7a763ed1 enter_chroot: optimize env_sync_proc ownership changing
Most of the time the files in the chroot /etc/ are already changed to
the proper owner.  Only on the first run do they need to be changed.
So check the owner before doing the sudo as that is a bit faster.  If
we do end up needing to run sudo, bundle the commands up to avoid having
to execute sudo multiple times.

BUG=None
TEST=`sudo chown root chroot/etc/resolv.conf && cros_sdk --enter`; see /etc/resolv.conf owned by me

Change-Id: Ifd974ace168ab309fdc2e7583d135ee23576a5bb
Reviewed-on: http://gerrit.chromium.org/gerrit/8418
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-28 19:47:57 -07:00
Mike Frysinger
2a97059dfc 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>
2011-09-28 08:09:04 -07:00
Mike Frysinger
8264917362 cros_sdk: avoid sudo to chmod when possible
Checking the permission of files is faster than assuming they're broken
and then running `sudo chmod`, so do just that.

BUG=None
TEST=run `cros_sdk --enter` with bad perms and see them fixed
TEST=run `cros_sdk --enter` with correct perms and see sudo skipped
TEST=the buildbot failure was due to other changes, not this one

Change-Id: Ie69b4e766e2e3652944e4723d091ce589d07a4f6
Reviewed-on: http://gerrit.chromium.org/gerrit/8028
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-27 16:36:53 -07:00
Mike Frysinger
94717e3099 cros_sdk: unify duplicate git calls for user commit info
No need to call `git var | sed` multiple times when we can call it once
and then use bash string parsing routines to extract the relevant info.

BUG=None
TEST=delete .gitconfig in chroot; enter chroot; verify .gitconfig is up-to-date

Change-Id: I900e4241a5c53bc46c90eb0f2a01152f4bfba577
Reviewed-on: http://gerrit.chromium.org/gerrit/8027
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-26 08:43:10 -07:00
Mike Frysinger
4d258cdf9d enter_chroot: restore auto locale generation
First let's add a chroot upgrade hook that'll declare a small list of
locales to speed up glibc upgrades.

The other blocker was that `cros_sdk --enter` took an inordinate amount
of time to execute (`locale-gen -u` specifically) when the number of
existing locales is huge.  This seems to be a bug in the bash/glibc
stack which is resolved in newer versions, but we can workaround the
issue by forcing locale-gen to run in a C locale.  The tool itself does
not care about its locale and we silence its output.

BUG=chromium-os:20378
TEST=`cros_sdk --enter`; see no locales in /etc/locale.gen; run `./build_packages` and see upgrade hook work
TEST=generate all 400 locales; `cros_sdk --enter`; see that it was quick

Change-Id: I8fcc5e26bd8e1bcfd52b6a6c7ef3cacf0a252081
Reviewed-on: http://gerrit.chromium.org/gerrit/7806
Reviewed-by: David James <davidjames@chromium.org>
Reviewed-by: Zdenek Behan <zbehan@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-19 21:57:14 -07:00
Mike Frysinger
acc4c9b3fc cros_sdk: optimize fuse loading
Running `sudo` at all is a bit poky, so let's avoid modprobing fuse when
we know it already exists because it's listed in /proc/filesystems.

The relative speed:
 time sudo modprobe fuse -> 0.164s
 time grep -q fuse /proc/filesystems -> 0.002s

BUG=None
TEST=enable `set -x`; run `sudo modprobe fuse`; run `cros_sdk true`; see modprobe skipped

Change-Id: I07213e7b0607ca65df2a8a3ae22eb4a49c8bb888
Reviewed-on: http://gerrit.chromium.org/gerrit/7824
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-19 10:20:00 -07:00
Mike Frysinger
da7be781c0 cros_sdk: optimize gconftool interaction
It doesn't make much sense to run gconftool when the default automount
value is what we already want: false.  So in this common case, skip the
save/restore logic altogether since we aren't actually changing things.

Further, we can merge the `which` check in by checking the exit status
of the `gconftool` run.  If it fails, the tool doesn't exist.

BUG=None
TEST=enable `set -x`; run `cros_sdk true`; see gconftool run once in common case

Change-Id: I1c6aee945218a8a9df533d9ef207c750f909c252
Reviewed-on: http://gerrit.chromium.org/gerrit/7823
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-09-19 09:57:26 -07:00
Mike Frysinger
1aa6124f1d cros_sdk: speed up unmounting when tearing down env
The teardown_env is a little slow when unmounting things because it runs
`sudo umount` once per mount point.  This is so that when things go wrong,
it can easily recover.  However, this slows down the common case at the
expense of the uncommon.

Refactor the code so that in the common case, we run one `sudo umount`.
When things do fail, we're a bit slower as we reparse the entire mount,
list, but that's fine as it's an error case.

BUG=None
TEST=enable `set -x`; run `cros_sdk true`; see all mount points unmounted in one shot

Change-Id: Iec98a7b9f51a77e90c30e6f6acae26e528b8c50d
Reviewed-on: http://gerrit.chromium.org/gerrit/7822
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
2011-09-16 18:58:17 -07:00
Raymes Khoury
4460ea782f Disable locale-gen temporarily to workaround bug
Works around:
http://code.google.com/p/chromium-os/issues/detail?id=20378

which is breaking the tree.

BUG=chromium-os:20378
TEST=cros_sdk --enter

Change-Id: I0d5dc2dd6466efe9baafcc404648d2c53309a3b7
Reviewed-on: http://gerrit.chromium.org/gerrit/7679
Reviewed-by: David James <davidjames@chromium.org>
Reviewed-by: Thieu Le <thieule@chromium.org>
Tested-by: David James <davidjames@chromium.org>
2011-09-13 17:10:30 -07:00
Matt Tennant
d4316fe32f When entering chroot, copy ~/.gdata_cred.txt if it exists.
The process of updating the Portage package status spreadsheet on
buildbots requires a credentials file at ~/.gdata_cred.txt in the
chroot.  All buildbot VMs have this file outside the chroot now,
so this change adds that file to the list of things created in
the user's homedir when entering the chroot.

BUG=None
TEST=Run cros_sdk in these scenarios:
~/.gdata_cred.txt exists -> Same file should be at $HOME in chroot
~/.gdata_cred.txt does not exist -> No file created in chroot

Change-Id: I5c0f333a9308f5efa5324ce2e202a7c9e9fdb48b
Reviewed-on: http://gerrit.chromium.org/gerrit/6911
Reviewed-by: Zdenek Behan <zbehan@chromium.org>
Tested-by: Matt Tennant <mtennant@chromium.org>
2011-08-30 13:43:13 -07:00
J. Richard Barnette
8e6750dee7 Clean up sdk_lib/enter_chroot.sh startup boilerplate.
BUG=None
TEST=run cros_sdk

Change-Id: I39fafd58c7cc9fd536fe9b75f314f9970766a483
Reviewed-on: http://gerrit.chromium.org/gerrit/6414
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
2011-08-22 12:57:34 -07:00
Mike Frysinger
4fc9c2706d enter_chroot.sh: always generate en_US locales
The buildbot code forces the en_US.UTF8 locale itself, and does so inside
of the chroot, so our auto-detection code doesn't catch it.  Always create
these locales that the buildbot uses.

BUG=None
TEST=cleared out locales, emptied out active locale env vars, ran enter_chroot, saw that en_US{,UTF8} were created

Change-Id: I9ad65007a340333e19743985c9cbeea9403823fa
Reviewed-on: http://gerrit.chromium.org/gerrit/6168
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
2011-08-17 12:42:54 -07:00
Mike Frysinger
6601c52b1f enter_chroot: auto generate user locales
Since we no longer force LC_ALL=C on everyone, the few times that perl
does get run by people, it spews the expected "Setting locale failed"
warnings.  This isn't as big a deal as with Debian systems as perl usage
is uncommon in Gentoo.

This is also highlights the long-existing small issue of only specific
locales being available in the chroot.  So for non US english speaking
users, they've been having non-optimal experiences.

So parse the user's active locale and automatically generate the missing
ones in the chroot so that when they do enter, things "just work".

BUG=chromium-os:19139
TEST=set locale to non-existent ones, enter_chroot, & verify locales are created

Change-Id: I43f809a1ee1472e4797edab0f32cecf582ea8b48
Reviewed-on: http://gerrit.chromium.org/gerrit/5986
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2011-08-17 07:33:34 -07:00
Zdenek Behan
892e6acdc0 crosutils: move enter_chroot.sh to sdk_lib, code unchanged
* Removed boilerplate, simplified search code.
* Fixed one too long line

This will unfortunately kill all outstanding CLs into enter_chroot.

BUG=chromium-os:18750
TEST=run it

Change-Id: I39c45fa8163d92487b512e7e8d298ce9231f4bd2
Reviewed-on: http://gerrit.chromium.org/gerrit/5830
Tested-by: Zdenek Behan <zbehan@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Anush Elangovan <anush@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
2011-08-12 16:35:07 -07:00