quotaops.h 10.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11
/*
 * Definitions for diskquota-operations. When diskquota is configured these
 * macros expand to the right source-code.
 *
 * Author:  Marco van Wieringen <mvw@planets.elm.net>
 */
#ifndef _LINUX_QUOTAOPS_
#define _LINUX_QUOTAOPS_

#include <linux/fs.h>

12 13
#define DQUOT_SPACE_WARN	0x1
#define DQUOT_SPACE_RESERVE	0x2
14
#define DQUOT_SPACE_NOFAIL	0x4
15

16 17 18 19
static inline struct quota_info *sb_dqopt(struct super_block *sb)
{
	return &sb->s_dquot;
}
20

21 22 23 24
/* i_mutex must being held */
static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
{
	return (ia->ia_valid & ATTR_SIZE && ia->ia_size != inode->i_size) ||
25 26
		(ia->ia_valid & ATTR_UID && !uid_eq(ia->ia_uid, inode->i_uid)) ||
		(ia->ia_valid & ATTR_GID && !gid_eq(ia->ia_gid, inode->i_gid));
27 28
}

L
Linus Torvalds 已提交
29 30
#if defined(CONFIG_QUOTA)

31 32 33
#define quota_error(sb, fmt, args...) \
	__quota_error((sb), __func__, fmt , ## args)

34
extern __printf(3, 4)
35 36
void __quota_error(struct super_block *sb, const char *func,
		   const char *fmt, ...);
37

L
Linus Torvalds 已提交
38 39 40
/*
 * declaration of quota_function calls in kernel.
 */
41 42 43
void inode_add_rsv_space(struct inode *inode, qsize_t number);
void inode_claim_rsv_space(struct inode *inode, qsize_t number);
void inode_sub_rsv_space(struct inode *inode, qsize_t number);
44
void inode_reclaim_rsv_space(struct inode *inode, qsize_t number);
45

46
void dquot_initialize(struct inode *inode);
47
void dquot_drop(struct inode *inode);
48
struct dquot *dqget(struct super_block *sb, struct kqid qid);
49 50 51 52 53 54 55 56
static inline struct dquot *dqgrab(struct dquot *dquot)
{
	/* Make sure someone else has active reference to dquot */
	WARN_ON_ONCE(!atomic_read(&dquot->dq_count));
	WARN_ON_ONCE(!test_bit(DQ_ACTIVE_B, &dquot->dq_flags));
	atomic_inc(&dquot->dq_count);
	return dquot;
}
57
void dqput(struct dquot *dquot);
58 59 60
int dquot_scan_active(struct super_block *sb,
		      int (*fn)(struct dquot *dquot, unsigned long priv),
		      unsigned long priv);
61 62
struct dquot *dquot_alloc(struct super_block *sb, int type);
void dquot_destroy(struct dquot *dquot);
63

64 65
int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags);
void __dquot_free_space(struct inode *inode, qsize_t number, int flags);
66

67
int dquot_alloc_inode(struct inode *inode);
68

69
int dquot_claim_space_nodirty(struct inode *inode, qsize_t number);
70
void dquot_free_inode(struct inode *inode);
71
void dquot_reclaim_space_nodirty(struct inode *inode, qsize_t number);
72

73 74 75 76 77 78 79 80
int dquot_disable(struct super_block *sb, int type, unsigned int flags);
/* Suspend quotas on remount RO */
static inline int dquot_suspend(struct super_block *sb, int type)
{
	return dquot_disable(sb, type, DQUOT_SUSPENDED);
}
int dquot_resume(struct super_block *sb, int type);

81 82 83 84 85 86
int dquot_commit(struct dquot *dquot);
int dquot_acquire(struct dquot *dquot);
int dquot_release(struct dquot *dquot);
int dquot_commit_info(struct super_block *sb, int type);
int dquot_mark_dquot_dirty(struct dquot *dquot);

87 88
int dquot_file_open(struct inode *inode, struct file *file);

89
int dquot_enable(struct inode *inode, int type, int format_id,
90
	unsigned int flags);
91
int dquot_quota_on(struct super_block *sb, int type, int format_id,
92
 	struct path *path);
93
int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
94
 	int format_id, int type);
95
int dquot_quota_off(struct super_block *sb, int type);
96 97
int dquot_writeback_dquots(struct super_block *sb, int type);
int dquot_quota_sync(struct super_block *sb, int type);
98 99
int dquot_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
int dquot_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
E
Eric W. Biederman 已提交
100
int dquot_get_dqblk(struct super_block *sb, struct kqid id,
C
Christoph Hellwig 已提交
101
		struct fs_disk_quota *di);
