Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
speed47 committed Apr 16, 2024
1 parent 04aa8f0 commit ae01f69
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions btrfs-list
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ If no mountpoints are specified, display info for all btrfs filesystems.
-h, --help display this message
--debug enable debug output
-q, --quiet silence warnings
-q, --quiet silence quota disabled & quota rescan warnings,
repeat to silence all other warnings.
--version display version info
--color WHEN colorize the output; WHEN can be 'never',
'always', or 'auto' (default is:
Expand Down Expand Up @@ -109,7 +110,7 @@ GetOptions(
'version' => \my $opt_version,
'ignore-version-check' => \my $opt_ignore_version_check,
'ignore-root-check' => \my $opt_ignore_root_check,
'q|quiet' => \my $opt_quiet,
'q|quiet+' => \my $opt_quiet,
's|hide-snap' => \my $opt_hide_snapshots,
'S|snap-only' => \my $opt_only_snapshots,
'f|free-space' => \my $opt_free_space,
Expand Down Expand Up @@ -146,6 +147,13 @@ sub debug {
return;
}

sub warning {
my ($level, @lines) = @_;
return if ($level <= $opt_quiet);
print STDERR "WARNING: $_\n" for @lines;
return;
} ## end sub warning

sub run_cmd {
my %params = @_;
my $cmd = $params{'cmd'};
Expand All @@ -166,13 +174,13 @@ sub run_cmd {
while (<$_stdout>) {
chomp;
debug("stdout: " . $_);
/WARNING:/ and print STDERR $_ . "\n";
/WARNING: (.+)/ and warning(2, "btrfs-progs: $1");
push @stdout, $_;
} ## end while (<$_stdout>)
while (<$_stderr>) {
chomp;
debug("stderr: " . $_);
/WARNING: (?!RAID56 detected, not implemented)/ and print STDERR $_ . "\n";
/WARNING: (RAID56 detected, not implemented)/ and warning(2, "btrfs-progs: $1");
if (!$silent_stderr) {
print join(' ', @$cmd) . ": stderr: " . $_ . "\n";
}
Expand Down Expand Up @@ -672,7 +680,7 @@ foreach my $fuuid (keys %filesystems) {
$profile = $opt_profile if defined $opt_profile;

if (!$profile) {
print STDERR "WARNING: No profile found, assuming single\n";
warning(2, "No profile found, assuming single");
$profile = "single";
}

Expand Down Expand Up @@ -820,7 +828,7 @@ foreach my $fuuid (keys %filesystems) {

$cmd = run_cmd(silent_stderr => 1, cmd => [qw{ btrfs quota rescan -s }, $mp]);
if ($cmd->{stdout}->[0] && $cmd->{stdout}->[0] =~ /operation running|current key/) {
print STDERR "WARNING: a quota rescan is running, size information is not correct yet\n" if not $opt_quiet;
warning(1, "a quota rescan is running, size information is not correct yet");
}

$cmd = run_cmd(silent_stderr => 1, cmd => [qw{ btrfs qgroup show -pcre --raw }, $mp]);
Expand All @@ -829,8 +837,7 @@ foreach my $fuuid (keys %filesystems) {
# btrfs-progs v3.18 doesn't support --raw
$cmd = run_cmd(silent_stderr => 1, cmd => [qw{ btrfs qgroup show -pcre }, $mp]);
if ($cmd->{status} || !@{$cmd->{stdout}}) {
print STDERR "WARNING: to get refer/excl size information, please enable qgroups (btrfs quota enable $mp)\n"
if not $opt_quiet;
warning(1, "to get refer/excl size information, please enable qgroups (btrfs quota enable $mp)");
$vol{$fuuid}{df}{noquota} = 1;
}
} ## end if ($cmd->{status} || ...)
Expand Down Expand Up @@ -991,7 +998,7 @@ foreach my $fuuid (sort keys %filesystems) {
# do we still have unseen volumes? (we shouldn't)
foreach my $vuuid (keys %{$vol{$fuuid}}) {
next if $seen{$vuuid};
print STDERR "WARN: we shouldn't have orphaned volumne $vuuid\n";
warning(2, "we shouldn't have orphaned volumne $vuuid");
push @ordered, $vuuid;
}

Expand Down

0 comments on commit ae01f69

Please sign in to comment.