nscommon: move to separate file

It's really awkward spilling the ns common infrastructure into multiple
headers. Move it to a separate file.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-09-17 12:28:02 +02:00
parent b2a0b19208
commit f74ca6da11
No known key found for this signature in database
GPG key ID: 91C61BC06578DCA2
4 changed files with 25 additions and 20 deletions

View file

@ -31,6 +31,9 @@ struct ns_common {
}; };
}; };
int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
bool alloc_inum);
#define to_ns_common(__ns) \ #define to_ns_common(__ns) \
_Generic((__ns), \ _Generic((__ns), \
struct cgroup_namespace *: &(__ns)->ns, \ struct cgroup_namespace *: &(__ns)->ns, \

View file

@ -66,25 +66,6 @@ static inline void proc_free_inum(unsigned int inum) {}
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
static inline int ns_common_init(struct ns_common *ns,
const struct proc_ns_operations *ops,
bool alloc_inum)
{
if (alloc_inum) {
int ret;
ret = proc_alloc_inum(&ns->inum);
if (ret)
return ret;
}
refcount_set(&ns->count, 1);
ns->stashed = NULL;
ns->ops = ops;
ns->ns_id = 0;
RB_CLEAR_NODE(&ns->ns_tree_node);
INIT_LIST_HEAD(&ns->ns_list_node);
return 0;
}
#define ns_free_inum(ns) proc_free_inum((ns)->inum) #define ns_free_inum(ns) proc_free_inum((ns)->inum)
#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)

View file

@ -8,7 +8,7 @@ obj-y = fork.o exec_domain.o panic.o \
sysctl.o capability.o ptrace.o user.o \ sysctl.o capability.o ptrace.o user.o \
signal.o sys.o umh.o workqueue.o pid.o task_work.o \ signal.o sys.o umh.o workqueue.o pid.o task_work.o \
extable.o params.o \ extable.o params.o \
kthread.o sys_ni.o nsproxy.o nstree.o \ kthread.o sys_ni.o nsproxy.o nstree.o nscommon.o \
notifier.o ksysfs.o cred.o reboot.o \ notifier.o ksysfs.o cred.o reboot.o \
async.o range.o smpboot.o ucount.o regset.o ksyms_common.o async.o range.o smpboot.o ucount.o regset.o ksyms_common.o

21
kernel/nscommon.c Normal file
View file

@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/ns_common.h>
int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
bool alloc_inum)
{
if (alloc_inum) {
int ret;
ret = proc_alloc_inum(&ns->inum);
if (ret)
return ret;
}
refcount_set(&ns->count, 1);
ns->stashed = NULL;
ns->ops = ops;
ns->ns_id = 0;
RB_CLEAR_NODE(&ns->ns_tree_node);
INIT_LIST_HEAD(&ns->ns_list_node);
return 0;
}