mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-30 18:20:19 +00:00
e9802c4940
This commits refactors the cephfs core functions with interfaces. This helps in better code structuring and writing the unit test cases. update #852 Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
/*
|
|
Copyright 2021 The Ceph-CSI Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package mounter
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/ceph/ceph-csi/internal/cephfs/store"
|
|
"github.com/ceph/ceph-csi/internal/util"
|
|
)
|
|
|
|
const (
|
|
volumeMounterKernel = "kernel"
|
|
netDev = "_netdev"
|
|
)
|
|
|
|
type KernelMounter struct{}
|
|
|
|
func mountKernel(ctx context.Context, mountPoint string, cr *util.Credentials, volOptions *store.VolumeOptions) error {
|
|
if err := execCommandErr(ctx, "modprobe", "ceph"); err != nil {
|
|
return err
|
|
}
|
|
|
|
args := []string{
|
|
"-t", "ceph",
|
|
fmt.Sprintf("%s:%s", volOptions.Monitors, volOptions.RootPath),
|
|
mountPoint,
|
|
}
|
|
|
|
optionsStr := fmt.Sprintf("name=%s,secretfile=%s", cr.ID, cr.KeyFile)
|
|
mdsNamespace := ""
|
|
if volOptions.FsName != "" {
|
|
mdsNamespace = fmt.Sprintf("mds_namespace=%s", volOptions.FsName)
|
|
}
|
|
optionsStr = util.MountOptionsAdd(optionsStr, mdsNamespace, volOptions.KernelMountOptions, netDev)
|
|
|
|
args = append(args, "-o", optionsStr)
|
|
|
|
_, stderr, err := util.ExecCommand(ctx, "mount", args[:]...)
|
|
if err != nil {
|
|
return fmt.Errorf("%w stderr: %s", err, stderr)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func (m *KernelMounter) Mount(
|
|
ctx context.Context,
|
|
mountPoint string,
|
|
cr *util.Credentials,
|
|
volOptions *store.VolumeOptions) error {
|
|
if err := util.CreateMountPoint(mountPoint); err != nil {
|
|
return err
|
|
}
|
|
|
|
return mountKernel(ctx, mountPoint, cr, volOptions)
|
|
}
|
|
|
|
func (m *KernelMounter) Name() string { return "Ceph kernel client" }
|