From: Thomas Lamprecht Date: Mon, 2 Jul 2018 13:54:45 +0000 (+0200) Subject: cifs: use add/delete hooks X-Git-Url: https://git.proxmox.com/?p=pve-storage.git;a=commitdiff_plain;h=ab5e32bb1d425538385a94fe24bdb212f7dc5964 cifs: use add/delete hooks Signed-off-by: Thomas Lamprecht --- diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm index 0d56115..240c9e0 100755 --- a/PVE/API2/Storage/Config.pm +++ b/PVE/API2/Storage/Config.pm @@ -197,10 +197,6 @@ __PACKAGE__->register_method ({ unlink $ceph_storage_keyring; die "failed to copy ceph authx keyring for storage '$storeid': $err\n"; } - } elsif ($type eq 'cifs' && defined($password)) { - # create a password file in /etc/pve/priv, - # this file is used as a cert_file at mount time. - $cred_file = PVE::Storage::CIFSPlugin::cifs_set_credentials($password, $storeid); } eval { @@ -301,12 +297,7 @@ __PACKAGE__->register_method ({ $plugin->on_delete_hook($storeid, $scfg); - if ($scfg->{type} eq 'cifs') { - my $cred_file = PVE::Storage::CIFSPlugin::cifs_cred_file_name($storeid); - if (-f $cred_file) { - unlink($cred_file) or warn "removing cifs credientials '$cred_file' failed: $!\n"; - } - } elsif ($scfg->{type} eq 'rbd' && !defined($scfg->{monhost})) { + if ($scfg->{type} eq 'rbd' && !defined($scfg->{monhost})) { my $ceph_storage_keyring = "/etc/pve/priv/ceph/${storeid}.keyring"; if (-f $ceph_storage_keyring) { unlink($ceph_storage_keyring) or warn "removing keyring of storage failed: $!\n"; diff --git a/PVE/Storage/CIFSPlugin.pm b/PVE/Storage/CIFSPlugin.pm index 254d3ff..b3f3d86 100644 --- a/PVE/Storage/CIFSPlugin.pm +++ b/PVE/Storage/CIFSPlugin.pm @@ -141,6 +141,23 @@ sub check_config { # Storage implementation +sub on_add_hook { + my ($class, $storeid, $scfg, %param) = @_; + + if (my $password = $param{password}) { + cifs_set_credentials($password, $storeid); + } +} + +sub on_delete_hook { + my ($class, $storeid, $scfg) = @_; + + my $cred_file = cifs_cred_file_name($storeid); + if (-f $cred_file) { + unlink($cred_file) or warn "removing cifs credientials '$cred_file' failed: $!\n"; + } +} + sub status { my ($class, $storeid, $scfg, $cache) = @_;