mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
util: add function to get the kernel version
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
2dc0bffc0a
commit
209a5e5602
@ -29,7 +29,6 @@ import (
|
||||
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
@ -151,12 +150,10 @@ func loadAvailableMounters(conf *util.Config) error {
|
||||
klog.Errorf("failed to run mount.ceph %v", err)
|
||||
} else {
|
||||
// fetch the current running kernel info
|
||||
utsname := unix.Utsname{}
|
||||
err = unix.Uname(&utsname)
|
||||
if err != nil {
|
||||
return err
|
||||
release, kvErr := util.KernelVersion()
|
||||
if kvErr != nil {
|
||||
return kvErr
|
||||
}
|
||||
release := string(utsname.Release[:64])
|
||||
|
||||
if conf.ForceKernelCephFS || kernelSupportsQuota(release) {
|
||||
klog.V(1).Infof("loaded mounter: %s", volumeMounterKernel)
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
@ -139,6 +140,17 @@ func ValidateDriverName(driverName string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// KernelVersion returns the version of the running Unix (like) system from the
|
||||
// 'utsname' structs 'release' component.
|
||||
func KernelVersion() (string, error) {
|
||||
utsname := unix.Utsname{}
|
||||
err := unix.Uname(&utsname)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(utsname.Release[:]), nil
|
||||
}
|
||||
|
||||
// GenerateVolID generates a volume ID based on passed in parameters and version, to be returned
|
||||
// to the CO system
|
||||
func GenerateVolID(ctx context.Context, monitors string, cr *Credentials, locationID int64, pool, clusterID, objUUID string, volIDVersion uint16) (string, error) {
|
||||
|
@ -142,3 +142,13 @@ func TestRoundOffVolSize(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestKernelVersion(t *testing.T) {
|
||||
version, err := KernelVersion()
|
||||
if err != nil {
|
||||
t.Errorf("failed to get kernel version: %s", err)
|
||||
}
|
||||
if version == "" {
|
||||
t.Error("version is empty, this is unexpected?!")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user