* [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking
@ 2026-11-29 21:21 NeilBrown
2026-11-29 21:21 ` [PATCH v4 1/8] coda: don't d_drop() early NeilBrown
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
So v3 was a bit of a disaster - sorry about that. I hope no-one spent
much time looking at it :-(
But I'm feeling better about this one - which doesn't try to do as much.
I've fixed up a whole bunch of problems that sashiko.dev found in the
afs patches, and made the procfs change a lot simpler. Hopefully it
isn't too simple - it does mean iterate_shared can sometimes do more
work, but I suspect the cost will be small.
I now understand the context of d_add_ci() and realise that it has
significant implications on my design. Any filesystem that uses
d_add_ci() cannot cache negative dentries because (it seems) there is no
canonical name for an equivalence classes of case-insensitive names.
And that means I cannot lock a "name" in a directory by locking the
corresponding dentry, at least not when the name doesn't exist yet.
I think I have a solution for d_add_ci(), but there is some non-trival
prep work needed so I'll delay that for now.
So here are tiny changes to coda and hostfs, several changes to afs, and the afore-mentioned change to readdir in procfs.
The goal is to
a: not drop dentries while an operation is on-going
b: not call d_alloc_parallel() while holding i_rwsem on the parent.
I'll follow up if sasiko.dev is happy, so feel free to ignore these until
that follow-up.
Thanks,
NeilBrown
[PATCH v4 1/8] coda: don't d_drop() early.
[PATCH v4 2/8] hostfs: don't d_drop() before d_splice_alias() in
[PATCH v4 3/8] afs: don't unhash/rehash dentries during unlink/rename
[PATCH v4 4/8] afs: use d_splice_alias() in afs_vnode_new_inode()
[PATCH v4 5/8] afs: use d_alloc_trylock in afs_sillyrename()
[PATCH v4 6/8] afs: use d_duplicate()
[PATCH v4 7/8] procfs: drop parent lock for d_alloc_parallel() in
[PATCH v4 8/8] afs: lookup_atsys to drop and reclaim lock.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 1/8] coda: don't d_drop() early.
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
2026-11-29 21:21 ` [PATCH v4 2/8] hostfs: don't d_drop() before d_splice_alias() in hostfs_mkdir() NeilBrown
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
Proposed locking changes will mean that calling d_drop() could
effectively unlock the name allowing a parallel lookup to proceed.
For this reason it should only be called *after* the attempt to create a
symlink (in this case) has completed (whether successfully or not).
So move the d_drop() to after the venus_symlink() call.
Doing this also means that if the upcall that handles venus_symlink()
happens to look up the name being created, it will get -ENOENT rather
then a possible deadlock.
Acked-by: Jan Harkes <jaharkes@cs.cmu.edu>
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/coda/dir.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index a85be5962e62..b47299527b65 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -249,13 +249,13 @@ static int coda_symlink(const struct mnt_idmap *idmap,
if (symlen > CODA_MAXPATHLEN)
return -ENAMETOOLONG;
+ error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len,
+ symname, symlen);
/*
- * This entry is now negative. Since we do not create
+ * This entry is still negative. Since we did not create
* an inode for the entry we have to drop it.
*/
d_drop(de);
- error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len,
- symname, symlen);
/* mtime is no good anymore */
if (!error)
base-commit: 4843f6873f7c4835e62f2c73ba0fd538e57a2f22
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 2/8] hostfs: don't d_drop() before d_splice_alias() in hostfs_mkdir()
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
2026-11-29 21:21 ` [PATCH v4 1/8] coda: don't d_drop() early NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
2026-11-29 21:21 ` [PATCH v4 3/8] afs: don't unhash/rehash dentries during unlink/rename NeilBrown
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
hostfs_mkdir() uses d_drop() and d_splice_alias() to ensure it has the
right dentry after a mkdir.
d_drop() is no longer needed here and will cause problem for future
changes to directory locking. So remove the d_drop().
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/hostfs/hostfs_kern.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 613146e76dec..7cf25c29cb78 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -700,7 +700,6 @@ static struct dentry *hostfs_mkdir(const struct mnt_idmap *idmap, struct inode *
dentry = ERR_PTR(err);
} else {
inode = hostfs_iget(dentry->d_sb, file);
- d_drop(dentry);
dentry = d_splice_alias(inode, dentry);
}
__putname(file);
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 3/8] afs: don't unhash/rehash dentries during unlink/rename
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
2026-11-29 21:21 ` [PATCH v4 1/8] coda: don't d_drop() early NeilBrown
2026-11-29 21:21 ` [PATCH v4 2/8] hostfs: don't d_drop() before d_splice_alias() in hostfs_mkdir() NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
2026-11-29 21:21 ` [PATCH v4 4/8] afs: use d_splice_alias() in afs_vnode_new_inode() NeilBrown
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
afs needs to block lookup of dentries during unlink and rename.
There are two reasons:
1/ If the target is to be removed, not silly-renamed, the subsequent
opens cannot be allowed as the file won't exist on the server,
but they shouldn't fail until the unlink/rename completes.
2/ If the rename source is being moved between directories a lookup,
particularly d_revalidate, might change ->d_time asynchronously
with rename changing ->d_time with possible incorrect results.
afs currently unhashes the dentry to force a lookup which will wait on the
directory lock, and rehashes afterwards. This is incompatible with
proposed changed to directory locking which will require a dentry to
remain hashed throughout rename/unlink/etc operations.
This patch copies a mechanism developed for NFS but uses the new
DCACHE_PRIVATE flag rather then ->d_fsdata. DCACHE_PRIVATE is given
the private name DCACHE_BLOCKED within afs.
The flag is set when lookups and revalidates must be blocked.
d_revalidate checks for this flag and waits for it to become be cleared.
->d_lock is used to ensure d_revalidate never updates the time stamp in
->d_fsdata while DCACHE_BLOCKED is set. It also avoids updating the
timestamp if the d_parent has changed.
For a ref-walk, ->d_lock provides all needed sequencing. It is taken in
__d_lookup() to increment the refcount and is held by afs when checking
the refcount and setting DCACHE_BLOCKED. d_revalidate() is called after
__d_lookup() so it will see DCACHE_BLOCKED if needed without any extra
barrier.
For RCU-walk, d_revalidate() is called before refcount is incremented,
so as well as setting DCACHE_BLOCKED we must
write_seqcount_invalidate(&dentry->d_seq).
If d_revalidate is called before that write_seqcount_invalidate(),
then the RCU-walk will be retried as ref-walk. If it is called
after, then DCACHE_BLOCKED will be seen providing we use smp_load_acquire().
The unlocking in afs_rename_edit_dir() is not needed. It was previously
needed because it would not be safe to d_rehash() after calling
d_move(). But now that we don't use d_rehash() that is not a concern.
afs_rename_put() is always called and is sufficient for all rename
unlocking.
For rename, we can clear DCACHE_BLOCKED in afs_rename_put() as that will
certainly be called. For unlink, afs_unlink_put() might not be called
if op->ops is updated to afs_fetch_status_operation, so DCACHE_BLOCKED
must be cleared in afs_unlink().
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/afs/dir.c | 111 +++++++++++++++++++++++++++++++---------------
fs/afs/internal.h | 5 +--
2 files changed, 77 insertions(+), 39 deletions(-)
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 75f8f70cfeff..e76a610ce89a 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -49,6 +49,16 @@ static int afs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
static int afs_dir_writepages(struct address_space *mapping,
struct writeback_control *wbc);
+/*
+ * This is set to stop d_revalidate looking at, and possibly changing,
+ * ->d_fsdata (a timestamp) on a dentry which is being moved between
+ * directories, and to block lookup and possible open() for a dentry
+ * that is being removed without silly-rename.
+ * When set to block open()s, we also invalidate ->d_seq.
+ * When set only to protect ->d_fsdata, we don't need to invalidate ->d_seq.
+ */
+#define DCACHE_BLOCKED DCACHE_PRIVATE
+
const struct file_operations afs_dir_file_operations = {
.open = afs_dir_open,
.release = afs_release,
@@ -1031,6 +1041,12 @@ static int afs_d_revalidate_rcu(struct afs_vnode *dvnode, struct dentry *dentry)
if (!afs_check_validity(dvnode))
return -ECHILD;
+ /* Is a rename/unlink is pending? We must load d_flags *after*
+ * ->d_seq was sampled in path_init() or similar so use "acquire".
+ */
+ if (smp_load_acquire(&dentry->d_flags) & DCACHE_BLOCKED)
+ return -ECHILD;
+
/* We only need to invalidate a dentry if the server's copy changed
* behind our back. If we made the change, it's no problem. Note that
* on a 32-bit system, we only have 32 bits in the dentry to store the
@@ -1079,6 +1095,10 @@ static int afs_d_revalidate(struct inode *parent_dir, const struct qstr *name,
if (IS_ERR(key))
key = NULL;
+ /* Wait for rename/unlink to complete */
+wait_for_rename:
+ wait_var_event(&dentry->d_flags, !(dentry->d_flags & DCACHE_BLOCKED));
+
/* validate the parent directory */
ret = afs_validate(dir, key);
if (ret == -ERESTARTSYS) {
@@ -1158,7 +1178,14 @@ static int afs_d_revalidate(struct inode *parent_dir, const struct qstr *name,
}
out_valid:
- dentry->d_fsdata = (void *)(unsigned long)dir_version;
+ spin_lock(&dentry->d_lock);
+ if (dentry->d_flags & DCACHE_BLOCKED) {
+ spin_unlock(&dentry->d_lock);
+ goto wait_for_rename;
+ }
+ if (dentry->d_parent->d_inode == parent_dir)
+ dentry->d_fsdata = (void *)(unsigned long)dir_version;
+ spin_unlock(&dentry->d_lock);
out_valid_noupdate:
key_put(key);
_leave(" = 1 [valid]");
@@ -1530,20 +1557,12 @@ static void afs_unlink_edit_dir(struct afs_operation *op)
fscache_end_operation(&cres);
}
-static void afs_unlink_put(struct afs_operation *op)
-{
- _enter("op=%08x", op->debug_id);
- if (op->unlink.need_rehash && afs_op_error(op) < 0 && afs_op_error(op) != -ENOENT)
- d_rehash(op->dentry);
-}
-
static const struct afs_operation_ops afs_unlink_operation = {
.issue_afs_rpc = afs_fs_remove_file,
.issue_yfs_rpc = yfs_fs_remove_file,
.success = afs_unlink_success,
.aborted = afs_check_for_remote_deletion,
.edit_dir = afs_unlink_edit_dir,
- .put = afs_unlink_put,
};
/*
@@ -1588,11 +1607,13 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
afs_op_set_error(op, afs_sillyrename(dvnode, vnode, dentry, op->key));
goto error;
}
- if (!d_unhashed(dentry)) {
- /* Prevent a race with RCU lookup. */
- __d_drop(dentry);
- op->unlink.need_rehash = true;
- }
+ dentry->d_flags |= DCACHE_BLOCKED;
+ /*
+ * As RCU-walk calls d_revalidate() before incrementing d_count
+ * it may have already run. We need to invalidate d_seq so
+ * legitimize_path() will trigger a retry.
+ */
+ write_seqcount_invalidate(&dentry->d_seq);
spin_unlock(&dentry->d_lock);
op->file[1].vnode = vnode;
@@ -1603,6 +1624,11 @@ static int afs_unlink(struct inode *dir, struct dentry *dentry)
afs_begin_vnode_operation(op);
afs_wait_for_operation(op);
+ spin_lock(&dentry->d_lock);
+ store_release_wake_up(&dentry->d_flags,
+ dentry->d_flags &~ DCACHE_BLOCKED);
+ spin_unlock(&dentry->d_lock);
+
/* If there was a conflict with a third party, check the status of the
* unlinked vnode.
*/
@@ -1899,11 +1925,6 @@ static void afs_rename_edit_dir(struct afs_operation *op)
_enter("op=%08x", op->debug_id);
- if (op->rename.rehash) {
- d_rehash(op->rename.rehash);
- op->rename.rehash = NULL;
- }
-
fscache_begin_write_operation(&orig_cres, afs_vnode_cache(orig_dvnode));
if (new_dvnode != orig_dvnode)
fscache_begin_write_operation(&new_cres, afs_vnode_cache(new_dvnode));
@@ -2023,11 +2044,18 @@ static void afs_rename_exchange_edit_dir(struct afs_operation *op)
static void afs_rename_put(struct afs_operation *op)
{
_enter("op=%08x", op->debug_id);
- if (op->rename.rehash)
- d_rehash(op->rename.rehash);
+ if (op->rename.unblock) {
+ spin_lock(&op->rename.unblock->d_lock);
+ store_release_wake_up(&op->rename.unblock->d_flags,
+ op->rename.unblock->d_flags &~ DCACHE_BLOCKED);
+ spin_unlock(&op->rename.unblock->d_lock);
+ op->rename.unblock = NULL;
+ }
+ spin_lock(&op->dentry->d_lock);
+ store_release_wake_up(&op->dentry->d_flags,
+ op->dentry->d_flags &~ DCACHE_BLOCKED);
+ spin_unlock(&op->dentry->d_lock);
dput(op->rename.tmp);
- if (afs_op_error(op))
- d_rehash(op->dentry);
}
static const struct afs_operation_ops afs_rename_operation = {
@@ -2135,7 +2163,11 @@ static int afs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
op->ops = &afs_rename_noreplace_operation;
} else if (flags & RENAME_EXCHANGE) {
op->ops = &afs_rename_exchange_operation;
- d_drop(new_dentry);
+ /* Block revalidate on new_dentry until rename completes */
+ spin_lock(&new_dentry->d_lock);
+ new_dentry->d_flags |= DCACHE_BLOCKED;
+ op->rename.unblock = new_dentry;
+ spin_unlock(&new_dentry->d_lock);
} else {
/* If we might displace the target, we might need to do silly
* rename.
@@ -2148,15 +2180,10 @@ static int afs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
* and becomes the new target.
*/
if (d_is_positive(new_dentry) && !d_is_dir(new_dentry)) {
- /* To prevent any new references to the target during
- * the rename, we unhash the dentry in advance.
- */
- if (!d_unhashed(new_dentry)) {
- d_drop(new_dentry);
- op->rename.rehash = new_dentry;
- }
+ spin_lock(&new_dentry->d_lock);
if (d_count(new_dentry) > 2) {
+ spin_unlock(&new_dentry->d_lock);
/* copy the target dentry's name */
op->rename.tmp = d_alloc(new_dentry->d_parent,
&new_dentry->d_name);
@@ -2174,8 +2201,21 @@ static int afs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
}
op->dentry_2 = op->rename.tmp;
- op->rename.rehash = NULL;
op->rename.new_negative = true;
+ } else {
+ /*
+ * To prevent any new references to the
+ * target during the rename, we set
+ * DCACHE_BLOCKED which afs_d_revalidate
+ * will wait for. d_lock ensures
+ * d_count() and DCACHE_BLOCKED are
+ * consistent, and d_seq ensure RCU-walk
+ * is retried.
+ */
+ new_dentry->d_flags |= DCACHE_BLOCKED;
+ write_seqcount_invalidate(&new_dentry->d_seq);
+ op->rename.unblock = new_dentry;
+ spin_unlock(&new_dentry->d_lock);
}
}
}
@@ -2186,10 +2226,11 @@ static int afs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
* d_revalidate may see old_dentry between the op having taken place
* and the version being updated.
*
- * So drop the old_dentry for now to make other threads go through
- * lookup instead - which we hold a lock against.
+ * So block revalidate on the old_dentry until the rename completes.
*/
- d_drop(old_dentry);
+ spin_lock(&old_dentry->d_lock);
+ old_dentry->d_flags |= DCACHE_BLOCKED;
+ spin_unlock(&old_dentry->d_lock);
ret = afs_do_sync_operation(op);
if (ret == -ENOTSUPP)
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 7cea5ba0d20d..578fe7d35ab4 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -901,10 +901,7 @@ struct afs_operation {
struct afs_symlink *symlink;
} create;
struct {
- bool need_rehash;
- } unlink;
- struct {
- struct dentry *rehash;
+ struct dentry *unblock;
struct dentry *tmp;
unsigned int rename_flags;
bool new_negative;
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 4/8] afs: use d_splice_alias() in afs_vnode_new_inode()
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
` (2 preceding siblings ...)
2026-11-29 21:21 ` [PATCH v4 3/8] afs: don't unhash/rehash dentries during unlink/rename NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
2026-11-29 21:21 ` [PATCH v4 5/8] afs: use d_alloc_trylock in afs_sillyrename() NeilBrown
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
As afs supports the fhandle interfaces there is a theoretical possibility
that the inode created for mkdir could be found by open_by_handle_at()
and given a dentry before d_instantiate() is called. This would result
in two dentries for the one directory inode, which is not permitted.
So this patch changes afs_mkdir() to use d_splice_alias() and to
return the alternate dentry from ->mkdir() if appropriate.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/afs/dir.c | 26 +++++++++++++++++++++-----
fs/afs/internal.h | 1 +
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index e76a610ce89a..a98cf2059394 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -1258,7 +1258,7 @@ void afs_check_for_remote_deletion(struct afs_operation *op)
/*
* Create a new inode for create/mkdir/symlink
*/
-static void afs_vnode_new_inode(struct afs_operation *op)
+static struct dentry *afs_vnode_new_inode(struct afs_operation *op)
{
struct afs_vnode_param *dvp = &op->file[0];
struct afs_vnode_param *vp = &op->file[1];
@@ -1275,7 +1275,7 @@ static void afs_vnode_new_inode(struct afs_operation *op)
* the new directory on the server.
*/
afs_op_accumulate_error(op, PTR_ERR(inode), 0);
- return;
+ return NULL;
}
vnode = AFS_FS_I(inode);
@@ -1286,16 +1286,27 @@ static void afs_vnode_new_inode(struct afs_operation *op)
afs_init_new_symlink(vnode, op);
if (!afs_op_error(op))
afs_cache_permit(vnode, op->key, vnode->cb_break, &vp->scb);
- d_instantiate(op->dentry, inode);
+ return d_splice_alias(inode, op->dentry);
}
static void afs_create_success(struct afs_operation *op)
{
+ struct dentry *ret;
+
_enter("op=%08x", op->debug_id);
op->ctime = op->file[0].scb.status.mtime_client;
afs_vnode_commit_status(op, &op->file[0]);
afs_update_dentry_version(op, &op->file[0], op->dentry);
- afs_vnode_new_inode(op);
+ ret = afs_vnode_new_inode(op);
+ if (IS_ERR(ret)) {
+ afs_op_set_error(op, PTR_ERR(ret));
+ ret = NULL;
+ }
+ if (op->create.ret) {
+ *op->create.ret = ret;
+ afs_update_dentry_version(op, &op->file[0], ret);
+ } else
+ dput(ret);
}
static void afs_create_edit_dir(struct afs_operation *op)
@@ -1342,6 +1353,7 @@ static struct dentry *afs_mkdir(const struct mnt_idmap *idmap, struct inode *dir
{
struct afs_operation *op;
struct afs_vnode *dvnode = AFS_FS_I(dir);
+ struct dentry *alias = NULL;
int ret;
_enter("{%llx:%llu},{%pd},%ho",
@@ -1362,11 +1374,15 @@ static struct dentry *afs_mkdir(const struct mnt_idmap *idmap, struct inode *dir
op->dentry = dentry;
op->create.mode = mode;
op->create.reason = afs_edit_dir_for_mkdir;
+ op->create.ret = &alias;
op->mtime = current_time(dir);
op->ops = &afs_mkdir_operation;
ret = afs_do_sync_operation(op);
afs_dir_unuse_cookie(dvnode, ret);
- return ERR_PTR(ret);
+ if (ret)
+ return ERR_PTR(ret);
+ else
+ return alias;
}
/*
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 578fe7d35ab4..6690df4f092a 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -899,6 +899,7 @@ struct afs_operation {
int reason; /* enum afs_edit_dir_reason */
mode_t mode;
struct afs_symlink *symlink;
+ struct dentry **ret;
} create;
struct {
struct dentry *unblock;
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 5/8] afs: use d_alloc_trylock in afs_sillyrename()
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
` (3 preceding siblings ...)
2026-11-29 21:21 ` [PATCH v4 4/8] afs: use d_splice_alias() in afs_vnode_new_inode() NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
2026-11-29 21:21 ` [PATCH v4 6/8] afs: use d_duplicate() NeilBrown
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
Rather than performing a normal lookup (which will be awkward with future
locking changes) use d_alloc_trylock() to find a dentry for an
unused name, and use an open-coded lookup_slow() to see if it is free on
the server.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/afs/dir.c | 6 ++---
fs/afs/dir_silly.c | 56 ++++++++++++++++++++++++++++++++--------------
fs/afs/internal.h | 2 ++
3 files changed, 43 insertions(+), 21 deletions(-)
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index a98cf2059394..aa0d83f7ecf1 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -19,8 +19,6 @@
#include "afs_fs.h"
#include "xdr_fs.h"
-static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
- unsigned int flags);
static int afs_dir_open(struct inode *inode, struct file *file);
static int afs_readdir(struct file *file, struct dir_context *ctx);
static int afs_d_revalidate(struct inode *dir, const struct qstr *name,
@@ -969,8 +967,8 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
/*
* look up an entry in a directory
*/
-static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
- unsigned int flags)
+struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
+ unsigned int flags)
{
struct afs_vnode *dvnode = AFS_FS_I(dir);
struct afs_fid fid = {};
diff --git a/fs/afs/dir_silly.c b/fs/afs/dir_silly.c
index 982bb6ec15f0..e07c882c4fc7 100644
--- a/fs/afs/dir_silly.c
+++ b/fs/afs/dir_silly.c
@@ -112,7 +112,8 @@ int afs_sillyrename(struct afs_vnode *dvnode, struct afs_vnode *vnode,
struct dentry *dentry, struct key *key)
{
static unsigned int sillycounter;
- struct dentry *sdentry = NULL;
+ struct dentry *sdentry = NULL, *old;
+ struct inode *dir = dentry->d_parent->d_inode;
unsigned char silly[16];
int ret = -EBUSY;
@@ -122,23 +123,44 @@ int afs_sillyrename(struct afs_vnode *dvnode, struct afs_vnode *vnode,
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
return -EBUSY;
- sdentry = NULL;
- do {
- dput(sdentry);
- sillycounter++;
-
- /* Create a silly name. Note that the ".__afs" prefix is
- * understood by the salvager and must not be changed.
- */
- scnprintf(silly, sizeof(silly), ".__afs%04X", sillycounter);
- sdentry = lookup_noperm(&QSTR(silly), dentry->d_parent);
+newname:
+ sillycounter++;
- /* N.B. Better to return EBUSY here ... it could be dangerous
- * to delete the file while it's in use.
- */
- if (IS_ERR(sdentry))
- goto out;
- } while (!d_is_negative(sdentry));
+ /*
+ * Create a silly name. Note that the ".__afs" prefix is
+ * understood by the salvager and must not be changed.
+ */
+ scnprintf(silly, sizeof(silly), ".__afs%04X", sillycounter);
+ sdentry = d_alloc_trylock(dentry->d_parent, &QSTR(silly));
+ if (sdentry == ERR_PTR(-EWOULDBLOCK))
+ /* try another name */
+ goto newname;
+ /* N.B. Better to return EBUSY here ... it could be dangerous
+ * to delete the file while it's in use.
+ */
+ if (IS_ERR(sdentry))
+ goto out;
+ if (!d_in_lookup(sdentry)) {
+ if (d_really_is_negative(sdentry)) {
+ /* try to get an in-lookup dentry */
+ d_drop(sdentry);
+ sillycounter--;
+ }
+ dput(sdentry);
+ goto newname;
+ }
+ /* This name isn't known locally - check on server */
+ old = afs_lookup(dir, sdentry, 0);
+ d_lookup_done(sdentry);
+ if (IS_ERR(old)) {
+ dput(sdentry);
+ goto out;
+ }
+ if (old || d_is_positive(sdentry)) {
+ dput(old);
+ dput(sdentry);
+ goto newname;
+ }
ihold(&vnode->netfs.inode);
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 6690df4f092a..7b666ab9a026 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -1111,6 +1111,8 @@ ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)
__acquires(&dvnode->validate_lock);
extern void afs_d_release(struct dentry *);
extern void afs_check_for_remote_deletion(struct afs_operation *);
+extern struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
+ unsigned int flags);
/*
* dir_edit.c
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 6/8] afs: use d_duplicate()
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
` (4 preceding siblings ...)
2026-11-29 21:21 ` [PATCH v4 5/8] afs: use d_alloc_trylock in afs_sillyrename() NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
2026-11-29 21:21 ` [PATCH v4 7/8] procfs: drop parent lock for d_alloc_parallel() in iterate_shared() NeilBrown
2026-11-29 21:21 ` [PATCH v4 8/8] afs: lookup_atsys to drop and reclaim lock NeilBrown
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
To prepare for d_alloc_parallel() being permitted without a directory
lock, use d_duplicate() when duplicating a dentry in order to perform a
silly-rename. This creates on in-lookup dentry which will contine to block
concurrent lookups after the original dentry is silly-renamed, and until
the final rename happens.
As the resulting dentry is in-lookup, we need to call d_lookup_done()
before d_put().
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/afs/dir.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index aa0d83f7ecf1..b40e02143224 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -2069,7 +2069,10 @@ static void afs_rename_put(struct afs_operation *op)
store_release_wake_up(&op->dentry->d_flags,
op->dentry->d_flags &~ DCACHE_BLOCKED);
spin_unlock(&op->dentry->d_lock);
- dput(op->rename.tmp);
+ if (op->rename.tmp) {
+ d_lookup_done(op->rename.tmp);
+ dput(op->rename.tmp);
+ }
}
static const struct afs_operation_ops afs_rename_operation = {
@@ -2199,10 +2202,10 @@ static int afs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
if (d_count(new_dentry) > 2) {
spin_unlock(&new_dentry->d_lock);
/* copy the target dentry's name */
- op->rename.tmp = d_alloc(new_dentry->d_parent,
- &new_dentry->d_name);
- if (!op->rename.tmp) {
+ op->rename.tmp = d_duplicate(new_dentry);
+ if (IS_ERR(op->rename.tmp)) {
afs_op_nomem(op);
+ op->rename.tmp = NULL;
goto error;
}
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 7/8] procfs: drop parent lock for d_alloc_parallel() in iterate_shared()
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
` (5 preceding siblings ...)
2026-11-29 21:21 ` [PATCH v4 6/8] afs: use d_duplicate() NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
2026-11-29 21:21 ` [PATCH v4 8/8] afs: lookup_atsys to drop and reclaim lock NeilBrown
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
When procfs finds a name during iterate_shared() that isn't in the
dcache it *must* add it so that it can have a stable inode number to
report (inodes are only accessible via the dcache in procfs).
It uses d_alloc_parallel(). A planned change to locking will make it
unsafe to call d_alloc_parallel() while holding the directory lock.
Other filesystems which prime the dcache in iterate_shared() use
d_alloc_trylock() which is safe but can fail if it races with ->lookup.
As procfs cannot handle failure we need something different.
procfs doesn't *need* the parent to be locked. There are no shared data
structures accessed that don't have their own locking. So it is safe to
drop and re-take the parent lock.
So unlock the parent and use lookup_noperm_unlocked() to find
child dentry, whether in dcache or via a call to ->lookup.
By doing this, procfs effectively delegates locking decisions to
lookup_noperm_unlocked(), which will be changed when the planned locking
changes happen.
A consequence of this is that when a child isn't in the dcache, more
work is done. ->lookup has to parse the name and find the details -
details which proc_fill_cache or proc_sys_fill_cache already have.
This should be a modest cost, and after the locking changes are made we
could restore the current behaviour if needed.
Other code that drops and retakes the lock in iterate_shared() needs to
be careful to check S_DEAD which could be set while the lock is
dropped. This is not needed in procfs as the flag is never set.
Note that in the case of an error from lookup_noperm_unlocked(),
proc_fill_cache() will return the name with inaccurate ino/type details
while proc_sys_fill_cache will above the readdir. This is a
pre-existing difference of long standing which I have chosen to leave
as-is. I doubt it is of any consequence.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/proc/base.c | 29 +++++++++--------------------
fs/proc/proc_sysctl.c | 42 ++++++++++++++----------------------------
2 files changed, 23 insertions(+), 48 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 7685660c3624..14bcfaea0ac9 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2106,31 +2106,20 @@ bool proc_fill_cache(struct file *file, struct dir_context *ctx,
unsigned type = DT_UNKNOWN;
ino_t ino = 1;
- child = try_lookup_noperm(&qname, dir);
+ inode_unlock_shared(dir->d_inode);
+
+ child = lookup_noperm_unlocked(&qname, dir);
+
if (IS_ERR(child))
goto end_instantiate;
-
- if (!child) {
- child = d_alloc_parallel(dir, &qname);
- if (IS_ERR(child))
- goto end_instantiate;
- if (d_in_lookup(child)) {
- struct dentry *res;
- res = instantiate(child, task, ptr);
- d_lookup_done(child);
- if (unlikely(res)) {
- dput(child);
- child = res;
- if (IS_ERR(child))
- goto end_instantiate;
- }
- }
+ if (d_really_is_positive(child)) {
+ inode = d_inode(child);
+ ino = inode->i_ino;
+ type = inode->i_mode >> 12;
}
- inode = d_inode(child);
- ino = inode->i_ino;
- type = inode->i_mode >> 12;
dput(child);
end_instantiate:
+ inode_lock_shared(dir->d_inode);
return dir_emit(ctx, name, len, ino, type);
}
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index eeebf813668e..37b96ec31fbe 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -687,38 +687,24 @@ static bool proc_sys_fill_cache(struct file *file,
struct inode *inode;
struct qstr qname;
ino_t ino = 0;
+ bool ret = false;
unsigned type = DT_UNKNOWN;
- qname.name = table->procname;
- qname.len = strlen(table->procname);
- qname.hash = full_name_hash(dir, qname.name, qname.len);
-
- child = d_lookup(dir, &qname);
- if (!child) {
- child = d_alloc_parallel(dir, &qname);
- if (IS_ERR(child))
- return false;
- if (d_in_lookup(child)) {
- struct dentry *res;
- inode = proc_sys_make_inode(dir->d_sb, head, table);
- res = d_splice_alias_ops(inode, child,
- &proc_sys_dentry_operations);
- d_lookup_done(child);
- if (unlikely(res)) {
- dput(child);
-
- if (IS_ERR(res))
- return false;
-
- child = res;
- }
- }
+ qname = QSTR(table->procname);
+ inode_unlock_shared(dir->d_inode);
+ child = lookup_noperm_unlocked(&qname, dir);
+ if (IS_ERR(child))
+ goto out;
+ if (d_really_is_positive(child)) {
+ inode = d_inode(child);
+ ino = inode->i_ino;
+ type = inode->i_mode >> 12;
}
- inode = d_inode(child);
- ino = inode->i_ino;
- type = inode->i_mode >> 12;
dput(child);
- return dir_emit(ctx, qname.name, qname.len, ino, type);
+ ret = dir_emit(ctx, qname.name, qname.len, ino, type);
+out:
+ inode_lock_shared(dir->d_inode);
+ return ret;
}
static bool proc_sys_link_fill_cache(struct file *file,
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 8/8] afs: lookup_atsys to drop and reclaim lock.
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
` (6 preceding siblings ...)
2026-11-29 21:21 ` [PATCH v4 7/8] procfs: drop parent lock for d_alloc_parallel() in iterate_shared() NeilBrown
@ 2026-11-29 21:21 ` NeilBrown
7 siblings, 0 replies; 9+ messages in thread
From: NeilBrown @ 2026-11-29 21:21 UTC (permalink / raw)
To: Alexander Viro, Christian Brauner
Cc: David Howells, Marc Dionne, Jan Harkes, coda, Jan Kara,
Richard Weinberger, Anton Ivanov, Johannes Berg, Jeff Layton,
Amir Goldstein, linux-kernel, codalist, linux-fsdevel, linux-um,
linux-afs
From: NeilBrown <neil@brown.name>
If afs is asked to lookup a name ending with @sys, it needs to look up
a different name for which it might need to allocate a dentry with
d_alloc_parallel().
This is done while the parent lock is held which will be a problem in
a future patch where the ordering of the parent lock and
d_alloc_parallel() locking is reversed.
There is no actual need to hold the lock during this nested lookup. The
original dentry will never be used - it is left unhashed and a dentry
with the alternate name is returned.
With this patch we unlock the directory and unlock (d_lookup_done) the
dnetry early and reclaim the directory lock later. Then we use
lookup_noperm_unlocked() for the nested lookup.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/afs/dir.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index b40e02143224..b4f2bcdc35b3 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -913,7 +913,8 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry)
/*
* Look up an entry in a directory with @sys substitution.
*/
-static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
+static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry,
+ unsigned int flags)
{
struct afs_sysnames *subs;
struct afs_net *net = afs_i2net(dir);
@@ -938,6 +939,18 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
refcount_inc(&subs->usage);
read_unlock(&net->sysnames_lock);
+ /*
+ * We need the directory to be unlocked so we can perform other lookups.
+ * We don't need the lock any more, we just need the name which we
+ * have taken a copy of.
+ * We won't be instantiating this dentry, so end lookup now. This
+ * makes it safe to take the parent lock in lookup_noperm_unlocked().
+ */
+ d_lookup_done(dentry);
+ if (flags & LOOKUP_SHARED)
+ inode_unlock_shared(dir);
+ else
+ inode_unlock(dir);
for (i = 0; i < subs->nr; i++) {
name = subs->subs[i];
len = dentry->d_name.len - 4 + strlen(name);
@@ -947,7 +960,7 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
}
strcpy(p, name);
- ret = lookup_noperm(&QSTR(buf), dentry->d_parent);
+ ret = lookup_noperm_unlocked(&QSTR(buf), dentry->d_parent);
if (IS_ERR(ret) || d_is_positive(ret))
goto out_s;
dput(ret);
@@ -958,6 +971,10 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
*/
ret = NULL;
out_s:
+ if (flags & LOOKUP_SHARED)
+ inode_lock_shared(dir);
+ else
+ inode_lock_nested(dir, I_MUTEX_PARENT);
afs_put_sysnames(subs);
kfree(buf);
out_p:
@@ -1003,7 +1020,7 @@ struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
dentry->d_name.name[dentry->d_name.len - 3] == 's' &&
dentry->d_name.name[dentry->d_name.len - 2] == 'y' &&
dentry->d_name.name[dentry->d_name.len - 1] == 's')
- return afs_lookup_atsys(dir, dentry);
+ return afs_lookup_atsys(dir, dentry, flags);
afs_stat_v(dvnode, n_lookup);
inode = afs_do_lookup(dir, dentry);
--
2.50.0.107.gf914562f5916.dirty
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-29 21:34 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 21:21 [PATCH v4 0/8] multiple-filesystems: prepare for changes to VFS locking NeilBrown
2026-11-29 21:21 ` [PATCH v4 1/8] coda: don't d_drop() early NeilBrown
2026-11-29 21:21 ` [PATCH v4 2/8] hostfs: don't d_drop() before d_splice_alias() in hostfs_mkdir() NeilBrown
2026-11-29 21:21 ` [PATCH v4 3/8] afs: don't unhash/rehash dentries during unlink/rename NeilBrown
2026-11-29 21:21 ` [PATCH v4 4/8] afs: use d_splice_alias() in afs_vnode_new_inode() NeilBrown
2026-11-29 21:21 ` [PATCH v4 5/8] afs: use d_alloc_trylock in afs_sillyrename() NeilBrown
2026-11-29 21:21 ` [PATCH v4 6/8] afs: use d_duplicate() NeilBrown
2026-11-29 21:21 ` [PATCH v4 7/8] procfs: drop parent lock for d_alloc_parallel() in iterate_shared() NeilBrown
2026-11-29 21:21 ` [PATCH v4 8/8] afs: lookup_atsys to drop and reclaim lock NeilBrown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®