@@ -25,6 +25,26 @@ func normalizeWindowsPath(path string) string {
25
25
return normalizedPath
26
26
}
27
27
28
+ func getRootMappingPath (path string ) (string , error ) {
29
+ items := strings .Split (path , "\\ " )
30
+ parts := []string {}
31
+ for _ , s := range items {
32
+ if len (s ) > 0 {
33
+ parts = append (parts , s )
34
+ if len (parts ) == 2 {
35
+ break
36
+ }
37
+ }
38
+ }
39
+ if len (parts ) != 2 {
40
+ klog .Errorf ("remote path (%s) is invalid" , path )
41
+ return "" , fmt .Errorf ("remote path (%s) is invalid" , path )
42
+ }
43
+ // parts[0] is a smb host name
44
+ // parts[1] is a smb share name
45
+ return strings .ToLower ("\\ \\ " + parts [0 ] + "\\ " + parts [1 ]), nil
46
+ }
47
+
28
48
func NewServer (hostAPI smb.API , fsServer * fsserver.Server ) (* Server , error ) {
29
49
return & Server {
30
50
hostAPI : hostAPI ,
@@ -43,38 +63,48 @@ func (s *Server) NewSmbGlobalMapping(context context.Context, request *internal.
43
63
return response , fmt .Errorf ("remote path is empty" )
44
64
}
45
65
46
- isMapped , err := s .hostAPI .IsSmbMapped (remotePath )
66
+ mappingPath , err := getRootMappingPath (remotePath )
67
+ if err != nil {
68
+ return response , err
69
+ }
70
+
71
+ isMapped , err := s .hostAPI .IsSmbMapped (mappingPath )
47
72
if err != nil {
48
73
isMapped = false
49
74
}
50
75
51
76
if isMapped {
52
- valid , err := s .fsServer .PathValid (context , remotePath )
77
+ klog .V (4 ).Infof ("Remote %s already mapped. Validating..." , mappingPath )
78
+
79
+ valid , err := s .fsServer .PathValid (context , mappingPath )
53
80
if err != nil {
54
- klog .Warningf ("PathValid(%s) failed with %v, ignore error" , remotePath , err )
81
+ klog .Warningf ("PathValid(%s) failed with %v, ignore error" , mappingPath , err )
55
82
}
56
83
57
84
if ! valid {
58
- klog .V (4 ).Infof ("RemotePath %s is not valid, removing now" , remotePath )
59
- err := s .hostAPI .RemoveSmbGlobalMapping (remotePath )
85
+ klog .V (4 ).Infof ("RemotePath %s is not valid, removing now" , mappingPath )
86
+ err := s .hostAPI .RemoveSmbGlobalMapping (mappingPath )
60
87
if err != nil {
61
- klog .Errorf ("RemoveSmbGlobalMapping(%s) failed with %v" , remotePath , err )
88
+ klog .Errorf ("RemoveSmbGlobalMapping(%s) failed with %v" , mappingPath , err )
62
89
return response , err
63
90
}
64
91
isMapped = false
92
+ } else {
93
+ klog .V (4 ).Infof ("RemotePath %s is valid" , mappingPath )
65
94
}
66
95
}
67
96
68
97
if ! isMapped {
69
- klog .V (4 ).Infof ("Remote %s not mapped. Mapping now!" , remotePath )
70
- err := s .hostAPI .NewSmbGlobalMapping (remotePath , request .Username , request .Password )
98
+ klog .V (4 ).Infof ("Remote %s not mapped. Mapping now!" , mappingPath )
99
+ err := s .hostAPI .NewSmbGlobalMapping (mappingPath , request .Username , request .Password )
71
100
if err != nil {
72
101
klog .Errorf ("failed NewSmbGlobalMapping %v" , err )
73
102
return response , err
74
103
}
75
104
}
76
105
77
106
if len (localPath ) != 0 {
107
+ klog .V (4 ).Infof ("ValidatePluginPath: '%s'" , localPath )
78
108
err = s .fsServer .ValidatePluginPath (localPath )
79
109
if err != nil {
80
110
klog .Errorf ("failed validate plugin path %v" , err )
@@ -101,11 +131,17 @@ func (s *Server) RemoveSmbGlobalMapping(context context.Context, request *intern
101
131
return response , fmt .Errorf ("remote path is empty" )
102
132
}
103
133
104
- err := s .hostAPI .RemoveSmbGlobalMapping (remotePath )
134
+ mappingPath , err := getRootMappingPath (remotePath )
135
+ if err != nil {
136
+ return response , err
137
+ }
138
+
139
+ err = s .hostAPI .RemoveSmbGlobalMapping (mappingPath )
105
140
if err != nil {
106
141
klog .Errorf ("failed RemoveSmbGlobalMapping %v" , err )
107
142
return response , err
108
143
}
144
+
109
145
klog .V (2 ).Infof ("RemoveSmbGlobalMapping on remote path %q is completed" , request .RemotePath )
110
146
return response , nil
111
147
}
0 commit comments