From 12130123aca84abc4b4a5ffa1672ca6f7fe9283b Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 17 Mar 2020 13:57:01 +0100 Subject: [PATCH] rbd: do not pass Credentials to checkVolExists() Signed-off-by: Niels de Vos --- internal/rbd/controllerserver.go | 8 +++++++- internal/rbd/rbd_journal.go | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 60d42b06e..8ce3c801f 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -156,7 +156,13 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } defer cs.VolumeLocks.Release(req.GetName()) - found, err := checkVolExists(ctx, rbdVol, cr) + err = rbdVol.Connect(cr) + if err != nil { + klog.Errorf(util.Log(ctx, "failed to connect to volume %v: %v"), rbdVol.RbdImageName, err) + return nil, status.Error(codes.Internal, err.Error()) + } + + found, err := rbdVol.Exists(ctx) if err != nil { if _, ok := err.(ErrVolNameConflict); ok { return nil, status.Error(codes.AlreadyExists, err.Error()) diff --git a/internal/rbd/rbd_journal.go b/internal/rbd/rbd_journal.go index f61062f93..24233cce6 100644 --- a/internal/rbd/rbd_journal.go +++ b/internal/rbd/rbd_journal.go @@ -163,7 +163,7 @@ volume names as requested by the CSI drivers. Hence, these need to be invoked on respective CSI snapshot or volume name based locks are held, as otherwise racy access to these omaps may end up leaving the omaps in an inconsistent state. */ -func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials) (bool, error) { +func (rbdVol *rbdVolume) Exists(ctx context.Context) (bool, error) { err := validateRbdVol(rbdVol) if err != nil { return false, err @@ -174,7 +174,7 @@ func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials kmsID = rbdVol.KMS.GetID() } - imageData, err := volJournal.CheckReservation(ctx, rbdVol.Monitors, cr, rbdVol.JournalPool, + imageData, err := volJournal.CheckReservation(ctx, rbdVol.Monitors, rbdVol.conn.Creds, rbdVol.JournalPool, rbdVol.RequestName, rbdVol.NamePrefix, "", kmsID) if err != nil { return false, err @@ -202,10 +202,10 @@ func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials // save it for size checks before fetching image data requestSize := rbdVol.VolSize // Fetch on-disk image attributes and compare against request - err = updateVolWithImageInfo(ctx, rbdVol, cr) + err = updateVolWithImageInfo(ctx, rbdVol, rbdVol.conn.Creds) if err != nil { if _, ok := err.(ErrImageNotFound); ok { - err = volJournal.UndoReservation(ctx, rbdVol.Monitors, cr, rbdVol.JournalPool, rbdVol.Pool, + err = volJournal.UndoReservation(ctx, rbdVol.Monitors, rbdVol.conn.Creds, rbdVol.JournalPool, rbdVol.Pool, rbdVol.RbdImageName, rbdVol.RequestName) return false, err } @@ -221,7 +221,7 @@ func checkVolExists(ctx context.Context, rbdVol *rbdVolume, cr *util.Credentials // TODO: We should also ensure image features and format is the same // found a volume already available, process and return it! - rbdVol.VolID, err = util.GenerateVolID(ctx, rbdVol.Monitors, cr, imageData.ImagePoolID, rbdVol.Pool, + rbdVol.VolID, err = util.GenerateVolID(ctx, rbdVol.Monitors, rbdVol.conn.Creds, imageData.ImagePoolID, rbdVol.Pool, rbdVol.ClusterID, imageUUID, volIDVersion) if err != nil { return false, err