[GFS2] Patch to remove stats gathering from GFS2
[safe/jmp/linux-2.6] / fs / gfs2 / ops_dentry.c
1 /*
2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3  * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
4  *
5  * This copyrighted material is made available to anyone wishing to use,
6  * modify, copy, or redistribute it subject to the terms and conditions
7  * of the GNU General Public License v.2.
8  */
9
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/smp_lock.h>
16 #include <asm/semaphore.h>
17
18 #include "gfs2.h"
19 #include "dir.h"
20 #include "glock.h"
21 #include "ops_dentry.h"
22
23 /**
24  * gfs2_drevalidate - Check directory lookup consistency
25  * @dentry: the mapping to check
26  * @nd:
27  *
28  * Check to make sure the lookup necessary to arrive at this inode from its
29  * parent is still good.
30  *
31  * Returns: 1 if the dentry is ok, 0 if it isn't
32  */
33
34 static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
35 {
36         struct dentry *parent = dget_parent(dentry);
37         struct gfs2_inode *dip = get_v2ip(parent->d_inode);
38         struct gfs2_sbd *sdp = dip->i_sbd;
39         struct inode *inode;
40         struct gfs2_holder d_gh;
41         struct gfs2_inode *ip;
42         struct gfs2_inum inum;
43         unsigned int type;
44         int error;
45
46         lock_kernel();
47
48         inode = dentry->d_inode;
49         if (inode && is_bad_inode(inode))
50                 goto invalid;
51
52         error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
53         if (error)
54                 goto fail;
55
56         error = gfs2_dir_search(dip, &dentry->d_name, &inum, &type);
57         switch (error) {
58         case 0:
59                 if (!inode)
60                         goto invalid_gunlock;
61                 break;
62         case -ENOENT:
63                 if (!inode)
64                         goto valid_gunlock;
65                 goto invalid_gunlock;
66         default:
67                 goto fail_gunlock;
68         }
69
70         ip = get_v2ip(inode);
71
72         if (!gfs2_inum_equal(&ip->i_num, &inum))
73                 goto invalid_gunlock;
74
75         if (IF2DT(ip->i_di.di_mode) != type) {
76                 gfs2_consist_inode(dip);
77                 goto fail_gunlock;
78         }
79
80  valid_gunlock:
81         gfs2_glock_dq_uninit(&d_gh);
82
83  valid:
84         unlock_kernel();
85         dput(parent);
86         return 1;
87
88  invalid_gunlock:
89         gfs2_glock_dq_uninit(&d_gh);
90
91  invalid:
92         if (inode && S_ISDIR(inode->i_mode)) {
93                 if (have_submounts(dentry))
94                         goto valid;
95                 shrink_dcache_parent(dentry);
96         }
97         d_drop(dentry);
98
99         unlock_kernel();
100         dput(parent);
101         return 0;
102
103  fail_gunlock:
104         gfs2_glock_dq_uninit(&d_gh);
105
106  fail:
107         unlock_kernel();
108         dput(parent);
109         return 0;
110 }
111
112 struct dentry_operations gfs2_dops = {
113         .d_revalidate = gfs2_drevalidate,
114 };
115