From 6ba0cd58b9ad75505e5486c41d6af61234d1bae3 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 24 Jun 2020 12:31:06 +0530 Subject: [PATCH] rbd: add code to store/retrieve the image ID cephcsi need to store and retrieve the rbd image ID in the omap as we need the image ID to add a task to remove the image from the Trash. Signed-off-by: Madhu Rajanna --- internal/journal/voljournal.go | 24 ++++++++++++++++++++++++ internal/rbd/rbd_util.go | 2 ++ 2 files changed, 26 insertions(+) diff --git a/internal/journal/voljournal.go b/internal/journal/voljournal.go index 4a43084be..fea7b1417 100644 --- a/internal/journal/voljournal.go +++ b/internal/journal/voljournal.go @@ -127,6 +127,10 @@ type Config struct { // Ceph volume was created csiNameKey string + // CSI ImageID in per Ceph volume object map, containing image ID + // of this Ceph volume + csiImageIDKey string + // CSI image-name key in per Ceph volume object map, containing RBD image-name // of this Ceph volume csiImageKey string @@ -160,6 +164,7 @@ func NewCSIVolumeJournal(suffix string) *Config { csiJournalPool: "csi.journalpool", cephSnapSourceKey: "", namespace: "", + csiImageIDKey: "csi.imageid", encryptKMSKey: "csi.volume.encryptKMS", commonPrefix: "csi.", } @@ -176,6 +181,7 @@ func NewCSISnapshotJournal(suffix string) *Config { csiJournalPool: "csi.journalpool", cephSnapSourceKey: "csi.source", namespace: "", + csiImageIDKey: "csi.imageid", encryptKMSKey: "csi.volume.encryptKMS", commonPrefix: "csi.", } @@ -650,6 +656,24 @@ func (conn *Connection) GetImageAttributes(ctx context.Context, pool, objectUUID return imageAttributes, nil } +// StoreImageID stores the image ID in omap +func (conn *Connection) StoreImageID(ctx context.Context, pool, reservedUUID, imageID string, cr *util.Credentials) error { + err := util.SetOMapKeyValue(ctx, conn.monitors, cr, pool, conn.config.namespace, conn.config.cephUUIDDirectoryPrefix+reservedUUID, conn.config.csiImageIDKey, imageID) + if err != nil { + return err + } + return nil +} + +// GetStoredImageID retrives the stored image ID from the omap +func (conn *Connection) GetStoredImageID(ctx context.Context, pool, reservedUUID string, cr *util.Credentials) (string, error) { + imageID, err := util.GetOMapValue(ctx, conn.monitors, cr, pool, conn.config.namespace, conn.config.cephUUIDDirectoryPrefix+reservedUUID, conn.config.csiImageIDKey) + if err != nil { + return "", err + } + return imageID, nil +} + // Destroy frees any resources and invalidates the journal connection. func (conn *Connection) Destroy() { // invalidate cluster connection metadata diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 55184ae72..f4d1edbd8 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -96,6 +96,7 @@ type rbdVolume struct { Mounter string `json:"mounter"` ClusterID string `json:"clusterId"` RequestName string + ReservedID string VolName string `json:"volName"` MonValueFromSecret string `json:"monValueFromSecret"` VolSize int64 `json:"volSize"` @@ -121,6 +122,7 @@ type rbdSnapshot struct { // Pool is where the image snapshot journal and snapshot is stored, and could be the same as `JournalPool` SourceVolumeID string RbdImageName string + ReservedID string NamePrefix string RbdSnapName string SnapID string