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 0216F922B6
 for <pve-devel@lists.proxmox.com>; Mon,  3 Oct 2022 15:52:48 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id D97D63222A
 for <pve-devel@lists.proxmox.com>; Mon,  3 Oct 2022 15:52:17 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Mon,  3 Oct 2022 15:52:15 +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 6265A4477B
 for <pve-devel@lists.proxmox.com>; Mon,  3 Oct 2022 15:52:15 +0200 (CEST)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon,  3 Oct 2022 15:52:07 +0200
Message-Id: <20221003135211.183340-5-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20221003135211.183340-1-f.ebner@proxmox.com>
References: <20221003135211.183340-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.029 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 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 1/1] vzdump: handle new 'performance'
 property string
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, 03 Oct 2022 13:52:48 -0000

Also generalizes the way vzdump property strings are handled for jobs.
Something similar could be done in VZDump.pm, but there the maxfiles
and prune-backups settings are currently coupled, so a dedicated
parse_performance() is used instead. Can be changed once maxfiles is
dropped.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

Dependency bump for libpve-guest-common-perl needed.

 PVE/API2/VZDump.pm        |  9 +++++----
 PVE/Jobs/VZDump.pm        | 23 ++++++++++-------------
 PVE/VZDump.pm             | 12 ++++++++++++
 configs/vzdump.conf       |  1 +
 www/manager6/dc/Backup.js |  8 +++++---
 5 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm
