mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 14:20:19 +00:00
cephfs: cache available volume mounters
This commit is contained in:
parent
c515a013d3
commit
6ddf98addf
@ -82,6 +82,10 @@ func (fs *cephfsDriver) Run(driverName, nodeId, endpoint, volumeMounter string)
|
|||||||
glog.Errorf("cephfs: failed to read volume cache: %v", err)
|
glog.Errorf("cephfs: failed to read volume cache: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := loadAvailableMounters(); err != nil {
|
||||||
|
glog.Fatalf("cephfs: failed to load ceph mounters: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if volumeMounter != "" {
|
if volumeMounter != "" {
|
||||||
if err := validateMounter(volumeMounter); err != nil {
|
if err := validateMounter(volumeMounter); err != nil {
|
||||||
glog.Fatalln(err)
|
glog.Fatalln(err)
|
||||||
@ -89,11 +93,9 @@ func (fs *cephfsDriver) Run(driverName, nodeId, endpoint, volumeMounter string)
|
|||||||
DefaultVolumeMounter = volumeMounter
|
DefaultVolumeMounter = volumeMounter
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
availableMounters := getAvailableMounters()
|
// Pick the first available mounter as the default one.
|
||||||
if len(availableMounters) == 0 {
|
// The choice is biased towards "fuse" in case both
|
||||||
glog.Fatal("no ceph mounters found on system")
|
// ceph fuse and kernel mounters are available.
|
||||||
}
|
|
||||||
|
|
||||||
DefaultVolumeMounter = availableMounters[0]
|
DefaultVolumeMounter = availableMounters[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +28,74 @@ const (
|
|||||||
volumeMounter_kernel = "kernel"
|
volumeMounter_kernel = "kernel"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
availableMounters []string
|
||||||
|
)
|
||||||
|
|
||||||
|
// Load available ceph mounters installed on system into availableMounters
|
||||||
|
// Called from driver.go's Run()
|
||||||
|
func loadAvailableMounters() error {
|
||||||
|
fuseMounterProbe := exec.Command("ceph-fuse", "--version")
|
||||||
|
kernelMounterProbe := exec.Command("mount.ceph")
|
||||||
|
|
||||||
|
if fuseMounterProbe.Run() == nil {
|
||||||
|
availableMounters = append(availableMounters, volumeMounter_fuse)
|
||||||
|
}
|
||||||
|
|
||||||
|
if kernelMounterProbe.Run() == nil {
|
||||||
|
availableMounters = append(availableMounters, volumeMounter_kernel)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(availableMounters) == 0 {
|
||||||
|
return fmt.Errorf("no ceph mounters found on system")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type volumeMounter interface {
|
type volumeMounter interface {
|
||||||
mount(mountPoint string, cr *credentials, volOptions *volumeOptions, volId volumeID) error
|
mount(mountPoint string, cr *credentials, volOptions *volumeOptions, volId volumeID) error
|
||||||
name() string
|
name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newMounter(volOptions *volumeOptions) (volumeMounter, error) {
|
||||||
|
// Get the mounter from the configuration
|
||||||
|
|
||||||
|
wantMounter := volOptions.Mounter
|
||||||
|
|
||||||
|
if wantMounter == "" {
|
||||||
|
wantMounter = DefaultVolumeMounter
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that it's available
|
||||||
|
|
||||||
|
var chosenMounter string
|
||||||
|
|
||||||
|
for _, availMounter := range availableMounters {
|
||||||
|
if chosenMounter == "" {
|
||||||
|
if availMounter == wantMounter {
|
||||||
|
chosenMounter = wantMounter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if chosenMounter == "" {
|
||||||
|
// Otherwise pick whatever is left
|
||||||
|
chosenMounter = availableMounters[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the mounter
|
||||||
|
|
||||||
|
switch chosenMounter {
|
||||||
|
case volumeMounter_fuse:
|
||||||
|
return &fuseMounter{}, nil
|
||||||
|
case volumeMounter_kernel:
|
||||||
|
return &kernelMounter{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("unknown mounter '%s'", chosenMounter)
|
||||||
|
}
|
||||||
|
|
||||||
type fuseMounter struct{}
|
type fuseMounter struct{}
|
||||||
|
|
||||||
func mountFuse(mountPoint string, cr *credentials, volOptions *volumeOptions, volId volumeID) error {
|
func mountFuse(mountPoint string, cr *credentials, volOptions *volumeOptions, volId volumeID) error {
|
||||||
@ -114,63 +177,3 @@ func unmountVolume(mountPoint string) error {
|
|||||||
func createMountPoint(root string) error {
|
func createMountPoint(root string) error {
|
||||||
return os.MkdirAll(root, 0750)
|
return os.MkdirAll(root, 0750)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAvailableMounters() []string {
|
|
||||||
var ms []string
|
|
||||||
|
|
||||||
fuseMounterProbe := exec.Command("ceph-fuse", "--version")
|
|
||||||
kernelMounterProbe := exec.Command("mount.ceph")
|
|
||||||
|
|
||||||
if fuseMounterProbe.Run() == nil {
|
|
||||||
ms = append(ms, volumeMounter_fuse)
|
|
||||||
}
|
|
||||||
|
|
||||||
if kernelMounterProbe.Run() == nil {
|
|
||||||
ms = append(ms, volumeMounter_kernel)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ms
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMounter(volOptions *volumeOptions) (volumeMounter, error) {
|
|
||||||
// Get the mounter from the configuration
|
|
||||||
|
|
||||||
wantMounter := volOptions.Mounter
|
|
||||||
|
|
||||||
if wantMounter == "" {
|
|
||||||
wantMounter = DefaultVolumeMounter
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify that it's available
|
|
||||||
|
|
||||||
availableMounters := getAvailableMounters()
|
|
||||||
if len(availableMounters) == 0 {
|
|
||||||
return nil, fmt.Errorf("no ceph mounters found on system")
|
|
||||||
}
|
|
||||||
|
|
||||||
var chosenMounter string
|
|
||||||
|
|
||||||
for _, availMounter := range getAvailableMounters() {
|
|
||||||
if chosenMounter == "" {
|
|
||||||
if availMounter == wantMounter {
|
|
||||||
chosenMounter = wantMounter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if chosenMounter == "" {
|
|
||||||
// Otherwise pick whatever is left
|
|
||||||
chosenMounter = availableMounters[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the mounter
|
|
||||||
|
|
||||||
switch chosenMounter {
|
|
||||||
case volumeMounter_fuse:
|
|
||||||
return &fuseMounter{}, nil
|
|
||||||
case volumeMounter_kernel:
|
|
||||||
return &kernelMounter{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("unknown mounter '%s'", chosenMounter)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user