Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

journal: Update group journal to accomudate rbd group #4687

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions internal/cephfs/groupcontrollerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,13 @@ func (cs *ControllerServer) createSnapshotAndAddMapping(
}
defer j.Destroy()
// Add the snapshot to the volume group journal
err = j.AddVolumeSnapshotMapping(ctx,
err = j.AddVolumesMapping(ctx,
vgo.MetadataPool,
vgs.ReservedID,
req.GetSourceVolumeId(),
resp.GetSnapshot().GetSnapshotId())
map[string]string{
req.GetSourceVolumeId(): resp.GetSnapshot().GetSnapshotId(),
},
)
if err != nil {
log.ErrorLog(ctx, "failed to add volume snapshot mapping: %v", err)
// Delete the last created snapshot as its still not added to the
Expand Down Expand Up @@ -640,11 +642,11 @@ func (cs *ControllerServer) deleteSnapshotsAndUndoReservation(ctx context.Contex
return err
}
// remove the entry from the omap
err = j.RemoveVolumeSnapshotMapping(
err = j.RemoveVolumesMapping(
ctx,
vgo.MetadataPool,
vgsi.ReservedID,
volID)
[]string{volID})
j.Destroy()
if err != nil {
log.ErrorLog(ctx, "failed to remove volume snapshot mapping: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions internal/cephfs/store/volumegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func NewVolumeGroupOptionsFromID(
vgs.RequestName = groupAttributes.RequestName
vgs.FsVolumeGroupSnapshotName = groupAttributes.GroupName
vgs.VolumeGroupSnapshotID = volumeGroupSnapshotID
vgs.VolumeSnapshotMap = groupAttributes.VolumeSnapshotMap
vgs.VolumeSnapshotMap = groupAttributes.VolumeMap

return volOptions, &vgs, nil
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func CheckVolumeGroupSnapExists(
vgs.RequestName = volOptions.RequestName
vgs.ReservedID = volGroupData.GroupUUID
vgs.FsVolumeGroupSnapshotName = volGroupData.GroupName
vgs.VolumeSnapshotMap = volGroupData.VolumeGroupAttributes.VolumeSnapshotMap
vgs.VolumeSnapshotMap = volGroupData.VolumeGroupAttributes.VolumeMap

// found a snapshot already available, process and return it!
vgs.VolumeGroupSnapshotID, err = util.GenerateVolID(ctx, volOptions.Monitors, cr, volOptions.FscID,
Expand Down
18 changes: 18 additions & 0 deletions internal/journal/voljournal.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ type Config struct {
// of this Ceph volume
csiImageIDKey string

// CSI GroupName is per Ceph volume object omap, contains the group ID of
// this Ceph volume
csiGroupIDKey string

// CSI image-name key in per Ceph volume object map, containing RBD image-name
// of this Ceph volume
csiImageKey string
Expand Down Expand Up @@ -174,6 +178,7 @@ func NewCSIVolumeJournal(suffix string) *Config {
cephSnapSourceKey: "",
namespace: "",
csiImageIDKey: "csi.imageid",
csiGroupIDKey: "csi.groupid",
encryptKMSKey: "csi.volume.encryptKMS",
encryptionType: "csi.volume.encryptionType",
ownerKey: "csi.volume.owner",
Expand Down Expand Up @@ -686,6 +691,7 @@ type ImageAttributes struct {
EncryptionType util.EncryptionType // Type of encryption used, if image encrypted
Owner string // Contains the owner to be used in combination with KmsID (for some KMS)
ImageID string // Contains the image id
GroupID string // Contains the group id of the image
JournalPoolID int64 // Pool ID of the CSI journal pool, stored in big endian format (on-disk data)
BackingSnapshotID string // ID of the snapshot on which the CephFS snapshot-backed volume is based
}
Expand Down Expand Up @@ -718,6 +724,7 @@ func (conn *Connection) GetImageAttributes(
cj.csiImageIDKey,
cj.ownerKey,
cj.backingSnapshotIDKey,
cj.csiGroupIDKey,
}
values, err := getOMapValues(
ctx, conn, pool, cj.namespace, cj.cephUUIDDirectoryPrefix+objectUUID,
Expand All @@ -736,6 +743,7 @@ func (conn *Connection) GetImageAttributes(
imageAttributes.Owner = values[cj.ownerKey]
imageAttributes.ImageID = values[cj.csiImageIDKey]
imageAttributes.BackingSnapshotID = values[cj.backingSnapshotIDKey]
imageAttributes.GroupID = values[cj.csiGroupIDKey]

// image key was added at a later point, so not all volumes will have this
// key set when ceph-csi was upgraded
Expand Down Expand Up @@ -795,6 +803,16 @@ func (conn *Connection) StoreAttribute(ctx context.Context, pool, reservedUUID,
return nil
}

// StoreGroupID stores an groupID in omap.
func (conn *Connection) StoreGroupID(ctx context.Context, pool, reservedUUID, groupID string) error {
err := conn.StoreAttribute(ctx, pool, reservedUUID, conn.config.csiGroupIDKey, groupID)
if err != nil {
return fmt.Errorf("failed to store groupID %w", err)
}

return nil
}

// FetchAttribute fetches an attribute (key) in omap.
func (conn *Connection) FetchAttribute(ctx context.Context, pool, reservedUUID, attribute string) (string, error) {
key := conn.config.commonPrefix + attribute
Expand Down
56 changes: 29 additions & 27 deletions internal/journal/volumegroupjournal.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type VolumeGroupJournal interface {
UndoReservation(
ctx context.Context,
csiJournalPool,
snapshotGroupName,
groupName,
reqName string) error
// GetGroupAttributes fetches all keys and their values, from a UUID directory,
// returning VolumeGroupAttributes structure.
Expand All @@ -55,19 +55,22 @@ type VolumeGroupJournal interface {
journalPoolID int64,
reqName,
namePrefix string) (string, string, error)
// AddVolumeSnapshotMapping adds a volumeID and snapshotID mapping to the UUID directory.
AddVolumeSnapshotMapping(
// 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
// volumegroupsnapshot its a snapshotID and its empty in case of
// volumegroup.
AddVolumesMapping(
ctx context.Context,
pool,
reservedUUID,
volumeID,
snapshotID string) error
// RemoveVolumeSnapshotMapping removes a volumeID and snapshotID mapping from the UUID directory.
RemoveVolumeSnapshotMapping(
reservedUUID string,
volumeMap map[string]string) error
// RemoveVolumesMapping removes volumeIDs mapping from the UUID directory.
RemoveVolumesMapping(
ctx context.Context,
pool,
reservedUUID,
volumeID string) error
reservedUUID string,
volumeIDs []string) error
}

// VolumeGroupJournalConfig contains the configuration.
Expand Down Expand Up @@ -222,7 +225,7 @@ func (vgjc *VolumeGroupJournalConnection) CheckReservation(ctx context.Context,
volGroupData.GroupName = savedVolumeGroupAttributes.GroupName
volGroupData.VolumeGroupAttributes = &VolumeGroupAttributes{}
volGroupData.VolumeGroupAttributes.RequestName = savedVolumeGroupAttributes.RequestName
volGroupData.VolumeGroupAttributes.VolumeSnapshotMap = savedVolumeGroupAttributes.VolumeSnapshotMap
volGroupData.VolumeGroupAttributes.VolumeMap = savedVolumeGroupAttributes.VolumeMap

return volGroupData, nil
}
Expand Down Expand Up @@ -361,9 +364,9 @@ func (vgjc *VolumeGroupJournalConnection) ReserveName(ctx context.Context,
// VolumeGroupAttributes contains the request name and the volumeID's and
// the corresponding snapshotID's.
type VolumeGroupAttributes struct {
RequestName string // Contains the request name for the passed in UUID
GroupName string // Contains the group name
VolumeSnapshotMap map[string]string // Contains the volumeID and the corresponding snapshotID mapping
RequestName string // Contains the request name for the passed in UUID
GroupName string // Contains the group name
VolumeMap map[string]string // Contains the volumeID and the corresponding value mapping
}

func (vgjc *VolumeGroupJournalConnection) GetVolumeGroupAttributes(
Expand Down Expand Up @@ -393,43 +396,42 @@ func (vgjc *VolumeGroupJournalConnection) GetVolumeGroupAttributes(
// looking for volumeID/snapshotID mapping
delete(values, cj.csiNameKey)
delete(values, cj.csiImageKey)
groupAttributes.VolumeSnapshotMap = map[string]string{}
groupAttributes.VolumeMap = map[string]string{}
for k, v := range values {
groupAttributes.VolumeSnapshotMap[k] = v
groupAttributes.VolumeMap[k] = v
}

return groupAttributes, nil
}

func (vgjc *VolumeGroupJournalConnection) AddVolumeSnapshotMapping(
func (vgjc *VolumeGroupJournalConnection) AddVolumesMapping(
ctx context.Context,
pool,
reservedUUID,
volumeID,
snapshotID string,
reservedUUID string,
volumeMap map[string]string,
) error {
err := setOMapKeys(ctx, vgjc.connection, pool, vgjc.config.namespace, vgjc.config.cephUUIDDirectoryPrefix+reservedUUID,
map[string]string{volumeID: snapshotID})
volumeMap)
if err != nil {
log.ErrorLog(ctx, "failed adding volume snapshot mapping: %v", err)
log.ErrorLog(ctx, "failed to add volumeMap %v: %w ", volumeMap, err)

return err
}

return nil
}

func (vgjc *VolumeGroupJournalConnection) RemoveVolumeSnapshotMapping(
func (vgjc *VolumeGroupJournalConnection) RemoveVolumesMapping(
ctx context.Context,
pool,
reservedUUID,
volumeID string,
reservedUUID string,
volumeIDs []string,
) error {
err := removeMapKeys(ctx, vgjc.connection, pool, vgjc.config.namespace,
vgjc.config.cephUUIDDirectoryPrefix+reservedUUID,
[]string{volumeID})
volumeIDs)
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", volumeIDs, err)

return err
}
Expand Down