index 13b6cd46..82b28db5 100644
--- a/PVE/API2/VZDump.pm
+++ b/PVE/API2/VZDump.pm
@@ -25,9 +25,10 @@ __PACKAGE__->register_method ({
     method => 'POST',
     description => "Create backup.",
     permissions => {
-	description => "The user needs 'VM.Backup' permissions on any VM, and 'Datastore.AllocateSpace'"
-	    ." on the backup storage. The 'maxfiles', 'prune-backups', 'tmpdir', 'dumpdir', 'script',"
-	    ." 'bwlimit' and 'ionice' parameters are restricted to the 'root\@pam' user.",
+	description => "The user needs 'VM.Backup' permissions on any VM, and "
+	    ."'Datastore.AllocateSpace' on the backup storage. The 'maxfiles', 'prune-backups', "
+	    ."'tmpdir', 'dumpdir', 'script', 'bwlimit', 'performance' and 'ionice' parameters are "
+	    ."restricted to the 'root\@pam' user.",
 	user => 'all',
     },
     protected => 1,
@@ -60,7 +61,7 @@ __PACKAGE__->register_method ({
 		if $param->{stdout};
 	}
 
-	foreach my $key (qw(maxfiles prune-backups tmpdir dumpdir script bwlimit ionice)) {
+	for my $key (qw(maxfiles prune-backups tmpdir dumpdir script bwlimit performance ionice)) {
 	    raise_param_exc({ $key => "Only root may set this option."})
 		if defined($param->{$key}) && ($user ne 'root@pam');
 	}
diff --git a/PVE/Jobs/VZDump.pm b/PVE/Jobs/VZDump.pm
index 7feb06a2..2963b348 100644
--- a/PVE/Jobs/VZDump.pm
+++ b/PVE/Jobs/VZDump.pm
@@ -42,11 +42,8 @@ sub options {
 sub decode_value {
     my ($class, $type, $key, $value) = @_;
 
-    if ($key eq 'prune-backups' && !ref($value)) {
-	$value = PVE::JSONSchema::parse_property_string(
-	    'prune-backups',
-	    $value,
-	);
+    if ((my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key}) && !ref($value)) {
+	$value = PVE::JSONSchema::parse_property_string($format, $value);
     }
 
     return $value;
@@ -55,11 +52,8 @@ sub decode_value {
 sub encode_value {
     my ($class, $type, $key, $value) = @_;
 
-    if ($key eq 'prune-backups' && ref($value) eq 'HASH') {
-	$value = PVE::JSONSchema::print_property_string(
-	    $value,
-	    'prune-backups',
-	);
+    if ((my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key}) && ref($value) eq 'HASH') {
+	$value = PVE::JSONSchema::print_property_string($value, $format);
     }
 
     return $value;
@@ -73,9 +67,12 @@ sub run {
 	delete $conf->{$opt} if !defined($props->{$opt});
     }
 
-    my $retention = $conf->{'prune-backups'};
-    if ($retention && ref($retention) eq 'HASH') { # fixup, its required as string parameter
-	$conf->{'prune-backups'} = PVE::JSONSchema::print_property_string($retention, 'prune-backups');
+    # Required as string parameters
+    for my $key (keys $PVE::VZDump::Common::PROPERTY_STRINGS->%*) {
+	if ($conf->{$key} && ref($conf->{$key}) eq 'HASH') {
+	    my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key};
+	    $conf->{$key} = PVE::JSONSchema::print_property_string($conf->{$key}, $format);
+	}
     }
 
     $conf->{quiet} = 1; # do not write to stdout/stderr
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index 87bb0bd2..d5b3c500 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -122,6 +122,15 @@ my $generate_notes = sub {
     return $notes_template;
 };
 
+my sub parse_performance {
+    my ($param) = @_;
+
+    if (defined(my $perf = $param->{performance})) {
+	return if ref($perf) eq 'HASH'; # already parsed
+	$param->{performance} = PVE::JSONSchema::parse_property_string('backup-performance', $perf);
+    }
+}
+
 my $parse_prune_backups_maxfiles = sub {
     my ($param, $kind) = @_;
 
@@ -261,6 +270,7 @@ sub read_vzdump_defaults {
 	} keys %$confdesc_for_defaults
     };
     $parse_prune_backups_maxfiles->($defaults, "defaults in VZDump schema");
+    parse_performance($defaults);
 
     my $raw;
     eval { $raw = PVE::Tools::file_get_contents($fn); };
@@ -276,6 +286,7 @@ sub read_vzdump_defaults {
 	$res->{mailto} = [ @mailto ];
     }
     $parse_prune_backups_maxfiles->($res, "options in '$fn'");
+    parse_performance($res);
 
     foreach my $key (keys %$defaults) {
 	$res->{$key} = $defaults->{$key} if !defined($res->{$key});
@@ -1354,6 +1365,7 @@ sub verify_vzdump_parameters {
 	if defined($param->{'prune-backups'}) && defined($param->{maxfiles});
 
     $parse_prune_backups_maxfiles->($param, 'CLI parameters');
+    parse_performance($param);
 
     if (my $template = $param->{'notes-template'}) {
 	eval { $verify_notes_template->($template); };
diff --git a/configs/vzdump.conf b/configs/vzdump.conf
index fe4b18ab..2ea09ae0 100644
--- a/configs/vzdump.conf
+++ b/configs/vzdump.conf
@@ -5,6 +5,7 @@
 #storage: STORAGE_ID
 #mode: snapshot|suspend|stop
 #bwlimit: KBPS
+#performance: max-workers=N
 #ionice: PRI
 #lockwait: MINUTES
 #stopwait: MINUTES
diff --git a/www/manager6/dc/Backup.js b/www/manager6/dc/Backup.js
index e9d74fb6..c81a76ce 100644
--- a/www/manager6/dc/Backup.js
+++ b/www/manager6/dc/Backup.js
@@ -594,9 +594,11 @@ Ext.define('PVE.dc.BackupView', {
 	    delete job['repeat-missed'];
 	    job.all = job.all === true ? 1 : 0;
 
-	    if (job['prune-backups']) {
-		job['prune-backups'] = PVE.Parser.printPropertyString(job['prune-backups']);
-	    }
+	    ['performance', 'prune-backups'].forEach(key => {
+		if (job[key]) {
+		    job[key] = PVE.Parser.printPropertyString(job[key]);
+		}
+	    });
 
 	    let allNodes = PVE.data.ResourceStore.getNodes();
 	    let nodes = allNodes.filter(node => node.status === 'online').map(node => node.node);
-- 
2.30.2