exports 3.57 KB
Newer Older
1 2 3 4 5 6
#
#
#
use strict;
use libinstall;
use installvars;
7
use Cwd qw(realpath);
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

sub Install($$$)
{
    my ($server, $isupdate, $impotent) = @_;

    # Boss is the FS *only* when OPS is a VM (jail) on boss. 
    return 0
	if (ISBOSSNODE($server) && !ISFS($server));

    if ($isupdate) {
	#
	# Replace the old domain/IP with the new domain/IP.
	#
	my ($a,$b,$c,$d) = ($CONTROL_NETWORK =~ /^(\d*)\.(\d*)\.(\d*)\.(\d*)/);
	my @replacements = (
	    # Looking for hostname.emulab.net 
	    [qr{\s(\w*boss)\.[-\w\.]+\s}, '" $1.' . ${OURDOMAIN} . ' "'],
	    # Looking for "-network a.b.c.d -mask a.b.c"
	    [qr{share\s+\-netmask\s+[\d\.]+\s+\-mask\s+[\d\.]+\s},
	     '"share\t-network' .
28
	     "${a}.${b}.${c}.${d} -mask " . $CONTROL_NETMASK . ' "'],
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
	    );
	Phase "exports", "Updating $EXPORTS_HEAD", sub {
	    QueryReplaceFileFatal($EXPORTS_HEAD, \@replacements);
	};
	return 0;
    }

    Phase "exports", "Setting up exports", sub {
	Phase "ex.head", "Creating $EXPORTS_HEAD", sub {
	    DoneIfExists($EXPORTS_HEAD);

	    #
	    # Figure out which of these directories are on the same
	    # filesystems.  Note: we cannot do /share on the same
	    # exports line as the other filesystems because of the RO
	    # mount below (trust me).
	    #
46 47 48 49 50 51 52 53
	    my @exports_lines = ();

	    if (!$OPSVM_ENABLE) {
		my %filesystems;
		my @dirs = ();
		if (ISOPSNODE($server)) {
		    # Ops always exports these to boss.
		    @dirs = ('/var', $PREFIX);
54
		}
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
		if (ISFS($server)) {
		    # The fileserver exports these too.
		    # But only /share if ZFS.
		    if ($WITHZFS) {
			@dirs = (@dirs, $SHAREROOT);
		    } else {
			@dirs = (@dirs, @MOUNTPOINTS);
		    }
		}
		foreach my $dir (@dirs) {
		    if ($dir ne $SHAREROOT) {
			my $dir = realpath($dir);
			chomp($dir);
			my $dev = (stat($dir))[0];
			push @{$filesystems{$dev}}, $dir;
		    }
71 72
		}

73 74 75 76
		#
		# Use that knowledge to create lines for /etc/exports.head
		#
		foreach my $key (keys %filesystems) {
77
		    push @exports_lines,
78 79 80 81 82 83 84 85
			join(" ",@{$filesystems{$key}}) .
			"\t$BOSSNODE -maproot=root";
		    # if not the ops node, must export to that node as well
		    if (!ISOPSNODE($server)) {
			push @exports_lines,
			    join(" ",@{$filesystems{$key}}) .
			    "\t$USERNODE -maproot=root";
		    }
86
		}
87 88
	    }

89 90 91 92 93
	    #
	    # /share is special. We want to export to boss read-write,
	    # but to the control network read-only.
	    #
	    if ($SHAREDIR && ISFS($server)) {
94
		my $realdir = realpath($SHAREROOT);
95 96 97
		chomp($realdir);
		push(@exports_lines,
		     "$realdir\t$BOSSNODE -maproot=root");
98
		# if not the ops node, must export to that node as well
99
		if (!ISOPSNODE($server) && !$OPSVM_ENABLE) {
100 101 102
		    push(@exports_lines,
			 "$realdir\t$USERNODE -maproot=root");
		}
103 104 105 106
		if (!$NOSHAREDFS) {
		    my ($a,$b,$c,$d) =
			($CONTROL_NETWORK =~ /^(\d*)\.(\d*)\.(\d*)\.(\d*)/);
		    push(@exports_lines,
107
			 "$realdir\t-network ${a}.${b}.${c}.${d} ".
108
			 "-mask $CONTROL_NETMASK -maproot=root -ro -alldirs");
109 110 111 112 113
		    if ($PROTOGENI_GENIRACK) {
			push(@exports_lines,
			     "$realdir\t-network 172.16.0.0 ".
			     "-mask 255.240.0.0 -maproot=root -ro -alldirs");
		    }
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
		}
	    }
	    
	    #
	    # Put them in exports.head, and copy that to /etc/exports
	    #
	    CreateFileFatal($EXPORTS_HEAD, @exports_lines);
	    ExecQuietFatal("cp $EXPORTS_HEAD $EXPORTS_FILE");
	};

	# XXX Newhup
	Phase "mountd", "HUPing mountd", sub {
	    PhaseSkip("No new exports file") if PhaseWasSkipped("ex.head");
	    PhaseSkip("mountd not running")
		unless `ps -auxw | grep mountd | grep -v grep`;
	    ExecQuietFatal("killall -HUP mountd");
	};
    };
    return 0;
}

# Local Variables:
# mode:perl
# End: