Skip to content

Commit

Permalink
fs: export the mount ns id via statmount
Browse files Browse the repository at this point in the history
In order to allow users to iterate through children mount namespaces via
listmount we need a way for them to know what the ns id for the mount.
Add a new field to statmount called mnt_ns_id which will carry the ns id
for the given mount entry.

Co-developed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/r/6dabf437331fb7415d886f7c64b21cb2a50b1c66.1719243756.git.josef@toxicpanda.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
  • Loading branch information
Josef Bacik authored and Christian Brauner committed Jun 28, 2024
1 parent 1901c92 commit 09b3129
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -4974,6 +4974,14 @@ static int statmount_fs_type(struct kstatmount *s, struct seq_file *seq)
return 0;
}

static void statmount_mnt_ns_id(struct kstatmount *s)
{
struct mnt_namespace *ns = current->nsproxy->mnt_ns;

s->sm.mask |= STATMOUNT_MNT_NS_ID;
s->sm.mnt_ns_id = ns->seq;
}

static int statmount_string(struct kstatmount *s, u64 flag)
{
int ret;
Expand Down Expand Up @@ -5070,6 +5078,9 @@ static int do_statmount(struct kstatmount *s)
if (!err && s->mask & STATMOUNT_MNT_POINT)
err = statmount_string(s, STATMOUNT_MNT_POINT);

if (!err && s->mask & STATMOUNT_MNT_NS_ID)
statmount_mnt_ns_id(s);

if (err)
return err;

Expand Down
4 changes: 3 additions & 1 deletion include/uapi/linux/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ struct statmount {
__u64 propagate_from; /* Propagation from in current namespace */
__u32 mnt_root; /* [str] Root of mount relative to root of fs */
__u32 mnt_point; /* [str] Mountpoint relative to current root */
__u64 __spare2[50];
__u64 mnt_ns_id; /* ID of the mount namespace */
__u64 __spare2[49];
char str[]; /* Variable size part containing strings */
};

Expand Down Expand Up @@ -202,6 +203,7 @@ struct mnt_id_req {
#define STATMOUNT_MNT_ROOT 0x00000008U /* Want/got mnt_root */
#define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */
#define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */
#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */

/*
* Special @mnt_id values that can be passed to listmount
Expand Down

0 comments on commit 09b3129

Please sign in to comment.