kernfs_remove_self(9)
π kernfs_remove_self β like, the Kernel API Manual edition, bestie
okay so bestie, listen up, because this one is genuinely iconic in a nerdy way: kernfs_remove_self lets a kernfs_node yeet itself out of existence from inside its own method. main character energy fr fr π
β¨ NAME β¨
kernfs_remove_self β remove a kernfs_node from its own method π
πΈ SYNOPSIS πΈ
bool kernfs_remove_self (struct kernfs_node *kn );
π¦ ARGUMENTS π¦
knβ the selfkernfs_nodeto remove. yes, the one doing the deleting. it's giving self-care honestly π
π§ DESCRIPTION π§
okay so first thing: the caller must be running off of a kernfs operation which is invoked with an active reference β like, one of kernfs_ops, no cap. this whole thing exists so you can implement a file operation that deletes itself. π«Ά
for example: the "delete" file for a sysfs device directory can be implemented by invoking kernfs_remove_self on the "delete" file itself. literally the file is the main character and the victim, we love a multitasker β¨
this function breaks the circular dependency of trying to deactivate self while holding an active ref itself. and here's the chill part β it isn't necessary to modify the usual removal path to use kernfs_remove_self. the "delete" implementation can simply invoke kernfs_remove_self on self before proceeding with the usual removal path. kernfs will ignore later kernfs_remove on self. so like, no messy aftermath, it just doesn't care anymore π
now the spicy part πΆοΈ: kernfs_remove_self can be called multiple times concurrently on the same kernfs_node. only the first one actually performs removal and returns true. all others will wait until the kernfs operation which won self-removal finishes and return false. and note β the losers wait for the completion of not only the winning kernfs_remove_self but also the whole kernfs_ops which won the arbitration. lowkey that's a whole group project dynamic π but it's useful! this can be used to guarantee, for example, all concurrent writes to a "delete" file to finish only after the whole operation is complete. slay, synchronized π
π₯ RETURN π₯
trueifknis removed by this call- otherwise
false
(and remember: only the first concurrent caller gets that true. everyone else gets false and a participation medal ποΈ)
π SEE ALSO π
kernel file ./fs/kernfs/dir.c β and the whole squad, alphabetically unbothered:
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_drain(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_by_name_ns(9)kernfs_rename_ns(9)
π«Ά reminder bestie: the caller has to be running off a kernfs operation invoked with an active reference β that's not a vibe suggestion, it's a requirement. don't come for me if you skip it π
and that's the whole page, bestie! π this little gem lives in ./fs/kernfs and the version/date stamps say October 2026 β so like, future-proof and fabulous β¨π bye, ily, go remove yourself from your own method π
πβ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms