quotaops.h 11 KB

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