Whamcloud - gitweb
LU-8055 ldev: File system label filtering 38/19738/14
authorGiuseppe Di Natale <dinatale2@llnl.gov>
Thu, 5 May 2016 22:17:24 +0000 (15:17 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 5 Jul 2016 23:52:35 +0000 (23:52 +0000)
Introduced -F option to ldev. The -F requires
a file system name to be provided. All labels
associated with that file system will be
printed to stdout. The new option can also be
used with command substitution.

Test-Parameters: trivial testlist=conf-sanity

Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Change-Id: I50726371dce809e4d1b4f3de6f530d6f637856a1
Reviewed-on: http://review.whamcloud.com/19738
Tested-by: Jenkins
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
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 [changed mode: 0644->0755]
lustre/tests/conf-sanity.sh
lustre/tests/test-framework.sh

index 187cc3f..c9f85e8 100644 (file)
@@ -33,6 +33,9 @@ Print labels for foreign devices.
 .I "-a, --all"
 Print labels for local and foreign devices.
 .TP
+.I "-F, --filesys NAME"
+Print labels for file system NAME.
+.TP
 .I "-s, --sanity"
 Sanity check config on this node.
 If any expected local or foreign devices are not present, print an error.
@@ -59,8 +62,9 @@ Print zpool containing LABEL.
 .TP
 .I "CMD [ARGS...]"
 Run one instance of \fICMD [ARGS]\fR for each label in parallel.
-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.
+Only the local labels are used by default, but foreign, all, or file system
+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
old mode 100644 (file)
new mode 100755 (executable)
index 8d7df7a..569daf6
@@ -22,6 +22,7 @@ Parse ldev.conf and answer the following queries:
   -l, --local         Print labels for local devices.
   -f, --foreign       Print labels for foreign devices.
   -a, --all           Print labels for local and foreign devices.
+  -F, --filesys NAME  Print labels for file system NAME.
   -s, --sanity        Sanity check config on this node.
   -d, --device LABEL  Print storage device of LABEL.
   -j, --journal LABEL Print journal device of LABEL if it exists.
@@ -31,7 +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
-                      May be used in combination with -l, -f, -a options.
+                      May be used in combination with -l, -f, -a, -F options.
 EOF
 
 my %eparse = (
@@ -62,6 +63,7 @@ query_journal ()  if $conf{journal};
 query_raidtab ()  if $conf{raidtab};
 query_type ()     if $conf{type};
 query_zpool ()    if $conf{zpool};
+query_filesys ()  if $conf{fsname};
 
 exit(0);
 
@@ -85,6 +87,7 @@ sub parse_cmdline
     $conf{sanity} = 0;
     $conf{execcmd} = "";
     $conf{journal} = "";
+    $conf{fsname} = "";
 
     my $rc = GetOptions (
         "help|h!"         => \$help,
@@ -101,12 +104,20 @@ sub parse_cmdline
         "raidtab|r=s"     => \$conf{raidtab},
         "type|t=s"        => \$conf{type},
         "zpool|z=s"       => \$conf{zpool},
+        "filesys|F=s"     => \$conf{fsname},
     );
 
     usage() if $help || !$rc;
 
     log_fatal ("cannot read config file\n") if (! -r $conf{config});
 
+    my $filters = 0;
+    $filters++ if ($conf{local});
+    $filters++ if ($conf{foreign});
+    $filters++ if ($conf{all});
+    $filters++ if ($conf{fsname});
+    log_fatal ("Only one of -l, -f, -a, or -F may be used.\n") if ($filters > 1);
+
     if (@ARGV) {
         $conf{execcmd} = " " . join " ", @ARGV;
     }
@@ -128,6 +139,7 @@ sub parse_config
     my %label2hostname = ();
     my @local_labels = ();
     my @foreign_labels = ();
+    my @fs_labels = ();
 
     open (CONF, "< $conf{config}") or log_fatal ("$conf{config}: $!\n");
 
@@ -173,6 +185,10 @@ sub parse_config
         } elsif ($foreign eq $conf{hostname}) {
             push @foreign_labels, $label;
         }
+
+        if ($conf{fsname} and $filesys eq $conf{fsname}) {
+            push @fs_labels, $label;
+        }
     }
     close CONF;
 
@@ -185,6 +201,7 @@ sub parse_config
 
     @{$conf{local_labels}} = @local_labels;
     @{$conf{foreign_labels}} = @foreign_labels;
+    @{$conf{fs_labels}} = @fs_labels;
     %{$conf{l2f}} = %l2f;
     %{$conf{label2dev}} = %label2dev;
     %{$conf{label2local}} = %label2local;
@@ -242,6 +259,11 @@ sub query_foreign
     map { print "$_\n"; } @{$conf{foreign_labels}};
 }
 
+sub query_filesys
+{
+    map { print "$_\n"; } @{$conf{fs_labels}};
+}
+
 sub query_all
 {
     query_local ();
@@ -420,13 +442,16 @@ sub exec_cmd
         $failnid = $host2nid{$l2f{$conf{hostname}}};
     }
 
