btrbk: check results of btrfs filesystem usage

pull/475/head
Axel Burri 2022-05-29 14:04:07 +02:00
parent 691885e6b8
commit eadeb89232
1 changed files with 24 additions and 43 deletions

53
btrbk
View File

@ -1058,53 +1058,34 @@ sub btrfs_filesystem_usage($)
my %detail; my %detail;
foreach(@$ret) { foreach(@$ret) {
if(/^\s+Device size:\s+(\S+)/) { $detail{device_size} = $1, next if(/^\s+Device size:\s+(\S+)/);
$detail{device_size} = $1; $detail{device_allocated} = $1, next if(/^\s+Device allocated:\s+(\S+)/);
} $detail{device_unallocated} = $1, next if(/^\s+Device unallocated:\s+(\S+)/);
elsif(/^\s+Device allocated:\s+(\S+)/) { $detail{device_missing} = $1, next if(/^\s+Device missing:\s+(\S+)/);
$detail{device_allocated} = $1; $detail{device_used} = $1, next if(/^\s+Used:\s+(\S+)/);
} @detail{qw(free free_min)} = ($1,$2), next if(/^\s+Free \(estimated\):\s+(\S+)\s+\(min: (\S+)\)/);
elsif(/^\s+Device unallocated:\s+(\S+)/) { $detail{data_ratio} = $1, next if(/^\s+Data ratio:\s+([0-9]+\.[0-9]+)/);
$detail{device_unallocated} = $1; $detail{metadata_ratio} = $1, next if(/^\s+Metadata ratio:\s+([0-9]+\.[0-9]+)/);
} $detail{used} = $1, next if(/^\s+Used:\s+(\S+)/);
elsif(/^\s+Device missing:\s+(\S+)/) { @detail{qw(global_reserve global_reserve_used)} = ($1,$2), next if(/^\s+Global reserve:\s+(\S+)\s+\(used: (\S+)\)/);
$detail{device_missing} = $1;
}
elsif(/^\s+Used:\s+(\S+)/) {
$detail{device_used} = $1;
}
elsif(/^\s+Free \(estimated\):\s+(\S+)\s+\(min: (\S+)\)/) {
$detail{free} = $1;
$detail{free_min} = $2;
}
elsif(/^\s+Data ratio:\s+(\S+)/) {
$detail{data_ratio} = $1;
}
elsif(/^\s+Metadata ratio:\s+(\S+)/) {
$detail{metadata_ratio} = $1;
}
elsif(/^\s+Used:\s+(\S+)/) {
$detail{used} = $1;
}
elsif(/^\s+Global reserve:\s+(\S+)\s+\(used: (\S+)\)/) {
$detail{global_reserve} = $1;
$detail{global_reserve_used} = $2;
}
else {
TRACE "Failed to parse filesystem usage line \"$_\" for: $vol->{PRINT}" if($do_trace); TRACE "Failed to parse filesystem usage line \"$_\" for: $vol->{PRINT}" if($do_trace);
} }
}
DEBUG "Parsed " . scalar(keys %detail) . " filesystem usage detail items: $vol->{PRINT}"; DEBUG "Parsed " . scalar(keys %detail) . " filesystem usage detail items: $vol->{PRINT}";
foreach (qw(device_size device_used data_ratio)) {
unless(defined($detail{$_})) {
ERROR "Failed to parse filesystem usage detail (unsupported btrfs-progs) for: $vol->{PRINT}";
return undef;
}
}
# calculate aggregate size / usage # calculate aggregate size / usage
if($detail{data_ratio} =~ /^[0-9]+\.[0-9]+$/) {
if($detail{device_size} =~ /^([0-9]+\.[0-9]+)(.*)/) { if($detail{device_size} =~ /^([0-9]+\.[0-9]+)(.*)/) {
$detail{size} = sprintf('%.2f%s', $1 / $detail{data_ratio}, $2); $detail{size} = sprintf('%.2f%s', $1 / $detail{data_ratio}, $2);
} }
if($detail{device_used} =~ /^([0-9]+\.[0-9]+)(.*)/) { if($detail{device_used} =~ /^([0-9]+\.[0-9]+)(.*)/) {
$detail{used} = sprintf('%.2f%s', $1 / $detail{data_ratio}, $2); $detail{used} = sprintf('%.2f%s', $1 / $detail{data_ratio}, $2);
} }
}
TRACE(Data::Dumper->Dump([\%detail], ["btrfs_filesystem_usage($vol->{URL})"])) if($do_trace && $do_dumper); TRACE(Data::Dumper->Dump([\%detail], ["btrfs_filesystem_usage($vol->{URL})"])) if($do_trace && $do_dumper);
return \%detail; return \%detail;