Whamcloud - gitweb
LU-7060 ldev: Added MGS NID substitution to ldev 29/16129/11
authorGiuseppe Di Natale <dinatale2@llnl.gov>
Fri, 28 Aug 2015 23:17:24 +0000 (16:17 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 6 Apr 2016 01:40:43 +0000 (01:40 +0000)
For automation purposes, it would be nice to have a
command substitution for the MGS NID of a node.
The ldev perl script now has a %m flag to sub in
the MGS NID. The MGS associated with a node is
determined by which file system the node is a part
of. The NID is obtained by using the current
NID file parsing. Also, MGS is now an acceptable
type to have specified in a label.

Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Change-Id: Ifcfad7664ac028e2074030e4b3ba5995ddb5358d
Reviewed-on: http://review.whamcloud.com/16129
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/doc/ldev.8
lustre/scripts/ldev
lustre/tests/conf-sanity.sh

index 438ffd3..187cc3f 100644 (file)
@@ -63,10 +63,10 @@ Only the local labels are used by default, but foreign or all labels
 may be selected by adding the \fI--foreign\fR or \fI--all\fR options.
 The following substitutions are made:
 %f=fsname, %d=device, %j=journal, %i=index, %I=hex-index, %t=type, %l=label,
 may be selected by adding the \fI--foreign\fR or \fI--all\fR options.
 The following substitutions are made:
 %f=fsname, %d=device, %j=journal, %i=index, %I=hex-index, %t=type, %l=label,
-%n=nid, %N=failnid.  On failure of any child processes, \fBldev\fR will
+%n=nid, %N=failnid, %m=mgsnid.  On failure of any child processes, \fBldev\fR will
 return a non-zero exit code.
 .LP
 return a non-zero exit code.
 .LP
-It is an error if %n or %N is used in a command and /etc/nids does not
+It is an error if %n, %N, or %m is used in a command and /etc/nids does not
 contain appropriate host to NID mappings.
 .SH EXAMPLES
 To run a preen check on all devices in a cluster in parallel:
 contain appropriate host to NID mappings.
 .SH EXAMPLES
 To run a preen check on all devices in a cluster in parallel:
index 4b7b008..8d7df7a 100644 (file)
@@ -30,7 +30,7 @@ Parse ldev.conf and answer the following queries:
   -z, --zpool LABEL   Print zpool containing LABEL.
   CMD [ARGS] ...      Run CMD in parallel for each device substituting:
                       %f=fsname  %d=device  %i=dec-index %n=main-nid %l=label
   -z, --zpool LABEL   Print zpool containing LABEL.
   CMD [ARGS] ...      Run CMD in parallel for each device substituting:
                       %f=fsname  %d=device  %i=dec-index %n=main-nid %l=label
-                      %t=srvtype %j=journal %I=hex-index %N=fail-nid
+                      %t=srvtype %j=journal %I=hex-index %N=fail-nid %m=mgs-nid
                       May be used in combination with -l, -f, -a options.
 EOF
 
                       May be used in combination with -l, -f, -a options.
 EOF
 
@@ -111,7 +111,7 @@ sub parse_cmdline
         $conf{execcmd} = " " . join " ", @ARGV;
     }
 
         $conf{execcmd} = " " . join " ", @ARGV;
     }
 
-    parse_nids () if ($conf{execcmd} =~ /(%n|%N)/);
+    parse_nids () if ($conf{execcmd} =~ /(%n|%N|%m)/);
 }
 
 sub parse_config
 }
 
 sub parse_config
@@ -124,6 +124,8 @@ sub parse_config
     my %label2raidtab = ();
     my %label2type = ();
     my %label2zpool = ();
     my %label2raidtab = ();
     my %label2type = ();
     my %label2zpool = ();
+    my %filesys2mgs = ();
+    my %label2hostname = ();
     my @local_labels = ();
     my @foreign_labels = ();
 
     my @local_labels = ();
     my @foreign_labels = ();
 
@@ -148,6 +150,9 @@ sub parse_config
 
         eparse_line ($line, "elabel_uniq") if (exists $label2dev{$label}
                                          || exists $label2local{$label});
 
         eparse_line ($line, "elabel_uniq") if (exists $label2dev{$label}
                                          || exists $label2local{$label});
