inode.h 19.7 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
 */

/*
 * inode operations
 */

#ifndef __AUFS_INODE_H__
#define __AUFS_INODE_H__

#ifdef __KERNEL__

J. R. Okajima's avatar
J. R. Okajima committed
28
#include <linux/fsnotify.h>
J. R. Okajima's avatar
J. R. Okajima committed
29
#include "rwsem.h"
J. R. Okajima's avatar
J. R. Okajima committed
30

31
32
struct vfsmount;

J. R. Okajima's avatar
J. R. Okajima committed
33
34
35
36
37
38
39
40
41
42
43
struct au_hnotify {
#ifdef CONFIG_AUFS_HNOTIFY
#ifdef CONFIG_AUFS_HFSNOTIFY
	/* never use fsnotify_add_vfsmount_mark() */
	struct fsnotify_mark		hn_mark;
#endif
	struct inode		*hn_aufs_inode;	/* no get/put */
	struct rcu_head		rcu;
#endif
} ____cacheline_aligned_in_smp;

J. R. Okajima's avatar
J. R. Okajima committed
44
45
struct au_hinode {
	struct inode		*hi_inode;
46
	aufs_bindex_t		hi_id;
J. R. Okajima's avatar
J. R. Okajima committed
47
48
49
#ifdef CONFIG_AUFS_HNOTIFY
	struct au_hnotify	*hi_notify;
#endif
J. R. Okajima's avatar
J. R. Okajima committed
50
51
52

	/* reference to the copied-up whiteout with get/put */
	struct dentry		*hi_whdentry;
J. R. Okajima's avatar
J. R. Okajima committed
53
54
};

