From 032fb228ddba3731f1d89dcadf115121cd35a7f9 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 2 Jul 2020 14:18:12 +0530 Subject: [PATCH] rbd: take lock on parent image during snapshotcreate we need to take lock on parent rbd image when we are creating a snapshot from it, if the user tries to delete/resize the rbd image when we are taking snapshots,we may face issues. if the volume lock is present on the rbd image, the user cannot resize the rbd image nor delete the rbd image. Signed-off-by: Madhu Rajanna --- internal/rbd/controllerserver.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index dd3a442d3..7e41e23ac 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -671,6 +671,13 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS } defer cs.SnapshotLocks.Release(req.GetName()) + // Take lock on parent rbd image + if acquired := cs.VolumeLocks.TryAcquire(rbdSnap.SourceVolumeID); !acquired { + klog.Errorf(util.Log(ctx, util.VolumeOperationAlreadyExistsFmt), rbdSnap.SourceVolumeID) + return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, rbdSnap.SourceVolumeID) + } + defer cs.VolumeLocks.Release(rbdSnap.SourceVolumeID) + // Need to check for already existing snapshot name, and if found // check for the requested source volume id and already allocated source volume id found, err := checkSnapCloneExists(ctx, rbdVol, rbdSnap, cr)