quotaops.h 7.7 KB

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