From 881f59d142d4143ef05ec514bfcac3c8fe12d4e8 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 23 Jan 2020 13:54:46 +0530 Subject: [PATCH] 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 --- pkg/cephfs/nodeserver.go | 20 ++------------------ pkg/cephfs/volumemounter.go | 7 +++++++ pkg/csi-common/nodeserver-default.go | 20 ++++++++++++++++++++ pkg/rbd/nodeserver.go | 15 +++++++++------ 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/pkg/cephfs/nodeserver.go b/pkg/cephfs/nodeserver.go index 4abcb6754..d3aa7cba5 100644 --- a/pkg/cephfs/nodeserver.go +++ b/pkg/cephfs/nodeserver.go @@ -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 // path 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 { 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()) } - 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) - } - } - } + mountOptions = csicommon.ConstructMountOptions(mountOptions, req.GetVolumeCapability()) // Check if the volume is already mounted diff --git a/pkg/cephfs/volumemounter.go b/pkg/cephfs/volumemounter.go index a78ae6282..3f86375fa 100644 --- a/pkg/cephfs/volumemounter.go +++ b/pkg/cephfs/volumemounter.go @@ -36,6 +36,7 @@ import ( const ( volumeMounterFuse = "fuse" volumeMounterKernel = "kernel" + netDev = "_netdev" ) var ( @@ -229,6 +230,7 @@ func mountFuse(ctx context.Context, mountPoint string, cr *util.Credentials, vol if volOptions.FuseMountOptions != "" { args = append(args, ","+volOptions.FuseMountOptions) } + if 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 != "" { optionsStr += fmt.Sprintf(",%s", volOptions.KernelMountOptions) } + + if !strings.Contains(volOptions.KernelMountOptions, netDev) { + optionsStr += fmt.Sprintf(",%s", netDev) + } + args = append(args, "-o", optionsStr) return execCommandErr(ctx, "mount", args[:]...) diff --git a/pkg/csi-common/nodeserver-default.go b/pkg/csi-common/nodeserver-default.go index 1680d6a7a..0ebbbf9aa 100644 --- a/pkg/csi-common/nodeserver-default.go +++ b/pkg/csi-common/nodeserver-default.go @@ -170,3 +170,23 @@ func (ns *DefaultNodeServer) NodeGetVolumeStats(ctx context.Context, req *csi.No }, }, 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 +} diff --git a/pkg/rbd/nodeserver.go b/pkg/rbd/nodeserver.go index 4ca602e4f..a866b0f48 100644 --- a/pkg/rbd/nodeserver.go +++ b/pkg/rbd/nodeserver.go @@ -331,7 +331,7 @@ func (ns *NodeServer) mountVolumeToStagePath(ctx context.Context, req *csi.NodeS } } - opt := []string{} + opt := []string{"_netdev"} isBlock := req.GetVolumeCapability().GetBlock() != nil if isBlock { @@ -350,16 +350,19 @@ func (ns *NodeServer) mountVolume(ctx context.Context, stagingPath string, req * // Publish Path fsType := req.GetVolumeCapability().GetMount().GetFsType() readOnly := req.GetReadonly() - mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags() + mountOptions := []string{"bind", "_netdev"} isBlock := req.GetVolumeCapability().GetBlock() != nil 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"), - targetPath, isBlock, fsType, stagingPath, readOnly, mountFlags) - mountFlags = append(mountFlags, "bind") + targetPath, isBlock, fsType, stagingPath, readOnly, mountOptions) + 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()) }