From faa958d6c5dda97f0c014d3ba36d40b324c2941a Mon Sep 17 00:00:00 2001 From: Giuseppe Di Natale Date: Thu, 5 May 2016 15:44:38 -0700 Subject: [PATCH] LU-8055 ldev: Introduced role filtering Output can now be filtered by using -R or --role as command line parameters, where role is a string such as "mdt", "ost", or "mgs". Also removed MGT as a possible node type in ldev.conf. Test-Parameters: trivial testlist=conf-sanity Signed-off-by: Giuseppe Di Natale Change-Id: I488ac702edf0cc7c08020b289dcba040706181b4 Reviewed-on: http://review.whamcloud.com/20041 Reviewed-by: Olaf Faaland-LLNL Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Christopher J. Morrone Reviewed-by: Oleg Drokin --- lustre/doc/ldev.8 | 3 ++ lustre/scripts/ldev | 12 ++++++-- lustre/tests/conf-sanity.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/lustre/doc/ldev.8 b/lustre/doc/ldev.8 index ef609b6..75a6ea6 100644 --- a/lustre/doc/ldev.8 +++ b/lustre/doc/ldev.8 @@ -60,6 +60,9 @@ Print device type of LABEL, i.e. "zfs" or "md". .I "-z, --zpool LABEL" Print zpool containing LABEL. .TP +.I "-R, --role ROLE" +Filter output based on role, i.e. mdt, ost, mgs. +.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, all, or file system diff --git a/lustre/scripts/ldev b/lustre/scripts/ldev index 8005bcf..77c0040 100755 --- a/lustre/scripts/ldev +++ b/lustre/scripts/ldev @@ -29,6 +29,7 @@ Parse ldev.conf and answer the following queries: -r, --raidtab LABEL Print raidtab of LABEL if it exists. -t, --type LABEL Print device type of LABEL, i.e. "zfs" or "md". -z, --zpool LABEL Print zpool containing LABEL. + -R, --role ROLE Filter output based on role, i.e. mdt, ost, mgs. 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 @@ -88,6 +89,7 @@ sub parse_cmdline $conf{sanity} = 0; $conf{execcmd} = ""; $conf{journal} = ""; + $conf{role} = ""; $conf{fsname} = ""; my $rc = GetOptions ( @@ -105,6 +107,7 @@ sub parse_cmdline "raidtab|r=s" => \$conf{raidtab}, "type|t=s" => \$conf{type}, "zpool|z=s" => \$conf{zpool}, + "role|R=s" => \$conf{role}, "filesys|F=s" => \$conf{fsname}, ); @@ -163,7 +166,7 @@ sub parse_config eparse_line ($line, "elabel_uniq") if (exists $label2dev{$label} || exists $label2local{$label}); - /(\w+)-(OST|MDT|MGT|MGS)([0-9a-fA-F]{4})/, $label; + /(\w+)-(OST|MDT|MGS)([0-9a-fA-F]{4})/, $label; my $filesys = $1; my $nodetype = $2; $label2dev{$label} = $dev; @@ -177,10 +180,13 @@ sub parse_config } } $label2hostname{$label}=$local; - if ($nodetype eq "MGS" or $nodetype eq "MGT") { + + if ($nodetype eq "MGS") { $filesys2mgs{$filesys} = $label; } + next if $conf{role} and lc $conf{role} ne lc $nodetype; + if ($local eq $conf{hostname}) { push @local_labels, $label; } elsif ($foreign eq $conf{hostname}) { @@ -455,7 +461,7 @@ sub exec_cmd } foreach (@labels) { - /(\w+)-(OST|MDT|MGT|MGS)([0-9a-fA-F]{4})/; + /(\w+)-(OST|MDT|MGS)([0-9a-fA-F]{4})/; my $fsname = $1; my $type = $2; $type =~ tr/A-Z/a-z/; diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh index b639d44..6702d6c 100755 --- a/lustre/tests/conf-sanity.sh +++ b/lustre/tests/conf-sanity.sh @@ -6705,6 +6705,80 @@ test_96() { } run_test 96 "ldev returns hostname and backend fs correctly in command sub" +test_97() { + 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 + local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt + + echo -e "\nMDT role" + $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mdt > $LDEV_OUTPUT + + if [ $? -ne 0 ]; then + rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT + error "ldev failed to execute for mdt role!" + fi + + for num in $(seq $MDSCOUNT); do + printf "%s-MDT%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 output for mdt role!" + fi + + echo -e "\nOST role" + $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R ost > $LDEV_OUTPUT + + if [ $? -ne 0 ]; then + rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT + error "ldev failed to execute for ost role!" + fi + + rm $EXPECTED_OUTPUT + 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 output for ost role!" + fi + + echo -e "\nMGS role" + $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mgs > $LDEV_OUTPUT + + if [ $? -ne 0 ]; then + rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT + error "ldev failed to execute for mgs role!" + fi + + printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT + + 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 for mgs role!" + fi + + rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT +} +run_test 97 "ldev returns correct ouput when querying based on role" + if ! combined_mgs_mds ; then stop mgs fi -- 1.8.3.1