quotaops.h 7.7 KB

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