Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 15 | #ifndef _LINUX_EXT3_JBD_H |
| 16 | #define _LINUX_EXT3_JBD_H |
| 17 | |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/jbd.h> |
| 20 | #include <linux/ext3_fs.h> |
| 21 | |
| 22 | #define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal) |
| 23 | |
| 24 | /* Define the number of blocks we need to account to a transaction to |
| 25 | * modify one block of data. |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 26 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * We may have to touch one inode, one bitmap buffer, up to three |
| 28 | * indirection blocks, the group and superblock summaries, and the data |
| 29 | * block to complete the transaction. */ |
| 30 | |
| 31 | #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U |
| 32 | |
| 33 | /* Extended attribute operations touch at most two data buffers, |
| 34 | * two bitmap buffers, and two group summaries, in addition to the inode |
| 35 | * and the superblock, which are already accounted for. */ |
| 36 | |
| 37 | #define EXT3_XATTR_TRANS_BLOCKS 6U |
| 38 | |
| 39 | /* Define the minimum size for a transaction which modifies data. This |
| 40 | * needs to take into account the fact that we may end up modifying two |
| 41 | * quota files too (one for the group, one for the user quota). The |
| 42 | * superblock only gets updated once, of course, so don't bother |
| 43 | * counting that again for the quota updates. */ |
| 44 | |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 45 | #define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | EXT3_XATTR_TRANS_BLOCKS - 2 + \ |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 47 | 2*EXT3_QUOTA_TRANS_BLOCKS(sb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | /* Delete operations potentially hit one directory's namespace plus an |
| 50 | * entire inode, plus arbitrary amounts of bitmap/indirection data. Be |
| 51 | * generous. We can grow the delete transaction later if necessary. */ |
| 52 | |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 53 | #define EXT3_DELETE_TRANS_BLOCKS(sb) (2 * EXT3_DATA_TRANS_BLOCKS(sb) + 64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* Define an arbitrary limit for the amount of data we will anticipate |
| 56 | * writing to any given transaction. For unbounded transactions such as |
| 57 | * write(2) and truncate(2) we can write more than this, but we always |
| 58 | * start off at the maximum transaction size and grow the transaction |
| 59 | * optimistically as we go. */ |
| 60 | |
| 61 | #define EXT3_MAX_TRANS_DATA 64U |
| 62 | |
| 63 | /* We break up a large truncate or write transaction once the handle's |
| 64 | * buffer credits gets this low, we need either to extend the |
| 65 | * transaction or to start a new one. Reserve enough space here for |
| 66 | * inode, bitmap, superblock, group and indirection updates for at least |
| 67 | * one block, plus two quota updates. Quota allocations are not |
| 68 | * needed. */ |
| 69 | |
| 70 | #define EXT3_RESERVE_TRANS_BLOCKS 12U |
| 71 | |
| 72 | #define EXT3_INDEX_EXTRA_TRANS_BLOCKS 8 |
| 73 | |
| 74 | #ifdef CONFIG_QUOTA |
| 75 | /* Amount of blocks needed for quota update - we know that the structure was |
| 76 | * allocated so we need to update only inode+data */ |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 77 | #define EXT3_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* Amount of blocks needed for quota insert/delete - we do some block writes |
| 79 | * but inode, sb and group updates are done only once */ |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 80 | #define EXT3_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\ |
| 81 | (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0) |
| 82 | #define EXT3_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\ |
| 83 | (EXT3_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #else |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 85 | #define EXT3_QUOTA_TRANS_BLOCKS(sb) 0 |
| 86 | #define EXT3_QUOTA_INIT_BLOCKS(sb) 0 |
| 87 | #define EXT3_QUOTA_DEL_BLOCKS(sb) 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif |
| 89 | |
| 90 | int |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 91 | ext3_mark_iloc_dirty(handle_t *handle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | struct inode *inode, |
| 93 | struct ext3_iloc *iloc); |
| 94 | |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 95 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | * On success, We end up with an outstanding reference count against |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 97 | * iloc->bh. This _must_ be cleaned up later. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | */ |
| 99 | |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 100 | int ext3_reserve_inode_write(handle_t *handle, struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | struct ext3_iloc *iloc); |
| 102 | |
| 103 | int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode); |
| 104 | |
| 105 | /* |
| 106 | * Wrapper functions with which ext3 calls into JBD. The intent here is |
| 107 | * to allow these to be turned into appropriate stubs so ext3 can control |
| 108 | * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't |
| 109 | * been done yet. |
| 110 | */ |
| 111 | |
Andrew Morton | 3a229b3 | 2006-12-06 20:37:14 -0800 | [diff] [blame] | 112 | static inline void ext3_journal_release_buffer(handle_t *handle, |
| 113 | struct buffer_head *bh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 115 | journal_release_buffer(handle, bh); |
| 116 | } |
| 117 | |
Andrew Morton | 3a229b3 | 2006-12-06 20:37:14 -0800 | [diff] [blame] | 118 | void ext3_journal_abort_handle(const char *caller, const char *err_fn, |
| 119 | struct buffer_head *bh, handle_t *handle, int err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Andrew Morton | 3a229b3 | 2006-12-06 20:37:14 -0800 | [diff] [blame] | 121 | int __ext3_journal_get_undo_access(const char *where, handle_t *handle, |
| 122 | struct buffer_head *bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Andrew Morton | 3a229b3 | 2006-12-06 20:37:14 -0800 | [diff] [blame] | 124 | int __ext3_journal_get_write_access(const char *where, handle_t *handle, |
| 125 | struct buffer_head *bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Andrew Morton | 3a229b3 | 2006-12-06 20:37:14 -0800 | [diff] [blame] | 127 | int __ext3_journal_forget(const char *where, handle_t *handle, |
| 128 | struct buffer_head *bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Andrew Morton | 3a229b3 | 2006-12-06 20:37:14 -0800 | [diff] [blame] | 130 | int __ext3_journal_revoke(const char *where, handle_t *handle, |
| 131 | unsigned long blocknr, struct buffer_head *bh); |
| 132 | |
| 133 | int __ext3_journal_get_create_access(const char *where, |
| 134 | handle_t *handle, struct buffer_head *bh); |
| 135 | |
| 136 | int __ext3_journal_dirty_metadata(const char *where, |
| 137 | handle_t *handle, struct buffer_head *bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | #define ext3_journal_get_undo_access(handle, bh) \ |
| 140 | __ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh)) |
| 141 | #define ext3_journal_get_write_access(handle, bh) \ |
| 142 | __ext3_journal_get_write_access(__FUNCTION__, (handle), (bh)) |
| 143 | #define ext3_journal_revoke(handle, blocknr, bh) \ |
| 144 | __ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh)) |
| 145 | #define ext3_journal_get_create_access(handle, bh) \ |
| 146 | __ext3_journal_get_create_access(__FUNCTION__, (handle), (bh)) |
| 147 | #define ext3_journal_dirty_metadata(handle, bh) \ |
| 148 | __ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh)) |
| 149 | #define ext3_journal_forget(handle, bh) \ |
| 150 | __ext3_journal_forget(__FUNCTION__, (handle), (bh)) |
| 151 | |
| 152 | int ext3_journal_dirty_data(handle_t *handle, struct buffer_head *bh); |
| 153 | |
| 154 | handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks); |
| 155 | int __ext3_journal_stop(const char *where, handle_t *handle); |
| 156 | |
| 157 | static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks) |
| 158 | { |
| 159 | return ext3_journal_start_sb(inode->i_sb, nblocks); |
| 160 | } |
| 161 | |
| 162 | #define ext3_journal_stop(handle) \ |
| 163 | __ext3_journal_stop(__FUNCTION__, (handle)) |
| 164 | |
| 165 | static inline handle_t *ext3_journal_current_handle(void) |
| 166 | { |
| 167 | return journal_current_handle(); |
| 168 | } |
| 169 | |
| 170 | static inline int ext3_journal_extend(handle_t *handle, int nblocks) |
| 171 | { |
| 172 | return journal_extend(handle, nblocks); |
| 173 | } |
| 174 | |
| 175 | static inline int ext3_journal_restart(handle_t *handle, int nblocks) |
| 176 | { |
| 177 | return journal_restart(handle, nblocks); |
| 178 | } |
| 179 | |
| 180 | static inline int ext3_journal_blocks_per_page(struct inode *inode) |
| 181 | { |
| 182 | return journal_blocks_per_page(inode); |
| 183 | } |
| 184 | |
| 185 | static inline int ext3_journal_force_commit(journal_t *journal) |
| 186 | { |
| 187 | return journal_force_commit(journal); |
| 188 | } |
| 189 | |
| 190 | /* super.c */ |
| 191 | int ext3_force_commit(struct super_block *sb); |
| 192 | |
| 193 | static inline int ext3_should_journal_data(struct inode *inode) |
| 194 | { |
| 195 | if (!S_ISREG(inode->i_mode)) |
| 196 | return 1; |
| 197 | if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA) |
| 198 | return 1; |
| 199 | if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) |
| 200 | return 1; |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static inline int ext3_should_order_data(struct inode *inode) |
| 205 | { |
| 206 | if (!S_ISREG(inode->i_mode)) |
| 207 | return 0; |
| 208 | if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) |
| 209 | return 0; |
| 210 | if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA) |
| 211 | return 1; |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static inline int ext3_should_writeback_data(struct inode *inode) |
| 216 | { |
| 217 | if (!S_ISREG(inode->i_mode)) |
| 218 | return 0; |
| 219 | if (EXT3_I(inode)->i_flags & EXT3_JOURNAL_DATA_FL) |
| 220 | return 0; |
| 221 | if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_WRITEBACK_DATA) |
| 222 | return 1; |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | #endif /* _LINUX_EXT3_JBD_H */ |