kernfs_drain(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… NAME πŸ’…

okay so this page is all about kernfs_drain β€” the function that literally drains a kernfs_node. that's it, that's the whole name, no cap. it's giving "short and iconic", and honestly? we love that for it. ✨

this one lives in section 9 of the Kernel API Manual, so yeah, it's kernel-dev territory, bestie β€” grab your fave beverage and let's go 🫢


🌸 SYNOPSIS 🌸

void kernfs_drain (struct kernfs_node *kn , bool drop_supers );

literally the whole signature right there. two args, one void return because this function does the work and doesn't hand you a result back β€” main character energy, honestly. πŸ‘‘


πŸŽ€ ARGUMENTS πŸŽ€

  • kn β€” the kernfs_node you're about to drain. this is the girl you're working on. πŸ’…
  • drop_supers β€” set this to true if this function is called with the kernfs_supers_rwsem locked. yes bestie, that kernfs_supers_rwsem. read the room (and your locking context) before you flip this one, ok? πŸ™ˆ

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does it actually do. two things, and they're both kinda fierce:

  • it drains existing usages of kn β€” like, politely but firmly showing everyone the door πŸšͺ
  • it nukes all existing mmaps of kn. yes. nukes. that's the actual word. violent but iconic πŸ’€πŸ”₯

and here's the part that lowkey slays: multiple removers may invoke this function concurrently on kn, and all of them will return after draining is complete. so no weird "who goes first" drama β€” everybody waits, everybody returns, everybody's fine. synchronized queen behavior, fr fr πŸ‘‘


⭐ SEE ALSO ⭐

the kernel file in question is ./fs/kernfs/dir.c, and it comes with a whole friend group of related functions β€” here's the full squad, no one gets left behind 🫢:

kernfs_path_from_node_locked(9), kernfs_name(9), kernfs_path_from_node(9), pr_cont_kernfs_name(9), pr_cont_kernfs_path(9), kernfs_get_parent(9), kernfs_name_hash(9), kernfs_link_sibling(9), kernfs_unlink_sibling(9), kernfs_get_active(9), kernfs_put_active(9), kernfs_get(9), kernfs_put(9), kernfs_node_from_dentry(9), kernfs_add_one(9), kernfs_find_ns(9), kernfs_find_and_get_ns(9), kernfs_walk_and_get_ns(9), kernfs_create_root(9), kernfs_destroy_root(9), kernfs_root_to_node(9), kernfs_create_dir_ns(9), kernfs_create_empty_dir(9), kernfs_next_descendant_post(9), kernfs_activate(9), kernfs_show(9), kernfs_remove(9), kernfs_break_active_protection(9), kernfs_unbreak_active_protection(9), kernfs_remove_self(9), kernfs_remove_by_name_ns(9), kernfs_rename_ns(9)

like, that's a lot of friends. go read them too, iykyk 🌈


okay that's the page!! this beauty came from ./fs/kernfs and it's dated October 2026 β€” so mark your calendar bestie, and slay your kernel work responsibly πŸ’–πŸŽ€βœ¨

πŸ“¦ where this page comes from