[GFS2] Patch to remove stats counters from GFS2 (II)
[linux-2.6.git] / 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 inode *inode;
39         struct gfs2_holder d_gh;
40         struct gfs2_inode *ip;
41         struct gfs2_inum inum;
42         unsigned int type;
43         int error;
44
45         lock_kernel();
46
47         inode = dentry->d_inode;
48         if (inode && is_bad_inode(inode))
49                 goto invalid;
50
51         error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
52         if (error)
53                 goto fail;
54
55         error = gfs2_dir_search(dip, &dentry->d_name, &inum, &type);
56         switch (error) {
57         case 0:
58                 if (!inode)
59                         goto invalid_gunlock;
60                 break;
61         case -ENOENT:
62                 if (!inode)
63                         goto valid_gunlock;
64                 goto invalid_gunlock;
65         default:
66                 goto fail_gunlock;
67         }
68
69         ip = get_v2ip(inode);
70
71         if (!gfs2_inum_equal(&ip->i_num, &inum))
72                 goto invalid_gunlock;
73
74         if (IF2DT(ip->i_di.di_mode) != type) {
75                 gfs2_consist_inode(dip);
76                 goto fail_gunlock;
77         }
78
79  valid_gunlock:
80         gfs2_glock_dq_uninit(&d_gh);
81
82  valid:
83         unlock_kernel();
84         dput(parent);
85         return 1;
86
87  invalid_gunlock:
88         gfs2_glock_dq_uninit(&d_gh);
89
90  invalid:
91         if (inode && S_ISDIR(inode->i_mode)) {
92                 if (have_submounts(dentry))
93                         goto valid;
94                 shrink_dcache_parent(dentry);
95         }
96         d_drop(dentry);
97
98         unlock_kernel();
99         dput(parent);
100         return 0;
101
102  fail_gunlock:
103         gfs2_glock_dq_uninit(&d_gh);
104
105  fail:
106         unlock_kernel();
107         dput(parent);
108         return 0;
109 }
110
111 struct dentry_operations gfs2_dops = {
112         .d_revalidate = gfs2_drevalidate,
113 };
114