E
Eric W. Biederman 已提交
102
int dquot_set_dqblk(struct super_block *sb, struct kqid id,
C
Christoph Hellwig 已提交
103
		struct fs_disk_quota *di);
104

105
int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
106
int dquot_transfer(struct inode *inode, struct iattr *iattr);
L
Linus Torvalds 已提交
107

108 109 110 111
static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
{
	return sb_dqopt(sb)->info + type;
}
112 113 114 115 116

/*
 * Functions for checking status of quota
 */

117
static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
118
{
119 120
	return sb_dqopt(sb)->flags &
				dquot_state_flag(DQUOT_USAGE_ENABLED, type);
121
}
122

123
static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
124
{
125 126
	return sb_dqopt(sb)->flags &
				dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
127
}
128

129
static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
130
{
131 132
	return sb_dqopt(sb)->flags &
				dquot_state_flag(DQUOT_SUSPENDED, type);
133
}
134

135
static inline unsigned sb_any_quota_suspended(struct super_block *sb)
136
{
137 138 139 140
	unsigned type, tmsk = 0;
	for (type = 0; type < MAXQUOTAS; type++)
		tmsk |= sb_has_quota_suspended(sb, type) << type;
	return tmsk;
141
}
142

143
/* Does kernel know about any quota information for given sb + type? */
144
static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
145 146 147 148 149
{
	/* Currently if anything is on, then quota usage is on as well */
	return sb_has_quota_usage_enabled(sb, type);
}

150
static inline unsigned sb_any_quota_loaded(struct super_block *sb)
151
{
152 153 154 155
	unsigned type, tmsk = 0;
	for (type = 0; type < MAXQUOTAS; type++)
		tmsk |= sb_has_quota_loaded(sb, type) << type;
	return	tmsk;
156 157
}

158
static inline bool sb_has_quota_active(struct super_block *sb, int type)
159 160 161 162 163
{
	return sb_has_quota_loaded(sb, type) &&
	       !sb_has_quota_suspended(sb, type);
}

L
Linus Torvalds 已提交
164 165 166
/*
 * Operations supported for diskquotas.
 */
167
extern const struct dquot_operations dquot_operations;
168
extern const struct quotactl_ops dquot_quotactl_ops;
169

L
Linus Torvalds 已提交
170 171
#else

172
static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
173 174 175 176
{
	return 0;
}

177
static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
178 179 180 181 182 183 184 185 186 187 188 189 190
{
	return 0;
}

static inline int sb_has_quota_suspended(struct super_block *sb, int type)
{
	return 0;
}

static inline int sb_any_quota_suspended(struct super_block *sb)
{
	return 0;
}
191

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
/* Does kernel know about any quota information for given sb + type? */
static inline int sb_has_quota_loaded(struct super_block *sb, int type)
{
	return 0;
}

static inline int sb_any_quota_loaded(struct super_block *sb)
{
	return 0;
}

static inline int sb_has_quota_active(struct super_block *sb, int type)
{
	return 0;
}

208
static inline void dquot_initialize(struct inode *inode)
209 210 211
{
}

212
static inline void dquot_drop(struct inode *inode)
213 214 215
{
}

216
static inline int dquot_alloc_inode(struct inode *inode)
217 218 219 220
{
	return 0;
}

221
static inline void dquot_free_inode(struct inode *inode)
222 223 224
{
}

225
static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
226 227 228 229
{
	return 0;
}

230
static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
231
		int flags)
L
Linus Torvalds 已提交
232
{
233
	if (!(flags & DQUOT_SPACE_RESERVE))
234
		inode_add_bytes(inode, number);
L
Linus Torvalds 已提交
235 236 237
	return 0;
}

238
static inline void __dquot_free_space(struct inode *inode, qsize_t number,
239
		int flags)
L
Linus Torvalds 已提交
240
{
241
	if (!(flags & DQUOT_SPACE_RESERVE))
242
		inode_sub_bytes(inode, number);
L
Linus Torvalds 已提交
243 244
}

245
static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
L
Linus Torvalds 已提交
246
{
247
	inode_add_bytes(inode, number);
L
Linus Torvalds 已提交
248 249 250
	return 0;
}

251 252 253 254 255 256 257
static inline int dquot_reclaim_space_nodirty(struct inode *inode,
					      qsize_t number)
{
	inode_sub_bytes(inode, number);
	return 0;
}

258 259 260 261 262 263 264 265 266 267 268 269 270 271
static inline int dquot_disable(struct super_block *sb, int type,
		unsigned int flags)
{
	return 0;
}

static inline int dquot_suspend(struct super_block *sb, int type)
{
	return 0;
}

static inline int dquot_resume(struct super_block *sb, int type)
{
	return 0;
L
Linus Torvalds 已提交
272 273
}

274 275
#define dquot_file_open		generic_file_open

