diff mbox series

[v1,2/2] syscalls/mount03: Add MS_STRICTATIME subcase

Message ID 1669375875-1943-2-git-send-email-xuyang2018.jy@fujitsu.com
State Accepted
Headers show
Series [v1,1/2] syscalls/mount03: Add MS_NODIRATIME subcase | expand

Commit Message

Yang Xu Nov. 25, 2022, 11:31 a.m. UTC
This case should check MS_NOATIME and MS_RELATIME are
not inside stat f_flags[1] .

[1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d0adde57
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/mount/mount03.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Richard Palethorpe Nov. 29, 2022, 1:54 p.m. UTC | #1
Hello,

Yang Xu <xuyang2018.jy@fujitsu.com> writes:

> This case should check MS_NOATIME and MS_RELATIME are
> not inside stat f_flags[1] .
>
> [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d0adde57
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  testcases/kernel/syscalls/mount/mount03.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c
> index 31a858c35..60f9963da 100644
> --- a/testcases/kernel/syscalls/mount/mount03.c
> +++ b/testcases/kernel/syscalls/mount/mount03.c
> @@ -19,6 +19,7 @@
>   * - MS_NOSUID - ignore suid and sgid bits
>   * - MS_NOATIME - do not update access times
>   * - MS_NODIRATIME - only update access_time for directory instead of all types
> + * - MS_STRICTATIME - always update access times
>   */
>  
>  #include <stdio.h>
> @@ -164,6 +165,11 @@ static void test_nodiratime(void)
>  	test_file_dir_noatime(1, 0);
>  }
>  
> +static void test_strictatime(void)
> +{
> +	test_file_dir_noatime(1, 1);
> +}
> +
>  #define FLAG_DESC(x) .flag = x, .flag2 = x, .desc = #x
>  #define FLAG_DESC2(x) .flag2 = x, .desc = #x
>  static struct tcase {
> @@ -179,6 +185,7 @@ static struct tcase {
>  	{FLAG_DESC(MS_NOSUID), test_nosuid},
>  	{FLAG_DESC(MS_NOATIME), test_noatime},
>  	{FLAG_DESC(MS_NODIRATIME), test_nodiratime},
> +	{FLAG_DESC(MS_STRICTATIME), test_strictatime}
>  };
>  
>  static void setup(void)
> @@ -215,6 +222,15 @@ static void run(unsigned int n)
>  		tc->test();
>  
>  	SAFE_STATFS(MNTPOINT, &stfs);
> +	if (tc->flag == MS_STRICTATIME) {
> +		if (stfs.f_flags & (MS_NOATIME | MS_RELATIME))
> +			tst_res(TFAIL, "statfs() gets the incorrect mount flag");
> +		else
> +			tst_res(TPASS, "statfs() gets the correct mount flag");
> +		cleanup();
> +		return;
> +	}

We don't need this branch.

> +
>  	if (stfs.f_flags & tc->flag2)

Could change this to something like

if (stfs.f_flags & tc->flag2
   && !(stfs.f_flags & MS_STRICTATIME && stfs.f_flags & (MS_NOATIME | MS_RELATIME))

Or however you would like to format that.
Yang Xu Nov. 30, 2022, 2:02 a.m. UTC | #2
Hi Richard

> Hello,
> 
> Yang Xu <xuyang2018.jy@fujitsu.com> writes:
> 
>> This case should check MS_NOATIME and MS_RELATIME are
>> not inside stat f_flags[1] .
>>
>> [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d0adde57
>> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
>> ---
>>   testcases/kernel/syscalls/mount/mount03.c | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>
>> diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c
>> index 31a858c35..60f9963da 100644
>> --- a/testcases/kernel/syscalls/mount/mount03.c
>> +++ b/testcases/kernel/syscalls/mount/mount03.c
>> @@ -19,6 +19,7 @@
>>    * - MS_NOSUID - ignore suid and sgid bits
>>    * - MS_NOATIME - do not update access times
>>    * - MS_NODIRATIME - only update access_time for directory instead of all types
>> + * - MS_STRICTATIME - always update access times
>>    */
>>   
>>   #include <stdio.h>
>> @@ -164,6 +165,11 @@ static void test_nodiratime(void)
>>   	test_file_dir_noatime(1, 0);
>>   }
>>   
>> +static void test_strictatime(void)
>> +{
>> +	test_file_dir_noatime(1, 1);
>> +}
>> +
>>   #define FLAG_DESC(x) .flag = x, .flag2 = x, .desc = #x
>>   #define FLAG_DESC2(x) .flag2 = x, .desc = #x
>>   static struct tcase {
>> @@ -179,6 +185,7 @@ static struct tcase {
>>   	{FLAG_DESC(MS_NOSUID), test_nosuid},
>>   	{FLAG_DESC(MS_NOATIME), test_noatime},
>>   	{FLAG_DESC(MS_NODIRATIME), test_nodiratime},
>> +	{FLAG_DESC(MS_STRICTATIME), test_strictatime}
>>   };
>>   
>>   static void setup(void)
>> @@ -215,6 +222,15 @@ static void run(unsigned int n)
>>   		tc->test();
>>   
>>   	SAFE_STATFS(MNTPOINT, &stfs);
>> +	if (tc->flag == MS_STRICTATIME) {
>> +		if (stfs.f_flags & (MS_NOATIME | MS_RELATIME))
>> +			tst_res(TFAIL, "statfs() gets the incorrect mount flag");
>> +		else
>> +			tst_res(TPASS, "statfs() gets the correct mount flag");
>> +		cleanup();
>> +		return;
>> +	}
> 
> We don't need this branch.
> 
>> +
>>   	if (stfs.f_flags & tc->flag2)
> 
> Could change this to something like
> 
> if (stfs.f_flags & tc->flag2
>     && !(stfs.f_flags & MS_STRICTATIME && stfs.f_flags & (MS_NOATIME | MS_RELATIME))

I try it, but case reports fail because stfs.f_flags doesn't contain 
MS_STRICTATIME flag.  Sorry, I guess my commit message only mentioned 
that MS_NOATIME and MS_RELATIME are not inside stat f_flags but missed 
that the MS_STRICTATIME flag is ignored by kernel.

Best Regards
Yang Xu
> 
> Or however you would like to format that.
> 
>
Richard Palethorpe Dec. 1, 2022, 9:48 a.m. UTC | #3
"xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com> writes:

> Hi Richard
>
>> Hello,
>> 
>> Yang Xu <xuyang2018.jy@fujitsu.com> writes:
>> 
>>> This case should check MS_NOATIME and MS_RELATIME are
>>> not inside stat f_flags[1] .
>>>
>>> [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d0adde57
>>> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
>>> ---
>>>   testcases/kernel/syscalls/mount/mount03.c | 16 ++++++++++++++++
>>>   1 file changed, 16 insertions(+)
>>>
>>> diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c
>>> index 31a858c35..60f9963da 100644
>>> --- a/testcases/kernel/syscalls/mount/mount03.c
>>> +++ b/testcases/kernel/syscalls/mount/mount03.c
>>> @@ -19,6 +19,7 @@
>>>    * - MS_NOSUID - ignore suid and sgid bits
>>>    * - MS_NOATIME - do not update access times
>>>    * - MS_NODIRATIME - only update access_time for directory instead of all types
>>> + * - MS_STRICTATIME - always update access times
>>>    */
>>>   
>>>   #include <stdio.h>
>>> @@ -164,6 +165,11 @@ static void test_nodiratime(void)
>>>   	test_file_dir_noatime(1, 0);
>>>   }
>>>   
>>> +static void test_strictatime(void)
>>> +{
>>> +	test_file_dir_noatime(1, 1);
>>> +}
>>> +
>>>   #define FLAG_DESC(x) .flag = x, .flag2 = x, .desc = #x
>>>   #define FLAG_DESC2(x) .flag2 = x, .desc = #x
>>>   static struct tcase {
>>> @@ -179,6 +185,7 @@ static struct tcase {
>>>   	{FLAG_DESC(MS_NOSUID), test_nosuid},
>>>   	{FLAG_DESC(MS_NOATIME), test_noatime},
>>>   	{FLAG_DESC(MS_NODIRATIME), test_nodiratime},
>>> +	{FLAG_DESC(MS_STRICTATIME), test_strictatime}
>>>   };
>>>   
>>>   static void setup(void)
>>> @@ -215,6 +222,15 @@ static void run(unsigned int n)
>>>   		tc->test();
>>>   
>>>   	SAFE_STATFS(MNTPOINT, &stfs);
>>> +	if (tc->flag == MS_STRICTATIME) {
>>> +		if (stfs.f_flags & (MS_NOATIME | MS_RELATIME))
>>> +			tst_res(TFAIL, "statfs() gets the incorrect mount flag");
>>> +		else
>>> +			tst_res(TPASS, "statfs() gets the correct mount flag");
>>> +		cleanup();
>>> +		return;
>>> +	}
>> 
>> We don't need this branch.
>> 
>>> +
>>>   	if (stfs.f_flags & tc->flag2)
>> 
>> Could change this to something like
>> 
>> if (stfs.f_flags & tc->flag2
>>     && !(stfs.f_flags & MS_STRICTATIME && stfs.f_flags & (MS_NOATIME | MS_RELATIME))
>
> I try it, but case reports fail because stfs.f_flags doesn't contain 
> MS_STRICTATIME flag.  Sorry, I guess my commit message only mentioned

Ah, sorry, it should be something like:

if (stfs.f_flags & tc->flag2
     && (tc->flag2 != MS_STRICTATIME || !(stfs.f_flags & MS_STRICTATIME
     && stfs.f_flags & (MS_NOATIME | MS_RELATIME)))

but actually this is getting kind of messy now. So I'll merge it as you
sent it. Thanks!
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c
index 31a858c35..60f9963da 100644
--- a/testcases/kernel/syscalls/mount/mount03.c
+++ b/testcases/kernel/syscalls/mount/mount03.c
@@ -19,6 +19,7 @@ 
  * - MS_NOSUID - ignore suid and sgid bits
  * - MS_NOATIME - do not update access times
  * - MS_NODIRATIME - only update access_time for directory instead of all types
+ * - MS_STRICTATIME - always update access times
  */
 
 #include <stdio.h>
@@ -164,6 +165,11 @@  static void test_nodiratime(void)
 	test_file_dir_noatime(1, 0);
 }
 
+static void test_strictatime(void)
+{
+	test_file_dir_noatime(1, 1);
+}
+
 #define FLAG_DESC(x) .flag = x, .flag2 = x, .desc = #x
 #define FLAG_DESC2(x) .flag2 = x, .desc = #x
 static struct tcase {
@@ -179,6 +185,7 @@  static struct tcase {
 	{FLAG_DESC(MS_NOSUID), test_nosuid},
 	{FLAG_DESC(MS_NOATIME), test_noatime},
 	{FLAG_DESC(MS_NODIRATIME), test_nodiratime},
+	{FLAG_DESC(MS_STRICTATIME), test_strictatime}
 };
 
 static void setup(void)
@@ -215,6 +222,15 @@  static void run(unsigned int n)
 		tc->test();
 
 	SAFE_STATFS(MNTPOINT, &stfs);
+	if (tc->flag == MS_STRICTATIME) {
+		if (stfs.f_flags & (MS_NOATIME | MS_RELATIME))
+			tst_res(TFAIL, "statfs() gets the incorrect mount flag");
+		else
+			tst_res(TPASS, "statfs() gets the correct mount flag");
+		cleanup();
+		return;
+	}
+
 	if (stfs.f_flags & tc->flag2)
 		tst_res(TPASS, "statfs() gets the correct mount flag");
 	else