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 | |
| 7 | int __ext4_journal_get_undo_access(const char *where, handle_t *handle, |
| 8 | struct buffer_head *bh) |
| 9 | { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 10 | int err = 0; |
| 11 | |
| 12 | if (ext4_handle_valid(handle)) { |
| 13 | err = jbd2_journal_get_undo_access(handle, bh); |
| 14 | if (err) |
| 15 | ext4_journal_abort_handle(where, __func__, bh, |
| 16 | handle, err); |
| 17 | } |
Andrew Morton | 8984d13 | 2006-12-06 20:37:15 -0800 | [diff] [blame] | 18 | return err; |
| 19 | } |
| 20 | |
| 21 | int __ext4_journal_get_write_access(const char *where, handle_t *handle, |
| 22 | struct buffer_head *bh) |
| 23 | { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 24 | int err = 0; |
| 25 | |
| 26 | if (ext4_handle_valid(handle)) { |
| 27 | err = jbd2_journal_get_write_access(handle, bh); |
| 28 | if (err) |
| 29 | ext4_journal_abort_handle(where, __func__, bh, |
| 30 | handle, err); |
| 31 | } |
Andrew Morton | 8984d13 | 2006-12-06 20:37:15 -0800 | [diff] [blame] | 32 | return err; |
| 33 | } |
| 34 | |
| 35 | int __ext4_journal_forget(const char *where, handle_t *handle, |
| 36 | struct buffer_head *bh) |
| 37 | { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 38 | int err = 0; |
| 39 | |
| 40 | if (ext4_handle_valid(handle)) { |
| 41 | err = jbd2_journal_forget(handle, bh); |
| 42 | if (err) |
| 43 | ext4_journal_abort_handle(where, __func__, bh, |
| 44 | handle, err); |
| 45 | } |
Curt Wohlgemuth | e6b5d30 | 2009-07-13 09:07:20 -0400 | [diff] [blame] | 46 | else |
Theodore Ts'o | c7acb4c | 2009-09-09 21:32:41 -0400 | [diff] [blame] | 47 | bforget(bh); |
Andrew Morton | 8984d13 | 2006-12-06 20:37:15 -0800 | [diff] [blame] | 48 | return err; |
| 49 | } |
| 50 | |
| 51 | int __ext4_journal_revoke(const char *where, handle_t *handle, |
| 52 | ext4_fsblk_t blocknr, struct buffer_head *bh) |
| 53 | { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 54 | int err = 0; |
| 55 | |
| 56 | if (ext4_handle_valid(handle)) { |
| 57 | err = jbd2_journal_revoke(handle, blocknr, bh); |
| 58 | if (err) |
| 59 | ext4_journal_abort_handle(where, __func__, bh, |
| 60 | handle, err); |
| 61 | } |
Curt Wohlgemuth | e6b5d30 | 2009-07-13 09:07:20 -0400 | [diff] [blame] | 62 | else |
Theodore Ts'o | c7acb4c | 2009-09-09 21:32:41 -0400 | [diff] [blame] | 63 | bforget(bh); |
Andrew Morton | 8984d13 | 2006-12-06 20:37:15 -0800 | [diff] [blame] | 64 | return err; |
| 65 | } |
| 66 | |
| 67 | int __ext4_journal_get_create_access(const char *where, |
| 68 | handle_t *handle, struct buffer_head *bh) |
| 69 | { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 70 | int err = 0; |
| 71 | |
| 72 | if (ext4_handle_valid(handle)) { |
| 73 | err = jbd2_journal_get_create_access(handle, bh); |
| 74 | if (err) |
| 75 | ext4_journal_abort_handle(where, __func__, bh, |
| 76 | handle, err); |
| 77 | } |
Andrew Morton | 8984d13 | 2006-12-06 20:37:15 -0800 | [diff] [blame] | 78 | return err; |
| 79 | } |
| 80 | |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 81 | int __ext4_handle_dirty_metadata(const char *where, handle_t *handle, |
| 82 | struct inode *inode, struct buffer_head *bh) |
Andrew Morton | 8984d13 | 2006-12-06 20:37:15 -0800 | [diff] [blame] | 83 | { |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 84 | int err = 0; |
| 85 | |
| 86 | if (ext4_handle_valid(handle)) { |
| 87 | err = jbd2_journal_dirty_metadata(handle, bh); |
| 88 | if (err) |
| 89 | ext4_journal_abort_handle(where, __func__, bh, |
| 90 | handle, err); |
| 91 | } else { |
Theodore Ts'o | fe188c0 | 2009-09-12 13:41:55 -0400 | [diff] [blame] | 92 | if (inode && bh) |
| 93 | mark_buffer_dirty_inode(bh, inode); |
| 94 | else |
| 95 | mark_buffer_dirty(bh); |
Frank Mayhar | 0390131 | 2009-01-07 00:06:22 -0500 | [diff] [blame] | 96 | if (inode && inode_needs_sync(inode)) { |
| 97 | sync_dirty_buffer(bh); |
| 98 | if (buffer_req(bh) && !buffer_uptodate(bh)) { |
| 99 | ext4_error(inode->i_sb, __func__, |
| 100 | "IO error syncing inode, " |
| 101 | "inode=%lu, block=%llu", |
| 102 | inode->i_ino, |
| 103 | (unsigned long long) bh->b_blocknr); |
| 104 | err = -EIO; |
| 105 | } |
| 106 | } |
| 107 | } |
Andrew Morton | 8984d13 | 2006-12-06 20:37:15 -0800 | [diff] [blame] | 108 | return err; |
| 109 | } |