From c901032afe02fa0612e2a70aa8e809e4855e0a8b Mon Sep 17 00:00:00 2001 From: jkoberg Date: Fri, 27 Oct 2023 11:25:06 +0200 Subject: [PATCH] release an expired lock on stat Signed-off-by: jkoberg --- .../unreleased/release-lock-when-expired.md | 5 ++++ pkg/storage/utils/decomposedfs/node/locks.go | 30 ++----------------- 2 files changed, 7 insertions(+), 28 deletions(-) create mode 100644 changelog/unreleased/release-lock-when-expired.md diff --git a/changelog/unreleased/release-lock-when-expired.md b/changelog/unreleased/release-lock-when-expired.md new file mode 100644 index 0000000000..11b280fb62 --- /dev/null +++ b/changelog/unreleased/release-lock-when-expired.md @@ -0,0 +1,5 @@ +Bugfix: Release lock when expired + +Release an expired lock when stating the resource + +https://github.com/cs3org/reva/pull/4291 diff --git a/pkg/storage/utils/decomposedfs/node/locks.go b/pkg/storage/utils/decomposedfs/node/locks.go index 65dafc0b2d..b968ef3aa4 100644 --- a/pkg/storage/utils/decomposedfs/node/locks.go +++ b/pkg/storage/utils/decomposedfs/node/locks.go @@ -276,38 +276,12 @@ func (n *Node) CheckLock(ctx context.Context) error { } func readLocksIntoOpaque(ctx context.Context, n *Node, ri *provider.ResourceInfo) error { - - // ensure parent path exists - if err := os.MkdirAll(filepath.Dir(n.InternalPath()), 0700); err != nil { - return errors.Wrap(err, "Decomposedfs: error creating parent folder for lock") - } - fileLock, err := filelocks.AcquireReadLock(n.InternalPath()) - + lock, err := n.ReadLock(ctx, false) if err != nil { + appctx.GetLogger(ctx).Error().Err(err).Msg("Decomposedfs: could not read lock") return err } - defer func() { - rerr := filelocks.ReleaseLock(fileLock) - - // if err is non nil we do not overwrite that - if err == nil { - err = rerr - } - }() - - f, err := os.Open(n.LockFilePath()) - if err != nil { - appctx.GetLogger(ctx).Error().Err(err).Msg("Decomposedfs: could not open lock file") - return err - } - defer f.Close() - - lock := &provider.Lock{} - if err := json.NewDecoder(f).Decode(lock); err != nil { - appctx.GetLogger(ctx).Error().Err(err).Msg("Decomposedfs: could not read lock file") - } - // reencode to ensure valid json var b []byte if b, err = json.Marshal(lock); err != nil {