J. R. Okajima's avatar
J. R. Okajima committed
55
56
57
58
59
60
61
62
/* ig_flags */
#define AuIG_HALF_REFRESHED		1
#define au_ig_ftest(flags, name)	((flags) & AuIG_##name)
#define au_ig_fset(flags, name) \
	do { (flags) |= AuIG_##name; } while (0)
#define au_ig_fclr(flags, name) \
	do { (flags) &= ~AuIG_##name; } while (0)

J. R. Okajima's avatar
J. R. Okajima committed
63
64
struct au_iigen {
	spinlock_t	ig_spin;
J. R. Okajima's avatar
J. R. Okajima committed
65
	__u32		ig_generation, ig_flags;
J. R. Okajima's avatar
J. R. Okajima committed
66
67
};

68
struct au_vdir;
J. R. Okajima's avatar
J. R. Okajima committed
69
struct au_iinfo {
J. R. Okajima's avatar
J. R. Okajima committed
70
71
72
	struct au_iigen		ii_generation;
	struct super_block	*ii_hsb1;	/* no get/put */

J. R. Okajima's avatar
J. R. Okajima committed
73
	struct au_rwsem		ii_rwsem;
J. R. Okajima's avatar
J. R. Okajima committed
74
	aufs_bindex_t		ii_btop, ii_bbot;
J. R. Okajima's avatar
J. R. Okajima committed
75
	__u32			ii_higen;
J. R. Okajima's avatar
J. R. Okajima committed
76
	struct au_hinode	*ii_hinode;
77
	struct au_vdir		*ii_vdir;
J. R. Okajima's avatar
J. R. Okajima committed
78
79
80
81
82
};

struct au_icntnr {
	struct au_iinfo		iinfo;
	struct inode		vfs_inode;
83
	struct hlist_bl_node	plink;
J. R. Okajima's avatar
J. R. Okajima committed
84
85
86
	struct rcu_head		rcu;
} ____cacheline_aligned_in_smp;

87
88
89
90
91
92
93
94
95
96
97
98
/* au_pin flags */
#define AuPin_DI_LOCKED		1
#define AuPin_MNT_WRITE		(1 << 1)
#define au_ftest_pin(flags, name)	((flags) & AuPin_##name)
#define au_fset_pin(flags, name) \
	do { (flags) |= AuPin_##name; } while (0)
#define au_fclr_pin(flags, name) \
	do { (flags) &= ~AuPin_##name; } while (0)

struct au_pin {
	/* input */
	struct dentry *dentry;
99
	unsigned int udba;
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
	unsigned char lsc_di, lsc_hi, flags;
	aufs_bindex_t bindex;

	/* output */
	struct dentry *parent;
	struct au_hinode *hdir;
	struct vfsmount *h_mnt;

	/* temporary unlock/relock for copyup */
	struct dentry *h_dentry, *h_parent;
	struct au_branch *br;
	struct task_struct *task;
};

void au_pin_hdir_unlock(struct au_pin *p);
int au_pin_hdir_lock(struct au_pin *p);
int au_pin_hdir_relock(struct au_pin *p);
void au_pin_hdir_acquire_nest(struct au_pin *p);
void au_pin_hdir_release(struct au_pin *p);

J. R. Okajima's avatar
J. R. Okajima committed
120
121
122
123
124
125
126
127
128
129
/* ---------------------------------------------------------------------- */

static inline struct au_iinfo *au_ii(struct inode *inode)
{
	BUG_ON(is_bad_inode(inode));
	return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
}

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

130
131
/* inode.c */
struct inode *au_igrab(struct inode *inode);
132
void au_refresh_iop(struct inode *inode, int force_getattr);
J. R. Okajima's avatar
J. R. Okajima committed
133
134
135
136
137
int au_refresh_hinode_self(struct inode *inode);
int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
	   unsigned int d_type, ino_t *ino);
struct inode *au_new_inode(struct dentry *dentry, int must_new);
138
139
int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
	       struct inode *inode);
140
141
142
143
int au_test_h_perm(struct user_namespace *h_userns, struct inode *h_inode,
		   int mask);
int au_test_h_perm_sio(struct user_namespace *h_userns, struct inode *h_inode,
		       int mask);
144

J. R. Okajima's avatar
J. R. Okajima committed
145
146
147
148
149
150
151
152
153
154
static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
			    ino_t h_ino, unsigned int d_type, ino_t *ino)
{
#ifdef CONFIG_AUFS_SHWH
	return au_ino(sb, bindex, h_ino, d_type, ino);
#else
	return 0;
#endif
}

155
/* i_op.c */
J. R. Okajima's avatar
J. R. Okajima committed
156
157
158
159
160
161
enum {
	AuIop_SYMLINK,
	AuIop_DIR,
	AuIop_OTHER,
	AuIop_Last
};
162
extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
163
	aufs_iop_nogetattr[AuIop_Last];
J. R. Okajima's avatar
J. R. Okajima committed
164

J. R. Okajima's avatar
J. R. Okajima committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* au_wr_dir flags */
#define AuWrDir_ADD_ENTRY	1
#define AuWrDir_ISDIR		(1 << 1)
#define AuWrDir_TMPFILE		(1 << 2)
#define au_ftest_wrdir(flags, name)	((flags) & AuWrDir_##name)
#define au_fset_wrdir(flags, name) \
	do { (flags) |= AuWrDir_##name; } while (0)
#define au_fclr_wrdir(flags, name) \
	do { (flags) &= ~AuWrDir_##name; } while (0)

struct au_wr_dir_args {
	aufs_bindex_t force_btgt;
	unsigned char flags;
};
int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
	      struct au_wr_dir_args *args);

182
183
184
struct dentry *au_pinned_h_parent(struct au_pin *pin);
void au_pin_init(struct au_pin *pin, struct dentry *dentry,
		 aufs_bindex_t bindex, int lsc_di, int lsc_hi,
185
		 unsigned int udba, unsigned char flags);
186
int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
187
	   unsigned int udba, unsigned char flags) __must_check;
188
189
int au_do_pin(struct au_pin *pin) __must_check;
void au_unpin(struct au_pin *pin);
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);

#define AuIcpup_DID_CPUP	1
#define au_ftest_icpup(flags, name)	((flags) & AuIcpup_##name)
#define au_fset_icpup(flags, name) \
	do { (flags) |= AuIcpup_##name; } while (0)
#define au_fclr_icpup(flags, name) \
	do { (flags) &= ~AuIcpup_##name; } while (0)

struct au_icpup_args {
	unsigned char flags;
	unsigned char pin_flags;
	aufs_bindex_t btgt;
	unsigned int udba;
	struct au_pin pin;
	struct path h_path;
	struct inode *h_inode;
};

int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
		     struct au_icpup_args *a);

212
213
int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
		      struct path *h_path, int locked);
214

J. R. Okajima's avatar
J. R. Okajima committed
215
216
217
/* i_op_add.c */
int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
	       struct dentry *h_parent, int isdir);
