From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 457B51FF184 for ; Thu, 20 Nov 2025 11:17:46 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D5B0127CE; Thu, 20 Nov 2025 11:17:50 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Thu, 20 Nov 2025 11:17:30 +0100 Message-ID: <20251120101742.24843-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1763633835454 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.017 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lvmplugin.pm] Subject: [pve-devel] [PATCH v2 storage] lvm plugin: fix locking for rollback when using CLI X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Doing a rollback via CLI on an LVM storage with 'saferemove' and 'snapshot-as-volume-chain' would run into a locking issue, because the forked zero-out worker would try to acquire the lock while the main CLI task is still inside the locked section for volume_snapshot_rollback_locked(). The same issue does not happen when the rollback is done via UI. The reason for this can be found in the note regarding fork_worker(): > we simulate running in foreground if ($self->{type} eq 'cli') So the worker will be awaited synchronously in CLI context, resulting in the deadlock, while via API/UI, the main task would move on and release the lock allowing the zero-out worker to acquire it. Avoid doing fork_cleanup_worker() inside the locked section to avoid the issue. Fixes: 8eabcc7 ("lvm plugin: snapshot-as-volume-chain: use locking for snapshot operations") Signed-off-by: Fiona Ebner --- Changes in v2: * Better explanation in commit message. * Also spawn cleanup worker in error scenario like before the patch. src/PVE/Storage/LVMPlugin.pm | 43 ++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index 97f7bf4..102cf22 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -1117,23 +1117,17 @@ sub volume_rollback_is_possible { } my sub volume_snapshot_rollback_locked { - my ($class, $scfg, $storeid, $volname, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $snap, $cleanup_worker) = @_; my $format = ($class->parse_volname($volname))[6]; die "can't rollback snapshot for '$format' volume\n" if $format ne 'qcow2'; - my $cleanup_worker = eval { free_snap_image($class, $storeid, $scfg, $volname, 'current'); }; + $cleanup_worker->$* = eval { free_snap_image($class, $storeid, $scfg, $volname, 'current'); }; die "error deleting snapshot $snap $@\n" if $@; eval { alloc_snap_image($class, $storeid, $scfg, $volname, $snap) }; - my $alloc_err = $@; - - fork_cleanup_worker($cleanup_worker); - - if ($alloc_err) { - die "can't allocate new volume $volname: $alloc_err\n"; - } + die "can't allocate new volume $volname: $@\n" if $@; return undef; } @@ -1141,14 +1135,29 @@ my sub volume_snapshot_rollback_locked { sub volume_snapshot_rollback { my ($class, $scfg, $storeid, $volname, $snap) = @_; - return $class->cluster_lock_storage( - $storeid, - $scfg->{shared}, - undef, - sub { - return volume_snapshot_rollback_locked($class, $scfg, $storeid, $volname, $snap); - }, - ); + my $cleanup_worker; + + eval { + $class->cluster_lock_storage( + $storeid, + $scfg->{shared}, + undef, + sub { + volume_snapshot_rollback_locked( + $class, $scfg, $storeid, $volname, $snap, \$cleanup_worker, + ); + }, + ); + }; + my $err = $@; + + # Spawn outside of the locked section, because with 'saferemove', the cleanup worker also needs + # to obtain the lock, and in CLI context, it will be awaited synchronously, see fork_worker(). + fork_cleanup_worker($cleanup_worker); + + die $err if $err; + + return; } sub volume_snapshot_delete { -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel