@@ -22,7 +22,6 @@ import (
22
22
23
23
"context"
24
24
25
- "golang.org/x/sys/unix"
26
25
"google.golang.org/grpc/codes"
27
26
"google.golang.org/grpc/status"
28
27
@@ -41,6 +40,7 @@ type GCENodeServer struct {
41
40
Driver * GCEDriver
42
41
Mounter * mount.SafeFormatAndMount
43
42
DeviceUtils mountmanager.DeviceUtils
43
+ VolumeStatter mountmanager.Statter
44
44
MetadataService metadataservice.MetadataService
45
45
46
46
// A map storing all volumes with ongoing operations so that additional operations
@@ -368,32 +368,33 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
368
368
}
369
369
370
370
func (ns * GCENodeServer ) NodeGetVolumeStats (ctx context.Context , req * csi.NodeGetVolumeStatsRequest ) (* csi.NodeGetVolumeStatsResponse , error ) {
371
+ if len (req .VolumeId ) == 0 {
372
+ return nil , status .Error (codes .InvalidArgument , "NodeGetVolumeStats volume ID was empty" )
373
+ }
371
374
if len (req .VolumePath ) == 0 {
372
375
return nil , status .Error (codes .InvalidArgument , "NodeGetVolumeStats volume path was empty" )
373
376
}
374
- statfs := & unix. Statfs_t {}
375
- err := unix . Statfs (req .VolumePath , statfs )
377
+
378
+ exists , err := ns . Mounter . Interface . ExistsPath (req .VolumePath )
376
379
if err != nil {
377
- return nil , status .Errorf (codes .Internal , "failed to get fs info on path %s: %v" , req .VolumePath , err )
380
+ return nil , status .Errorf (codes .Internal , "unknown error when stat on %s: %v" , req .VolumePath , err )
381
+ }
382
+ if ! exists {
383
+ return nil , status .Errorf (codes .NotFound , "path %s does not exist" , req .VolumePath )
378
384
}
379
385
380
- // Available is blocks available * fragment size
381
- available := int64 (statfs .Bavail ) * int64 (statfs .Bsize )
382
- // Capacity is total block count * fragment size
383
- capacity := int64 (statfs .Blocks ) * int64 (statfs .Bsize )
384
- // Usage is block being used * fragment size (aka block size).
385
- usage := (int64 (statfs .Blocks ) - int64 (statfs .Bfree )) * int64 (statfs .Bsize )
386
- inodes := int64 (statfs .Files )
387
- inodesFree := int64 (statfs .Ffree )
388
- inodesUsed := inodes - inodesFree
386
+ available , capacity , used , inodesFree , inodes , inodesUsed , err := ns .VolumeStatter .StatFS (req .VolumePath )
387
+ if err != nil {
388
+ return nil , status .Errorf (codes .Internal , "failed to get fs info on path %s: %v" , req .VolumePath , err )
389
+ }
389
390
390
391
return & csi.NodeGetVolumeStatsResponse {
391
392
Usage : []* csi.VolumeUsage {
392
393
{
393
394
Unit : csi .VolumeUsage_BYTES ,
394
395
Available : available ,
395
396
Total : capacity ,
396
- Used : usage ,
397
+ Used : used ,
397
398
},
398
399
{
399
400
Unit : csi .VolumeUsage_INODES ,
0 commit comments