]>
Commit | Line | Data |
---|---|---|
ac27a0ec | 1 | /* |
617ba13b | 2 | * linux/include/linux/ext4_jbd.h |
ac27a0ec DK |
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 | * | |
617ba13b | 12 | * Ext4-specific journaling extensions. |
ac27a0ec DK |
13 | */ |
14 | ||
617ba13b MC |
15 | #ifndef _LINUX_EXT4_JBD_H |
16 | #define _LINUX_EXT4_JBD_H | |
ac27a0ec DK |
17 | |
18 | #include <linux/fs.h> | |
19 | #include <linux/jbd.h> | |
617ba13b | 20 | #include <linux/ext4_fs.h> |
ac27a0ec | 21 | |
617ba13b | 22 | #define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal) |
ac27a0ec DK |
23 | |
24 | /* Define the number of blocks we need to account to a transaction to | |
25 | * modify one block of data. | |
26 | * | |
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 | ||
617ba13b | 31 | #define EXT4_SINGLEDATA_TRANS_BLOCKS 8U |
ac27a0ec DK |
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 | ||
617ba13b | 37 | #define EXT4_XATTR_TRANS_BLOCKS 6U |
ac27a0ec DK |
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 | ||
617ba13b MC |
45 | #define EXT4_DATA_TRANS_BLOCKS(sb) (EXT4_SINGLEDATA_TRANS_BLOCKS + \ |
46 | EXT4_XATTR_TRANS_BLOCKS - 2 + \ | |
47 | 2*EXT4_QUOTA_TRANS_BLOCKS(sb)) | |
ac27a0ec DK |
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 | ||
617ba13b | 53 | #define EXT4_DELETE_TRANS_BLOCKS(sb) (2 * EXT4_DATA_TRANS_BLOCKS(sb) + 64) |
ac27a0ec DK |
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 | ||
617ba13b | 61 | #define EXT4_MAX_TRANS_DATA 64U |
ac27a0ec DK |
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 | ||
617ba13b | 70 | #define EXT4_RESERVE_TRANS_BLOCKS 12U |
ac27a0ec | 71 | |
617ba13b | 72 | #define EXT4_INDEX_EXTRA_TRANS_BLOCKS 8 |
ac27a0ec DK |
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 */ | |
617ba13b | 77 | #define EXT4_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0) |
ac27a0ec DK |
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 */ | |
617ba13b MC |
80 | #define EXT4_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\ |
81 | (EXT4_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_INIT_REWRITE) : 0) | |
82 | #define EXT4_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\ | |
83 | (EXT4_SINGLEDATA_TRANS_BLOCKS-3)+3+DQUOT_DEL_REWRITE) : 0) | |
ac27a0ec | 84 | #else |
617ba13b MC |
85 | #define EXT4_QUOTA_TRANS_BLOCKS(sb) 0 |
86 | #define EXT4_QUOTA_INIT_BLOCKS(sb) 0 | |
87 | #define EXT4_QUOTA_DEL_BLOCKS(sb) 0 | |
ac27a0ec DK |
88 | #endif |
89 | ||
90 | int | |
617ba13b | 91 | ext4_mark_iloc_dirty(handle_t *handle, |
ac27a0ec | 92 | struct inode *inode, |
617ba13b | 93 | struct ext4_iloc *iloc); |
ac27a0ec DK |
94 | |
95 | /* | |
96 | * On success, We end up with an outstanding reference count against | |
97 | * iloc->bh. This _must_ be cleaned up later. | |
98 | */ | |
99 | ||
617ba13b MC |
100 | int ext4_reserve_inode_write(handle_t *handle, struct inode *inode, |
101 | struct ext4_iloc *iloc); | |
ac27a0ec | 102 | |
617ba13b | 103 | int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode); |
ac27a0ec DK |
104 | |
105 | /* | |
617ba13b MC |
106 | * Wrapper functions with which ext4 calls into JBD. The intent here is |
107 | * to allow these to be turned into appropriate stubs so ext4 can control | |
108 | * ext2 filesystems, so ext2+ext4 systems only nee one fs. This work hasn't | |
ac27a0ec DK |
109 | * been done yet. |
110 | */ | |
111 | ||
617ba13b | 112 | void ext4_journal_abort_handle(const char *caller, const char *err_fn, |
ac27a0ec DK |
113 | struct buffer_head *bh, handle_t *handle, int err); |
114 | ||
115 | static inline int | |
617ba13b | 116 | __ext4_journal_get_undo_access(const char *where, handle_t *handle, |
ac27a0ec DK |
117 | struct buffer_head *bh) |
118 | { | |
119 | int err = journal_get_undo_access(handle, bh); | |
120 | if (err) | |
617ba13b | 121 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); |
ac27a0ec DK |
122 | return err; |
123 | } | |
124 | ||
125 | static inline int | |
617ba13b | 126 | __ext4_journal_get_write_access(const char *where, handle_t *handle, |
ac27a0ec DK |
127 | struct buffer_head *bh) |
128 | { | |
129 | int err = journal_get_write_access(handle, bh); | |
130 | if (err) | |
617ba13b | 131 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); |
ac27a0ec DK |
132 | return err; |
133 | } | |
134 | ||
135 | static inline void | |
617ba13b | 136 | ext4_journal_release_buffer(handle_t *handle, struct buffer_head *bh) |
ac27a0ec DK |
137 | { |
138 | journal_release_buffer(handle, bh); | |
139 | } | |
140 | ||
141 | static inline int | |
617ba13b | 142 | __ext4_journal_forget(const char *where, handle_t *handle, struct buffer_head *bh) |
ac27a0ec DK |
143 | { |
144 | int err = journal_forget(handle, bh); | |
145 | if (err) | |
617ba13b | 146 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); |
ac27a0ec DK |
147 | return err; |
148 | } | |
149 | ||
150 | static inline int | |
617ba13b | 151 | __ext4_journal_revoke(const char *where, handle_t *handle, |
ac27a0ec DK |
152 | unsigned long blocknr, struct buffer_head *bh) |
153 | { | |
154 | int err = journal_revoke(handle, blocknr, bh); | |
155 | if (err) | |
617ba13b | 156 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); |
ac27a0ec DK |
157 | return err; |
158 | } | |
159 | ||
160 | static inline int | |
617ba13b | 161 | __ext4_journal_get_create_access(const char *where, |
ac27a0ec DK |
162 | handle_t *handle, struct buffer_head *bh) |
163 | { | |
164 | int err = journal_get_create_access(handle, bh); | |
165 | if (err) | |
617ba13b | 166 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); |
ac27a0ec DK |
167 | return err; |
168 | } | |
169 | ||
170 | static inline int | |
617ba13b | 171 | __ext4_journal_dirty_metadata(const char *where, |
ac27a0ec DK |
172 | handle_t *handle, struct buffer_head *bh) |
173 | { | |
174 | int err = journal_dirty_metadata(handle, bh); | |
175 | if (err) | |
617ba13b | 176 | ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); |
ac27a0ec DK |
177 | return err; |
178 | } | |
179 | ||
180 | ||
617ba13b MC |
181 | #define ext4_journal_get_undo_access(handle, bh) \ |
182 | __ext4_journal_get_undo_access(__FUNCTION__, (handle), (bh)) | |
183 | #define ext4_journal_get_write_access(handle, bh) \ | |
184 | __ext4_journal_get_write_access(__FUNCTION__, (handle), (bh)) | |
185 | #define ext4_journal_revoke(handle, blocknr, bh) \ | |
186 | __ext4_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh)) | |
187 | #define ext4_journal_get_create_access(handle, bh) \ | |
188 | __ext4_journal_get_create_access(__FUNCTION__, (handle), (bh)) | |
189 | #define ext4_journal_dirty_metadata(handle, bh) \ | |
190 | __ext4_journal_dirty_metadata(__FUNCTION__, (handle), (bh)) | |
191 | #define ext4_journal_forget(handle, bh) \ | |
192 | __ext4_journal_forget(__FUNCTION__, (handle), (bh)) | |
ac27a0ec | 193 | |
617ba13b | 194 | int ext4_journal_dirty_data(handle_t *handle, struct buffer_head *bh); |
ac27a0ec | 195 | |
617ba13b MC |
196 | handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks); |
197 | int __ext4_journal_stop(const char *where, handle_t *handle); | |
ac27a0ec | 198 | |
617ba13b | 199 | static inline handle_t *ext4_journal_start(struct inode *inode, int nblocks) |
ac27a0ec | 200 | { |
617ba13b | 201 | return ext4_journal_start_sb(inode->i_sb, nblocks); |
ac27a0ec DK |
202 | } |
203 | ||
617ba13b MC |
204 | #define ext4_journal_stop(handle) \ |
205 | __ext4_journal_stop(__FUNCTION__, (handle)) | |
ac27a0ec | 206 | |
617ba13b | 207 | static inline handle_t *ext4_journal_current_handle(void) |
ac27a0ec DK |
208 | { |
209 | return journal_current_handle(); | |
210 | } | |
211 | ||
617ba13b | 212 | static inline int ext4_journal_extend(handle_t *handle, int nblocks) |
ac27a0ec DK |
213 | { |
214 | return journal_extend(handle, nblocks); | |
215 | } | |
216 | ||
617ba13b | 217 | static inline int ext4_journal_restart(handle_t *handle, int nblocks) |
ac27a0ec DK |
218 | { |
219 | return journal_restart(handle, nblocks); | |
220 | } | |
221 | ||
617ba13b | 222 | static inline int ext4_journal_blocks_per_page(struct inode *inode) |
ac27a0ec DK |
223 | { |
224 | return journal_blocks_per_page(inode); | |
225 | } | |
226 | ||
617ba13b | 227 | static inline int ext4_journal_force_commit(journal_t *journal) |
ac27a0ec DK |
228 | { |
229 | return journal_force_commit(journal); | |
230 | } | |
231 | ||
232 | /* super.c */ | |
617ba13b | 233 | int ext4_force_commit(struct super_block *sb); |
ac27a0ec | 234 | |
617ba13b | 235 | static inline int ext4_should_journal_data(struct inode *inode) |
ac27a0ec DK |
236 | { |
237 | if (!S_ISREG(inode->i_mode)) | |
238 | return 1; | |
617ba13b | 239 | if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) |
ac27a0ec | 240 | return 1; |
617ba13b | 241 | if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) |
ac27a0ec DK |
242 | return 1; |
243 | return 0; | |
244 | } | |
245 | ||
617ba13b | 246 | static inline int ext4_should_order_data(struct inode *inode) |
ac27a0ec DK |
247 | { |
248 | if (!S_ISREG(inode->i_mode)) | |
249 | return 0; | |
617ba13b | 250 | if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) |
ac27a0ec | 251 | return 0; |
617ba13b | 252 | if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA) |
ac27a0ec DK |
253 | return 1; |
254 | return 0; | |
255 | } | |
256 | ||
617ba13b | 257 | static inline int ext4_should_writeback_data(struct inode *inode) |
ac27a0ec DK |
258 | { |
259 | if (!S_ISREG(inode->i_mode)) | |
260 | return 0; | |
617ba13b | 261 | if (EXT4_I(inode)->i_flags & EXT4_JOURNAL_DATA_FL) |
ac27a0ec | 262 | return 0; |
617ba13b | 263 | if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA) |
ac27a0ec DK |
264 | return 1; |
265 | return 0; | |
266 | } | |
267 | ||
617ba13b | 268 | #endif /* _LINUX_EXT4_JBD_H */ |