@@ -21,15 +21,11 @@ import (
21
21
"os"
22
22
"path/filepath"
23
23
"strings"
24
- "sync"
25
24
26
25
"k8s.io/klog/v2"
27
26
"sigs.k8s.io/azurefile-csi-driver/pkg/util"
28
- azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
29
27
)
30
28
31
- var getRemoteServerFromTargetMutex = & sync.Mutex {}
32
-
33
29
func IsSmbMapped (remotePath string ) (bool , error ) {
34
30
cmdLine := `$(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath -ErrorAction Stop).Status`
35
31
cmdEnv := fmt .Sprintf ("smbremotepath=%s" , remotePath )
@@ -71,33 +67,17 @@ func RemoveSmbGlobalMapping(remotePath string) error {
71
67
}
72
68
73
69
// GetRemoteServerFromTarget- gets the remote server path given a mount point, the function is recursive until it find the remote server or errors out
74
- func GetRemoteServerFromTarget (mount string , volStatsCache azcache.Resource ) (string , error ) {
75
- // use mutex to allow more cache hit
76
- getRemoteServerFromTargetMutex .Lock ()
77
- defer getRemoteServerFromTargetMutex .Unlock ()
78
-
79
- cache , err := volStatsCache .Get (mount , azcache .CacheReadTypeDefault )
80
- if err != nil {
81
- return "" , err
82
- }
83
- if cache != nil {
84
- remoteServer := cache .(string )
85
- klog .V (6 ).Infof ("GetRemoteServerFromTarget(%s) cache hit: %s" , mount , remoteServer )
86
- return remoteServer , nil
87
- }
70
+ func GetRemoteServerFromTarget (mount string ) (string , error ) {
88
71
target , err := os .Readlink (mount )
89
72
klog .V (2 ).Infof ("read link for mount %s, target: %s" , mount , target )
90
73
if err != nil || len (target ) == 0 {
91
74
return "" , fmt .Errorf ("error reading link for mount %s. target %s err: %v" , mount , target , err )
92
75
}
93
- remoteServer := strings .TrimSpace (target )
94
- // cache the remote server path
95
- volStatsCache .Set (mount , remoteServer )
96
- return remoteServer , nil
76
+ return strings .TrimSpace (target ), nil
97
77
}
98
78
99
79
// CheckForDuplicateSMBMounts checks if there is any other SMB mount exists on the same remote server
100
- func CheckForDuplicateSMBMounts (dir , mount , remoteServer string , volStatsCache azcache. Resource ) (bool , error ) {
80
+ func CheckForDuplicateSMBMounts (dir , mount , remoteServer string ) (bool , error ) {
101
81
files , err := os .ReadDir (dir )
102
82
if err != nil {
103
83
return false , err
@@ -113,7 +93,7 @@ func CheckForDuplicateSMBMounts(dir, mount, remoteServer string, volStatsCache a
113
93
fileInfo , err := os .Lstat (globalMountPath )
114
94
// check if the file is a symlink, if yes, check if it is pointing to the same remote server
115
95
if err == nil && fileInfo .Mode ()& os .ModeSymlink != 0 {
116
- remoteServerPath , err := GetRemoteServerFromTarget (globalMountPath , volStatsCache )
96
+ remoteServerPath , err := GetRemoteServerFromTarget (globalMountPath )
117
97
klog .V (2 ).Infof ("checking remote server path %s on local path %s" , remoteServerPath , globalMountPath )
118
98
if err == nil {
119
99
if remoteServerPath == remoteServer {
0 commit comments