blob: 91beddadd38876367d5163ad0b73617d023b158c [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
David Teiglandb3b94fa2006-01-16 16:50:04 +000010#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050014#include <linux/gfs2_ondisk.h>
Steven Whitehouse71b86f52006-03-28 14:14:04 -050015#include <linux/crc32.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000016
17#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050018#include "incore.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000019#include "dir.h"
20#include "glock.h"
Steven Whitehouseb2760582008-10-14 16:05:55 +010021#include "super.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050022#include "util.h"
Steven Whitehousedbb7cae2007-05-15 15:37:50 +010023#include "inode.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000024
25/**
26 * gfs2_drevalidate - Check directory lookup consistency
27 * @dentry: the mapping to check
28 * @nd:
29 *
30 * Check to make sure the lookup necessary to arrive at this inode from its
31 * parent is still good.
32 *
33 * Returns: 1 if the dentry is ok, 0 if it isn't
34 */
35
36static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
37{
38 struct dentry *parent = dget_parent(dentry);
Steven Whitehousefeaa7bb2006-06-14 15:32:57 -040039 struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode);
40 struct gfs2_inode *dip = GFS2_I(parent->d_inode);
Steven Whitehousec7526662006-03-20 12:30:04 -050041 struct inode *inode = dentry->d_inode;
David Teiglandb3b94fa2006-01-16 16:50:04 +000042 struct gfs2_holder d_gh;
Steven Whitehousedbb7cae2007-05-15 15:37:50 +010043 struct gfs2_inode *ip = NULL;
David Teiglandb3b94fa2006-01-16 16:50:04 +000044 int error;
Steven Whitehouse7afd88d2008-02-22 16:07:18 +000045 int had_lock = 0;
David Teiglandb3b94fa2006-01-16 16:50:04 +000046
Steven Whitehousedbb7cae2007-05-15 15:37:50 +010047 if (inode) {
48 if (is_bad_inode(inode))
49 goto invalid;
50 ip = GFS2_I(inode);
51 }
David Teiglandb3b94fa2006-01-16 16:50:04 +000052
Steven Whitehousec7526662006-03-20 12:30:04 -050053 if (sdp->sd_args.ar_localcaching)
54 goto valid;
55
Steven Whitehouse7afd88d2008-02-22 16:07:18 +000056 had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
Wendy Cheng549ae0a2007-02-06 03:52:16 -050057 if (!had_lock) {
58 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
59 if (error)
60 goto fail;
61 }
David Teiglandb3b94fa2006-01-16 16:50:04 +000062
Steven Whitehousedbb7cae2007-05-15 15:37:50 +010063 error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +000064 switch (error) {
65 case 0:
66 if (!inode)
67 goto invalid_gunlock;
68 break;
69 case -ENOENT:
70 if (!inode)
71 goto valid_gunlock;
72 goto invalid_gunlock;
73 default:
74 goto fail_gunlock;
75 }
76
Steven Whitehousea91ea692006-09-04 12:04:26 -040077valid_gunlock:
Wendy Cheng549ae0a2007-02-06 03:52:16 -050078 if (!had_lock)
79 gfs2_glock_dq_uninit(&d_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -040080valid:
David Teiglandb3b94fa2006-01-16 16:50:04 +000081 dput(parent);
82 return 1;
83
Steven Whitehousea91ea692006-09-04 12:04:26 -040084invalid_gunlock:
Wendy Cheng549ae0a2007-02-06 03:52:16 -050085 if (!had_lock)
86 gfs2_glock_dq_uninit(&d_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -040087invalid:
David Teiglandb3b94fa2006-01-16 16:50:04 +000088 if (inode && S_ISDIR(inode->i_mode)) {
89 if (have_submounts(dentry))
90 goto valid;
91 shrink_dcache_parent(dentry);
92 }
93 d_drop(dentry);
David Teiglandb3b94fa2006-01-16 16:50:04 +000094 dput(parent);
95 return 0;
96
Steven Whitehousea91ea692006-09-04 12:04:26 -040097fail_gunlock:
David Teiglandb3b94fa2006-01-16 16:50:04 +000098 gfs2_glock_dq_uninit(&d_gh);
Steven Whitehousea91ea692006-09-04 12:04:26 -040099fail:
David Teiglandb3b94fa2006-01-16 16:50:04 +0000100 dput(parent);
101 return 0;
102}
103
Steven Whitehousec7526662006-03-20 12:30:04 -0500104static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
105{
106 str->hash = gfs2_disk_hash(str->name, str->len);
107 return 0;
108}
109
Wengang Wang970343c2009-08-18 14:25:03 +0800110static int gfs2_dentry_delete(struct dentry *dentry)
111{
112 struct gfs2_inode *ginode;
113
114 if (!dentry->d_inode)
115 return 0;
116
117 ginode = GFS2_I(dentry->d_inode);
118 if (!ginode->i_iopen_gh.gh_gl)
119 return 0;
120
121 if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
122 return 1;
123
124 return 0;
125}
126
Al Viro92cecbb2009-02-20 06:00:05 +0000127const struct dentry_operations gfs2_dops = {
David Teiglandb3b94fa2006-01-16 16:50:04 +0000128 .d_revalidate = gfs2_drevalidate,
Steven Whitehousec7526662006-03-20 12:30:04 -0500129 .d_hash = gfs2_dhash,
Wengang Wang970343c2009-08-18 14:25:03 +0800130 .d_delete = gfs2_dentry_delete,
David Teiglandb3b94fa2006-01-16 16:50:04 +0000131};
132