[pve-devel] [PATCH v2 manager 1/2] fix #4235: vzdump: add cluster-wide configuration

Leo Nunner l.nunner at proxmox.com
Tue Mar 7 13:11:04 CET 2023


The different config files get merged in the following order:

/etc/vzdump.conf <- /etc/pve/vzdump.conf <- default values

So the local configuration takes the highest precedence, then the
cluster-wide config, and finally the default values.

Signed-off-by: Leo Nunner <l.nunner at proxmox.com>
---
 PVE/VZDump.pm | 50 ++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 14 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index a04837e7..d0ab03ac 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -13,7 +13,7 @@ use IPC::Open3;
 use POSIX qw(strftime);
 use Time::Local;
 
-use PVE::Cluster qw(cfs_read_file);
+use PVE::Cluster qw(cfs_register_file cfs_read_file);
 use PVE::DataCenterConfig;
 use PVE::Exception qw(raise_param_exc);
 use PVE::HA::Config;
@@ -258,6 +258,32 @@ sub check_vmids {
     return $res;
 }
 
+sub parse_vzdump_conf {
+    my ($fn, $content) = @_;
+
+    return {} if !defined($content);
+
+    my $conf_schema = { type => 'object', properties => $confdesc_for_defaults };
+    my $res = PVE::JSONSchema::parse_config($conf_schema, $fn, $content);
+    if (my $excludes = $res->{'exclude-path'}) {
+        $res->{'exclude-path'} = PVE::Tools::split_args($excludes);
+    }
+    if (defined($res->{mailto})) {
+        my @mailto = split_list($res->{mailto});
+        $res->{mailto} = [ @mailto ];
+    }
+    $parse_prune_backups_maxfiles->($res, "options in '$fn'");
+    parse_performance($res);
+
+    if (defined($res->{storage} && defined($res->{dumpdir}))) {
+        debugmsg('warn', "both 'storage' and 'dumpdir' defined in $fn - ignoring 'dumpdir'");
+        delete $res->{dumpdir};
+    }
+
+    return $res;
+}
+
+cfs_register_file("vzdump.conf", \&parse_vzdump_conf);
 
 sub read_vzdump_defaults {
 
@@ -266,7 +292,7 @@ sub read_vzdump_defaults {
     my $defaults = {
 	map {
 	    my $default = $confdesc->{$_}->{default};
-	     defined($default) ? ($_ => $default) : ()
+	    defined($default) ? ($_ => $default) : ()
 	} keys %$confdesc_for_defaults
     };
     $parse_prune_backups_maxfiles->($defaults, "defaults in VZDump schema");
@@ -274,26 +300,22 @@ sub read_vzdump_defaults {
 
     my $raw;
     eval { $raw = PVE::Tools::file_get_contents($fn); };
-    return $defaults if $@;
 
-    my $conf_schema = { type => 'object', properties => $confdesc_for_defaults };
-    my $res = PVE::JSONSchema::parse_config($conf_schema, $fn, $raw);
-    if (my $excludes = $res->{'exclude-path'}) {
-	$res->{'exclude-path'} = PVE::Tools::split_args($excludes);
-    }
-    if (defined($res->{mailto})) {
-	my @mailto = split_list($res->{mailto});
-	$res->{mailto} = [ @mailto ];
+    my $res = parse_vzdump_conf($fn, $raw);
+
+    # Merge in cluster-wide config
+    my $cluster_conf = cfs_read_file("vzdump.conf");
+    foreach my $key (keys %$cluster_conf) {
+	$res->{$key} = $cluster_conf->{$key} if !defined($res->{$key});
     }
-    $parse_prune_backups_maxfiles->($res, "options in '$fn'");
-    parse_performance($res);
 
+    # Merge in defaults
     foreach my $key (keys %$defaults) {
 	$res->{$key} = $defaults->{$key} if !defined($res->{$key});
     }
 
     if (defined($res->{storage}) && defined($res->{dumpdir})) {
-	debugmsg('warn', "both 'storage' and 'dumpdir' defined in '$fn' - ignoring 'dumpdir'");
+	debugmsg('warn', "both 'storage' and 'dumpdir' defined in config - ignoring 'dumpdir'");
 	delete $res->{dumpdir};
     }
 
-- 
2.30.2






More information about the pve-devel mailing list