diff options
author | Eric Dumazet <dada1@cosmosbay.com> | 2006-12-06 23:38:49 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-07 11:39:41 -0500 |
commit | 304e61e6fbadec586dfe002b535f169a04248e49 (patch) | |
tree | b70c8ec7ca6b538b5d02f3c5372a35268643a5bf /net/socket.c | |
parent | b3423415fbc2e5461605826317da1c8dbbf21f97 (diff) |
[PATCH] net: don't insert socket dentries into dentry_hashtable
We currently insert socket dentries into the global dentry hashtable. This
is suboptimal because there is currently no way these entries can be used
for a lookup(). (/proc/xxx/fd/xxx uses a different mechanism). Inserting
them in dentry hashtable slows dcache lookups.
To let __dpath() still work correctly (ie not adding a " (deleted)") after
dentry name, we do :
- Right after d_alloc(), pretend they are hashed by clearing the
DCACHE_UNHASHED bit.
- Call d_instantiate() instead of d_add() : dentry is not inserted in
hash table.
__dpath() & friends work as intended during dentry lifetime.
- At dismantle time, once dput() must clear the dentry, setting again
DCACHE_UNHASHED bit inside the custom d_delete() function provided by
socket code, so that dput() can just kill_it.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/net/socket.c b/net/socket.c index 43eff489c878..29ea1de43ecb 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -305,7 +305,14 @@ static struct file_system_type sock_fs_type = { | |||
305 | 305 | ||
306 | static int sockfs_delete_dentry(struct dentry *dentry) | 306 | static int sockfs_delete_dentry(struct dentry *dentry) |
307 | { | 307 | { |
308 | return 1; | 308 | /* |
309 | * At creation time, we pretended this dentry was hashed | ||
310 | * (by clearing DCACHE_UNHASHED bit in d_flags) | ||
311 | * At delete time, we restore the truth : not hashed. | ||
312 | * (so that dput() can proceed correctly) | ||
313 | */ | ||
314 | dentry->d_flags |= DCACHE_UNHASHED; | ||
315 | return 0; | ||
309 | } | 316 | } |
310 | static struct dentry_operations sockfs_dentry_operations = { | 317 | static struct dentry_operations sockfs_dentry_operations = { |
311 | .d_delete = sockfs_delete_dentry, | 318 | .d_delete = sockfs_delete_dentry, |
@@ -353,14 +360,20 @@ static int sock_attach_fd(struct socket *sock, struct file *file) | |||
353 | 360 | ||
354 | this.len = sprintf(name, "[%lu]", SOCK_INODE(sock)->i_ino); | 361 | this.len = sprintf(name, "[%lu]", SOCK_INODE(sock)->i_ino); |
355 | this.name = name; | 362 | this.name = name; |
356 | this.hash = SOCK_INODE(sock)->i_ino; | 363 | this.hash = 0; |
357 | 364 | ||
358 | file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this); | 365 | file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this); |
359 | if (unlikely(!file->f_dentry)) | 366 | if (unlikely(!file->f_dentry)) |
360 | return -ENOMEM; | 367 | return -ENOMEM; |
361 | 368 | ||
362 | file->f_dentry->d_op = &sockfs_dentry_operations; | 369 | file->f_dentry->d_op = &sockfs_dentry_operations; |
363 | d_add(file->f_dentry, SOCK_INODE(sock)); | 370 | /* |
371 | * We dont want to push this dentry into global dentry hash table. | ||
372 | * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED | ||
373 | * This permits a working /proc/$pid/fd/XXX on sockets | ||
374 | */ | ||
375 | file->f_dentry->d_flags &= ~DCACHE_UNHASHED; | ||
376 | d_instantiate(file->f_dentry, SOCK_INODE(sock)); | ||
364 | file->f_vfsmnt = mntget(sock_mnt); | 377 | file->f_vfsmnt = mntget(sock_mnt); |
365 | file->f_mapping = file->f_dentry->d_inode->i_mapping; | 378 | file->f_mapping = file->f_dentry->d_inode->i_mapping; |
366 | 379 | ||