journal: split journal types creating a new Connection type

Before, the one CSIJournal type was handling both configuration and
providing methods to make changes to the journal. This created the
temptation to modify the state of the global configuration object to
enact changes through the method calls.

This change creates a new type `journal.Connection` that takes the
monitors and credentials to create a short(er)-lived object to actually
read and make changes on the journal. This also avoid mixing the
arguments needed to connect to the cluster with the arguments needed
for the various journal read & update calls.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-05-12 17:05:55 -04:00 committed by mergify[bot]
parent f0b3cee94a
commit 52603d595a
6 changed files with 166 additions and 50 deletions

View File

@ -54,8 +54,14 @@ func checkVolExists(ctx context.Context, volOptions *volumeOptions, secret map[s
} }
defer cr.DeleteCredentials() defer cr.DeleteCredentials()
imageData, err := volJournal.CheckReservation(ctx, volOptions.Monitors, cr, j, err := volJournal.Connect(volOptions.Monitors, cr)
volOptions.MetadataPool, volOptions.RequestName, volOptions.NamePrefix, "", "") if err != nil {
return nil, err
}
defer j.Destroy()
imageData, err := j.CheckReservation(
ctx, volOptions.MetadataPool, volOptions.RequestName, volOptions.NamePrefix, "", "")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -68,7 +74,7 @@ func checkVolExists(ctx context.Context, volOptions *volumeOptions, secret map[s
_, err = getVolumeRootPathCeph(ctx, volOptions, cr, volumeID(vid.FsSubvolName)) _, err = getVolumeRootPathCeph(ctx, volOptions, cr, volumeID(vid.FsSubvolName))
if err != nil { if err != nil {
if _, ok := err.(ErrVolumeNotFound); ok { if _, ok := err.(ErrVolumeNotFound); ok {
err = volJournal.UndoReservation(ctx, volOptions.Monitors, cr, volOptions.MetadataPool, err = j.UndoReservation(ctx, volOptions.MetadataPool,
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName) volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
return nil, err return nil, err
} }
@ -102,7 +108,13 @@ func undoVolReservation(ctx context.Context, volOptions *volumeOptions, vid volu
} }
defer cr.DeleteCredentials() defer cr.DeleteCredentials()
err = volJournal.UndoReservation(ctx, volOptions.Monitors, cr, volOptions.MetadataPool, j, err := volJournal.Connect(volOptions.Monitors, cr)
if err != nil {
return err
}
defer j.Destroy()
err = j.UndoReservation(ctx, volOptions.MetadataPool,
volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName) volOptions.MetadataPool, vid.FsSubvolName, volOptions.RequestName)
return err return err
@ -142,8 +154,16 @@ func reserveVol(ctx context.Context, volOptions *volumeOptions, secret map[strin
return nil, err return nil, err
} }
imageUUID, vid.FsSubvolName, err = volJournal.ReserveName(ctx, volOptions.Monitors, cr, volOptions.MetadataPool, util.InvalidPoolID, j, err := volJournal.Connect(volOptions.Monitors, cr)
volOptions.MetadataPool, util.InvalidPoolID, volOptions.RequestName, volOptions.NamePrefix, "", "") if err != nil {
return nil, err
}
defer j.Destroy()
imageUUID, vid.FsSubvolName, err = j.ReserveName(
ctx, volOptions.MetadataPool, util.InvalidPoolID,
volOptions.MetadataPool, util.InvalidPoolID, volOptions.RequestName,
volOptions.NamePrefix, "", "")
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -261,8 +261,14 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret
return nil, nil, err return nil, nil, err
} }
imageAttributes, err := volJournal.GetImageAttributes(ctx, volOptions.Monitors, cr, j, err := volJournal.Connect(volOptions.Monitors, cr)
volOptions.MetadataPool, vi.ObjectUUID, false) if err != nil {
return nil, nil, err
}
defer j.Destroy()
imageAttributes, err := j.GetImageAttributes(
ctx, volOptions.MetadataPool, vi.ObjectUUID, false)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -204,6 +204,25 @@ type ImageData struct {
ImageAttributes *ImageAttributes ImageAttributes *ImageAttributes
} }
// Connection represents a real or virtual connection to a ceph cluster
// that can make changes to the journal(s).
type Connection struct {
config *CSIJournal
// connection metadata
monitors string
cr *util.Credentials
}
// Connect establishes a new connection to a ceph cluster for journal metadata.
func (cj *CSIJournal) Connect(monitors string, cr *util.Credentials) (*Connection, error) {
conn := &Connection{
config: cj,
monitors: monitors,
cr: cr,
}
return conn, nil
}
/* /*
CheckReservation checks if given request name contains a valid reservation CheckReservation checks if given request name contains a valid reservation
- If there is a valid reservation, then the corresponding UUID for the volume/snapshot is returned - If there is a valid reservation, then the corresponding UUID for the volume/snapshot is returned
@ -219,13 +238,14 @@ Return values:
there was no reservation found there was no reservation found
- error: non-nil in case of any errors - error: non-nil in case of any errors
*/ */
func (cj *CSIJournal) CheckReservation(ctx context.Context, monitors string, cr *util.Credentials, func (conn *Connection) CheckReservation(ctx context.Context,
journalPool, reqName, namePrefix, parentName, kmsConfig string) (*ImageData, error) { journalPool, reqName, namePrefix, parentName, kmsConfig string) (*ImageData, error) {
var ( var (
snapSource bool snapSource bool
objUUID string objUUID string
savedImagePool string savedImagePool string
savedImagePoolID int64 = util.InvalidPoolID savedImagePoolID int64 = util.InvalidPoolID
cj = conn.config
) )
if parentName != "" { if parentName != "" {
@ -237,7 +257,7 @@ func (cj *CSIJournal) CheckReservation(ctx context.Context, monitors string, cr
} }
// check if request name is already part of the directory omap // check if request name is already part of the directory omap
objUUIDAndPool, err := util.GetOMapValue(ctx, monitors, cr, journalPool, cj.namespace, cj.csiDirectory, objUUIDAndPool, err := util.GetOMapValue(ctx, conn.monitors, conn.cr, journalPool, cj.namespace, cj.csiDirectory,
cj.csiNameKeyPrefix+reqName) cj.csiNameKeyPrefix+reqName)
if err != nil { if err != nil {
// error should specifically be not found, for volume to be absent, any other error // error should specifically be not found, for volume to be absent, any other error
@ -265,22 +285,22 @@ func (cj *CSIJournal) CheckReservation(ctx context.Context, monitors string, cr
} }
savedImagePoolID = int64(binary.BigEndian.Uint64(buf64)) savedImagePoolID = int64(binary.BigEndian.Uint64(buf64))
savedImagePool, err = util.GetPoolName(ctx, monitors, cr, savedImagePoolID) savedImagePool, err = util.GetPoolName(ctx, conn.monitors, conn.cr, savedImagePoolID)
if err != nil { if err != nil {
if _, ok := err.(util.ErrPoolNotFound); ok { if _, ok := err.(util.ErrPoolNotFound); ok {
err = cj.UndoReservation(ctx, monitors, cr, journalPool, "", "", reqName) err = conn.UndoReservation(ctx, journalPool, "", "", reqName)
} }
return nil, err return nil, err
} }
} }
savedImageAttributes, err := cj.GetImageAttributes(ctx, monitors, cr, savedImagePool, savedImageAttributes, err := conn.GetImageAttributes(ctx, savedImagePool,
objUUID, snapSource) objUUID, snapSource)
if err != nil { if err != nil {
// error should specifically be not found, for image to be absent, any other error // error should specifically be not found, for image to be absent, any other error
// is not conclusive, and we should not proceed // is not conclusive, and we should not proceed
if _, ok := err.(util.ErrKeyNotFound); ok { if _, ok := err.(util.ErrKeyNotFound); ok {
err = cj.UndoReservation(ctx, monitors, cr, journalPool, savedImagePool, err = conn.UndoReservation(ctx, journalPool, savedImagePool,
cj.GetNameForUUID(namePrefix, objUUID, snapSource), reqName) cj.GetNameForUUID(namePrefix, objUUID, snapSource), reqName)
} }
return nil, err return nil, err
@ -344,10 +364,11 @@ Input arguments:
- volJournalPool: Pool name that holds the image/subvolume and the per-image journal (may be - volJournalPool: Pool name that holds the image/subvolume and the per-image journal (may be
different if image is created in a topology constrained pool) different if image is created in a topology constrained pool)
*/ */
func (cj *CSIJournal) UndoReservation(ctx context.Context, monitors string, cr *util.Credentials, func (conn *Connection) UndoReservation(ctx context.Context,
csiJournalPool, volJournalPool, volName, reqName string) error { csiJournalPool, volJournalPool, volName, reqName string) error {
// delete volume UUID omap (first, inverse of create order) // delete volume UUID omap (first, inverse of create order)
cj := conn.config
if volName != "" { if volName != "" {
if len(volName) < 36 { if len(volName) < 36 {
return fmt.Errorf("unable to parse UUID from %s, too short", volName) return fmt.Errorf("unable to parse UUID from %s, too short", volName)
@ -358,7 +379,7 @@ func (cj *CSIJournal) UndoReservation(ctx context.Context, monitors string, cr *
return fmt.Errorf("failed parsing UUID in %s", volName) return fmt.Errorf("failed parsing UUID in %s", volName)
} }
err := util.RemoveObject(ctx, monitors, cr, volJournalPool, cj.namespace, cj.cephUUIDDirectoryPrefix+imageUUID) err := util.RemoveObject(ctx, conn.monitors, conn.cr, volJournalPool, cj.namespace, cj.cephUUIDDirectoryPrefix+imageUUID)
if err != nil { if err != nil {
if _, ok := err.(util.ErrObjectNotFound); !ok { if _, ok := err.(util.ErrObjectNotFound); !ok {
klog.Errorf(util.Log(ctx, "failed removing oMap %s (%s)"), cj.cephUUIDDirectoryPrefix+imageUUID, err) klog.Errorf(util.Log(ctx, "failed removing oMap %s (%s)"), cj.cephUUIDDirectoryPrefix+imageUUID, err)
@ -368,7 +389,7 @@ func (cj *CSIJournal) UndoReservation(ctx context.Context, monitors string, cr *
} }
// delete the request name key (last, inverse of create order) // delete the request name key (last, inverse of create order)
err := util.RemoveOMapKey(ctx, monitors, cr, csiJournalPool, cj.namespace, cj.csiDirectory, err := util.RemoveOMapKey(ctx, conn.monitors, conn.cr, csiJournalPool, cj.namespace, cj.csiDirectory,
cj.csiNameKeyPrefix+reqName) cj.csiNameKeyPrefix+reqName)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed removing oMap key %s (%s)"), cj.csiNameKeyPrefix+reqName, err) klog.Errorf(util.Log(ctx, "failed removing oMap key %s (%s)"), cj.csiNameKeyPrefix+reqName, err)
@ -433,7 +454,7 @@ Return values:
- string: Contains the image name that was reserved for the passed in reqName - string: Contains the image name that was reserved for the passed in reqName
- error: non-nil in case of any errors - error: non-nil in case of any errors
*/ */
func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util.Credentials, func (conn *Connection) ReserveName(ctx context.Context,
journalPool string, journalPoolID int64, journalPool string, journalPoolID int64,
imagePool string, imagePoolID int64, imagePool string, imagePoolID int64,
reqName, namePrefix, parentName, kmsConf string) (string, string, error) { reqName, namePrefix, parentName, kmsConf string) (string, string, error) {
@ -441,6 +462,7 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
var ( var (
snapSource bool snapSource bool
nameKeyVal string nameKeyVal string
cj = conn.config
) )
if parentName != "" { if parentName != "" {
@ -455,7 +477,7 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
// NOTE: If any service loss occurs post creation of the UUID directory, and before // NOTE: If any service loss occurs post creation of the UUID directory, and before
// setting the request name key (csiNameKey) to point back to the UUID directory, the // setting the request name key (csiNameKey) to point back to the UUID directory, the
// UUID directory key will be leaked // UUID directory key will be leaked
volUUID, err := reserveOMapName(ctx, monitors, cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix) volUUID, err := reserveOMapName(ctx, conn.monitors, conn.cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
@ -473,7 +495,7 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
nameKeyVal = volUUID nameKeyVal = volUUID
} }
err = util.SetOMapKeyValue(ctx, monitors, cr, journalPool, cj.namespace, cj.csiDirectory, err = util.SetOMapKeyValue(ctx, conn.monitors, conn.cr, journalPool, cj.namespace, cj.csiDirectory,
cj.csiNameKeyPrefix+reqName, nameKeyVal) cj.csiNameKeyPrefix+reqName, nameKeyVal)
if err != nil { if err != nil {
return "", "", err return "", "", err
@ -481,7 +503,7 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
defer func() { defer func() {
if err != nil { if err != nil {
klog.Warningf(util.Log(ctx, "reservation failed for volume: %s"), reqName) klog.Warningf(util.Log(ctx, "reservation failed for volume: %s"), reqName)
errDefer := cj.UndoReservation(ctx, monitors, cr, imagePool, journalPool, imageName, reqName) errDefer := conn.UndoReservation(ctx, imagePool, journalPool, imageName, reqName)
if errDefer != nil { if errDefer != nil {
klog.Warningf(util.Log(ctx, "failed undoing reservation of volume: %s (%v)"), reqName, errDefer) klog.Warningf(util.Log(ctx, "failed undoing reservation of volume: %s (%v)"), reqName, errDefer)
} }
@ -492,14 +514,14 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
// and also CSI journal pool, when only the VolumeID is passed in (e.g DeleteVolume/DeleteSnapshot, // and also CSI journal pool, when only the VolumeID is passed in (e.g DeleteVolume/DeleteSnapshot,
// VolID during CreateSnapshot). // VolID during CreateSnapshot).
// Update UUID directory to store CSI request name // Update UUID directory to store CSI request name
err = util.SetOMapKeyValue(ctx, monitors, cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, err = util.SetOMapKeyValue(ctx, conn.monitors, conn.cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
cj.csiNameKey, reqName) cj.csiNameKey, reqName)
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
// Update UUID directory to store image name // Update UUID directory to store image name
err = util.SetOMapKeyValue(ctx, monitors, cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, err = util.SetOMapKeyValue(ctx, conn.monitors, conn.cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
cj.csiImageKey, imageName) cj.csiImageKey, imageName)
if err != nil { if err != nil {
return "", "", err return "", "", err
@ -507,7 +529,7 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
// Update UUID directory to store encryption values // Update UUID directory to store encryption values
if kmsConf != "" { if kmsConf != "" {
err = util.SetOMapKeyValue(ctx, monitors, cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, err = util.SetOMapKeyValue(ctx, conn.monitors, conn.cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
cj.encryptKMSKey, kmsConf) cj.encryptKMSKey, kmsConf)
if err != nil { if err != nil {
return "", "", err return "", "", err
@ -520,7 +542,7 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
journalPoolIDStr := hex.EncodeToString(buf64) journalPoolIDStr := hex.EncodeToString(buf64)
// Update UUID directory to store CSI journal pool name (prefer ID instead of name to be pool rename proof) // Update UUID directory to store CSI journal pool name (prefer ID instead of name to be pool rename proof)
err = util.SetOMapKeyValue(ctx, monitors, cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, err = util.SetOMapKeyValue(ctx, conn.monitors, conn.cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
cj.csiJournalPool, journalPoolIDStr) cj.csiJournalPool, journalPoolIDStr)
if err != nil { if err != nil {
return "", "", err return "", "", err
@ -529,7 +551,7 @@ func (cj *CSIJournal) ReserveName(ctx context.Context, monitors string, cr *util
if snapSource { if snapSource {
// Update UUID directory to store source volume UUID in case of snapshots // Update UUID directory to store source volume UUID in case of snapshots
err = util.SetOMapKeyValue(ctx, monitors, cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID, err = util.SetOMapKeyValue(ctx, conn.monitors, conn.cr, imagePool, cj.namespace, cj.cephUUIDDirectoryPrefix+volUUID,
cj.cephSnapSourceKey, parentName) cj.cephSnapSourceKey, parentName)
if err != nil { if err != nil {
return "", "", err return "", "", err
@ -549,10 +571,11 @@ type ImageAttributes struct {
} }
// GetImageAttributes fetches all keys and their values, from a UUID directory, returning ImageAttributes structure // GetImageAttributes fetches all keys and their values, from a UUID directory, returning ImageAttributes structure
func (cj *CSIJournal) GetImageAttributes(ctx context.Context, monitors string, cr *util.Credentials, pool, objectUUID string, snapSource bool) (*ImageAttributes, error) { func (conn *Connection) GetImageAttributes(ctx context.Context, pool, objectUUID string, snapSource bool) (*ImageAttributes, error) {
var ( var (
err error err error
imageAttributes *ImageAttributes = &ImageAttributes{} imageAttributes *ImageAttributes = &ImageAttributes{}
cj = conn.config
) )
if snapSource && cj.cephSnapSourceKey == "" { if snapSource && cj.cephSnapSourceKey == "" {
@ -561,7 +584,7 @@ func (cj *CSIJournal) GetImageAttributes(ctx context.Context, monitors string, c
} }
// TODO: fetch all omap vals in one call, than make multiple listomapvals // TODO: fetch all omap vals in one call, than make multiple listomapvals
imageAttributes.RequestName, err = util.GetOMapValue(ctx, monitors, cr, pool, cj.namespace, imageAttributes.RequestName, err = util.GetOMapValue(ctx, conn.monitors, conn.cr, pool, cj.namespace,
cj.cephUUIDDirectoryPrefix+objectUUID, cj.csiNameKey) cj.cephUUIDDirectoryPrefix+objectUUID, cj.csiNameKey)
if err != nil { if err != nil {
return nil, err return nil, err
@ -569,7 +592,7 @@ func (cj *CSIJournal) GetImageAttributes(ctx context.Context, monitors string, c
// image key was added at some point, so not all volumes will have this key set // image key was added at some point, so not all volumes will have this key set
// when ceph-csi was upgraded // when ceph-csi was upgraded
imageAttributes.ImageName, err = util.GetOMapValue(ctx, monitors, cr, pool, cj.namespace, imageAttributes.ImageName, err = util.GetOMapValue(ctx, conn.monitors, conn.cr, pool, cj.namespace,
cj.cephUUIDDirectoryPrefix+objectUUID, cj.csiImageKey) cj.cephUUIDDirectoryPrefix+objectUUID, cj.csiImageKey)
if err != nil { if err != nil {
// if the key was not found, assume the default key + UUID // if the key was not found, assume the default key + UUID
@ -587,7 +610,7 @@ func (cj *CSIJournal) GetImageAttributes(ctx context.Context, monitors string, c
} }
} }
imageAttributes.KmsID, err = util.GetOMapValue(ctx, monitors, cr, pool, cj.namespace, imageAttributes.KmsID, err = util.GetOMapValue(ctx, conn.monitors, conn.cr, pool, cj.namespace,
cj.cephUUIDDirectoryPrefix+objectUUID, cj.encryptKMSKey) cj.cephUUIDDirectoryPrefix+objectUUID, cj.encryptKMSKey)
if err != nil { if err != nil {
// ErrKeyNotFound means no encryption KMS was used // ErrKeyNotFound means no encryption KMS was used
@ -599,7 +622,7 @@ func (cj *CSIJournal) GetImageAttributes(ctx context.Context, monitors string, c
} }
} }
journalPoolIDStr, err := util.GetOMapValue(ctx, monitors, cr, pool, cj.namespace, journalPoolIDStr, err := util.GetOMapValue(ctx, conn.monitors, conn.cr, pool, cj.namespace,
cj.cephUUIDDirectoryPrefix+objectUUID, cj.csiJournalPool) cj.cephUUIDDirectoryPrefix+objectUUID, cj.csiJournalPool)
if err != nil { if err != nil {
if _, ok := err.(util.ErrKeyNotFound); !ok { if _, ok := err.(util.ErrKeyNotFound); !ok {
@ -616,7 +639,7 @@ func (cj *CSIJournal) GetImageAttributes(ctx context.Context, monitors string, c
} }
if snapSource { if snapSource {
imageAttributes.SourceName, err = util.GetOMapValue(ctx, monitors, cr, pool, cj.namespace, imageAttributes.SourceName, err = util.GetOMapValue(ctx, conn.monitors, conn.cr, pool, cj.namespace,
cj.cephUUIDDirectoryPrefix+objectUUID, cj.cephSnapSourceKey) cj.cephUUIDDirectoryPrefix+objectUUID, cj.cephSnapSourceKey)
if err != nil { if err != nil {
return nil, err return nil, err
@ -625,3 +648,10 @@ func (cj *CSIJournal) GetImageAttributes(ctx context.Context, monitors string, c
return imageAttributes, nil return imageAttributes, nil
} }
// Destroy frees any resources and invalidates the journal connection.
func (conn *Connection) Destroy() {
// invalidate cluster connection metadata
conn.monitors = ""
conn.cr = nil
}

View File

@ -153,8 +153,17 @@ func (ns *NodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
imageAttributes, err = volJournal.GetImageAttributes(ctx, volOptions.Monitors, cr, j, err2 := volJournal.Connect(volOptions.Monitors, cr)
volOptions.Pool, vi.ObjectUUID, false) if err2 != nil {
klog.Errorf(
util.Log(ctx, "failed to establish cluster connection: %v"),
err2)
return nil, status.Error(codes.Internal, err.Error())
}
defer j.Destroy()
imageAttributes, err = j.GetImageAttributes(
ctx, volOptions.Pool, vi.ObjectUUID, false)
if err != nil { if err != nil {
err = fmt.Errorf("error fetching image attributes for volume ID (%s) (%s)", err, volID) err = fmt.Errorf("error fetching image attributes for volume ID (%s) (%s)", err, volID)
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())

View File

@ -114,7 +114,13 @@ func checkSnapExists(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credent
return false, err return false, err
} }
snapData, err := snapJournal.CheckReservation(ctx, rbdSnap.Monitors, cr, rbdSnap.JournalPool, j, err := snapJournal.Connect(rbdSnap.Monitors, cr)
if err != nil {
return false, err
}
defer j.Destroy()
snapData, err := j.CheckReservation(ctx, rbdSnap.JournalPool,
rbdSnap.RequestName, rbdSnap.NamePrefix, rbdSnap.RbdImageName, "") rbdSnap.RequestName, rbdSnap.NamePrefix, rbdSnap.RbdImageName, "")
if err != nil { if err != nil {
return false, err return false, err
@ -135,7 +141,7 @@ func checkSnapExists(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credent
err = updateSnapWithImageInfo(ctx, rbdSnap, cr) err = updateSnapWithImageInfo(ctx, rbdSnap, cr)
if err != nil { if err != nil {
if _, ok := err.(ErrSnapNotFound); ok { if _, ok := err.(ErrSnapNotFound); ok {
err = snapJournal.UndoReservation(ctx, rbdSnap.Monitors, cr, rbdSnap.JournalPool, err = j.UndoReservation(ctx, rbdSnap.JournalPool,
rbdSnap.Pool, rbdSnap.RbdSnapName, rbdSnap.RequestName) rbdSnap.Pool, rbdSnap.RbdSnapName, rbdSnap.RequestName)
return false, err return false, err
} }
@ -174,8 +180,14 @@ func (rv *rbdVolume) Exists(ctx context.Context) (bool, error) {
kmsID = rv.KMS.GetID() kmsID = rv.KMS.GetID()
} }
imageData, err := volJournal.CheckReservation(ctx, rv.Monitors, rv.conn.Creds, rv.JournalPool, j, err := volJournal.Connect(rv.Monitors, rv.conn.Creds)
rv.RequestName, rv.NamePrefix, "", kmsID) if err != nil {
return false, err
}
defer j.Destroy()
imageData, err := j.CheckReservation(
ctx, rv.JournalPool, rv.RequestName, rv.NamePrefix, "", kmsID)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -205,7 +217,7 @@ func (rv *rbdVolume) Exists(ctx context.Context) (bool, error) {
err = updateVolWithImageInfo(ctx, rv, rv.conn.Creds) err = updateVolWithImageInfo(ctx, rv, rv.conn.Creds)
if err != nil { if err != nil {
if _, ok := err.(ErrImageNotFound); ok { if _, ok := err.(ErrImageNotFound); ok {
err = volJournal.UndoReservation(ctx, rv.Monitors, rv.conn.Creds, rv.JournalPool, rv.Pool, err = j.UndoReservation(ctx, rv.JournalPool, rv.Pool,
rv.RbdImageName, rv.RequestName) rv.RbdImageName, rv.RequestName)
return false, err return false, err
} }
@ -246,8 +258,15 @@ func reserveSnap(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credentials
return err return err
} }
snapUUID, rbdSnap.RbdSnapName, err = snapJournal.ReserveName(ctx, rbdSnap.Monitors, cr, rbdSnap.JournalPool, journalPoolID, j, err := snapJournal.Connect(rbdSnap.Monitors, cr)
rbdSnap.Pool, imagePoolID, rbdSnap.RequestName, rbdSnap.NamePrefix, rbdSnap.RbdImageName, "") if err != nil {
return err
}
defer j.Destroy()
snapUUID, rbdSnap.RbdSnapName, err = j.ReserveName(
ctx, rbdSnap.JournalPool, journalPoolID, rbdSnap.Pool, imagePoolID,
rbdSnap.RequestName, rbdSnap.NamePrefix, rbdSnap.RbdImageName, "")
if err != nil { if err != nil {
return err return err
} }
@ -318,8 +337,15 @@ func reserveVol(ctx context.Context, rbdVol *rbdVolume, rbdSnap *rbdSnapshot, cr
kmsID = rbdVol.KMS.GetID() kmsID = rbdVol.KMS.GetID()
} }
imageUUID, rbdVol.RbdImageName, err = volJournal.ReserveName(ctx, rbdVol.Monitors, cr, rbdVol.JournalPool, journalPoolID, j, err := volJournal.Connect(rbdVol.Monitors, cr)
rbdVol.Pool, imagePoolID, rbdVol.RequestName, rbdVol.NamePrefix, "", kmsID) if err != nil {
return err
}
defer j.Destroy()
imageUUID, rbdVol.RbdImageName, err = j.ReserveName(
ctx, rbdVol.JournalPool, journalPoolID, rbdVol.Pool, imagePoolID,
rbdVol.RequestName, rbdVol.NamePrefix, "", kmsID)
if err != nil { if err != nil {
return err return err
} }
@ -338,15 +364,28 @@ func reserveVol(ctx context.Context, rbdVol *rbdVolume, rbdSnap *rbdSnapshot, cr
// undoSnapReservation is a helper routine to undo a name reservation for rbdSnapshot // undoSnapReservation is a helper routine to undo a name reservation for rbdSnapshot
func undoSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credentials) error { func undoSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, cr *util.Credentials) error {
err := snapJournal.UndoReservation(ctx, rbdSnap.Monitors, cr, rbdSnap.JournalPool, rbdSnap.Pool, j, err := snapJournal.Connect(rbdSnap.Monitors, cr)
rbdSnap.RbdSnapName, rbdSnap.RequestName) if err != nil {
return err
}
defer j.Destroy()
err = j.UndoReservation(
ctx, rbdSnap.JournalPool, rbdSnap.Pool, rbdSnap.RbdSnapName,
rbdSnap.RequestName)
return err return err
} }
// undoVolReservation is a helper routine to undo a name reservation for rbdVolume // undoVolReservation is a helper routine to undo a name reservation for rbdVolume
func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error { func undoVolReservation(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) error {
err := volJournal.UndoReservation(ctx, rbdVol.Monitors, cr, rbdVol.JournalPool, rbdVol.Pool, j, err := volJournal.Connect(rbdVol.Monitors, cr)
if err != nil {
return err
}
defer j.Destroy()
err = j.UndoReservation(ctx, rbdVol.JournalPool, rbdVol.Pool,
rbdVol.RbdImageName, rbdVol.RequestName) rbdVol.RbdImageName, rbdVol.RequestName)
return err return err

View File

@ -391,8 +391,14 @@ func genSnapFromSnapID(ctx context.Context, rbdSnap *rbdSnapshot, snapshotID str
} }
rbdSnap.JournalPool = rbdSnap.Pool rbdSnap.JournalPool = rbdSnap.Pool
imageAttributes, err := snapJournal.GetImageAttributes(ctx, rbdSnap.Monitors, j, err := snapJournal.Connect(rbdSnap.Monitors, cr)
cr, rbdSnap.Pool, vi.ObjectUUID, true) if err != nil {
return err
}
defer j.Destroy()
imageAttributes, err := j.GetImageAttributes(
ctx, rbdSnap.Pool, vi.ObjectUUID, true)
if err != nil { if err != nil {
return err return err
} }
@ -453,8 +459,14 @@ func genVolFromVolID(ctx context.Context, volumeID string, cr *util.Credentials,
} }
rbdVol.JournalPool = rbdVol.Pool rbdVol.JournalPool = rbdVol.Pool
imageAttributes, err := volJournal.GetImageAttributes(ctx, rbdVol.Monitors, cr, j, err := volJournal.Connect(rbdVol.Monitors, cr)
rbdVol.Pool, vi.ObjectUUID, false) if err != nil {
return nil, err
}
defer j.Destroy()
imageAttributes, err := j.GetImageAttributes(
ctx, rbdVol.Pool, vi.ObjectUUID, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }