quotaops.h 9.9 KB

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