Skip to content

Commit a382a34

Browse files
beshlemanPaolo Abeni
authored andcommitted
selftests/vsock: change tests to respect write-once child ns mode
The child_ns_mode sysctl parameter becomes write-once in a future patch in this series, which breaks existing tests. This patch updates the tests to respect this new policy. No additional tests are added. Add "global-parent" and "local-parent" namespaces as intermediaries to spawn namespaces in the given modes. This avoids the need to change "child_ns_mode" in the init_ns. nsenter must be used because ip netns unshares the mount namespace so nested "ip netns add" breaks exec calls from the init ns. Adds nsenter to the deps check. Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Bobby Eshleman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 97f87e5 commit a382a34

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

tools/testing/selftests/vsock/vmtest.sh

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,21 @@ check_result() {
210210
}
211211

212212
add_namespaces() {
213-
local orig_mode
214-
orig_mode=$(cat /proc/sys/net/vsock/child_ns_mode)
215-
216-
for mode in "${NS_MODES[@]}"; do
217-
echo "${mode}" > /proc/sys/net/vsock/child_ns_mode
218-
ip netns add "${mode}0" 2>/dev/null
219-
ip netns add "${mode}1" 2>/dev/null
220-
done
221-
222-
echo "${orig_mode}" > /proc/sys/net/vsock/child_ns_mode
213+
ip netns add "global-parent" 2>/dev/null
214+
echo "global" | ip netns exec "global-parent" \
215+
tee /proc/sys/net/vsock/child_ns_mode &>/dev/null
216+
ip netns add "local-parent" 2>/dev/null
217+
echo "local" | ip netns exec "local-parent" \
218+
tee /proc/sys/net/vsock/child_ns_mode &>/dev/null
219+
220+
nsenter --net=/var/run/netns/global-parent \
221+
ip netns add "global0" 2>/dev/null
222+
nsenter --net=/var/run/netns/global-parent \
223+
ip netns add "global1" 2>/dev/null
224+
nsenter --net=/var/run/netns/local-parent \
225+
ip netns add "local0" 2>/dev/null
226+
nsenter --net=/var/run/netns/local-parent \
227+
ip netns add "local1" 2>/dev/null
223228
}
224229

225230
init_namespaces() {
@@ -237,6 +242,8 @@ del_namespaces() {
237242
log_host "removed ns ${mode}0"
238243
log_host "removed ns ${mode}1"
239244
done
245+
ip netns del "global-parent" &>/dev/null
246+
ip netns del "local-parent" &>/dev/null
240247
}
241248

242249
vm_ssh() {
@@ -287,7 +294,7 @@ check_args() {
287294
}
288295

289296
check_deps() {
290-
for dep in vng ${QEMU} busybox pkill ssh ss socat; do
297+
for dep in vng ${QEMU} busybox pkill ssh ss socat nsenter; do
291298
if [[ ! -x $(command -v "${dep}") ]]; then
292299
echo -e "skip: dependency ${dep} not found!\n"
293300
exit "${KSFT_SKIP}"
@@ -1231,12 +1238,8 @@ test_ns_local_same_cid_ok() {
12311238
}
12321239

12331240
test_ns_host_vsock_child_ns_mode_ok() {
1234-
local orig_mode
1235-
local rc
1236-
1237-
orig_mode=$(cat /proc/sys/net/vsock/child_ns_mode)
1241+
local rc="${KSFT_PASS}"
12381242

1239-
rc="${KSFT_PASS}"
12401243
for mode in "${NS_MODES[@]}"; do
12411244
local ns="${mode}0"
12421245

@@ -1246,15 +1249,13 @@ test_ns_host_vsock_child_ns_mode_ok() {
12461249
continue
12471250
fi
12481251

1249-
if ! echo "${mode}" > /proc/sys/net/vsock/child_ns_mode; then
1250-
log_host "child_ns_mode should be writable to ${mode}"
1252+
if ! echo "${mode}" | ip netns exec "${ns}" \
1253+
tee /proc/sys/net/vsock/child_ns_mode &>/dev/null; then
12511254
rc="${KSFT_FAIL}"
12521255
continue
12531256
fi
12541257
done
12551258

1256-
echo "${orig_mode}" > /proc/sys/net/vsock/child_ns_mode
1257-
12581259
return "${rc}"
12591260
}
12601261

0 commit comments

Comments
 (0)