From b89f0dc94bd83857b187a84a0d4ae127000f0b1c Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 16 Jul 2026 20:47:57 +0200 Subject: fusefrontend: LockSharedStorage: loop on EINTR, add debug output --- internal/fusefrontend/file_lock.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'internal/fusefrontend') diff --git a/internal/fusefrontend/file_lock.go b/internal/fusefrontend/file_lock.go index f440754..c2965ae 100644 --- a/internal/fusefrontend/file_lock.go +++ b/internal/fusefrontend/file_lock.go @@ -4,6 +4,7 @@ import ( "golang.org/x/sys/unix" "github.com/rfjakob/gocryptfs/v2/internal/syscallcompat" + "github.com/rfjakob/gocryptfs/v2/internal/tlog" ) // SharedStorageLock conveniently wraps F_OFD_SETLKW. @@ -17,7 +18,7 @@ import ( // * unix.F_UNLCK (unlock) // // This function is a no-op if args.SharedStorage == false. -func (f *File) LockSharedStorage(lkType int16, lkStart int64, lkLen int64) error { +func (f *File) LockSharedStorage(lkType int16, lkStart int64, lkLen int64) (err error) { if !f.rootNode.args.SharedStorage { return nil } @@ -27,7 +28,21 @@ func (f *File) LockSharedStorage(lkType int16, lkStart int64, lkLen int64) error Start: lkStart, Len: lkLen, } - return unix.FcntlFlock(uintptr(f.intFd()), syscallcompat.F_OFD_SETLKW, &lk) + err = unix.FcntlFlock(uintptr(f.intFd()), syscallcompat.F_OFD_SETLK, &lk) + switch err { + case unix.EACCES, unix.EAGAIN: + tlog.Debug.Printf("LockSharedStorage: waiting for lock") + case nil: + return + } + for { + err = unix.FcntlFlock(uintptr(f.intFd()), syscallcompat.F_OFD_SETLKW, &lk) + if err == unix.EINTR { + tlog.Debug.Printf("LockSharedStorage: looping on EINTR") + continue + } + return + } } // UnlockSharedStorage calls LockSharedStorage with unix.F_UNLCK. -- cgit v1.2.3