quotaops.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * Definitions for diskquota-operations. When diskquota is configured these
  3. * macros expand to the right source-code.
  4. *
  5. * Author: Marco van Wieringen <mvw@planets.elm.net>
  6. *
  7. * Version: $Id: quotaops.h,v 1.2 1998/01/15 16:22:26 ecd Exp $
  8. *
  9. */
  10. #ifndef _LINUX_QUOTAOPS_
  11. #define _LINUX_QUOTAOPS_
  12. #include <linux/smp_lock.h>
  13. #include <linux/fs.h>
  14. #define sb_dqopt(sb) (&(sb)->s_dquot)
  15. #if defined(CONFIG_QUOTA)
  16. /*
  17. * declaration of quota_function calls in kernel.
  18. */
  19. void sync_dquots(struct super_block *sb, int type);
  20. int dquot_initialize(struct inode *inode, int type);
  21. int dquot_drop(struct inode *inode);
  22. int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
  23. int dquot_alloc_inode(const struct inode *inode, unsigned long number);
  24. int dquot_free_space(struct inode *inode, qsize_t number);
  25. int dquot_free_inode(const struct inode *inode, unsigned long number);
  26. int dquot_transfer(struct inode *inode, struct iattr *iattr);
  27. int dquot_commit(struct dquot *dquot);
  28. int dquot_acquire(struct dquot *dquot);
  29. int dquot_release(struct dquot *dquot);
  30. int dquot_commit_info(struct super_block *sb, int type);
  31. int dquot_mark_dquot_dirty(struct dquot *dquot);
  32. int vfs_quota_on(struct super_block *sb, int type, int format_id,
  33. char *path, int remount);
  34. int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
  35. int format_id, int type);
  36. int vfs_quota_off(struct super_block *sb, int type, int remount);
  37. int vfs_quota_sync(struct super_block *sb, int type);
  38. int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  39. int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  40. int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  41. int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  42. void vfs_dq_drop(struct inode *inode);
  43. int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
  44. int vfs_dq_quota_on_remount(struct super_block *sb);
  45. #define sb_dqinfo(sb, type) (sb_dqopt(sb)->info+(type))
  46. /*
  47. * Functions for checking status of quota
  48. */
  49. #define sb_has_quota_enabled(sb, type) ((type)==USRQUOTA ? \
  50. (sb_dqopt(sb)->flags & DQUOT_USR_ENABLED) : (sb_dqopt(sb)->flags & DQUOT_GRP_ENABLED))
  51. #define sb_any_quota_enabled(sb) (sb_has_quota_enabled(sb, USRQUOTA) | \
  52. sb_has_quota_enabled(sb, GRPQUOTA))
  53. #define sb_has_quota_suspended(sb, type) \
  54. ((type) == USRQUOTA ? (sb_dqopt(sb)->flags & DQUOT_USR_SUSPENDED) : \
  55. (sb_dqopt(sb)->flags & DQUOT_GRP_SUSPENDED))
  56. #define sb_any_quota_suspended(sb) (sb_has_quota_suspended(sb, USRQUOTA) | \
  57. sb_has_quota_suspended(sb, GRPQUOTA))
  58. /*
  59. * Operations supported for diskquotas.
  60. */
  61. extern struct dquot_operations dquot_operations;
  62. extern struct quotactl_ops vfs_quotactl_ops;
  63. #define sb_dquot_ops (&dquot_operations)
  64. #define sb_quotactl_ops (&vfs_quotactl_ops)
  65. /* It is better to call this function outside of any transaction as it might
  66. * need a lot of space in journal for dquot structure allocation. */
  67. static inline void vfs_dq_init(struct inode *inode)
  68. {
  69. BUG_ON(!inode->i_sb);
  70. if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
  71. inode->i_sb->dq_op->initialize(inode, -1);
  72. }
  73. /* The following allocation/freeing/transfer functions *must* be called inside
  74. * a transaction (deadlocks possible otherwise) */
  75. static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
  76. {
  77. if (sb_any_quota_enabled(inode->i_sb)) {
  78. /* Used space is updated in alloc_space() */
  79. if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
  80. return 1;
  81. }
  82. else
  83. inode_add_bytes(inode, nr);
  84. return 0;
  85. }
  86. static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
  87. {
  88. int ret;
  89. if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
  90. mark_inode_dirty(inode);
  91. return ret;
  92. }
  93. static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
  94. {
  95. if (sb_any_quota_enabled(inode->i_sb)) {
  96. /* Used space is updated in alloc_space() */
  97. if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
  98. return 1;
  99. }
  100. else
  101. inode_add_bytes(inode, nr);
  102. return 0;
  103. }
  104. static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
  105. {
  106. int ret;
  107. if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
  108. mark_inode_dirty(inode);
  109. return ret;
  110. }
  111. static inline int vfs_dq_alloc_inode(struct inode *inode)
  112. {
  113. if (sb_any_quota_enabled(inode->i_sb)) {
  114. vfs_dq_init(inode);
  115. if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
  116. return 1;
  117. }
  118. return 0;
  119. }
  120. static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
  121. {
  122. if (sb_any_quota_enabled(inode->i_sb))
  123. inode->i_sb->dq_op->free_space(inode, nr);
  124. else
  125. inode_sub_bytes(inode, nr);
  126. }
  127. static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
  128. {
  129. vfs_dq_free_space_nodirty(inode, nr);
  130. mark_inode_dirty(inode);
  131. }
  132. static inline void vfs_dq_free_inode(struct inode *inode)
  133. {
  134. if (sb_any_quota_enabled(inode->i_sb))
  135. inode->i_sb->dq_op->free_inode(inode, 1);
  136. }
  137. /* The following two functions cannot be called inside a transaction */
  138. static inline void vfs_dq_sync(struct super_block *sb)
  139. {
  140. sync_dquots(sb, -1);
  141. }
  142. static inline int vfs_dq_off(struct super_block *sb, int remount)
  143. {
  144. int ret = -ENOSYS;
  145. if (sb->s_qcop && sb->s_qcop->quota_off)
  146. ret = sb->s_qcop->quota_off(sb, -1, remount);
  147. return ret;
  148. }
  149. #else
  150. #define sb_has_quota_enabled(sb, type) 0
  151. #define sb_any_quota_enabled(sb) 0
  152. #define sb_has_quota_suspended(sb, type) 0
  153. #define sb_any_quota_suspended(sb) 0
  154. /*
  155. * NO-OP when quota not configured.
  156. */
  157. #define sb_dquot_ops (NULL)
  158. #define sb_quotactl_ops (NULL)
  159. static inline void vfs_dq_init(struct inode *inode)
  160. {
  161. }
  162. static inline void vfs_dq_drop(struct inode *inode)
  163. {
  164. }
  165. static inline int vfs_dq_alloc_inode(struct inode *inode)
  166. {
  167. return 0;
  168. }
  169. static inline void vfs_dq_free_inode(struct inode *inode)
  170. {
  171. }
  172. static inline void vfs_dq_sync(struct super_block *sb)
  173. {
  174. }
  175. static inline int vfs_dq_off(struct super_block *sb, int remount)
  176. {
  177. return 0;
  178. }
  179. static inline int vfs_dq_quota_on_remount(struct super_block *sb)
  180. {
  181. return 0;
  182. }
  183. static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
  184. {
  185. return 0;
  186. }
  187. static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
  188. {
  189. inode_add_bytes(inode, nr);
  190. return 0;
  191. }
  192. static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
  193. {
  194. vfs_dq_prealloc_space_nodirty(inode, nr);
  195. mark_inode_dirty(inode);
  196. return 0;
  197. }
  198. static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
  199. {
  200. inode_add_bytes(inode, nr);
  201. return 0;
  202. }
  203. static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
  204. {
  205. vfs_dq_alloc_space_nodirty(inode, nr);
  206. mark_inode_dirty(inode);
  207. return 0;
  208. }
  209. static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
  210. {
  211. inode_sub_bytes(inode, nr);
  212. }
  213. static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
  214. {
  215. vfs_dq_free_space_nodirty(inode, nr);
  216. mark_inode_dirty(inode);
  217. }
  218. #endif /* CONFIG_QUOTA */
  219. static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
  220. {
  221. return vfs_dq_prealloc_space_nodirty(inode,
  222. nr << inode->i_sb->s_blocksize_bits);
  223. }
  224. static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
  225. {
  226. return vfs_dq_prealloc_space(inode,
  227. nr << inode->i_sb->s_blocksize_bits);
  228. }
  229. static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
  230. {
  231. return vfs_dq_alloc_space_nodirty(inode,
  232. nr << inode->i_sb->s_blocksize_bits);
  233. }
  234. static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
  235. {
  236. return vfs_dq_alloc_space(inode,
  237. nr << inode->i_sb->s_blocksize_bits);
  238. }
  239. static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
  240. {
  241. vfs_dq_free_space_nodirty(inode, nr << inode->i_sb->s_blocksize_bits);
  242. }
  243. static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
  244. {
  245. vfs_dq_free_space(inode, nr << inode->i_sb->s_blocksize_bits);
  246. }
  247. /*
  248. * Define uppercase equivalents for compatibility with old function names
  249. * Can go away when we think all users have been converted (15/04/2008)
  250. */
  251. #define DQUOT_INIT(inode) vfs_dq_init(inode)
  252. #define DQUOT_DROP(inode) vfs_dq_drop(inode)
  253. #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
  254. vfs_dq_prealloc_space_nodirty(inode, nr)
  255. #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
  256. #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
  257. vfs_dq_alloc_space_nodirty(inode, nr)
  258. #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
  259. #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
  260. vfs_dq_prealloc_block_nodirty(inode, nr)
  261. #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
  262. #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
  263. vfs_dq_alloc_block_nodirty(inode, nr)
  264. #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
  265. #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
  266. #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
  267. vfs_dq_free_space_nodirty(inode, nr)
  268. #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
  269. #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
  270. vfs_dq_free_block_nodirty(inode, nr)
  271. #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
  272. #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
  273. #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
  274. #define DQUOT_SYNC(sb) vfs_dq_sync(sb)
  275. #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
  276. #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
  277. #endif /* _LINUX_QUOTAOPS_ */