Skip to content

fix: allow more cache hit in GetRemoteServerFromTarget on hpc deployment #1940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,7 +41,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 @@ -80,8 +80,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
Loading