Skip to contentSkip to conversation

controllers/cpuacct: Fix deleting directories errors

PATCH New Dai Shili 2 participants 3 messages Sep 15, 2021

lore
Share & tools
lore

Dai Shili

author
#0 lore raw

PATCH 1/1 controllers/cpuacct: Fix deleting directories errors

To remove a directory hierarchy on a normal file system you can use rm command to remove all files from each subdirectory and then remove the parent directories. But a cgroup which doesn't have any children and is associated only with zombie processes is considered empty and can not be removed by rm.
The following errors will be reported.

cpuacct 1 TINFO: removing created directories
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cgroup.procs': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpu.cfs_period_us': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpu.stat': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.usage_percpu_sys': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpu.shares': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.usage_percpu': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.stat': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.usage': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/subgroup_1/cgroup.procs': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/subgroup_1/cpu.cfs_period_us': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/subgroup_1/cpu.stat': Operation not permitted
...

It's recommended to use rmdir command.

[1] http://blog.tinola.com/?e=21
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/cgroup-v2.rst#n237

---
 testcases/kernel/controllers/cpuacct/cpuacct.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/controllers/cpuacct/cpuacct.sh +4 -1
index 99258c2..f526d0f 100755
@@ -122,7 +122,10 @@ cleanup()
 
 	if [ "$testpath" ]; then
 		tst_res TINFO "removing created directories"
-		rm -rf $testpath
+		if [ -d "$testpath/subgroup_1" ]; then
+			rmdir $testpath/subgroup_*
+		fi
+			rmdir $testpath
 	fi
 
 	if [ "$mounted" -ne 1 ]; then
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 controllers/cpuacct: Fix deleting directories errors

Hi Dai, Xu,

Quoted 20 lines

To remove a directory hierarchy on a normal file system you can use rm command to remove all files from each subdirectory and then remove the parent directories. But a cgroup which doesn't have any children and is associated only with zombie processes is considered empty and can not be removed by rm.
The following errors will be reported.

cpuacct 1 TINFO: removing created directories
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cgroup.procs': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpu.cfs_period_us': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpu.stat': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.usage_percpu_sys': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpu.shares': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.usage_percpu': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.stat': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/cpuacct.usage': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/subgroup_1/cgroup.procs': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/subgroup_1/cpu.cfs_period_us': Operation not permitted
rm: cannot remove '/sys/fs/cgroup/cpu,cpuacct/ltp_cpuacct/subgroup_1/cpu.stat': Operation not permitted
...

Quoted 1 line

It's recommended to use rmdir command.

Sorry for introducing a regression and for correction.
I'll revert on your behalf commit d6cc08592 ("controllers/cpuacct: Simplify deleting directories"), with your explanation.

Kind regards,
Petr

Quoted 25 lines

[1] http://blog.tinola.com/?e=21
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/cgroup-v2.rst#n237

---
 testcases/kernel/controllers/cpuacct/cpuacct.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
testcases/kernel/controllers/cpuacct/cpuacct.sh +4 -1
index 99258c2..f526d0f 100755
@@ -122,7 +122,10 @@ cleanup()
 
 	if [ "$testpath" ]; then
 		tst_res TINFO "removing created directories"
-		rm -rf $testpath
+		if [ -d "$testpath/subgroup_1" ]; then
+			rmdir $testpath/subgroup_*
+		fi
+			rmdir $testpath
 	fi
 
 	if [ "$mounted" -ne 1 ]; then
#2 lore raw

PATCH 1/1 controllers/cpuacct: Fix deleting directories errors

Hi Dai, Xu,

...

Quoted 3 lines

Sorry for introducing a regression and for correction.
I'll revert on your behalf commit d6cc08592 ("controllers/cpuacct: Simplify deleting directories"), with your explanation.

FYI Merged!

Kind regards,
Petr