Skip to content

Commit

Permalink
fix: use GetFreeSpace call in ExpandVolume on Windows
Browse files Browse the repository at this point in the history
fix gomod
  • Loading branch information
andyzhangx committed Apr 12, 2024
1 parent 57643e8 commit 7eb1c58
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 28 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
go.uber.org/mock v0.4.0
golang.org/x/net v0.22.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.18.0
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
k8s.io/api v0.29.3
Expand Down Expand Up @@ -136,7 +137,6 @@ require (
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions pkg/azuredisk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ func (d *Driver) NodeExpandVolume(_ context.Context, req *csi.NodeExpandVolumeRe
klog.Errorf("%v, will continue checking whether the volume has been resized", retErr)
}

if runtime.GOOS == "windows" && d.enableWindowsHostProcess {
// in windows host process mode, this driver could get the volume size from the volume path
devicePath = volumePath
}
gotBlockSizeBytes, err := getBlockSizeBytes(devicePath, d.mounter)
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("could not get size of block volume at path %s: %v", devicePath, err))
Expand Down
6 changes: 3 additions & 3 deletions pkg/mounter/safe_mounter_host_process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ func (mounter *winMounter) GetDeviceNameFromMount(mountPath, pluginMountDir stri
}

// GetVolumeSizeInBytes returns the size of the volume in bytes.
func (mounter *winMounter) GetVolumeSizeInBytes(devicePath string) (int64, error) {
volumeSize, _, err := volume.GetVolumeStats(devicePath)
return volumeSize, err
func (mounter *winMounter) GetVolumeSizeInBytes(volumePath string) (int64, error) {
_, totalBytes, _, err := GetFreeSpace(volumePath)
return totalBytes, err
}

// ResizeVolume resizes the volume to the maximum available size.
Expand Down
24 changes: 0 additions & 24 deletions pkg/os/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,6 @@ func ResizeVolume(volumeID string, size int64) error {
return nil
}

// GetVolumeStats - retrieves the volume stats for a given volume
func GetVolumeStats(volumeID string) (int64, int64, error) {
// get the size and sizeRemaining for the volume
cmd := "(Get-Volume -UniqueId \"$Env:volumeID\" | Select SizeRemaining,Size) | ConvertTo-Json"
out, err := azureutils.RunPowershellCmd(cmd, fmt.Sprintf("volumeID=%s", volumeID))

if err != nil {
return -1, -1, fmt.Errorf("error getting capacity and used size of volume. cmd: %s, output: %s, error: %v", cmd, string(out), err)
}

var getVolume map[string]int64
outString := string(out)
err = json.Unmarshal([]byte(outString), &getVolume)
if err != nil {
return -1, -1, fmt.Errorf("out %v outstring %v err %v", out, outString, err)
}

volumeSize := getVolume["Size"]
volumeSizeRemaining := getVolume["SizeRemaining"]

volumeUsedSize := volumeSize - volumeSizeRemaining
return volumeSize, volumeUsedSize, nil
}

// GetDiskNumberFromVolumeID - gets the disk number where the volume is.
func GetDiskNumberFromVolumeID(volumeID string) (uint32, error) {
// get the size and sizeRemaining for the volume
Expand Down

0 comments on commit 7eb1c58

Please sign in to comment.