ops_dentry.c 2.4 KB
Newer Older
D
David Teigland 已提交
1 2
/*
 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3
 * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
D
David Teigland 已提交
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
7
 * of the GNU General Public License version 2.
D
David Teigland 已提交
8 9 10 11 12 13
 */

#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
14
#include <linux/gfs2_ondisk.h>
15
#include <linux/crc32.h>
16
#include <linux/lm_interface.h>
D
David Teigland 已提交
17 18

#include "gfs2.h"
19
#include "incore.h"
D
David Teigland 已提交
20 21
#include "dir.h"
#include "glock.h"
22
#include "super.h"
23
#include "util.h"
24
#include "inode.h"
D
David Teigland 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

/**
 * gfs2_drevalidate - Check directory lookup consistency
 * @dentry: the mapping to check
 * @nd:
 *
 * 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
 */

static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
{
	struct dentry *parent = dget_parent(dentry);
40 41
	struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode);
	struct gfs2_inode *dip = GFS2_I(parent->d_inode);
42
	struct inode *inode = dentry->d_inode;
D
David Teigland 已提交
43
	struct gfs2_holder d_gh;
44
	struct gfs2_inode *ip = NULL;
D
David Teigland 已提交
45
	int error;
46
	int had_lock = 0;
D
David Teigland 已提交
47

48 49 50 51 52
	if (inode) {
		if (is_bad_inode(inode))
			goto invalid;
		ip = GFS2_I(inode);
	}
D
David Teigland 已提交
53

54 55 56
	if (sdp->sd_args.ar_localcaching)
		goto valid;

57
	had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
58 59 60 61 62
	if (!had_lock) {
		error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
		if (error)
			goto fail;
	} 
D
David Teigland 已提交
63

64
	error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip);
D
David Teigland 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77
	switch (error) {
	case 0:
		if (!inode)
			goto invalid_gunlock;
		break;
	case -ENOENT:
		if (!inode)
			goto valid_gunlock;
		goto invalid_gunlock;
	default:
		goto fail_gunlock;
	}

78
valid_gunlock:
79 80
	if (!had_lock)
		gfs2_glock_dq_uninit(&d_gh);
81
valid:
D
David Teigland 已提交
82 83 84
	dput(parent);
	return 1;

85
invalid_gunlock:
86 87
	if (!had_lock)
		gfs2_glock_dq_uninit(&d_gh);
88
invalid:
D
David Teigland 已提交
89 90 91 92 93 94 95 96 97
	if (inode && S_ISDIR(inode->i_mode)) {
		if (have_submounts(dentry))
			goto valid;
		shrink_dcache_parent(dentry);
	}
	d_drop(dentry);
	dput(parent);
	return 0;

98
fail_gunlock:
D
David Teigland 已提交
99
	gfs2_glock_dq_uninit(&d_gh);
100
fail:
D
David Teigland 已提交
101 102 103 104
	dput(parent);
	return 0;
}

105 106 107 108 109 110
static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
{
	str->hash = gfs2_disk_hash(str->name, str->len);
	return 0;
}

A
Al Viro 已提交
111
const struct dentry_operations gfs2_dops = {
D
David Teigland 已提交
112
	.d_revalidate = gfs2_drevalidate,
113
	.d_hash = gfs2_dhash,
D
David Teigland 已提交
114 115
};