Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial RPC_GET_VOLUME_STAT support #113

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/kubernetes-csi/csi-test/v3 v3.1.1
github.com/linode/linodego v0.21.0
golang.org/x/net v0.7.0
golang.org/x/sys v0.5.0
google.golang.org/grpc v1.31.1
k8s.io/apimachinery v0.19.2
k8s.io/utils v0.0.0-20201005171033-6301aaf42dc7
Expand All @@ -20,7 +21,6 @@ require (
github.com/onsi/ginkgo v1.11.0 // indirect
github.com/onsi/gomega v1.7.1 // indirect
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
Expand Down
1 change: 1 addition & 0 deletions pkg/linode-bs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (linodeDriver *LinodeDriver) SetupLinodeDriver(linodeClient linodeclient.Li
ns := []csi.NodeServiceCapability_RPC_Type{
csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
csi.NodeServiceCapability_RPC_EXPAND_VOLUME,
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
}
if err := linodeDriver.AddNodeServiceCapabilities(ns); err != nil {
return err
Expand Down
33 changes: 32 additions & 1 deletion pkg/linode-bs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import (
"errors"
"fmt"
"os"
"strconv"
Expand All @@ -27,6 +28,7 @@ import (
"github.com/linode/linode-blockstorage-csi-driver/pkg/metadata"
mountmanager "github.com/linode/linode-blockstorage-csi-driver/pkg/mount-manager"
"golang.org/x/net/context"
"golang.org/x/sys/unix"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/utils/mount"
Expand Down Expand Up @@ -304,5 +306,34 @@ func (ns *LinodeNodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInf
}

func (ns *LinodeNodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
return nil, status.Error(codes.Unimplemented, "NodeGetVolumeStats is not yet implemented")
if req.VolumeId == "" || req.VolumePath == "" {
return nil, status.Error(codes.InvalidArgument, "volume ID or path empty")
}

var statfs unix.Statfs_t
// See http://man7.org/linux/man-pages/man2/statfs.2.html for details.
err := unix.Statfs(req.VolumePath, &statfs)
if err != nil {
if errors.Is(err, unix.ENOENT) {
return nil, status.Errorf(codes.NotFound, "volume path not found: %v", err.Error())
}
return nil, status.Errorf(codes.Internal, "failed to get stats: %v", err.Error())
}

return &csi.NodeGetVolumeStatsResponse{
Usage: []*csi.VolumeUsage{
{
Available: int64(statfs.Bavail) * int64(statfs.Bsize),
Total: int64(statfs.Blocks) * int64(statfs.Bsize),
Used: (int64(statfs.Blocks) - int64(statfs.Bfree)) * int64(statfs.Bsize),
Unit: csi.VolumeUsage_BYTES,
},
{
Available: int64(statfs.Ffree),
Total: int64(statfs.Files),
Used: int64(statfs.Files) - int64(statfs.Ffree),
Unit: csi.VolumeUsage_INODES,
},
},
}, nil
}