marsadm: view additional mount info when possible

This commit is contained in:
Thomas Schoebel-Theuer 2022-08-05 13:15:33 +02:00 committed by Thomas Schoebel-Theuer
parent a505a391b5
commit 095b96620d

View File

@ -311,6 +311,9 @@ my $kernel_strategy_version = -1;
my $kernel_flags_version = ~0x0;
my %known_ips;
my %known_mounts;
my %known_fstypes;
my %known_mountflags;
##################################################################
@ -4745,6 +4748,25 @@ sub _get_ip {
ldie "Cannot determine my own IP address ($real_host)\n";
}
sub _get_known_mounts {
my ($cmd, $res) = @_;
if (!%known_mounts) {
my $proc_mounts = "/proc/mounts";
open(my $fh, "<", $proc_mounts)
or return "";
while (my $line = <$fh>) {
chomp $line;
next unless $line =~ m:^/dev/mars/([^\s]+)\s+([^\s]+)\s*([^\s]*)\s*([^\s]*):;
my ($resname, $mountpoint, $fstype, $mountflags) = ($1, $2, $3, $4);
$known_mounts{$resname} = $mountpoint;
$known_fstypes{$resname} = $fstype;
$known_mountflags{$resname} = $mountflags;
}
close($fh);
}
return $known_mounts{$res};
}
sub _fake_versionlink {
my ($cmd, $res, $nr_links, $log_nr, $primary) = @_;
my $basedir = "$mars/resource-$res";
@ -8502,6 +8524,26 @@ sub eval_fn {
}
return $result;
}
if (/^known[-_]?(device)[-_]?(mounted|mountpoint|fstype|mountflags)$/) {
my $what = $1;
my $op = $2;
my $peer = $$env{"host"};
if ($peer ne $real_host) {
return "";
}
my $val =_get_known_mounts($$env{"cmd"}, $$env{"res"});
if ($val) {
if ($op eq "mounted") {
$val = 1;
} elsif ($op eq "fstype") {
$val = $known_fstypes{$$env{"res"}};
} elsif ($op eq "mountflags") {
$val = $known_mountflags{$$env{"res"}};
}
}
$val = "" unless defined($val);
return $val;
}
if (/^is[-_]?split([-_]?brain)?$/) {
my $split = detect_splitbrain($$env{"res"}, 0);
return $split ? 0 : 1;
@ -9159,6 +9201,12 @@ my %complex_macros =
=> ""
. "%if{%device-opened{}}{"
. "Opened, "
. "%if{%known-device-mounted{}}{"
. "%known-device-mountpoint{}"
. "%if{%{verbose}}{"
. " %known-device-fstype{} %known-device-mountflags{}"
. "}, "
. "}"
. "%if{%device-error{}}{"
. "DEVICE_ERROR=%device-error{}%errno-text{%device-error{}}, "
. "}"
@ -9634,6 +9682,8 @@ my %trivial_globs =
=> "",
"device-{opened,nrflying,error,completion-{stamp,age}}"
=> "",
"known-device-{mounted,mountpoint,fstype,mountflags}"
=> "",
"get-log-status"
=> "",
"get-resource-{fat,err,wrn}{,-count}"