@@ -55,8 +55,9 @@ type CSIProxyMounter interface {
5555var _ CSIProxyMounter = & csiProxyMounter {}
5656
5757type csiProxyMounter struct {
58- FsClient * fsclient.Client
59- SMBClient * smbclient.Client
58+ FsClient * fsclient.Client
59+ SMBClient * smbclient.Client
60+ RemoveSMBMappingDuringUnmount bool
6061}
6162
6263func normalizeWindowsPath (path string ) string {
@@ -101,12 +102,9 @@ func (mounter *csiProxyMounter) SMBMount(source, target, fsType string, mountOpt
101102 }
102103
103104 source = strings .Replace (source , "/" , "\\ " , - 1 )
104- if strings .HasSuffix (source , "\\ " ) {
105- source = strings .TrimSuffix (source , "\\ " )
106- }
107-
105+ source = strings .TrimSuffix (source , "\\ " )
108106 mappingPath , err := getRootMappingPath (source )
109- if err != nil {
107+ if mounter . RemoveSMBMappingDuringUnmount && err != nil {
110108 return fmt .Errorf ("getRootMappingPath(%s) failed with error: %v" , source , err )
111109 }
112110 unlock := lock (mappingPath )
@@ -119,16 +117,17 @@ func (mounter *csiProxyMounter) SMBMount(source, target, fsType string, mountOpt
119117 Username : mountOptions [0 ],
120118 Password : sensitiveMountOptions [0 ],
121119 }
122- klog .V (2 ).Infof ("begin to mount %s on %s" , source , normalizedTarget )
120+ klog .V (2 ).Infof ("begin to NewSmbGlobalMapping %s on %s" , source , normalizedTarget )
123121 if _ , err := mounter .SMBClient .NewSmbGlobalMapping (context .Background (), smbMountRequest ); err != nil {
124- return fmt .Errorf ("smb mapping failed with error: %v" , err )
122+ return fmt .Errorf ("NewSmbGlobalMapping(%s, %s) failed with error: %v" , source , normalizedTarget , err )
125123 }
126- klog .V (2 ).Infof ("mount %s on %s successfully" , source , normalizedTarget )
124+ klog .V (2 ).Infof ("NewSmbGlobalMapping %s on %s successfully" , source , normalizedTarget )
127125
128- if err = incementRemotePathReferencesCount (mappingPath , source ); err != nil {
129- klog .Warningf ("incementMappingPathCount(%s, %s) failed with error: %v" , mappingPath , source , err )
126+ if mounter .RemoveSMBMappingDuringUnmount {
127+ if err := incementRemotePathReferencesCount (mappingPath , source ); err != nil {
128+ return fmt .Errorf ("incementMappingPathCount(%s, %s) failed with error: %v" , mappingPath , source , err )
129+ }
130130 }
131-
132131 return nil
133132}
134133
@@ -138,35 +137,32 @@ func (mounter *csiProxyMounter) SMBUnmount(target string) error {
138137 if remotePath , err := os .Readlink (target ); err != nil {
139138 klog .Warningf ("SMBUnmount: can't get remote path: %v" , err )
140139 } else {
141- if strings .HasSuffix (remotePath , "\\ " ) {
142- remotePath = strings .TrimSuffix (remotePath , "\\ " )
143- }
140+ remotePath = strings .TrimSuffix (remotePath , "\\ " )
144141 mappingPath , err := getRootMappingPath (remotePath )
145- if err != nil {
146- klog . Warningf ("getRootMappingPath(%s) failed with error: %v" , remotePath , err )
147- } else {
148- klog .V (4 ).Infof ("SMBUnmount: remote path: %s, mapping path: %s" , remotePath , mappingPath )
142+ if mounter . RemoveSMBMappingDuringUnmount && err != nil {
143+ return fmt . Errorf ("getRootMappingPath(%s) failed with error: %v" , remotePath , err )
144+ }
145+ klog .V (4 ).Infof ("SMBUnmount: remote path: %s, mapping path: %s" , remotePath , mappingPath )
149146
150- unlock := lock (mappingPath )
151- defer unlock ()
147+ unlock := lock (mappingPath )
148+ defer unlock ()
152149
150+ if mounter .RemoveSMBMappingDuringUnmount {
153151 if err := decrementRemotePathReferencesCount (mappingPath , remotePath ); err != nil {
154- klog .Warningf ("decrementMappingPathCount(%s, %d) failed with error: %v" , mappingPath , remotePath , err )
155- } else {
156- count := getRemotePathReferencesCount (mappingPath )
157- if count == 0 {
158- smbUnmountRequest := & smb.RemoveSmbGlobalMappingRequest {
159- RemotePath : remotePath ,
160- }
161- klog .V (2 ).Infof ("begin to unmount %s on %s" , remotePath , target )
162- if _ , err := mounter .SMBClient .RemoveSmbGlobalMapping (context .Background (), smbUnmountRequest ); err != nil {
163- return fmt .Errorf ("smb unmapping failed with error: %v" , err )
164- } else {
165- klog .V (2 ).Infof ("unmount %s on %s successfully" , remotePath , target )
166- }
167- } else {
168- klog .Infof ("SMBUnmount: found %f links to %s" , count , mappingPath )
152+ return fmt .Errorf ("decrementMappingPathCount(%s, %s) failed with error: %v" , mappingPath , remotePath , err )
153+ }
154+ count := getRemotePathReferencesCount (mappingPath )
155+ if count == 0 {
156+ smbUnmountRequest := & smb.RemoveSmbGlobalMappingRequest {
157+ RemotePath : remotePath ,
158+ }
159+ klog .V (2 ).Infof ("begin to RemoveSmbGlobalMapping %s on %s" , remotePath , target )
160+ if _ , err := mounter .SMBClient .RemoveSmbGlobalMapping (context .Background (), smbUnmountRequest ); err != nil {
161+ return fmt .Errorf ("RemoveSmbGlobalMapping failed with error: %v" , err )
169162 }
163+ klog .V (2 ).Infof ("RemoveSmbGlobalMapping %s on %s successfully" , remotePath , target )
164+ } else {
165+ klog .Infof ("SMBUnmount: found %d links to %s" , count , mappingPath )
170166 }
171167 }
172168 }
@@ -342,7 +338,7 @@ func (mounter *csiProxyMounter) MountSensitiveWithoutSystemdWithMountFlags(sourc
342338
343339// NewCSIProxyMounter - creates a new CSI Proxy mounter struct which encompassed all the
344340// clients to the CSI proxy - filesystem, disk and volume clients.
345- func NewCSIProxyMounter () (* csiProxyMounter , error ) {
341+ func NewCSIProxyMounter (removeSMBMappingDuringUnmount bool ) (* csiProxyMounter , error ) {
346342 fsClient , err := fsclient .NewClient ()
347343 if err != nil {
348344 return nil , err
@@ -353,13 +349,14 @@ func NewCSIProxyMounter() (*csiProxyMounter, error) {
353349 }
354350
355351 return & csiProxyMounter {
356- FsClient : fsClient ,
357- SMBClient : smbClient ,
352+ FsClient : fsClient ,
353+ SMBClient : smbClient ,
354+ RemoveSMBMappingDuringUnmount : removeSMBMappingDuringUnmount ,
358355 }, nil
359356}
360357
361- func NewSafeMounter () (* mount.SafeFormatAndMount , error ) {
362- csiProxyMounter , err := NewCSIProxyMounter ()
358+ func NewSafeMounter (removeSMBMappingDuringUnmount bool ) (* mount.SafeFormatAndMount , error ) {
359+ csiProxyMounter , err := NewCSIProxyMounter (removeSMBMappingDuringUnmount )
363360 if err == nil {
364361 klog .V (2 ).Infof ("using CSIProxyMounterV1, %s" , csiProxyMounter .GetAPIVersions ())
365362 return & mount.SafeFormatAndMount {
0 commit comments