quotaops.h 11 KB

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