ext4_jbd2.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Interface between ext4 and JBD
  3. */
  4. #include "ext4_jbd2.h"
  5. #include <trace/events/ext4.h>
  6. int __ext4_journal_get_write_access(const char *where, unsigned int line,
  7. handle_t *handle, struct buffer_head *bh)
  8. {
  9. int err = 0;
  10. if (ext4_handle_valid(handle)) {
  11. err = jbd2_journal_get_write_access(handle, bh);
  12. if (err)
  13. ext4_journal_abort_handle(where, line, __func__, bh,
  14. handle, err);
  15. }
  16. return err;
  17. }
  18. /*
  19. * The ext4 forget function must perform a revoke if we are freeing data
  20. * which has been journaled. Metadata (eg. indirect blocks) must be
  21. * revoked in all cases.
  22. *
  23. * "bh" may be NULL: a metadata block may have been freed from memory
  24. * but there may still be a record of it in the journal, and that record
  25. * still needs to be revoked.
  26. *
  27. * If the handle isn't valid we're not journaling, but we still need to
  28. * call into ext4_journal_revoke() to put the buffer head.
  29. */
  30. int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
  31. int is_metadata, struct inode *inode,
  32. struct buffer_head *bh, ext4_fsblk_t blocknr)
  33. {
  34. int err;
  35. might_sleep();
  36. trace_ext4_forget(inode, is_metadata, blocknr);
  37. BUFFER_TRACE(bh, "enter");
  38. jbd_debug(4, "forgetting bh %p: is_metadata = %d, mode %o, "
  39. "data mode %x\n",
  40. bh, is_metadata, inode->i_mode,
  41. test_opt(inode->i_sb, DATA_FLAGS));
  42. /* In the no journal case, we can just do a bforget and return */
  43. if (!ext4_handle_valid(handle)) {
  44. bforget(bh);
  45. return 0;
  46. }
  47. /* Never use the revoke function if we are doing full data
  48. * journaling: there is no need to, and a V1 superblock won't
  49. * support it. Otherwise, only skip the revoke on un-journaled
  50. * data blocks. */
  51. if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
  52. (!is_metadata && !ext4_should_journal_data(inode))) {
  53. if (bh) {
  54. BUFFER_TRACE(bh, "call jbd2_journal_forget");
  55. err = jbd2_journal_forget(handle, bh);
  56. if (err)
  57. ext4_journal_abort_handle(where, line, __func__,
  58. bh, handle, err);
  59. return err;
  60. }
  61. return 0;
  62. }
  63. /*
  64. * data!=journal && (is_metadata || should_journal_data(inode))
  65. */
  66. BUFFER_TRACE(bh, "call jbd2_journal_revoke");
  67. err = jbd2_journal_revoke(handle, blocknr, bh);
  68. if (err) {
  69. ext4_journal_abort_handle(where, line, __func__,
  70. bh, handle, err);
  71. __ext4_abort(inode->i_sb, where, line,
  72. "error %d when attempting revoke", err);
  73. }
  74. BUFFER_TRACE(bh, "exit");
  75. return err;
  76. }
  77. int __ext4_journal_get_create_access(const char *where, unsigned int line,
  78. handle_t *handle, struct buffer_head *bh)
  79. {
  80. int err = 0;
  81. if (ext4_handle_valid(handle)) {
  82. err = jbd2_journal_get_create_access(handle, bh);
  83. if (err)
  84. ext4_journal_abort_handle(where, line, __func__,
  85. bh, handle, err);
  86. }
  87. return err;
  88. }
  89. int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
  90. handle_t *handle, struct inode *inode,
  91. struct buffer_head *bh)
  92. {
  93. int err = 0;
  94. if (ext4_handle_valid(handle)) {
  95. err = jbd2_journal_dirty_metadata(handle, bh);
  96. if (err)
  97. ext4_journal_abort_handle(where, line, __func__,
  98. bh, handle, err);
  99. } else {
  100. if (inode)
  101. mark_buffer_dirty_inode(bh, inode);
  102. else
  103. mark_buffer_dirty(bh);
  104. if (inode && inode_needs_sync(inode)) {
  105. sync_dirty_buffer(bh);
  106. if (buffer_req(bh) && !buffer_uptodate(bh)) {
  107. struct ext4_super_block *es;
  108. es = EXT4_SB(inode->i_sb)->s_es;
  109. es->s_last_error_block =
  110. cpu_to_le64(bh->b_blocknr);
  111. ext4_error_inode(inode, where, line,
  112. bh->b_blocknr,
  113. "IO error syncing itable block");
  114. err = -EIO;
  115. }
  116. }
  117. }
  118. return err;
  119. }
  120. int __ext4_handle_dirty_super(const char *where, unsigned int line,
  121. handle_t *handle, struct super_block *sb)
  122. {
  123. struct buffer_head *bh = EXT4_SB(sb)->s_sbh;
  124. int err = 0;
  125. if (ext4_handle_valid(handle)) {
  126. err = jbd2_journal_dirty_metadata(handle, bh);
  127. if (err)
  128. ext4_journal_abort_handle(where, line, __func__,
  129. bh, handle, err);
  130. } else
  131. sb->s_dirt = 1;
  132. return err;
  133. }