X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fscripts%2Fldev;h=77c0040bdfa551a6a6c104fefaf93406a0b3bc58;hp=4b7b008323017a68bb61301506045a166612f074;hb=c1d0a355a6a64ec97c9f56c38ba036e5e50cd8c4;hpb=04a38ba7cda4e242850a47b13d4402a69e8dd921 diff --git a/lustre/scripts/ldev b/lustre/scripts/ldev old mode 100644 new mode 100755 index 4b7b008..77c0040 --- a/lustre/scripts/ldev +++ b/lustre/scripts/ldev @@ -22,16 +22,19 @@ 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. -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 - May be used in combination with -l, -f, -a options. + %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 my %eparse = ( @@ -62,6 +65,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 +89,8 @@ sub parse_cmdline $conf{sanity} = 0; $conf{execcmd} = ""; $conf{journal} = ""; + $conf{role} = ""; + $conf{fsname} = ""; my $rc = GetOptions ( "help|h!" => \$help, @@ -101,17 +107,26 @@ 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}, ); 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; } - parse_nids () if ($conf{execcmd} =~ /(%n|%N)/); + parse_nids () if ($conf{execcmd} =~ /(%n|%N|%m)/); } sub parse_config @@ -124,8 +139,11 @@ sub parse_config my %label2raidtab = (); my %label2type = (); my %label2zpool = (); + my %filesys2mgs = (); + my %label2hostname = (); my @local_labels = (); my @foreign_labels = (); + my @fs_labels = (); open (CONF, "< $conf{config}") or log_fatal ("$conf{config}: $!\n"); @@ -148,6 +166,9 @@ sub parse_config eparse_line ($line, "elabel_uniq") if (exists $label2dev{$label} || exists $label2local{$label}); + /(\w+)-(OST|MDT|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; @@ -158,12 +179,23 @@ sub parse_config $label2zpool{$label} = $1; } } + $label2hostname{$label}=$local; + + 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}) { push @foreign_labels, $label; } + + if ($conf{fsname} and $filesys eq $conf{fsname}) { + push @fs_labels, $label; + } } close CONF; @@ -176,6 +208,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; @@ -183,6 +216,8 @@ sub parse_config %{$conf{label2raidtab}} = %label2raidtab; %{$conf{label2type}} = %label2type; %{$conf{label2zpool}} = %label2zpool; + %{$conf{filesys2mgs}} = %filesys2mgs; + %{$conf{label2hostname}} = %label2hostname; } sub parse_nids () @@ -231,6 +266,11 @@ sub query_foreign map { print "$_\n"; } @{$conf{foreign_labels}}; } +sub query_filesys +{ + map { print "$_\n"; } @{$conf{fs_labels}}; +} + sub query_all { query_local (); @@ -385,7 +425,10 @@ 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}}; my %l2f = %{$conf{l2f}}; my ($nid, $failnid); @@ -407,15 +450,18 @@ 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)([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/; @@ -428,6 +474,29 @@ 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}) { + 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 @@ -438,6 +507,9 @@ 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/%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"; }