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."),