public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [BUG] Inconsistent behaviour of rmdir
@ 2000-11-16 13:47 Jean-Marc Saffroy
  2000-11-16 15:49 ` Linus Torvalds
  2000-11-17 17:56 ` Guest section DW
  0 siblings, 2 replies; 19+ messages in thread
From: Jean-Marc Saffroy @ 2000-11-16 13:47 UTC (permalink / raw)
  To: torvalds, viro, linux-kernel; +Cc: Eric Paire, Jean-Marc Saffroy

Hello,


It looks like the rmdir syscall behaves strangely in 2.4 kernels :

saffroy@sisley:~> uname -a
Linux sisley 2.2.14-5.0smp #1 SMP Tue Mar 7 21:01:40 EST 2000 i686 unknown
saffroy@sisley:/tmp> mkdir foo
saffroy@sisley:/tmp> rmdir foo/.
saffroy@sisley:/tmp> mkdir foo
saffroy@sisley:/tmp> cd foo/
saffroy@sisley:/tmp/foo> rmdir .
saffroy@sisley:/tmp/foo> cd ..
saffroy@sisley:/tmp> 

[root@picasso /tmp]# uname -a
Linux picasso 2.4.0-test10 #1 SMP Thu Nov 9 14:30:23 GMT+2 2000 i586 unknown
[root@picasso /tmp]# mkdir foo
[root@picasso /tmp]# rmdir foo/.
rmdir: foo/.: Device or resource busy
[root@picasso /tmp]# rmdir foo/ 
[root@picasso /tmp]# mkdir foo
[root@picasso /tmp]# cd foo
[root@picasso foo]# rmdir .
rmdir: .: Device or resource busy
[root@picasso foo]# rmdir ../foo/
[root@picasso foo]#

As you see, it looks like the rmdir fails simply because the dir name ends
with a dot !! This is confirmed by sys_rmdir in fs/namei.c, around line
1384 :

        switch(nd.last_type) {
                case LAST_DOTDOT:
                        error = -ENOTEMPTY;
                        goto exit1;
                case LAST_ROOT: case LAST_DOT:
                        error = -EBUSY;
                        goto exit1;
        }

Should we rip off the offending "case LAST_DOT" ? Or do we need a smarter
patch ? Is it really a problem that a process has its current directory
deleted ? How about the root ?

The man page for rmdir(2) should be updated as well, the current one
states :
       EBUSY  pathname is the current working directory  or  root
              directory of some process.

Maybe rmdir should return EBUSY only when trying to remove a mount point ?


Regards,

-- 
Jean-Marc Saffroy - Research Engineer - Silicomp Research Institute
mailto:jms@migrantprogrammer.com

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: [BUG] Inconsistent behaviour of rmdir
@ 2000-11-16 16:07 Jesse Pollard
  0 siblings, 0 replies; 19+ messages in thread
From: Jesse Pollard @ 2000-11-16 16:07 UTC (permalink / raw)
  To: saffroy, torvalds, viro, linux-kernel

Jean-Marc Saffroy <saffroy@ri.silicomp.fr>:
> 
> It looks like the rmdir syscall behaves strangely in 2.4 kernels :
> 
> saffroy@sisley:~> uname -a
> Linux sisley 2.2.14-5.0smp #1 SMP Tue Mar 7 21:01:40 EST 2000 i686 unknown
> saffroy@sisley:/tmp> mkdir foo
> saffroy@sisley:/tmp> rmdir foo/.
> saffroy@sisley:/tmp> mkdir foo
> saffroy@sisley:/tmp> cd foo/
> saffroy@sisley:/tmp/foo> rmdir .
> saffroy@sisley:/tmp/foo> cd ..
> saffroy@sisley:/tmp> 
> 
> [root@picasso /tmp]# uname -a
> Linux picasso 2.4.0-test10 #1 SMP Thu Nov 9 14:30:23 GMT+2 2000 i586 unknown
> [root@picasso /tmp]# mkdir foo
> [root@picasso /tmp]# rmdir foo/.
> rmdir: foo/.: Device or resource busy
> [root@picasso /tmp]# rmdir foo/ 
> [root@picasso /tmp]# mkdir foo
> [root@picasso /tmp]# cd foo
> [root@picasso foo]# rmdir .
> rmdir: .: Device or resource busy
> [root@picasso foo]# rmdir ../foo/
> [root@picasso foo]#
> 
> As you see, it looks like the rmdir fails simply because the dir name ends
> with a dot !! This is confirmed by sys_rmdir in fs/namei.c, around line
> 1384 :
> 
>         switch(nd.last_type) {
>                 case LAST_DOTDOT:
>                         error = -ENOTEMPTY;
>                         goto exit1;
>                 case LAST_ROOT: case LAST_DOT:
>                         error = -EBUSY;
>                         goto exit1;
>         }
> 
> Should we rip off the offending "case LAST_DOT" ? Or do we need a smarter
> patch ? Is it really a problem that a process has its current directory
> deleted ? How about the root ?
> 
> The man page for rmdir(2) should be updated as well, the current one
> states :
>        EBUSY  pathname is the current working directory  or  root
>               directory of some process.
> 
> Maybe rmdir should return EBUSY only when trying to remove a mount point ?

This may not be relevent, but it actually is busy - consider that the
namei lookup must open the directory named "foo" (during the unlink
processing. While that directory is open it is searched for the name ".".

Now that the path is recognized, the unlink attempts to remove the directory
"." from the directory. This is a loop, which is held busy by the lookup of
the name "foo/.".  Since this REALLY is a hard link between "." and "foo",
there is no way to know what is causing it to be busy - another process, or
a different open on the directory (foo is open for modification after all).

I admit that some special case handling such as verifying that the use
count of . equals 1 AND that the inode of "." equals the inode of "foo"
before allowing it (and foo) to be removed would work.

But why bother. It is busy, even if only by the process attempting the
unlink, and then only during the unlink system call. This becomes a
sort of recursive use of the unlink system call, that must also unlink
the name "foo" from the parent directory (.., or the directory containing foo).
If the parent directory is NOT handled then you get a corrupted directory
named foo, that doesn't have "." in it.

It would be simpler to just say "don't do that".

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: pollard@navo.hpc.mil

Any opinions expressed are solely my own.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2000-11-20 10:09 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-16 13:47 [BUG] Inconsistent behaviour of rmdir Jean-Marc Saffroy
2000-11-16 15:49 ` Linus Torvalds
2000-11-16 17:49   ` Alexander Viro
2000-11-16 18:14   ` Jean-Marc Saffroy
2000-11-16 18:28     ` Alexander Viro
2000-11-16 18:51       ` Jean-Marc Saffroy
2000-11-16 18:59         ` Alexander Viro
2000-11-16 21:17       ` David Feuer
2000-11-16 22:35         ` H. Peter Anvin
2000-11-16 23:10           ` Alexander Viro
2000-11-16 23:43           ` David Feuer
2000-11-17  0:04             ` Alexander Viro
2000-11-18  1:30               ` Nix
2000-11-18  1:58                 ` Alexander Viro
2000-11-17 17:56 ` Guest section DW
2000-11-17 20:27   ` Alexander Viro
2000-11-20  8:32     ` Eric Paire
2000-11-20  9:39       ` Guest section DW
  -- strict thread matches above, loose matches on Subject: below --
2000-11-16 16:07 Jesse Pollard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox