From c65c29880be840198875307d0af0429b9ec3f13f Mon Sep 17 00:00:00 2001 From: Hou Junjie Date: Fri, 16 Jul 2021 15:52:26 +0800 Subject: [PATCH] fix: do not check watchers if staging rbd on node read only --- internal/rbd/controllerserver.go | 15 +++++++++++++++ internal/rbd/driver.go | 2 ++ internal/rbd/nodeserver.go | 2 +- internal/util/validate.go | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 43acce5126a..10e86e85218 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -1123,3 +1123,18 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi NodeExpansionRequired: nodeExpansion, }, nil } + +// ControllerPublishVolume collects information useful for NodeStageVolume to tell if the volume is expected to be mounted readonly. +func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) { + ro := "false" + if req.GetReadonly() { + ro = "true" + } + // todo: check rwo and rox constrains + return &csi.ControllerPublishVolumeResponse{PublishContext: map[string]string{"readonly": ro}}, nil +} + +// ControllerUnpublishVolume does nothing. +func (cs *ControllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { + return &csi.ControllerUnpublishVolumeResponse{}, nil +} diff --git a/internal/rbd/driver.go b/internal/rbd/driver.go index 4f43ce99def..48605a5c916 100644 --- a/internal/rbd/driver.go +++ b/internal/rbd/driver.go @@ -133,6 +133,8 @@ func (r *Driver) Run(conf *util.Config) { csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT, csi.ControllerServiceCapability_RPC_CLONE_VOLUME, csi.ControllerServiceCapability_RPC_EXPAND_VOLUME, + csi.ControllerServiceCapability_RPC_PUBLISH_READONLY, + csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME, }) // We only support the multi-writer option when using block, but it's a supported capability for the plugin in general // In addition, we want to add the remaining modes like MULTI_NODE_READER_ONLY, diff --git a/internal/rbd/nodeserver.go b/internal/rbd/nodeserver.go index e4fb269c9d9..f3edd88df4b 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -117,8 +117,8 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol return nil, err } + disableInUseChecks := req.GetPublishContext()["readonly"] == "true" isBlock := req.GetVolumeCapability().GetBlock() != nil - disableInUseChecks := false // MULTI_NODE_MULTI_WRITER is supported by default for Block access type volumes if req.VolumeCapability.AccessMode.Mode == csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER { if !isBlock { diff --git a/internal/util/validate.go b/internal/util/validate.go index e45116aca55..98101a00d38 100644 --- a/internal/util/validate.go +++ b/internal/util/validate.go @@ -90,7 +90,7 @@ func CheckReadOnlyManyIsSupported(req *csi.CreateVolumeRequest) error { writable = true } } - if ! writable && req.GetVolumeContentSource() == nil { + if !writable && req.GetVolumeContentSource() == nil { return status.Error(codes.InvalidArgument, "readOnly accessMode is supported only with content source") } return nil