mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 22:40:12 +01:00
feat(volstats): return volstats for path if it is a mountpath
Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
parent
1e5c81d2ac
commit
820d0800cd
2 changed files with 26 additions and 1 deletions
|
|
@ -273,9 +273,13 @@ func (ns *node) NodeGetVolumeStats(
|
||||||
return nil, status.Error(codes.InvalidArgument, "path is not provided")
|
return nil, status.Error(codes.InvalidArgument, "path is not provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if zfs.IsMountPath(path) == false {
|
||||||
|
return nil, status.Error(codes.InvalidArgument, "path is not a mount path")
|
||||||
|
}
|
||||||
|
|
||||||
var sfs unix.Statfs_t
|
var sfs unix.Statfs_t
|
||||||
if err := unix.Statfs(path, &sfs); err != nil {
|
if err := unix.Statfs(path, &sfs); err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "statfs on %s was failed: %v", path, err)
|
return nil, status.Errorf(codes.Internal, "statfs on %s failed: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var usage []*csi.VolumeUsage
|
var usage []*csi.VolumeUsage
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,27 @@ func GetMounts(dev string) ([]string, error) {
|
||||||
return currentMounts, nil
|
return currentMounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMountPath returns true if path is a mount path
|
||||||
|
func IsMountPath(path string) bool {
|
||||||
|
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
mountList []mount.MountPoint
|
||||||
|
)
|
||||||
|
|
||||||
|
mounter := mount.New("")
|
||||||
|
// Get list of mounted paths present with the node
|
||||||
|
if mountList, err = mounter.List(); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, mntInfo := range mountList {
|
||||||
|
if mntInfo.Path == path {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func verifyMountRequest(vol *apis.ZFSVolume, mountpath string) error {
|
func verifyMountRequest(vol *apis.ZFSVolume, mountpath string) error {
|
||||||
if len(mountpath) == 0 {
|
if len(mountpath) == 0 {
|
||||||
return status.Error(codes.InvalidArgument, "mount path missing in request")
|
return status.Error(codes.InvalidArgument, "mount path missing in request")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue