From 467e6d641eb357c56d80944550b9e666743e0372 Mon Sep 17 00:00:00 2001 From: Michal Fox Date: Fri, 2 Oct 2026 16:17:54 +0200 Subject: [PATCH] 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 --- src/PVE/API2/Disks/ZFS.pm | 2 +- src/test/zfs_pool_detail_test.pm | 103 +++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/src/PVE/API2/Disks/ZFS.pm b/src/PVE/API2/Disks/ZFS.pm index b26805a..2215dd6 100644 --- a/src/PVE/API2/Disks/ZFS.pm +++ b/src/PVE/API2/Disks/ZFS.pm @@ -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); diff --git a/src/test/zfs_pool_detail_test.pm b/src/test/zfs_pool_detail_test.pm index 00d666a..bcca5ae 100644 --- a/src/test/zfs_pool_detail_test.pm +++ b/src/test/zfs_pool_detail_test.pm @@ -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;