218
219
220
221
222
223
int aufs_mknod(struct user_namespace *userns, struct inode *dir,
	       struct dentry *dentry, umode_t mode, dev_t dev);
int aufs_symlink(struct user_namespace *userns, struct inode *dir,
		 struct dentry *dentry, const char *symname);
int aufs_create(struct user_namespace *userns, struct inode *dir,
		struct dentry *dentry, umode_t mode, bool want_excl);
224
225
226
struct vfsub_aopen_args;
int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
		       struct vfsub_aopen_args *args);
227
228
int aufs_tmpfile(struct user_namespace *userns, struct inode *dir,
		 struct dentry *dentry, umode_t mode);
J. R. Okajima's avatar
J. R. Okajima committed
229
230
int aufs_link(struct dentry *src_dentry, struct inode *dir,
	      struct dentry *dentry);
231
232
int aufs_mkdir(struct user_namespace *userns, struct inode *dir,
	       struct dentry *dentry, umode_t mode);
J. R. Okajima's avatar
J. R. Okajima committed
233

J. R. Okajima's avatar
J. R. Okajima committed
234
235
236
237
238
/* i_op_del.c */
int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
	       struct dentry *h_parent, int isdir);
int aufs_unlink(struct inode *dir, struct dentry *dentry);
J. R. Okajima's avatar
J. R. Okajima committed
239
int aufs_rmdir(struct inode *dir, struct dentry *dentry);
J. R. Okajima's avatar
J. R. Okajima committed
240

241
242
/* i_op_ren.c */
int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
243
244
245
246
int aufs_rename(struct user_namespace *userns,
		struct inode *_src_dir, struct dentry *_src_dentry,
		struct inode *_dst_dir, struct dentry *_dst_dentry,
		unsigned int _flags);
247

J. R. Okajima's avatar
J. R. Okajima committed
248
249
250
/* iinfo.c */
struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
void au_hiput(struct au_hinode *hinode);
J. R. Okajima's avatar
J. R. Okajima committed
251
252
void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
		  struct dentry *h_wh);
J. R. Okajima's avatar
J. R. Okajima committed
253
254
255
256
unsigned int au_hi_flags(struct inode *inode, int isdir);

/* hinode flags */
#define AuHi_XINO	1
J. R. Okajima's avatar
J. R. Okajima committed
257
#define AuHi_HNOTIFY	(1 << 1)
J. R. Okajima's avatar
J. R. Okajima committed
258
259
260
261
262
#define au_ftest_hi(flags, name)	((flags) & AuHi_##name)
#define au_fset_hi(flags, name) \
	do { (flags) |= AuHi_##name; } while (0)
#define au_fclr_hi(flags, name) \
	do { (flags) &= ~AuHi_##name; } while (0)
J. R. Okajima's avatar
J. R. Okajima committed
263

J. R. Okajima's avatar
J. R. Okajima committed
264
265
266
267
268
#ifndef CONFIG_AUFS_HNOTIFY
#undef AuHi_HNOTIFY
#define AuHi_HNOTIFY	0
#endif

J. R. Okajima's avatar
J. R. Okajima committed
269
270
271
void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
		   struct inode *h_inode, unsigned int flags);

J. R. Okajima's avatar
J. R. Okajima committed
272
void au_update_iigen(struct inode *inode, int half);
J. R. Okajima's avatar
J. R. Okajima committed
273
void au_update_ibrange(struct inode *inode, int do_put_zero);
J. R. Okajima's avatar
J. R. Okajima committed
274

J. R. Okajima's avatar
J. R. Okajima committed
275
276
277
278
void au_icntnr_init_once(void *_c);
void au_hinode_init(struct au_hinode *hinode);
int au_iinfo_init(struct inode *inode);
void au_iinfo_fin(struct inode *inode);
279
int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
J. R. Okajima's avatar
J. R. Okajima committed
280

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#ifdef CONFIG_PROC_FS
/* plink.c */
int au_plink_maint(struct super_block *sb, int flags);
struct au_sbinfo;
void au_plink_maint_leave(struct au_sbinfo *sbinfo);
int au_plink_maint_enter(struct super_block *sb);
#ifdef CONFIG_AUFS_DEBUG
void au_plink_list(struct super_block *sb);
#else
AuStubVoid(au_plink_list, struct super_block *sb)
#endif
int au_plink_test(struct inode *inode);
struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
		     struct dentry *h_dentry);
