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.eb...@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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to