rbd: add MakeVolumeGroupID() utility function

The Manager.MakeVolumeGroupID() function can be used to build a CSI
VolumeGroupID from the backend (pool and name of the RBD-group). This
will be used when checking if an RBD-image belongs to a group already.
It is also possible to resolve the VolumeGroup by passing the
VolumeGroupID to the existing Manager.GetVolumeGroupByID() function.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos
2025-03-20 18:21:26 +01:00
committed by mergify[bot]
parent a8ee0fe304
commit 32285c8365
4 changed files with 151 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"
"github.com/ceph/ceph-csi/internal/util"
@ -166,6 +167,28 @@ func generateVolumeGroupName(namePrefix, groupUUID string) string {
return namePrefix + groupUUID
}
// MakeVolumeGroupID is a utility function that takes details of a VolumeGroup
// and creates the CSI VolumeGroupId out of those.
func MakeVolumeGroupID(clusterID string, poolID int64, name, prefix string) (string, error) {
namePrefix := prefix
if prefix == "" {
namePrefix = defaultVolumeGroupNamingPrefix
}
id, found := strings.CutPrefix(name, namePrefix)
if !found {
return "", fmt.Errorf("volume group name %q does not start with %q", name, namePrefix)
}
handle := util.CSIIdentifier{
ClusterID: clusterID,
LocationID: poolID,
ObjectUUID: id,
}
return handle.ComposeCSIID()
}
/*
CheckReservation checks if given request name contains a valid reservation
- If there is a valid reservation, then the corresponding VolumeGroupData for