mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-29 17:50:23 +00:00
Merge pull request #409 from humblec/mount-options
Add mount options support in CephFS CSI driver
This commit is contained in:
commit
883ccd1bb1
@ -34,3 +34,5 @@ parameters:
|
|||||||
# --volumemounter command-line argument.
|
# --volumemounter command-line argument.
|
||||||
# mounter: kernel
|
# mounter: kernel
|
||||||
reclaimPolicy: Delete
|
reclaimPolicy: Delete
|
||||||
|
mountOptions:
|
||||||
|
- noexec
|
||||||
|
@ -136,9 +136,11 @@ func mountOneCacheEntry(volOptions *volumeOptions, vid *volumeIdentifier, me *vo
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mountOptions := []string{"bind"}
|
||||||
for targetPath, readOnly := range me.TargetPaths {
|
for targetPath, readOnly := range me.TargetPaths {
|
||||||
if err := cleanupMountPoint(targetPath); err == nil {
|
if err := cleanupMountPoint(targetPath); err == nil {
|
||||||
if err := bindMount(me.StagingPath, targetPath, readOnly); err != nil {
|
if err := bindMount(me.StagingPath, targetPath, readOnly, mountOptions); err != nil {
|
||||||
klog.Errorf("mount-cache: failed to bind-mount volume %s: %s %s %v %v",
|
klog.Errorf("mount-cache: failed to bind-mount volume %s: %s %s %v %v",
|
||||||
volID, me.StagingPath, targetPath, readOnly, err)
|
volID, me.StagingPath, targetPath, readOnly, err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,6 +178,8 @@ func (*NodeServer) mount(volOptions *volumeOptions, req *csi.NodeStageVolumeRequ
|
|||||||
// NodePublishVolume mounts the volume mounted to the staging path to the target
|
// NodePublishVolume mounts the volume mounted to the staging path to the target
|
||||||
// path
|
// path
|
||||||
func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
|
func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
|
||||||
|
|
||||||
|
mountOptions := []string{"bind"}
|
||||||
if err := validateNodePublishVolumeRequest(req); err != nil {
|
if err := validateNodePublishVolumeRequest(req); err != nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||||
}
|
}
|
||||||
@ -192,6 +194,28 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
|||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volCap := req.GetVolumeCapability()
|
||||||
|
|
||||||
|
if req.GetReadonly() {
|
||||||
|
mountOptions = append(mountOptions, "ro")
|
||||||
|
}
|
||||||
|
|
||||||
|
if m := volCap.GetMount(); m != nil {
|
||||||
|
hasOption := func(options []string, opt string) bool {
|
||||||
|
for _, o := range options {
|
||||||
|
if o == opt {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, f := range m.MountFlags {
|
||||||
|
if !hasOption(mountOptions, f) {
|
||||||
|
mountOptions = append(mountOptions, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the volume is already mounted
|
// Check if the volume is already mounted
|
||||||
|
|
||||||
isMnt, err := isMountPoint(targetPath)
|
isMnt, err := isMountPoint(targetPath)
|
||||||
@ -208,7 +232,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
|
|||||||
|
|
||||||
// It's not, mount now
|
// It's not, mount now
|
||||||
|
|
||||||
if err = bindMount(req.GetStagingTargetPath(), req.GetTargetPath(), req.GetReadonly()); err != nil {
|
if err = bindMount(req.GetStagingTargetPath(), req.GetTargetPath(), req.GetReadonly(), mountOptions); err != nil {
|
||||||
klog.Errorf("failed to bind-mount volume %s: %v", volID, err)
|
klog.Errorf("failed to bind-mount volume %s: %v", volID, err)
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ceph/ceph-csi/pkg/util"
|
"github.com/ceph/ceph-csi/pkg/util"
|
||||||
@ -194,13 +195,15 @@ func (m *kernelMounter) mount(mountPoint string, cr *credentials, volOptions *vo
|
|||||||
|
|
||||||
func (m *kernelMounter) name() string { return "Ceph kernel client" }
|
func (m *kernelMounter) name() string { return "Ceph kernel client" }
|
||||||
|
|
||||||
func bindMount(from, to string, readOnly bool) error {
|
func bindMount(from, to string, readOnly bool, mntOptions []string) error {
|
||||||
if err := execCommandErr("mount", "--bind", from, to); err != nil {
|
mntOptionSli := strings.Join(mntOptions, ",")
|
||||||
|
if err := execCommandErr("mount", "-o", mntOptionSli, from, to); err != nil {
|
||||||
return fmt.Errorf("failed to bind-mount %s to %s: %v", from, to, err)
|
return fmt.Errorf("failed to bind-mount %s to %s: %v", from, to, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if readOnly {
|
if readOnly {
|
||||||
if err := execCommandErr("mount", "-o", "remount,ro,bind", to); err != nil {
|
mntOptionSli = mntOptionSli + ",remount"
|
||||||
|
if err := execCommandErr("mount", "-o", mntOptionSli, to); err != nil {
|
||||||
return fmt.Errorf("failed read-only remount of %s: %v", to, err)
|
return fmt.Errorf("failed read-only remount of %s: %v", to, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user