quotaops.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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_dquots(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. /* The following two functions cannot be called inside a transaction */
  220. static inline void vfs_dq_sync(struct super_block *sb)
  221. {
  222. sync_dquots(sb, -1);
  223. }
  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 vfs_dq_sync(struct super_block *sb)
  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. /*
  381. * Define uppercase equivalents for compatibility with old function names
  382. * Can go away when we think all users have been converted (15/04/2008)
  383. */
  384. #define DQUOT_INIT(inode) vfs_dq_init(inode)
  385. #define DQUOT_DROP(inode) vfs_dq_drop(inode)
  386. #define DQUOT_PREALLOC_SPACE_NODIRTY(inode, nr) \
  387. vfs_dq_prealloc_space_nodirty(inode, nr)
  388. #define DQUOT_PREALLOC_SPACE(inode, nr) vfs_dq_prealloc_space(inode, nr)
  389. #define DQUOT_ALLOC_SPACE_NODIRTY(inode, nr) \
  390. vfs_dq_alloc_space_nodirty(inode, nr)
  391. #define DQUOT_ALLOC_SPACE(inode, nr) vfs_dq_alloc_space(inode, nr)
  392. #define DQUOT_PREALLOC_BLOCK_NODIRTY(inode, nr) \
  393. vfs_dq_prealloc_block_nodirty(inode, nr)
  394. #define DQUOT_PREALLOC_BLOCK(inode, nr) vfs_dq_prealloc_block(inode, nr)
  395. #define DQUOT_ALLOC_BLOCK_NODIRTY(inode, nr) \
  396. vfs_dq_alloc_block_nodirty(inode, nr)
  397. #define DQUOT_ALLOC_BLOCK(inode, nr) vfs_dq_alloc_block(inode, nr)
  398. #define DQUOT_ALLOC_INODE(inode) vfs_dq_alloc_inode(inode)
  399. #define DQUOT_FREE_SPACE_NODIRTY(inode, nr) \
  400. vfs_dq_free_space_nodirty(inode, nr)
  401. #define DQUOT_FREE_SPACE(inode, nr) vfs_dq_free_space(inode, nr)
  402. #define DQUOT_FREE_BLOCK_NODIRTY(inode, nr) \
  403. vfs_dq_free_block_nodirty(inode, nr)
  404. #define DQUOT_FREE_BLOCK(inode, nr) vfs_dq_free_block(inode, nr)
  405. #define DQUOT_FREE_INODE(inode) vfs_dq_free_inode(inode)
  406. #define DQUOT_TRANSFER(inode, iattr) vfs_dq_transfer(inode, iattr)
  407. #define DQUOT_SYNC(sb) vfs_dq_sync(sb)
  408. #define DQUOT_OFF(sb, remount) vfs_dq_off(sb, remount)
  409. #define DQUOT_ON_REMOUNT(sb) vfs_dq_quota_on_remount(sb)
  410. #endif /* _LINUX_QUOTAOPS_ */