quotaops.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.1.1.1 2007/06/12 07:27:16 eyryu 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. int remove_inode_dquot_ref(struct inode *inode, int type,
  32. struct list_head *tofree_head);
  33. extern int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path);
  34. extern int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
  35. int format_id, int type);
  36. extern int vfs_quota_off(struct super_block *sb, int type);
  37. #define vfs_quota_off_mount(sb, type) vfs_quota_off(sb, type)
  38. extern int vfs_quota_sync(struct super_block *sb, int type);
  39. extern int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  40. extern int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  41. extern int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  42. extern int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  43. /*
  44. * Operations supported for diskquotas.
  45. */
  46. extern struct dquot_operations dquot_operations;
  47. extern struct quotactl_ops vfs_quotactl_ops;
  48. #define sb_dquot_ops (&dquot_operations)
  49. #define sb_quotactl_ops (&vfs_quotactl_ops)
  50. /* It is better to call this function outside of any transaction as it might
  51. * need a lot of space in journal for dquot structure allocation. */
  52. static __inline__ void DQUOT_INIT(struct inode *inode)
  53. {
  54. BUG_ON(!inode->i_sb);
  55. if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode))
  56. inode->i_sb->dq_op->initialize(inode, -1);
  57. }
  58. /* The same as with DQUOT_INIT */
  59. static __inline__ void DQUOT_DROP(struct inode *inode)
  60. {
  61. /* Here we can get arbitrary inode from clear_inode() so we have
  62. * to be careful. OTOH we don't need locking as quota operations
  63. * are allowed to change only at mount time */
  64. if (!IS_NOQUOTA(inode) && inode->i_sb && inode->i_sb->dq_op
  65. && inode->i_sb->dq_op->drop) {
  66. int cnt;
  67. /* Test before calling to rule out calls from proc and such
  68. * where we are not allowed to block. Note that this is
  69. * actually reliable test even without the lock - the caller
  70. * must assure that nobody can come after the DQUOT_DROP and
  71. * add quota pointers back anyway */
  72. for (cnt = 0; cnt < MAXQUOTAS; cnt++)
  73. if (inode->i_dquot[cnt] != NODQUOT)
  74. break;
  75. if (cnt < MAXQUOTAS)
  76. inode->i_sb->dq_op->drop(inode);
  77. }
  78. }
  79. /* The following allocation/freeing/transfer functions *must* be called inside
  80. * a transaction (deadlocks possible otherwise) */
  81. static __inline__ int DQUOT_PREALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  82. {
  83. if (sb_any_quota_enabled(inode->i_sb)) {
  84. /* Used space is updated in alloc_space() */
  85. if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
  86. return 1;
  87. }
  88. else
  89. inode_add_bytes(inode, nr);
  90. return 0;
  91. }
  92. static __inline__ int DQUOT_PREALLOC_SPACE(struct inode *inode, qsize_t nr)
  93. {
  94. int ret;
  95. if (!(ret = DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr)))
  96. mark_inode_dirty(inode);
  97. return ret;
  98. }
  99. static __inline__ int DQUOT_ALLOC_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  100. {
  101. if (sb_any_quota_enabled(inode->i_sb)) {
  102. /* Used space is updated in alloc_space() */
  103. if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
  104. return 1;
  105. }
  106. else
  107. inode_add_bytes(inode, nr);
  108. return 0;
  109. }
  110. static __inline__ int DQUOT_ALLOC_SPACE(struct inode *inode, qsize_t nr)
  111. {
  112. int ret;
  113. if (!(ret = DQUOT_ALLOC_SPACE_NODIRTY(inode, nr)))
  114. mark_inode_dirty(inode);
  115. return ret;
  116. }
  117. static __inline__ int DQUOT_ALLOC_INODE(struct inode *inode)
  118. {
  119. if (sb_any_quota_enabled(inode->i_sb)) {
  120. DQUOT_INIT(inode);
  121. if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
  122. return 1;
  123. }
  124. return 0;
  125. }
  126. static __inline__ void DQUOT_FREE_SPACE_NODIRTY(struct inode *inode, qsize_t nr)
  127. {
  128. if (sb_any_quota_enabled(inode->i_sb))
  129. inode->i_sb->dq_op->free_space(inode, nr);
  130. else
  131. inode_sub_bytes(inode, nr);
  132. }
  133. static __inline__ void DQUOT_FREE_SPACE(struct inode *inode, qsize_t nr)
  134. {
  135. DQUOT_FREE_SPACE_NODIRTY(inode, nr);
  136. mark_inode_dirty(inode);
  137. }
  138. static __inline__ void DQUOT_FREE_INODE(struct inode *inode)
  139. {
  140. if (sb_any_quota_enabled(inode->i_sb))
  141. inode->i_sb->dq_op->free_inode(inode, 1);
  142. }
  143. static __inline__ int DQUOT_TRANSFER(struct inode *inode, struct iattr *iattr)
  144. {
  145. if (sb_any_quota_enabled(inode->i_sb) && !IS_NOQUOTA(inode)) {
  146. DQUOT_INIT(inode);
  147. if (inode->i_sb->dq_op->transfer(inode, iattr) == NO_QUOTA)
  148. return 1;
  149. }
  150. return 0;
  151. }
  152. /* The following two functions cannot be called inside a transaction */
  153. #define DQUOT_SYNC(sb) sync_dquots(sb, -1)
  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) do { } while(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. #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_PREALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
  207. #define DQUOT_PREALLOC_BLOCK(inode, nr) DQUOT_PREALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
  208. #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) DQUOT_ALLOC_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
  209. #define DQUOT_ALLOC_BLOCK(inode, nr) DQUOT_ALLOC_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
  210. #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) DQUOT_FREE_SPACE_NODIRTY(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
  211. #define DQUOT_FREE_BLOCK(inode, nr) DQUOT_FREE_SPACE(inode, ((qsize_t)(nr)) << (inode)->i_sb->s_blocksize_bits)
  212. #endif /* _LINUX_QUOTAOPS_ */