diff --git a/internal/cephfs/driver.go b/internal/cephfs/driver.go index 7c6f1b18741..b99ded8bd7c 100644 --- a/internal/cephfs/driver.go +++ b/internal/cephfs/driver.go @@ -25,6 +25,7 @@ import ( casceph "github.com/ceph/ceph-csi/internal/csi-addons/cephfs" csiaddons "github.com/ceph/ceph-csi/internal/csi-addons/server" csicommon "github.com/ceph/ceph-csi/internal/csi-common" + hc "github.com/ceph/ceph-csi/internal/health-checker" "github.com/ceph/ceph-csi/internal/journal" "github.com/ceph/ceph-csi/internal/util" "github.com/ceph/ceph-csi/internal/util/log" @@ -82,6 +83,7 @@ func NewNodeServer( VolumeLocks: util.NewVolumeLocks(), kernelMountOptions: kernelMountOptions, fuseMountOptions: fuseMountOptions, + healthChecker: hc.NewHealthCheckManager(), } } diff --git a/internal/cephfs/nodeserver.go b/internal/cephfs/nodeserver.go index 7287cde7605..f2f8eb7ec16 100644 --- a/internal/cephfs/nodeserver.go +++ b/internal/cephfs/nodeserver.go @@ -29,6 +29,7 @@ import ( "github.com/ceph/ceph-csi/internal/cephfs/store" fsutil "github.com/ceph/ceph-csi/internal/cephfs/util" csicommon "github.com/ceph/ceph-csi/internal/csi-common" + hc "github.com/ceph/ceph-csi/internal/health-checker" "github.com/ceph/ceph-csi/internal/util" "github.com/ceph/ceph-csi/internal/util/fscrypt" "github.com/ceph/ceph-csi/internal/util/log" @@ -47,6 +48,7 @@ type NodeServer struct { VolumeLocks *util.VolumeLocks kernelMountOptions string fuseMountOptions string + healthChecker hc.Manager } func getCredentialsForVolume( @@ -228,6 +230,8 @@ func (ns *NodeServer) NodeStageVolume( return nil, status.Error(codes.Internal, err.Error()) } + ns.healthChecker.StartChecker(stagingTargetPath) + return &csi.NodeStageVolumeResponse{}, nil } @@ -270,6 +274,8 @@ func (ns *NodeServer) NodeStageVolume( } } + ns.healthChecker.StartChecker(stagingTargetPath) + return &csi.NodeStageVolumeResponse{}, nil } @@ -608,6 +614,8 @@ func (ns *NodeServer) NodeUnstageVolume( stagingTargetPath := req.GetStagingTargetPath() + ns.healthChecker.StopChecker(stagingTargetPath) + if err = fsutil.RemoveNodeStageMountinfo(fsutil.VolumeID(volID)); err != nil { log.ErrorLog(ctx, "cephfs: failed to remove NodeStageMountinfo for volume %s: %v", volID, err) @@ -670,6 +678,13 @@ func (ns *NodeServer) NodeGetCapabilities( }, }, }, + { + Type: &csi.NodeServiceCapability_Rpc{ + Rpc: &csi.NodeServiceCapability_RPC{ + Type: csi.NodeServiceCapability_RPC_VOLUME_CONDITION, + }, + }, + }, { Type: &csi.NodeServiceCapability_Rpc{ Rpc: &csi.NodeServiceCapability_RPC{ @@ -711,7 +726,21 @@ func (ns *NodeServer) NodeGetVolumeStats( } if stat.Mode().IsDir() { - return csicommon.FilesystemNodeGetVolumeStats(ctx, ns.Mounter, targetPath, false) + res, err := csicommon.FilesystemNodeGetVolumeStats(ctx, ns.Mounter, targetPath, false) + if err != nil { + return nil, err + } + + healthy, msg := ns.healthChecker.IsHealthy(req.GetStagingTargetPath()) + res.VolumeCondition = &csi.VolumeCondition{ + Abnormal: !healthy, + } + + if !healthy { + res.VolumeCondition.Message = msg.Error() + } + + return res, nil } return nil, status.Errorf(codes.InvalidArgument, "targetpath %q is not a directory or device", targetPath)