Skip to content

Commit

Permalink
journal: add option to store the groupID
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Madhu-1 authored and mergify[bot] committed Jun 20, 2024
1 parent 4a46353 commit 95733b3
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit 95733b3

Please sign in to comment.