2018-03-05 11:59:47 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 The Kubernetes 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 cephfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2018-03-09 16:05:19 +00:00
|
|
|
)
|
|
|
|
|
2018-03-22 13:01:10 +00:00
|
|
|
const (
|
|
|
|
volumeMounter_fuse = "fuse"
|
|
|
|
volumeMounter_kernel = "kernel"
|
|
|
|
)
|
|
|
|
|
|
|
|
type volumeMounter interface {
|
|
|
|
mount(mountPoint string, volOptions *volumeOptions) error
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 13:01:10 +00:00
|
|
|
type fuseMounter struct{}
|
|
|
|
|
2018-03-26 13:00:28 +00:00
|
|
|
func execCommandAndValidate(program string, args ...string) error {
|
|
|
|
out, err := execCommand(program, args...)
|
2018-03-09 16:05:19 +00:00
|
|
|
if err != nil {
|
2018-03-26 13:00:28 +00:00
|
|
|
return fmt.Errorf("cephfs: %s failed with following error: %s\ncephfs: %s output: %s", program, err, program, out)
|
2018-03-09 16:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 13:00:28 +00:00
|
|
|
func (m *fuseMounter) mount(mountPoint string, volOptions *volumeOptions) error {
|
|
|
|
return execCommandAndValidate("ceph-fuse", mountPoint, "-n", "client."+volOptions.User, "-r", volOptions.RootPath)
|
|
|
|
}
|
|
|
|
|
2018-03-22 13:01:10 +00:00
|
|
|
type kernelMounter struct{}
|
|
|
|
|
|
|
|
func (m *kernelMounter) mount(mountPoint string, volOptions *volumeOptions) error {
|
2018-03-26 13:00:28 +00:00
|
|
|
if err := execCommandAndValidate("modprobe", "ceph"); err != nil {
|
|
|
|
return err
|
2018-03-22 13:01:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 13:00:28 +00:00
|
|
|
return execCommandAndValidate("mount",
|
2018-03-22 13:01:10 +00:00
|
|
|
"-t", "ceph",
|
|
|
|
fmt.Sprintf("%s:%s", volOptions.Monitors, volOptions.RootPath),
|
|
|
|
mountPoint,
|
|
|
|
"-o",
|
|
|
|
fmt.Sprintf("name=%s,secretfile=%s", volOptions.User, getCephSecretPath(volOptions.User)),
|
2018-03-26 13:00:28 +00:00
|
|
|
)
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-22 13:01:10 +00:00
|
|
|
func unmountVolume(mountPoint string) error {
|
2018-03-26 13:00:28 +00:00
|
|
|
return execCommandAndValidate("umount", mountPoint)
|
2018-03-05 11:59:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 16:05:19 +00:00
|
|
|
func createMountPoint(root string) error {
|
|
|
|
return os.MkdirAll(root, 0750)
|
|
|
|
}
|