quotaops.h 9.8 KB

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