dcsub.h 2.49 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2005-2019 Junjiro R. Okajima
 */

/*
 * sub-routines for dentry cache
 */

#ifndef __AUFS_DCSUB_H__
#define __AUFS_DCSUB_H__

#ifdef __KERNEL__

#include <linux/dcache.h>
J. R. Okajima's avatar
J. R. Okajima committed
16
#include <linux/fs.h>
J. R. Okajima's avatar
J. R. Okajima committed
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
struct au_dpage {
	int ndentry;
	struct dentry **dentries;
};

struct au_dcsub_pages {
	int ndpage;
	struct au_dpage *dpages;
};

/* ---------------------------------------------------------------------- */

/* dcsub.c */
int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
void au_dpages_free(struct au_dcsub_pages *dpages);
typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
J. R. Okajima's avatar
J. R. Okajima committed
34
35
int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
		   au_dpages_test test, void *arg);
36
37
38
39
int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
		       int do_include, au_dpages_test test, void *arg);
int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
			    struct dentry *dentry, int do_include);
40
int au_test_subdir(struct dentry *d1, struct dentry *d2);
41
42
43

/* ---------------------------------------------------------------------- */

J. R. Okajima's avatar
J. R. Okajima committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * todo: in linux-3.13, several similar (but faster) helpers are added to
 * include/linux/dcache.h. Try them (in the future).
 */

static inline int au_d_hashed_positive(struct dentry *d)
{
	int err;
	struct inode *inode = d_inode(d);

	err = 0;
	if (unlikely(d_unhashed(d)
		     || d_is_negative(d)
		     || !inode->i_nlink))
		err = -ENOENT;
	return err;
}

static inline int au_d_alive(struct dentry *d)
{
	int err;
	struct inode *inode;

	err = 0;
	if (!IS_ROOT(d))
		err = au_d_hashed_positive(d);
	else {
		inode = d_inode(d);
		if (unlikely(d_unlinked(d)
			     || d_is_negative(d)
			     || !inode->i_nlink))
			err = -ENOENT;
	}
	return err;
}

static inline int au_alive_dir(struct dentry *d)
{
	int err;

	err = au_d_alive(d);
	if (unlikely(err || IS_DEADDIR(d_inode(d))))
		err = -ENOENT;
	return err;
}

90
91
92
93
94
95
static inline int au_qstreq(struct qstr *a, struct qstr *b)
{
	return a->len == b->len
		&& !memcmp(a->name, b->name, a->len);
}

J. R. Okajima's avatar
J. R. Okajima committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * by the commit
 * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
 *			taking d_lock
 * the type of d_lockref.count became int, but the inlined function d_count()
 * still returns unsigned int.
 * I don't know why. Maybe it is for every d_count() users?
 * Anyway au_dcount() lives on.
 */
static inline int au_dcount(struct dentry *d)
{
	return (int)d_count(d);
}

#endif /* __KERNEL__ */
#endif /* __AUFS_DCSUB_H__ */