public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Michal Fox <me@dualfroz.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage 3/3] fix #6389: api: disks: zfs: parse the message of hot spares in use
Date: Sat,  3 Oct 2026 12:49:17 +0000	[thread overview]
Message-ID: <20261003124917.7-4-me@dualfroz.com> (raw)
In-Reply-To: <20261003124917.7-1-me@dualfroz.com>

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>
---
 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;
-- 
2.43.0




      parent reply	other threads:[~2026-10-03 12:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03 12:49 [PATCH storage 0/3] api: disks: zfs: fix error counters and in-use spares in pool details Michal Fox
2026-10-03 12:49 ` [PATCH storage 1/3] test: add tests for zpool status parsing of the ZFS disk API Michal Fox
2026-10-03 12:49 ` [PATCH storage 2/3] fix #6640, #6938: api: disks: zfs: return exact error counters Michal Fox
2026-10-03 12:49 ` Michal Fox [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261003124917.7-4-me@dualfroz.com \
    --to=me@dualfroz.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal