From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 610BF7225F
 for <pve-devel@lists.proxmox.com>; Mon, 12 Apr 2021 10:47:37 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 560C81BECF
 for <pve-devel@lists.proxmox.com>; Mon, 12 Apr 2021 10:47:37 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 9A33F1BEC5
 for <pve-devel@lists.proxmox.com>; Mon, 12 Apr 2021 10:47:36 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 67767420AC
 for <pve-devel@lists.proxmox.com>; Mon, 12 Apr 2021 10:47:36 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Thomas Lamprecht <t.lamprecht@proxmox.com>
Date: Mon, 12 Apr 2021 10:47:31 +0200
Message-Id: <20210412084731.27810-1-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.007 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH manager] vzdump: getlock: return lock file
 handle and let the caller close it
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 12 Apr 2021 08:47:37 -0000

so it doesn't get out of scope too early.

Regression introduced by a06e0311de595e19f6312a12d07c6767365d7a2c as pointed
out by Fabian Grünbichler.

Reported in the community forum:
https://forum.proxmox.com/threads/limit-simultaneous-backup-jobs.87489

Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 PVE/API2/VZDump.pm | 4 +++-
 PVE/VZDump.pm      | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
index 44376106..94bb0605 100644
--- a/PVE/API2/VZDump.pm
+++ b/PVE/API2/VZDump.pm
@@ -106,7 +106,7 @@ __PACKAGE__->register_method ({
 	    $param->{vmids} = $local_vmids;
 	    my $vzdump = PVE::VZDump->new($cmdline, $param, $skiplist);
 
-	    eval {
+	    my $LOCK_FH = eval {
 		$vzdump->getlock($upid); # only one process allowed
 	    };
 	    if (my $err = $@) {
@@ -122,6 +122,8 @@ __PACKAGE__->register_method ({
 		}
 	    }
 	    $vzdump->exec_backup($rpcenv, $user);
+
+	    close($LOCK_FH);
 	};
 
 	open STDOUT, '>/dev/null' if $param->{quiet} && !$param->{stdout};
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index fb4c8bad..171d208e 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -621,6 +621,8 @@ sub getlock {
     }
 
     PVE::Tools::file_set_contents($pidfile, $upid);
+
+    return $SERVER_FLCK;
 }
 
 sub run_hook_script {
-- 
2.20.1