Listing all mounts in all mount namespaces

submited by
Style Pass
2024-12-22 09:00:05

To make it easier to interact with mounts the listmount(2) and statmount(2) system calls were introduced in Linux v6.9. They both allow interacting with mounts through the new 64 bit mount id (unsigned) that is assigned to each mount on the system. The new mount id isn’t recycled and is unique for the lifetime of the system whereas the old mount id was recycled frequently and maxed out at INT_MAX. To differentiate the new and old mount id the new mount id starts at INT_MAX + 1.

statmount() allows to retrieved detailed information about a mount. The mount to retrieve information about can be specified in mnt_id_req->mnt_id. The information is supposed to be retrieved must be specified in mnt_id_req->param.

listmount(2) allows to (recursively) retrieve the list of child mounts of the provided mount. The mount whose children to list is specified in mnt_id_req->mnt_id. For convenience it can be set to LSTMT_ROOT to start listing mounts from the rootfs mount.

A nice feature of listmount(2) is its ability to iterate through all mounts in a mount namespace. For example, a buffer for 100 mounts ids is passed to listmount(2) but mount namespace contains more than 100 mounts. listmount(2) will retrieve 100 mounts. Afterwards the mnt_id_req->param can be set to the last mount id returned in the previous request. listmount(2) will return the next mount after the last mount.

Leave a Comment