diff options
| author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2025-08-03 23:28:48 -0700 | 
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2025-08-03 23:28:48 -0700 | 
| commit | a7bee4e7f78089c101be2ad51f4b5ec64782053e (patch) | |
| tree | 01c730cd0a71026fb1e74d601e1cbb4d0143126a /tools/testing/selftests/filesystems/statmount | |
| parent | 61c6fef7c4b06b4bdbf3142f4e5cace70597e0de (diff) | |
| parent | 45ee66c37f9bd8cff7718c70d84e0291d385a093 (diff) | |
Merge tag 'ib-mfd-gpio-input-pwm-v6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd into next
Merge an immutable branch between MFD, GPIO, Input and PWM to resolve
conflicts for the merge window pull request.
Diffstat (limited to 'tools/testing/selftests/filesystems/statmount')
3 files changed, 46 insertions, 82 deletions
| diff --git a/tools/testing/selftests/filesystems/statmount/Makefile b/tools/testing/selftests/filesystems/statmount/Makefile index 14ee91a41650..8e354fe99b44 100644 --- a/tools/testing/selftests/filesystems/statmount/Makefile +++ b/tools/testing/selftests/filesystems/statmount/Makefile @@ -1,6 +1,10 @@  # SPDX-License-Identifier: GPL-2.0-or-later -CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) +CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) +LDLIBS += -lcap +  TEST_GEN_PROGS := statmount_test statmount_test_ns listmount_test  include ../../lib.mk + +$(OUTPUT)/statmount_test_ns: ../utils.c diff --git a/tools/testing/selftests/filesystems/statmount/statmount.h b/tools/testing/selftests/filesystems/statmount/statmount.h index a7a5289ddae9..99e5ad082fb1 100644 --- a/tools/testing/selftests/filesystems/statmount/statmount.h +++ b/tools/testing/selftests/filesystems/statmount/statmount.h @@ -7,6 +7,42 @@  #include <linux/mount.h>  #include <asm/unistd.h> +#ifndef __NR_statmount +	#if defined __alpha__ +		#define __NR_statmount 567 +	#elif defined _MIPS_SIM +		#if _MIPS_SIM == _MIPS_SIM_ABI32	/* o32 */ +			#define __NR_statmount 4457 +		#endif +		#if _MIPS_SIM == _MIPS_SIM_NABI32	/* n32 */ +			#define __NR_statmount 6457 +		#endif +		#if _MIPS_SIM == _MIPS_SIM_ABI64	/* n64 */ +			#define __NR_statmount 5457 +		#endif +	#else +		#define __NR_statmount 457 +	#endif +#endif + +#ifndef __NR_listmount +	#if defined __alpha__ +		#define __NR_listmount 568 +	#elif defined _MIPS_SIM +		#if _MIPS_SIM == _MIPS_SIM_ABI32	/* o32 */ +			#define __NR_listmount 4458 +		#endif +		#if _MIPS_SIM == _MIPS_SIM_NABI32	/* n32 */ +			#define __NR_listmount 6458 +		#endif +		#if _MIPS_SIM == _MIPS_SIM_ABI64	/* n64 */ +			#define __NR_listmount 5458 +		#endif +	#else +		#define __NR_listmount 458 +	#endif +#endif +  static inline int statmount(uint64_t mnt_id, uint64_t mnt_ns_id, uint64_t mask,  			    struct statmount *buf, size_t bufsize,  			    unsigned int flags) diff --git a/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c b/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c index 70cb0c8b21cf..605a3fa16bf7 100644 --- a/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c +++ b/tools/testing/selftests/filesystems/statmount/statmount_test_ns.c @@ -14,6 +14,7 @@  #include <linux/stat.h>  #include "statmount.h" +#include "../utils.h"  #include "../../kselftest.h"  #define NSID_PASS 0 @@ -78,87 +79,10 @@ static int get_mnt_ns_id(const char *mnt_ns, uint64_t *mnt_ns_id)  	return NSID_PASS;  } -static int get_mnt_id(const char *path, uint64_t *mnt_id) -{ -	struct statx sx; -	int ret; - -	ret = statx(AT_FDCWD, path, 0, STATX_MNT_ID_UNIQUE, &sx); -	if (ret == -1) { -		ksft_print_msg("retrieving unique mount ID for %s: %s\n", path, -			       strerror(errno)); -		return NSID_ERROR; -	} - -	if (!(sx.stx_mask & STATX_MNT_ID_UNIQUE)) { -		ksft_print_msg("no unique mount ID available for %s\n", path); -		return NSID_ERROR; -	} - -	*mnt_id = sx.stx_mnt_id; -	return NSID_PASS; -} - -static int write_file(const char *path, const char *val) -{ -	int fd = open(path, O_WRONLY); -	size_t len = strlen(val); -	int ret; - -	if (fd == -1) { -		ksft_print_msg("opening %s for write: %s\n", path, strerror(errno)); -		return NSID_ERROR; -	} - -	ret = write(fd, val, len); -	if (ret == -1) { -		ksft_print_msg("writing to %s: %s\n", path, strerror(errno)); -		return NSID_ERROR; -	} -	if (ret != len) { -		ksft_print_msg("short write to %s\n", path); -		return NSID_ERROR; -	} - -	ret = close(fd); -	if (ret == -1) { -		ksft_print_msg("closing %s\n", path); -		return NSID_ERROR; -	} - -	return NSID_PASS; -} -  static int setup_namespace(void)  { -	int ret; -	char buf[32]; -	uid_t uid = getuid(); -	gid_t gid = getgid(); - -	ret = unshare(CLONE_NEWNS|CLONE_NEWUSER|CLONE_NEWPID); -	if (ret == -1) -		ksft_exit_fail_msg("unsharing mountns and userns: %s\n", -				   strerror(errno)); - -	sprintf(buf, "0 %d 1", uid); -	ret = write_file("/proc/self/uid_map", buf); -	if (ret != NSID_PASS) -		return ret; -	ret = write_file("/proc/self/setgroups", "deny"); -	if (ret != NSID_PASS) -		return ret; -	sprintf(buf, "0 %d 1", gid); -	ret = write_file("/proc/self/gid_map", buf); -	if (ret != NSID_PASS) -		return ret; - -	ret = mount("", "/", NULL, MS_REC|MS_PRIVATE, NULL); -	if (ret == -1) { -		ksft_print_msg("making mount tree private: %s\n", -			       strerror(errno)); +	if (setup_userns() != 0)  		return NSID_ERROR; -	}  	return NSID_PASS;  } @@ -174,9 +98,9 @@ static int _test_statmount_mnt_ns_id(void)  	if (ret != NSID_PASS)  		return ret; -	ret = get_mnt_id("/", &root_id); -	if (ret != NSID_PASS) -		return ret; +	root_id = get_unique_mnt_id("/"); +	if (!root_id) +		return NSID_ERROR;  	ret = statmount(root_id, 0, STATMOUNT_MNT_NS_ID, &sm, sizeof(sm), 0);  	if (ret == -1) { | 
