attach_recursive_mnt(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

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

okay so this is attach_recursive_mnt(9) from the Kernel API Manual, and it's genuinely one of those "attach a source mount tree" functions that looks scary but is so slay once you get it πŸ’–


πŸŽ€ NAME

attach_recursive_mnt β€” attach a source mount tree 🌸


✨ SYNOPSIS

int attach_recursive_mnt (struct mount *source_mnt , const struct
       pinned_mountpoint *dest );

🫢 ARGUMENTS

  • source_mnt β€” the mount tree you wanna attach, bestie 🌈
  • dest β€” the context for mounting at the place where the tree should go ✨

πŸ’… NOTE

so this next part is literally the vibe check table πŸ‘‘ β€” it explains the semantics when a source mount of a given type is attached to a destination mount of a given type. read it carefully, no skipping πŸ™ˆ

       ---------------------------------------------------------------------------
       |         BIND MOUNT OPERATION
       |
       |**************************************************************************
       | source-->| shared        |       private  |       slave    |
       unbindable | | dest     |               |                |
       |            | |   |      |               |                |
       |            | |   v      |               |                |
       |            |
       |**************************************************************************
       |  shared  | shared (++)   |     shared (+) |     shared(+++)|  invalid
       | |          |               |                |                |
       | |non-shared| shared (+)    |      private   |      slave (*) |
       invalid   |
       ***************************************************************************

A bind operation clones the source mount and mounts the clone on the destination mount. that's the whole bit πŸ’«

Here's the legend, bestie πŸ“:

  • (++) β€” the cloned mount is propagated to all the mounts in the propagation tree of the destination mount, and the cloned mount is added to the peer group of the source mount πŸ”₯
  • (+) β€” the cloned mount is created under the destination mount and is marked as shared. the cloned mount is added to the peer group of the source mount ✨
  • (+++) β€” the mount is propagated to all the mounts in the propagation tree of the destination mount, and the cloned mount is made slave of the same master as that of the source mount. the cloned mount is marked as 'shared and slave' πŸ‘‘
  • (*) β€” the cloned mount is made a slave of the same master as that of the source mount πŸ’œ

and now the move side of things πŸ¦‹:

       ---------------------------------------------------------------------------
       |                    MOVE MOUNT OPERATION
       |
       |**************************************************************************
       | source-->| shared        |       private  |       slave    |
       unbindable | | dest     |               |                |
       |            | |   |      |               |                |
       |            | |   v      |               |                |
       |            |
       |**************************************************************************
       |  shared  | shared (+)    |     shared (+) |    shared(+++) |  invalid
       | |          |               |                |                |
       | |non-shared| shared (+*)   |      private   |    slave (*)   |
       unbindable |
       ***************************************************************************

Legend for the move table, periodt πŸ’…:

  • (+) β€” the mount is moved to the destination. and is then propagated to all the mounts in the propagation tree of the destination mount 🌟
  • (+*) β€” the mount is moved to the destination. that's it, that's the whole thing πŸ’–
  • (+++) β€” the mount is moved to the destination and is then propagated to all the mounts belonging to the destination mount's propagation tree. the mount is marked as 'shared and slave' πŸŽ€
  • (*) β€” the mount continues to be a slave at the new location 🧚

if the source mount is a tree, the operations explained above is applied to each mount in the tree 🌈 β€” like, every single one, no cap.

fr fr warning πŸ™ˆ: must be called without spinlocks held, since this function can sleep in allocations. do nottt hold those spinlocks, bestie, it will not end well 😭

πŸ”’ CONTEXT

The function expects namespace_lock to be held. that's non-negotiable, it's giving very "you must have the lock" energy πŸ‘‘


⭐ RETURN

If source_mnt was successfully attached, 0 is returned πŸŽ‰. Otherwise a negative error code is returned πŸ’€.


πŸ’œ SEE ALSO

Kernel file ./fs/namespace.c β€” and the whole friend group πŸ’–:


kay that's the whole page, you ate that 🫢 go attach some mount trees responsibly, mwah πŸ’‹

source: ./fs β€” version vibes from October 2026, attach_recursive_mnt(9) ✨ periodt πŸ’…

πŸ“¦ where this page comes from