super.h 5.89 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
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2005-2019 Junjiro R. Okajima
 */

/*
 * super_block operations
 */

#ifndef __AUFS_SUPER_H__
#define __AUFS_SUPER_H__

#ifdef __KERNEL__

J. R. Okajima's avatar
J. R. Okajima committed
15
16
17
#include <linux/fs.h>
#include <linux/kobject.h>
#include "rwsem.h"
J. R. Okajima's avatar
J. R. Okajima committed
18
#include "wkq.h"
J. R. Okajima's avatar
J. R. Okajima committed
19
20
21

struct au_branch;
struct au_sbinfo {
J. R. Okajima's avatar
J. R. Okajima committed
22
23
24
	/* nowait tasks in the system-wide workqueue */
	struct au_nowait_tasks	si_nowait;

J. R. Okajima's avatar
J. R. Okajima committed
25
26
27
28
29
30
31
	/*
	 * tried sb->s_umount, but failed due to the dependency between i_mutex.
	 * rwsem for au_sbinfo is necessary.
	 */
	struct au_rwsem		si_rwsem;

	/* branch management */
J. R. Okajima's avatar
J. R. Okajima committed
32
33
	unsigned int		si_generation;

J. R. Okajima's avatar
J. R. Okajima committed
34
	aufs_bindex_t		si_bbot;
35
36
37
38

	/* dirty trick to keep br_id plus */
	unsigned int		si_last_br_id :
				sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
J. R. Okajima's avatar
J. R. Okajima committed
39
40
	struct au_branch	**si_branch;

41
42
43
44
	/* mount flags */
	/* include/asm-ia64/siginfo.h defines a macro named si_flags */
	unsigned int		si_mntflags;

J. R. Okajima's avatar
J. R. Okajima committed
45
46
47
48
49
50
51
52
53
54
55
	/* external inode number (bitmap and translation table) */
	vfs_readf_t		si_xread;
	vfs_writef_t		si_xwrite;
	loff_t			si_ximaxent;	/* max entries in a xino */

	struct file		*si_xib;
	struct mutex		si_xib_mtx; /* protect xib members */
	unsigned long		*si_xib_buf;
	unsigned long		si_xib_last_pindex;
	int			si_xib_next_bit;

J. R. Okajima's avatar
J. R. Okajima committed
56
57
	unsigned long		si_xino_jiffy;
	unsigned long		si_xino_expire;
J. R. Okajima's avatar
J. R. Okajima committed
58
59
60
	/* reserved for future use */
	/* unsigned long long	si_xib_limit; */	/* Max xib file size */

J. R. Okajima's avatar
J. R. Okajima committed
61
62
63
64
65
66
67
	/*
	 * sysfs and lifetime management.
	 * this is not a small structure and it may be a waste of memory in case
	 * of sysfs is disabled, particularly when many aufs-es are mounted.
	 * but using sysfs is majority.
	 */
	struct kobject		si_kobj;
J. R. Okajima's avatar
J. R. Okajima committed
68
69
70

	/* dirty, necessary for unmounting, sysfs and sysrq */
	struct super_block	*si_sb;
J. R. Okajima's avatar
J. R. Okajima committed
71
72
73
74
};

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

