[pve-devel] [PATCH storage] Make check_connection less costly.

Wolfgang Link w.link at proxmox.com
Wed May 16 13:46:42 CEST 2018


This command will only check the needed share
and do not query the hole server shares.

This reduce the answer time and also has the benefit we check the
credentials on this share and not on the server.
---
 PVE/Storage/CIFSPlugin.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/PVE/Storage/CIFSPlugin.pm b/PVE/Storage/CIFSPlugin.pm
index 724fb1f..cb7c844 100644
--- a/PVE/Storage/CIFSPlugin.pm
+++ b/PVE/Storage/CIFSPlugin.pm
@@ -198,9 +198,9 @@ sub deactivate_storage {
 sub check_connection {
     my ($class, $storeid, $scfg) = @_;
 
-    my $server = $scfg->{server};
+    my $servicename = '//'.$scfg->{server}.'/'.$scfg->{share};
 
-    my $cmd = ['/usr/bin/smbclient', '-L', $server, '-d', '0', '-m'];
+    my $cmd = ['/usr/bin/smbclient', $servicename, '-d', '0', '-m'];
 
     push @$cmd, $scfg->{smbversion} ? "smb".int($scfg->{smbversion}) : 'smb3';
 
@@ -211,6 +211,8 @@ sub check_connection {
 	push @$cmd, '-U', 'Guest','-N';
     }
 
+    push @$cmd, '-c', 'echo 1 0';
+
     my $out_str;
     eval {
 	run_command($cmd, timeout => 2, outfunc => sub {$out_str .= shift;},
-- 
2.11.0




More information about the pve-devel mailing list