On Thu, Feb 06, 2025 at 04:42:56PM +1100, NeilBrown wrote: > nfs_sillyrename(struct inode *dir, struct dentry *dentry) > { > static unsigned int sillycounter; > @@ -447,7 +451,8 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry) > struct dentry *sdentry; > struct inode *inode = d_inode(dentry); > struct rpc_task *task; > - int error = -EBUSY; > + struct dentry *base; > + int error = -EBUSY; > > dfprintk(VFS, "NFS: silly-rename(%pd2, ct=%d)\n", > dentry, d_count(dentry)); > @@ -461,10 +466,11 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry) > > fileid = NFS_FILEID(d_inode(dentry)); > > + base = d_find_alias(dir); Huh? That would better be dentry->d_parent and all operations are in that directory, so you don't even need to grab a reference... > sdentry = NULL; > do { > int slen; > - dput(sdentry); > + > sillycounter++; > slen = scnprintf(silly, sizeof(silly), > SILLYNAME_PREFIX "%0*llx%0*x", > @@ -474,14 +480,19 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry) > dfprintk(VFS, "NFS: trying to rename %pd to %s\n", > dentry, silly); > > - sdentry = lookup_one_len(silly, dentry->d_parent, slen); > - /* > - * 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_inode(sdentry) != NULL); /* need negative lookup */ > + sdentry = lookup_and_lock_one(NULL, silly, slen, > + base, > + LOOKUP_CREATE | LOOKUP_EXCL > + | LOOKUP_RENAME_TARGET > + | LOOKUP_PARENT_LOCKED); > + } while (PTR_ERR_OR_ZERO(sdentry) == -EEXIST); /* need negative lookup */ What's wrong with sdentry == ERR_PTR(-EEXIST)?