Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.

Commit 70ace81

Browse files
committed
support umount moduls
1 parent 3cdfe53 commit 70ace81

File tree

4 files changed

+296
-5
lines changed

4 files changed

+296
-5
lines changed

fs/namespace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ static void put_mountpoint(struct mountpoint *mp)
797797
}
798798
}
799799

800-
static inline int check_mnt(struct mount *mnt)
800+
inline int check_mnt(struct mount *mnt)
801801
{
802802
return mnt->mnt_ns == current->nsproxy->mnt_ns;
803803
}
@@ -1170,7 +1170,7 @@ void flush_delayed_mntput_wait(void)
11701170
flush_delayed_work(&delayed_mntput_work);
11711171
}
11721172

1173-
static void mntput_no_expire(struct mount *mnt)
1173+
void mntput_no_expire(struct mount *mnt)
11741174
{
11751175
rcu_read_lock();
11761176
if (likely(READ_ONCE(mnt->mnt_ns))) {
@@ -1550,7 +1550,7 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)
15501550

15511551
static void shrink_submounts(struct mount *mnt);
15521552

1553-
static int do_umount(struct mount *mnt, int flags)
1553+
int do_umount(struct mount *mnt, int flags)
15541554
{
15551555
struct super_block *sb = mnt->mnt.mnt_sb;
15561556
int retval;
@@ -1689,7 +1689,7 @@ void __detach_mounts(struct dentry *dentry)
16891689
/*
16901690
* Is the caller allowed to modify his namespace?
16911691
*/
1692-
static inline bool may_mount(void)
1692+
inline bool may_mount(void)
16931693
{
16941694
return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
16951695
}

kernel/cgroup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3859,6 +3859,10 @@ static int cgroup_add_file(struct cgroup_subsys_state *css, struct cgroup *cgrp,
38593859
cfile->kn = kn;
38603860
spin_unlock_irq(&cgroup_file_kn_lock);
38613861
}
3862+
if (cft->ss && (cgrp->root->flags & CGRP_ROOT_NOPREFIX) && !(cft->flags & CFTYPE_NO_PREFIX)) {
3863+
snprintf(name, CGROUP_FILE_NAME_MAX, "%s.%s", cft->ss->name, cft->name);
3864+
kernfs_create_link(cgrp->kn, name, kn);
3865+
}
38623866

38633867
return 0;
38643868
}

lxc-checkconfig

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: LGPL-2.1+
3+
4+
export LC_ALL=C.UTF-8
5+
export LANGUAGE=en
6+
7+
# Allow environment variables to override config
8+
: "${CONFIG:=/proc/config.gz}"
9+
: "${MODNAME:=configs}"
10+
11+
GREP="grep"
12+
13+
if [ -t 1 ]; then
14+
SETCOLOR_SUCCESS="printf \\033[1;32m"
15+
SETCOLOR_FAILURE="printf \\033[1;31m"
16+
SETCOLOR_WARNING="printf \\033[1;33m"
17+
SETCOLOR_NORMAL="printf \\033[0;39m"
18+
else
19+
SETCOLOR_SUCCESS=":"
20+
SETCOLOR_FAILURE=":"
21+
SETCOLOR_WARNING=":"
22+
SETCOLOR_NORMAL=":"
23+
fi
24+
25+
is_set() {
26+
$GREP -wm1 "^${1}=[y|m]" "${CONFIG}" > /dev/null
27+
return $?
28+
}
29+
30+
show_enabled() {
31+
RES=$1
32+
RET=1
33+
if [ "$RES" -eq 0 ]; then
34+
$SETCOLOR_SUCCESS && printf "enabled" && $SETCOLOR_NORMAL
35+
RET=0
36+
else
37+
if [ -n "$mandatory" ] && [ "$mandatory" = yes ]; then
38+
$SETCOLOR_FAILURE && printf "required" && $SETCOLOR_NORMAL
39+
else
40+
$SETCOLOR_WARNING && printf "missing" && $SETCOLOR_NORMAL
41+
fi
42+
fi
43+
return $RET
44+
}
45+
46+
is_enabled() {
47+
mandatory=$2
48+
49+
is_set "$1"
50+
show_enabled $?
51+
}
52+
53+
has_cgroup_ns() {
54+
mandatory=no
55+
56+
if [ -f "/proc/self/ns/cgroup" ]; then
57+
show_enabled 0
58+
else
59+
show_enabled 1
60+
fi
61+
}
62+
63+
is_probed() {
64+
if [ ! -f /proc/modules ]; then
65+
return
66+
fi
67+
if lsmod | grep -wm1 "^${1}" > /dev/null; then
68+
printf ", loaded"
69+
else
70+
printf ", not loaded"
71+
fi
72+
}
73+
74+
if command -v lxc-start >/dev/null; then
75+
echo "LXC version $(lxc-start --version)"
76+
fi
77+
78+
if [ ! -f $CONFIG ]; then
79+
echo "Kernel configuration not found at $CONFIG; searching..."
80+
KVER="$(uname -r)"
81+
HEADERS_CONFIG="/lib/modules/$KVER/build/.config"
82+
BOOT_CONFIG="/boot/config-$KVER"
83+
[ -f "${HEADERS_CONFIG}" ] && CONFIG=${HEADERS_CONFIG}
84+
[ -f "${BOOT_CONFIG}" ] && CONFIG=${BOOT_CONFIG}
85+
if [ ! -f "$CONFIG" ]; then
86+
MODULEFILE="$(modinfo -k "$KVER" -n "$MODNAME" 2> /dev/null)"
87+
# don't want to modprobe, so give user a hint
88+
# although scripts/extract-ikconfig could be used to extract contents without loading kernel module
89+
# http://svn.pld-linux.org/trac/svn/browser/geninitrd/trunk/geninitrd?rev=12696#L327
90+
fi
91+
if [ ! -f "$CONFIG" ]; then
92+
echo "$(basename "$0"): unable to retrieve kernel configuration" >&2
93+
echo >&2
94+
if [ -f "$MODULEFILE" ]; then
95+
echo "Try modprobe $MODNAME module, or" >&2
96+
fi
97+
echo "Try recompiling with IKCONFIG_PROC, installing the kernel headers," >&2
98+
echo "or specifying the kernel configuration path with:" >&2
99+
echo " CONFIG=<path> $(basename "$0")" >&2
100+
exit 1
101+
else
102+
echo "Kernel configuration found at $CONFIG"
103+
fi
104+
fi
105+
106+
if gunzip -tq < "$CONFIG" 2>/dev/null; then
107+
GREP="zgrep"
108+
fi
109+
110+
KVER_MAJOR="$($GREP -m1 '^# Linux.*Kernel Configuration' "${CONFIG}" | \
111+
sed -r 's/.* ([0-9])\.[0-9]{1,2}\.[0-9]{1,3}.*/\1/')"
112+
if [ "$KVER_MAJOR" = "2" ]; then
113+
KVER_MINOR="$($GREP -m1 '^# Linux.*Kernel Configuration' "${CONFIG}" | \
114+
sed -r 's/.* 2.6.([0-9]{2}).*/\1/')"
115+
else
116+
KVER_MINOR="$($GREP -m1 '^# Linux.*Kernel Configuration' "${CONFIG}" | \
117+
sed -r 's/.* [0-9]\.([0-9]{1,3})\.[0-9]{1,3}.*/\1/')"
118+
fi
119+
120+
if [ -z "${KVER_MAJOR}" ]; then
121+
echo "WARNING: Unable to detect version from configuration, assuming latest"
122+
echo
123+
KVER_MAJOR="100"
124+
KVER_MINOR="0"
125+
fi
126+
127+
echo "
128+
--- Namespaces ---"
129+
printf "Namespaces: " && is_enabled CONFIG_NAMESPACES yes
130+
echo
131+
printf "Utsname namespace: " && is_enabled CONFIG_UTS_NS
132+
echo
133+
printf "Ipc namespace: " && is_enabled CONFIG_IPC_NS yes
134+
echo
135+
printf "Pid namespace: " && is_enabled CONFIG_PID_NS yes
136+
echo
137+
printf "User namespace: " && is_enabled CONFIG_USER_NS
138+
echo
139+
if is_set CONFIG_USER_NS; then
140+
if command -v newuidmap >/dev/null 2>&1; then
141+
f=$(command -v newuidmap)
142+
if [ ! -u "${f}" ]; then
143+
echo "Warning: newuidmap is not setuid-root"
144+
fi
145+
else
146+
echo "newuidmap is not installed"
147+
fi
148+
if command -v newgidmap >/dev/null 2>&1; then
149+
f=$(command -v newgidmap)
150+
if [ ! -u "${f}" ]; then
151+
echo "Warning: newgidmap is not setuid-root"
152+
fi
153+
else
154+
echo "newgidmap is not installed"
155+
fi
156+
fi
157+
printf "Network namespace: " && is_enabled CONFIG_NET_NS
158+
echo
159+
if [ $KVER_MAJOR -lt 4 ] || { [ $KVER_MAJOR -eq 4 ] && [ $KVER_MINOR -lt 7 ]; }; then
160+
printf "Multiple /dev/pts instances: " && is_enabled DEVPTS_MULTIPLE_INSTANCES
161+
echo
162+
fi
163+
164+
echo "
165+
--- Control groups ---"
166+
printf "Cgroups: " && is_enabled CONFIG_CGROUPS
167+
echo
168+
printf "Cgroup namespace: " && has_cgroup_ns
169+
echo
170+
171+
print_cgroups() {
172+
# print all mountpoints for cgroup filesystems
173+
awk '$1 !~ /#/ && $3 == mp { print $2; } ; END { exit(0); } ' "mp=$1" "$2" ;
174+
}
175+
CGROUP_V1_MNTS=$(print_cgroups cgroup /proc/self/mounts)
176+
CGROUP_V2_MNTS=$(print_cgroups cgroup2 /proc/self/mounts)
177+
178+
echo "Cgroup v1 mount points: "
179+
for mnt in ${CGROUP_V1_MNTS}; do
180+
echo " - ${mnt}"
181+
done
182+
183+
echo "Cgroup v2 mount points: "
184+
for mnt in ${CGROUP_V2_MNTS}; do
185+
echo " - ${mnt}"
186+
done
187+
188+
if [ "${CGROUP_V2_MNTS}" != "/sys/fs/cgroup" ]; then
189+
CGROUP_SYSTEMD_MNTPT=$(echo "$CGROUP_V1_MNTS" | grep -F "/systemd")
190+
if [ -z "$CGROUP_SYSTEMD_MNTPT" ]; then
191+
printf "Cgroup v1 systemd controller: "
192+
$SETCOLOR_FAILURE && echo "missing" && $SETCOLOR_NORMAL
193+
fi
194+
195+
CGROUP_FREEZER_MNTPT=$(echo "$CGROUP_V1_MNTS" | grep -F "/freezer")
196+
if [ -z "$CGROUP_FREEZER_MNTPT" ]; then
197+
printf "Cgroup v1 freezer controller: "
198+
$SETCOLOR_FAILURE && echo "missing" && $SETCOLOR_NORMAL
199+
fi
200+
201+
CGROUP_MNT_PATH=$(echo "$CGROUP_V1_MNTS" | head -n 1)
202+
if [ -f "$CGROUP_MNT_PATH/cgroup.clone_children" ]; then
203+
printf "Cgroup v1 clone_children flag: " &&
204+
$SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
205+
fi
206+
fi
207+
208+
printf "Cgroup device: " && is_enabled CONFIG_CGROUP_DEVICE
209+
echo
210+
211+
printf "Cgroup sched: " && is_enabled CONFIG_CGROUP_SCHED
212+
echo
213+
214+
printf "Cgroup cpu account: " && is_enabled CONFIG_CGROUP_CPUACCT
215+
echo
216+
217+
printf "Cgroup memory controller: "
218+
if { [ $KVER_MAJOR -ge 3 ] && [ $KVER_MINOR -ge 6 ]; } || [ $KVER_MAJOR -gt 3 ]; then
219+
is_enabled CONFIG_MEMCG
220+
else
221+
is_enabled CONFIG_CGROUP_MEM_RES_CTLR
222+
fi
223+
echo
224+
225+
is_set CONFIG_SMP && printf "Cgroup cpuset: " && is_enabled CONFIG_CPUSETS && echo
226+
227+
echo "
228+
--- Misc ---"
229+
printf "Veth pair device: " && is_enabled CONFIG_VETH && is_probed veth
230+
echo
231+
printf "Macvlan: " && is_enabled CONFIG_MACVLAN && is_probed macvlan
232+
echo
233+
printf "Vlan: " && is_enabled CONFIG_VLAN_8021Q && is_probed 8021q
234+
echo
235+
printf "Bridges: " && is_enabled CONFIG_BRIDGE && is_probed bridge
236+
echo
237+
printf "Advanced netfilter: " && is_enabled CONFIG_NETFILTER_ADVANCED && is_probed nf_tables
238+
if { [ $KVER_MAJOR -gt 3 ] && [ $KVER_MINOR -gt 6 ]; } && [ $KVER_MAJOR -lt 5 ]; then
239+
echo
240+
printf "CONFIG_NF_NAT_IPV4: " && is_enabled CONFIG_NF_NAT_IPV4 && is_probed nf_nat_ipv4
241+
echo
242+
printf "CONFIG_NF_NAT_IPV6: " && is_enabled CONFIG_NF_NAT_IPV6 && is_probed nf_nat_ipv6
243+
fi
244+
echo
245+
printf "CONFIG_IP_NF_TARGET_MASQUERADE: " && is_enabled CONFIG_IP_NF_TARGET_MASQUERADE && is_probed nf_nat_masquerade_ipv4
246+
echo
247+
printf "CONFIG_IP6_NF_TARGET_MASQUERADE: " && is_enabled CONFIG_IP6_NF_TARGET_MASQUERADE && is_probed nf_nat_masquerade_ipv6
248+
echo
249+
printf "CONFIG_NETFILTER_XT_TARGET_CHECKSUM: " && is_enabled CONFIG_NETFILTER_XT_TARGET_CHECKSUM && is_probed xt_CHECKSUM
250+
echo
251+
printf "CONFIG_NETFILTER_XT_MATCH_COMMENT: " && is_enabled CONFIG_NETFILTER_XT_MATCH_COMMENT && is_probed xt_comment
252+
echo
253+
printf "FUSE (for use with lxcfs): " && is_enabled CONFIG_FUSE_FS && is_probed fuse
254+
echo
255+
256+
echo "
257+
--- Checkpoint/Restore ---"
258+
printf "checkpoint restore: " && is_enabled CONFIG_CHECKPOINT_RESTORE
259+
echo
260+
printf "CONFIG_FHANDLE: " && is_enabled CONFIG_FHANDLE
261+
echo
262+
printf "CONFIG_EVENTFD: " && is_enabled CONFIG_EVENTFD
263+
echo
264+
printf "CONFIG_EPOLL: " && is_enabled CONFIG_EPOLL
265+
echo
266+
printf "CONFIG_UNIX_DIAG: " && is_enabled CONFIG_UNIX_DIAG
267+
echo
268+
printf "CONFIG_INET_DIAG: " && is_enabled CONFIG_INET_DIAG
269+
echo
270+
printf "CONFIG_PACKET_DIAG: " && is_enabled CONFIG_PACKET_DIAG
271+
echo
272+
printf "CONFIG_NETLINK_DIAG: " && is_enabled CONFIG_NETLINK_DIAG
273+
echo
274+
printf "File capabilities: "
275+
if [ "${KVER_MAJOR}" = 2 ] && [ ${KVER_MINOR} -lt 33 ]; then
276+
is_enabled CONFIG_SECURITY_FILE_CAPABILITIES
277+
echo
278+
else
279+
$SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
280+
fi
281+
282+
echo "
283+
Note: Before booting a new kernel, you can check its configuration with:
284+
285+
CONFIG=/path/to/config $0
286+
287+
"

0 commit comments

Comments
 (0)