quotaops.h 12 KB

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