From 8cb10ebc7e4a276683b4c83a5f2df62f8ed93f45 Mon Sep 17 00:00:00 2001 From: Hou Junjie Date: Fri, 23 Jul 2021 18:39:29 +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 | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 43acce5126a8..4affc52b8cd4 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 constains + 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 4f43ce99deff..48605a5c916e 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 e4fb269c9d90..4bf772e3fe8f 100644 --- a/internal/rbd/nodeserver.go +++ b/internal/rbd/nodeserver.go @@ -117,6 +117,8 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol return nil, err } + readonly := req.GetPublishContext()["readonly"] == "true" + isBlock := req.GetVolumeCapability().GetBlock() != nil disableInUseChecks := false // MULTI_NODE_MULTI_WRITER is supported by default for Block access type volumes @@ -126,7 +128,8 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol return nil, status.Error(codes.InvalidArgument, "rbd: RWX access mode request is only valid for volumes with access type `block`") } - disableInUseChecks = true + // todo: if some of the watchers is r/w, we can not tell the differences + disableInUseChecks = readonly } volID := req.GetVolumeId()