ext3_jbd.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. EXT3_MAXQUOTAS_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) (EXT3_MAXQUOTAS_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. #define EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_TRANS_BLOCKS(sb))
  73. #define EXT3_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_INIT_BLOCKS(sb))
  74. #define EXT3_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_DEL_BLOCKS(sb))
  75. int
  76. ext3_mark_iloc_dirty(handle_t *handle,
  77. struct inode *inode,
  78. struct ext3_iloc *iloc);
  79. /*
  80. * On success, We end up with an outstanding reference count against
  81. * iloc->bh. This _must_ be cleaned up later.
  82. */
  83. int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
  84. struct ext3_iloc *iloc);
  85. int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);
  86. /*
  87. * Wrapper functions with which ext3 calls into JBD. The intent here is
  88. * to allow these to be turned into appropriate stubs so ext3 can control
  89. * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't
  90. * been done yet.
  91. */
  92. static inline void ext3_journal_release_buffer(handle_t *handle,
  93. struct buffer_head *bh)
  94. {
  95. journal_release_buffer(handle, bh);
  96. }
  97. void ext3_journal_abort_handle(const char *caller, const char *err_fn,
  98. struct buffer_head *bh, handle_t *handle, int err);
  99. int __ext3_journal_get_undo_access(const char *where, handle_t *handle,
  100. struct buffer_head *bh);
  101. int __ext3_journal_get_write_access(const char *where, handle_t *handle,
  102. struct buffer_head *bh);
  103. int __ext3_journal_forget(const char *where, handle_t *handle,
  104. struct buffer_head *bh);
  105. int __ext3_journal_revoke(const char *where, handle_t *handle,
  106. unsigned long blocknr, struct buffer_head *bh);
  107. int __ext3_journal_get_create_access(const char *where,
  108. handle_t *handle, struct buffer_head *bh);
  109. int __ext3_journal_dirty_metadata(const char *where,
  110. handle_t *handle, struct buffer_head *bh);
  111. #define ext3_journal_get_undo_access(handle, bh) \
  112. __ext3_journal_get_undo_access(__func__, (handle), (bh))
  113. #define ext3_journal_get_write_access(handle, bh) \
  114. __ext3_journal_get_write_access(__func__, (handle), (bh))
  115. #define ext3_journal_revoke(handle, blocknr, bh) \
  116. __ext3_journal_revoke(__func__, (handle), (blocknr), (bh))
  117. #define ext3_journal_get_create_access(handle, bh) \
  118. __ext3_journal_get_create_access(__func__, (handle), (bh))
  119. #define ext3_journal_dirty_metadata(handle, bh) \
  120. __ext3_journal_dirty_metadata(__func__, (handle), (bh))
  121. #define ext3_journal_forget(handle, bh) \
  122. __ext3_journal_forget(__func__, (handle), (bh))
  123. int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
  124. handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);
  125. int __ext3_journal_stop(const char *where, handle_t *handle);
  126. static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
  127. {
  128. return ext3_journal_start_sb(inode->i_sb, nblocks);
  129. }
  130. #define ext3_journal_stop(handle) \
  131. __ext3_journal_stop(__func__, (handle))
  132. static inline handle_t *ext3_journal_current_handle(void)
  133. {
  134. return journal_current_handle();
  135. }
  136. static inline int ext3_journal_extend(handle_t *handle, int nblocks)
  137. {
  138. return journal_extend(handle, nblocks);
  139. }
  140. static inline int ext3_journal_restart(handle_t *handle, int nblocks)
  141. {
  142. return journal_restart(handle, nblocks);
  143. }
  144. static inline int ext3_journal_blocks_per_page(struct inode *inode)
  145. {
  146. return journal_blocks_per_page(inode);
  147. }
  148. static inline int ext3_journal_force_commit(journal_t *journal)
  149. {
  150. return journal_force_commit(journal);
  151. }
  152. /* super.c */
  153. int ext3_force_commit(struct super_block *sb);
  154. static inline int ext3_should_journal_data(struct inode *inode)
  155. {
  156. if (!S_ISREG(inode->i_mode))
  157. return 1;
  158. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
  159. return 1;
  160. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  161. return 1;
  162. return 0;
  163. }
  164. static inline int ext3_should_order_data(struct inode *inode)
  165. {
  166. if (!S_ISREG(inode->i_mode))
  167. return 0;
  168. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  169. return 0;
  170. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)
  171. return 1;
  172. return 0;
  173. }
  174. static inline int ext3_should_writeback_data(struct inode *inode)
  175. {
  176. if (!S_ISREG(inode->i_mode))
  177. return 0;
  178. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  179. return 0;
  180. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)
  181. return 1;
  182. return 0;
  183. }
  184. #endif /* _LINUX_EXT3_JBD_H */