quotaops.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. #if defined(CONFIG_QUOTA)
  15. /*
  16. * declaration of quota_function calls in kernel.
  17. */
  18. extern void sync_dquots(struct super_block *sb, int type);
  19. extern int dquot_initialize(struct inode *inode, int type);
  20. extern int dquot_drop(struct inode *inode);
  21. extern int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
  22. extern int dquot_alloc_inode(const struct inode *inode, unsigned long number);
  23. extern int dquot_free_space(struct inode *inode, qsize_t number);
  24. extern int dquot_free_inode(const struct inode *inode, unsigned long number);
  25. extern int dquot_transfer(struct inode *inode, struct iattr *iattr);
  26. extern int dquot_commit(struct dquot *dquot);
  27. extern int dquot_acquire(struct dquot *dquot);
  28. extern int dquot_release(struct dquot *dquot);
  29. extern int dquot_commit_info(struct super_block *sb, int type);
  30. extern int dquot_mark_dquot_dirty(struct dquot *dquot);
  31. extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path);
  32. extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
  33. int format_id, int type);
  34. extern int vfs_quota_off(struct super_block *sb, int type);
  35. extern int vfs_quota_sync(struct super_block *sb, int type);
  36. extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  37. extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  38. extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  39. extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  40. /*
  41. * Operations supported for diskquotas.
  42. */
  43. extern struct dquot_operations dquot_operations;
  44. extern struct quotactl_ops vfs_quotactl_ops;
  45. #define sb_dquot_ops (&dquot_operations)
  46. #define sb_quotactl_ops (&vfs_quotactl_ops)
  47. /* It is better to call this function outside of any transaction as it might
  48. * need a lot of space in journal for dquot structure allocation. */
  49. static inline void DQUOT_INIT(struct inode *inode)
  50. {
  51. BUG_ON(!inode->i_sb);
  52. if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
  53. inode->i_sb->dq_op->initialize(inode, -1);
  54. }
  55. /* The same as with DQUOT_INIT */
  56. static inline void DQUOT_DROP(struct inode *inode)
  57. {
  58. /* Here we can get arbitrary inode from clear_inode() so we have
  59. * to be careful. OTOH we don't need locking as quota operations
  60. * are allowed to change only at mount time */
  61. if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
  62. && inode->i_sb->dq_op->drop) {
  63. int cnt;
  64. /* Test before calling to rule out calls from proc and such
  65. * where we are not allowed to block. Note that this is
  66. * actually reliable test even without the lock - the caller
  67. * must assure that nobody can come after the DQUOT_DROP and
  68. * add quota pointers back anyway */
  69. for (cnt = 0; cnt < MAXQUOTAS; cnt++)
  70. if (inode->i_dquot[cnt] != NODQUOT)
  71. break;
  72. if (cnt < MAXQUOTAS)
  73. inode->i_sb->dq_op->drop(inode);
  74. }
  75. }
  76. /* The following allocation/freeing/transfer functions *must* be called inside
  77. * a transaction (deadlocks possible otherwise) */
  78. static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  79. {
  80. if (sb_any_quota_enabled(inode->i_sb)) {
  81. /* Used space is updated in alloc_space() */
  82. if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
  83. return 1;
  84. }
  85. else
  86. inode_add_bytes(inode, nr);
  87. return 0;
  88. }
  89. static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
  90. {
  91. int ret;
  92. if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
  93. mark_inode_dirty(inode);
  94. return ret;
  95. }
  96. static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  97. {
  98. if (sb_any_quota_enabled(inode->i_sb)) {
  99. /* Used space is updated in alloc_space() */
  100. if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
  101. return 1;
  102. }
  103. else
  104. inode_add_bytes(inode, nr);
  105. return 0;
  106. }
  107. static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
  108. {
  109. int ret;
  110. if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
  111. mark_inode_dirty(inode);
  112. return ret;
  113. }
  114. static inline int DQUOT_ALLOC_INODE(struct inode *inode)
  115. {
  116. if (sb_any_quota_enabled(inode->i_sb)) {
  117. DQUOT_INIT(inode);
  118. if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
  119. return 1;
  120. }
  121. return 0;
  122. }
  123. static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  124. {
  125. if (sb_any_quota_enabled(inode->i_sb))
  126. inode->i_sb->dq_op->free_space(inode, nr);
  127. else
  128. inode_sub_bytes(inode, nr);
  129. }
  130. static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
  131. {
  132. DQUOT_FREE_SPACE_NODIRTY(inode, nr);
  133. mark_inode_dirty(inode);
  134. }
  135. static inline void DQUOT_FREE_INODE(struct inode *inode)
  136. {
  137. if (sb_any_quota_enabled(inode->i_sb))
  138. inode->i_sb->dq_op->free_inode(inode, 1);
  139. }
  140. static inline int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
  141. {
  142. if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
  143. DQUOT_INIT(inode);
  144. if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
  145. return 1;
  146. }
  147. return 0;
  148. }
  149. /* The following two functions cannot be called inside a transaction */
  150. static inline void DQUOT_SYNC(struct super_block *sb)
  151. {
  152. sync_dquots(sb, -1);
  153. }
  154. static inline int DQUOT_OFF(struct super_block *sb)
  155. {
  156. int ret = -ENOSYS;
  157. if (sb_any_quota_enabled(sb) && sb->s_qcop && sb->s_qcop->quota_off)
  158. ret = sb->s_qcop->quota_off(sb, -1);
  159. return ret;
  160. }
  161. #else
  162. /*
  163. * NO-OP when quota not configured.
  164. */
  165. #define sb_dquot_ops (NULL)
  166. #define sb_quotactl_ops (NULL)
  167. #define DQUOT_INIT(inode) do { } while(0)
  168. #define DQUOT_DROP(inode) do { } while(0)
  169. #define DQUOT_ALLOC_INODE(inode) (0)
  170. #define DQUOT_FREE_INODE(inode) do { } while(0)
  171. #define DQUOT_SYNC(sb) do { } while(0)
  172. #define DQUOT_OFF(sb) (0)
  173. #define DQUOT_TRANSFER(inode, iattr) (0)
  174. static inline int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  175. {
  176. inode_add_bytes(inode, nr);
  177. return 0;
  178. }
  179. static inline int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
  180. {
  181. DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr);
  182. mark_inode_dirty(inode);
  183. return 0;
  184. }
  185. static inline int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  186. {
  187. inode_add_bytes(inode, nr);
  188. return 0;
  189. }
  190. static inline int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
  191. {
  192. DQUOT_ALLOC_SPACE_NODIRTY(inode, nr);
  193. mark_inode_dirty(inode);
  194. return 0;
  195. }
  196. static inline void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  197. {
  198. inode_sub_bytes(inode, nr);
  199. }
  200. static inline void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
  201. {
  202. DQUOT_FREE_SPACE_NODIRTY(inode, nr);
  203. mark_inode_dirty(inode);
  204. }
  205. #endif /* CONFIG_QUOTA */
  206. static inline int DQUOT_PREALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
  207. {
  208. return DQUOT_PREALLOC_SPACE_NODIRTY(inode,
  209. nr << inode->i_sb->s_blocksize_bits);
  210. }
  211. static inline int DQUOT_PREALLOC_BLOCK(struct inode *inode, qsize_t nr)
  212. {
  213. return DQUOT_PREALLOC_SPACE(inode,
  214. nr << inode->i_sb->s_blocksize_bits);
  215. }
  216. static inline int DQUOT_ALLOC_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
  217. {
  218. return DQUOT_ALLOC_SPACE_NODIRTY(inode,
  219. nr << inode->i_sb->s_blocksize_bits);
  220. }
  221. static inline int DQUOT_ALLOC_BLOCK(struct inode *inode, qsize_t nr)
  222. {
  223. return DQUOT_ALLOC_SPACE(inode,
  224. nr << inode->i_sb->s_blocksize_bits);
  225. }
  226. static inline void DQUOT_FREE_BLOCK_NODIRTY(struct inode *inode, qsize_t nr)
  227. {
  228. DQUOT_FREE_SPACE_NODIRTY(inode, nr << inode->i_sb->s_blocksize_bits);
  229. }
  230. static inline void DQUOT_FREE_BLOCK(struct inode *inode, qsize_t nr)
  231. {
  232. DQUOT_FREE_SPACE(inode, nr << inode->i_sb->s_blocksize_bits);
  233. }
  234. #endif /* _LINUX_QUOTAOPS_ */