diff mbox series

syscalls/acct02.c: Read threshold from /proc/sys/kernel/acct

Message ID 1563203796-22102-1-git-send-email-ice_yangxiao@163.com
State Changes Requested
Headers show
Series syscalls/acct02.c: Read threshold from /proc/sys/kernel/acct | expand

Commit Message

Xiao Yang July 15, 2019, 3:16 p.m. UTC
Don't use hardcoded threshold(default 4%) to check free space
because it can be changed by writing "/proc/sys/kernel/acct"
or using sysctl.

Signed-off-by: Xiao Yang <ice_yangxiao@163.com>
---
 testcases/kernel/syscalls/acct/acct02.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Cyril Hrubis July 15, 2019, 4 p.m. UTC | #1
Hi!
> Don't use hardcoded threshold(default 4%) to check free space
> because it can be changed by writing "/proc/sys/kernel/acct"
> or using sysctl.

Good catch, I missed the sysctl API since I haven't realized that the
proc handlers are all stuffed in a different file in kernel/sysctl.c.

What about we as well temporarily lower the value if needed while the
test is running?
Xiao Yang July 16, 2019, 2:04 p.m. UTC | #2
On 07/16/2019 12:00 AM, Cyril Hrubis wrote:
> Hi!
>> Don't use hardcoded threshold(default 4%) to check free space
>> because it can be changed by writing "/proc/sys/kernel/acct"
>> or using sysctl.
> Good catch, I missed the sysctl API since I haven't realized that the
> proc handlers are all stuffed in a different file in kernel/sysctl.c.
>
> What about we as well temporarily lower the value if needed while the
> test is running?
Hi Cyril,

When free space is not enough, test can change the threshold by itself
or remind user to modify the threshold by sysctl API manually.

Which one do you prefer?

Best Regards,
Xiao Yang
>
Cyril Hrubis July 16, 2019, 2:17 p.m. UTC | #3
Hi!
> > Good catch, I missed the sysctl API since I haven't realized that the
> > proc handlers are all stuffed in a different file in kernel/sysctl.c.
> >
> > What about we as well temporarily lower the value if needed while the
> > test is running?
> Hi Cyril,
> 
> When free space is not enough, test can change the threshold by itself
> or remind user to modify the threshold by sysctl API manually.
> 
> Which one do you prefer?

Ideally the test should modify the threshold.
Xiao Yang July 16, 2019, 3:37 p.m. UTC | #4
On 07/16/2019 10:17 PM, Cyril Hrubis wrote:
> Hi!
>>> Good catch, I missed the sysctl API since I haven't realized that the
>>> proc handlers are all stuffed in a different file in kernel/sysctl.c.
>>>
>>> What about we as well temporarily lower the value if needed while the
>>> test is running?
>> Hi Cyril,
>>
>> When free space is not enough, test can change the threshold by itself
>> or remind user to modify the threshold by sysctl API manually.
>>
>> Which one do you prefer?
> Ideally the test should modify the threshold.
Hi Cyril,

OK, I will improve the patch as you suggested. :-)

Best Regards,
Xiao Yang
>
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/acct/acct02.c b/testcases/kernel/syscalls/acct/acct02.c
index c2c2066..9e2f934 100644
--- a/testcases/kernel/syscalls/acct/acct02.c
+++ b/testcases/kernel/syscalls/acct/acct02.c
@@ -150,18 +150,21 @@  static void run(void)
 static void setup(void)
 {
 	struct statfs buf;
+	float limit;
 
 	clock_ticks = SAFE_SYSCONF(_SC_CLK_TCK);
 
 	SAFE_STATFS(".", &buf);
 
 	float avail = (100.00 * buf.f_bavail) / buf.f_blocks;
+	SAFE_FILE_SCANF("/proc/sys/kernel/acct", "%f %*i %*i", &limit);
+	limit += 0.1;
 
 	/* The accounting data are silently discarded on nearly FS */
-	if (avail < 4.1) {
+	if (avail < limit) {
 		tst_brk(TCONF,
-			"Less than 4.1%% (%.2f) of free space on filesystem",
-			avail);
+			"Less than (%.2f)%% (%.2f) of free space on filesystem",
+			limit, avail);
 	}
 
 	TEST(acct(NULL));