2 * Definitions for diskquota-operations. When diskquota is configured these
3 * macros expand to the right source-code.
5 * Author: Marco van Wieringen <mvw@planets.elm.net>
7 #ifndef _LINUX_QUOTAOPS_
8 #define _LINUX_QUOTAOPS_
10 #include <linux/smp_lock.h>
13 static inline struct quota_info
*sb_dqopt(struct super_block
*sb
)
18 #if defined(CONFIG_QUOTA)
21 * declaration of quota_function calls in kernel.
23 void sync_quota_sb(struct super_block
*sb
, int type
);
24 static inline void writeout_quota_sb(struct super_block
*sb
, int type
)
26 if (sb
->s_qcop
->quota_sync
)
27 sb
->s_qcop
->quota_sync(sb
, type
);
30 int dquot_initialize(struct inode
*inode
, int type
);
31 int dquot_drop(struct inode
*inode
);
32 struct dquot
*dqget(struct super_block
*sb
, unsigned int id
, int type
);
33 void dqput(struct dquot
*dquot
);
34 int dquot_scan_active(struct super_block
*sb
,
35 int (*fn
)(struct dquot
*dquot
, unsigned long priv
),
37 struct dquot
*dquot_alloc(struct super_block
*sb
, int type
);
38 void dquot_destroy(struct dquot
*dquot
);
40 int dquot_alloc_space(struct inode
*inode
, qsize_t number
, int prealloc
);
41 int dquot_alloc_inode(const struct inode
*inode
, qsize_t number
);
43 int dquot_reserve_space(struct inode
*inode
, qsize_t number
, int prealloc
);
44 int dquot_claim_space(struct inode
*inode
, qsize_t number
);
45 void dquot_release_reserved_space(struct inode
*inode
, qsize_t number
);
46 qsize_t
dquot_get_reserved_space(struct inode
*inode
);
48 int dquot_free_space(struct inode
*inode
, qsize_t number
);
49 int dquot_free_inode(const struct inode
*inode
, qsize_t number
);
51 int dquot_transfer(struct inode
*inode
, struct iattr
*iattr
);
52 int dquot_commit(struct dquot
*dquot
);
53 int dquot_acquire(struct dquot
*dquot
);
54 int dquot_release(struct dquot
*dquot
);
55 int dquot_commit_info(struct super_block
*sb
, int type
);
56 int dquot_mark_dquot_dirty(struct dquot
*dquot
);
58 int vfs_quota_on(struct super_block
*sb
, int type
, int format_id
,
59 char *path
, int remount
);
60 int vfs_quota_enable(struct inode
*inode
, int type
, int format_id
,
62 int vfs_quota_on_path(struct super_block
*sb
, int type
, int format_id
,
64 int vfs_quota_on_mount(struct super_block
*sb
, char *qf_name
,
65 int format_id
, int type
);
66 int vfs_quota_off(struct super_block
*sb
, int type
, int remount
);
67 int vfs_quota_disable(struct super_block
*sb
, int type
, unsigned int flags
);
68 int vfs_quota_sync(struct super_block
*sb
, int type
);
69 int vfs_get_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
70 int vfs_set_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
71 int vfs_get_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
72 int vfs_set_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
74 void vfs_dq_drop(struct inode
*inode
);
75 int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
);
76 int vfs_dq_quota_on_remount(struct super_block
*sb
);
78 static inline struct mem_dqinfo
*sb_dqinfo(struct super_block
*sb
, int type
)
80 return sb_dqopt(sb
)->info
+ type
;
84 * Functions for checking status of quota
87 static inline int sb_has_quota_usage_enabled(struct super_block
*sb
, int type
)
89 return sb_dqopt(sb
)->flags
&
90 dquot_state_flag(DQUOT_USAGE_ENABLED
, type
);
93 static inline int sb_has_quota_limits_enabled(struct super_block
*sb
, int type
)
95 return sb_dqopt(sb
)->flags
&
96 dquot_state_flag(DQUOT_LIMITS_ENABLED
, type
);
99 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
101 return sb_dqopt(sb
)->flags
&
102 dquot_state_flag(DQUOT_SUSPENDED
, type
);
105 static inline int sb_any_quota_suspended(struct super_block
*sb
)
107 return sb_has_quota_suspended(sb
, USRQUOTA
) ||
108 sb_has_quota_suspended(sb
, GRPQUOTA
);
111 /* Does kernel know about any quota information for given sb + type? */
112 static inline int sb_has_quota_loaded(struct super_block
*sb
, int type
)
114 /* Currently if anything is on, then quota usage is on as well */
115 return sb_has_quota_usage_enabled(sb
, type
);
118 static inline int sb_any_quota_loaded(struct super_block
*sb
)
120 return sb_has_quota_loaded(sb
, USRQUOTA
) ||
121 sb_has_quota_loaded(sb
, GRPQUOTA
);
124 static inline int sb_has_quota_active(struct super_block
*sb
, int type
)
126 return sb_has_quota_loaded(sb
, type
) &&
127 !sb_has_quota_suspended(sb
, type
);
130 static inline int sb_any_quota_active(struct super_block
*sb
)
132 return sb_has_quota_active(sb
, USRQUOTA
) ||
133 sb_has_quota_active(sb
, GRPQUOTA
);
137 * Operations supported for diskquotas.
139 extern struct dquot_operations dquot_operations
;
140 extern struct quotactl_ops vfs_quotactl_ops
;
142 #define sb_dquot_ops (&dquot_operations)
143 #define sb_quotactl_ops (&vfs_quotactl_ops)
145 /* It is better to call this function outside of any transaction as it might
146 * need a lot of space in journal for dquot structure allocation. */
147 static inline void vfs_dq_init(struct inode
*inode
)
149 BUG_ON(!inode
->i_sb
);
150 if (sb_any_quota_active(inode
->i_sb
) && !IS_NOQUOTA(inode
))
151 inode
->i_sb
->dq_op
->initialize(inode
, -1);
154 /* The following allocation/freeing/transfer functions *must* be called inside
155 * a transaction (deadlocks possible otherwise) */
156 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
158 if (sb_any_quota_active(inode
->i_sb
)) {
159 /* Used space is updated in alloc_space() */
160 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 1) == NO_QUOTA
)
164 inode_add_bytes(inode
, nr
);
168 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
171 if (!(ret
= vfs_dq_prealloc_space_nodirty(inode
, nr
)))
172 mark_inode_dirty(inode
);
176 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
178 if (sb_any_quota_active(inode
->i_sb
)) {
179 /* Used space is updated in alloc_space() */
180 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 0) == NO_QUOTA
)
184 inode_add_bytes(inode
, nr
);
188 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
191 if (!(ret
= vfs_dq_alloc_space_nodirty(inode
, nr
)))
192 mark_inode_dirty(inode
);
196 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
198 if (sb_any_quota_active(inode
->i_sb
)) {
199 /* Used space is updated in alloc_space() */
200 if (inode
->i_sb
->dq_op
->reserve_space(inode
, nr
, 0) == NO_QUOTA
)
206 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
208 if (sb_any_quota_active(inode
->i_sb
)) {
210 if (inode
->i_sb
->dq_op
->alloc_inode(inode
, 1) == NO_QUOTA
)
217 * Convert in-memory reserved quotas to real consumed quotas
219 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
221 if (sb_any_quota_active(inode
->i_sb
)) {
222 if (inode
->i_sb
->dq_op
->claim_space(inode
, nr
) == NO_QUOTA
)
225 inode_add_bytes(inode
, nr
);
227 mark_inode_dirty(inode
);
232 * Release reserved (in-memory) quotas
235 void vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
237 if (sb_any_quota_active(inode
->i_sb
))
238 inode
->i_sb
->dq_op
->release_rsv(inode
, nr
);
241 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
243 if (sb_any_quota_active(inode
->i_sb
))
244 inode
->i_sb
->dq_op
->free_space(inode
, nr
);
246 inode_sub_bytes(inode
, nr
);
249 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
251 vfs_dq_free_space_nodirty(inode
, nr
);
252 mark_inode_dirty(inode
);
255 static inline void vfs_dq_free_inode(struct inode
*inode
)
257 if (sb_any_quota_active(inode
->i_sb
))
258 inode
->i_sb
->dq_op
->free_inode(inode
, 1);
261 /* Cannot be called inside a transaction */
262 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
266 if (sb
->s_qcop
&& sb
->s_qcop
->quota_off
)
267 ret
= sb
->s_qcop
->quota_off(sb
, -1, remount
);
273 static inline int sb_has_quota_usage_enabled(struct super_block
*sb
, int type
)
278 static inline int sb_has_quota_limits_enabled(struct super_block
*sb
, int type
)
283 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
288 static inline int sb_any_quota_suspended(struct super_block
*sb
)
293 /* Does kernel know about any quota information for given sb + type? */
294 static inline int sb_has_quota_loaded(struct super_block
*sb
, int type
)
299 static inline int sb_any_quota_loaded(struct super_block
*sb
)
304 static inline int sb_has_quota_active(struct super_block
*sb
, int type
)
309 static inline int sb_any_quota_active(struct super_block
*sb
)
315 * NO-OP when quota not configured.
317 #define sb_dquot_ops (NULL)
318 #define sb_quotactl_ops (NULL)
320 static inline void vfs_dq_init(struct inode
*inode
)
324 static inline void vfs_dq_drop(struct inode
*inode
)
328 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
333 static inline void vfs_dq_free_inode(struct inode
*inode
)
337 static inline void sync_quota_sb(struct super_block
*sb
, int type
)
341 static inline void writeout_quota_sb(struct super_block
*sb
, int type
)
345 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
350 static inline int vfs_dq_quota_on_remount(struct super_block
*sb
)
355 static inline int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
)
360 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
362 inode_add_bytes(inode
, nr
);
366 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
368 vfs_dq_prealloc_space_nodirty(inode
, nr
);
369 mark_inode_dirty(inode
);
373 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
375 inode_add_bytes(inode
, nr
);
379 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
381 vfs_dq_alloc_space_nodirty(inode
, nr
);
382 mark_inode_dirty(inode
);
386 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
391 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
393 return vfs_dq_alloc_space(inode
, nr
);
397 int vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
402 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
404 inode_sub_bytes(inode
, nr
);
407 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
409 vfs_dq_free_space_nodirty(inode
, nr
);
410 mark_inode_dirty(inode
);
413 #endif /* CONFIG_QUOTA */
415 static inline int vfs_dq_prealloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
417 return vfs_dq_prealloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
420 static inline int vfs_dq_prealloc_block(struct inode
*inode
, qsize_t nr
)
422 return vfs_dq_prealloc_space(inode
, nr
<< inode
->i_blkbits
);
425 static inline int vfs_dq_alloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
427 return vfs_dq_alloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
430 static inline int vfs_dq_alloc_block(struct inode
*inode
, qsize_t nr
)
432 return vfs_dq_alloc_space(inode
, nr
<< inode
->i_blkbits
);
435 static inline int vfs_dq_reserve_block(struct inode
*inode
, qsize_t nr
)
437 return vfs_dq_reserve_space(inode
, nr
<< inode
->i_blkbits
);
440 static inline int vfs_dq_claim_block(struct inode
*inode
, qsize_t nr
)
442 return vfs_dq_claim_space(inode
, nr
<< inode
->i_blkbits
);
446 void vfs_dq_release_reservation_block(struct inode
*inode
, qsize_t nr
)
448 vfs_dq_release_reservation_space(inode
, nr
<< inode
->i_blkbits
);
451 static inline void vfs_dq_free_block_nodirty(struct inode
*inode
, qsize_t nr
)
453 vfs_dq_free_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
456 static inline void vfs_dq_free_block(struct inode
*inode
, qsize_t nr
)
458 vfs_dq_free_space(inode
, nr
<< inode
->i_blkbits
);
461 #endif /* _LINUX_QUOTAOPS_ */