mikaku / Fiwix

A UNIX-like kernel for the i386 architecture
https://www.fiwix.org
Other
401 stars 32 forks source link

Allow removing directory in use #59

Closed rick-masters closed 7 months ago

rick-masters commented 7 months ago

Linux allows removing a directory that is the current directory for a running process:

$ mkdir testdir
$ cd testdir
$ rmdir ../testdir
$

Fiwix does not:

[(root) ~]# mkdir testdir
[(root) ~]# cd testdir
[(root) ~/testdir]# rmdir ../testdir
rmdir: failed to remove '../testdir': Device or resource busy
[(root) ~/testdir]#

This issue causes live-bootstrap to fail:

flex-2.5.11: postprocess binaries.
flex-2.5.11: creating package.
flex-2.5.11: cleaning up.
rm: cannot remove directory `/steps/flex-2.5.11/build/flex-2.5.11'
Subprocess error 1
ABORTING HARD
Subprocess error 1
ABORTING HARD

WARNING: the last user process has exited. The kernel will stop itself.

It appears that programs are run in the background as part of the build process for many different packages. These programs don't necessarily finish before the package build finishes. I was not able to find a simple way to avoid this behavior.

I have a patch I have been applying that disables the check in Fiwix, which is in a forthcoming PR. I haven't seen any bad side effects of removing this check but I haven't explored all the possible issues. If there is an issue with this change perhaps it could be configurable.

mikaku commented 7 months ago

Fiwix should allow removing directory as long as the resource (the directory in this case) is freed when its usage counter reaches zero.

I'll test it with a massive package build and I'll let you know the results.

mikaku commented 7 months ago

After a complete package built I've not seen any problem with this change.

Also, I've confirmed that Fiwix correctly frees the space used by the removed directory as soon as no other process uses it:

[(root) ~]# df /
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/hda2        1039752 663583    324182  68% /
[(root) ~]# mkdir testdir
[(root) ~]# cd testdir
[(root) ~/testdir]# df /
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/hda2        1039752 663584    324181  68% /
[(root) ~/testdir]# rmdir ../testdir/
[(root) ~/testdir]# df /
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/hda2        1039752 663584    324181  68% /
[(root) ~/testdir]# cd
[(root) ~]# df /
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/hda2        1039752 663583    324182  68% /
[(root) ~]# 
mikaku commented 7 months ago

Thank you very much.