[pve-devel] [PATCH storage 05/11] Add cifs in create API call.

Wolfgang Link w.link at proxmox.com
Tue Mar 13 15:11:05 CET 2018


In this patch the nodes will be deleted if the nodes parameter comes with a empty string.
We need this in the GUI when update the nodes in the config to reset if a nodes.

If we do not erase the empty hash the storage online check would be skipped.
Also the password and user would not be verified.
---
 PVE/API2/Storage/Config.pm | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm
index a321204..f274593 100755
--- a/PVE/API2/Storage/Config.pm
+++ b/PVE/API2/Storage/Config.pm
@@ -154,6 +154,14 @@ __PACKAGE__->register_method ({
 	my $type = extract_param($param, 'type');
 	my $storeid = extract_param($param, 'storage');
 
+	# revent an empty nodelist.
+	# fix me in section config create never need an empty entity.
+
+	delete $param->{nodes} if !$param->{nodes};
+
+	my $user_data = &$extract_cifs_credentials($param)
+	    if $type eq 'cifs' && $param->{username};
+
 	if ($param->{portal}) {
 	    $param->{portal} = PVE::Storage::resolv_portal($param->{portal});
 	}
@@ -205,11 +213,21 @@ __PACKAGE__->register_method ({
 			die "failed to copy ceph authx keyring for storage '$storeid': $err\n";
 		    }
 		}
-
-		# try to activate if enabled on local node,
-		# we only do this to detect errors/problems sooner
-		if (PVE::Storage::storage_check_enabled($cfg, $storeid, undef, 1)) {
-		    PVE::Storage::activate_storage($cfg, $storeid);
+		# create a password file in /etc/pve/priv,
+		# this file is used as a cert_file at mount time.
+		my $cred_file = &$set_cifs_credentials($user_data, $storeid)
+		    if defined($user_data);
+
+		eval {
+		    # try to activate if enabled on local node,
+		    # we only do this to detect errors/problems sooner
+		    if (PVE::Storage::storage_check_enabled($cfg, $storeid, undef, 1)) {
+			PVE::Storage::activate_storage($cfg, $storeid);
+		    }
+		};
+		if(my $err = $@) {
+		    unlink $cred_file if defined($cred_file);
+		    die $err;
 		}
 
 		PVE::Storage::write_config($cfg);
-- 
2.11.0




More information about the pve-devel mailing list