Re: [PATCH] nilfs2: fix checkpoint root lifetime on sysfs errors

From: Aldo Ariel Panzardo

Date: Wed Sep 16 2026 - 19:47:11 EST


Hi Slava,

Good point about the wait_for_completion under the lock. There is no
circular dependency (the release callback only calls complete() without
taking ns_cptree_lock), but holding the mutex during an unbounded wait
is unnecessary. In v3 I move wait_for_completion() and kfree() after
the mutex_unlock() in nilfs_put_root(). By that point rb_erase() has
already removed the root from the tree and the refcount is zero, so no
concurrent lookup can find it and no other put can race.

Regarding rwsem: the kernel does not provide a combined
refcount_dec_and_rwsem_lock() helper, so nilfs_put_root() would need
the two-stage refcount_dec_not_one() / down_write() /
refcount_dec_and_test() pattern. That is doable, but the lookup
contention on ns_cptree is minimal (mount, segctor, recovery), so the
added complexity does not seem justified here.

v3 follows.

Aldo