quotaops.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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/fs.h>
  10. static inline struct quota_info *sb_dqopt(struct super_block *sb)
  11. {
  12. return &sb->s_dquot;
  13. }
  14. #if defined(CONFIG_QUOTA)
  15. /*
  16. * declaration of quota_function calls in kernel.
  17. */
  18. void inode_add_rsv_space(struct inode *inode, qsize_t number);
  19. void inode_claim_rsv_space(struct inode *inode, qsize_t number);
  20. void inode_sub_rsv_space(struct inode *inode, qsize_t number);
  21. int dquot_initialize(struct inode *inode, int type);
  22. int dquot_drop(struct inode *inode);
  23. struct dquot *dqget(struct super_block *sb, unsigned int id, int type);
  24. void dqput(struct dquot *dquot);
  25. int dquot_scan_active(struct super_block *sb,
  26. int (*fn)(struct dquot *dquot, unsigned long priv),
  27. unsigned long priv);
  28. struct dquot *dquot_alloc(struct super_block *sb, int type);
  29. void dquot_destroy(struct dquot *dquot);
  30. int dquot_alloc_space(struct inode *inode, qsize_t number, int prealloc);
  31. int dquot_alloc_inode(const struct inode *inode, qsize_t number);
  32. int dquot_reserve_space(struct inode *inode, qsize_t number, int prealloc);
  33. int dquot_claim_space(struct inode *inode, qsize_t number);
  34. void dquot_release_reserved_space(struct inode *inode, qsize_t number);
  35. int dquot_free_space(struct inode *inode, qsize_t number);
  36. int dquot_free_inode(const struct inode *inode, qsize_t number);
  37. int dquot_transfer(struct inode *inode, struct iattr *iattr);
  38. int dquot_commit(struct dquot *dquot);
  39. int dquot_acquire(struct dquot *dquot);
  40. int dquot_release(struct dquot *dquot);
  41. int dquot_commit_info(struct super_block *sb, int type);
  42. int dquot_mark_dquot_dirty(struct dquot *dquot);
  43. int vfs_quota_on(struct super_block *sb, int type, int format_id,
  44. char *path, int remount);
  45. int vfs_quota_enable(struct inode *inode, int type, int format_id,
  46. unsigned int flags);
  47. int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
  48. struct path *path);
  49. int vfs_quota_on_mount(struct super_block *sb, char *qf_name,
  50. int format_id, int type);
  51. int vfs_quota_off(struct super_block *sb, int type, int remount);
  52. int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags);
  53. int vfs_quota_sync(struct super_block *sb, int type, int wait);
  54. int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  55. int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
  56. int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  57. int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di);
  58. void vfs_dq_drop(struct inode *inode);
  59. int vfs_dq_transfer(struct inode *inode, struct iattr *iattr);
  60. int vfs_dq_quota_on_remount(struct super_block *sb);
  61. static inline struct mem_dqinfo *sb_dqinfo(struct super_block *sb, int type)
  62. {
  63. return sb_dqopt(sb)->info + type;
  64. }
  65. /*
  66. * Functions for checking status of quota
  67. */
  68. static inline bool sb_has_quota_usage_enabled(struct super_block *sb, int type)
  69. {
  70. return sb_dqopt(sb)->flags &
  71. dquot_state_flag(DQUOT_USAGE_ENABLED, type);
  72. }
  73. static inline bool sb_has_quota_limits_enabled(struct super_block *sb, int type)
  74. {
  75. return sb_dqopt(sb)->flags &
  76. dquot_state_flag(DQUOT_LIMITS_ENABLED, type);
  77. }
  78. static inline bool sb_has_quota_suspended(struct super_block *sb, int type)
  79. {
  80. return sb_dqopt(sb)->flags &
  81. dquot_state_flag(DQUOT_SUSPENDED, type);
  82. }
  83. static inline unsigned sb_any_quota_suspended(struct super_block *sb)
  84. {
  85. unsigned type, tmsk = 0;
  86. for (type = 0; type < MAXQUOTAS; type++)
  87. tmsk |= sb_has_quota_suspended(sb, type) << type;
  88. return tmsk;
  89. }
  90. /* Does kernel know about any quota information for given sb + type? */
  91. static inline bool sb_has_quota_loaded(struct super_block *sb, int type)
  92. {
  93. /* Currently if anything is on, then quota usage is on as well */
  94. return sb_has_quota_usage_enabled(sb, type);
  95. }
  96. static inline unsigned sb_any_quota_loaded(struct super_block *sb)
  97. {
  98. unsigned type, tmsk = 0;
  99. for (type = 0; type < MAXQUOTAS; type++)
  100. tmsk |= sb_has_quota_loaded(sb, type) << type;
  101. return tmsk;
  102. }
  103. static inline bool sb_has_quota_active(struct super_block *sb, int type)
  104. {
  105. return sb_has_quota_loaded(sb, type) &&
  106. !sb_has_quota_suspended(sb, type);
  107. }
  108. static inline unsigned sb_any_quota_active(struct super_block *sb)
  109. {
  110. return sb_any_quota_loaded(sb) & ~sb_any_quota_suspended(sb);
  111. }
  112. /*
  113. * Operations supported for diskquotas.
  114. */
  115. extern const struct dquot_operations dquot_operations;
  116. extern const struct quotactl_ops vfs_quotactl_ops;
  117. #define sb_dquot_ops (&dquot_operations)
  118. #define sb_quotactl_ops (&vfs_quotactl_ops)
  119. /* It is better to call this function outside of any transaction as it might
  120. * need a lot of space in journal for dquot structure allocation. */
  121. static inline void vfs_dq_init(struct inode *inode)
  122. {
  123. BUG_ON(!inode->i_sb);
  124. if (sb_any_quota_active(inode->i_sb) && !IS_NOQUOTA(inode))
  125. inode->i_sb->dq_op->initialize(inode, -1);
  126. }
  127. /* The following allocation/freeing/transfer functions *must* be called inside
  128. * a transaction (deadlocks possible otherwise) */
  129. static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
  130. {
  131. if (sb_any_quota_active(inode->i_sb)) {
  132. /* Used space is updated in alloc_space() */
  133. if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
  134. return 1;
  135. }
  136. else
  137. inode_add_bytes(inode, nr);
  138. return 0;
  139. }
  140. static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
  141. {
  142. int ret;
  143. if (!(ret = vfs_dq_prealloc_space_nodirty(inode, nr)))
  144. mark_inode_dirty(inode);
  145. return ret;
  146. }
  147. static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
  148. {
  149. if (sb_any_quota_active(inode->i_sb)) {
  150. /* Used space is updated in alloc_space() */
  151. if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
  152. return 1;
  153. }
  154. else
  155. inode_add_bytes(inode, nr);
  156. return 0;
  157. }
  158. static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
  159. {
  160. int ret;
  161. if (!(ret = vfs_dq_alloc_space_nodirty(inode, nr)))
  162. mark_inode_dirty(inode);
  163. return ret;
  164. }
  165. static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
  166. {
  167. if (sb_any_quota_active(inode->i_sb)) {
  168. /* Used space is updated in alloc_space() */
  169. if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
  170. return 1;
  171. }
  172. else
  173. inode_add_rsv_space(inode, nr);
  174. return 0;
  175. }
  176. static inline int vfs_dq_alloc_inode(struct inode *inode)
  177. {
  178. if (sb_any_quota_active(inode->i_sb)) {
  179. vfs_dq_init(inode);
  180. if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
  181. return 1;
  182. }
  183. return 0;
  184. }
  185. /*
  186. * Convert in-memory reserved quotas to real consumed quotas
  187. */
  188. static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
  189. {
  190. if (sb_any_quota_active(inode->i_sb)) {
  191. if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
  192. return 1;
  193. } else
  194. inode_claim_rsv_space(inode, nr);
  195. mark_inode_dirty(inode);
  196. return 0;
  197. }
  198. /*
  199. * Release reserved (in-memory) quotas
  200. */
  201. static inline
  202. void vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
  203. {
  204. if (sb_any_quota_active(inode->i_sb))
  205. inode->i_sb->dq_op->release_rsv(inode, nr);
  206. else
  207. inode_sub_rsv_space(inode, nr);
  208. }
  209. static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
  210. {
  211. if (sb_any_quota_active(inode->i_sb))
  212. inode->i_sb->dq_op->free_space(inode, nr);
  213. else
  214. inode_sub_bytes(inode, nr);
  215. }
  216. static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
  217. {
  218. vfs_dq_free_space_nodirty(inode, nr);
  219. mark_inode_dirty(inode);
  220. }
  221. static inline void vfs_dq_free_inode(struct inode *inode)
  222. {
  223. if (sb_any_quota_active(inode->i_sb))
  224. inode->i_sb->dq_op->free_inode(inode, 1);
  225. }
  226. /* Cannot be called inside a transaction */
  227. static inline int vfs_dq_off(struct super_block *sb, int remount)
  228. {
  229. int ret = -ENOSYS;
  230. if (sb->s_qcop && sb->s_qcop->quota_off)
  231. ret = sb->s_qcop->quota_off(sb, -1, remount);
  232. return ret;
  233. }
  234. #else
  235. static inline int sb_has_quota_usage_enabled(struct super_block *sb, int type)
  236. {
  237. return 0;
  238. }
  239. static inline int sb_has_quota_limits_enabled(struct super_block *sb, int type)
  240. {
  241. return 0;
  242. }
  243. static inline int sb_has_quota_suspended(struct super_block *sb, int type)
  244. {
  245. return 0;
  246. }
  247. static inline int sb_any_quota_suspended(struct super_block *sb)
  248. {
  249. return 0;
  250. }
  251. /* Does kernel know about any quota information for given sb + type? */
  252. static inline int sb_has_quota_loaded(struct super_block *sb, int type)
  253. {
  254. return 0;
  255. }
  256. static inline int sb_any_quota_loaded(struct super_block *sb)
  257. {
  258. return 0;
  259. }
  260. static inline int sb_has_quota_active(struct super_block *sb, int type)
  261. {
  262. return 0;
  263. }
  264. static inline int sb_any_quota_active(struct super_block *sb)
  265. {
  266. return 0;
  267. }
  268. /*
  269. * NO-OP when quota not configured.
  270. */
  271. #define sb_dquot_ops (NULL)
  272. #define sb_quotactl_ops (NULL)
  273. static inline void vfs_dq_init(struct inode *inode)
  274. {
  275. }
  276. static inline void vfs_dq_drop(struct inode *inode)
  277. {
  278. }
  279. static inline int vfs_dq_alloc_inode(struct inode *inode)
  280. {
  281. return 0;
  282. }
  283. static inline void vfs_dq_free_inode(struct inode *inode)
  284. {
  285. }
  286. static inline int vfs_dq_off(struct super_block *sb, int remount)
  287. {
  288. return 0;
  289. }
  290. static inline int vfs_dq_quota_on_remount(struct super_block *sb)
  291. {
  292. return 0;
  293. }
  294. static inline int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
  295. {
  296. return 0;
  297. }
  298. static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
  299. {
  300. inode_add_bytes(inode, nr);
  301. return 0;
  302. }
  303. static inline int vfs_dq_prealloc_space(struct inode *inode, qsize_t nr)
  304. {
  305. vfs_dq_prealloc_space_nodirty(inode, nr);
  306. mark_inode_dirty(inode);
  307. return 0;
  308. }
  309. static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
  310. {
  311. inode_add_bytes(inode, nr);
  312. return 0;
  313. }
  314. static inline int vfs_dq_alloc_space(struct inode *inode, qsize_t nr)
  315. {
  316. vfs_dq_alloc_space_nodirty(inode, nr);
  317. mark_inode_dirty(inode);
  318. return 0;
  319. }
  320. static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
  321. {
  322. return 0;
  323. }
  324. static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
  325. {
  326. return vfs_dq_alloc_space(inode, nr);
  327. }
  328. static inline
  329. int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
  330. {
  331. return 0;
  332. }
  333. static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
  334. {
  335. inode_sub_bytes(inode, nr);
  336. }
  337. static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
  338. {
  339. vfs_dq_free_space_nodirty(inode, nr);
  340. mark_inode_dirty(inode);
  341. }
  342. #endif /* CONFIG_QUOTA */
  343. static inline int vfs_dq_prealloc_block_nodirty(struct inode *inode, qsize_t nr)
  344. {
  345. return vfs_dq_prealloc_space_nodirty(inode, nr << inode->i_blkbits);
  346. }
  347. static inline int vfs_dq_prealloc_block(struct inode *inode, qsize_t nr)
  348. {
  349. return vfs_dq_prealloc_space(inode, nr << inode->i_blkbits);
  350. }
  351. static inline int vfs_dq_alloc_block_nodirty(struct inode *inode, qsize_t nr)
  352. {
  353. return vfs_dq_alloc_space_nodirty(inode, nr << inode->i_blkbits);
  354. }
  355. static inline int vfs_dq_alloc_block(struct inode *inode, qsize_t nr)
  356. {
  357. return vfs_dq_alloc_space(inode, nr << inode->i_blkbits);
  358. }
  359. static inline int vfs_dq_reserve_block(struct inode *inode, qsize_t nr)
  360. {
  361. return vfs_dq_reserve_space(inode, nr << inode->i_blkbits);
  362. }
  363. static inline int vfs_dq_claim_block(struct inode *inode, qsize_t nr)
  364. {
  365. return vfs_dq_claim_space(inode, nr << inode->i_blkbits);
  366. }
  367. static inline
  368. void vfs_dq_release_reservation_block(struct inode *inode, qsize_t nr)
  369. {
  370. vfs_dq_release_reservation_space(inode, nr << inode->i_blkbits);
  371. }
  372. static inline void vfs_dq_free_block_nodirty(struct inode *inode, qsize_t nr)
  373. {
  374. vfs_dq_free_space_nodirty(inode, nr << inode->i_blkbits);
  375. }
  376. static inline void vfs_dq_free_block(struct inode *inode, qsize_t nr)
  377. {
  378. vfs_dq_free_space(inode, nr << inode->i_blkbits);
  379. }
  380. #endif /* _LINUX_QUOTAOPS_ */