]>
Commit | Line | Data |
---|---|---|
7336d0e6 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
b3b94faa DT |
2 | /* |
3 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. | |
3a8a9a10 | 4 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
b3b94faa DT |
5 | */ |
6 | ||
b3b94faa DT |
7 | #include <linux/spinlock.h> |
8 | #include <linux/completion.h> | |
9 | #include <linux/buffer_head.h> | |
5c676f6d | 10 | #include <linux/gfs2_ondisk.h> |
34286d66 | 11 | #include <linux/namei.h> |
71b86f56 | 12 | #include <linux/crc32.h> |
b3b94faa DT |
13 | |
14 | #include "gfs2.h" | |
5c676f6d | 15 | #include "incore.h" |
b3b94faa DT |
16 | #include "dir.h" |
17 | #include "glock.h" | |
b2760583 | 18 | #include "super.h" |
5c676f6d | 19 | #include "util.h" |
dbb7cae2 | 20 | #include "inode.h" |
b3b94faa DT |
21 | |
22 | /** | |
23 | * gfs2_drevalidate - Check directory lookup consistency | |
24 | * @dentry: the mapping to check | |
0b728e19 | 25 | * @flags: lookup flags |
b3b94faa DT |
26 | * |
27 | * Check to make sure the lookup necessary to arrive at this inode from its | |
28 | * parent is still good. | |
29 | * | |
30 | * Returns: 1 if the dentry is ok, 0 if it isn't | |
31 | */ | |
32 | ||
0b728e19 | 33 | static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags) |
b3b94faa | 34 | { |
34286d66 NP |
35 | struct dentry *parent; |
36 | struct gfs2_sbd *sdp; | |
37 | struct gfs2_inode *dip; | |
38 | struct inode *inode; | |
b3b94faa | 39 | struct gfs2_holder d_gh; |
dbb7cae2 | 40 | struct gfs2_inode *ip = NULL; |
8c5ca117 | 41 | int error, valid = 0; |
7afd88d9 | 42 | int had_lock = 0; |
b3b94faa | 43 | |
0b728e19 | 44 | if (flags & LOOKUP_RCU) |
34286d66 NP |
45 | return -ECHILD; |
46 | ||
47 | parent = dget_parent(dentry); | |
2b0143b5 DH |
48 | sdp = GFS2_SB(d_inode(parent)); |
49 | dip = GFS2_I(d_inode(parent)); | |
50 | inode = d_inode(dentry); | |
34286d66 | 51 | |
dbb7cae2 SW |
52 | if (inode) { |
53 | if (is_bad_inode(inode)) | |
8c5ca117 | 54 | goto out; |
dbb7cae2 SW |
55 | ip = GFS2_I(inode); |
56 | } | |
b3b94faa | 57 | |
8c5ca117 BP |
58 | if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) { |
59 | valid = 1; | |
60 | goto out; | |
61 | } | |
c752666c | 62 | |
7afd88d9 | 63 | had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL); |
549ae0ac WC |
64 | if (!had_lock) { |
65 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); | |
66 | if (error) | |
8c5ca117 | 67 | goto out; |
b3b94faa DT |
68 | } |
69 | ||
8c5ca117 BP |
70 | error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip); |
71 | valid = inode ? !error : (error == -ENOENT); | |
b3b94faa | 72 | |
549ae0ac WC |
73 | if (!had_lock) |
74 | gfs2_glock_dq_uninit(&d_gh); | |
8c5ca117 | 75 | out: |
b3b94faa | 76 | dput(parent); |
8c5ca117 | 77 | return valid; |
b3b94faa DT |
78 | } |
79 | ||
da53be12 | 80 | static int gfs2_dhash(const struct dentry *dentry, struct qstr *str) |
c752666c SW |
81 | { |
82 | str->hash = gfs2_disk_hash(str->name, str->len); | |
83 | return 0; | |
84 | } | |
85 | ||
fe15ce44 | 86 | static int gfs2_dentry_delete(const struct dentry *dentry) |
970343cd WW |
87 | { |
88 | struct gfs2_inode *ginode; | |
89 | ||
2b0143b5 | 90 | if (d_really_is_negative(dentry)) |
970343cd WW |
91 | return 0; |
92 | ||
2b0143b5 | 93 | ginode = GFS2_I(d_inode(dentry)); |
6df9f9a2 | 94 | if (!gfs2_holder_initialized(&ginode->i_iopen_gh)) |
970343cd WW |
95 | return 0; |
96 | ||
97 | if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags)) | |
98 | return 1; | |
99 | ||
100 | return 0; | |
101 | } | |
102 | ||
92cecbbf | 103 | const struct dentry_operations gfs2_dops = { |
b3b94faa | 104 | .d_revalidate = gfs2_drevalidate, |
c752666c | 105 | .d_hash = gfs2_dhash, |
970343cd | 106 | .d_delete = gfs2_dentry_delete, |
b3b94faa DT |
107 | }; |
108 |