mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-23 23:00:19 +00:00
Add _netdev as default mount options in plugin
This values will be added at both nodestage
and nodepublish for rbd, nbd and ceph kernel client.
As cephfs fuse doesnot support this value,
this is added only during the nodepublish.
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit 881f59d142
)
This commit is contained in:
parent
a1c5e6b250
commit
5a3d439137
@ -163,7 +163,7 @@ func (*NodeServer) mount(ctx context.Context, volOptions *volumeOptions, req *cs
|
|||||||
// 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"}
|
mountOptions := []string{"bind", "_netdev"}
|
||||||
if err := util.ValidateNodePublishVolumeRequest(req); err != nil {
|
if err := util.ValidateNodePublishVolumeRequest(req); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -182,27 +182,11 @@ 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() {
|
if req.GetReadonly() {
|
||||||
mountOptions = append(mountOptions, "ro")
|
mountOptions = append(mountOptions, "ro")
|
||||||
}
|
}
|
||||||
|
|
||||||
if m := volCap.GetMount(); m != nil {
|
mountOptions = csicommon.ConstructMountOptions(mountOptions, req.GetVolumeCapability())
|
||||||
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
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
volumeMounterFuse = "fuse"
|
volumeMounterFuse = "fuse"
|
||||||
volumeMounterKernel = "kernel"
|
volumeMounterKernel = "kernel"
|
||||||
|
netDev = "_netdev"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -229,6 +230,7 @@ func mountFuse(ctx context.Context, mountPoint string, cr *util.Credentials, vol
|
|||||||
if volOptions.FuseMountOptions != "" {
|
if volOptions.FuseMountOptions != "" {
|
||||||
args = append(args, ","+volOptions.FuseMountOptions)
|
args = append(args, ","+volOptions.FuseMountOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
if volOptions.FsName != "" {
|
if volOptions.FsName != "" {
|
||||||
args = append(args, "--client_mds_namespace="+volOptions.FsName)
|
args = append(args, "--client_mds_namespace="+volOptions.FsName)
|
||||||
}
|
}
|
||||||
@ -288,6 +290,11 @@ func mountKernel(ctx context.Context, mountPoint string, cr *util.Credentials, v
|
|||||||
if volOptions.KernelMountOptions != "" {
|
if volOptions.KernelMountOptions != "" {
|
||||||
optionsStr += fmt.Sprintf(",%s", volOptions.KernelMountOptions)
|
optionsStr += fmt.Sprintf(",%s", volOptions.KernelMountOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(volOptions.KernelMountOptions, netDev) {
|
||||||
|
optionsStr += fmt.Sprintf(",%s", netDev)
|
||||||
|
}
|
||||||
|
|
||||||
args = append(args, "-o", optionsStr)
|
args = append(args, "-o", optionsStr)
|
||||||
|
|
||||||
return execCommandErr(ctx, "mount", args[:]...)
|
return execCommandErr(ctx, "mount", args[:]...)
|
||||||
|
@ -170,3 +170,23 @@ func (ns *DefaultNodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.No
|
|||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConstructMountOptions returns only unique mount options in slice
|
||||||
|
func ConstructMountOptions(mountOptions []string, volCap *csi.VolumeCapability) []string {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mountOptions
|
||||||
|
}
|
||||||
|
@ -331,7 +331,7 @@ func (ns *NodeServer) mountVolumeToStagePath(ctx context.Context, req *csi.NodeS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opt := []string{}
|
opt := []string{"_netdev"}
|
||||||
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
||||||
|
|
||||||
if isBlock {
|
if isBlock {
|
||||||
@ -350,16 +350,19 @@ func (ns *NodeServer) mountVolume(ctx context.Context, stagingPath string, req *
|
|||||||
// Publish Path
|
// Publish Path
|
||||||
fsType := req.GetVolumeCapability().GetMount().GetFsType()
|
fsType := req.GetVolumeCapability().GetMount().GetFsType()
|
||||||
readOnly := req.GetReadonly()
|
readOnly := req.GetReadonly()
|
||||||
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
|
mountOptions := []string{"bind", "_netdev"}
|
||||||
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
||||||
targetPath := req.GetTargetPath()
|
targetPath := req.GetTargetPath()
|
||||||
|
|
||||||
|
mountOptions = csicommon.ConstructMountOptions(mountOptions, req.GetVolumeCapability())
|
||||||
|
|
||||||
klog.V(4).Infof(util.Log(ctx, "target %v\nisBlock %v\nfstype %v\nstagingPath %v\nreadonly %v\nmountflags %v\n"),
|
klog.V(4).Infof(util.Log(ctx, "target %v\nisBlock %v\nfstype %v\nstagingPath %v\nreadonly %v\nmountflags %v\n"),
|
||||||
targetPath, isBlock, fsType, stagingPath, readOnly, mountFlags)
|
targetPath, isBlock, fsType, stagingPath, readOnly, mountOptions)
|
||||||
mountFlags = append(mountFlags, "bind")
|
|
||||||
if readOnly {
|
if readOnly {
|
||||||
mountFlags = append(mountFlags, "ro")
|
mountOptions = append(mountOptions, "ro")
|
||||||
}
|
}
|
||||||
if err := util.Mount(stagingPath, targetPath, fsType, mountFlags); err != nil {
|
if err := util.Mount(stagingPath, targetPath, fsType, mountOptions); err != nil {
|
||||||
return status.Error(codes.Internal, err.Error())
|
return status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user