Skip to content

Commit 93f67a7

Browse files
committed
uts: split namespace into separate header
We have dedicated headers for all namespace types. Add one for the uts namespace as well. Now it's consistent for all namespace types. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 3ab378c commit 93f67a7

2 files changed

Lines changed: 66 additions & 57 deletions

File tree

include/linux/uts_namespace.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_UTS_NAMESPACE_H
3+
#define _LINUX_UTS_NAMESPACE_H
4+
5+
#include <linux/ns_common.h>
6+
#include <uapi/linux/utsname.h>
7+
8+
struct user_namespace;
9+
extern struct user_namespace init_user_ns;
10+
11+
struct uts_namespace {
12+
struct new_utsname name;
13+
struct user_namespace *user_ns;
14+
struct ucounts *ucounts;
15+
struct ns_common ns;
16+
} __randomize_layout;
17+
18+
extern struct uts_namespace init_uts_ns;
19+
20+
#ifdef CONFIG_UTS_NS
21+
static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
22+
{
23+
return container_of(ns, struct uts_namespace, ns);
24+
}
25+
26+
static inline void get_uts_ns(struct uts_namespace *ns)
27+
{
28+
refcount_inc(&ns->ns.count);
29+
}
30+
31+
extern struct uts_namespace *copy_utsname(unsigned long flags,
32+
struct user_namespace *user_ns, struct uts_namespace *old_ns);
33+
extern void free_uts_ns(struct uts_namespace *ns);
34+
35+
static inline void put_uts_ns(struct uts_namespace *ns)
36+
{
37+
if (refcount_dec_and_test(&ns->ns.count))
38+
free_uts_ns(ns);
39+
}
40+
41+
void uts_ns_init(void);
42+
#else
43+
static inline void get_uts_ns(struct uts_namespace *ns)
44+
{
45+
}
46+
47+
static inline void put_uts_ns(struct uts_namespace *ns)
48+
{
49+
}
50+
51+
static inline struct uts_namespace *copy_utsname(unsigned long flags,
52+
struct user_namespace *user_ns, struct uts_namespace *old_ns)
53+
{
54+
if (flags & CLONE_NEWUTS)
55+
return ERR_PTR(-EINVAL);
56+
57+
return old_ns;
58+
}
59+
60+
static inline void uts_ns_init(void)
61+
{
62+
}
63+
#endif
64+
65+
#endif /* _LINUX_UTS_NAMESPACE_H */

include/linux/utsname.h

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <linux/nsproxy.h>
88
#include <linux/ns_common.h>
99
#include <linux/err.h>
10-
#include <uapi/linux/utsname.h>
10+
#include <linux/uts_namespace.h>
1111

1212
enum uts_proc {
1313
UTS_PROC_ARCH,
@@ -18,62 +18,6 @@ enum uts_proc {
1818
UTS_PROC_DOMAINNAME,
1919
};
2020

21-
struct user_namespace;
22-
extern struct user_namespace init_user_ns;
23-
24-
struct uts_namespace {
25-
struct new_utsname name;
26-
struct user_namespace *user_ns;
27-
struct ucounts *ucounts;
28-
struct ns_common ns;
29-
} __randomize_layout;
30-
extern struct uts_namespace init_uts_ns;
31-
32-
#ifdef CONFIG_UTS_NS
33-
static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
34-
{
35-
return container_of(ns, struct uts_namespace, ns);
36-
}
37-
38-
static inline void get_uts_ns(struct uts_namespace *ns)
39-
{
40-
refcount_inc(&ns->ns.count);
41-
}
42-
43-
extern struct uts_namespace *copy_utsname(unsigned long flags,
44-
struct user_namespace *user_ns, struct uts_namespace *old_ns);
45-
extern void free_uts_ns(struct uts_namespace *ns);
46-
47-
static inline void put_uts_ns(struct uts_namespace *ns)
48-
{
49-
if (refcount_dec_and_test(&ns->ns.count))
50-
free_uts_ns(ns);
51-
}
52-
53-
void uts_ns_init(void);
54-
#else
55-
static inline void get_uts_ns(struct uts_namespace *ns)
56-
{
57-
}
58-
59-
static inline void put_uts_ns(struct uts_namespace *ns)
60-
{
61-
}
62-
63-
static inline struct uts_namespace *copy_utsname(unsigned long flags,
64-
struct user_namespace *user_ns, struct uts_namespace *old_ns)
65-
{
66-
if (flags & CLONE_NEWUTS)
67-
return ERR_PTR(-EINVAL);
68-
69-
return old_ns;
70-
}
71-
72-
static inline void uts_ns_init(void)
73-
{
74-
}
75-
#endif
76-
7721
#ifdef CONFIG_PROC_SYSCTL
7822
extern void uts_proc_notify(enum uts_proc proc);
7923
#else

0 commit comments

Comments
 (0)