diff --git a/go.mod b/go.mod index c489cb00eb..b0aa2611e6 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/pkg/azuredisk/nodeserver.go b/pkg/azuredisk/nodeserver.go index 57a8410281..09c10a66fc 100644 --- a/pkg/azuredisk/nodeserver.go +++ b/pkg/azuredisk/nodeserver.go @@ -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)) diff --git a/pkg/mounter/safe_mounter_host_process_windows.go b/pkg/mounter/safe_mounter_host_process_windows.go index 29737e53c3..9bf86a26f2 100644 --- a/pkg/mounter/safe_mounter_host_process_windows.go +++ b/pkg/mounter/safe_mounter_host_process_windows.go @@ -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. diff --git a/pkg/os/volume/volume.go b/pkg/os/volume/volume.go index 28d04e8f2c..7cbfede04b 100644 --- a/pkg/os/volume/volume.go +++ b/pkg/os/volume/volume.go @@ -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