mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-26 08:10:20 +00:00
journal: replace getStoredImageId with go-ceph
moved implementation of getStoredImageID to go-ceph to get better performance. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
341a3c9f59
commit
9bb79fbe7d
@ -587,6 +587,7 @@ type ImageAttributes struct {
|
|||||||
SourceName string // Contains the parent image name for the passed in UUID, if it is a snapshot
|
SourceName string // Contains the parent image name for the passed in UUID, if it is a snapshot
|
||||||
ImageName string // Contains the image or subvolume name for the passed in UUID
|
ImageName string // Contains the image or subvolume name for the passed in UUID
|
||||||
KmsID string // Contains encryption KMS, if it is an encrypted image
|
KmsID string // Contains encryption KMS, if it is an encrypted image
|
||||||
|
ImageID string // Contains the image id
|
||||||
JournalPoolID int64 // Pool ID of the CSI journal pool, stored in big endian format (on-disk data)
|
JournalPoolID int64 // Pool ID of the CSI journal pool, stored in big endian format (on-disk data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,6 +610,7 @@ func (conn *Connection) GetImageAttributes(ctx context.Context, pool, objectUUID
|
|||||||
cj.encryptKMSKey,
|
cj.encryptKMSKey,
|
||||||
cj.csiJournalPool,
|
cj.csiJournalPool,
|
||||||
cj.cephSnapSourceKey,
|
cj.cephSnapSourceKey,
|
||||||
|
cj.csiImageIDKey,
|
||||||
}
|
}
|
||||||
values, err := getOMapValues(
|
values, err := getOMapValues(
|
||||||
ctx, conn, pool, cj.namespace, cj.cephUUIDDirectoryPrefix+objectUUID,
|
ctx, conn, pool, cj.namespace, cj.cephUUIDDirectoryPrefix+objectUUID,
|
||||||
@ -625,6 +627,7 @@ func (conn *Connection) GetImageAttributes(ctx context.Context, pool, objectUUID
|
|||||||
var found bool
|
var found bool
|
||||||
imageAttributes.RequestName = values[cj.csiNameKey]
|
imageAttributes.RequestName = values[cj.csiNameKey]
|
||||||
imageAttributes.KmsID = values[cj.encryptKMSKey]
|
imageAttributes.KmsID = values[cj.encryptKMSKey]
|
||||||
|
imageAttributes.ImageID = values[cj.csiImageIDKey]
|
||||||
|
|
||||||
// image key was added at a later point, so not all volumes will have this
|
// image key was added at a later point, so not all volumes will have this
|
||||||
// key set when ceph-csi was upgraded
|
// key set when ceph-csi was upgraded
|
||||||
|
@ -945,23 +945,9 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
|
|||||||
return nil, status.Error(codes.Internal, err.Error())
|
return nil, status.Error(codes.Internal, err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// save image ID
|
rbdVol.ImageID = rbdSnap.ImageID
|
||||||
var j = &journal.Connection{}
|
|
||||||
j, err = snapJournal.Connect(rbdSnap.Monitors, cr)
|
|
||||||
if err != nil {
|
|
||||||
klog.Errorf(util.Log(ctx, "failed to connect to cluster: %v"), err)
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
|
||||||
}
|
|
||||||
defer j.Destroy()
|
|
||||||
// TODO replace GetStoredImageID with GetImageAttributes in all places
|
|
||||||
rbdVol.ImageID, err = j.GetStoredImageID(ctx, rbdSnap.JournalPool, rbdSnap.ReservedID, cr)
|
|
||||||
if err != nil {
|
|
||||||
klog.Errorf(util.Log(ctx, "failed to get reserved image id: %v"), err)
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
|
||||||
}
|
|
||||||
// update parent name to delete the snapshot
|
// update parent name to delete the snapshot
|
||||||
rbdSnap.RbdImageName = rbdVol.RbdImageName
|
rbdSnap.RbdImageName = rbdVol.RbdImageName
|
||||||
|
|
||||||
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol, cr)
|
err = cleanUpSnapshot(ctx, rbdVol, rbdSnap, rbdVol, cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to delete image: %v"), err)
|
klog.Errorf(util.Log(ctx, "failed to delete image: %v"), err)
|
||||||
|
@ -133,6 +133,7 @@ func checkSnapCloneExists(ctx context.Context, parentVol *rbdVolume, rbdSnap *rb
|
|||||||
}
|
}
|
||||||
snapUUID := snapData.ImageUUID
|
snapUUID := snapData.ImageUUID
|
||||||
rbdSnap.RbdSnapName = snapData.ImageAttributes.ImageName
|
rbdSnap.RbdSnapName = snapData.ImageAttributes.ImageName
|
||||||
|
rbdSnap.ImageID = snapData.ImageAttributes.ImageID
|
||||||
|
|
||||||
// it should never happen that this disagrees, but check
|
// it should never happen that this disagrees, but check
|
||||||
if rbdSnap.Pool != snapData.ImagePool {
|
if rbdSnap.Pool != snapData.ImagePool {
|
||||||
@ -193,8 +194,7 @@ func checkSnapCloneExists(ctx context.Context, parentVol *rbdVolume, rbdSnap *rb
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
vol.ImageID, err = j.GetStoredImageID(ctx, vol.JournalPool, vol.ReservedID, cr)
|
if vol.ImageID == "" {
|
||||||
if _, ok := err.(util.ErrKeyNotFound); ok {
|
|
||||||
sErr := vol.getImageID()
|
sErr := vol.getImageID()
|
||||||
if sErr != nil {
|
if sErr != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to get image id %s: %v"), vol, sErr)
|
klog.Errorf(util.Log(ctx, "failed to get image id %s: %v"), vol, sErr)
|
||||||
@ -254,7 +254,7 @@ func (rv *rbdVolume) Exists(ctx context.Context) (bool, error) {
|
|||||||
|
|
||||||
rv.ReservedID = imageData.ImageUUID
|
rv.ReservedID = imageData.ImageUUID
|
||||||
rv.RbdImageName = imageData.ImageAttributes.ImageName
|
rv.RbdImageName = imageData.ImageAttributes.ImageName
|
||||||
|
rv.ImageID = imageData.ImageAttributes.ImageID
|
||||||
// check if topology constraints match what is found
|
// check if topology constraints match what is found
|
||||||
rv.Topology, err = util.MatchTopologyForPool(rv.TopologyPools, rv.TopologyRequirement,
|
rv.Topology, err = util.MatchTopologyForPool(rv.TopologyPools, rv.TopologyRequirement,
|
||||||
imageData.ImagePool)
|
imageData.ImagePool)
|
||||||
@ -282,8 +282,7 @@ func (rv *rbdVolume) Exists(ctx context.Context) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rv.ImageID, err = j.GetStoredImageID(ctx, rv.JournalPool, rv.ReservedID, rv.conn.Creds)
|
if rv.ImageID == "" {
|
||||||
if _, ok := err.(util.ErrKeyNotFound); ok {
|
|
||||||
err = rv.getImageID()
|
err = rv.getImageID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to get image id %s: %v"), rv, err)
|
klog.Errorf(util.Log(ctx, "failed to get image id %s: %v"), rv, err)
|
||||||
|
@ -124,12 +124,14 @@ type rbdSnapshot struct {
|
|||||||
// RequestName is the CSI generated snapshot name for the rbdSnapshot
|
// RequestName is the CSI generated snapshot name for the rbdSnapshot
|
||||||
// JournalPool is the ceph pool in which the CSI snapshot Journal is stored
|
// JournalPool is the ceph pool in which the CSI snapshot Journal is stored
|
||||||
// Pool is where the image snapshot journal and snapshot is stored, and could be the same as `JournalPool`
|
// Pool is where the image snapshot journal and snapshot is stored, and could be the same as `JournalPool`
|
||||||
|
// ImageID contains the image id of cloned image
|
||||||
SourceVolumeID string
|
SourceVolumeID string
|
||||||
RbdImageName string
|
RbdImageName string
|
||||||
ReservedID string
|
ReservedID string
|
||||||
NamePrefix string
|
NamePrefix string
|
||||||
RbdSnapName string
|
RbdSnapName string
|
||||||
SnapID string
|
SnapID string
|
||||||
|
ImageID string
|
||||||
Monitors string
|
Monitors string
|
||||||
JournalPool string
|
JournalPool string
|
||||||
Pool string
|
Pool string
|
||||||
@ -563,6 +565,7 @@ func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID str
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
rbdSnap.ImageID = imageAttributes.ImageID
|
||||||
rbdSnap.RequestName = imageAttributes.RequestName
|
rbdSnap.RequestName = imageAttributes.RequestName
|
||||||
rbdSnap.RbdImageName = imageAttributes.SourceName
|
rbdSnap.RbdImageName = imageAttributes.SourceName
|
||||||
rbdSnap.RbdSnapName = imageAttributes.ImageName
|
rbdSnap.RbdSnapName = imageAttributes.ImageName
|
||||||
@ -633,6 +636,7 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
|
|||||||
rbdVol.RequestName = imageAttributes.RequestName
|
rbdVol.RequestName = imageAttributes.RequestName
|
||||||
rbdVol.RbdImageName = imageAttributes.ImageName
|
rbdVol.RbdImageName = imageAttributes.ImageName
|
||||||
rbdVol.ReservedID = vi.ObjectUUID
|
rbdVol.ReservedID = vi.ObjectUUID
|
||||||
|
rbdVol.ImageID = imageAttributes.ImageID
|
||||||
|
|
||||||
if imageAttributes.KmsID != "" {
|
if imageAttributes.KmsID != "" {
|
||||||
rbdVol.Encrypted = true
|
rbdVol.Encrypted = true
|
||||||
@ -650,8 +654,7 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rbdVol.ImageID, err = j.GetStoredImageID(ctx, rbdVol.JournalPool, rbdVol.ReservedID, cr)
|
if rbdVol.ImageID == "" {
|
||||||
if _, ok := err.(util.ErrKeyNotFound); ok {
|
|
||||||
err = rbdVol.getImageID()
|
err = rbdVol.getImageID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to get image id %s: %v"), rbdVol, err)
|
klog.Errorf(util.Log(ctx, "failed to get image id %s: %v"), rbdVol, err)
|
||||||
|
@ -87,6 +87,7 @@ func generateVolFromSnap(rbdSnap *rbdSnapshot) *rbdVolume {
|
|||||||
vol.Pool = rbdSnap.Pool
|
vol.Pool = rbdSnap.Pool
|
||||||
vol.JournalPool = rbdSnap.JournalPool
|
vol.JournalPool = rbdSnap.JournalPool
|
||||||
vol.RbdImageName = rbdSnap.RbdSnapName
|
vol.RbdImageName = rbdSnap.RbdSnapName
|
||||||
|
vol.ImageID = rbdSnap.ImageID
|
||||||
return vol
|
return vol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user