dentry.c 2.7 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
 */

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

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

/**
 * 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);
38 39
	struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode);
	struct gfs2_inode *dip = GFS2_I(parent->d_inode);
40
	struct inode *inode = dentry->d_inode;
D
David Teigland 已提交
41
	struct gfs2_holder d_gh;
42
	struct gfs2_inode *ip = NULL;
D
David Teigland 已提交
43
	int error;
44
	int had_lock = 0;
D
David Teigland 已提交
45

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

52
	if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
53 54
		goto valid;

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

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

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

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

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

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

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
static int gfs2_dentry_delete(struct dentry *dentry)
{
	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;
}

A
Al Viro 已提交
126
const struct dentry_operations gfs2_dops = {
D
David Teigland 已提交
127
	.d_revalidate = gfs2_drevalidate,
128
	.d_hash = gfs2_dhash,
129
	.d_delete = gfs2_dentry_delete,
D
David Teigland 已提交
130 131
};