Commit 622e2187 authored by Mike Hibler's avatar Mike Hibler

Two semi-related exports_setup changes.

1. Don't stat all exported mountpoints from boss to see if they exist.
   Not only is this wrong from boss (a mount may be valid, but not yet
   exported) it also makes the automounter work its butt off as we might
   stat hundreds or thousands of directories across NFS. The original
   purpose of this was to keep mountd from freaking out when presented
   with a non-existent directory. Since mountd freaking out is about as
   rare as the sun rising in the east, we keep this check but do it on
   the proxy (ops) side instead.

2. Have exports_setup (boss) generate a list of directories that it should
   be able to mount. This goes in /usr/testbed/etc/validmounts.txt and will
   be used by autofs (I hope) to narrow down the wildcarded "/users/*"
   and "/proj/*" mounts to those that might actually work. Right now you
   can "ls /users/WtF" and it will try to mount it from ops and take 4
   seconds to timeout and fail.
parent fa370849
......@@ -74,6 +74,7 @@ my $LINUX_FSNODE= @LINUX_FSNODE@;
my $NFSMAPTOUSER= "@NFSMAPTOUSER@";
my $WITHZFS = @WITHZFS@;
my $ZFS_NOEXPORT= @ZFS_NOEXPORT@;
my $WITHAMD = @WITHAMD@;
my $INC_MOUNTD = @INCREMENTAL_MOUNTD@;
# XXX for TESTMODE: output to stdout
......@@ -87,6 +88,7 @@ my $SSH = "$TB/bin/sshtb -l root -host $FSNODE";
my $PROG = "$TB/sbin/exports_setup.proxy";
my $exportstail = "/var/tmp/exports.tail";
my $smbconftail = "/var/tmp/smbconf.tail";
my $bossmountfile = "$TB/etc/validmounts.txt";
my @row;
# For determining file server mountpoints (XXX BSD specific)
......@@ -398,31 +400,19 @@ while ($row = $nodes_result->fetchrow_hashref) {
# Construct a list of directories accessible from this node.
# First the project and group directories.
# XXX needs to be fixed for shared experiments?
if (-d "$PROJROOT/$pid") {
push(@dirlist, "$projdir/$pid");
push(@smbshares, ["proj-$pid", "$projdir/$pid"]);
}
else {
print STDERR
"*** exports_setup: $PROJROOT/$pid does not exist!\n";
}
push(@dirlist, "$projdir/$pid");
push(@smbshares, ["proj-$pid", "$projdir/$pid"]);
if ($gid ne $pid) {
if (-d "$GROUPROOT/$pid/$gid") {
push(@dirlist, "$groupdir/$pid/$gid");
push(@smbshares, ["${pid}-${gid}", "$groupdir/$pid/$gid"]);
}
else {
print STDERR "*** exports_setup: ".
"$GROUPROOT/$pid/$gid does not exist!\n";
}
push(@dirlist, "$groupdir/$pid/$gid");
push(@smbshares, ["${pid}-${gid}", "$groupdir/$pid/$gid"]);
}
if ($ZFS_NOEXPORT && $gid eq $pid) {
$bossexports{"$projdir/$pid"} = "$projdir/$pid";
$bossexports{"$groupdir/$pid"} = "$groupdir/$pid";
}
if ($scratchdir && -d "$SCRATCHROOT/$pid") {
if ($scratchdir) {
push(@dirlist, "$scratchdir/$pid");
push(@smbshares, ["scratch-$pid", "$scratchdir/$pid"]);
}
......@@ -451,14 +441,8 @@ while ($row = $nodes_result->fetchrow_hashref) {
while (@usersrow = $users_result->fetchrow_array) {
my $uid = $usersrow[0];
if (-d "$USERROOT/$uid") {
push(@dirlist, "$usersdir/$uid");
push(@smbshares, [$uid, "$usersdir/$uid"]);
}
else {
print STDERR "*** exports_setup: ".
"$USERROOT/$uid does not exist!\n";
}
push(@dirlist, "$usersdir/$uid");
push(@smbshares, [$uid, "$usersdir/$uid"]);
if ($ZFS_NOEXPORT) {
$bossexports{"$usersdir/$uid"} = "$usersdir/$uid";
......@@ -526,6 +510,15 @@ while ($row = $nodes_result->fetchrow_hashref) {
}
}
#
# When using FreeBSD autofs on boss, we generate a list of valid directories
# that can be mounted. We use this in an executable map script to avoid
# attempting (and failing after several seconds) to mount arbitrary paths
# under /users, /proj, and /groups.
#
my $bossdirlist = ($WITHZFS && !$WITHAMD) ? 1 : 0;
my @bossmounts = ();
# just cuz
sub sortbyip {
my @ao = split('\.', $a);
......@@ -583,11 +576,41 @@ if ($ZFS_NOEXPORT) {
print "$str -maproot=$NFSMAPTOUSER $BOSSNODE\n"
if ($debug);
}
# remember all valid mount points
if ($bossdirlist) {
push(@bossmounts, $fs);
}
}
}
close(MAP);
#
# Spit out an autofs map if needed. We will move this into place once we
# know that the fs node has updated its exports.
#
# If $ZFS_NOEXPORT, we use info from %bossexports that we computed above
# Otherwise, we use @mountpoints which is export info we got from ops
#
if ($bossdirlist) {
if (open(BM, ">$bossmountfile.new")) {
my $list = $ZFS_NOEXPORT ? \@bossmounts : \@mountpoints;
foreach my $dir (sort @$list) {
print BM "$dir\n"
if ($dir ne "/");
}
close(BM);
} else {
$bossdirlist = 0;
print STDERR "*** $0: WARNING: could not update $bossmountfile,".
" will try to mount anything!\n";
if (!$TESTMODE) {
unlink("bossmountfile.new", $bossmountfile);
}
}
}
#
# Spit out smb shares!
#
......@@ -628,6 +651,9 @@ if (!$TESTMODE) {
if ($WINSUPPORT) {
system("/bin/cat $smbconftail");
}
if ($bossdirlist) {
system("/bin/cat $bossmountfile.new");
}
}
else {
my $arg = ($incremental ? "-i" : "");
......@@ -663,6 +689,13 @@ if (!$TESTMODE) {
}
TBDebugTimeStamp("Wait done");
}
#
# Move the new boss autofs mount map in place.
#
if ($bossdirlist) {
rename("$bossmountfile.new", $bossmountfile);
}
}
#
......
......@@ -54,9 +54,11 @@ my $exportstail;
my $pidfile;
my $daemon;
my $incremental;
my $issamba = 0;
# Are we modifying the Samba config file or the NFS exports?
if (defined($opts{'S'})) {
$issamba = 1;
$etcdir = ($LINUX_FSNODE ? "/etc/samba" : "/usr/local/etc");
$exports = "$etcdir/smb.conf";
$exportsnew = "$etcdir/smb.conf.new";
......@@ -120,7 +122,47 @@ use libtestbed;
#
open(TAIL, ">$exportstail") || fatal("Couldn't open $exportstail\n");
while (<STDIN>) {
print TAIL $_;
#
# Pass through if samba or a comment or blank line.
# We don't test samba lines since we assume the samba invocation
# of us (-S) will follow the normal invocation and have the same
# directories.
#
if ($issamba || $_ !~ /^\//) {
print TAIL $_;
next;
}
#
# As we do this, we parse the lines and check each of the exported
# filesystems to make sure they exist. Otherwise mountd may prematurely
# fail. We used to do this on the boss-side, but that would stat the
# directories across NFS, and in some cases, before the filesystem
# was even exported!
#
my @tokens = ();
my $numdirs = 0;
my $dirsdone = 0;
foreach my $token (split) {
if (!$dirsdone) {
# starts with a slash, assume it is an exported dir
if ($token =~ /^\//) {
if (! -d "$token") {
print STDERR "$token: does not exist, ignored\n";
next;
}
$numdirs++;
} else {
$dirsdone = 1;
}
}
push(@tokens, $token);
}
# if there were valid directories to export, do so
if ($numdirs > 0) {
print TAIL join(' ', @tokens), "\n";
}
}
close(TAIL);
chmod(0444, $exportstail);
......@@ -160,7 +202,7 @@ system("cat $exportstail >> $exportsnew") == 0 or
# an inconsisency. But only for mountd, not smbd.
#
my $outfile;
if (defined($opts{'S'})) {
if ($issamba) {
system("/usr/bin/diff -q $exports $exportsnew >/dev/null");
} else {
$outfile = "/tmp/exports_diff." . time();
......@@ -202,7 +244,7 @@ if (!$LINUX_FSNODE) {
# here so we don't have to bother checking the content, we just have to
# wait for it to exist.
#
if (!defined($opts{'S'}) && unlink("/var/run/mountd.ts") != 0) {
if (!$issamba && unlink("/var/run/mountd.ts") != 0) {
$checkstamp = 1;
}
......@@ -218,7 +260,7 @@ if (!$LINUX_FSNODE) {
}
else {
# Not supporting Samba at this time.
if (! defined($opts{'S'})) {
if (!$issamba) {
#
# run exportfs. linux handles exports changes much more gracefully
# then freebsd does.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment