Whamcloud - gitweb
LU-8055 ldev: Add %H and %b to command sub 40/20040/9
authorGiuseppe Di Natale <dinatale2@llnl.gov>
Thu, 5 May 2016 22:43:28 +0000 (15:43 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 5 Jul 2016 23:52:49 +0000 (23:52 +0000)
Introduced %H and %b substitutions for hostname
and backend file system, respectively.

Test-Parameters: trivial testlist=conf-sanity
Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Change-Id: I9b50defee43307f614106de4ad75e1fa9267e23b
Reviewed-on: http://review.whamcloud.com/20040
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Christopher J. Morrone <morrone2@llnl.gov>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/doc/ldev.8
lustre/scripts/ldev
lustre/tests/conf-sanity.sh

index c9f85e8..ef609b6 100644 (file)
@@ -67,8 +67,8 @@ labels may be selected by adding the \fI--foreign\fR, \fI--all\fR, or
 \fI--filesys\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, %m=mgsnid.  On failure of any child processes, \fBldev\fR will
-return a non-zero exit code.
+%n=nid, %N=failnid, %m=mgsnid, %H=hostname, %b=backing-fs.  On failure of
+any child processes, \fBldev\fR will return a non-zero exit code.
 .LP
 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.
index 569daf6..8005bcf 100755 (executable)
@@ -32,6 +32,7 @@ Parse ldev.conf and answer the following queries:
   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 %m=mgs-nid
+                      %H=hostname %b=backing-fs
                       May be used in combination with -l, -f, -a, -F options.
 EOF
 
@@ -418,6 +419,7 @@ sub exec_cmd
     my @labels = ();
     my @cmds = ();
     my %label2dev = %{$conf{label2dev}};
+    my %label2type = %{$conf{label2type}};
     my %label2journal = %{$conf{label2journal}};
     my %filesys2mgs = %{$conf{filesys2mgs}};
     my %label2hostname = %{$conf{label2hostname}};
@@ -466,6 +468,11 @@ sub exec_cmd
             log_fatal ("%j used but no journal defined for $_\n");
         }
         my $journal = $label2journal{$_};
+        my $fstype = $label2type{$_};
+        if (!defined $fstype or $fstype ne "zfs") {
+            $fstype = "ldiskfs";
+        }
+        my $hostname = $label2hostname{$_};
         my $mgsnid;
         if ($cmd =~ /%m/) {
             if (!exists $filesys2mgs{$fsname}) {
@@ -495,6 +502,8 @@ sub exec_cmd
         $cmd =~ s/%n/$nid/g;     # %n = nid
         $cmd =~ s/%N/$failnid/g; # %N = failnid
         $cmd =~ s/%m/$mgsnid/g;  # %m = MGS nid
+        $cmd =~ s/%b/$fstype/g;  # %b = backing file system type
+        $cmd =~ s/%H/$hostname/g;# %H = hostname
 
         push @cmds, "$_ $cmd";
     }
index 000be7a..c5d4ee3 100755 (executable)
@@ -6341,10 +6341,21 @@ run_test 91 "evict-by-nid support"
 generate_ldev_conf() {
        # generate an ldev.conf file
        local ldevconfpath=$1
+       local fstype=
+       local fsldevformat=""
        touch $ldevconfpath
-       printf "%s\t-\t%s-MGS0000\t%s\n" \
+
+       fstype=$(facet_fstype mgs)
+       if [ "$fstype" == "zfs" ]; then
+               fsldevformat="$fstype:"
+       else
+               fsldevformat=""
+       fi
+
+       printf "%s\t-\t%s-MGS0000\t%s%s\n" \
                $mgs_HOST \
                $FSNAME \
+               $fsldevformat \
                $(mgsdevname) > $ldevconfpath
 
        local mdsfo_host=$mdsfailover_HOST;
@@ -6353,11 +6364,19 @@ generate_ldev_conf() {
        fi
 
        for num in $(seq $MDSCOUNT); do
-               printf "%s\t%s\t%s-MDT%04d\t%s\n" \
+               fstype=$(facet_fstype mds$num)
+               if [ "$fstype" == "zfs" ]; then
+                       fsldevformat="$fstype:"
+               else
+                       fsldevformat=""
+               fi
+
+               printf "%s\t%s\t%s-MDT%04d\t%s%s\n" \
                        $mds_HOST \
                        $mdsfo_host \
                        $FSNAME \
                        $num \
+                       $fsldevformat \
                        $(mdsdevname $num) >> $ldevconfpath
        done
 
@@ -6367,11 +6386,19 @@ generate_ldev_conf() {
        fi
 
        for num in $(seq $OSTCOUNT); do
-               printf "%s\t%s\t%s-OST%04d\t%s\n" \
+               fstype=$(facet_fstype ost$num)
+               if [ "$fstype" == "zfs" ]; then
+                       fsldevformat="$fstype:"
+               else
+                       fsldevformat=""
+               fi
+
+               printf "%s\t%s\t%s-OST%04d\t%s%s\n" \
                        $ost_HOST \
                        $ostfo_host \
                        $FSNAME \
                        $num \
+                       $fsldevformat \
                        $(ostdevname $num) >> $ldevconfpath
        done
 
@@ -6613,6 +6640,58 @@ test_95() {
 }
 run_test 95 "ldev should only allow one label filter"
 
+test_96() {
+       if [ -z "$LDEV" ]; then
+               error "ldev is missing!"
+       fi
+
+       local LDEVCONFPATH=$TMP/ldev.conf
+       local NIDSPATH=$TMP/nids
+
+       generate_ldev_conf $LDEVCONFPATH
+       generate_nids $NIDSPATH
+
+       local LDEV_OUTPUT=$TMP/ldev-output.txt
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -H $mgs_HOST \
+               echo %H-%b | \
+               awk '{print $2}' > $LDEV_OUTPUT
+
+       # ldev failed, error
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
+               error "ldev failed to execute!"
+       fi
+
+       # expected output
+       local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
+
+       echo "$mgs_HOST-$(facet_fstype mgs)" > $EXPECTED_OUTPUT
+
+       if [ "$mgs_HOST" == "$mds_HOST" ]; then
+               for num in $(seq $MDSCOUNT); do
+                       echo "$mds_HOST-$(facet_fstype mds$num)" \
+                       >> $EXPECTED_OUTPUT
+               done
+       fi
+
+       if [ "$mgs_HOST" == "$ost_HOST" ]; then
+               for num in $(seq $OSTCOUNT); do
+                       echo "$ost_HOST-$(facet_fstype ost$num)" \
+                       >> $EXPECTED_OUTPUT
+               done
+       fi
+
+       compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
+
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
+               error "ldev failed to produce the correct output!"
+       fi
+
+       rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
+}
+run_test 96 "ldev returns hostname and backend fs correctly in command sub"
+
 if ! combined_mgs_mds ; then
        stop mgs
 fi