diff --git a/pkg/cephfs/driver.go b/pkg/cephfs/driver.go index c17b7f9cf46..6e2ece76220 100644 --- a/pkg/cephfs/driver.go +++ b/pkg/cephfs/driver.go @@ -50,9 +50,6 @@ type Driver struct { } var ( - // DefaultVolumeMounter for mounting volumes - DefaultVolumeMounter string - // CSIInstanceID is the instance ID that is unique to an instance of CSI, used when sharing // ceph clusters across CSI instances, to differentiate omap names per CSI instance CSIInstanceID = "default" @@ -103,18 +100,9 @@ func (fs *Driver) Run(conf *util.Config, cachePersister util.CachePersister) { if conf.VolumeMounter != "" { if err := validateMounter(conf.VolumeMounter); err != nil { klog.Fatalln(err) - } else { - DefaultVolumeMounter = conf.VolumeMounter } - } else { - // 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] } - klog.Infof("cephfs: setting default volume mounter to %s", DefaultVolumeMounter) - if err := util.WriteCephConfig(); err != nil { klog.Fatalf("failed to write ceph configuration file: %v", err) } diff --git a/pkg/cephfs/volumemounter.go b/pkg/cephfs/volumemounter.go index 7b656997cf6..36d86bb6751 100644 --- a/pkg/cephfs/volumemounter.go +++ b/pkg/cephfs/volumemounter.go @@ -55,12 +55,32 @@ func loadAvailableMounters() error { // #nosec kernelMounterProbe := exec.Command("mount.ceph") - if fuseMounterProbe.Run() == nil { - availableMounters = append(availableMounters, volumeMounterFuse) + err := kernelMounterProbe.Run() + if err == nil { + kernelVersion, _, err := execCommand(context.TODO(), "uname", "-r") + if err != nil { + return err + } + vers := strings.Split(string(kernelVersion), ".") + majorVers, err := strconv.Atoi(vers[0]) + if err != nil { + return err + } + minorVers, err := strconv.Atoi(vers[1]) + if err != nil { + return err + } + if majorVers >= 4 && minorVers >= 17 { + klog.Infof("loaded mounter: %s", volumeMounterKernel) + availableMounters = append(availableMounters, volumeMounterKernel) + } else { + klog.Infof("kernel version < 4.17 might not support quota feature, hence not loading kernel client") + } } - if kernelMounterProbe.Run() == nil { - availableMounters = append(availableMounters, volumeMounterKernel) + if fuseMounterProbe.Run() == nil { + klog.Infof("loaded mounter: %s", volumeMounterFuse) + availableMounters = append(availableMounters, volumeMounterFuse) } if len(availableMounters) == 0 { @@ -80,25 +100,21 @@ func newMounter(volOptions *volumeOptions) (volumeMounter, error) { 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 availMounter == wantMounter { + chosenMounter = wantMounter + break } } if chosenMounter == "" { // Otherwise pick whatever is left chosenMounter = availableMounters[0] + klog.Infof("requested mounter: %s, chosen mounter: %s", wantMounter, chosenMounter) } // Create the mounter