nfsmounts 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#
# The template
#
use strict;
use libinstall;
use installvars;

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

    if ($isupdate) {
	#
	# Update /etc/fstab for new domain.
	#
	my @replacements = (
	    # Looking for hostname.emulab.net 
	    [qr{^(\w*ops)\.[-\w\.]+:}, '"$1.' . ${OURDOMAIN} . ':"'],
	    [qr{^(\w*fs)\.[-\w\.]+:}, '"$1.' . ${OURDOMAIN} . ':"']);
	
	Phase "fstab", "Updating $FSTAB", sub {
	    QueryReplaceFileFatal($FSTAB, \@replacements);
	};
	return 0;
    }

    Phase "NFSmounts", "Setting up NFS mounts", sub {
	if (ISOPSNODE($server) && $OPSVM_ENABLE) {
	    PhaseSkip("FSes are mounted from outside the VM");
	}
	my @dirs = ();
32
	my @mkdirs = ();
33 34 35 36 37 38 39 40 41

	#
	# If we are the FS then we do not need to mount the FS file systems.
	# If not acting as the FS (boss,ops), then must mount the file systems
	# on the FS node.
	# In addition, boss must mount a couple of file systems on ops,
	# unless ops is a VM on boss (see skip above).
	#
	if (!ISFS($server)) {
42 43 44 45 46 47
	    if ($WITHZFS) {
		@dirs = ($SHAREROOT);
	    } else {
		@dirs = @MOUNTPOINTS;
	    }
	    @mkdirs = @MOUNTPOINTS;
48 49 50
	}
	if (ISBOSSNODE($server) && !$OPSVM_ENABLE) {
	    @dirs = (@dirs, $USERSVAR_MOUNTPOINT, $OPSDIR_MOUNTPOINT);
51
	    @mkdirs = (@mkdirs, $USERSVAR_MOUNTPOINT, $OPSDIR_MOUNTPOINT);
52 53
	}
	PhaseSkip("Nothing to mount")
54
	    if (!@mkdirs);
55 56

	Phase "mountpoints", "Creating mountpoints", sub {
57
	    foreach my $dir (@mkdirs) {
58 59 60 61 62 63 64 65 66 67 68 69
		Phase $dir, $dir, sub {
		    DoneIfExists($dir);
		    mkdir $dir, 0777 or
			PhaseFail("Unable to create $dir : $!");
		};
	    }
	};
	Phase "fstab", "Adding NFS mounts to $FSTAB", sub {
	    DoneIfEdited($FSTAB);
	    my $nfsopt = "nosuid";
	    $nfsopt .= ",nodev"
		if ($FBSD_MAJOR < 7);
70 71 72 73 74 75
	    #
	    # Do late mounts on boss to avoid deadlocks with fs node
	    # which might want services from boss before exporting FSes
	    #
	    $nfsopt .= ",late"
		if (ISBOSSNODE($server));
76 77 78 79 80 81 82 83 84 85 86 87 88

	    my @lines = ();
	    foreach my $dir (@dirs) {
		if ($dir eq $USERSVAR_MOUNTPOINT) {
		    push(@lines,
			 "$USERNODE:/var\t\t$USERSVAR_MOUNTPOINT\tnfs\t".
			 "ro,soft,-b,$nfsopt\t0\t0");
		}
		elsif ($dir eq $OPSDIR_MOUNTPOINT) {
		    push(@lines,
			 "$USERNODE:/usr/testbed\t\t$OPSDIR_MOUNTPOINT\tnfs\t".
			 "rw,soft,-b,$nfsopt\t0\t0");
		}
89 90 91 92 93 94
		#
		# For ZFS, we do not mount the roots of the {users,proj,groups}
		# filesystems as each {user,proj,group} has their own FS.
		# We only mount /share.
		#
		elsif (!$WITHZFS || $dir eq $SHAREROOT) {
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
		    push(@lines,
			 "$FSNODE:$dir\t\t$dir\tnfs\trw,$nfsopt\t0\t0");
		}
	    }
	    AppendToFileFatal($FSTAB, @lines);
	};
	Phase "mounts", "Mounting NFS filesystems", sub {
	    my $opt = ($FBSD_MAJOR >= 8 ? "retrycnt=1" : "'-R 1'");
	    
	    foreach my $dir (@dirs) {
		Phase $dir, $dir, sub {
		    DoneIfMounted($dir);
		    ExecQuietFatal("$MOUNT -o $opt $dir");
		};
	    }
	};
    };
    return 0;
}

# Local Variables:
# mode:perl
# End: