notify_change(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… notify_change(9) β€” the Kernel API Manual, bestie edition ✨

okay so you want to change some attributes on a filesystem object and you found notify_change β€” good instinct, queen πŸ‘‘ this one's from the Kernel API Manual and it's lowkey iconic for one specific reason: the delegation dance 🩰 let's get into it.


✨ SYNOPSIS ✨

int notify_change (struct mnt_idmap *idmap , struct dentry *dentry ,
struct iattr *attr , struct delegated_inode *delegated_inode );

four args, one int return, the whole vibe in one line 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • idmap β€” the idmap of the mount the inode was found from. like, which mount's identity-mapping are we working with πŸ’…
  • dentry β€” the object affected. this is the actual thing you're touching ✨
  • attr β€” the new attributes. the glow-up itself 🌸
  • delegated_inode β€” returns the inode, if the inode is delegated πŸ‘€ yes it's an out-param, yes that's the tea

πŸ’– DESCRIPTION πŸ’–

first things first, no cap: the caller must hold the i_rwsem exclusively on the affected object. that's not a suggestion, that's the law 🚨

so here's the situation. if notify_change discovers a delegation that's in need of breaking, it will return -EWOULDBLOCK and hand you back a reference to the inode in delegated_inode. what do you do then? you break the delegation and you retry, obviously πŸ’β€β™€οΈ and because breaking a delegation may take a long time β€” like, main-character-long 😭 β€” the caller should drop the i_rwsem before doing so. yes, drop the lock. it's giving trust the process.

alternatively πŸŒ€ a caller may pass NULL for delegated_inode. when is that appropriate? for callers that expect the underlying filesystem not to be NFS exported. also, passing NULL is totally fine for callers holding the file open for write, because in that case there can be no conflicting delegation. no drama, no delegation, no problem πŸ¦‹

and now the idmap bit, because this part matters 🫢 if the inode has been found through an idmapped mount, the idmap of the vfsmount must be passed through idmap. this function will then take care to map the inode according to idmap before checking permissions πŸ‘‘ on non-idmapped mounts, or if permission checking is to be performed on the raw inode, simply pass nop_mnt_idmap. simple as πŸŽ€

ok real talk bestie β€” the lock thing and the -EWOULDBLOCK retry loop are the whole point of this function. if you skip the drop-the-i_rwsem-before-breaking-the-delegation step you're gonna have a bad time πŸ’€

🌈 SEE ALSO 🌈

go read them, iykyk πŸ“šβœ¨


and that's the page, bestie πŸ’œ this one ships out of ./fs in October 2026 β€” slay, mark your calendar, periodt πŸ—“οΈπŸ’…

πŸ“¦ where this page comes from