From 4d11490a2b6d9a466aa5da5656c15bfdbb18e0fe Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 16 Jun 2020 12:59:20 +0530 Subject: [PATCH] cephfs: Add support for ROX PVC cephcsi need to add mount the cephfs subvolume as the readonly when the PVC type is ROX to provide only readonly access to the users Signed-off-by: Madhu Rajanna --- internal/cephfs/nodeserver.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/cephfs/nodeserver.go b/internal/cephfs/nodeserver.go index 57d641534..9d734f504 100644 --- a/internal/cephfs/nodeserver.go +++ b/internal/cephfs/nodeserver.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "os" + "strings" csicommon "github.com/ceph/ceph-csi/internal/csi-common" "github.com/ceph/ceph-csi/internal/util" @@ -150,6 +151,21 @@ func (*NodeServer) mount(ctx context.Context, volOptions *volumeOptions, req *cs klog.V(4).Infof(util.Log(ctx, "cephfs: mounting volume %s with %s"), volID, m.name()) + if req.VolumeCapability.AccessMode.Mode == csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY || + req.VolumeCapability.AccessMode.Mode == csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY { + readOnly := "ro" + switch m.(type) { + case *fuseMounter: + if !csicommon.MountOptionContains(strings.Split(volOptions.FuseMountOptions, ","), readOnly) { + volOptions.FuseMountOptions = util.MountOptionsAdd(volOptions.FuseMountOptions, readOnly) + } + case *kernelMounter: + if !csicommon.MountOptionContains(strings.Split(volOptions.KernelMountOptions, ","), readOnly) { + volOptions.KernelMountOptions = util.MountOptionsAdd(volOptions.KernelMountOptions, readOnly) + } + } + } + if err = m.mount(ctx, stagingTargetPath, cr, volOptions); err != nil { klog.Errorf(util.Log(ctx, "failed to mount volume %s: %v Check dmesg logs if required."),