+        /(\w+)-(OST|MDT|MGT|MGS)([0-9a-fA-F]{4})/, $label;
+        my $filesys = $1;
+        my $nodetype = $2;
         $label2dev{$label} = $dev;
         $label2local{$label} = $local;
         $label2journal{$label} = $j if defined $j;
         $label2dev{$label} = $dev;
         $label2local{$label} = $local;
         $label2journal{$label} = $j if defined $j;
@@ -158,6 +163,10 @@ sub parse_config
                 $label2zpool{$label} = $1;
             }
         }
                 $label2zpool{$label} = $1;
             }
         }
+        $label2hostname{$label}=$local;
+        if ($nodetype eq "MGS" or $nodetype eq "MGT") {
+            $filesys2mgs{$filesys} = $label;
+        }
 
         if ($local eq $conf{hostname}) {
             push @local_labels, $label;
 
         if ($local eq $conf{hostname}) {
             push @local_labels, $label;
@@ -183,6 +192,8 @@ sub parse_config
     %{$conf{label2raidtab}} = %label2raidtab;
     %{$conf{label2type}} = %label2type;
     %{$conf{label2zpool}} = %label2zpool;
     %{$conf{label2raidtab}} = %label2raidtab;
     %{$conf{label2type}} = %label2type;
     %{$conf{label2zpool}} = %label2zpool;
+    %{$conf{filesys2mgs}} = %filesys2mgs;
+    %{$conf{label2hostname}} = %label2hostname;
 }
 
 sub parse_nids ()
 }
 
 sub parse_nids ()
@@ -386,6 +397,8 @@ sub exec_cmd
     my @cmds = ();
     my %label2dev = %{$conf{label2dev}};
     my %label2journal = %{$conf{label2journal}};
     my @cmds = ();
     my %label2dev = %{$conf{label2dev}};
     my %label2journal = %{$conf{label2journal}};
+    my %filesys2mgs = %{$conf{filesys2mgs}};
+    my %label2hostname = %{$conf{label2hostname}};
     my %l2f = %{$conf{l2f}};
     my ($nid, $failnid);
 
     my %l2f = %{$conf{l2f}};
     my ($nid, $failnid);
 
@@ -415,7 +428,7 @@ sub exec_cmd
         @labels = (@{$conf{local_labels}}, @{$conf{foreign_labels}});
     }
     foreach (@labels) {
         @labels = (@{$conf{local_labels}}, @{$conf{foreign_labels}});
     }
     foreach (@labels) {
-        /(\w+)-(OST|MDT|MGT)([0-9a-fA-F]{4})/;
+        /(\w+)-(OST|MDT|MGT|MGS)([0-9a-fA-F]{4})/;
 
         my $fsname = $1;
         my $type = $2; $type =~ tr/A-Z/a-z/;
 
         my $fsname = $1;
         my $type = $2; $type =~ tr/A-Z/a-z/;
@@ -428,6 +441,24 @@ sub exec_cmd
             log_fatal ("%j used but no journal defined for $_\n");
         }
         my $journal = $label2journal{$_};
             log_fatal ("%j used but no journal defined for $_\n");
         }
         my $journal = $label2journal{$_};
+        my $mgsnid;
+        if ($cmd =~ /%m/) {
+            if (!exists $filesys2mgs{$fsname}) {
+                 log_fatal ("$fsname has no MGS defined\n");
+            }
+
+            my $mgs = $filesys2mgs{$fsname};
+            if (!exists $label2hostname{$mgs}) {
+                 log_fatal ("$mgs has no hostname defined\n");
+            }
+
+            my %host2nid = %{$conf{host2nid}};
+            $mgs = $label2hostname{$mgs};
+            if (!exists $host2nid{$mgs}) {
+                 log_fatal ("$mgs has no NID defined\n");
+            }
+            $mgsnid = $host2nid{$mgs};
+        }
 
         $cmd =~ s/%f/$fsname/g;  # %f = fsname
         $cmd =~ s/%t/$type/g;    # %t = server type
 
         $cmd =~ s/%f/$fsname/g;  # %f = fsname
         $cmd =~ s/%t/$type/g;    # %t = server type
@@ -438,6 +469,7 @@ sub exec_cmd
         $cmd =~ s/%j/$journal/g; # %j = journal device
         $cmd =~ s/%n/$nid/g;     # %n = nid
         $cmd =~ s/%N/$failnid/g; # %N = failnid
         $cmd =~ s/%j/$journal/g; # %j = journal device
         $cmd =~ s/%n/$nid/g;     # %n = nid
         $cmd =~ s/%N/$failnid/g; # %N = failnid
