| 1 | package Device::RAID::Poller::Backends::FBSD_gmirror; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | Device::RAID::Poller::Backends::FBSD_gmirror - FreeBSD GEOM mirror RAID backend. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 VERSION | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Version 0.0.0 | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | our $VERSION = '0.0.0'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | use Device::RAID::Poller::Backends::FBSD_gmirror; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | my $backend = Device::RAID::Poller::Backends::FBSD_gmirror->new; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | my $usable=$backend->usable; | ||||||||||||||||||||||||||||
| 27 | my %return_hash; | ||||||||||||||||||||||||||||
| 28 | if ( $usable ){ | ||||||||||||||||||||||||||||
| 29 | %return_hash=$backend->run; | ||||||||||||||||||||||||||||
| 30 | my %status=$backend->run; | ||||||||||||||||||||||||||||
| 31 | use Data::Dumper; | ||||||||||||||||||||||||||||
| 32 | print Dumper( \%status ); | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 new | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Initiates the backend object. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | my $backend = Device::RAID::Poller::Backends::FBSD_gmirror->new; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $self = { | |||||||||||||||||||||||||||
| 47 | usable=>0, | ||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||
| 49 | 0 | bless $self; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | return $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head2 run | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Runs the poller backend and report the results. | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | If nothing is nothing is loaded, load will be called. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | my %status=$backend->run; | ||||||||||||||||||||||||||||
| 61 | use Data::Dumper; | ||||||||||||||||||||||||||||
| 62 | print Dumper( \%status ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my %return_hash=( | |||||||||||||||||||||||||||
| 70 | 'status'=>0, | ||||||||||||||||||||||||||||
| 71 | 'devices'=>{}, | ||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # if not usable, no point in continuing | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( ! $self->{usable} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | return %return_hash; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Fetch the raw gmirror status. | ||||||||||||||||||||||||||||
| 80 | 0 | my $raw=`/sbin/gmirror status`; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( $? != 0 ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | return %return_hash; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | my @raw_split=split( /\n/, $raw ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # The first line contains nothing of interest. | ||||||||||||||||||||||||||||
| 88 | 0 | shift @raw_split; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | my $dev=undef; | |||||||||||||||||||||||||||
| 91 | 0 | foreach my $line (@raw_split){ | |||||||||||||||||||||||||||
| 92 | 0 | my @line_split=split( /[\t ]+/, $line ); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # lines starting with mirror mean we have a new dev | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( $line_split[0] =~ /^mirror/ ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $dev=$line_split[0]; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | #create the device if needed in the return hash | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( ! defined( $return_hash{$dev} ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $return_hash{devices}{$dev}={ | |||||||||||||||||||||||||||
| 101 | 'backend'=>'FBSD_gmirror', | ||||||||||||||||||||||||||||
| 102 | 'name'=>$dev, | ||||||||||||||||||||||||||||
| 103 | 'good'=>[], | ||||||||||||||||||||||||||||
| 104 | 'bad'=>[], | ||||||||||||||||||||||||||||
| 105 | 'spare'=>[], | ||||||||||||||||||||||||||||
| 106 | 'type'=>'mirror', | ||||||||||||||||||||||||||||
| 107 | 'BBUstatus'=>'na', | ||||||||||||||||||||||||||||
| 108 | 'status'=>'unknown', | ||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # Check known mirror status values. | ||||||||||||||||||||||||||||
| 113 | # Values pulled from sys/geom/mirror/g_mirror.c | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( $line_split[1] eq 'COMPLETE' ){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 115 | 0 | $return_hash{devices}{$dev}{status}='good'; | |||||||||||||||||||||||||||
| 116 | }elsif( $line_split[1] eq "DEGRADED" ){ | ||||||||||||||||||||||||||||
| 117 | 0 | $return_hash{devices}{$dev}{status}='bad'; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # Check known disk status values. | ||||||||||||||||||||||||||||
| 121 | # Values pulled from sys/geom/mirror/g_mirror.c | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( $line_split[3] eq "(SYNCHRONIZING)" ){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 123 | 0 | $return_hash{devices}{$dev}{status}='rebuilding'; | |||||||||||||||||||||||||||
| 124 | 0 | push( @{ $return_hash{devices}{$dev}{good} }, $line_split[2] ); | |||||||||||||||||||||||||||
| 125 | }elsif( $line_split[3] eq "(ACTIVE)" ){ | ||||||||||||||||||||||||||||
| 126 | 0 | push( @{ $return_hash{devices}{$dev}{good} }, $line_split[2] ); | |||||||||||||||||||||||||||
| 127 | }else{ | ||||||||||||||||||||||||||||
| 128 | 0 | push( @{ $return_hash{devices}{$dev}{bad} }, $line_split[2] ); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | }else{ | ||||||||||||||||||||||||||||
| 132 | # Check known disk status values. | ||||||||||||||||||||||||||||
| 133 | # Values pulled from sys/geom/mirror/g_mirror.c | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ( $line_split[2] eq "(SYNCHRONIZING)" ){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 135 | 0 | $return_hash{$dev}{status}='rebuilding'; | |||||||||||||||||||||||||||
| 136 | 0 | push( @{ $return_hash{devices}{$dev}{good} }, $line_split[1] ); | |||||||||||||||||||||||||||
| 137 | }elsif( $line_split[2] eq "(ACTIVE)" ){ | ||||||||||||||||||||||||||||
| 138 | 0 | push( @{ $return_hash{devices}{$dev}{good} }, $line_split[1] ); | |||||||||||||||||||||||||||
| 139 | }else{ | ||||||||||||||||||||||||||||
| 140 | 0 | push( @{ $return_hash{devices}{$dev}{bad} }, $line_split[1] ); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | $return_hash{status}=1; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | return %return_hash; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head2 usable | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Returns a perl boolean for if it is usable or not. | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | my $usable=$backend->usable; | ||||||||||||||||||||||||||||
| 155 | if ( ! $usable ){ | ||||||||||||||||||||||||||||
| 156 | print "This backend is not usable.\n"; | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub usable { | ||||||||||||||||||||||||||
|
Subroutine
usable: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$^O =~ /freebsd/ or -x "/sbin/gmirror"
MC/DC0%0/2
$^O =~ /freebsd/ or -x "/sbin/gmirror"
$^O =~ /freebsd/
-x "/sbin/gmirror"
Truth table0%0/3
A or B
A= $^O =~ /freebsd/B= -x "/sbin/gmirror"
| |||||||||||||||||||||||||||||
| 165 | ( $^O !~ 'freebsd' ) && | ||||||||||||||||||||||||||||
| 166 | ( ! -x '/sbin/gmirror' ) | ||||||||||||||||||||||||||||
| 167 | ){ | ||||||||||||||||||||||||||||
| 168 | 0 | $self->{usable}=0; | |||||||||||||||||||||||||||
| 169 | 0 | return 0; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # Test for it via this instead of '/sbin/kldstat -q -n geom_mirror' | ||||||||||||||||||||||||||||
| 173 | # as kldstat won't work if it is compiled in. | ||||||||||||||||||||||||||||
| 174 | 0 | system('/sbin/sysctl -q kern.features.geom_mirror > /dev/null'); | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ( $? != 0 ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | $self->{usable}=0; | |||||||||||||||||||||||||||
| 177 | 0 | return 0; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | $self->{usable}=1; | |||||||||||||||||||||||||||
| 181 | 0 | return 1; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =head1 BUGS | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Please report any bugs or feature requests to C<bug-device-raid-poller at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 191 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Device-RAID-Poller>. I will be | ||||||||||||||||||||||||||||
| 192 | notified, and then you'll automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | perldoc Device::RAID::Poller | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | You can also look for information at: | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =over 4 | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Device-RAID-Poller> | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | L<http://annocpan.org/dist/Device-RAID-Poller> | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | L<https://cpanratings.perl.org/d/Device-RAID-Poller> | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | L<https://metacpan.org/release/Device-RAID-Poller> | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =back | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | This software is Copyright (c) 2019 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | The Artistic License 2.0 (GPL Compatible) | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =cut | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 1 | 1; # End of Device::RAID::Poller | |||||||||||||||||||||||||||