mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-09 16:00:22 +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)
|
||||
}
|
||||
|
||||
if err := loadAvailableMounters(); err != nil {
|
||||
glog.Fatalf("cephfs: failed to load ceph mounters: %v", err)
|
||||
}
|
||||
|
||||
if volumeMounter != "" {
|
||||
if err := validateMounter(volumeMounter); err != nil {
|
||||
glog.Fatalln(err)
|
||||
@ -89,11 +93,9 @@ func (fs *cephfsDriver) Run(driverName, nodeId, endpoint, volumeMounter string)
|
||||
DefaultVolumeMounter = volumeMounter
|
||||
}
|
||||
} else {
|
||||
availableMounters := getAvailableMounters()
|
||||
if len(availableMounters) == 0 {
|
||||
glog.Fatal("no ceph mounters found on system")
|
||||
}
|
||||
|
||||
// Pick the first available mounter as the default one.
|
||||
// The choice is biased towards "fuse" in case both
|
||||
// ceph fuse and kernel mounters are available.
|
||||
DefaultVolumeMounter = availableMounters[0]
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,74 @@ const (
|
||||
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 {
|
||||
mount(mountPoint string, cr *credentials, volOptions *volumeOptions, volId volumeID) error
|
||||
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{}
|
||||
|
||||
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 {
|
||||
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