void au_plink_put(struct super_block *sb, int verbose);
void au_plink_clean(struct super_block *sb, int verbose);
298
void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
299
300
301
302
303
304
305
306
307
308
309
310
#else
AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
AuStubInt0(au_plink_maint_enter, struct super_block *sb);
AuStubVoid(au_plink_list, struct super_block *sb);
AuStubInt0(au_plink_test, struct inode *inode);
AuStub(struct dentry *, au_plink_lkup, return NULL,
       struct inode *inode, aufs_bindex_t bindex);
AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
	   struct dentry *h_dentry);
AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
311
AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
312
313
#endif /* CONFIG_PROC_FS */

J. R. Okajima's avatar
J. R. Okajima committed
314
315
#ifdef CONFIG_AUFS_XATTR
/* xattr.c */
316
int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
J. R. Okajima's avatar
J. R. Okajima committed
317
318
319
320
		  unsigned int verbose);
ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
void au_xattr_init(struct super_block *sb);
#else
321
AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
J. R. Okajima's avatar
J. R. Okajima committed
322
323
324
325
326
327
	   int ignore_flags, unsigned int verbose);
AuStubVoid(au_xattr_init, struct super_block *sb);
#endif

#ifdef CONFIG_FS_POSIX_ACL
struct posix_acl *aufs_get_acl(struct inode *inode, int type);
328
329
int aufs_set_acl(struct user_namespace *userns, struct inode *inode,
		 struct posix_acl *acl, int type);
J. R. Okajima's avatar
J. R. Okajima committed
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#endif

#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
enum {
	AU_XATTR_SET,
	AU_ACL_SET
};

struct au_sxattr {
	int type;
	union {
		struct {
			const char	*name;
			const void	*value;
			size_t		size;
			int		flags;
		} set;
		struct {
			struct posix_acl *acl;
			int		type;
		} acl_set;
	} u;
};
ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
		  struct au_sxattr *arg);
#endif

J. R. Okajima's avatar
J. R. Okajima committed
357
358
/* ---------------------------------------------------------------------- */

J. R. Okajima's avatar
J. R. Okajima committed
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* lock subclass for iinfo */
enum {
	AuLsc_II_CHILD,		/* child first */
	AuLsc_II_CHILD2,	/* rename(2), link(2), and cpup at hnotify */
	AuLsc_II_CHILD3,	/* copyup dirs */
	AuLsc_II_PARENT,	/* see AuLsc_I_PARENT in vfsub.h */
	AuLsc_II_PARENT2,
	AuLsc_II_PARENT3,	/* copyup dirs */
	AuLsc_II_NEW_CHILD
};

/*
 * ii_read_lock_child, ii_write_lock_child,
 * ii_read_lock_child2, ii_write_lock_child2,
 * ii_read_lock_child3, ii_write_lock_child3,
 * ii_read_lock_parent, ii_write_lock_parent,
 * ii_read_lock_parent2, ii_write_lock_parent2,
 * ii_read_lock_parent3, ii_write_lock_parent3,
 * ii_read_lock_new_child, ii_write_lock_new_child,
 */
#define AuReadLockFunc(name, lsc) \
static inline void ii_read_lock_##name(struct inode *i) \
{ \
	au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
}

