journal: add volumeMap to the group

instead of adding single volumes to the
group journal, support adding multiple
volumeID's map to the group journal
which is required for RBD as well.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-06-18 11:19:11 +02:00 committed by mergify[bot]
parent fc0a7d2542
commit f8fbf2e95a
2 changed files with 21 additions and 19 deletions

View File

@ -461,11 +461,13 @@ func (cs *ControllerServer) createSnapshotAndAddMapping(
} }
defer j.Destroy() defer j.Destroy()
// Add the snapshot to the volume group journal // Add the snapshot to the volume group journal
err = j.AddVolumeMapping(ctx, err = j.AddVolumesMapping(ctx,
vgo.MetadataPool, vgo.MetadataPool,
vgs.ReservedID, vgs.ReservedID,
req.GetSourceVolumeId(), map[string]string{
resp.GetSnapshot().GetSnapshotId()) req.GetSourceVolumeId(): resp.GetSnapshot().GetSnapshotId(),
},
)
if err != nil { if err != nil {
log.ErrorLog(ctx, "failed to add volume snapshot mapping: %v", err) log.ErrorLog(ctx, "failed to add volume snapshot mapping: %v", err)
// Delete the last created snapshot as its still not added to the // Delete the last created snapshot as its still not added to the
@ -640,7 +642,7 @@ func (cs *ControllerServer) deleteSnapshotsAndUndoReservation(ctx context.Contex
return err return err
} }
// remove the entry from the omap // remove the entry from the omap
err = j.RemoveVolumeMapping( err = j.RemoveVolumesMapping(
ctx, ctx,
vgo.MetadataPool, vgo.MetadataPool,
vgsi.ReservedID, vgsi.ReservedID,

View File

@ -55,17 +55,18 @@ type VolumeGroupJournal interface {
journalPoolID int64, journalPoolID int64,
reqName, reqName,
namePrefix string) (string, string, error) namePrefix string) (string, string, error)
// AddVolumeMapping adds a volumeID and value mapping to the UUID // AddVolumesMapping adds a volumeMap map which contains volumeID's and its
// corresponding values mapping which need to be added to the UUID
// directory. value can be anything which needs mapping, in case of // directory. value can be anything which needs mapping, in case of
// volumegroupsnapshot its a snapshotID and its empty in case of volumegroup. // volumegroupsnapshot its a snapshotID and its empty in case of
AddVolumeMapping( // volumegroup.
AddVolumesMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID, reservedUUID string,
volumeID, volumeMap map[string]string) error
value string) error // RemoveVolumesMapping removes volumeIDs mapping from the UUID directory.
// RemoveVolumeMapping removes volumeIDs mapping from the UUID directory. RemoveVolumesMapping(
RemoveVolumeMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID string, reservedUUID string,
@ -403,17 +404,16 @@ func (vgjc *VolumeGroupJournalConnection) GetVolumeGroupAttributes(
return groupAttributes, nil return groupAttributes, nil
} }
func (vgjc *VolumeGroupJournalConnection) AddVolumeMapping( func (vgjc *VolumeGroupJournalConnection) AddVolumesMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID, reservedUUID string,
volumeID, volumeMap map[string]string,
value string,
) error { ) error {
err := setOMapKeys(ctx, vgjc.connection, pool, vgjc.config.namespace, vgjc.config.cephUUIDDirectoryPrefix+reservedUUID, err := setOMapKeys(ctx, vgjc.connection, pool, vgjc.config.namespace, vgjc.config.cephUUIDDirectoryPrefix+reservedUUID,
map[string]string{volumeID: value}) volumeMap)
if err != nil { if err != nil {
log.ErrorLog(ctx, "failed adding volume mapping: %v", err) log.ErrorLog(ctx, "failed to add volumeMap %v: %w ", volumeMap, err)
return err return err
} }
@ -421,7 +421,7 @@ func (vgjc *VolumeGroupJournalConnection) AddVolumeMapping(
return nil return nil
} }
func (vgjc *VolumeGroupJournalConnection) RemoveVolumeMapping( func (vgjc *VolumeGroupJournalConnection) RemoveVolumesMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID string, reservedUUID string,