ext3_jbd.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 (EXT3_SINGLEDATA_TRANS_BLOCKS + \
  37. EXT3_XATTR_TRANS_BLOCKS - 2 + \
  38. 2*EXT3_QUOTA_TRANS_BLOCKS)
  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 (2 * EXT3_DATA_TRANS_BLOCKS + 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 2
  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 (DQUOT_MAX_WRITES*\
  64. (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3)
  65. #else
  66. #define EXT3_QUOTA_TRANS_BLOCKS 0
  67. #define EXT3_QUOTA_INIT_BLOCKS 0
  68. #endif
  69. int
  70. ext3_mark_iloc_dirty(handle_t *handle,
  71. struct inode *inode,
  72. struct ext3_iloc *iloc);
  73. /*
  74. * On success, We end up with an outstanding reference count against
  75. * iloc->bh. This _must_ be cleaned up later.
  76. */
  77. int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
  78. struct ext3_iloc *iloc);
  79. int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);
  80. /*
  81. * Wrapper functions with which ext3 calls into JBD. The intent here is
  82. * to allow these to be turned into appropriate stubs so ext3 can control
  83. * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't
  84. * been done yet.
  85. */
  86. void ext3_journal_abort_handle(const char *caller, const char *err_fn,
  87. struct buffer_head *bh, handle_t *handle, int err);
  88. static inline int
  89. __ext3_journal_get_undo_access(const char *where, handle_t *handle,
  90. struct buffer_head *bh)
  91. {
  92. int err = journal_get_undo_access(handle, bh);
  93. if (err)
  94. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  95. return err;
  96. }
  97. static inline int
  98. __ext3_journal_get_write_access(const char *where, handle_t *handle,
  99. struct buffer_head *bh)
  100. {
  101. int err = journal_get_write_access(handle, bh);
  102. if (err)
  103. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  104. return err;
  105. }
  106. static inline void
  107. ext3_journal_release_buffer(handle_t *handle, struct buffer_head *bh)
  108. {
  109. journal_release_buffer(handle, bh);
  110. }
  111. static inline int
  112. __ext3_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh)
  113. {
  114. int err = journal_forget(handle, bh);
  115. if (err)
  116. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  117. return err;
  118. }
  119. static inline int
  120. __ext3_journal_revoke(const char *where, handle_t *handle,
  121. unsigned long blocknr, struct buffer_head *bh)
  122. {
  123. int err = journal_revoke(handle, blocknr, bh);
  124. if (err)
  125. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  126. return err;
  127. }
  128. static inline int
  129. __ext3_journal_get_create_access(const char *where,
  130. handle_t *handle, struct buffer_head *bh)
  131. {
  132. int err = journal_get_create_access(handle, bh);
  133. if (err)
  134. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  135. return err;
  136. }
  137. static inline int
  138. __ext3_journal_dirty_metadata(const char *where,
  139. handle_t *handle, struct buffer_head *bh)
  140. {
  141. int err = journal_dirty_metadata(handle, bh);
  142. if (err)
  143. ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
  144. return err;
  145. }
  146. #define ext3_journal_get_undo_access(handle, bh) \
  147. __ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh))
  148. #define ext3_journal_get_write_access(handle, bh) \
  149. __ext3_journal_get_write_access(__FUNCTION__, (handle), (bh))
  150. #define ext3_journal_revoke(handle, blocknr, bh) \
  151. __ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh))
  152. #define ext3_journal_get_create_access(handle, bh) \
  153. __ext3_journal_get_create_access(__FUNCTION__, (handle), (bh))
  154. #define ext3_journal_dirty_metadata(handle, bh) \
  155. __ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh))
  156. #define ext3_journal_forget(handle, bh) \
  157. __ext3_journal_forget(__FUNCTION__, (handle), (bh))
  158. int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh);
  159. handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks);
  160. int __ext3_journal_stop(const char *where, handle_t *handle);
  161. static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
  162. {
  163. return ext3_journal_start_sb(inode->i_sb, nblocks);
  164. }
  165. #define ext3_journal_stop(handle) \
  166. __ext3_journal_stop(__FUNCTION__, (handle))
  167. static inline handle_t *ext3_journal_current_handle(void)
  168. {
  169. return journal_current_handle();
  170. }
  171. static inline int ext3_journal_extend(handle_t *handle, int nblocks)
  172. {
  173. return journal_extend(handle, nblocks);
  174. }
  175. static inline int ext3_journal_restart(handle_t *handle, int nblocks)
  176. {
  177. return journal_restart(handle, nblocks);
  178. }
  179. static inline int ext3_journal_blocks_per_page(struct inode *inode)
  180. {
  181. return journal_blocks_per_page(inode);
  182. }
  183. static inline int ext3_journal_force_commit(journal_t *journal)
  184. {
  185. return journal_force_commit(journal);
  186. }
  187. /* super.c */
  188. int ext3_force_commit(struct super_block *sb);
  189. static inline int ext3_should_journal_data(struct inode *inode)
  190. {
  191. if (!S_ISREG(inode->i_mode))
  192. return 1;
  193. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
  194. return 1;
  195. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  196. return 1;
  197. return 0;
  198. }
  199. static inline int ext3_should_order_data(struct inode *inode)
  200. {
  201. if (!S_ISREG(inode->i_mode))
  202. return 0;
  203. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  204. return 0;
  205. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA)
  206. return 1;
  207. return 0;
  208. }
  209. static inline int ext3_should_writeback_data(struct inode *inode)
  210. {
  211. if (!S_ISREG(inode->i_mode))
  212. return 0;
  213. if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL)
  214. return 0;
  215. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA)
  216. return 1;
  217. return 0;
  218. }
  219. #endif /* _LINUX_EXT3_JBD_H */