Whamcloud - gitweb
LU-8055 ldev: Introduced role filtering
[fs/lustre-release.git] / lustre / scripts / ldev
index 569daf6..77c0040 100755 (executable)
@@ -29,9 +29,11 @@ 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
+                      %H=hostname %b=backing-fs
                       May be used in combination with -l, -f, -a, -F options.
 EOF
 
@@ -87,6 +89,7 @@ sub parse_cmdline
     $conf{sanity} = 0;
     $conf{execcmd} = "";
     $conf{journal} = "";
+    $conf{role} = "";
     $conf{fsname} = "";
 
     my $rc = GetOptions (
@@ -104,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},
     );
 
@@ -162,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;
@@ -176,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}) {
@@ -418,6 +425,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}};
@@ -453,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/;
@@ -466,6 +474,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 +508,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";
     }