mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-04-11 18:13:00 +00:00
rbd: add Manager.getVolumeGroupNamePrefix()
The `prefix` is passed to several functions, but it can easily be obtained with a small helper function. This makes calling the functions a little simpler. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
parent
ca7c8b0fdb
commit
728f9e9a44
@ -83,6 +83,12 @@ func (mgr *rbdManager) getCredentials() (*util.Credentials, error) {
|
|||||||
return creds, nil
|
return creds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getVolumeGroupNamePrefix returns the prefix for the volume group if set, or
|
||||||
|
// an empty string if none is configured.
|
||||||
|
func (mgr *rbdManager) getVolumeGroupNamePrefix() string {
|
||||||
|
return mgr.parameters["volumeGroupNamePrefix"]
|
||||||
|
}
|
||||||
|
|
||||||
func (mgr *rbdManager) getVolumeGroupJournal(clusterID string) (journal.VolumeGroupJournal, error) {
|
func (mgr *rbdManager) getVolumeGroupJournal(clusterID string) (journal.VolumeGroupJournal, error) {
|
||||||
if mgr.vgJournal != nil {
|
if mgr.vgJournal != nil {
|
||||||
return mgr.vgJournal, nil
|
return mgr.vgJournal, nil
|
||||||
@ -123,12 +129,14 @@ func (mgr *rbdManager) getVolumeGroupJournal(clusterID string) (journal.VolumeGr
|
|||||||
// 3. an error or nil.
|
// 3. an error or nil.
|
||||||
func (mgr *rbdManager) getGroupUUID(
|
func (mgr *rbdManager) getGroupUUID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
clusterID, journalPool, name, prefix string,
|
clusterID, journalPool, name string,
|
||||||
) (string, func(), error) {
|
) (string, func(), error) {
|
||||||
nothingToUndo := func() {
|
nothingToUndo := func() {
|
||||||
// the reservation was not done, no need to undo the reservation
|
// the reservation was not done, no need to undo the reservation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefix := mgr.getVolumeGroupNamePrefix()
|
||||||
|
|
||||||
vgJournal, err := mgr.getVolumeGroupJournal(clusterID)
|
vgJournal, err := mgr.getVolumeGroupJournal(clusterID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nothingToUndo, err
|
return "", nothingToUndo, err
|
||||||
@ -259,7 +267,7 @@ func (mgr *rbdManager) CreateVolumeGroup(ctx context.Context, name string) (type
|
|||||||
}
|
}
|
||||||
|
|
||||||
// volumeGroupNamePrefix is an optional parameter, can be an empty string
|
// volumeGroupNamePrefix is an optional parameter, can be an empty string
|
||||||
prefix := mgr.parameters["volumeGroupNamePrefix"]
|
prefix := mgr.getVolumeGroupNamePrefix()
|
||||||
|
|
||||||
// check if the journal contains a generated name for the group already
|
// check if the journal contains a generated name for the group already
|
||||||
vgData, err := vgJournal.CheckReservation(ctx, journalPool, name, prefix)
|
vgData, err := vgJournal.CheckReservation(ctx, journalPool, name, prefix)
|
||||||
@ -347,15 +355,12 @@ func (mgr *rbdManager) GetVolumeGroupSnapshotByName(
|
|||||||
return nil, errors.New("required 'pool' option missing in volume group parameters")
|
return nil, errors.New("required 'pool' option missing in volume group parameters")
|
||||||
}
|
}
|
||||||
|
|
||||||
// volumeGroupNamePrefix is an optional parameter, can be an empty string
|
|
||||||
prefix := mgr.parameters["volumeGroupNamePrefix"]
|
|
||||||
|
|
||||||
clusterID, err := util.GetClusterID(mgr.parameters)
|
clusterID, err := util.GetClusterID(mgr.parameters)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get cluster-id: %w", err)
|
return nil, fmt.Errorf("failed to get cluster-id: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid, freeUUID, err := mgr.getGroupUUID(ctx, clusterID, pool, name, prefix)
|
uuid, freeUUID, err := mgr.getGroupUUID(ctx, clusterID, pool, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get a UUID for volume group snapshot %q: %w", name, err)
|
return nil, fmt.Errorf("failed to get a UUID for volume group snapshot %q: %w", name, err)
|
||||||
}
|
}
|
||||||
@ -410,15 +415,12 @@ func (mgr *rbdManager) CreateVolumeGroupSnapshot(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// volumeGroupNamePrefix is an optional parameter, can be an empty string
|
|
||||||
prefix := mgr.parameters["volumeGroupNamePrefix"]
|
|
||||||
|
|
||||||
clusterID, err := vg.GetClusterID(ctx)
|
clusterID, err := vg.GetClusterID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get cluster id for volume group snapshot %q: %w", vg, err)
|
return nil, fmt.Errorf("failed to get cluster id for volume group snapshot %q: %w", vg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid, freeUUID, err := mgr.getGroupUUID(ctx, clusterID, pool, name, prefix)
|
uuid, freeUUID, err := mgr.getGroupUUID(ctx, clusterID, pool, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get a UUID for volume group snapshot %q: %w", vg, err)
|
return nil, fmt.Errorf("failed to get a UUID for volume group snapshot %q: %w", vg, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user