[pve-devel] applied: [PATCH cluster] updatecerts: create base directories of observed files
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Apr 30 17:35:57 CEST 2020
replaces the random hacks where we do some hail-mary mkdir in a
writer or the like, to ensure that the directory structure exists and
we can write safely.
more central and safer would be pmxcfs itself, but to late in the
release cycle to do that now.
Chicken out if pmxcfs is not mounted, we don't want to trash it's
(future) mountpoint..
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
as discussed with Fabian off-list
data/PVE/CLI/pvecm.pm | 1 +
data/PVE/Cluster.pm | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index 4b52dee..b381f4f 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -569,6 +569,7 @@ __PACKAGE__->register_method ({
# no-good for ExecStartPost as it fails the whole service in this case
PVE::Tools::run_fork_with_timeout(30, sub {
PVE::Cluster::Setup::updatecerts_and_ssh($param->@{qw(force silent)});
+ PVE::Cluster::prepare_observed_file_basedirs();
});
return undef;
diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
index f40215a..e73f3aa 100644
--- a/data/PVE/Cluster.pm
+++ b/data/PVE/Cluster.pm
@@ -5,6 +5,7 @@ use warnings;
use Encode;
use File::stat qw();
+use File::Path qw(make_path);
use JSON;
use Net::SSLeay;
use POSIX qw(ENOENT);
@@ -74,6 +75,22 @@ my $observed = {
'virtual-guest/cpu-models.conf' => 1,
};
+sub prepare_observed_file_basedirs {
+
+ if (check_cfs_is_mounted(1)) {
+ warn "pmxcfs isn't mounted (/etc/pve), chickening out..\n";
+ return;
+ }
+
+ for my $f (sort keys %$observed) {
+ next if $f !~ m!^(.*)/[^/]+$!;
+ my $dir = "$basedir/$1";
+ next if -e $dir; # can also be a link, so just use -e xist check
+ print "creating directory '$dir' for observerd files\n";
+ make_path($dir);
+ }
+}
+
sub base_dir {
return $basedir;
}
--
2.20.1
More information about the pve-devel
mailing list