Blame view

fs/gfs2/dentry.c 2.76 KB
b3b94faa5   David Teigland   [GFS2] The core o...
1
2
  /*
   * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3a8a9a103   Steven Whitehouse   [GFS2] Update cop...
3
   * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
b3b94faa5   David Teigland   [GFS2] The core o...
4
5
6
   *
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
e9fc2aa09   Steven Whitehouse   [GFS2] Update cop...
7
   * of the GNU General Public License version 2.
b3b94faa5   David Teigland   [GFS2] The core o...
8
   */
b3b94faa5   David Teigland   [GFS2] The core o...
9
10
11
  #include <linux/spinlock.h>
  #include <linux/completion.h>
  #include <linux/buffer_head.h>
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
12
  #include <linux/gfs2_ondisk.h>
34286d666   Nick Piggin   fs: rcu-walk awar...
13
  #include <linux/namei.h>
71b86f562   Steven Whitehouse   [GFS2] Further up...
14
  #include <linux/crc32.h>
b3b94faa5   David Teigland   [GFS2] The core o...
15
16
  
  #include "gfs2.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
17
  #include "incore.h"
b3b94faa5   David Teigland   [GFS2] The core o...
18
19
  #include "dir.h"
  #include "glock.h"
b27605837   Steven Whitehouse   GFS2: Rationalise...
20
  #include "super.h"
5c676f6d3   Steven Whitehouse   [GFS2] Macros rem...
21
  #include "util.h"
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
22
  #include "inode.h"
b3b94faa5   David Teigland   [GFS2] The core o...
23
24
25
26
  
  /**
   * gfs2_drevalidate - Check directory lookup consistency
   * @dentry: the mapping to check
0b728e191   Al Viro   stop passing name...
27
   * @flags: lookup flags
b3b94faa5   David Teigland   [GFS2] The core o...
28
29
30
31
32
33
   *
   * Check to make sure the lookup necessary to arrive at this inode from its
   * parent is still good.
   *
   * Returns: 1 if the dentry is ok, 0 if it isn't
   */
0b728e191   Al Viro   stop passing name...
34
  static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
b3b94faa5   David Teigland   [GFS2] The core o...
35
  {
34286d666   Nick Piggin   fs: rcu-walk awar...
36
37
38
39
  	struct dentry *parent;
  	struct gfs2_sbd *sdp;
  	struct gfs2_inode *dip;
  	struct inode *inode;
b3b94faa5   David Teigland   [GFS2] The core o...
40
  	struct gfs2_holder d_gh;
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
41
  	struct gfs2_inode *ip = NULL;
b3b94faa5   David Teigland   [GFS2] The core o...
42
  	int error;
7afd88d91   Steven Whitehouse   [GFS2] Fix a page...
43
  	int had_lock = 0;
b3b94faa5   David Teigland   [GFS2] The core o...
44

0b728e191   Al Viro   stop passing name...
45
  	if (flags & LOOKUP_RCU)
34286d666   Nick Piggin   fs: rcu-walk awar...
46
47
48
49
50
51
  		return -ECHILD;
  
  	parent = dget_parent(dentry);
  	sdp = GFS2_SB(parent->d_inode);
  	dip = GFS2_I(parent->d_inode);
  	inode = dentry->d_inode;
dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
52
53
54
55
56
  	if (inode) {
  		if (is_bad_inode(inode))
  			goto invalid;
  		ip = GFS2_I(inode);
  	}
b3b94faa5   David Teigland   [GFS2] The core o...
57

c2048b003   Steven Whitehouse   GFS2: Remove loca...
58
  	if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
59
  		goto valid;
7afd88d91   Steven Whitehouse   [GFS2] Fix a page...
60
  	had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
549ae0ac3   Wendy Cheng   [GFS2] nfsd readd...
61
62
63
64
65
  	if (!had_lock) {
  		error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  		if (error)
  			goto fail;
  	} 
b3b94faa5   David Teigland   [GFS2] The core o...
66

dbb7cae2a   Steven Whitehouse   [GFS2] Clean up i...
67
  	error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip);
b3b94faa5   David Teigland   [GFS2] The core o...
68
69
70
71
72
73
74
75
76
77
78
79
  	switch (error) {
  	case 0:
  		if (!inode)
  			goto invalid_gunlock;
  		break;
  	case -ENOENT:
  		if (!inode)
  			goto valid_gunlock;
  		goto invalid_gunlock;
  	default:
  		goto fail_gunlock;
  	}
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
80
  valid_gunlock:
549ae0ac3   Wendy Cheng   [GFS2] nfsd readd...
81
82
  	if (!had_lock)
  		gfs2_glock_dq_uninit(&d_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
83
  valid:
b3b94faa5   David Teigland   [GFS2] The core o...
84
85
  	dput(parent);
  	return 1;
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
86
  invalid_gunlock:
549ae0ac3   Wendy Cheng   [GFS2] nfsd readd...
87
88
  	if (!had_lock)
  		gfs2_glock_dq_uninit(&d_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
89
  invalid:
1191a2bdf   Miklos Szeredi   gfs2: use check_s...
90
91
  	if (check_submounts_and_drop(dentry) != 0)
  		goto valid;
b3b94faa5   David Teigland   [GFS2] The core o...
92
93
  	dput(parent);
  	return 0;
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
94
  fail_gunlock:
b3b94faa5   David Teigland   [GFS2] The core o...
95
  	gfs2_glock_dq_uninit(&d_gh);
a91ea69ff   Steven Whitehouse   [GFS2] Align all ...
96
  fail:
b3b94faa5   David Teigland   [GFS2] The core o...
97
98
99
  	dput(parent);
  	return 0;
  }
da53be12b   Linus Torvalds   Don't pass inode ...
100
  static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
101
102
103
104
  {
  	str->hash = gfs2_disk_hash(str->name, str->len);
  	return 0;
  }
fe15ce446   Nick Piggin   fs: change d_dele...
105
  static int gfs2_dentry_delete(const struct dentry *dentry)
970343cd4   Wengang Wang   GFS2: free disk i...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  {
  	struct gfs2_inode *ginode;
  
  	if (!dentry->d_inode)
  		return 0;
  
  	ginode = GFS2_I(dentry->d_inode);
  	if (!ginode->i_iopen_gh.gh_gl)
  		return 0;
  
  	if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
  		return 1;
  
  	return 0;
  }
92cecbbfa   Al Viro   constify dentry_o...
121
  const struct dentry_operations gfs2_dops = {
b3b94faa5   David Teigland   [GFS2] The core o...
122
  	.d_revalidate = gfs2_drevalidate,
c752666c1   Steven Whitehouse   [GFS2] Fix bug in...
123
  	.d_hash = gfs2_dhash,
970343cd4   Wengang Wang   GFS2: free disk i...
124
  	.d_delete = gfs2_dentry_delete,
b3b94faa5   David Teigland   [GFS2] The core o...
125
  };