On Wed, Aug 13, 2025 at 1:53 AM NeilBrown <n...@brown.name> wrote: > > Proposed changes to directory-op locking will lock the dentry rather > than the whole directory. So the dentry will need to be unlocked. > > vfs_mkdir() consumes the dentry on error, so there will be no dentry to > be unlocked.
Why does it need to consume the dentry on error? Why can't it leave the state as is on error and let the caller handle its own cleanup? > > So this patch changes vfs_mkdir() to unlock on error as well as > releasing the dentry. This requires various other functions in various > callers to also unlock on error - particularly in nfsd and overlayfs. > > At present this results in some clumsy code. Once the transition to > dentry locking is complete the clumsiness will be gone. > > Callers of vfs_mkdir() in ecrypytfs, nfsd, xfs, cachefiles, and > overlayfs are changed to make the new behaviour. I will let Al do the vfs review of this and will speak up on behalf of the vfs users of the API One problem with a change like this - subtle change to semantics with no function prototype change is that it is a "backporting land mine" both AUTOSEL and human can easily not be aware of the subtle semantic change in a future time when a fix is being backported across this semantic change. Now there was a prototype change in c54b386969a5 ("VFS: Change vfs_mkdir() to return the dentry.") in v6.15 not long ago, so (big) if this semantic change (or the one that follows it) both get into the 2025 LTS kernel, we are in less of a problem, but if they don't, it's kind of a big problem for the stability of those subsystems in LTS kernels IMO - not being able to use "cleanly applies and build" as an indication to "likelihood of a correct backport". and now onto review of ovl code... > diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c > index 70b8687dc45e..24f7e28b9a4f 100644 > --- a/fs/overlayfs/dir.c > +++ b/fs/overlayfs/dir.c > @@ -162,14 +162,18 @@ int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct > dentry *dir, > goto out; > } > > +/* dir will be unlocked on return */ > struct dentry *ovl_create_real(struct ovl_fs *ofs, struct dentry *parent, > - struct dentry *newdentry, struct ovl_cattr > *attr) > + struct dentry *newdentry_arg, struct ovl_cattr > *attr) > { > struct inode *dir = parent->d_inode; > + struct dentry *newdentry __free(dentry_lookup) = newdentry_arg; > int err; > > - if (IS_ERR(newdentry)) > + if (IS_ERR(newdentry)) { > + inode_unlock(dir); > return newdentry; > + } > > err = -ESTALE; > if (newdentry->d_inode) > @@ -213,12 +217,9 @@ struct dentry *ovl_create_real(struct ovl_fs *ofs, > struct dentry *parent, > err = -EIO; > } > out: > - if (err) { > - if (!IS_ERR(newdentry)) > - dput(newdentry); > + if (err) > return ERR_PTR(err); > - } > - return newdentry; > + return dget(newdentry); > } > > struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct dentry *workdir, > @@ -228,7 +229,6 @@ struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct > dentry *workdir, > inode_lock(workdir->d_inode); > ret = ovl_create_real(ofs, workdir, > ovl_lookup_temp(ofs, workdir), attr); > - inode_unlock(workdir->d_inode); Things like that putting local code out of balance make my life as maintainer very hard. I prefer that you leave the explicit dir unlock in the callers until the time that you change the create() API not require holding the dir lock. I don't even understand how you changed the call semantics to an ovl function that creates a directory or non-directory when your patch only changes mkdir semantics, but I don't want to know, because even if this works and I cannot easily understand how, then I do not want the confusing semantics in ovl code. I think you should be able to scope ovl_lookup_temp() with dentry_lookup*() { } done_dentry_lookup() and use whichever semantics you like about dir lock inside the helpers, as long as ovl code looks and feels balanced. > return ret; > } > > @@ -336,7 +336,6 @@ static int ovl_create_upper(struct dentry *dentry, struct > inode *inode, > ovl_lookup_upper(ofs, dentry->d_name.name, > upperdir, > dentry->d_name.len), > attr); > - inode_unlock(udir); > if (IS_ERR(newdentry)) > return PTR_ERR(newdentry); > > diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h > index 4f84abaa0d68..238c26142318 100644 > --- a/fs/overlayfs/overlayfs.h > +++ b/fs/overlayfs/overlayfs.h > @@ -250,6 +250,7 @@ static inline struct dentry *ovl_do_mkdir(struct ovl_fs > *ofs, > > ret = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode); > pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, > PTR_ERR_OR_ZERO(ret)); > + /* Note: dir will have been unlocked on failure */ > return ret; > } > > diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c > index df85a76597e9..5a4b0a05139c 100644 > --- a/fs/overlayfs/super.c > +++ b/fs/overlayfs/super.c > @@ -328,11 +328,13 @@ static struct dentry *ovl_workdir_create(struct ovl_fs > *ofs, > } > > work = ovl_do_mkdir(ofs, dir, work, attr.ia_mode); > - inode_unlock(dir); > err = PTR_ERR(work); > if (IS_ERR(work)) > goto out_err; > > + dget(work); /* Need to return this */ > + > + done_dentry_lookup(work); Another weird example. I would expect that dentry_lookup*()/done_dentry_lookup() would be introduced to users in the same commit, so the code always remains balanced. All in all, I think you should drop this patch from the series altogether and drop dir unlock from callers only later after they have been converted to use the new API. Am I misunderstanding something that prevents you from doing that? Thanks, Amir.