-    if ($conf{foreign} and !$conf{local} and !$conf{all}) {
+    if ($conf{foreign}) {
         @labels = @{$conf{foreign_labels}};
-    } elsif (!$conf{foreign} and !$conf{all}) {
-        @labels = @{$conf{local_labels}};
-    } else {
+    } elsif ($conf{all}) {
         @labels = (@{$conf{local_labels}}, @{$conf{foreign_labels}});
+    } elsif ($conf{fsname}) {
+        @labels = (@labels, @{$conf{fs_labels}});
+    } else {
+        @labels = @{$conf{local_labels}};
     }
+
     foreach (@labels) {
         /(\w+)-(OST|MDT|MGT|MGS)([0-9a-fA-F]{4})/;
 
index 48252bf..000be7a 100755 (executable)
@@ -6345,7 +6345,7 @@ generate_ldev_conf() {
        printf "%s\t-\t%s-MGS0000\t%s\n" \
                $mgs_HOST \
                $FSNAME \
-               $(mgsdevname) >> $ldevconfpath
+               $(mgsdevname) > $ldevconfpath
 
        local mdsfo_host=$mdsfailover_HOST;
        if [ -z "$mdsfo_host" ]; then
@@ -6374,6 +6374,11 @@ generate_ldev_conf() {
                        $num \
                        $(ostdevname $num) >> $ldevconfpath
        done
+
+       echo "----- $ldevconfpath -----"
+       cat $ldevconfpath
+       echo "--- END $ldevconfpath ---"
+
 }
 
 generate_nids() {
@@ -6381,11 +6386,37 @@ generate_nids() {
        # 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
+       echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
+
+       echo "----- $nidspath -----"
+       cat $nidspath
+       echo "--- END $nidspath ---"
+}
+
+compare_ldev_output() {
+       ldev_output=$1
+       expected_output=$2
+
+       sort $expected_output -o $expected_output
+       sort $ldev_output -o $ldev_output
+
+       echo "-- START OF LDEV OUTPUT --"
+       cat $ldev_output
+       echo "--- END OF LDEV OUTPUT ---"
+
+       echo "-- START OF EXPECTED OUTPUT --"
+       cat $expected_output
+       echo "--- END OF EXPECTED OUTPUT ---"
+
+       diff $expected_output $ldev_output
+       return $?
 }
 
 test_92() {
+       if [ -z "$LDEV" ]; then
+               error "ldev is missing!"
+       fi
+
        local LDEVCONFPATH=$TMP/ldev.conf
        local NIDSPATH=$TMP/nids
 
@@ -6394,32 +6425,11 @@ test_92() {
        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)
+       output=$($LDEV -c $LDEVCONFPATH -H $ost_HOST -n $NIDSPATH echo %m)
 
        echo "-- START OF LDEV OUTPUT --"
        echo -e "$output"
@@ -6472,6 +6482,137 @@ test_93() {
 }
 run_test 93 "register mulitple MDT at the same time"
 
+test_94() {
+       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 -F $FSNAME > $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.txt
+
+       printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
+
+       for num in $(seq $MDSCOUNT); do
+               printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
+       done
+
+       for num in $(seq $OSTCOUNT); do
+               printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
+       done
+
+       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 hostlist!"
+       fi
+
+       rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
+}
+run_test 94 "ldev outputs correct labels for file system name query"
+
+test_95() {
+       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
+
+       # SUCCESS CASES
+       # file sys filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -F failed!"
+       fi
+
+       # local filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -l failed!"
+       fi
+
+       # foreign filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -f failed!"
+       fi
+
+       # all filter
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
+       if [ $? -ne 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a failed!"
+       fi
+
+       # FAILURE CASES
+       # all & file sys
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a and -F incorrectly succeeded"
+       fi
+
+       # all & foreign
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a and -f incorrectly succeeded"
+       fi
+
+       # all & local
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -a and -l incorrectly succeeded"
+       fi
+
+       # foreign & local
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -f and -l incorrectly succeeded"
+       fi
+
+       # file sys & local
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -F and -l incorrectly succeeded"
+       fi
+
+       # file sys & foreign
+       $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
+       if [ $? -eq 0 ]; then
+               rm $LDEVCONFPATH $NIDSPATH
+               error "ldev label filtering w/ -F and -f incorrectly succeeded"
+       fi
+
+       rm $LDEVCONFPATH $NIDSPATH
+}
+run_test 95 "ldev should only allow one label filter"
+
 if ! combined_mgs_mds ; then
        stop mgs
 fi
index 6d6843a..7efae3a 100755 (executable)
@@ -294,6 +294,8 @@ init_test_env() {
     export DIR2
     export SAVE_PWD=${SAVE_PWD:-$LUSTRE/tests}
     export AT_MAX_PATH
+    export LDEV=${LDEV:-"$LUSTRE/scripts/ldev"}
+    [ ! -f "$LDEV" ] && export LDEV=$(which ldev 2> /dev/null)
 
     if [ "$ACCEPTOR_PORT" ]; then
         export PORT_OPT="--port $ACCEPTOR_PORT"