From c86a1a5bd20cd97ed578fb450b3773772ad72d9c Mon Sep 17 00:00:00 2001 From: Giuseppe Di Natale Date: Thu, 5 May 2016 15:43:28 -0700 Subject: [PATCH 1/1] LU-8055 ldev: Add %H and %b to command sub Introduced %H and %b substitutions for hostname and backend file system, respectively. Test-Parameters: trivial testlist=conf-sanity Signed-off-by: Giuseppe Di Natale Change-Id: I9b50defee43307f614106de4ad75e1fa9267e23b Reviewed-on: http://review.whamcloud.com/20040 Reviewed-by: Olaf Faaland-LLNL Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Christopher J. Morrone Reviewed-by: Oleg Drokin --- lustre/doc/ldev.8 | 4 +-- lustre/scripts/ldev | 9 +++++ lustre/tests/conf-sanity.sh | 85 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/lustre/doc/ldev.8 b/lustre/doc/ldev.8 index c9f85e8..ef609b6 100644 --- a/lustre/doc/ldev.8 +++ b/lustre/doc/ldev.8 @@ -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. diff --git a/lustre/scripts/ldev b/lustre/scripts/ldev index 569daf6..8005bcf 100755 --- a/lustre/scripts/ldev +++ b/lustre/scripts/ldev @@ -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"; } diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh index 000be7a..c5d4ee3 100755 --- a/lustre/tests/conf-sanity.sh +++ b/lustre/tests/conf-sanity.sh @@ -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 -- 1.8.3.1