Skip to content
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
49 changes: 27 additions & 22 deletions internal/cephfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ import (
rterrors "github.com/ceph/ceph-csi/internal/util/reftracker/errors"
)

// ControllerServer struct of CEPH CSI driver with supported methods of CSI
// controller server spec.
type ControllerServer struct {
// cephfsControllerServer implements the CSI controller server for the CephFS driver.
type cephfsControllerServer struct {
Comment thread
nixpanic marked this conversation as resolved.
*csicommon.DefaultControllerServer
// A map storing all volumes with ongoing operations so that additional operations
// for that same volume (as defined by VolumeID/volume name) return an Aborted error
Expand All @@ -65,6 +64,12 @@ type ControllerServer struct {
ClusterName string
}

// Assert required implementation of CSI interfaces.
var (
_ csi.ControllerServer = &cephfsControllerServer{}
_ csi.GroupControllerServer = &cephfsControllerServer{}
)

// subvolumeMetadataHandler holds the metadata handling functions.
type subvolumeMetadataHandler struct {
logSubvolumeName string
Expand All @@ -73,7 +78,7 @@ type subvolumeMetadataHandler struct {
}

// createBackingVolume creates the backing subvolume and on any error cleans up any created entities.
func (cs *ControllerServer) createBackingVolume(
func (cs *cephfsControllerServer) createBackingVolume(
ctx context.Context,
volOptions,
parentVolOpt *store.VolumeOptions,
Expand Down Expand Up @@ -112,7 +117,7 @@ func (cs *ControllerServer) createBackingVolume(
return nil
}

func (cs *ControllerServer) createBackingVolumeFromSnapshotSource(
func (cs *cephfsControllerServer) createBackingVolumeFromSnapshotSource(
ctx context.Context,
volOptions *store.VolumeOptions,
parentVolOpt *store.VolumeOptions,
Expand Down Expand Up @@ -156,7 +161,7 @@ func (cs *ControllerServer) createBackingVolumeFromSnapshotSource(
return nil
}

func (cs *ControllerServer) createBackingVolumeFromVolumeSource(
func (cs *cephfsControllerServer) createBackingVolumeFromVolumeSource(
ctx context.Context,
parentVolOpt *store.VolumeOptions,
volClient core.SubVolumeClient,
Expand All @@ -183,7 +188,7 @@ func (cs *ControllerServer) createBackingVolumeFromVolumeSource(
return nil
}

func (cs *ControllerServer) checkContentSource(
func (cs *cephfsControllerServer) checkContentSource(
ctx context.Context,
req *csi.CreateVolumeRequest,
cr *util.Credentials,
Expand Down Expand Up @@ -289,7 +294,7 @@ func buildCreateVolumeResponse(
// CreateVolume creates a reservation and the volume in backend, if it is not already present.
//
//nolint:gocognit,gocyclo,nestif,cyclop // TODO: reduce complexity
func (cs *ControllerServer) CreateVolume(
func (cs *cephfsControllerServer) CreateVolume(
ctx context.Context,
req *csi.CreateVolumeRequest,
) (*csi.CreateVolumeResponse, error) {
Expand Down Expand Up @@ -484,7 +489,7 @@ func (cs *ControllerServer) CreateVolume(
}

// DeleteVolume deletes the volume in backend and its reservation.
func (cs *ControllerServer) DeleteVolume(
func (cs *cephfsControllerServer) DeleteVolume(
ctx context.Context,
req *csi.DeleteVolumeRequest,
) (*csi.DeleteVolumeResponse, error) {
Expand Down Expand Up @@ -583,7 +588,7 @@ func (cs *ControllerServer) DeleteVolume(
return &csi.DeleteVolumeResponse{}, nil
}

func (cs *ControllerServer) cleanUpBackingVolume(
func (cs *cephfsControllerServer) cleanUpBackingVolume(
ctx context.Context,
volOptions *store.VolumeOptions,
volID *store.VolumeIdentifier,
Expand Down Expand Up @@ -674,7 +679,7 @@ func (cs *ControllerServer) cleanUpBackingVolume(

// ValidateVolumeCapabilities checks whether the volume capabilities requested
// are supported.
func (cs *ControllerServer) ValidateVolumeCapabilities(
func (cs *cephfsControllerServer) ValidateVolumeCapabilities(
ctx context.Context,
req *csi.ValidateVolumeCapabilitiesRequest,
) (*csi.ValidateVolumeCapabilitiesResponse, error) {
Expand All @@ -693,7 +698,7 @@ func (cs *ControllerServer) ValidateVolumeCapabilities(
}

// ControllerExpandVolume expands CephFS Volumes on demand based on resizer request.
func (cs *ControllerServer) ControllerExpandVolume(
func (cs *cephfsControllerServer) ControllerExpandVolume(
ctx context.Context,
req *csi.ControllerExpandVolumeRequest,
) (*csi.ControllerExpandVolumeResponse, error) {
Expand Down Expand Up @@ -755,7 +760,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
// in store
//
//nolint:gocyclo,cyclop // golangci-lint did not catch this earlier, needs to get fixed late
func (cs *ControllerServer) CreateSnapshot(
func (cs *cephfsControllerServer) CreateSnapshot(
ctx context.Context,
req *csi.CreateSnapshotRequest,
) (*csi.CreateSnapshotResponse, error) {
Expand Down Expand Up @@ -916,7 +921,7 @@ func (cs *ControllerServer) CreateSnapshot(
}, nil
}

func (cs *ControllerServer) doSnapshot(
func (cs *cephfsControllerServer) doSnapshot(
ctx context.Context,
volOpt *store.VolumeOptions,
snapshotName string,
Expand Down Expand Up @@ -960,7 +965,7 @@ func (cs *ControllerServer) doSnapshot(
return snap, err
}

func (cs *ControllerServer) validateSnapshotReq(ctx context.Context, req *csi.CreateSnapshotRequest) error {
func (cs *cephfsControllerServer) validateSnapshotReq(ctx context.Context, req *csi.CreateSnapshotRequest) error {
if err := cs.Driver.ValidateControllerServiceRequest(
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil {
log.ErrorLog(ctx, "invalid create snapshot req: %v", protosanitizer.StripSecrets(req))
Expand All @@ -981,7 +986,7 @@ func (cs *ControllerServer) validateSnapshotReq(ctx context.Context, req *csi.Cr

// DeleteSnapshot deletes the snapshot in backend and removes the
// snapshot metadata from store.
func (cs *ControllerServer) DeleteSnapshot(
func (cs *cephfsControllerServer) DeleteSnapshot(
ctx context.Context,
req *csi.DeleteSnapshotRequest,
) (*csi.DeleteSnapshotResponse, error) {
Expand Down Expand Up @@ -1127,7 +1132,7 @@ func deleteSnapshotAndUndoReservation(
// ControllerPublishVolume implements the CSI ControllerPublishVolume RPC.
// It reads the service account restriction metadata from the backing CephFS
// subvolume and passes it to the node via publish context.
func (cs *ControllerServer) ControllerPublishVolume(
func (cs *cephfsControllerServer) ControllerPublishVolume(
ctx context.Context,
req *csi.ControllerPublishVolumeRequest,
) (*csi.ControllerPublishVolumeResponse, error) {
Expand All @@ -1150,7 +1155,7 @@ func (cs *ControllerServer) ControllerPublishVolume(
// getServiceAccountRestriction reads the service account restriction metadata
// from the CephFS subvolume backing the volume. Returns empty string if no
// restriction is set.
func (cs *ControllerServer) getServiceAccountRestriction(
func (cs *cephfsControllerServer) getServiceAccountRestriction(
ctx context.Context,
req *csi.ControllerPublishVolumeRequest,
) (string, error) {
Expand Down Expand Up @@ -1207,7 +1212,7 @@ func (cs *ControllerServer) getServiceAccountRestriction(

// ControllerUnpublishVolume implements the CSI ControllerUnpublishVolume RPC.
// This function is responsible for fencing a node when a volume is unpublished.
func (cs *ControllerServer) ControllerUnpublishVolume(
func (cs *cephfsControllerServer) ControllerUnpublishVolume(
ctx context.Context,
req *csi.ControllerUnpublishVolumeRequest,
) (*csi.ControllerUnpublishVolumeResponse, error) {
Expand Down Expand Up @@ -1266,7 +1271,7 @@ func (cs *ControllerServer) ControllerUnpublishVolume(

// getSubvolumeMetadataHandler returns the appropriate metadata handler based on whether
// the volume is a backing snapshot or a regular subvolume.
func (cs *ControllerServer) getSubvolumeMetadataHandler(
func (cs *cephfsControllerServer) getSubvolumeMetadataHandler(
ctx context.Context,
volOptions *store.VolumeOptions,
secrets map[string]string,
Expand Down Expand Up @@ -1317,7 +1322,7 @@ func (cs *ControllerServer) getSubvolumeMetadataHandler(
//
// Behavior:
// - Removes the user ID mapping metadata for the specified nodeId from the subvolume.
func (cs *ControllerServer) removeUserIdMapping(
func (cs *cephfsControllerServer) removeUserIdMapping(
ctx context.Context,
volumeId, nodeId string,
secrets map[string]string,
Expand Down Expand Up @@ -1367,7 +1372,7 @@ func (cs *ControllerServer) removeUserIdMapping(
// - Handles missing or empty metadata gracefully and logs appropriate warnings.
//
// Returns an error if any step in the fencing process fails.
func (cs *ControllerServer) fenceNode(
func (cs *cephfsControllerServer) fenceNode(
ctx context.Context,
volumeId, nodeId string,
secrets map[string]string,
Expand Down
26 changes: 13 additions & 13 deletions internal/cephfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import (
type cephfsDriver struct {
cd *csicommon.CSIDriver

is *IdentityServer
ns *NodeServer
cs *ControllerServer
is csi.IdentityServer
ns csi.NodeServer
cs csi.ControllerServer
// cas is the CSIAddonsServer where CSI-Addons services are handled
cas *csiaddons.CSIAddonsServer
}
Expand All @@ -55,20 +55,21 @@ func NewDriver() driver.Driver {
}

// NewIdentityServer initialize a identity server for ceph CSI driver.
func NewIdentityServer(d *csicommon.CSIDriver) *IdentityServer {
return &IdentityServer{
func NewIdentityServer(d *csicommon.CSIDriver) csi.IdentityServer {
return &cephfsIdentityServer{
DefaultIdentityServer: csicommon.NewDefaultIdentityServer(d),
}
}

// NewControllerServer initialize a controller server for ceph CSI driver.
func NewControllerServer(d *csicommon.CSIDriver) *ControllerServer {
return &ControllerServer{
func NewControllerServer(d *csicommon.CSIDriver, clusterName string) csi.ControllerServer {
return &cephfsControllerServer{
DefaultControllerServer: csicommon.NewDefaultControllerServer(d),
VolumeLocks: util.NewIDLocker(),
SnapshotLocks: util.NewIDLocker(),
VolumeGroupLocks: util.NewIDLocker(),
OperationLocks: util.NewOperationLock(),
ClusterName: clusterName,
}
}

Expand All @@ -79,9 +80,9 @@ func NewNodeServer(
kernelMountOptions string,
fuseMountOptions string,
nodeLabels, topology, crushLocationMap map[string]string,
) *NodeServer {
) csi.NodeServer {
cliReadAffinityMapOptions := util.ConstructReadAffinityMapOption(crushLocationMap)
ns := &NodeServer{
ns := &cephfsNodeServer{
DefaultNodeServer: csicommon.NewDefaultNodeServer(d, t, cliReadAffinityMapOptions, topology, nodeLabels),
VolumeLocks: util.NewIDLocker(),
kernelMountOptions: kernelMountOptions,
Expand Down Expand Up @@ -174,8 +175,7 @@ func (fs *cephfsDriver) Run(conf *util.Config) {
}

if conf.IsControllerServer {
fs.cs = NewControllerServer(fs.cd)
fs.cs.ClusterName = conf.ClusterName
fs.cs = NewControllerServer(fs.cd, conf.ClusterName)
}
if !conf.IsControllerServer && !conf.IsNodeServer {
topology, err = util.GetTopologyFromDomainLabels(conf.DomainLabels, conf.NodeID, conf.DriverName)
Expand All @@ -187,7 +187,7 @@ func (fs *cephfsDriver) Run(conf *util.Config) {
conf.KernelMountOptions, conf.FuseMountOptions,
nodeLabels, topology, crushLocationMap,
)
fs.cs = NewControllerServer(fs.cd)
fs.cs = NewControllerServer(fs.cd, "")
}

// configure CSI-Addons server and components
Expand All @@ -201,7 +201,7 @@ func (fs *cephfsDriver) Run(conf *util.Config) {
IS: fs.is,
CS: fs.cs,
NS: fs.ns,
GS: fs.cs,
GS: csicommon.ToGroupControllerServer(fs.cs),
Comment thread
nixpanic marked this conversation as resolved.
}
server.Start(conf.Endpoint, srv, csicommon.MiddlewareServerOptionConfig{
LogSlowOpInterval: conf.LogSlowOpInterval,
Expand Down
6 changes: 3 additions & 3 deletions internal/cephfs/fuserecovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (ms mountState) String() string {
}[int(ms)]
}

func (ns *NodeServer) getMountState(path string) (mountState, error) {
func (ns *cephfsNodeServer) getMountState(path string) (mountState, error) {
isMnt, err := ns.Mounter.IsMountPoint(path)
if err != nil {
if util.IsCorruptedMountError(err) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (ns *NodeServer) getMountState(path string) (mountState, error) {
// * staging target path is unmounted and mounted again using ceph-fuse,
// * target path is only unmounted; NodePublishVolume is then expected to
// continue normally.
func (ns *NodeServer) tryRestoreFuseMountsInNodePublish(
func (ns *cephfsNodeServer) tryRestoreFuseMountsInNodePublish(
ctx context.Context,
volID fsutil.VolumeID,
stagingTargetPath string,
Expand Down Expand Up @@ -174,7 +174,7 @@ func (ns *NodeServer) tryRestoreFuseMountsInNodePublish(
// Try to restore FUSE mount of the staging target path in NodeStageVolume.
// If corruption is detected, try to only unmount the volume. NodeStageVolume
// should be able to continue with mounting the volume normally afterwards.
func (ns *NodeServer) tryRestoreFuseMountInNodeStage(
func (ns *cephfsNodeServer) tryRestoreFuseMountInNodeStage(
ctx context.Context,
stagingTargetPath string,
) error {
Expand Down
18 changes: 9 additions & 9 deletions internal/cephfs/groupcontrollerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (

// validateCreateVolumeGroupSnapshotRequest validates the request for creating
// a group snapshot of volumes.
func (cs *ControllerServer) validateCreateVolumeGroupSnapshotRequest(
func (cs *cephfsControllerServer) validateCreateVolumeGroupSnapshotRequest(
ctx context.Context,
req *csi.CreateVolumeGroupSnapshotRequest,
) error {
Expand Down Expand Up @@ -74,7 +74,7 @@ func (cs *ControllerServer) validateCreateVolumeGroupSnapshotRequest(
}

// CreateVolumeGroupSnapshot creates a group snapshot of volumes.
func (cs *ControllerServer) CreateVolumeGroupSnapshot(
func (cs *cephfsControllerServer) CreateVolumeGroupSnapshot(
ctx context.Context,
req *csi.CreateVolumeGroupSnapshotRequest) (
*csi.CreateVolumeGroupSnapshotResponse,
Expand Down Expand Up @@ -188,7 +188,7 @@ func (cs *ControllerServer) CreateVolumeGroupSnapshot(
// queisceFileSystems quiesces the subvolumes and subvolume groups present in
// the filesystems of the volumeID's present in the
// CreateVolumeGroupSnapshotRequest.
func (cs *ControllerServer) queisceFileSystems(ctx context.Context,
func (cs *cephfsControllerServer) queisceFileSystems(ctx context.Context,
vgs *store.VolumeGroupSnapshotIdentifier,
fsMap core.FSQuiesceClientMap,
) (bool, error) {
Expand All @@ -215,7 +215,7 @@ func (cs *ControllerServer) queisceFileSystems(ctx context.Context,
// releaseQuiesceAndGetVolumeGroupSnapshotResponse releases the quiesce of the
// subvolumes and subvolume groups in the filesystems for the volumeID's
// present in the CreateVolumeGroupSnapshotRequest.
func (cs *ControllerServer) releaseQuiesceAndGetVolumeGroupSnapshotResponse(
func (cs *cephfsControllerServer) releaseQuiesceAndGetVolumeGroupSnapshotResponse(
ctx context.Context,
req *csi.CreateVolumeGroupSnapshotRequest,
vgs *store.VolumeGroupSnapshotIdentifier,
Expand Down Expand Up @@ -306,7 +306,7 @@ func (cs *ControllerServer) releaseQuiesceAndGetVolumeGroupSnapshotResponse(
// volume and add the snapshotID and volumeID to the volume group journal omap.
// If any error occurs other than ErrInProgress it will delete the snapshots
// and undo the reservation and return the error.
func (cs *ControllerServer) createSnapshotAddToVolumeGroupJournal(
func (cs *cephfsControllerServer) createSnapshotAddToVolumeGroupJournal(
ctx context.Context,
req *csi.CreateVolumeGroupSnapshotRequest,
vgo *store.VolumeGroupOptions,
Expand Down Expand Up @@ -439,7 +439,7 @@ func fsQuiesceWithExpireTimeout(ctx context.Context,
// createSnapshotAndAddMapping creates the snapshot and adds the snapshotID and
// volumeID to the volume group journal omap. If any error occurs it will
// delete the last created snapshot as its still not added to the journal.
func (cs *ControllerServer) createSnapshotAndAddMapping(
func (cs *cephfsControllerServer) createSnapshotAndAddMapping(
ctx context.Context,
req *csi.CreateSnapshotRequest,
vgo *store.VolumeGroupOptions,
Expand Down Expand Up @@ -612,7 +612,7 @@ func matchesSourceVolumeIDs(sourceVolumeIDs, volumeIDsInOMap []string) bool {
// when fsMap is empty function will skip filesystem quiesce operations and
// only perform snapshot deletion and reservation cleanup. This is the intended
// behavior for DeleteVolumeGroupSnapshot operation where filesystem quiesce is not required.
func (cs *ControllerServer) deleteSnapshotsAndUndoReservation(ctx context.Context,
func (cs *cephfsControllerServer) deleteSnapshotsAndUndoReservation(ctx context.Context,
vgs *store.VolumeGroupSnapshotIdentifier,
cr *util.Credentials,
fsMap core.FSQuiesceClientMap,
Expand Down Expand Up @@ -679,7 +679,7 @@ func (cs *ControllerServer) deleteSnapshotsAndUndoReservation(ctx context.Contex

// validateVolumeGroupSnapshotDeleteRequest validates the request for creating a group
// snapshot of volumes.
func (cs *ControllerServer) validateVolumeGroupSnapshotDeleteRequest(
func (cs *cephfsControllerServer) validateVolumeGroupSnapshotDeleteRequest(
ctx context.Context,
req *csi.DeleteVolumeGroupSnapshotRequest,
) error {
Expand All @@ -699,7 +699,7 @@ func (cs *ControllerServer) validateVolumeGroupSnapshotDeleteRequest(
}

// DeleteVolumeGroupSnapshot deletes a group snapshot of volumes.
func (cs *ControllerServer) DeleteVolumeGroupSnapshot(ctx context.Context,
func (cs *cephfsControllerServer) DeleteVolumeGroupSnapshot(ctx context.Context,
req *csi.DeleteVolumeGroupSnapshotRequest) (
*csi.DeleteVolumeGroupSnapshotResponse,
error,
Expand Down
2 changes: 1 addition & 1 deletion internal/cephfs/groupcontrollerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

func TestControllerServer_validateCreateVolumeGroupSnapshotRequest(t *testing.T) {
t.Parallel()
cs := ControllerServer{
cs := cephfsControllerServer{
DefaultControllerServer: csicommon.NewDefaultControllerServer(
csicommon.NewCSIDriver("cephfs.csi.ceph.com", "1.0.0", "test", "default", false)),
}
Expand Down
Loading