quotaops.h 12 KB

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