276 277 278 279 280
static inline int dquot_writeback_dquots(struct super_block *sb, int type)
{
	return 0;
}

281 282 283
#endif /* CONFIG_QUOTA */

static inline int dquot_alloc_space_nodirty(struct inode *inode, qsize_t nr)
L
Linus Torvalds 已提交
284
{
285
	return __dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN);
L
Linus Torvalds 已提交
286 287
}

288 289 290
static inline void dquot_alloc_space_nofail(struct inode *inode, qsize_t nr)
{
	__dquot_alloc_space(inode, nr, DQUOT_SPACE_WARN|DQUOT_SPACE_NOFAIL);
291
	mark_inode_dirty_sync(inode);
L
Linus Torvalds 已提交
292 293
}

294
static inline int dquot_alloc_space(struct inode *inode, qsize_t nr)
295
{
296 297 298
	int ret;

	ret = dquot_alloc_space_nodirty(inode, nr);
299 300 301 302
	if (!ret) {
		/*
		 * Mark inode fully dirty. Since we are allocating blocks, inode
		 * would become fully dirty soon anyway and it reportedly
303
		 * reduces lock contention.
304 305 306
		 */
		mark_inode_dirty(inode);
	}
307
	return ret;
308 309
}

310
static inline int dquot_alloc_block_nodirty(struct inode *inode, qsize_t nr)
311
{
312
	return dquot_alloc_space_nodirty(inode, nr << inode->i_blkbits);
313 314
}

315 316 317 318 319
static inline void dquot_alloc_block_nofail(struct inode *inode, qsize_t nr)
{
	dquot_alloc_space_nofail(inode, nr << inode->i_blkbits);
}

320
static inline int dquot_alloc_block(struct inode *inode, qsize_t nr)
321
{
322
	return dquot_alloc_space(inode, nr << inode->i_blkbits);
323 324
}

325
static inline int dquot_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
L
Linus Torvalds 已提交
326
{
327
	return __dquot_alloc_space(inode, nr << inode->i_blkbits, 0);
L
Linus Torvalds 已提交
328 329
}

330
static inline int dquot_prealloc_block(struct inode *inode, qsize_t nr)
L
Linus Torvalds 已提交
331
{
332
	int ret;
L
Linus Torvalds 已提交
333

334 335
	ret = dquot_prealloc_block_nodirty(inode, nr);
	if (!ret)
336
		mark_inode_dirty_sync(inode);
337
	return ret;
J
Jan Kara 已提交
338 339
}

340
static inline int dquot_reserve_block(struct inode *inode, qsize_t nr)
J
Jan Kara 已提交
341
{
342 343
	return __dquot_alloc_space(inode, nr << inode->i_blkbits,
				DQUOT_SPACE_WARN|DQUOT_SPACE_RESERVE);
J
Jan Kara 已提交
344 345
}

346
static inline int dquot_claim_block(struct inode *inode, qsize_t nr)
J
Jan Kara 已提交
347
{
348
	int ret;
J
Jan Kara 已提交
349

350 351
	ret = dquot_claim_space_nodirty(inode, nr << inode->i_blkbits);
	if (!ret)
352
		mark_inode_dirty_sync(inode);
353
	return ret;
J
Jan Kara 已提交
354 355
}

356 357 358 359 360 361
static inline void dquot_reclaim_block(struct inode *inode, qsize_t nr)
{
	dquot_reclaim_space_nodirty(inode, nr << inode->i_blkbits);
	mark_inode_dirty_sync(inode);
}

362
static inline void dquot_free_space_nodirty(struct inode *inode, qsize_t nr)
363
{
364
	__dquot_free_space(inode, nr, 0);
365 366
}

367
static inline void dquot_free_space(struct inode *inode, qsize_t nr)
368
{
369
	dquot_free_space_nodirty(inode, nr);
370
	mark_inode_dirty_sync(inode);
371 372
}

373
static inline void dquot_free_block_nodirty(struct inode *inode, qsize_t nr)
374
{
375
	dquot_free_space_nodirty(inode, nr << inode->i_blkbits);
376 377
}

378
static inline void dquot_free_block(struct inode *inode, qsize_t nr)
J
Jan Kara 已提交
379
{
380
	dquot_free_space(inode, nr << inode->i_blkbits);
J
Jan Kara 已提交
381 382
}

383 384
static inline void dquot_release_reservation_block(struct inode *inode,
		qsize_t nr)
J
Jan Kara 已提交
385
{
386
	__dquot_free_space(inode, nr << inode->i_blkbits, DQUOT_SPACE_RESERVE);
J
Jan Kara 已提交
387
}
L
Linus Torvalds 已提交
388 389

#endif /* _LINUX_QUOTAOPS_ */