[pve-devel] [PATCH storage 2/5] cifs: use add/delete hooks

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jul 2 15:54:45 CEST 2018


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 PVE/API2/Storage/Config.pm | 11 +----------
 PVE/Storage/CIFSPlugin.pm  | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 10 deletions(-)

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) = @_;
 
-- 
2.17.1





More information about the pve-devel mailing list