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_
12 static inline struct quota_info
*sb_dqopt(struct super_block
*sb
)
17 #if defined(CONFIG_QUOTA)
20 * declaration of quota_function calls in kernel.
22 void sync_quota_sb(struct super_block
*sb
, int type
);
23 static inline void writeout_quota_sb(struct super_block
*sb
, int type
)
25 if (sb
->s_qcop
->quota_sync
)
26 sb
->s_qcop
->quota_sync(sb
, type
);
29 void inode_add_rsv_space(struct inode
*inode
, qsize_t number
);
30 void inode_claim_rsv_space(struct inode
*inode
, qsize_t number
);
31 void inode_sub_rsv_space(struct inode
*inode
, qsize_t number
);
33 int dquot_initialize(struct inode
*inode
, int type
);
34 int dquot_drop(struct inode
*inode
);
35 struct dquot
*dqget(struct super_block
*sb
, unsigned int id
, int type
);
36 void dqput(struct dquot
*dquot
);
37 int dquot_scan_active(struct super_block
*sb
,
38 int (*fn
)(struct dquot
*dquot
, unsigned long priv
),
40 struct dquot
*dquot_alloc(struct super_block
*sb
, int type
);
41 void dquot_destroy(struct dquot
*dquot
);
43 int dquot_alloc_space(struct inode
*inode
, qsize_t number
, int prealloc
);
44 int dquot_alloc_inode(const struct inode
*inode
, qsize_t number
);
46 int dquot_reserve_space(struct inode
*inode
, qsize_t number
, int prealloc
);
47 int dquot_claim_space(struct inode
*inode
, qsize_t number
);
48 void dquot_release_reserved_space(struct inode
*inode
, qsize_t number
);
50 int dquot_free_space(struct inode
*inode
, qsize_t number
);
51 int dquot_free_inode(const struct inode
*inode
, qsize_t number
);
53 int dquot_transfer(struct inode
*inode
, struct iattr
*iattr
);
54 int dquot_commit(struct dquot
*dquot
);
55 int dquot_acquire(struct dquot
*dquot
);
56 int dquot_release(struct dquot
*dquot
);
57 int dquot_commit_info(struct super_block
*sb
, int type
);
58 int dquot_mark_dquot_dirty(struct dquot
*dquot
);
60 int vfs_quota_on(struct super_block
*sb
, int type
, int format_id
,
61 char *path
, int remount
);
62 int vfs_quota_enable(struct inode
*inode
, int type
, int format_id
,
64 int vfs_quota_on_path(struct super_block
*sb
, int type
, int format_id
,
66 int vfs_quota_on_mount(struct super_block
*sb
, char *qf_name
,
67 int format_id
, int type
);
68 int vfs_quota_off(struct super_block
*sb
, int type
, int remount
);
69 int vfs_quota_disable(struct super_block
*sb
, int type
, unsigned int flags
);
70 int vfs_quota_sync(struct super_block
*sb
, int type
);
71 int vfs_get_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
72 int vfs_set_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
73 int vfs_get_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
74 int vfs_set_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
76 void vfs_dq_drop(struct inode
*inode
);
77 int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
);
78 int vfs_dq_quota_on_remount(struct super_block
*sb
);
80 static inline struct mem_dqinfo
*sb_dqinfo(struct super_block
*sb
, int type
)
82 return sb_dqopt(sb
)->info
+ type
;
86 * Functions for checking status of quota
89 static inline int sb_has_quota_usage_enabled(struct super_block
*sb
, int type
)
91 return sb_dqopt(sb
)->flags
&
92 dquot_state_flag(DQUOT_USAGE_ENABLED
, type
);
95 static inline int sb_has_quota_limits_enabled(struct super_block
*sb
, int type
)
97 return sb_dqopt(sb
)->flags
&
98 dquot_state_flag(DQUOT_LIMITS_ENABLED
, type
);
101 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
103 return sb_dqopt(sb
)->flags
&
104 dquot_state_flag(DQUOT_SUSPENDED
, type
);
107 static inline int sb_any_quota_suspended(struct super_block
*sb
)
109 return sb_has_quota_suspended(sb
, USRQUOTA
) ||
110 sb_has_quota_suspended(sb
, GRPQUOTA
);
113 /* Does kernel know about any quota information for given sb + type? */
114 static inline int sb_has_quota_loaded(struct super_block
*sb
, int type
)
116 /* Currently if anything is on, then quota usage is on as well */
117 return sb_has_quota_usage_enabled(sb
, type
);
120 static inline int sb_any_quota_loaded(struct super_block
*sb
)
122 return sb_has_quota_loaded(sb
, USRQUOTA
) ||
123 sb_has_quota_loaded(sb
, GRPQUOTA
);
126 static inline int sb_has_quota_active(struct super_block
*sb
, int type
)
128 return sb_has_quota_loaded(sb
, type
) &&
129 !sb_has_quota_suspended(sb
, type
);
132 static inline int sb_any_quota_active(struct super_block
*sb
)
134 return sb_has_quota_active(sb
, USRQUOTA
) ||
135 sb_has_quota_active(sb
, GRPQUOTA
);
139 * Operations supported for diskquotas.
141 extern const struct dquot_operations dquot_operations
;
142 extern const struct quotactl_ops vfs_quotactl_ops
;
144 #define sb_dquot_ops (&dquot_operations)
145 #define sb_quotactl_ops (&vfs_quotactl_ops)
147 /* It is better to call this function outside of any transaction as it might
148 * need a lot of space in journal for dquot structure allocation. */
149 static inline void vfs_dq_init(struct inode
*inode
)
151 BUG_ON(!inode
->i_sb
);
152 if (sb_any_quota_active(inode
->i_sb
) && !IS_NOQUOTA(inode
))
153 inode
->i_sb
->dq_op
->initialize(inode
, -1);
156 /* The following allocation/freeing/transfer functions *must* be called inside
157 * a transaction (deadlocks possible otherwise) */
158 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
160 if (sb_any_quota_active(inode
->i_sb
)) {
161 /* Used space is updated in alloc_space() */
162 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 1) == NO_QUOTA
)
166 inode_add_bytes(inode
, nr
);
170 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
173 if (!(ret
= vfs_dq_prealloc_space_nodirty(inode
, nr
)))
174 mark_inode_dirty(inode
);
178 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
180 if (sb_any_quota_active(inode
->i_sb
)) {
181 /* Used space is updated in alloc_space() */
182 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 0) == NO_QUOTA
)
186 inode_add_bytes(inode
, nr
);
190 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
193 if (!(ret
= vfs_dq_alloc_space_nodirty(inode
, nr
)))
194 mark_inode_dirty(inode
);
198 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
200 if (sb_any_quota_active(inode
->i_sb
)) {
201 /* Used space is updated in alloc_space() */
202 if (inode
->i_sb
->dq_op
->reserve_space(inode
, nr
, 0) == NO_QUOTA
)
206 inode_add_rsv_space(inode
, nr
);
210 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
212 if (sb_any_quota_active(inode
->i_sb
)) {
214 if (inode
->i_sb
->dq_op
->alloc_inode(inode
, 1) == NO_QUOTA
)
221 * Convert in-memory reserved quotas to real consumed quotas
223 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
225 if (sb_any_quota_active(inode
->i_sb
)) {
226 if (inode
->i_sb
->dq_op
->claim_space(inode
, nr
) == NO_QUOTA
)
229 inode_claim_rsv_space(inode
, nr
);
231 mark_inode_dirty(inode
);
236 * Release reserved (in-memory) quotas
239 void vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
241 if (sb_any_quota_active(inode
->i_sb
))
242 inode
->i_sb
->dq_op
->release_rsv(inode
, nr
);
244 inode_sub_rsv_space(inode
, nr
);
247 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
249 if (sb_any_quota_active(inode
->i_sb
))
250 inode
->i_sb
->dq_op
->free_space(inode
, nr
);
252 inode_sub_bytes(inode
, nr
);
255 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
257 vfs_dq_free_space_nodirty(inode
, nr
);
258 mark_inode_dirty(inode
);
261 static inline void vfs_dq_free_inode(struct inode
*inode
)
263 if (sb_any_quota_active(inode
->i_sb
))
264 inode
->i_sb
->dq_op
->free_inode(inode
, 1);
267 /* Cannot be called inside a transaction */
268 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
272 if (sb
->s_qcop
&& sb
->s_qcop
->quota_off
)
273 ret
= sb
->s_qcop
->quota_off(sb
, -1, remount
);
279 static inline int sb_has_quota_usage_enabled(struct super_block
*sb
, int type
)
284 static inline int sb_has_quota_limits_enabled(struct super_block
*sb
, int type
)
289 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
294 static inline int sb_any_quota_suspended(struct super_block
*sb
)
299 /* Does kernel know about any quota information for given sb + type? */
300 static inline int sb_has_quota_loaded(struct super_block
*sb
, int type
)
305 static inline int sb_any_quota_loaded(struct super_block
*sb
)
310 static inline int sb_has_quota_active(struct super_block
*sb
, int type
)
315 static inline int sb_any_quota_active(struct super_block
*sb
)
321 * NO-OP when quota not configured.
323 #define sb_dquot_ops (NULL)
324 #define sb_quotactl_ops (NULL)
326 static inline void vfs_dq_init(struct inode
*inode
)
330 static inline void vfs_dq_drop(struct inode
*inode
)
334 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
339 static inline void vfs_dq_free_inode(struct inode
*inode
)
343 static inline void sync_quota_sb(struct super_block
*sb
, int type
)
347 static inline void writeout_quota_sb(struct super_block
*sb
, int type
)
351 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
356 static inline int vfs_dq_quota_on_remount(struct super_block
*sb
)
361 static inline int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
)
366 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
368 inode_add_bytes(inode
, nr
);
372 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
374 vfs_dq_prealloc_space_nodirty(inode
, nr
);
375 mark_inode_dirty(inode
);
379 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
381 inode_add_bytes(inode
, nr
);
385 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
387 vfs_dq_alloc_space_nodirty(inode
, nr
);
388 mark_inode_dirty(inode
);
392 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
397 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
399 return vfs_dq_alloc_space(inode
, nr
);
403 int vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
408 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
410 inode_sub_bytes(inode
, nr
);
413 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
415 vfs_dq_free_space_nodirty(inode
, nr
);
416 mark_inode_dirty(inode
);
419 #endif /* CONFIG_QUOTA */
421 static inline int vfs_dq_prealloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
423 return vfs_dq_prealloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
426 static inline int vfs_dq_prealloc_block(struct inode
*inode
, qsize_t nr
)
428 return vfs_dq_prealloc_space(inode
, nr
<< inode
->i_blkbits
);
431 static inline int vfs_dq_alloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
433 return vfs_dq_alloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
436 static inline int vfs_dq_alloc_block(struct inode
*inode
, qsize_t nr
)
438 return vfs_dq_alloc_space(inode
, nr
<< inode
->i_blkbits
);
441 static inline int vfs_dq_reserve_block(struct inode
*inode
, qsize_t nr
)
443 return vfs_dq_reserve_space(inode
, nr
<< inode
->i_blkbits
);
446 static inline int vfs_dq_claim_block(struct inode
*inode
, qsize_t nr
)
448 return vfs_dq_claim_space(inode
, nr
<< inode
->i_blkbits
);
452 void vfs_dq_release_reservation_block(struct inode
*inode
, qsize_t nr
)
454 vfs_dq_release_reservation_space(inode
, nr
<< inode
->i_blkbits
);
457 static inline void vfs_dq_free_block_nodirty(struct inode
*inode
, qsize_t nr
)
459 vfs_dq_free_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
462 static inline void vfs_dq_free_block(struct inode
*inode
, qsize_t nr
)
464 vfs_dq_free_space(inode
, nr
<< inode
->i_blkbits
);
467 #endif /* _LINUX_QUOTAOPS_ */