Linux filesystem development
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, Jeff Layton <jlayton@kernel.org>,
	 Lennart Poettering <lennart@poettering.net>,
	 Daan De Meyer <daan.j.demeyer@gmail.com>,
	Mike Yuan <me@yhndnzj.com>,
	 Christian Brauner <brauner@kernel.org>
Subject: [PATCH v2 04/15] pidfs: add inode allocation
Date: Tue, 04 Mar 2025 10:41:04 +0100	[thread overview]
Message-ID: <20250304-work-pidfs-kill_on_last_close-v2-4-44fdacfaa7b7@kernel.org> (raw)
In-Reply-To: <20250304-work-pidfs-kill_on_last_close-v2-0-44fdacfaa7b7@kernel.org>

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/pidfs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/fs/pidfs.c b/fs/pidfs.c
index ecc0dd886714..eaecb0a947f0 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -24,6 +24,27 @@
 #include "internal.h"
 #include "mount.h"
 
+static struct kmem_cache *pidfs_cachep __ro_after_init;
+
+/*
+ * Stashes information that userspace needs to access even after the
+ * process has been reaped.
+ */
+struct pidfs_exit_info {
+	__u64 cgroupid;
+	__u64 exit_code;
+};
+
+struct pidfs_inode {
+	struct pidfs_exit_info exit_info;
+	struct inode vfs_inode;
+};
+
+static inline struct pidfs_inode *pidfs_i(struct inode *inode)
+{
+	return container_of(inode, struct pidfs_inode, vfs_inode);
+}
+
 static struct rb_root pidfs_ino_tree = RB_ROOT;
 
 #if BITS_PER_LONG == 32
@@ -492,9 +513,29 @@ static void pidfs_evict_inode(struct inode *inode)
 	put_pid(pid);
 }
 
+static struct inode *pidfs_alloc_inode(struct super_block *sb)
+{
+	struct pidfs_inode *pi;
+
+	pi = alloc_inode_sb(sb, pidfs_cachep, GFP_KERNEL);
+	if (!pi)
+		return NULL;
+
+	memset(&pi->exit_info, 0, sizeof(pi->exit_info));
+
+	return &pi->vfs_inode;
+}
+
+static void pidfs_free_inode(struct inode *inode)
+{
+	kmem_cache_free(pidfs_cachep, pidfs_i(inode));
+}
+
 static const struct super_operations pidfs_sops = {
+	.alloc_inode	= pidfs_alloc_inode,
 	.drop_inode	= generic_delete_inode,
 	.evict_inode	= pidfs_evict_inode,
+	.free_inode	= pidfs_free_inode,
 	.statfs		= simple_statfs,
 };
 
@@ -704,8 +745,19 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags)
 	return pidfd_file;
 }
 
+static void pidfs_inode_init_once(void *data)
+{
+	struct pidfs_inode *pi = data;
+
+	inode_init_once(&pi->vfs_inode);
+}
+
 void __init pidfs_init(void)
 {
+	pidfs_cachep = kmem_cache_create("pidfs_cache", sizeof(struct pidfs_inode), 0,
+					 (SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
+					  SLAB_ACCOUNT | SLAB_PANIC),
+					 pidfs_inode_init_once);
 	pidfs_mnt = kern_mount(&pidfs_type);
 	if (IS_ERR(pidfs_mnt))
 		panic("Failed to mount pidfs pseudo filesystem");

-- 
2.47.2


  parent reply	other threads:[~2025-03-04  9:41 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04  9:41 [PATCH v2 00/15] pidfs: provide information after task has been reaped Christian Brauner
2025-03-04  9:41 ` [PATCH v2 01/15] pidfs: switch to copy_struct_to_user() Christian Brauner
2025-03-04 12:42   ` Jeff Layton
2025-03-04  9:41 ` [PATCH v2 02/15] pidfd: rely on automatic cleanup in __pidfd_prepare() Christian Brauner
2025-03-04 12:44   ` Jeff Layton
2025-03-04  9:41 ` [PATCH v2 03/15] pidfs: move setting flags into pidfs_alloc_file() Christian Brauner
2025-03-04 12:53   ` Jeff Layton
2025-03-04  9:41 ` Christian Brauner [this message]
2025-03-04 13:06   ` [PATCH v2 04/15] pidfs: add inode allocation Jeff Layton
2025-03-04  9:41 ` [PATCH v2 05/15] pidfs: record exit code and cgroupid at exit Christian Brauner
2025-03-04 13:05   ` Jeff Layton
2025-03-04 13:10   ` Oleg Nesterov
2025-03-04 19:10     ` Christian Brauner
2025-03-04  9:41 ` [PATCH v2 06/15] pidfs: allow to retrieve exit information Christian Brauner
2025-03-04 13:27   ` Jeff Layton
2025-03-04 17:23     ` Christian Brauner
2025-03-04 17:22   ` Oleg Nesterov
2025-03-04 20:16     ` Christian Brauner
2025-03-04 17:34   ` Oleg Nesterov
2025-03-04 20:09     ` Christian Brauner
2025-03-04 21:47       ` Oleg Nesterov
2025-03-05  8:54         ` Christian Brauner
2025-03-04  9:41 ` [PATCH v2 07/15] selftests/pidfd: fix header inclusion Christian Brauner
2025-03-04  9:41 ` [PATCH v2 08/15] pidfs/selftests: ensure correct headers for ioctl handling Christian Brauner
2025-03-04  9:41 ` [PATCH v2 09/15] selftests/pidfd: move more defines to common header Christian Brauner
2025-03-04  9:41 ` [PATCH v2 10/15] selftests/pidfd: add first PIDFD_INFO_EXIT selftest Christian Brauner
2025-03-04  9:41 ` [PATCH v2 11/15] selftests/pidfd: add second " Christian Brauner
2025-03-04  9:41 ` [PATCH v2 12/15] selftests/pidfd: add third " Christian Brauner
2025-03-04  9:41 ` [PATCH v2 13/15] selftests/pidfd: add fourth " Christian Brauner
2025-03-04  9:41 ` [PATCH v2 14/15] selftests/pidfd: add fifth " Christian Brauner
2025-03-04  9:41 ` [PATCH v2 15/15] selftests/pidfd: add sixth " Christian Brauner
2025-03-04 20:18   ` [PATCH v2 17/16] selftests/pidfd: test multi-threaded exec with PPIDFD_INFO_EXIT Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250304-work-pidfs-kill_on_last_close-v2-4-44fdacfaa7b7@kernel.org \
    --to=brauner@kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=jlayton@kernel.org \
    --cc=lennart@poettering.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=me@yhndnzj.com \
    --cc=oleg@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox