ext3_jbd.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * linux/include/linux/ext3_jbd.h
  3. *
  4. * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
  5. *
  6. * Copyright 1998--1999 Red Hat corp --- All Rights Reserved
  7. *
  8. * This file is part of the Linux kernel and is made available under
  9. * the terms of the GNU General Public License, version 2, or at your
  10. * option, any later version, incorporated herein by reference.
  11. *
  12. * Ext3-specific journaling extensions.
  13. */
  14. #ifndef _LINUX_EXT3_JBD_H
  15. #define _LINUX_EXT3_JBD_H
  16. #include <linux/fs.h>
  17. #include <linux/jbd.h>
  18. #include <linux/ext3_fs.h>
  19. #define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal)
  20. /* Define the number of blocks we need to account to a transaction to
  21. * modify one block of data.
  22. *
  23. * We may have to touch one inode, one bitmap buffer, up to three
  24. * indirection blocks, the group and superblock summaries, and the data
  25. * block to complete the transaction. */
  26. #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U
  27. /* Extended attribute operations touch at most two data buffers,
  28. * two bitmap buffers, and two group summaries, in addition to the inode
  29. * and the superblock, which are already accounted for. */
  30. #define EXT3_XATTR_TRANS_BLOCKS 6U
  31. /* Define the minimum size for a transaction which modifies data. This
  32. * needs to take into account the fact that we may end up modifying two
  33. * quota files too (one for the group, one for the user quota). The
  34. * superblock only gets updated once, of course, so don't bother
  35. * counting that again for the quota updates. */
  36. #define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \
  37. EXT3_XATTR_TRANS_BLOCKS - 2 + \
  38. 2*EXT3_QUOTA_TRANS_BLOCKS(sb))
  39. /* Delete operations potentially hit one directory's namespace plus an
  40. * entire inode, plus arbitrary amounts of bitmap/indirection data. Be
  41. * generous. We can grow the delete transaction later if necessary. */
  42. #define EXT3_DELETE_TRANS_BLOCKS(sb) (2 * EXT3_DATA_TRANS_BLOCKS(sb) + 64)
  43. /* Define an arbitrary limit for the amount of data we will anticipate
  44. * writing to any given transaction. For unbounded transactions such as
  45. * write(2) and truncate(2) we can write more than this, but we always
  46. * start off at the maximum transaction size and grow the transaction
  47. * optimistically as we go. */
  48. #define EXT3_MAX_TRANS_DATA 64U
  49. /* We break up a large truncate or write transaction once the handle's
  50. * buffer credits gets this low, we need either to extend the
  51. * transaction or to start a new one. Reserve enough space here for
  52. * inode, bitmap, superblock, group and indirection updates for at least
  53. * one block, plus two quota updates. Quota allocations are not
  54. * needed. */
  55. #define EXT3_RESERVE_TRANS_BLOCKS 12U
  56. #define EXT3_INDEX_EXTRA_TRANS_BLOCKS 8
  57. #ifdef CONFIG_QUOTA
  58. /* Amount of blocks needed for quota update - we know that the structure was
  59. * allocated so we need to update only inode+data */
  60. #define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0)
  61. /* Amount of blocks needed for quota insert/delete - we do some block writes
  62. * but inode, sb and group updates are done only once */
  63. #define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\
  64. (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0)
  65. #define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\
  66. (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0)
  67. #else
  68. #define EXT3_QUOTA_TRANS_BLOCKS(sb) 0
  69. #define EXT3_QUOTA_INIT_BLOCKS(sb) 0
  70. #define EXT3_QUOTA_DEL_BLOCKS(sb) 0
  71. #endif
  72. int
  73. ext3_mark_iloc_dirty(handle_t *handle,
  74. struct inode *inode,
  75. struct ext3_iloc *iloc);
  76. /*
  77. * On success, We end up with an outstanding reference count against
  78. * iloc->bh. This _must_ be cleaned up later.
  79. */
  80. int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
  81. struct ext3_iloc *iloc);
  82. int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);
  83. /*
  84. * Wrapper functions with which ext3 calls into JBD. The intent here is
  85. * to allow these to be turned into appropriate stubs so ext3 can control
  86. * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't
  87. * been done yet.
  88. */
  89. void ext3_journal_abort_handle(const char *caller, const char *err_fn,
  90. struct buffer_head *bh, handle_t *handle, int err);
  91. static inline int
  92. __ext3_journal_get_undo_access(const char *where, handle_t *handle,
  93. struct buffer_head *bh)
  94. {
  95. int err = journal_get_undo_access(handle, bh);
  96. if (err)
  97. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  98. return err;
  99. }
  100. static inline int
  101. __ext3_journal_get_write_access(const char *where, handle_t *handle,
  102. struct buffer_head *bh)
  103. {
  104. int err = journal_get_write_access(handle, bh);
  105. if (err)
  106. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  107. return err;
  108. }
  109. static inline void
  110. ext3_journal_release_buffer(handle_t *handle, struct buffer_head *bh)
  111. {
  112. journal_release_buffer(handle, bh);
  113. }
  114. static inline int
  115. __ext3_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh)
  116. {
  117. int err = journal_forget(handle, bh);
  118. if (err)
  119. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  120. return err;
  121. }
  122. static inline int
  123. __ext3_journal_revoke(const char *where, handle_t *handle,
  124. unsigned long blocknr, struct buffer_head *bh)
  125. {
  126. int err = journal_revoke(handle, blocknr, bh);
  127. if (err)
  128. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  129. return err;
  130. }
  131. static inline int
  132. __ext3_journal_get_create_access(const char *where,
  133. handle_t *handle, struct buffer_head *bh)
  134. {
  135. int err = journal_get_create_access(handle, bh);
  136. if (err)
  137. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  138. return err;
  139. }
  140. static inline int
  141. __ext3_journal_dirty_metadata(const char *where,
  142. handle_t *handle, struct buffer_head *bh)
  143. {
  144. int err = journal_dirty_metadata(handle, bh);
  145. if (err)
  146. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  147. return err;
  148. }
  149. #define ext3_journal_get_undo_access(handle, bh) \
  150. __ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh))
  151. #define ext3_journal_get_write_access(handle, bh) \
  152. __ext3_journal_get_write_access(__FUNCTION__, (handle), (bh))
  153. #define ext3_journal_revoke(handle, blocknr, bh) \
  154. __ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh))
  155. #define ext3_journal_get_create_access(handle, bh) \
  156. __ext3_journal_get_create_access(__FUNCTION__, (handle), (bh))
  157. #define ext3_journal_dirty_metadata(handle, bh) \
  158. __ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh))
  159. #define ext3_journal_forget(handle, bh) \
  160. __ext3_journal_forget(__FUNCTION__, (handle), (bh))
  161. int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
  162. handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);
  163. int __ext3_journal_stop(const char *where, handle_t *handle);
  164. static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
  165. {
  166. return ext3_journal_start_sb(inode->i_sb, nblocks);
  167. }
  168. #define ext3_journal_stop(handle) \
  169. __ext3_journal_stop(__FUNCTION__, (handle))
  170. static inline handle_t *ext3_journal_current_handle(void)
  171. {
  172. return journal_current_handle();
  173. }
  174. static inline int ext3_journal_extend(handle_t *handle, int nblocks)
  175. {
  176. return journal_extend(handle, nblocks);
  177. }
  178. static inline int ext3_journal_restart(handle_t *handle, int nblocks)
  179. {
  180. return journal_restart(handle, nblocks);
  181. }
  182. static inline int ext3_journal_blocks_per_page(struct inode *inode)
  183. {
  184. return journal_blocks_per_page(inode);
  185. }
  186. static inline int ext3_journal_force_commit(journal_t *journal)
  187. {
  188. return journal_force_commit(journal);
  189. }
  190. /* super.c */
  191. int ext3_force_commit(struct super_block *sb);
  192. static inline int ext3_should_journal_data(struct inode *inode)
  193. {
  194. if (!S_ISREG(inode->i_mode))
  195. return 1;
  196. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
  197. return 1;
  198. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  199. return 1;
  200. return 0;
  201. }
  202. static inline int ext3_should_order_data(struct inode *inode)
  203. {
  204. if (!S_ISREG(inode->i_mode))
  205. return 0;
  206. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  207. return 0;
  208. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)
  209. return 1;
  210. return 0;
  211. }
  212. static inline int ext3_should_writeback_data(struct inode *inode)
  213. {
  214. if (!S_ISREG(inode->i_mode))
  215. return 0;
  216. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  217. return 0;
  218. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)
  219. return 1;
  220. return 0;
  221. }
  222. #endif /* _LINUX_EXT3_JBD_H */