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 * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $
10 #ifndef _LINUX_QUOTAOPS_
11 #define _LINUX_QUOTAOPS_
13 #include <linux/smp_lock.h>
16 static inline struct quota_info
*sb_dqopt(struct super_block
*sb
)
21 #if defined(CONFIG_QUOTA)
24 * declaration of quota_function calls in kernel.
26 void sync_dquots(struct super_block
*sb
, int type
);
28 int dquot_initialize(struct inode
*inode
, int type
);
29 int dquot_drop(struct inode
*inode
);
31 int dquot_alloc_space(struct inode
*inode
, qsize_t number
, int prealloc
);
32 int dquot_alloc_inode(const struct inode
*inode
, unsigned long number
);
34 int dquot_free_space(struct inode
*inode
, qsize_t number
);
35 int dquot_free_inode(const struct inode
*inode
, unsigned long number
);
37 int dquot_transfer(struct inode
*inode
, struct iattr
*iattr
);
38 int dquot_commit(struct dquot
*dquot
);
39 int dquot_acquire(struct dquot
*dquot
);
40 int dquot_release(struct dquot
*dquot
);
41 int dquot_commit_info(struct super_block
*sb
, int type
);
42 int dquot_mark_dquot_dirty(struct dquot
*dquot
);
44 int vfs_quota_on(struct super_block
*sb
, int type
, int format_id
,
45 char *path
, int remount
);
46 int vfs_quota_on_mount(struct super_block
*sb
, char *qf_name
,
47 int format_id
, int type
);
48 int vfs_quota_off(struct super_block
*sb
, int type
, int remount
);
49 int vfs_quota_sync(struct super_block
*sb
, int type
);
50 int vfs_get_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
51 int vfs_set_dqinfo(struct super_block
*sb
, int type
, struct if_dqinfo
*ii
);
52 int vfs_get_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
53 int vfs_set_dqblk(struct super_block
*sb
, int type
, qid_t id
, struct if_dqblk
*di
);
55 void vfs_dq_drop(struct inode
*inode
);
56 int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
);
57 int vfs_dq_quota_on_remount(struct super_block
*sb
);
59 static inline struct mem_dqinfo
*sb_dqinfo(struct super_block
*sb
, int type
)
61 return sb_dqopt(sb
)->info
+ type
;
65 * Functions for checking status of quota
68 static inline int sb_has_quota_enabled(struct super_block
*sb
, int type
)
71 return sb_dqopt(sb
)->flags
& DQUOT_USR_ENABLED
;
72 return sb_dqopt(sb
)->flags
& DQUOT_GRP_ENABLED
;
75 static inline int sb_any_quota_enabled(struct super_block
*sb
)
77 return sb_has_quota_enabled(sb
, USRQUOTA
) ||
78 sb_has_quota_enabled(sb
, GRPQUOTA
);
81 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
84 return sb_dqopt(sb
)->flags
& DQUOT_USR_SUSPENDED
;
85 return sb_dqopt(sb
)->flags
& DQUOT_GRP_SUSPENDED
;
88 static inline int sb_any_quota_suspended(struct super_block
*sb
)
90 return sb_has_quota_suspended(sb
, USRQUOTA
) ||
91 sb_has_quota_suspended(sb
, GRPQUOTA
);
95 * Operations supported for diskquotas.
97 extern struct dquot_operations dquot_operations
;
98 extern struct quotactl_ops vfs_quotactl_ops
;
100 #define sb_dquot_ops (&dquot_operations)
101 #define sb_quotactl_ops (&vfs_quotactl_ops)
103 /* It is better to call this function outside of any transaction as it might
104 * need a lot of space in journal for dquot structure allocation. */
105 static inline void vfs_dq_init(struct inode
*inode
)
107 BUG_ON(!inode
->i_sb
);
108 if (sb_any_quota_enabled(inode
->i_sb
) && !IS_NOQUOTA(inode
))
109 inode
->i_sb
->dq_op
->initialize(inode
, -1);
112 /* The following allocation/freeing/transfer functions *must* be called inside
113 * a transaction (deadlocks possible otherwise) */
114 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
116 if (sb_any_quota_enabled(inode
->i_sb
)) {
117 /* Used space is updated in alloc_space() */
118 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 1) == NO_QUOTA
)
122 inode_add_bytes(inode
, nr
);
126 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
129 if (!(ret
= vfs_dq_prealloc_space_nodirty(inode
, nr
)))
130 mark_inode_dirty(inode
);
134 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
136 if (sb_any_quota_enabled(inode
->i_sb
)) {
137 /* Used space is updated in alloc_space() */
138 if (inode
->i_sb
->dq_op
->alloc_space(inode
, nr
, 0) == NO_QUOTA
)
142 inode_add_bytes(inode
, nr
);
146 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
149 if (!(ret
= vfs_dq_alloc_space_nodirty(inode
, nr
)))
150 mark_inode_dirty(inode
);
154 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
156 if (sb_any_quota_enabled(inode
->i_sb
)) {
158 if (inode
->i_sb
->dq_op
->alloc_inode(inode
, 1) == NO_QUOTA
)
164 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
166 if (sb_any_quota_enabled(inode
->i_sb
))
167 inode
->i_sb
->dq_op
->free_space(inode
, nr
);
169 inode_sub_bytes(inode
, nr
);
172 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
174 vfs_dq_free_space_nodirty(inode
, nr
);
175 mark_inode_dirty(inode
);
178 static inline void vfs_dq_free_inode(struct inode
*inode
)
180 if (sb_any_quota_enabled(inode
->i_sb
))
181 inode
->i_sb
->dq_op
->free_inode(inode
, 1);
184 /* The following two functions cannot be called inside a transaction */
185 static inline void vfs_dq_sync(struct super_block
*sb
)
190 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
194 if (sb
->s_qcop
&& sb
->s_qcop
->quota_off
)
195 ret
= sb
->s_qcop
->quota_off(sb
, -1, remount
);
201 static inline int sb_has_quota_enabled(struct super_block
*sb
, int type
)
206 static inline int sb_any_quota_enabled(struct super_block
*sb
)
211 static inline int sb_has_quota_suspended(struct super_block
*sb
, int type
)
216 static inline int sb_any_quota_suspended(struct super_block
*sb
)
222 * NO-OP when quota not configured.
224 #define sb_dquot_ops (NULL)
225 #define sb_quotactl_ops (NULL)
227 static inline void vfs_dq_init(struct inode
*inode
)
231 static inline void vfs_dq_drop(struct inode
*inode
)
235 static inline int vfs_dq_alloc_inode(struct inode
*inode
)
240 static inline void vfs_dq_free_inode(struct inode
*inode
)
244 static inline void vfs_dq_sync(struct super_block
*sb
)
248 static inline int vfs_dq_off(struct super_block
*sb
, int remount
)
253 static inline int vfs_dq_quota_on_remount(struct super_block
*sb
)
258 static inline int vfs_dq_transfer(struct inode
*inode
, struct iattr
*iattr
)
263 static inline int vfs_dq_prealloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
265 inode_add_bytes(inode
, nr
);
269 static inline int vfs_dq_prealloc_space(struct inode
*inode
, qsize_t nr
)
271 vfs_dq_prealloc_space_nodirty(inode
, nr
);
272 mark_inode_dirty(inode
);
276 static inline int vfs_dq_alloc_space_nodirty(struct inode
*inode
, qsize_t nr
)
278 inode_add_bytes(inode
, nr
);
282 static inline int vfs_dq_alloc_space(struct inode
*inode
, qsize_t nr
)
284 vfs_dq_alloc_space_nodirty(inode
, nr
);
285 mark_inode_dirty(inode
);
289 static inline void vfs_dq_free_space_nodirty(struct inode
*inode
, qsize_t nr
)
291 inode_sub_bytes(inode
, nr
);
294 static inline void vfs_dq_free_space(struct inode
*inode
, qsize_t nr
)
296 vfs_dq_free_space_nodirty(inode
, nr
);
297 mark_inode_dirty(inode
);
300 #endif /* CONFIG_QUOTA */
302 static inline int vfs_dq_prealloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
304 return vfs_dq_prealloc_space_nodirty(inode
,
305 nr
<< inode
->i_sb
->s_blocksize_bits
);
308 static inline int vfs_dq_prealloc_block(struct inode
*inode
, qsize_t nr
)
310 return vfs_dq_prealloc_space(inode
,
311 nr
<< inode
->i_sb
->s_blocksize_bits
);
314 static inline int vfs_dq_alloc_block_nodirty(struct inode
*inode
, qsize_t nr
)
316 return vfs_dq_alloc_space_nodirty(inode
,
317 nr
<< inode
->i_sb
->s_blocksize_bits
);
320 static inline int vfs_dq_alloc_block(struct inode
*inode
, qsize_t nr
)
322 return vfs_dq_alloc_space(inode
,
323 nr
<< inode
->i_sb
->s_blocksize_bits
);
326 static inline void vfs_dq_free_block_nodirty(struct inode
*inode
, qsize_t nr
)
328 vfs_dq_free_space_nodirty(inode
, nr
<< inode
->i_sb
->s_blocksize_bits
);
331 static inline void vfs_dq_free_block(struct inode
*inode
, qsize_t nr
)
333 vfs_dq_free_space(inode
, nr
<< inode
->i_sb
->s_blocksize_bits
);
337 * Define uppercase equivalents for compatibility with old function names
338 * Can go away when we think all users have been converted (15/04/2008)
340 #define DQUOT_INIT(inode) vfs_dq_init(inode)
341 #define DQUOT_DROP(inode) vfs_dq_drop(inode)
342 #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
343 vfs_dq_prealloc_space_nodirty(inode, nr)
344 #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
345 #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
346 vfs_dq_alloc_space_nodirty(inode, nr)
347 #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
348 #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
349 vfs_dq_prealloc_block_nodirty(inode, nr)
350 #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
351 #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
352 vfs_dq_alloc_block_nodirty(inode, nr)
353 #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
354 #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
355 #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
356 vfs_dq_free_space_nodirty(inode, nr)
357 #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
358 #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
359 vfs_dq_free_block_nodirty(inode, nr)
360 #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
361 #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
362 #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
363 #define DQUOT_SYNC(sb) vfs_dq_sync(sb)
364 #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
365 #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
367 #endif /* _LINUX_QUOTAOPS_ */