public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH storage] fix #8076: zfs: activate volume: check for existence to fix regression with cloud-init disk
Date: Wed,  7 Oct 2026 13:48:57 +0200	[thread overview]
Message-ID: <20261007114904.132273-1-f.ebner@proxmox.com> (raw)

Explicitly checking for existence during activation has the advantage
to catch issues earlier with a clearer error message. Note that the
implementation in Plugin.pm already explicitly checks for existence,
so this also aligns the implementation for ZFS closer to that.

This also fixes #8076: For a zvol (i.e. 'raw' format),
zfs_wait_for_zvol_link() was called without first checking if the
volume actually exists. This means that for non-existent volumes,
activation would only fail after the timeout of 300 seconds in worker
context.

This change also means that non-existent snapshots are caught during
activation already, since previously, activate_volume() would return
early without doing anything for snapshots.

The error message "dataset does not exist" is matched against, because
the exit status from 'zfs' will always be 1 if an error occured; from
the man page:
> The zfs utility exits 0 on success, 1 if an error occurs, and 2 if
> invalid command line options were specified.
Note that zfs_delete_zvol() already does the same.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/Storage/ZFSPoolPlugin.pm | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm
index 61c49d9..023bd21 100644
--- a/src/PVE/Storage/ZFSPoolPlugin.pm
+++ b/src/PVE/Storage/ZFSPoolPlugin.pm
@@ -288,6 +288,21 @@ sub zfs_request {
     return $msg;
 }
 
+my sub zfs_volume_exists {
+    my ($class, $scfg, $volname, $snapname) = @_;
+
+    my $name = ($class->parse_volname($volname))[1];
+    my $dataset = "$scfg->{pool}/${name}";
+    $dataset .= "\@${snapname}" if defined($snapname);
+
+    eval { $class->zfs_request($scfg, 10, 'list', '-o', 'name', '-Hp', $dataset); };
+    if (my $err = $@) {
+        return 0 if $err =~ m/dataset does not exist/;
+        die $err;
+    }
+    return 1;
+}
+
 sub zfs_wait_for_zvol_link {
     my ($class, $scfg, $volname, $timeout) = @_;
 
@@ -739,6 +754,12 @@ sub deactivate_storage {
 sub activate_volume {
     my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
 
+    if (!zfs_volume_exists($class, $scfg, $volname, $snapname)) {
+        my $name = "$volname";
+        $name .= "\@${snapname}" if defined($snapname);
+        die "volume ${name} does not exist on storage ${storeid}\n";
+    }
+
     return 1 if defined($snapname);
 
     my (undef, $dataset, undef, undef, undef, undef, $format) = $class->parse_volname($volname);
-- 
2.47.3





                 reply	other threads:[~2026-10-07 11:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261007114904.132273-1-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.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