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