From 6894b4b91015b68568cfbe06c346927bedc3ce84 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Fri, 6 May 2022 19:03:25 +0530 Subject: [PATCH] rbd: prepare krbd feature attrs if supported_features file is absent Upstream /sys/bus/rbd/supported_features is part of Linux kernel v4.11.0 Prepare the attributes and use them in case if /sys/bus/rbd/supported_features is missing. Signed-off-by: Prasanna Kumar Kalever (cherry picked from commit e53fd8715422dc436d61e1fae09c8370aaa650ce) --- internal/rbd/rbd_util.go | 113 ++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 24 deletions(-) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 7c6360839..bc9c16735 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -192,28 +192,83 @@ type migrationVolID struct { clusterID string } -var supportedFeatures = map[string]imageFeature{ - librbd.FeatureNameLayering: { - needRbdNbd: false, - }, - librbd.FeatureNameExclusiveLock: { - needRbdNbd: false, - }, - librbd.FeatureNameObjectMap: { - needRbdNbd: false, - dependsOn: []string{librbd.FeatureNameExclusiveLock}, - }, - librbd.FeatureNameFastDiff: { - needRbdNbd: false, - dependsOn: []string{librbd.FeatureNameObjectMap}, - }, - librbd.FeatureNameJournaling: { - needRbdNbd: true, - dependsOn: []string{librbd.FeatureNameExclusiveLock}, - }, - librbd.FeatureNameDeepFlatten: { - needRbdNbd: false, - }, +var ( + supportedFeatures = map[string]imageFeature{ + librbd.FeatureNameLayering: { + needRbdNbd: false, + }, + librbd.FeatureNameExclusiveLock: { + needRbdNbd: false, + }, + librbd.FeatureNameObjectMap: { + needRbdNbd: false, + dependsOn: []string{librbd.FeatureNameExclusiveLock}, + }, + librbd.FeatureNameFastDiff: { + needRbdNbd: false, + dependsOn: []string{librbd.FeatureNameObjectMap}, + }, + librbd.FeatureNameJournaling: { + needRbdNbd: true, + dependsOn: []string{librbd.FeatureNameExclusiveLock}, + }, + librbd.FeatureNameDeepFlatten: { + needRbdNbd: false, + }, + } + + krbdLayeringSupport = []util.KernelVersion{ + { + Version: 3, + PatchLevel: 8, + SubLevel: 0, + }, + } + krbdStripingV2Support = []util.KernelVersion{ + { + Version: 3, + PatchLevel: 10, + SubLevel: 0, + }, + } + krbdExclusiveLockSupport = []util.KernelVersion{ + { + Version: 4, + PatchLevel: 9, + SubLevel: 0, + }, + } + krbdDataPoolSupport = []util.KernelVersion{ + { + Version: 4, + PatchLevel: 11, + SubLevel: 0, + }, + } +) + +// prepareKrbdFeatureAttrs prepare krbd fearure set based on kernel version. +// Minimum kernel version should be 3.8, else it will return error. +func prepareKrbdFeatureAttrs() (uint64, error) { + // fetch the current running kernel info + release, err := util.GetKernelVersion() + if err != nil { + return 0, fmt.Errorf("fetching current kernel version failed: %w", err) + } + + switch { + case util.CheckKernelSupport(release, krbdDataPoolSupport): + return librbd.FeatureDataPool, nil + case util.CheckKernelSupport(release, krbdExclusiveLockSupport): + return librbd.FeatureExclusiveLock, nil + case util.CheckKernelSupport(release, krbdStripingV2Support): + return librbd.FeatureStripingV2, nil + case util.CheckKernelSupport(release, krbdLayeringSupport): + return librbd.FeatureLayering, nil + } + log.ErrorLogMsg("kernel version is too old: %q", release) + + return 0, os.ErrNotExist } // GetKrbdSupportedFeatures load the module if needed and return supported @@ -238,9 +293,19 @@ func GetKrbdSupportedFeatures() (string, error) { } val, err := os.ReadFile(krbdSupportedFeaturesFile) if err != nil { - log.ErrorLogMsg("reading file %q failed: %v", krbdSupportedFeaturesFile, err) + if !errors.Is(err, os.ErrNotExist) { + log.ErrorLogMsg("reading file %q failed: %v", krbdSupportedFeaturesFile, err) - return "", err + return "", err + } + attrs, err := prepareKrbdFeatureAttrs() + if err != nil { + log.ErrorLogMsg("preparing krbd feature attributes failed, %v", err) + + return "", err + } + + return strconv.FormatUint(attrs, 16), nil } return strings.TrimSuffix(string(val), "\n"), nil