Skip to content

Commit

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

[release-1.29] fix: possible dead loop in GetVolumeStats on Windows
  • Loading branch information
andyzhangx committed Apr 11, 2024
2 parents 30d9231 + ff110dd commit 0dfa04f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/os/volume/volume.go
Expand Up @@ -228,18 +228,21 @@ func GetDiskNumberFromVolumeID(volumeID string) (uint32, error) {

// GetVolumeIDFromTargetPath - gets the volume ID given a mount point, the function is recursive until it find a volume or errors out
func GetVolumeIDFromTargetPath(mount string) (string, error) {
return getTarget(mount)
return getTarget(mount, 5 /*max depth*/)
}

func getTarget(mount string) (string, error) {
func getTarget(mount string, depth int) (string, error) {
if depth == 0 {
return "", fmt.Errorf("maximum depth reached on mount %s", mount)
}
cmd := "(Get-Item -Path $Env:mount).Target"
out, err := azureutils.RunPowershellCmd(cmd, fmt.Sprintf("mount=%s", mount))
if err != nil || len(out) == 0 {
return "", fmt.Errorf("error getting volume from mount. cmd: %s, output: %s, error: %v", cmd, string(out), err)
}
volumeString := strings.TrimSpace(string(out))
if !strings.HasPrefix(volumeString, "Volume") {
return getTarget(volumeString)
return getTarget(volumeString, depth-1)
}

return ensureVolumePrefix(volumeString), nil
Expand Down

0 comments on commit 0dfa04f

Please sign in to comment.