ext3_jbd.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. static inline void ext3_journal_release_buffer(handle_t *handle,
  90. struct buffer_head *bh)
  91. {
  92. journal_release_buffer(handle, bh);
  93. }
  94. void ext3_journal_abort_handle(const char *caller, const char *err_fn,
  95. struct buffer_head *bh, handle_t *handle, int err);
  96. int __ext3_journal_get_undo_access(const char *where, handle_t *handle,
  97. struct buffer_head *bh);
  98. int __ext3_journal_get_write_access(const char *where, handle_t *handle,
  99. struct buffer_head *bh);
  100. int __ext3_journal_forget(const char *where, handle_t *handle,
  101. struct buffer_head *bh);
  102. int __ext3_journal_revoke(const char *where, handle_t *handle,
  103. unsigned long blocknr, struct buffer_head *bh);
  104. int __ext3_journal_get_create_access(const char *where,
  105. handle_t *handle, struct buffer_head *bh);
  106. int __ext3_journal_dirty_metadata(const char *where,
  107. handle_t *handle, struct buffer_head *bh);
  108. #define ext3_journal_get_undo_access(handle, bh) \
  109. __ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh))
  110. #define ext3_journal_get_write_access(handle, bh) \
  111. __ext3_journal_get_write_access(__FUNCTION__, (handle), (bh))
  112. #define ext3_journal_revoke(handle, blocknr, bh) \
  113. __ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh))
  114. #define ext3_journal_get_create_access(handle, bh) \
  115. __ext3_journal_get_create_access(__FUNCTION__, (handle), (bh))
  116. #define ext3_journal_dirty_metadata(handle, bh) \
  117. __ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh))
  118. #define ext3_journal_forget(handle, bh) \
  119. __ext3_journal_forget(__FUNCTION__, (handle), (bh))
  120. int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
  121. handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);
  122. int __ext3_journal_stop(const char *where, handle_t *handle);
  123. static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
  124. {
  125. return ext3_journal_start_sb(inode->i_sb, nblocks);
  126. }
  127. #define ext3_journal_stop(handle) \
  128. __ext3_journal_stop(__FUNCTION__, (handle))
  129. static inline handle_t *ext3_journal_current_handle(void)
  130. {
  131. return journal_current_handle();
  132. }
  133. static inline int ext3_journal_extend(handle_t *handle, int nblocks)
  134. {
  135. return journal_extend(handle, nblocks);
  136. }
  137. static inline int ext3_journal_restart(handle_t *handle, int nblocks)
  138. {
  139. return journal_restart(handle, nblocks);
  140. }
  141. static inline int ext3_journal_blocks_per_page(struct inode *inode)
  142. {
  143. return journal_blocks_per_page(inode);
  144. }
  145. static inline int ext3_journal_force_commit(journal_t *journal)
  146. {
  147. return journal_force_commit(journal);
  148. }
  149. /* super.c */
  150. int ext3_force_commit(struct super_block *sb);
  151. static inline int ext3_should_journal_data(struct inode *inode)
  152. {
  153. if (!S_ISREG(inode->i_mode))
  154. return 1;
  155. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
  156. return 1;
  157. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  158. return 1;
  159. return 0;
  160. }
  161. static inline int ext3_should_order_data(struct inode *inode)
  162. {
  163. if (!S_ISREG(inode->i_mode))
  164. return 0;
  165. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  166. return 0;
  167. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)
  168. return 1;
  169. return 0;
  170. }
  171. static inline int ext3_should_writeback_data(struct inode *inode)
  172. {
  173. if (!S_ISREG(inode->i_mode))
  174. return 0;
  175. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  176. return 0;
  177. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)
  178. return 1;
  179. return 0;
  180. }
  181. #endif /* _LINUX_EXT3_JBD_H */