dentry.h 7.83 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
/* SPDX-License-Identifier: GPL-2.0 */
/*
3
 * Copyright (C) 2005-2020 Junjiro R. Okajima
4
5
6
7
8
9
10
11
12
13
14
15
16
 *
 * This program, aufs is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
J. R. Okajima's avatar
J. R. Okajima committed
17
18
19
20
21
22
23
24
25
26
27
28
 */

/*
 * lookup and dentry operations
 */

#ifndef __AUFS_DENTRY_H__
#define __AUFS_DENTRY_H__

#ifdef __KERNEL__

#include <linux/dcache.h>
29
#include "dirren.h"
J. R. Okajima's avatar
J. R. Okajima committed
30
31
32
33
#include "rwsem.h"

struct au_hdentry {
	struct dentry		*hd_dentry;
34
	aufs_bindex_t		hd_id;
J. R. Okajima's avatar
J. R. Okajima committed
35
36
37
};

struct au_dinfo {
J. R. Okajima's avatar
J. R. Okajima committed
38
39
	atomic_t		di_generation;

J. R. Okajima's avatar
J. R. Okajima committed
40
	struct au_rwsem		di_rwsem;
J. R. Okajima's avatar
J. R. Okajima committed
41
	aufs_bindex_t		di_btop, di_bbot, di_bwh, di_bdiropq;
J. R. Okajima's avatar
J. R. Okajima committed
42
	unsigned char		di_tmpfile; /* to allow the different name */
J. R. Okajima's avatar
J. R. Okajima committed
43
44
45
46
47
48
	struct au_hdentry	*di_hdentry;
	struct rcu_head		rcu;
} ____cacheline_aligned_in_smp;

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

49
50
51
/* flags for au_lkup_dentry() */
#define AuLkup_ALLOW_NEG	1
#define AuLkup_IGNORE_PERM	(1 << 1)
52
#define AuLkup_DIRREN		(1 << 2)
53
54
55
56
57
58
#define au_ftest_lkup(flags, name)	((flags) & AuLkup_##name)
#define au_fset_lkup(flags, name) \
	do { (flags) |= AuLkup_##name; } while (0)
#define au_fclr_lkup(flags, name) \
	do { (flags) &= ~AuLkup_##name; } while (0)

59
60
61
62
63
#ifndef CONFIG_AUFS_DIRREN
#undef AuLkup_DIRREN
#define AuLkup_DIRREN 0
#endif

64
65
66
67
struct au_do_lookup_args {
	unsigned int		flags;
	mode_t			type;
	struct qstr		whname, *name;
68
	struct au_dr_lookup	dirren;
69
70
71
72
};

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

73
/* dentry.c */
74
extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
75
struct au_branch;
76
struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
77
int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
78
79
		struct dentry *h_parent, struct au_branch *br);

80
81
82
int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
		   unsigned int flags);
int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
83
84
int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
85
void au_refresh_dop(struct dentry *dentry, int force_reval);
86

J. R. Okajima's avatar
J. R. Okajima committed
87
88
89
90
/* dinfo.c */
void au_di_init_once(void *_di);
struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
void au_di_free(struct au_dinfo *dinfo);
91
92
void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
J. R. Okajima's avatar
J. R. Okajima committed
93
94
int au_di_init(struct dentry *dentry);
void au_di_fin(struct dentry *dentry);
95
int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
J. R. Okajima's avatar
J. R. Okajima committed
96
97
98
99
100
101

void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
void di_read_unlock(struct dentry *d, int flags);
void di_downgrade_lock(struct dentry *d, int flags);
void di_write_lock(struct dentry *d, unsigned int lsc);
void di_write_unlock(struct dentry *d);
102
103
104
void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
void di_write_unlock2(struct dentry *d1, struct dentry *d2);
J. R. Okajima's avatar
J. R. Okajima committed
105
106

struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
J. R. Okajima's avatar
J. R. Okajima committed
107
struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
J. R. Okajima's avatar
J. R. Okajima committed
108
109
aufs_bindex_t au_dbtail(struct dentry *dentry);
aufs_bindex_t au_dbtaildir(struct dentry *dentry);
J. R. Okajima's avatar
J. R. Okajima committed
110
111
112

void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
		   struct dentry *h_dentry);
J. R. Okajima's avatar
J. R. Okajima committed
113
int au_digen_test(struct dentry *dentry, unsigned int sigen);
J. R. Okajima's avatar
J. R. Okajima committed
114
int au_dbrange_test(struct dentry *dentry);
J. R. Okajima's avatar
J. R. Okajima committed
115
void au_update_digen(struct dentry *dentry);
J. R. Okajima's avatar
J. R. Okajima committed
116
void au_update_dbrange(struct dentry *dentry, int do_put_zero);
J. R. Okajima's avatar
J. R. Okajima committed
117
118
void au_update_dbtop(struct dentry *dentry);
void au_update_dbbot(struct dentry *dentry);
119
int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
J. R. Okajima's avatar
J. R. Okajima committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

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

