Skip to content

Commit

Permalink
Merge pull request #1942 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…1940-to-release-1.29

[release-1.29] fix: allow more cache hit in GetRemoteServerFromTarget on hpc deployment
  • Loading branch information
k8s-ci-robot authored Jun 23, 2024
2 parents 5ae2129 + 07142ab commit 557a886
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/os/smb/smb.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import (
"os"
"path/filepath"
"strings"
"sync"

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

var getRemoteServerFromTargetMutex = &sync.Mutex{}

func IsSmbMapped(remotePath string) (bool, error) {
cmdLine := `$(Get-SmbGlobalMapping -RemotePath $Env:smbremotepath -ErrorAction Stop).Status`
cmdEnv := fmt.Sprintf("smbremotepath=%s", remotePath)
Expand Down Expand Up @@ -69,6 +72,10 @@ func RemoveSmbGlobalMapping(remotePath string) error {

// GetRemoteServerFromTarget- gets the remote server path given a mount point, the function is recursive until it find the remote server or errors out
func GetRemoteServerFromTarget(mount string, volStatsCache azcache.Resource) (string, error) {
// use mutex to allow more cache hit
getRemoteServerFromTargetMutex.Lock()
defer getRemoteServerFromTargetMutex.Unlock()

cache, err := volStatsCache.Get(mount, azcache.CacheReadTypeDefault)
if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
AzcopyJobCompleted AzcopyJobState = "Completed"
)

var mutex = &sync.Mutex{}
var powershellCmdMutex = &sync.Mutex{}

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

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

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

0 comments on commit 557a886

Please sign in to comment.