J. R. Okajima's avatar
J. R. Okajima committed
75
/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
J. R. Okajima's avatar
J. R. Okajima committed
76
77
78
#define AuLock_DW		1		/* write-lock dentry */
#define AuLock_IR		(1 << 1)	/* read-lock inode */
#define AuLock_IW		(1 << 2)	/* write-lock inode */
J. R. Okajima's avatar
J. R. Okajima committed
79
#define AuLock_FLUSH		(1 << 3)	/* wait for 'nowait' tasks */
J. R. Okajima's avatar
J. R. Okajima committed
80
81
82
83
84
85
86
87
#define au_ftest_lock(flags, name)	((flags) & AuLock_##name)
#define au_fset_lock(flags, name) \
	do { (flags) |= AuLock_##name; } while (0)
#define au_fclr_lock(flags, name) \
	do { (flags) &= ~AuLock_##name; } while (0)

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

J. R. Okajima's avatar
J. R. Okajima committed
88
89
90
/* super.c */
struct inode *au_iget_locked(struct super_block *sb, ino_t ino);

J. R. Okajima's avatar
J. R. Okajima committed
91
92
93
/* sbinfo.c */
void au_si_free(struct kobject *kobj);
int au_si_alloc(struct super_block *sb);
94
int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
J. R. Okajima's avatar
J. R. Okajima committed
95

J. R. Okajima's avatar
J. R. Okajima committed
96
unsigned int au_sigen_inc(struct super_block *sb);
97
aufs_bindex_t au_new_br_id(struct super_block *sb);
J. R. Okajima's avatar
J. R. Okajima committed
98

J. R. Okajima's avatar
J. R. Okajima committed
99
100
101
int si_read_lock(struct super_block *sb, int flags);
int si_write_lock(struct super_block *sb, int flags);

J. R. Okajima's avatar
J. R. Okajima committed
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* ---------------------------------------------------------------------- */

static inline struct au_sbinfo *au_sbi(struct super_block *sb)
{
	return sb->s_fs_info;
}

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

/* lock superblock. mainly for entry point functions */
#define __si_read_lock(sb)	au_rw_read_lock(&au_sbi(sb)->si_rwsem)
#define __si_write_lock(sb)	au_rw_write_lock(&au_sbi(sb)->si_rwsem)
#define __si_read_trylock(sb)	au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
#define __si_write_trylock(sb)	au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
/*
#define __si_read_trylock_nested(sb) \
	au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
#define __si_write_trylock_nested(sb) \
	au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
*/

#define __si_read_unlock(sb)	au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
#define __si_write_unlock(sb)	au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
#define __si_downgrade_lock(sb)	au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)

#define SiMustNoWaiters(sb)	AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
#define SiMustAnyLock(sb)	AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
#define SiMustWriteLock(sb)	AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)

J. R. Okajima's avatar
J. R. Okajima committed
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
178
179
180
181
182
183
184
185
186
187
188
189
static inline void si_noflush_read_lock(struct super_block *sb)
{
	__si_read_lock(sb);
	/* re-commit later */
}

static inline int si_noflush_read_trylock(struct super_block *sb)
{
	return __si_read_trylock(sb);	/* re-commit later */
}

static inline void si_noflush_write_lock(struct super_block *sb)
{
	__si_write_lock(sb);
	/* re-commit later */
}

static inline int si_noflush_write_trylock(struct super_block *sb)
{
	return __si_write_trylock(sb);	/* re-commit later */
}

#if 0 /* reserved */
static inline int si_read_trylock(struct super_block *sb, int flags)
{
	if (au_ftest_lock(flags, FLUSH))
		au_nwt_flush(&au_sbi(sb)->si_nowait);
	return si_noflush_read_trylock(sb);
}
#endif

static inline void si_read_unlock(struct super_block *sb)
{
	/* re-commit later */
	__si_read_unlock(sb);
}

#if 0 /* reserved */
static inline int si_write_trylock(struct super_block *sb, int flags)
{
	if (au_ftest_lock(flags, FLUSH))
		au_nwt_flush(&au_sbi(sb)->si_nowait);
	return si_noflush_write_trylock(sb);
}
#endif

static inline void si_write_unlock(struct super_block *sb)
{
	/* re-commit later */
	__si_write_unlock(sb);
}

#if 0 /* reserved */
static inline void si_downgrade_lock(struct super_block *sb)
{
	__si_downgrade_lock(sb);
}
#endif

J. R. Okajima's avatar
J. R. Okajima committed
190
191
192
193
194
195
196
197
/* ---------------------------------------------------------------------- */

static inline aufs_bindex_t au_sbbot(struct super_block *sb)
{
	SiMustAnyLock(sb);
	return au_sbi(sb)->si_bbot;
}

198
199
200
201
202
203
static inline unsigned int au_mntflags(struct super_block *sb)
{
	SiMustAnyLock(sb);
	return au_sbi(sb)->si_mntflags;
}

J. R. Okajima's avatar
J. R. Okajima committed
204
205
206
207
208
209
static inline unsigned int au_sigen(struct super_block *sb)
{
	SiMustAnyLock(sb);
	return au_sbi(sb)->si_generation;
}

210
211
212
213
214
215
216
static inline struct au_branch *au_sbr(struct super_block *sb,
				       aufs_bindex_t bindex)
{
	SiMustAnyLock(sb);
	return au_sbi(sb)->si_branch[0 + bindex];
}

J. R. Okajima's avatar
J. R. Okajima committed
217
218
219
220
221
222
static inline loff_t au_xi_maxent(struct super_block *sb)
{
	SiMustAnyLock(sb);
	return au_sbi(sb)->si_ximaxent;
}

J. R. Okajima's avatar
J. R. Okajima committed
223
224
#endif /* __KERNEL__ */
#endif /* __AUFS_SUPER_H__ */