brintos

brintos / linux-shallow public Read only

0
0
Text · 2.4 KiB · 35e8d47 Raw
102 lines · plain
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.03# description: Test tracefs GID mount option4# requires: "[gid=<gid>]":README5 6fail() {7	local msg="$1"8 9	echo "FAILED: $msg"10	exit_fail11}12 13find_alternate_gid() {14	local original_gid="$1"15	tac /etc/group | grep -v ":$original_gid:" | head -1 | cut -d: -f316}17 18mount_tracefs_with_options() {19	local mount_point="$1"20	local options="$2"21 22	mount -t tracefs -o "$options" nodev "$mount_point"23 24	setup25}26 27unmount_tracefs() {28	local mount_point="$1"29 30	# Need to make sure the mount isn't busy so that we can umount it31	(cd $mount_point; finish_ftrace;)32 33	cleanup34}35 36create_instance() {37	local mount_point="$1"38	local instance="$mount_point/instances/$(mktemp -u test-XXXXXX)"39 40	mkdir "$instance"41	echo "$instance"42}43 44remove_instance() {45	local instance="$1"46 47	rmdir "$instance"48}49 50check_gid() {51	local mount_point="$1"52	local expected_gid="$2"53 54	echo "Checking permission group ..."55 56	cd "$mount_point"57 58	for file in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable"; do59		local gid=`stat -c "%g" $file`60		if [ "$gid" -ne "$expected_gid" ]; then61			cd - # Return to the previous working directory (tracefs root)62			fail "$(realpath $file): Expected group $expected_gid; Got group $gid"63		fi64	done65 66	cd - # Return to the previous working directory (tracefs root)67}68 69test_gid_mount_option() {70	local mount_point=$(get_mount_point)71	local mount_options=$(get_mnt_options "$mount_point")72	local original_group=$(stat -c "%g" .)73	local other_group=$(find_alternate_gid "$original_group")74 75	# Set up mount options with new GID for testing76	local new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`77	if [ "$new_options" = "$mount_options" ]; then78		new_options="$mount_options,gid=$other_group"79		mount_options="$mount_options,gid=$original_group"80	fi81 82	# Unmount existing tracefs instance and mount with new GID83	unmount_tracefs "$mount_point"84	mount_tracefs_with_options "$mount_point" "$new_options"85 86	check_gid "$mount_point" "$other_group"87 88	# Check that files created after the mount inherit the GID89	local instance=$(create_instance "$mount_point")90	check_gid "$instance" "$other_group"91	remove_instance "$instance"92 93	# Unmount and remount with the original GID94	unmount_tracefs "$mount_point"95	mount_tracefs_with_options "$mount_point" "$mount_options"96	check_gid "$mount_point" "$original_group"97}98 99test_gid_mount_option100 101exit 0102