@@ -18,8 +18,6 @@ import (
18
18
"fmt"
19
19
"os"
20
20
"runtime"
21
- "strconv"
22
- "strings"
23
21
24
22
"context"
25
23
@@ -398,7 +396,7 @@ func (ns *GCENodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGe
398
396
return nil , status .Errorf (codes .Internal , "failed to determine whether %s is block device: %v" , req .VolumePath , err )
399
397
}
400
398
if isBlock {
401
- bcap , err := ns . getBlockSizeBytes (req .VolumePath )
399
+ bcap , err := getBlockSizeBytes (req .VolumePath , ns . Mounter )
402
400
if err != nil {
403
401
return nil , status .Errorf (codes .Internal , "failed to get block capacity on path %s: %v" , req .VolumePath , err )
404
402
}
@@ -482,14 +480,10 @@ func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpa
482
480
483
481
}
484
482
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 {
491
485
// 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 )
493
487
}
494
488
495
489
// TODO(dyzz) Some sort of formatted volume could also check the fs size.
@@ -531,16 +525,3 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
531
525
}
532
526
return volumeLimitBig , nil
533
527
}
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