PVE/Storage/Plugin.pm: introduce on_update_hook

We need this to correctly update the password file.
This commit is contained in:
Dietmar Maurer
2020-02-20 12:33:58 +01:00
committed by Thomas Lamprecht
parent 9e34813f6c
commit 0ff4cfead1
2 changed files with 32 additions and 2 deletions

View File

@ -204,12 +204,25 @@ __PACKAGE__->register_method ({
PVE::SectionConfig::assert_if_modified($cfg, $digest);
my $scfg = PVE::Storage::storage_config($cfg, $storeid);
my $type = $scfg->{type};
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
my $password;
# always extract pw, else it gets written to the www-data readable scfg
if (my $tmp_pw = extract_param($param, 'password')) {
if (($type eq 'pbs') || ($type eq 'cifs' && $param->{username})) {
$password = $tmp_pw;
} else {
warn "ignore password parameter\n";
}
}
my $plugin = PVE::Storage::Plugin->lookup($type);
my $opts = $plugin->check_config($storeid, $param, 0, 1);
my $delete_password = 0;
if ($delete) {
my $options = $plugin->private()->{options}->{$scfg->{type}};
my $options = $plugin->private()->{options}->{$type};
foreach my $k (PVE::Tools::split_list($delete)) {
my $d = $options->{$k} || die "no such option '$k'\n";
die "unable to delete required option '$k'\n" if !$d->{optional};
@ -218,9 +231,17 @@ __PACKAGE__->register_method ({
if defined($opts->{$k});
delete $scfg->{$k};
$delete_password = 1 if $k eq 'password';
}
}
if ($delete_password || defined($password)) {
$plugin->on_update_hook($storeid, $opts, password => $password);
} else {
$plugin->on_update_hook($storeid, $opts);
}
for my $k (keys %$opts) {
$scfg->{$k} = $opts->{$k};
}

View File

@ -366,6 +366,15 @@ sub on_add_hook {
# do nothing by default
}
# called during storage configuration update (before the updated storage config got written)
# die to abort the update if there are (grave) problems
# NOTE: runs in a storage config *locked* context
sub on_update_hook {
my ($class, $storeid, $scfg, %param) = @_;
# do nothing by default
}
# called during deletion of storage (before the new storage config got written)
# and if the activate check on addition fails, to cleanup all storage traces
# which on_add_hook may have created.