Re: [PATCH v2 0/2] cephfs: prepare for changes to VFS locking
From: Xiubo Li
Date: Tue Nov 10 2026 - 02:04:44 EST
On Tue, Nov 10, 2026 at 07:20:23AM +1100, NeilBrown wrote:
> @@ -2230,7 +2226,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,
> if (inode_state_read_once(in) & I_NEW)
> unlock_new_inode(in);
>
> - if (d_really_is_negative(dn)) {
> + if (d_in_lookup(dn) || d_really_is_negative(dn)) {
Nit: An in-lookup dentry is always negative: __d_instantiate() warns on one,
and __d_add() ends the lookup before it sets the inode. Here dn can only
be in-lookup if d_alloc_trylock() has just allocated it for us, so
d_really_is_negative(dn) already covers that case and the old test could
stay as it was. Feel free to keep it if you prefer it spelled out.
Otherwise this looks good to me.
Today ceph_readdir() runs with i_rwsem held exclusive (WRAP_DIR_ITER),
so the -EWOULDBLOCK branch cannot be reached yet. To exercise it, I ran
a test-only build that drops the parent's shared lock in ceph_lookup()
and sleeps 300ms while the dentry is in-lookup, which is what the lookup
side will look like once d_alloc_parallel() moves above i_rwsem. In
that build, readdir replies met the in-lookup dentries
(d_alloc_trylock() returned -EWOULDBLOCK 64 times over 4 rounds), and
afterwards:
- the first and the second (cached) listing both showed every name,
- every lookup returned the inode the other client sees,
- there were no duplicate hashed dentries in the directory (checked
with drgn),
- the MDS cap count matched,
- KASAN and lockdep stayed quiet.
Reviewed-by: Xiubo Li <xiubo.li@xxxxxxxxx>
Tested-by: Xiubo Li <xiubo.li@xxxxxxxxx>
Thanks
Xiubo
NeilBrown <neilb@xxxxxxxxxxx> 于2026年11月9日周一 21:25写道:
>
> This v2 drops 3/3 which was deprecating d_add() - there is no rush for
> that so I'm not going to push it at present.
> It also fixes the first patch to increment "skipped" when d_alloc_trylock()
> returns -EWOULDBLOCK.
>
> The VFS patches that this series depends on are upstream, so this can
> land in any tree.
>
> Thanks,
> NeilBrown
>
> original intro:
> I am working on changes to directory locking. The medium term goal is
> to lift d_alloc_parallel() locking above i_rwsem, so d_alloc_paralle()
> can be run unlocked, and consequently cannot be called when ->i_rwsem is
> held.
>
> The requires:
> 1/ that d_alloc_parallel() not be called while i_rwsem is held and also
> that d_alloc()/d_splice_alias() not be used (unless the filesystems
> doesn't support creating objects).
> cephfs uses d_alloc()/d_splice_alias() when priming the dcache from
> the results of readdir. A new interface d_alloc_trylock()
> is now available and can be used instead.
>
> 2/ a dentry must not be d_drop()ed while an operation is ongoing, as an
> unlocked d_alloc_parallel() would then be able to create a new
> dentry with the same name. cephfs calls d_drop() in couple of places
> before d_splice_alias() but this is no longer needed as d_splice_alias()
> handles spliced aliases now.
>
>
> [PATCH v2 1/2] cephfs: Use d_alloc_trylock() in
> [PATCH v2 2/2] cephfs: Don't d_drop() before d_splice_alias()
>