quotaops.h 12 KB

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