Overview

If multiple DSS containers are exported via NFS to a single system or VM, or if there are often changes to the list of containers that are exported to a system or VM, a system administrator has to adjust the configuration of NFS mounts in /etc/fstab. To avoid this manual intervention the Linux AutoFS (automounter) can be used to query and mount all DSS containers that are exported to system automatically.   

Prerequisites  and Setup

To use the automounter script the Linux "autofs" and "nfs-util" packages have to be installed on the system.

Two files have to be created in the "/etc/auto.master.d" directory: 

/etc/auto.master.d/dss.autofs.pl
#!/usr/bin/env perl -w
#####################################################################
## This script checks all DSS CES servers for exported filesystems
##   that can be mounted via autofs
##
## Takes automounter key ($1) as /dss/<filesystem> to look for
##
## This file must be executable to work! chmod 755!
## 
##    Copyright (C) 2019 M. Stephan (m.stephan@lrz.de)
##
##    This program is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program.  If not, see <https://www.gnu.org/licenses/>.
##
#####################################################################
# main program
#####################################################################
use strict;
use POSIX;
use FindBin;
#####################################################################
# make sure we have the corret path to showmount
my $SHOWMOUNT_CMD="/sbin/showmount";

# List of all potential NFS servers
my @DSSNFSSERVER = ( "<Add NFS server DNS name>", "<Add NFS server DNS name>" );

# NFS mount options
#   add "nosymlink" here if you want to suppress symlinking local filesystems
#   add "nonstrict" to make it OK for some filesystems to not mount
my $NFSOPTS="-fstype=nfs,hard,intr,nodev,nosuid";

#####################################################################
# Takes automounter key ($1) as /dss/<filesystem> to look for
exit 1 if (! $ARGV[0] );
my $DSSFILESYSTEM=$ARGV[0];

# Empty hash for exports/servers
my %EXPORTLIST = ();

#####################################################################
# Check all server(s) for requested exports
foreach my $nfsserver ( @DSSNFSSERVER ) {
  open(SMNT,"$SHOWMOUNT_CMD -e $nfsserver |") || next;
  while(<SMNT>) {
    if( $_ =~ /^(\/dss\/$DSSFILESYSTEM\/\S+)\s+[0-9,\.]+/ ) {
      $EXPORTLIST{$1} = $nfsserver;
    }
  }
  close(SMNT);
}

#####################################################################
# exit with return code 1 if no export was found
exit 1 if (! keys(%EXPORTLIST) );

#####################################################################
# Return list of existing exports to autofs
print "$NFSOPTS";
foreach my $export ( keys(%EXPORTLIST) ) {
  $export =~ /^\/dss\/$DSSFILESYSTEM(\/\S+)/;
  print " \\\n  $1 $EXPORTLIST{$export}:$export";
}
print "\n";

exit 0;
# Done
#####################################################################
/etc/auto.master.d/dss.autofs
#####################################################################
##    Copyright (C) 2019 M. Stephan (m.stephan@lrz.de)
##
##    This program/config file is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program.  If not, see <https://www.gnu.org/licenses/>.
##
#####################################################################
#
/dss /etc/auto.master.d/dss.autofs.pl
#


Add the hostname(s) of the exporting NFS server(s) in /etc/auto.master.d/dss.autofs.pl (Line with @DSSNFSSERVER declaration).

The necessary information about NFS server name and DSS Filesystem can be seen in the DSSWeb interface:

 

In the example the DSSNFSSERVER is: datdsscnfs02.dss.lrz.de and the <DSS Filesystem> is: dssfs01 

Make script executable and test it. 

chmod 755 /etc/auto.master.d/dss.autofs.pl
mkdir /dss

/etc/auto.master.d/dss.autofs.pl <DSS Filesystem>

The output should look similar to this example:

> /etc/auto.master.d/dss.autofs.pl dssfs01
-fstype=nfs,hard,intr,nodev,nosuid \
  /lwp-dss-0000/pr74qo/pr74qo-dss-0005 datdsscnfs02.dss.lrz.de:/dss/dssfs01/lwp-dss-0000/pr74qo/pr74qo-dss-0005   

Check if autofs includes the files in the /etc/auto.master.d/ directory:

> grep -vE "^#" /etc/auto.master | grep "/etc/auto.master.d"
+dir:/etc/auto.master.d


And finally start autofs: 

> systemctl start autofs 
> systemctl status autofs