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 int dquot_initialize(struct inode
*inode
, int type
);
30 int dquot_drop(struct inode
*inode
);
31 struct dquot
*dqget(struct super_block
*sb
, unsigned int id
, int type
);
32 void dqput(struct dquot
*dquot
);
33 int dquot_scan_active(struct super_block
*sb
,
34 int (*fn
)(struct dquot
*dquot
, unsigned long priv
),
36 struct dquot
*dquot_alloc(struct super_block
*sb
, int type
);
37 void dquot_destroy(struct dquot
*dquot
);
39 int dquot_alloc_space(struct inode
*inode
, qsize_t number
, int prealloc
);
40 int dquot_alloc_inode(const struct inode
*inode
, qsize_t number
);
42 int dquot_reserve_space(struct inode
*inode
, qsize_t number
, int prealloc
);
43 int dquot_claim_space(struct inode
*inode
, qsize_t number
);
44 void dquot_release_reserved_space(struct inode
*inode
, qsize_t number
);
45 qsize_t
dquot_get_reserved_space(struct inode
*inode
);
47 int dquot_free_space(struct inode
*inode
, qsize_t number
);
48 int dquot_free_inode(const struct inode
*inode
, qsize_t number
);
50 int dquot_transfer(struct inode
*inode
, struct iattr
*iattr
);
51 int dquot_commit(struct dquot
*dquot
);
52 int dquot_acquire(struct dquot
*dquot
);
53 int dquot_release(struct dquot
*dquot
);
54 int dquot_commit_info(struct super_block
*sb
, int type
);
55 int dquot_mark_dquot_dirty(struct dquot
*dquot
);
57 int vfs_quota_on(struct super_block
*sb
, int type
, int format_id
,
58 char *path
, int remount
);
59 int vfs_quota_enable(struct inode
*inode
, int type
, int format_id
,
61 int vfs_quota_on_path(struct super_block
*sb
, int type
, int format_id
,
63 int vfs_quota_on_mount(struct super_block
*sb
, char *qf_name
,
64 int format_id
, int type
);
65 int vfs_quota_off(struct super_block
*sb
, int type
, int remount
);
66 int vfs_quota_disable(struct super_block
*sb
, int type
, unsigned int flags
);
67 int vfs_quota_sync(struct super_block
*sb
, int type
);
68 int vfs_get_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
69 int vfs_set_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
70 int vfs_get_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
71 int vfs_set_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
73 void vfs_dq_drop(struct inode
*inode
);
74 int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
);
75 int vfs_dq_quota_on_remount(struct super_block
*sb
);
77 static inline struct mem_dqinfo
*sb_dqinfo(struct super_block
*sb
, int type
)
79 return sb_dqopt(sb
)->info
+ type
;
83 * Functions for checking status of quota
86 static inline int sb_has_quota_usage_enabled(struct super_block
*sb
, int type
)
88 return sb_dqopt(sb
)->flags
&
89 dquot_state_flag(DQUOT_USAGE_ENABLED
, type
);
92 static inline int sb_has_quota_limits_enabled(struct super_block
*sb
, int type
)
94 return sb_dqopt(sb
)->flags
&
95 dquot_state_flag(DQUOT_LIMITS_ENABLED
, type
);
98 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
100 return sb_dqopt(sb
)->flags
&
101 dquot_state_flag(DQUOT_SUSPENDED
, type
);
104 static inline int sb_any_quota_suspended(struct super_block
*sb
)
106 return sb_has_quota_suspended(sb
, USRQUOTA
) ||
107 sb_has_quota_suspended(sb
, GRPQUOTA
);
110 /* Does kernel know about any quota information for given sb + type? */
111 static inline int sb_has_quota_loaded(struct super_block
*sb
, int type
)
113 /* Currently if anything is on, then quota usage is on as well */
114 return sb_has_quota_usage_enabled(sb
, type
);
117 static inline int sb_any_quota_loaded(struct super_block
*sb
)
119 return sb_has_quota_loaded(sb
, USRQUOTA
) ||
120 sb_has_quota_loaded(sb
, GRPQUOTA
);
123 static inline int sb_has_quota_active(struct super_block
*sb
, int type
)
125 return sb_has_quota_loaded(sb
, type
) &&
126 !sb_has_quota_suspended(sb
, type
);
129 static inline int sb_any_quota_active(struct super_block
*sb
)
131 return sb_has_quota_active(sb
, USRQUOTA
) ||
132 sb_has_quota_active(sb
, GRPQUOTA
);
136 * Operations supported for diskquotas.
138 extern struct dquot_operations dquot_operations
;
139 extern struct quotactl_ops vfs_quotactl_ops
;
141 #define sb_dquot_ops (&dquot_operations)
142 #define sb_quotactl_ops (&vfs_quotactl_ops)
144 /* It is better to call this function outside of any transaction as it might
145 * need a lot of space in journal for dquot structure allocation. */
146 static inline void vfs_dq_init(struct inode
*inode
)
148 BUG_ON(!inode
->i_sb
);
149 if (sb_any_quota_active(inode
->i_sb
) && !IS_NOQUOTA(inode
))
150 inode
->i_sb
->dq_op
->initialize(inode
, -1);
153 /* The following allocation/freeing/transfer functions *must* be called inside
154 * a transaction (deadlocks possible otherwise) */
155 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
157 if (sb_any_quota_active(inode
->i_sb
)) {
158 /* Used space is updated in alloc_space() */
159 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 1) == NO_QUOTA
)
163 inode_add_bytes(inode
, nr
);
167 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
170 if (!(ret
= vfs_dq_prealloc_space_nodirty(inode
, nr
)))
171 mark_inode_dirty(inode
);
175 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
177 if (sb_any_quota_active(inode
->i_sb
)) {
178 /* Used space is updated in alloc_space() */
179 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 0) == NO_QUOTA
)
183 inode_add_bytes(inode
, nr
);
187 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
190 if (!(ret
= vfs_dq_alloc_space_nodirty(inode
, nr
)))
191 mark_inode_dirty(inode
);
195 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
197 if (sb_any_quota_active(inode
->i_sb
)) {
198 /* Used space is updated in alloc_space() */
199 if (inode
->i_sb
->dq_op
->reserve_space(inode
, nr
, 0) == NO_QUOTA
)
205 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
207 if (sb_any_quota_active(inode
->i_sb
)) {
209 if (inode
->i_sb
->dq_op
->alloc_inode(inode
, 1) == NO_QUOTA
)
216 * Convert in-memory reserved quotas to real consumed quotas
218 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
220 if (sb_any_quota_active(inode
->i_sb
)) {
221 if (inode
->i_sb
->dq_op
->claim_space(inode
, nr
) == NO_QUOTA
)
224 inode_add_bytes(inode
, nr
);
226 mark_inode_dirty(inode
);
231 * Release reserved (in-memory) quotas
234 void vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
236 if (sb_any_quota_active(inode
->i_sb
))
237 inode
->i_sb
->dq_op
->release_rsv(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 void sync_quota_sb(struct super_block
*sb
, int type
)
340 static inline void writeout_quota_sb(struct super_block
*sb
, int type
)
344 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
349 static inline int vfs_dq_quota_on_remount(struct super_block
*sb
)
354 static inline int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
)
359 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
361 inode_add_bytes(inode
, nr
);
365 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
367 vfs_dq_prealloc_space_nodirty(inode
, nr
);
368 mark_inode_dirty(inode
);
372 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
374 inode_add_bytes(inode
, nr
);
378 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
380 vfs_dq_alloc_space_nodirty(inode
, nr
);
381 mark_inode_dirty(inode
);
385 static inline int vfs_dq_reserve_space(struct inode
*inode
, qsize_t nr
)
390 static inline int vfs_dq_claim_space(struct inode
*inode
, qsize_t nr
)
392 return vfs_dq_alloc_space(inode
, nr
);
396 int vfs_dq_release_reservation_space(struct inode
*inode
, qsize_t nr
)
401 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
403 inode_sub_bytes(inode
, nr
);
406 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
408 vfs_dq_free_space_nodirty(inode
, nr
);
409 mark_inode_dirty(inode
);
412 #endif /* CONFIG_QUOTA */
414 static inline int vfs_dq_prealloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
416 return vfs_dq_prealloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
419 static inline int vfs_dq_prealloc_block(struct inode
*inode
, qsize_t nr
)
421 return vfs_dq_prealloc_space(inode
, nr
<< inode
->i_blkbits
);
424 static inline int vfs_dq_alloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
426 return vfs_dq_alloc_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
429 static inline int vfs_dq_alloc_block(struct inode
*inode
, qsize_t nr
)
431 return vfs_dq_alloc_space(inode
, nr
<< inode
->i_blkbits
);
434 static inline int vfs_dq_reserve_block(struct inode
*inode
, qsize_t nr
)
436 return vfs_dq_reserve_space(inode
, nr
<< inode
->i_blkbits
);
439 static inline int vfs_dq_claim_block(struct inode
*inode
, qsize_t nr
)
441 return vfs_dq_claim_space(inode
, nr
<< inode
->i_blkbits
);
445 void vfs_dq_release_reservation_block(struct inode
*inode
, qsize_t nr
)
447 vfs_dq_release_reservation_space(inode
, nr
<< inode
->i_blkbits
);
450 static inline void vfs_dq_free_block_nodirty(struct inode
*inode
, qsize_t nr
)
452 vfs_dq_free_space_nodirty(inode
, nr
<< inode
->i_blkbits
);
455 static inline void vfs_dq_free_block(struct inode
*inode
, qsize_t nr
)
457 vfs_dq_free_space(inode
, nr
<< inode
->i_blkbits
);
460 #endif /* _LINUX_QUOTAOPS_ */