mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rbd: use ioctx locks for key rotation
Signed-off-by: Niraj Yadav <niryadav@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
0bed833ef7
commit
4445247690
@ -22,9 +22,11 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
kmsapi "github.com/ceph/ceph-csi/internal/kms"
|
||||
"github.com/ceph/ceph-csi/internal/util"
|
||||
"github.com/ceph/ceph-csi/internal/util/lock"
|
||||
"github.com/ceph/ceph-csi/internal/util/log"
|
||||
|
||||
librbd "github.com/ceph/go-ceph/rbd"
|
||||
@ -463,6 +465,28 @@ func (rv *rbdVolume) RotateEncryptionKey(ctx context.Context) error {
|
||||
return errors.New("key rotation not supported for unencrypted device")
|
||||
}
|
||||
|
||||
// Call open Ioctx to create a new ioctx object
|
||||
// if the obj already exists, no error is returned
|
||||
err = rv.openIoctx()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open ioctx, err: %w", err)
|
||||
}
|
||||
|
||||
// Lock params
|
||||
lockName := rv.VolID + "-mutexlock"
|
||||
lockDesc := "Key rotation mutex lock for " + rv.VolID
|
||||
lockDuration := 3 * time.Minute
|
||||
lockCookie := rv.VolID + "-enc-key-rotate"
|
||||
|
||||
// Acquire the exclusive lock based on vol id
|
||||
lck := lock.NewLock(rv.ioctx, rv.VolID, lockName, lockCookie, lockDesc, lockDuration)
|
||||
err = lck.LockExclusive(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer lck.Unlock(ctx)
|
||||
log.DebugLog(ctx, "acquired ioctx lock for vol id: %s", rv.VolID)
|
||||
|
||||
// Get the device path for the underlying image
|
||||
useNbd := rv.Mounter == rbdNbdMounter && hasNBD
|
||||
devicePath, found := waitForPath(ctx, rv.Pool, rv.RadosNamespace, rv.RbdImageName, 1, useNbd)
|
||||
|
Reference in New Issue
Block a user