#define AuWriteLockFunc(name, lsc) \
static inline void ii_write_lock_##name(struct inode *i) \
{ \
	au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##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);
AuRWLockFuncs(new_child, NEW_CHILD);

#undef AuReadLockFunc
#undef AuWriteLockFunc
#undef AuRWLockFuncs

#define ii_read_unlock(i)	au_rw_read_unlock(&au_ii(i)->ii_rwsem)
#define ii_write_unlock(i)	au_rw_write_unlock(&au_ii(i)->ii_rwsem)
#define ii_downgrade_lock(i)	au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)

#define IiMustNoWaiters(i)	AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
#define IiMustAnyLock(i)	AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
#define IiMustWriteLock(i)	AuRwMustWriteLock(&au_ii(i)->ii_rwsem)

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

J. R. Okajima's avatar
J. R. Okajima committed
417
418
static inline void au_icntnr_init(struct au_icntnr *c)
{
J. R. Okajima's avatar
J. R. Okajima committed
419
420
421
#ifdef CONFIG_AUFS_DEBUG
	c->vfs_inode.i_mode = 0;
#endif
J. R. Okajima's avatar
J. R. Okajima committed
422
423
}

J. R. Okajima's avatar
J. R. Okajima committed
424
static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
J. R. Okajima's avatar
J. R. Okajima committed
425
426
427
428
429
430
431
432
{
	unsigned int gen;
	struct au_iinfo *iinfo;
	struct au_iigen *iigen;

	iinfo = au_ii(inode);
	iigen = &iinfo->ii_generation;
	spin_lock(&iigen->ig_spin);
J. R. Okajima's avatar
J. R. Okajima committed
433
434
	if (igflags)
		*igflags = iigen->ig_flags;
J. R. Okajima's avatar
J. R. Okajima committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
	gen = iigen->ig_generation;
	spin_unlock(&iigen->ig_spin);

	return gen;
}

/* tiny test for inode number */
/* tmpfs generation is too rough */
static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
{
	struct au_iinfo *iinfo;

	iinfo = au_ii(inode);
	AuRwMustAnyLock(&iinfo->ii_rwsem);
	return !(iinfo->ii_hsb1 == h_inode->i_sb
		 && iinfo->ii_higen == h_inode->i_generation);
}

static inline void au_iigen_dec(struct inode *inode)
{
	struct au_iinfo *iinfo;
	struct au_iigen *iigen;

	iinfo = au_ii(inode);
	iigen = &iinfo->ii_generation;
	spin_lock(&iigen->ig_spin);
	iigen->ig_generation--;
	spin_unlock(&iigen->ig_spin);
}

static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
{
	int err;

	err = 0;
J. R. Okajima's avatar
J. R. Okajima committed
470
	if (unlikely(inode && au_iigen(inode, NULL) != sigen))
J. R. Okajima's avatar
J. R. Okajima committed
471
472
473
474
475
		err = -EIO;

	return err;
}

J. R. Okajima's avatar
J. R. Okajima committed
476
477
478
479
480
481
482
483
484
485
486
487
488
/* ---------------------------------------------------------------------- */

static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
					  aufs_bindex_t bindex)
{
	return iinfo->ii_hinode + bindex;
}

static inline int au_is_bad_inode(struct inode *inode)
{
	return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
}

489
490
491
492
493
494
495
static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
					aufs_bindex_t bindex)
{
	IiMustAnyLock(inode);
	return au_hinode(au_ii(inode), bindex)->hi_id;
}

J. R. Okajima's avatar
J. R. Okajima committed
496
497
static inline aufs_bindex_t au_ibtop(struct inode *inode)
{
J. R. Okajima's avatar
J. R. Okajima committed
498
	IiMustAnyLock(inode);
J. R. Okajima's avatar
J. R. Okajima committed
499
500
501
502
503
	return au_ii(inode)->ii_btop;
}

static inline aufs_bindex_t au_ibbot(struct inode *inode)
{
J. R. Okajima's avatar
J. R. Okajima committed
504
	IiMustAnyLock(inode);
J. R. Okajima's avatar
J. R. Okajima committed
505
506
507
	return au_ii(inode)->ii_bbot;
}

508
509
510
511
512
513
static inline struct au_vdir *au_ivdir(struct inode *inode)
{
	IiMustAnyLock(inode);
	return au_ii(inode)->ii_vdir;
}

J. R. Okajima's avatar
J. R. Okajima committed
514
515
516
517
518
519
static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
{
	IiMustAnyLock(inode);
	return au_hinode(au_ii(inode), bindex)->hi_whdentry;
}

J. R. Okajima's avatar
J. R. Okajima committed
520
521
static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
{
J. R. Okajima's avatar
J. R. Okajima committed
522
	IiMustWriteLock(inode);
J. R. Okajima's avatar
J. R. Okajima committed
523
524
525
526
527
	au_ii(inode)->ii_btop = bindex;
}

static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
{
J. R. Okajima's avatar
J. R. Okajima committed
528
	IiMustWriteLock(inode);
J. R. Okajima's avatar
J. R. Okajima committed
529
530
531
	au_ii(inode)->ii_bbot = bindex;
}

532
533
534
535
536
537
static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
{
	IiMustWriteLock(inode);
	au_ii(inode)->ii_vdir = vdir;
}

J. R. Okajima's avatar
J. R. Okajima committed
538
539
static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
{
J. R. Okajima's avatar
J. R. Okajima committed
540
	IiMustAnyLock(inode);
J. R. Okajima's avatar
J. R. Okajima committed
541
542
543
	return au_hinode(au_ii(inode), bindex);
}

