Skip to content

Commit

Permalink
Set object lock for volumes for cephfs encryption
Browse files Browse the repository at this point in the history
Signed-off-by: Sunnatillo <sunnat.samadov@est.tech>
  • Loading branch information
Sunnatillo committed Jun 27, 2024
1 parent 85f48dd commit 2b27638
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 1,348 deletions.
55 changes: 13 additions & 42 deletions internal/cephfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ import (
"github.com/ceph/ceph-csi/internal/util"
"github.com/ceph/ceph-csi/internal/util/fscrypt"
"github.com/ceph/ceph-csi/internal/util/log"
"github.com/ceph/ceph-csi/internal/util/radosmutex"
"github.com/ceph/ceph-csi/internal/util/radosmutex/retryoptions"
"github.com/ceph/ceph-csi/internal/util/reftracker/radoswrapper"

"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes"
Expand All @@ -55,10 +52,6 @@ type NodeServer struct {
healthChecker hc.Manager
}

func volumeRadosMutexName(volumeID string) string {
return "rados-mutex-" + volumeID
}

func getCredentialsForVolume(
volOptions *store.VolumeOptions,
secrets map[string]string,
Expand Down Expand Up @@ -121,7 +114,7 @@ func validateSnapshotBackedVolCapability(volCap *csi.VolumeCapability) error {
mode := volCap.GetAccessMode().GetMode()
if mode != csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY &&
mode != csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY {
return status.Error(codes.InvalidArgument,
return status.Error(coLockVolumedes.InvalidArgument,
"snapshot-backed volume supports only read-only access mode")
}

Expand All @@ -136,18 +129,17 @@ func maybeUnlockFileEncryption(
volID fsutil.VolumeID,
) error {

retryoptions := retryoptions.RetryOptions{
MaxAttempts: 20,
SleepDuration: 2000 * time.Microsecond,
}

lockName := volumeRadosMutexName(string(volID))

if volOptions.IsEncrypted() == false {
return nil
}
// Define Mutex Lock variables
lockName := string(volID) + "-mutexLock"
lockCookie := lockName + "coockie"
lockDesc := "Lock for" + string(volID)
lockDuration := 40 * time.Second
var flags byte = 0

log.ErrorLog(ctx, "Creating lock for the following volume ID %s", lockName)
log.DebugLog(ctx, "Creating lock for the following volume ID %s", volID)

ioctx, err := volOptions.GetConnection().GetIoctx(volOptions.MetadataPool)
if err != nil {
Expand All @@ -157,43 +149,22 @@ func maybeUnlockFileEncryption(
}
defer ioctx.Destroy()

ioctx.SetNamespace(fsutil.RadosNamespace)
ioctxW := radoswrapper.NewIOContext(ioctx)

created, err := radosmutex.CreateOrAquireLock(
ctx,
ioctxW,
lockName,
"This is some pod here",
retryoptions,
)
res, err := ioctx.LockExclusive(volOptions.VolID, lockName, string(lockCookie), lockDesc, lockDuration, &flags)
if err != nil {
log.ErrorLog(ctx, "failed to aquire lock %s: %v", lockName, err)

return err
return fmt.Errorf("Failed to lock volume ID %v: %s", volID, err)
}
log.DebugLog(ctx, "Lock successfully created for the volume ID %s", volID)

if created {
if res == 0 {
defer func() {
log.DebugLog(ctx, "Releasing following lock %s", lockName)

var deleted bool
deleted, err = radosmutex.ReleaseLock(
ctx,
ioctxW,
lockName,
"This is some pod here",
)
_, err = ioctx.Unlock(string(volID), lockName, lockCookie)

if err != nil {
log.ErrorLog(ctx, "failed to release following lock, this will lead to orphan lock %s: %v",
lockName, err)
}
if !deleted {
log.ErrorLog(ctx, "failed to release following lock, this will lead to orphan lock %s",
lockName)
}

}()

log.DebugLog(ctx, "cephfs: unlocking fscrypt on volume %q path %s", volID, stagingTargetPath)
Expand Down
84 changes: 0 additions & 84 deletions internal/util/radosmutex/errors/errors.go

This file was deleted.

97 changes: 0 additions & 97 deletions internal/util/radosmutex/lock/lock.go

This file was deleted.

96 changes: 0 additions & 96 deletions internal/util/radosmutex/lock/lock_test.go

This file was deleted.

Loading

0 comments on commit 2b27638

Please sign in to comment.