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 nixpanic
parent 728f9e9a44
commit 340568a0e9
4 changed files with 151 additions and 0 deletions

View File

@ -238,6 +238,21 @@ func (mgr *rbdManager) GetVolumeGroupByID(ctx context.Context, id string) (types
return vg, nil
}
func (mgr *rbdManager) MakeVolumeGroupID(ctx context.Context, poolID int64, name string) (string, error) {
clusterID, err := util.GetClusterID(mgr.parameters)
if err != nil {
return "", fmt.Errorf("failed to get cluster-id: %w", err)
}
// convert the clusterid, poolid and name to an id/handle
id, err := journal.MakeVolumeGroupID(clusterID, poolID, name, mgr.getVolumeGroupNamePrefix())
if err != nil {
return "", fmt.Errorf("failed to convert name %q to a CSI-handle: %w", name, err)
}
return id, nil
}
func (mgr *rbdManager) CreateVolumeGroup(ctx context.Context, name string) (types.VolumeGroup, error) {
creds, err := mgr.getCredentials()
if err != nil {