rbd: export HexStringToInteger()

HexStringToInteger() used to return a uint64, but everywhere else uint
is used. Having HexStringToInteger() return a uint as well makes it a
little easier to use when setting it with SetGlobalInt().

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2021-12-09 09:16:32 +01:00 committed by mergify[bot]
parent 8b531f337e
commit 44d69502bc
2 changed files with 6 additions and 6 deletions

View File

@ -250,8 +250,8 @@ func GetKrbdSupportedFeatures() (string, error) {
return strings.TrimSuffix(string(val), "\n"), nil return strings.TrimSuffix(string(val), "\n"), nil
} }
// hexStringToInteger convert hex value to uint. // HexStringToInteger convert hex value to uint.
func hexStringToInteger(hexString string) (uint64, error) { func HexStringToInteger(hexString string) (uint, error) {
// trim 0x prefix // trim 0x prefix
numberStr := strings.TrimPrefix(strings.ToLower(hexString), "0x") numberStr := strings.TrimPrefix(strings.ToLower(hexString), "0x")
@ -262,7 +262,7 @@ func hexStringToInteger(hexString string) (uint64, error) {
return 0, err return 0, err
} }
return output, nil return uint(output), nil
} }
// isKrbdFeatureSupported checks if a given Image Feature is supported by krbd // isKrbdFeatureSupported checks if a given Image Feature is supported by krbd
@ -274,7 +274,7 @@ func isKrbdFeatureSupported(ctx context.Context, imageFeatures string) bool {
supported := true supported := true
for _, featureName := range imageFeatureSet.Names() { for _, featureName := range imageFeatureSet.Names() {
if (uint64(librbd.FeatureSetFromNames(strings.Split(featureName, " "))) & krbdFeatures) == 0 { if (uint(librbd.FeatureSetFromNames(strings.Split(featureName, " "))) & krbdFeatures) == 0 {
supported = false supported = false
log.ErrorLog(ctx, "krbd feature %q not supported", featureName) log.ErrorLog(ctx, "krbd feature %q not supported", featureName)

View File

@ -334,9 +334,9 @@ func TestIsKrbdFeatureSupported(t *testing.T) {
t.Parallel() t.Parallel()
var err error var err error
krbdSupportedFeaturesAttr := "0x1" krbdSupportedFeaturesAttr := "0x1"
krbdFeatures, err = hexStringToInteger(krbdSupportedFeaturesAttr) // initialize krbdFeatures krbdFeatures, err = HexStringToInteger(krbdSupportedFeaturesAttr) // initialize krbdFeatures
if err != nil { if err != nil {
t.Errorf("hexStringToInteger(%s) failed", krbdSupportedFeaturesAttr) t.Errorf("HexStringToInteger(%s) failed", krbdSupportedFeaturesAttr)
} }
supported := isKrbdFeatureSupported(ctx, tc.featureName) supported := isKrbdFeatureSupported(ctx, tc.featureName)
if supported != tc.isSupported { if supported != tc.isSupported {