From nobody Wed Dec 17 09:00:21 2025 Received: from smtpbguseast3.qq.com (smtpbguseast3.qq.com [54.243.244.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A5A31D63C2; Sun, 11 May 2025 11:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.243.244.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746963821; cv=none; b=JeV/43XuQX7+fDnMmc9RkfFCcewmPAXpCQQMgBCtIocrE2NlufzucPCzdhWM9fzMIT7+JoUi1sgCVpWPQshbgc1IaSol5MHz4qPt/tjxhrF5sQqpU0RXSbM5Hjdb0SSioyKos8fQVJunKksFhaOqd26gupF4k4G5kJqp/8wb96A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746963821; c=relaxed/simple; bh=ZPvxAooEpfDoKQZzvszZnuoHXtjVGwgesqHCgjlgE4A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ChqE7blnhQ+NTMnBzg2E8qA5ZADMiVA5hLsYhppFFqUWi5J7nquldSeBs+20vLiVv3OzQOFEcnFBPovEiM6cKCzwrWJStVLLoj62monE2ApS1gbPrgZ2O7MpyC30vKeFaBMntnkjcp1XuGApRop5wP5k1Ch5+Gpctr7tf1ybxjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=bbW2+qnr; arc=none smtp.client-ip=54.243.244.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="bbW2+qnr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1746963810; bh=FoJvhhjjd/ZdkM/GndWXo3kordP5UEz6B23XMYFaBmk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bbW2+qnrEDINCSJulkgNTFQo2n1yDAYdGQ5V2Jas7uD5yE8llfnL1b6yucLqWg90z 2b/FvXI3WE+tmXcW671gKl9Sj31R4xsS6z92IxiviNjAkAruFp6l1+MZEI4PL1+2TU 2gukYodZ/DD7AQ8hHsYKKqbdf4aWSkVKUhJKwUh0= X-QQ-mid: zesmtpip4t1746963797t33ba7a67 X-QQ-Originating-IP: kYfqd3Ijwqo5BKNFllcGhIDKYTXwOjy+//ib0K/u+GE= Received: from localhost.localdomain ( [localhost]) by bizesmtp.qq.com (ESMTP) with id ; Sun, 11 May 2025 19:43:15 +0800 (CST) X-QQ-SSF: 0002000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 15087200853929096546 EX-QQ-RecipientCnt: 19 From: WangYuli To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz Cc: akpm@linux-foundation.org, tglx@linutronix.de, jlayton@kernel.org, frederic@kernel.org, chenlinxuan@uniontech.com, xu.xin16@zte.com.cn, adrian.ratiu@collabora.com, lorenzo.stoakes@oracle.com, mingo@kernel.org, felix.moessbauer@siemens.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, zhanjun@uniontech.com, niecheng1@uniontech.com, guanwentao@uniontech.com, WangYuli Subject: [PATCH] proc: Show the mountid associated with exe Date: Sun, 11 May 2025 19:42:43 +0800 Message-ID: <3885DACAB5D311F7+20250511114243.215132-1-wangyuli@uniontech.com> X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSI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+aqhot3DFTx1ldpatNLcFkgVAwvbB6ZZKgDuvQ9JSZ6rClfBt2MA LNlgAGZTC2+a+dcr3gELyW2b0JC4SEgBEiup36sw== X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" From: Chen Linxuan In Linux, an fd (file descriptor) is a non-negative integer representing an open file or other I/O resource associated with a process. These resources are located on file systems accessed via mount points. A mount ID (mnt_id) is a unique identifier for a specific instance of a mounted file system within a mount namespace, essential for understanding the file's context, especially in complex or containerized environments. The executable (exe), pointed to by /proc//exe, is the process's binary file, which also resides on a file system. Knowing the mount ID for both file descriptors and the executable is valuable for debugging and understanding a process's resource origins. We can easily obtain the mnt_id for an open fd by reading /proc//fdinfo/ Signed-off-by: WangYuli --- fs/proc/base.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/fs/proc/base.c b/fs/proc/base.c index b0d4e1908b22..fe8a2d5b3bc1 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -101,6 +101,7 @@ #include #include "internal.h" #include "fd.h" +#include "../mount.h" =20 #include "../../lib/kstrtox.h" =20 @@ -1790,6 +1791,28 @@ static int proc_exe_link(struct dentry *dentry, stru= ct path *exe_path) return -ENOENT; } =20 +static int proc_exe_mntid(struct seq_file *m, struct pid_namespace *ns, + struct pid *pid, struct task_struct *task) +{ + struct file *exe_file; + struct path exe_path; + + exe_file =3D get_task_exe_file(task); + + if (exe_file) { + exe_path =3D exe_file->f_path; + path_get(&exe_file->f_path); + + seq_printf(m, "%i\n", real_mount(exe_path.mnt)->mnt_id); + + path_put(&exe_file->f_path); + fput(exe_file); + + return 0; + } else + return -ENOENT; +} + static const char *proc_pid_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) @@ -3342,6 +3365,7 @@ static const struct pid_entry tgid_base_stuff[] =3D { LNK("cwd", proc_cwd_link), LNK("root", proc_root_link), LNK("exe", proc_exe_link), + ONE("exe_mntid", S_IRUGO, proc_exe_mntid), REG("mounts", S_IRUGO, proc_mounts_operations), REG("mountinfo", S_IRUGO, proc_mountinfo_operations), REG("mountstats", S_IRUSR, proc_mountstats_operations), --=20 2.49.0