11=================================================================================
2- WHY FUSE CONVERTS -EAGAIN TO AOP_TRUNCATED_PAGE IN fuse_read_folio()
2+ WHY FUSE CONVERTS -EDEADLK TO AOP_TRUNCATED_PAGE IN fuse_read_folio()
33=================================================================================
44
55TLDR: To prevent ABBA deadlock between page locks and DLM (cluster) locks.
@@ -292,21 +292,22 @@ Core-0: Application reading from FUSE filesystem
292292 │ Sends FUSE_READ to userspace daemon
293293 │ Daemon may need to acquire cluster lock
294294 │
295- └─ Might return -EAGAIN if DLM detects possible
295+ └─ Might return -EDEADLK if DLM detects possible
296296 deadlock due to concurrant page invalidation
297+ - For now -EAGAIN handled the same
297298
298299
299300─────────────────────────────────────────────────────────────────────────────
300301WHY FUSE NEEDS THIS CONVERSION
301302─────────────────────────────────────────────────────────────────────────────
302303
303- When fuse_simple_request() returns -EAGAIN :
304+ When fuse_simple_request() returns -EDEADLK :
304305 - Userspace FUSE daemon encountered transient failure
305306 - Could be: cluster lock contention, timeout, daemon busy
306307 - The page might be stale/modified during the wait
307308 - Page lock is STILL HELD at this point
308309
309- If -EAGAIN were returned directly:
310+ If -EDEADLK were returned directly:
310311 ❌ VFS would see error and fail the read
311312 ❌ Page would remain locked
312313 ❌ No retry mechanism triggered
@@ -342,11 +343,12 @@ Location: fs/fuse/file.c:947-964
342343 out:
343344 // LINE 962: ✓ CRITICAL - Always unlocks page before returning
344345 folio_unlock(folio);
345- return err; // Returns AOP_TRUNCATED_PAGE if -EAGAIN occurred
346+ return err; // Returns AOP_TRUNCATED_PAGE if -EDEADLK occurred
346347 }
347348
348349This matches OCFS2's pattern:
349350 1. Detect lock contention (-EAGAIN from daemon)
351+ - Note: confusing that OCFS2 uses -EAGAIN instead of -EDEADLK
350352 2. Unlock the page (line 962)
351353 3. Return AOP_TRUNCATED_PAGE
352354 4. VFS retries the operation
@@ -372,7 +374,7 @@ Callers in mm/filemap.c handle it consistently:
372374 - do_filemap_fault(): "if (error == AOP_TRUNCATED_PAGE) goto retry_find;"
373375
374376=================================================================================
375- WHY NOT JUST RETURN -EAGAIN?
377+ WHY NOT JUST RETURN -EDEADLK (- EAGAIN) ?
376378=================================================================================
377379
378380From OCFS2 comments (fs/ocfs2/dlmglue.c:2555-2560):
@@ -434,7 +436,7 @@ T2 Call: ocfs2_read_folio() DLM downconvert starts
434436 Lock: DLM inode lock
435437
436438T3 Try: DLM lock (NONBLOCK) Want: page lock
437- Returns: -EAGAIN ❌ BLOCKED (held by Core-0)
439+ Returns: -EDEADLK ❌ BLOCKED (held by Core-0)
438440
439441T4 ✓ Unlock: page lock ✓ Acquires: page lock
440442 Return: AOP_TRUNCATED_PAGE Continues: reclaim work
@@ -517,10 +519,10 @@ Caller 3: do_filemap_fault() - lines 3542-3543
517519Effect: Re-handles the page fault from scratch
518520
519521=================================================================================
520- SUMMARY: Why -EAGAIN → AOP_TRUNCATED_PAGE is Essential
522+ SUMMARY: Why -EDEADLK → AOP_TRUNCATED_PAGE is Essential
521523=================================================================================
522524
523- The conversion -EAGAIN → AOP_TRUNCATED_PAGE in fuse_read_folio() is necessary:
525+ The conversion -EDEADLK → AOP_TRUNCATED_PAGE in fuse_read_folio() is necessary:
524526
5255271. **Prevent Deadlock**: Avoids page lock vs cluster lock ABBA deadlock
526528 - Core-0 holds page lock, wants DLM lock
@@ -535,7 +537,7 @@ The conversion -EAGAIN → AOP_TRUNCATED_PAGE in fuse_read_folio() is necessary:
5355373. **Enable Retry**: Uses VFS's built-in retry mechanism properly
536538 - AOP_TRUNCATED_PAGE is understood by mm/filemap.c
537539 - Triggers automatic retry loops at multiple call sites
538- - -EAGAIN alone would just fail the operation
540+ - -EDEADLK alone would just fail the operation
539541
5405424. **Ensure Fairness**: Allows fair lock acquisition through retry cycle
541543 - Other threads get chance to acquire locks
@@ -553,7 +555,7 @@ Core-0 (Read Path):
553555 - Entry: filemap_read() [mm/filemap.c:2675]
554556 - Page lock: folio_trylock() [mm/filemap.c:2466]
555557 - FUSE read: fuse_do_readfolio() [fs/fuse/file.c:905]
556- - -EAGAIN conversion [fs/fuse/file.c:934-935]
558+ - -EDEADLK conversion [fs/fuse/file.c:934-935]
557559 - Page unlock: folio_unlock() [fs/fuse/file.c:962]
558560
559561Core-1 (Reclaim Path):
0 commit comments