vfs_rename(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… vfs_rename(9) β€” straight outta the Kernel API Manual ✨

okay bestie, buckle up: this is vfs_rename(9), the manpage about renaming filesystem objects, and she is a lot. πŸŽ€

πŸ¦‹ NAME πŸ¦‹

vfs_rename β€” rename a filesystem object πŸ”₯

✨ SYNOPSIS ✨

int vfs_rename (struct renamedata *rd );

πŸŽ€ ARGUMENTS πŸŽ€

  • rd β€” pointer to struct renamedata info. that’s the vibe check, bestie 🫢

πŸ’– DESCRIPTION πŸ’–

First things first: the caller must hold multiple mutexes β€” see lock_rename). πŸ”’πŸ˜­

If vfs_rename discovers a delegation in need of breaking at either the source or destination, it will return -EWOULDBLOCK and return a reference to the inode in delegated_inode. The caller should then break the delegation and retry. Because breaking a delegation may take a long time, the caller should drop all locks before doing so. πŸŒ€πŸ’€

Alternatively, a caller may pass NULL for delegated_inode. This may be appropriate for callers that expect the underlying filesystem not to be NFS exported. πŸ™ˆβœ¨

Then we get to the absolute worst of all namespace operations β€” renaming a directory. "Perverted" doesn’t even start to describe it. Somebody in UCB had a heck of a trip... Problems: πŸ˜΅β€πŸ’«

  • a) we can get into loop creation. πŸ”
  • b) race potential β€” two innocent renames can create a loop together. That’s where 4.4BSD screws up. Current fix: serialization on sb->s_vfs_rename_mutex. We might be more accurate, but that’s another story. πŸŒͺ️
  • c) we may have to lock up to four objects β€” parents and victim (if it exists), and source (if it’s a non-directory or a subdirectory that moves to different parent). And that β€” after we got ->i_rwsem on parents (until then we don’t know whether the target exists). Solution: try to be smart with locking order for inodes. We rely on the fact that tree topology may change only under ->s_vfs_rename_mutex and that parent of the object we move will be locked. Thus we can rank directories by the tree (ancestors first) and rank all non-directories after them. That works since everybody except rename does "lock parent, lookup, lock child" and rename is under ->s_vfs_rename_mutex. HOWEVER, it relies on the assumption that any object with ->lookup has no more than 1 dentry. If "hybrid" objects will ever appear, we’d better make sure that there’s no link(2) for them. πŸ”πŸ‘‘
  • d) conversion from fhandle to dentry may come in the wrong moment β€” when we are removing the target. Solution: we will have to grab ->i_rwsem in the fhandle_to_dentry code. [FIXME - current nfsfh.c relies on ->i_rwsem on parents, which works but leads to some truly excessive locking] 😭πŸ”₯

🌈 SEE ALSO 🌈


πŸ’– and that’s the whole vfs_rename(9) saga, bestie. The footer bits say source/version ./fs and date October 2026 β€” iconic, no cap. πŸŽ€βœ¨πŸ«Ά

πŸ“¦ where this page comes from