static inline struct au_dinfo *au_di(struct dentry *dentry)
{
	return dentry->d_fsdata;
}

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

/* lock subclass for dinfo */
enum {
	AuLsc_DI_CHILD,		/* child first */
	AuLsc_DI_CHILD2,	/* rename(2), link(2), and cpup at hnotify */
	AuLsc_DI_CHILD3,	/* copyup dirs */
	AuLsc_DI_PARENT,
	AuLsc_DI_PARENT2,
	AuLsc_DI_PARENT3,
	AuLsc_DI_TMP		/* temp for replacing dinfo */
};

/*
 * di_read_lock_child, di_write_lock_child,
 * di_read_lock_child2, di_write_lock_child2,
 * di_read_lock_child3, di_write_lock_child3,
 * di_read_lock_parent, di_write_lock_parent,
 * di_read_lock_parent2, di_write_lock_parent2,
 * di_read_lock_parent3, di_write_lock_parent3,
 */
#define AuReadLockFunc(name, lsc) \
static inline void di_read_lock_##name(struct dentry *d, int flags) \
{ di_read_lock(d, flags, AuLsc_DI_##lsc); }

#define AuWriteLockFunc(name, lsc) \
static inline void di_write_lock_##name(struct dentry *d) \
{ di_write_lock(d, AuLsc_DI_##lsc); }

#define AuRWLockFuncs(name, lsc) \
	AuReadLockFunc(name, lsc) \
	AuWriteLockFunc(name, lsc)

AuRWLockFuncs(child, CHILD);
AuRWLockFuncs(child2, CHILD2);
AuRWLockFuncs(child3, CHILD3);
AuRWLockFuncs(parent, PARENT);
AuRWLockFuncs(parent2, PARENT2);
AuRWLockFuncs(parent3, PARENT3);

#undef AuReadLockFunc
#undef AuWriteLockFunc
#undef AuRWLockFuncs

#define DiMustNoWaiters(d)	AuRwMustNoWaiters(&au_di(d)->di_rwsem)
#define DiMustAnyLock(d)	AuRwMustAnyLock(&au_di(d)->di_rwsem)
#define DiMustWriteLock(d)	AuRwMustWriteLock(&au_di(d)->di_rwsem)

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

J. R. Okajima's avatar
J. R. Okajima committed
178
179
180
181
182
183
/* todo: memory barrier? */
static inline unsigned int au_digen(struct dentry *d)
{
	return atomic_read(&au_di(d)->di_generation);
}

J. R. Okajima's avatar
J. R. Okajima committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
static inline void au_h_dentry_init(struct au_hdentry *hdentry)
{
	hdentry->hd_dentry = NULL;
}

static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
					    aufs_bindex_t bindex)
{
	return di->di_hdentry + bindex;
}

static inline void au_hdput(struct au_hdentry *hd)
{
	if (hd)
		dput(hd->hd_dentry);
}

static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
{
	DiMustAnyLock(dentry);
	return au_di(dentry)->di_btop;
}

static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
{
	DiMustAnyLock(dentry);
	return au_di(dentry)->di_bbot;
}

J. R. Okajima's avatar
J. R. Okajima committed
213
214
215
216
217
218
static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
{
	DiMustAnyLock(dentry);
	return au_di(dentry)->di_bwh;
}

J. R. Okajima's avatar
J. R. Okajima committed
219
220
221
222
223
224
static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
{
	DiMustAnyLock(dentry);
	return au_di(dentry)->di_bdiropq;
}

J. R. Okajima's avatar
J. R. Okajima committed
225
226
227
228
229
230
231
232
233
234
235
236
237
/* todo: hard/soft set? */
static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
{
	DiMustWriteLock(dentry);
	au_di(dentry)->di_btop = bindex;
}

static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
{
	DiMustWriteLock(dentry);
	au_di(dentry)->di_bbot = bindex;
}

J. R. Okajima's avatar
J. R. Okajima committed
238
239
240
241
242
243
244
static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
{
	DiMustWriteLock(dentry);
	/* dbwh can be outside of btop - bbot range */
	au_di(dentry)->di_bwh = bindex;
}

J. R. Okajima's avatar
J. R. Okajima committed
245
246
247
248
249
250
static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
{
	DiMustWriteLock(dentry);
	au_di(dentry)->di_bdiropq = bindex;
}

J. R. Okajima's avatar
J. R. Okajima committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/* ---------------------------------------------------------------------- */

#ifdef CONFIG_AUFS_HNOTIFY
static inline void au_digen_dec(struct dentry *d)
{
	atomic_dec(&au_di(d)->di_generation);
}

static inline void au_hn_di_reinit(struct dentry *dentry)
{
	dentry->d_fsdata = NULL;
}
#else
AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
#endif /* CONFIG_AUFS_HNOTIFY */

J. R. Okajima's avatar
J. R. Okajima committed
267
268
#endif /* __KERNEL__ */
#endif /* __AUFS_DENTRY_H__ */