@@ -18,8 +18,6 @@ import (
1818 "fmt"
1919 "os"
2020 "runtime"
21- "strconv"
22- "strings"
2321
2422 "context"
2523
@@ -398,7 +396,7 @@ func (ns *GCENodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGe
398396 return nil , status .Errorf (codes .Internal , "failed to determine whether %s is block device: %v" , req .VolumePath , err )
399397 }
400398 if isBlock {
401- bcap , err := ns . getBlockSizeBytes (req .VolumePath )
399+ bcap , err := getBlockSizeBytes (req .VolumePath , ns . Mounter )
402400 if err != nil {
403401 return nil , status .Errorf (codes .Internal , "failed to get block capacity on path %s: %v" , req .VolumePath , err )
404402 }
@@ -482,14 +480,10 @@ func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpa
482480
483481 }
484482
485- // Check the block size
486- gotBlockSizeBytes , err := ns .getBlockSizeBytes (devicePath )
487- if err != nil {
488- return nil , status .Error (codes .Internal , fmt .Sprintf ("error when getting size of block volume at path %s: %v" , devicePath , err ))
489- }
490- if gotBlockSizeBytes < reqBytes {
483+ diskSizeBytes , err := getBlockSizeBytes (devicePath , ns .Mounter )
484+ if diskSizeBytes < reqBytes {
491485 // It's possible that the somewhere the volume size was rounded up, getting more size than requested is a success :)
492- return nil , status .Errorf (codes .Internal , "resize requested for %v but after resize volume was size %v" , reqBytes , gotBlockSizeBytes )
486+ return nil , status .Errorf (codes .Internal , "resize requested for %v but after resize volume was size %v" , reqBytes , diskSizeBytes )
493487 }
494488
495489 // TODO(dyzz) Some sort of formatted volume could also check the fs size.
@@ -531,16 +525,3 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
531525 }
532526 return volumeLimitBig , nil
533527}
534-
535- func (ns * GCENodeServer ) getBlockSizeBytes (devicePath string ) (int64 , error ) {
536- output , err := ns .Mounter .Exec .Command ("blockdev" , "--getsize64" , devicePath ).CombinedOutput ()
537- if err != nil {
538- return - 1 , fmt .Errorf ("error when getting size of block volume at path %s: output: %s, err: %v" , devicePath , string (output ), err )
539- }
540- strOut := strings .TrimSpace (string (output ))
541- gotSizeBytes , err := strconv .ParseInt (strOut , 10 , 64 )
542- if err != nil {
543- return - 1 , fmt .Errorf ("failed to parse %s into an int size" , strOut )
544- }
545- return gotSizeBytes , nil
546- }
0 commit comments