544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/* ---------------------------------------------------------------------- */

static inline struct dentry *au_pinned_parent(struct au_pin *pin)
{
	if (pin)
		return pin->parent;
	return NULL;
}

static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
{
	if (pin && pin->hdir)
		return pin->hdir->hi_inode;
	return NULL;
}

static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
{
	if (pin)
		return pin->hdir;
	return NULL;
}

static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
{
	if (pin)
		pin->dentry = dentry;
}

static inline void au_pin_set_parent_lflag(struct au_pin *pin,
					   unsigned char lflag)
{
	if (pin) {
		if (lflag)
			au_fset_pin(pin->flags, DI_LOCKED);
		else
			au_fclr_pin(pin->flags, DI_LOCKED);
	}
}

#if 0 /* reserved */
static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
{
	if (pin) {
		dput(pin->parent);
		pin->parent = dget(parent);
	}
}
#endif

J. R. Okajima's avatar
J. R. Okajima committed
594
595
596
597
598
599
600
601
602
/* ---------------------------------------------------------------------- */

struct au_branch;
#ifdef CONFIG_AUFS_HNOTIFY
struct au_hnotify_op {
	void (*ctl)(struct au_hinode *hinode, int do_set);
	int (*alloc)(struct au_hinode *hinode);

	/*
J. R. Okajima's avatar
J. R. Okajima committed
603
	 * if it returns true, the caller should free hinode->hi_notify,
J. R. Okajima's avatar
J. R. Okajima committed
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
	 * otherwise ->free() frees it.
	 */
	int (*free)(struct au_hinode *hinode,
		    struct au_hnotify *hn) __must_check;

	void (*fin)(void);
	int (*init)(void);

	int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
	void (*fin_br)(struct au_branch *br);
	int (*init_br)(struct au_branch *br, int perm);
};

/* hnotify.c */
int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
void au_hn_free(struct au_hinode *hinode);
void au_hn_ctl(struct au_hinode *hinode, int do_set);
void au_hn_reset(struct inode *inode, unsigned int flags);
int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
623
	       const struct qstr *h_child_qstr, struct inode *h_child_inode);
J. R. Okajima's avatar
J. R. Okajima committed
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
int au_hnotify_init_br(struct au_branch *br, int perm);
void au_hnotify_fin_br(struct au_branch *br);
int __init au_hnotify_init(void);
void au_hnotify_fin(void);

/* hfsnotify.c */
extern const struct au_hnotify_op au_hnotify_op;

static inline
void au_hn_init(struct au_hinode *hinode)
{
	hinode->hi_notify = NULL;
}

static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
{
	return hinode->hi_notify;
}

#else
AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
       struct au_hinode *hinode __maybe_unused,
       struct inode *inode __maybe_unused)
AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
	   int do_set __maybe_unused)
AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
	   unsigned int flags __maybe_unused)
AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
	   struct au_branch *br __maybe_unused,
	   int perm __maybe_unused)
AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
	   int perm __maybe_unused)
AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
AuStubInt0(__init au_hnotify_init, void)
AuStubVoid(au_hnotify_fin, void)
AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
#endif /* CONFIG_AUFS_HNOTIFY */

static inline void au_hn_suspend(struct au_hinode *hdir)
{
	au_hn_ctl(hdir, /*do_set*/0);
}

static inline void au_hn_resume(struct au_hinode *hdir)
{
	au_hn_ctl(hdir, /*do_set*/1);
}

static inline void au_hn_inode_lock(struct au_hinode *hdir)
{
	inode_lock(hdir->hi_inode);
	au_hn_suspend(hdir);
}

static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
					  unsigned int sc __maybe_unused)
{
	inode_lock_nested(hdir->hi_inode, sc);
	au_hn_suspend(hdir);
}

#if 0 /* unused */
#include "vfsub.h"
static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
						  unsigned int sc)
{
	inode_lock_shared_nested(hdir->hi_inode, sc);
	au_hn_suspend(hdir);
}
#endif

static inline void au_hn_inode_unlock(struct au_hinode *hdir)
{
	au_hn_resume(hdir);
	inode_unlock(hdir->hi_inode);
}

J. R. Okajima's avatar
J. R. Okajima committed
704
705
#endif /* __KERNEL__ */
#endif /* __AUFS_INODE_H__ */