-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 %m=mgs-nid
- May be used in combination with -l, -f, -a options.
+ %H=hostname %b=backing-fs
+ May be used in combination with -l, -f, -a, -F options.
EOF
my %eparse = (
query_raidtab () if $conf{raidtab};
query_type () if $conf{type};
query_zpool () if $conf{zpool};
+query_filesys () if $conf{fsname};
exit(0);
$conf{sanity} = 0;
$conf{execcmd} = "";
$conf{journal} = "";
+ $conf{role} = "";
+ $conf{fsname} = "";
my $rc = GetOptions (
"help|h!" => \$help,
"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;
}
my %label2hostname = ();
my @local_labels = ();
my @foreign_labels = ();
+ my @fs_labels = ();
open (CONF, "< $conf{config}") or log_fatal ("$conf{config}: $!\n");
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;
}
}
$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}) {
push @foreign_labels, $label;
}
+
+ if ($conf{fsname} and $filesys eq $conf{fsname}) {
+ push @fs_labels, $label;
+ }
}
close CONF;
@{$conf{local_labels}} = @local_labels;
@{$conf{foreign_labels}} = @foreign_labels;
+ @{$conf{fs_labels}} = @fs_labels;
%{$conf{l2f}} = %l2f;
%{$conf{label2dev}} = %label2dev;
%{$conf{label2local}} = %label2local;
map { print "$_\n"; } @{$conf{foreign_labels}};
}
+sub query_filesys
+{
+ map { print "$_\n"; } @{$conf{fs_labels}};
+}
+
sub query_all
{
query_local ();
my @labels = ();
my @cmds = ();
my %label2dev = %{$conf{label2dev}};
+ my %label2type = %{$conf{label2type}};
my %label2journal = %{$conf{label2journal}};
my %filesys2mgs = %{$conf{filesys2mgs}};
my %label2hostname = %{$conf{label2hostname}};
$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})/;
+ /(\w+)-(OST|MDT|MGS)([0-9a-fA-F]{4})/;
my $fsname = $1;
my $type = $2; $type =~ tr/A-Z/a-z/;
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}) {
$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";
}