Bug 8536

Summary: rmdir shows wrong behaviour when trying to remove a mountpoint
Product: [Retired] Red Hat Linux Reporter: Dmitry Pugachov <dima_p>
Component: kernelAssignee: Michael K. Johnson <johnsonm>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-01-17 13:49:11 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Dmitry Pugachov 2000-01-17 13:49:11 UTC
When rmdir() is called with a mounpoint (directory with a mounted
filesystem) name as the argument, it returns ENOENT error code. It appears
that there is a bug in the do_rmdir() routine (fs/namei.c module):

...........
        dentry = lookup_dentry(name, NULL, 0);
...........
        dir = dget(dentry->d_parent);
...........
        error = -ENOENT;
        if (check_parent(dir, dentry))
                error = vfs_rmdir(dir->d_inode, dentry);
...........

lookup_dentry() will return the dentry for the root of the mounted
filesystem, thus resulting in that dir will be the same as dentry (d_parent
field of "/" points to itself). After that, check_parent() will fail
(because dir == dentry), and ENOENT will be returned.

Clearly, "no such file or directory" is not the right way to tell the user
that she's trying to rmdir() a mountpoint. Changing check_parent() to:

#define check_parent(dir, dentry) \
        ((dir) == (dentry) || (dir) == (dentry)->d_parent &&
!list_empty(&dentry->d_hash))

fixes the problem, but that might cause some trouble with parent locking,
or am I wrong?