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 inode_add_rsv_space(struct inode
*inode
, qsize_t number
);
23 void inode_claim_rsv_space(struct inode
*inode
, qsize_t number
);
24 void inode_sub_rsv_space(struct inode
*inode
, qsize_t number
);
26 int dquot_initialize(struct inode
*inode
, int type
);
27 int dquot_drop(struct inode
*inode
);
28 struct dquot
*dqget(struct super_block
*sb
, unsigned int id
, int type
);
29 void dqput(struct dquot
*dquot
);
30 int dquot_scan_active(struct super_block
*sb
,
31 int (*fn
)(struct dquot
*dquot
, unsigned long priv
),
33 struct dquot
*dquot_alloc(struct super_block
*sb
, int type
);
34 void dquot_destroy(struct dquot
*dquot
);
36 int dquot_alloc_space(struct inode
*inode
, qsize_t number
, int prealloc
);
37 int dquot_alloc_inode(const struct inode
*inode
, qsize_t number
);
39 int dquot_reserve_space(struct inode
*inode
, qsize_t number
, int prealloc
);
40 int dquot_claim_space(struct inode
*inode
, qsize_t number
);
41 void dquot_release_reserved_space(struct inode
*inode
, qsize_t number
);
43 int dquot_free_space(struct inode
*inode
, qsize_t number
);
44 int dquot_free_inode(const struct inode
*inode
, qsize_t number
);
46 int dquot_transfer(struct inode
*inode
, struct iattr
*iattr
);
47 int dquot_commit(struct dquot
*dquot
);
48 int dquot_acquire(struct dquot
*dquot
);
49 int dquot_release(struct dquot
*dquot
);
50 int dquot_commit_info(struct super_block
*sb
, int type
);
51 int dquot_mark_dquot_dirty(struct dquot
*dquot
);
53 int vfs_quota_on(struct super_block
*sb
, int type
, int format_id
,
54 char *path
, int remount
);
55 int vfs_quota_enable(struct inode
*inode
, int type
, int format_id
,
57 int vfs_quota_on_path(struct super_block
*sb
, int type
, int format_id
,
59 int vfs_quota_on_mount(struct super_block
*sb
, char *qf_name
,
60 int format_id
, int type
);
61 int vfs_quota_off(struct super_block
*sb
, int type
, int remount
);
62 int vfs_quota_disable(struct super_block
*sb
, int type
, unsigned int flags
);
63 int vfs_quota_sync(struct super_block
*sb
, int type
, int wait
);
64 int vfs_get_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
65 int vfs_set_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
66 int vfs_get_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
67 int vfs_set_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
69 void vfs_dq_drop(struct inode
*inode
);
70 int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
);
71 int vfs_dq_quota_on_remount(struct super_block
*sb
);
73 static inline struct mem_dqinfo
*sb_dqinfo(struct super_block
*sb
, int type
)
75 return sb_dqopt(sb
)->info
+ type
;
79 * Functions for checking status of quota
82 static inline int sb_has_quota_usage_enabled(struct super_block
*sb
, int type
)
84 return sb_dqopt(sb
)->flags
&
85 dquot_state_flag(DQUOT_USAGE_ENABLED
, type
);
88 static inline int sb_has_quota_limits_enabled(struct super_block
*sb
, int type
)
90 return sb_dqopt(sb
)->flags
&
91 dquot_state_flag(DQUOT_LIMITS_ENABLED
, type
);
94 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
96 return sb_dqopt(sb
)->flags
&
97 dquot_state_flag(DQUOT_SUSPENDED
, type
);
100 static inline int sb_any_quota_suspended(struct super_block
*sb
)
102 return sb_has_quota_suspended(sb
, USRQUOTA
) ||
103 sb_has_quota_suspended(sb
, GRPQUOTA
);
106 /* Does kernel know about any quota information for given sb + type? */
107 static inline int sb_has_quota_loaded(struct super_block
*sb
, int type
)
109 /* Currently if anything is on, then quota usage is on as well */
110 return sb_has_quota_usage_enabled(sb
, type
);
113 static inline int sb_any_quota_loaded(struct super_block
*sb
)
115 return sb_has_quota_loaded(sb
, USRQUOTA
) ||
116 sb_has_quota_loaded(sb
, GRPQUOTA
);
119 static inline int sb_has_quota_active(struct super_block
*sb
, int type
)
121 return sb_has_quota_loaded(sb
, type
) &&
122 !sb_has_quota_suspended(sb
, type
);
125 static inline int sb_any_quota_active(struct super_block
*sb
)
127 return sb_has_quota_active(sb
, USRQUOTA
) ||
128 sb_has_quota_active(sb
, GRPQUOTA
);
132 * Operations supported for diskquotas.
134 extern const struct dquot_operations dquot_operations
;
135 extern const struct quotactl_ops vfs_quotactl_ops
;
137 #define sb_dquot_ops (&dquot_operations)
138 #define sb_quotactl_ops (&vfs_quotactl_ops)
140 /* It is better to call this function outside of any transaction as it might
141 * need a lot of space in journal for dquot structure allocation. */
142 static inline void vfs_dq_init(struct inode
*inode
)
144 BUG_ON(!inode
->i_sb
);
145 if (sb_any_quota_active(inode
->i_sb
) && !IS_NOQUOTA(inode
))
146 inode
->i_sb
->dq_op
->initialize(inode
, -1);
149 /* The following allocation/freeing/transfer functions *must* be called inside
150 * a transaction (deadlocks possible otherwise) */
151 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
153 if (sb_any_quota_active(inode
->i_sb
)) {
154 /* Used space is updated in alloc_space() */
155 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 1) == NO_QUOTA
)
159 inode_add_bytes(inode
, nr
);
163 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
166 if (!(ret
= vfs_dq_prealloc_space_nodirty(inode
, nr
)))
167 mark_inode_dirty(inode
);
171 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
173 if (sb_any_quota_active(inode
->i_sb
)) {
174 /* Used space is updated in alloc_space() */
175 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 0) == NO_QUOTA
)
179 inode_add_bytes(inode
, nr
);
183 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
186 if (!(ret
= vfs_dq_alloc_space_nodirty(inode
, nr
)))
187 mark_inode_dirty(inode
);
191 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
193 if (sb_any_quota_active(inode
->i_sb
)) {
194 /* Used space is updated in alloc_space() */
195 if (inode
->i_sb
->dq_op
->reserve_space(inode
, nr
, 0) == NO_QUOTA
)
199 inode_add_rsv_space(inode
, nr
);
203 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
205 if (sb_any_quota_active(inode
->i_sb
)) {
207 if (inode
->i_sb
->dq_op
->alloc_inode(inode
, 1) == NO_QUOTA
)
214 * Convert in-memory reserved quotas to real consumed quotas
216 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
218 if (sb_any_quota_active(inode
->i_sb
)) {
219 if (inode
->i_sb
->dq_op
->claim_space(inode
, nr
) == NO_QUOTA
)
222 inode_claim_rsv_space(inode
, nr
);
224 mark_inode_dirty(inode
);
229 * Release reserved (in-memory) quotas
232 void vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
234 if (sb_any_quota_active(inode
->i_sb
))
235 inode
->i_sb
->dq_op
->release_rsv(inode
, nr
);
237 inode_sub_rsv_space(inode
, nr
);
240 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
242 if (sb_any_quota_active(inode
->i_sb
))
243 inode
->i_sb
->dq_op
->free_space(inode
, nr
);
245 inode_sub_bytes(inode
, nr
);
248 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
250 vfs_dq_free_space_nodirty(inode
, nr
);
251 mark_inode_dirty(inode
);
254 static inline void vfs_dq_free_inode(struct inode
*inode
)
256 if (sb_any_quota_active(inode
->i_sb
))
257 inode
->i_sb
->dq_op
->free_inode(inode
, 1);
260 /* Cannot be called inside a transaction */
261 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
265 if (sb
->s_qcop
&& sb
->s_qcop
->quota_off
)
266 ret
= sb
->s_qcop
->quota_off(sb
, -1, remount
);
272 static inline int sb_has_quota_usage_enabled(struct super_block
*sb
, int type
)
277 static inline int sb_has_quota_limits_enabled(struct super_block
*sb
, int type
)
282 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
287 static inline int sb_any_quota_suspended(struct super_block
*sb
)
292 /* Does kernel know about any quota information for given sb + type? */
293 static inline int sb_has_quota_loaded(struct super_block
*sb
, int type
)
298 static inline int sb_any_quota_loaded(struct super_block
*sb
)
303 static inline int sb_has_quota_active(struct super_block
*sb
, int type
)
308 static inline int sb_any_quota_active(struct super_block
*sb
)
314 * NO-OP when quota not configured.
316 #define sb_dquot_ops (NULL)
317 #define sb_quotactl_ops (NULL)
319 static inline void vfs_dq_init(struct inode
*inode
)
323 static inline void vfs_dq_drop(struct inode
*inode
)
327 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
332 static inline void vfs_dq_free_inode(struct inode
*inode
)
336 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
341 static inline int vfs_dq_quota_on_remount(struct super_block
*sb
)
346 static inline int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
)
351 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
353 inode_add_bytes(inode
, nr
);
357 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
359 vfs_dq_prealloc_space_nodirty(inode
, nr
);
360 mark_inode_dirty(inode
);
364 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
366 inode_add_bytes(inode
, nr
);
370 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
372 vfs_dq_alloc_space_nodirty(inode
, nr
);
373 mark_inode_dirty(inode
);
377 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
382 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
384 return vfs_dq_alloc_space(inode
, nr
);
388 int vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
393 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
395 inode_sub_bytes(inode
, nr
);
398 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
400 vfs_dq_free_space_nodirty(inode
, nr
);
401 mark_inode_dirty(inode
);
404 #endif /* CONFIG_QUOTA */
406 static inline int vfs_dq_prealloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
408 return vfs_dq_prealloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
411 static inline int vfs_dq_prealloc_block(struct inode
*inode
, qsize_t nr
)
413 return vfs_dq_prealloc_space(inode
, nr
<< inode
->i_blkbits
);
416 static inline int vfs_dq_alloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
418 return vfs_dq_alloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
421 static inline int vfs_dq_alloc_block(struct inode
*inode
, qsize_t nr
)
423 return vfs_dq_alloc_space(inode
, nr
<< inode
->i_blkbits
);
426 static inline int vfs_dq_reserve_block(struct inode
*inode
, qsize_t nr
)
428 return vfs_dq_reserve_space(inode
, nr
<< inode
->i_blkbits
);
431 static inline int vfs_dq_claim_block(struct inode
*inode
, qsize_t nr
)
433 return vfs_dq_claim_space(inode
, nr
<< inode
->i_blkbits
);
437 void vfs_dq_release_reservation_block(struct inode
*inode
, qsize_t nr
)
439 vfs_dq_release_reservation_space(inode
, nr
<< inode
->i_blkbits
);
442 static inline void vfs_dq_free_block_nodirty(struct inode
*inode
, qsize_t nr
)
444 vfs_dq_free_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
447 static inline void vfs_dq_free_block(struct inode
*inode
, qsize_t nr
)
449 vfs_dq_free_space(inode
, nr
<< inode
->i_blkbits
);
452 #endif /* _LINUX_QUOTAOPS_ */