Skip to content

Commit 557a886

Browse files
authored
Merge pull request #1942 from k8s-infra-cherrypick-robot/cherry-pick-1940-to-release-1.29
[release-1.29] fix: allow more cache hit in GetRemoteServerFromTarget on hpc deployment
2 parents 5ae2129 + 07142ab commit 557a886

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pkg/os/smb/smb.go

+7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import (
2121
"os"
2222
"path/filepath"
2323
"strings"
24+
"sync"
2425

2526
"k8s.io/klog/v2"
2627
"sigs.k8s.io/azurefile-csi-driver/pkg/util"
2728
azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
2829
)
2930

31+
var getRemoteServerFromTargetMutex = &sync.Mutex{}
32+
3033
func IsSmbMapped(remotePath string) (bool, error) {
3134
cmdLine := `$(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath -ErrorAction Stop).Status`
3235
cmdEnv := fmt.Sprintf("smbremotepath=%s", remotePath)
@@ -69,6 +72,10 @@ func RemoveSmbGlobalMapping(remotePath string) error {
6972

7073
// GetRemoteServerFromTarget- gets the remote server path given a mount point, the function is recursive until it find the remote server or errors out
7174
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+
7279
cache, err := volStatsCache.Get(mount, azcache.CacheReadTypeDefault)
7380
if err != nil {
7481
return "", err

pkg/util/util.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const (
4040
AzcopyJobCompleted AzcopyJobState = "Completed"
4141
)
4242

43-
var mutex = &sync.Mutex{}
43+
var powershellCmdMutex = &sync.Mutex{}
4444

4545
// RoundUpBytes rounds up the volume size in bytes up to multiplications of GiB
4646
// in the unit of Bytes
@@ -79,8 +79,8 @@ func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
7979

8080
func RunPowershellCmd(command string, envs ...string) ([]byte, error) {
8181
// only one powershell command can be executed at a time to avoid OOM
82-
mutex.Lock()
83-
defer mutex.Unlock()
82+
powershellCmdMutex.Lock()
83+
defer powershellCmdMutex.Unlock()
8484

8585
cmd := exec.Command("powershell", "-Mta", "-NoProfile", "-Command", command)
8686
cmd.Env = append(os.Environ(), envs...)

0 commit comments

Comments
 (0)