From 95733b3a91be0b1a25906017002d506895177385 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 18 Jun 2024 10:58:26 +0200 Subject: [PATCH] journal: add option to store the groupID we need to have groupID stored and retrived when we are doing group level operations, we need to find out the groupID from the volumeID Signed-off-by: Madhu Rajanna --- internal/journal/voljournal.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/journal/voljournal.go b/internal/journal/voljournal.go index b8aec1cd8..096375a68 100644 --- a/internal/journal/voljournal.go +++ b/internal/journal/voljournal.go @@ -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 @@ -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", @@ -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 } @@ -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, @@ -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 @@ -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