Skip to content
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

[release-1.29] fix: possible dead loop in GetVolumeStats on Windows #2271

Merged
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
9 changes: 6 additions & 3 deletions pkg/os/volume/volume.go
Original file line number Diff line number Diff line change
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
Loading