mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-27 08:40:23 +00:00
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 <prasanna.kalever@redhat.com>
(cherry picked from commit e53fd87154
)
This commit is contained in:
parent
2673a0b97a
commit
6894b4b910
@ -192,7 +192,8 @@ type migrationVolID struct {
|
|||||||
clusterID string
|
clusterID string
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportedFeatures = map[string]imageFeature{
|
var (
|
||||||
|
supportedFeatures = map[string]imageFeature{
|
||||||
librbd.FeatureNameLayering: {
|
librbd.FeatureNameLayering: {
|
||||||
needRbdNbd: false,
|
needRbdNbd: false,
|
||||||
},
|
},
|
||||||
@ -216,6 +217,60 @@ var supportedFeatures = map[string]imageFeature{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// GetKrbdSupportedFeatures load the module if needed and return supported
|
||||||
// features attribute as a string.
|
// features attribute as a string.
|
||||||
func GetKrbdSupportedFeatures() (string, error) {
|
func GetKrbdSupportedFeatures() (string, error) {
|
||||||
@ -238,10 +293,20 @@ func GetKrbdSupportedFeatures() (string, error) {
|
|||||||
}
|
}
|
||||||
val, err := os.ReadFile(krbdSupportedFeaturesFile)
|
val, err := os.ReadFile(krbdSupportedFeaturesFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
log.ErrorLogMsg("reading file %q failed: %v", krbdSupportedFeaturesFile, err)
|
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
|
return strings.TrimSuffix(string(val), "\n"), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user