journal: remove snapshot specific name from group

Adjusted method names to not have any
specific things to volumesnapshot as
we want to reuse the same journal for
volumegroup as well.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-06-18 11:11:33 +02:00 committed by mergify[bot]
parent 95733b3a91
commit f346f3d201
3 changed files with 24 additions and 22 deletions

View File

@ -461,7 +461,7 @@ 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.AddVolumeSnapshotMapping(ctx, err = j.AddVolumeMapping(ctx,
vgo.MetadataPool, vgo.MetadataPool,
vgs.ReservedID, vgs.ReservedID,
req.GetSourceVolumeId(), req.GetSourceVolumeId(),
@ -640,7 +640,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.RemoveVolumeSnapshotMapping( err = j.RemoveVolumeMapping(
ctx, ctx,
vgo.MetadataPool, vgo.MetadataPool,
vgsi.ReservedID, vgsi.ReservedID,

View File

@ -169,7 +169,7 @@ func NewVolumeGroupOptionsFromID(
vgs.RequestName = groupAttributes.RequestName vgs.RequestName = groupAttributes.RequestName
vgs.FsVolumeGroupSnapshotName = groupAttributes.GroupName vgs.FsVolumeGroupSnapshotName = groupAttributes.GroupName
vgs.VolumeGroupSnapshotID = volumeGroupSnapshotID vgs.VolumeGroupSnapshotID = volumeGroupSnapshotID
vgs.VolumeSnapshotMap = groupAttributes.VolumeSnapshotMap vgs.VolumeSnapshotMap = groupAttributes.VolumeMap
return volOptions, &vgs, nil return volOptions, &vgs, nil
} }
@ -208,7 +208,7 @@ func CheckVolumeGroupSnapExists(
vgs.RequestName = volOptions.RequestName vgs.RequestName = volOptions.RequestName
vgs.ReservedID = volGroupData.GroupUUID vgs.ReservedID = volGroupData.GroupUUID
vgs.FsVolumeGroupSnapshotName = volGroupData.GroupName vgs.FsVolumeGroupSnapshotName = volGroupData.GroupName
vgs.VolumeSnapshotMap = volGroupData.VolumeGroupAttributes.VolumeSnapshotMap vgs.VolumeSnapshotMap = volGroupData.VolumeGroupAttributes.VolumeMap
// found a snapshot already available, process and return it! // found a snapshot already available, process and return it!
vgs.VolumeGroupSnapshotID, err = util.GenerateVolID(ctx, volOptions.Monitors, cr, volOptions.FscID, vgs.VolumeGroupSnapshotID, err = util.GenerateVolID(ctx, volOptions.Monitors, cr, volOptions.FscID,

View File

@ -41,7 +41,7 @@ type VolumeGroupJournal interface {
UndoReservation( UndoReservation(
ctx context.Context, ctx context.Context,
csiJournalPool, csiJournalPool,
snapshotGroupName, groupName,
reqName string) error reqName string) error
// GetGroupAttributes fetches all keys and their values, from a UUID directory, // GetGroupAttributes fetches all keys and their values, from a UUID directory,
// returning VolumeGroupAttributes structure. // returning VolumeGroupAttributes structure.
@ -55,15 +55,17 @@ type VolumeGroupJournal interface {
journalPoolID int64, journalPoolID int64,
reqName, reqName,
namePrefix string) (string, string, error) namePrefix string) (string, string, error)
// AddVolumeSnapshotMapping adds a volumeID and snapshotID mapping to the UUID directory. // AddVolumeMapping adds a volumeID and value mapping to the UUID
AddVolumeSnapshotMapping( // directory. value can be anything which needs mapping, in case of
// volumegroupsnapshot its a snapshotID and its empty in case of volumegroup.
AddVolumeMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID, reservedUUID,
volumeID, volumeID,
snapshotID string) error value string) error
// RemoveVolumeSnapshotMapping removes a volumeID and snapshotID mapping from the UUID directory. // RemoveVolumeMapping removes a volumeID mapping from the UUID directory.
RemoveVolumeSnapshotMapping( RemoveVolumeMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID, reservedUUID,
@ -222,7 +224,7 @@ func (vgjc *VolumeGroupJournalConnection) CheckReservation(ctx context.Context,
volGroupData.GroupName = savedVolumeGroupAttributes.GroupName volGroupData.GroupName = savedVolumeGroupAttributes.GroupName
volGroupData.VolumeGroupAttributes = &VolumeGroupAttributes{} volGroupData.VolumeGroupAttributes = &VolumeGroupAttributes{}
volGroupData.VolumeGroupAttributes.RequestName = savedVolumeGroupAttributes.RequestName volGroupData.VolumeGroupAttributes.RequestName = savedVolumeGroupAttributes.RequestName
volGroupData.VolumeGroupAttributes.VolumeSnapshotMap = savedVolumeGroupAttributes.VolumeSnapshotMap volGroupData.VolumeGroupAttributes.VolumeMap = savedVolumeGroupAttributes.VolumeMap
return volGroupData, nil return volGroupData, nil
} }
@ -361,9 +363,9 @@ func (vgjc *VolumeGroupJournalConnection) ReserveName(ctx context.Context,
// VolumeGroupAttributes contains the request name and the volumeID's and // VolumeGroupAttributes contains the request name and the volumeID's and
// the corresponding snapshotID's. // the corresponding snapshotID's.
type VolumeGroupAttributes struct { type VolumeGroupAttributes struct {
RequestName string // Contains the request name for the passed in UUID RequestName string // Contains the request name for the passed in UUID
GroupName string // Contains the group name GroupName string // Contains the group name
VolumeSnapshotMap map[string]string // Contains the volumeID and the corresponding snapshotID mapping VolumeMap map[string]string // Contains the volumeID and the corresponding value mapping
} }
func (vgjc *VolumeGroupJournalConnection) GetVolumeGroupAttributes( func (vgjc *VolumeGroupJournalConnection) GetVolumeGroupAttributes(
@ -393,25 +395,25 @@ func (vgjc *VolumeGroupJournalConnection) GetVolumeGroupAttributes(
// looking for volumeID/snapshotID mapping // looking for volumeID/snapshotID mapping
delete(values, cj.csiNameKey) delete(values, cj.csiNameKey)
delete(values, cj.csiImageKey) delete(values, cj.csiImageKey)
groupAttributes.VolumeSnapshotMap = map[string]string{} groupAttributes.VolumeMap = map[string]string{}
for k, v := range values { for k, v := range values {
groupAttributes.VolumeSnapshotMap[k] = v groupAttributes.VolumeMap[k] = v
} }
return groupAttributes, nil return groupAttributes, nil
} }
func (vgjc *VolumeGroupJournalConnection) AddVolumeSnapshotMapping( func (vgjc *VolumeGroupJournalConnection) AddVolumeMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID, reservedUUID,
volumeID, volumeID,
snapshotID 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: snapshotID}) map[string]string{volumeID: value})
if err != nil { if err != nil {
log.ErrorLog(ctx, "failed adding volume snapshot mapping: %v", err) log.ErrorLog(ctx, "failed adding volume mapping: %v", err)
return err return err
} }
@ -419,7 +421,7 @@ func (vgjc *VolumeGroupJournalConnection) AddVolumeSnapshotMapping(
return nil return nil
} }
func (vgjc *VolumeGroupJournalConnection) RemoveVolumeSnapshotMapping( func (vgjc *VolumeGroupJournalConnection) RemoveVolumeMapping(
ctx context.Context, ctx context.Context,
pool, pool,
reservedUUID, reservedUUID,
@ -429,7 +431,7 @@ func (vgjc *VolumeGroupJournalConnection) RemoveVolumeSnapshotMapping(
vgjc.config.cephUUIDDirectoryPrefix+reservedUUID, vgjc.config.cephUUIDDirectoryPrefix+reservedUUID,
[]string{volumeID}) []string{volumeID})
if err != nil { if err != nil {
log.ErrorLog(ctx, "failed removing volume snapshot mapping: %v", err) log.ErrorLog(ctx, "failed removing volume mapping from group: key %q: %v", volumeID, err)
return err return err
} }