Skip to content

Commit

Permalink
Added FusionInventory::Agent::Tools::Linux::_filterMultipath() (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
po1vo committed Oct 7, 2020
1 parent e8ae273 commit 9a1aeed
Show file tree
Hide file tree
Showing 4 changed files with 545 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/FusionInventory/Agent/Tools/Linux.pm
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ sub getDevicesFromProc {
my %seen;
@names = grep { !$seen{$_}++ } @names;

# filter multipath
@names = _filterMultipath(names => \@names) if canRun('multipath');

my $udisksctl = canRun('udisksctl');
$dump->{udisksctl} = 1 if ($dump && $udisksctl);
$udisksctl = 1 if $root && -e "$root/udisksctl";
Expand Down Expand Up @@ -344,6 +347,37 @@ sub _getValueFromSysProc {
return trimWhitespace($value);
}

sub _filterMultipath {
my (%params) = (
command => 'multipath -l',
@_
);

my %hnames = map {$_ => 1} @{$params{names}};

# parse multipath
my (@groups, @group);
foreach my $line (getAllLines(%params)) {
if ($line =~ /^\w+ \(\w+\) dm-\d+ \w+/) {
push @groups, [@group] if scalar @group;
@group = ();
} elsif ($line =~ / (sd[a-z]+) /) {
push @group, $1;
}
}
push @groups, [@group] if scalar @group;

# filter
foreach my $group (@groups) {
# delete all but first element from each group
for (my $i = 1; $i < scalar @$group; $i++) {
delete $hnames{ @$group[$i] } ;
}
}

return keys %hnames;
}

sub _readLinkFromSysFs {
my ($path, $root, $dump) = @_;

Expand Down
120 changes: 120 additions & 0 deletions resources/linux/multipath/multipath1
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
d11 (35000c500ad9ae4b3) dm-15 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:20:0 sdai 66:32 active undef running
`- 14:0:45:0 sdbg 67:160 active undef running
d08 (35000c500ad9b3c2b) dm-11 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:17:0 sdaf 65:240 active undef running
`- 14:0:42:0 sdbd 67:112 active undef running
d10 (35000c500ad9b3823) dm-13 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:19:0 sdah 66:16 active undef running
`- 14:0:44:0 sdbf 67:144 active undef running
d07 (35000c500ad9b12bb) dm-10 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:16:0 sdae 65:224 active undef running
`- 14:0:41:0 sdbc 67:96 active undef running
d06 (35000c500ad9b3467) dm-16 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:21:0 sdaj 66:48 active undef running
`- 14:0:46:0 sdbh 67:176 active undef running
d23 (35000c500ad9b4d5b) dm-19 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:3:0 sdr 65:16 active undef running
`- 14:0:28:0 sdap 66:144 active undef running
d05 (35000c500ad9b2e17) dm-17 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:22:0 sdak 66:64 active undef running
`- 14:0:47:0 sdbi 67:192 active undef running
d22 (35000c500ad9a841f) dm-14 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:2:0 sdq 65:0 active undef running
`- 14:0:27:0 sdao 66:128 active undef running
d19 (35000c500ad9b3def) dm-21 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:5:0 sdt 65:48 active undef running
`- 14:0:30:0 sdar 66:176 active undef running
d04 (35000c500ad9b418f) dm-9 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:15:0 sdad 65:208 active undef running
`- 14:0:40:0 sdbb 67:80 active undef running
d21 (35000c500ad9b3b0f) dm-3 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:1:0 sdp 8:240 active undef running
`- 14:0:26:0 sdan 66:112 active undef running
d18 (35000c500ad9b0703) dm-20 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:4:0 sds 65:32 active undef running
`- 14:0:29:0 sdaq 66:160 active undef running
d03 (35000c500ad9b2fd3) dm-8 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:14:0 sdac 65:192 active undef running
`- 14:0:39:0 sdba 67:64 active undef running
d20 (35000c500ad9ac2d3) dm-2 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:0:0 sdo 8:224 active undef running
`- 14:0:25:0 sdam 66:96 active undef running
d02 (35000c500ad9ad647) dm-7 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:13:0 sdab 65:176 active undef running
`- 14:0:38:0 sdaz 67:48 active undef running
d17 (35000c500ad9b4d27) dm-5 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:11:0 sdz 65:144 active undef running
`- 14:0:36:0 sdax 67:16 active undef running
d01 (35000c500ad9acc7f) dm-6 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:12:0 sdaa 65:160 active undef running
`- 14:0:37:0 sday 67:32 active undef running
d16 (35000c500ad9aecf3) dm-4 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:10:0 sdy 65:128 active undef running
`- 14:0:35:0 sdaw 67:0 active undef running
d15 (35000c500ad9b222b) dm-25 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:9:0 sdx 65:112 active undef running
`- 14:0:34:0 sdav 66:240 active undef running
d00 (35000c500ad9b100b) dm-18 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:23:0 sdal 66:80 active undef running
`- 14:0:48:0 sdbj 67:208 active undef running
d14 (35000c500ad9b2667) dm-24 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:8:0 sdw 65:96 active undef running
`- 14:0:33:0 sdau 66:224 active undef running
d13 (35000c500ad9aa4ff) dm-23 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:7:0 sdv 65:80 active undef running
`- 14:0:32:0 sdat 66:208 active undef running
d12 (35000c500ad9acfe7) dm-22 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:6:0 sdu 65:64 active undef running
`- 14:0:31:0 sdas 66:192 active undef running
d09 (35000c500ad9ad22f) dm-12 SEAGATE,DL1800MM0159
size=1.6T features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
|- 14:0:18:0 sdag 66:0 active undef running
`- 14:0:43:0 sdbe 67:128 active undef running

0 comments on commit 9a1aeed

Please sign in to comment.