fix #6389: api: disks: zfs: parse the message of hot spares in use

Hot spares have no error counters in the output of 'zpool status', so a
spare that is in use only has a message after its state:

  nvme10n1      INUSE     currently in use

The parser took the three words of that message as READ, WRITE and
CKSUM counters, so the API returned zero for all of them and lost the
message, while logging warnings like:

  Argument "currently" isn't numeric in addition (+)

As 'zpool status' is called with '-p', the counters are always plain
numbers, so only accept digits for them. This way, the message of a
spare in use ends up in 'msg', like for any other vdev.

Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
dualfroz committed 2026-10-02 16:17:54 +02:00
1 parent 6320a3a111
commit 467e6d641e
2 files changed
+104 -1

No files matched your search

+1 -1
View File
@@ -245,7 +245,7 @@ __PACKAGE__->register_method({
$config = 1;
} elsif (
$config
&& $line =~ m/^(\s+)(\S+)\s*(\S+)?(?:\s+(\S+)\s+(\S+)\s+(\S+))?\s*(.*)$/
&& $line =~ m/^(\s+)(\S+)\s*(\S+)?(?:\s+(\d+)\s+(\d+)\s+(\d+))?\s*(.*)$/
) {
my ($space, $name, $state, $read, $write, $cksum, $msg) =
($1, $2, $3, $4, $5, $6, $7);
+103
View File
@@ -225,6 +225,109 @@ EOF
],
},
},
{
description => 'hot spare in use',
status => <<"EOF",
pool: tank
state: ONLINE
scan: resilvered 725M in 00:00:00 with 0 errors on Mon May 12 16:50:25 2025
config:
\tNAME STATE READ WRITE CKSUM
\ttank ONLINE 0 0 0
\t mirror-0 ONLINE 0 0 0
\t spare-0 ONLINE 0 0 0
\t /dev/disk/by-id/ata-DISK_A-part1 ONLINE 0 0 0
\t /dev/disk/by-id/ata-DISK_C-part1 ONLINE 0 0 0
\t /dev/disk/by-id/ata-DISK_B-part1 ONLINE 0 0 0
\tspares
\t /dev/disk/by-id/ata-DISK_C-part1 INUSE currently in use
errors: No known data errors
EOF
expected => {
name => 'tank',
state => 'ONLINE',
scan => 'resilvered 725M in 00:00:00 with 0 errors on Mon May 12 16:50:25 2025',
errors => 'No known data errors',
leaf => 0,
children => [
{
name => 'tank',
state => 'ONLINE',
read => 0,
write => 0,
cksum => 0,
msg => '',
leaf => 0,
children => [
{
name => 'mirror-0',
state => 'ONLINE',
read => 0,
write => 0,
cksum => 0,
msg => '',
leaf => 0,
children => [
{
name => 'spare-0',
state => 'ONLINE',
read => 0,
write => 0,
cksum => 0,
msg => '',
leaf => 0,
children => [
{
name => '/dev/disk/by-id/ata-DISK_A-part1',
state => 'ONLINE',
read => 0,
write => 0,
cksum => 0,
msg => '',
leaf => 1,
},
{
name => '/dev/disk/by-id/ata-DISK_C-part1',
state => 'ONLINE',
read => 0,
write => 0,
cksum => 0,
msg => '',
leaf => 1,
},
],
},
{
name => '/dev/disk/by-id/ata-DISK_B-part1',
state => 'ONLINE',
read => 0,
write => 0,
cksum => 0,
msg => '',
leaf => 1,
},
],
},
],
},
{
name => 'spares',
msg => '',
leaf => 0,
children => [
{
name => '/dev/disk/by-id/ata-DISK_C-part1',
state => 'INUSE',
msg => 'currently in use',
leaf => 1,
},
],
},
],
},
},
];
plan tests => scalar @$tests;