[LTP] [PATCH] syscalls/statx01: Add stx_mnt_id check

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Tue Nov 30 04:40:43 CET 2021


Hi Cyril
> Hi!
>> +static int file_fd = -1;
>> +
>> +#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
>> +static void test_mnt_id(struct statx *buf)
>> +{
>> +	FILE *file;
>> +	char line[PATH_MAX];
>> +	int pid;
>> +	unsigned int line_mjr, line_mnr, mnt_id;
>
> Shouldn't we check the STATX_MNT_ID bit here before we event attempt to
> continue? Otherwise if we compile the test with headers where stx_mnt_id
> is defined then run it on old kernel there will be garbage in the
> stx_mnt_id field.
Agree.
>
>> +	file = SAFE_FOPEN("/proc/self/mountinfo", "r");
>> +
>> +	while (fgets(line, sizeof(line), file)) {
>> +		if (sscanf(line, "%d %*d %d:%d",&mnt_id,&line_mjr,&line_mnr) != 3)
>> +			continue;
>> +
>> +		if (line_mjr == buf->stx_dev_major&&  line_mnr == buf->stx_dev_minor)
>> +			break;
>> +	}
>> +
>> +	SAFE_FCLOSE(file);
>> +
>> +	if (buf->stx_mnt_id == mnt_id)
>> +		tst_res(TPASS,
>> +			"statx.stx_mnt_id equals to mount_id(%d) in /proc/self/mountinfo",
>> +			mnt_id);
>> +	else
>> +		tst_res(TFAIL,
>> +			"statx.stx_mnt_id(%d) is different from mount_id(%d) in /proc/self/mountinfo",
>> +			buf->stx_mnt_id, mnt_id);
>> +
>> +	pid = getpid();
>> +	snprintf(line, PATH_MAX, "/proc/%d/fdinfo/%d", pid, file_fd);
>> +	TST_ASSERT_FILE_INT(line, "mnt_id:", buf->stx_mnt_id);
>> +}
>> +#endif
>> +
>>   static void test_normal_file(void)
>>   {
>>   	struct statx buff;
>> @@ -106,6 +146,11 @@ static void test_normal_file(void)
>>   		tst_res(TFAIL, "stx_nlink(%u) is different from expected(1)",
>>   			buff.stx_nlink);
>>
>> +#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
>> +	test_mnt_id(&buff);
>> +#else
>> +	tst_res(TCONF, "stx_mnt_id was not supported until linux 5.8.");
>
> This is confusing at best, if we end up here we were missing the
> structure member during compilation regardless the kernel version.
>
> So this message really should be:
>
> "stx_mnt_id not defined in struct statx"
Will do it in v2.

Best Regards
Yang Xu
>
>


More information about the ltp mailing list