+        $cmd =~ s/%m/$mgsnid/g;  # %m = MGS nid
 
         push @cmds, "$_ $cmd";
     }
 
         push @cmds, "$_ $cmd";
     }
index 7a6d88e..7254a2f 100755 (executable)
@@ -6293,6 +6293,111 @@ test_91() {
 }
 run_test 91 "evict-by-nid support"
 
 }
 run_test 91 "evict-by-nid support"
 
+generate_ldev_conf() {
+       # generate an ldev.conf file
+       local ldevconfpath=$1
+       touch $ldevconfpath
+       printf "%s\t-\t%s-MGS0000\t%s\n" \
+               $mgs_HOST \
+               $FSNAME \
+               $(mgsdevname) >> $ldevconfpath
+
+       local mdsfo_host=$mdsfailover_HOST;
+       if [ -z "$mdsfo_host" ]; then
+               mdsfo_host="-"
+       fi
+
+       for num in $(seq $MDSCOUNT); do
+               printf "%s\t%s\t%s-MDT%04d\t%s\n" \
+                       $mds_HOST \
+                       $mdsfo_host \
+                       $FSNAME \
+                       $num \
+                       $(mdsdevname $num) >> $ldevconfpath
+       done
+
+       local ostfo_host=$ostfailover_HOST;
+       if [ -z "$ostfo_host" ]; then
+               ostfo_host="-"
+       fi
+
+       for num in $(seq $OSTCOUNT); do
+               printf "%s\t%s\t%s-OST%04d\t%s\n" \
+                       $ost_HOST \
+                       $ostfo_host \
+                       $FSNAME \
+                       $num \
+                       $(ostdevname $num) >> $ldevconfpath
+       done
+}
+
+generate_nids() {
+       # generate a nids file (mapping between hostname to nid)
+       # looks like we only have the MGS nid available to us
+       # so just echo that to a file
+       local nidspath=$1
+       touch $nidspath
+       echo -e "${mgs_HOST}\t${MGSNID}" >> $nidspath
+}
+
+test_92() {
+       local LDEVCONFPATH=$TMP/ldev.conf
+       local NIDSPATH=$TMP/nids
+
+       echo "Host is $(hostname)"
+
+       generate_ldev_conf $LDEVCONFPATH
+       generate_nids $NIDSPATH
+
+       echo "----- ldev.conf -----"
+       cat $LDEVCONFPATH
+       echo "--- END ldev.conf ---"
+
+       echo "----- /etc/nids -----"
+       cat $NIDSPATH
+       echo "--- END /etc/nids ---"
+
+       # ldev can be in our build tree and if we aren't in a
+       # build tree, use 'which' to try and find it
+       local LDEV=$LUSTRE/scripts/ldev
+       [ ! -f "$LDEV" ] && local LDEV=$(which ldev 2> /dev/null)
+
+       echo "ldev path is $LDEV"
+
+       if [ ! -f "$LDEV" ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "failed to find ldev!"
+       fi
+
+       # echo the mgs nid and compare it to environment variable MGSNID
+       # also, ldev.conf and nids is a server side thing, use the OSS
+       # hostname
+       local output
+       output=$(perl $LDEV -c $LDEVCONFPATH -H \
+                       $ost_HOST -n $NIDSPATH echo %m)
+
+       echo "-- START OF LDEV OUTPUT --"
+       echo -e "$output"
+       echo "--- END OF LDEV OUTPUT ---"
+
+       # ldev failed, error
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev failed to execute!"
+       fi
+
+       # need to process multiple lines because of combined MGS and MDS
+       echo -e $output | awk '{ print $2 }' | while read -r line ; do
+               if [ "$line" != "$MGSNID" ]; then
+                       rm $LDEVCONFPATH $NIDSPATH
+                       error "ldev failed mgs nid '$line', expected '$MGSNID'"
+               fi
+       done
+
+       rm $LDEVCONFPATH $NIDSPATH
+}
+run_test 92 "ldev returns MGS NID correctly in command substitution"
+
 if ! combined_mgs_mds ; then
        stop mgs
 fi
 if ! combined_mgs_mds ; then
        stop mgs
 fi