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.
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
31 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U
32
33 /* Define the minimum size for a transaction which modifies data. This
34 * needs to take into account the fact that we may end up modifying two
35 * quota files too (one for the group, one for the user quota). The
36 * superblock only gets updated once, of course, so don't bother
37 * counting that again for the quota updates. */
38
39 #define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
40
41 extern int ext3_writepage_trans_blocks(struct inode *inode);
42
43 /* Delete operations potentially hit one directory's namespace plus an
44 * entire inode, plus arbitrary amounts of bitmap/indirection data. Be
45 * generous. We can grow the delete transaction later if necessary. */
46
47 #define EXT3_DELETE_TRANS_BLOCKS (2 * EXT3_DATA_TRANS_BLOCKS + 64)
48
49 /* Define an arbitrary limit for the amount of data we will anticipate
50 * writing to any given transaction. For unbounded transactions such as
51 * write(2) and truncate(2) we can write more than this, but we always
52 * start off at the maximum transaction size and grow the transaction
53 * optimistically as we go. */
54
55 #define EXT3_MAX_TRANS_DATA 64U
56
57 /* We break up a large truncate or write transaction once the handle's
58 * buffer credits gets this low, we need either to extend the
59 * transaction or to start a new one. Reserve enough space here for
60 * inode, bitmap, superblock, group and indirection updates for at least
61 * one block, plus two quota updates. Quota allocations are not
62 * needed. */
63
64 #define EXT3_RESERVE_TRANS_BLOCKS 12U
65
66 int
67 ext3_mark_iloc_dirty(handle_t *handle,
68 struct inode *inode,
69 struct ext3_iloc *iloc);
70
71 /*
72 * On success, We end up with an outstanding reference count against
73 * iloc->bh. This _must_ be cleaned up later.
74 */
75
76 int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
77 struct ext3_iloc *iloc);
78
79 int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);
80
81 /*
82 * Wrapper functions with which ext3 calls into JBD. The intent here is
83 * to allow these to be turned into appropriate stubs so ext3 can control
84 * ext2 filesystems, so ext2+ext3 systems only nee one fs. This work hasn't
85 * been done yet.
86 */
87
ext3_journal_abort_handle(const char * caller,const char * err_fn,struct buffer_head * bh,handle_t * handle,int err)88 static inline void ext3_journal_abort_handle(const char *caller,
89 const char *err_fn,
90 struct buffer_head *bh,
91 handle_t *handle,
92 int err)
93 {
94 char nbuf[16];
95 const char *errstr = ext3_decode_error(NULL, err, nbuf);
96
97 printk(KERN_ERR "%s: aborting transaction: %s in %s",
98 caller, errstr, err_fn);
99
100 if (bh)
101 BUFFER_TRACE(bh, "abort");
102 journal_abort_handle(handle);
103 if (!handle->h_err)
104 handle->h_err = err;
105 }
106
107 static inline int
__ext3_journal_get_undo_access(const char * where,handle_t * handle,struct buffer_head * bh)108 __ext3_journal_get_undo_access(const char *where,
109 handle_t *handle, struct buffer_head *bh)
110 {
111 int err = journal_get_undo_access(handle, bh);
112 if (err)
113 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
114 return err;
115 }
116
117 static inline int
__ext3_journal_get_write_access(const char * where,handle_t * handle,struct buffer_head * bh)118 __ext3_journal_get_write_access(const char *where,
119 handle_t *handle, struct buffer_head *bh)
120 {
121 int err = journal_get_write_access(handle, bh);
122 if (err)
123 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
124 return err;
125 }
126
127 static inline int
__ext3_journal_dirty_data(const char * where,handle_t * handle,struct buffer_head * bh,int async)128 __ext3_journal_dirty_data(const char *where,
129 handle_t *handle, struct buffer_head *bh, int async)
130 {
131 int err = journal_dirty_data(handle, bh, async);
132 if (err)
133 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
134 return err;
135 }
136
137 static inline void
ext3_journal_forget(handle_t * handle,struct buffer_head * bh)138 ext3_journal_forget(handle_t *handle, struct buffer_head *bh)
139 {
140 journal_forget(handle, bh);
141 }
142
143 static inline int
__ext3_journal_revoke(const char * where,handle_t * handle,unsigned long blocknr,struct buffer_head * bh)144 __ext3_journal_revoke(const char *where, handle_t *handle,
145 unsigned long blocknr, struct buffer_head *bh)
146 {
147 int err = journal_revoke(handle, blocknr, bh);
148 if (err)
149 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
150 return err;
151 }
152
153 static inline int
__ext3_journal_get_create_access(const char * where,handle_t * handle,struct buffer_head * bh)154 __ext3_journal_get_create_access(const char *where,
155 handle_t *handle, struct buffer_head *bh)
156 {
157 int err = journal_get_create_access(handle, bh);
158 if (err)
159 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
160 return err;
161 }
162
163 static inline int
__ext3_journal_dirty_metadata(const char * where,handle_t * handle,struct buffer_head * bh)164 __ext3_journal_dirty_metadata(const char *where,
165 handle_t *handle, struct buffer_head *bh)
166 {
167 int err = journal_dirty_metadata(handle, bh);
168 if (err)
169 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
170 return err;
171 }
172
173
174 #define ext3_journal_get_undo_access(handle, bh) \
175 __ext3_journal_get_undo_access(__FUNCTION__, (handle), (bh))
176 #define ext3_journal_get_write_access(handle, bh) \
177 __ext3_journal_get_write_access(__FUNCTION__, (handle), (bh))
178 #define ext3_journal_dirty_data(handle, bh, async) \
179 __ext3_journal_dirty_data(__FUNCTION__, (handle), (bh), (async))
180 #define ext3_journal_revoke(handle, blocknr, bh) \
181 __ext3_journal_revoke(__FUNCTION__, (handle), (blocknr), (bh))
182 #define ext3_journal_get_create_access(handle, bh) \
183 __ext3_journal_get_create_access(__FUNCTION__, (handle), (bh))
184 #define ext3_journal_dirty_metadata(handle, bh) \
185 __ext3_journal_dirty_metadata(__FUNCTION__, (handle), (bh))
186
187
188
189 /*
190 * Wrappers for journal_start/end.
191 *
192 * The only special thing we need to do here is to make sure that all
193 * journal_end calls result in the superblock being marked dirty, so
194 * that sync() will call the filesystem's write_super callback if
195 * appropriate.
196 */
ext3_journal_start(struct inode * inode,int nblocks)197 static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
198 {
199 journal_t *journal;
200
201 if (inode->i_sb->s_flags & MS_RDONLY)
202 return ERR_PTR(-EROFS);
203
204 /* Special case here: if the journal has aborted behind our
205 * backs (eg. EIO in the commit thread), then we still need to
206 * take the FS itself readonly cleanly. */
207 journal = EXT3_JOURNAL(inode);
208 if (is_journal_aborted(journal)) {
209 ext3_abort(inode->i_sb, __FUNCTION__,
210 "Detected aborted journal");
211 return ERR_PTR(-EROFS);
212 }
213
214 return journal_start(journal, nblocks);
215 }
216
217 static inline handle_t *
ext3_journal_try_start(struct inode * inode,int nblocks)218 ext3_journal_try_start(struct inode *inode, int nblocks)
219 {
220 if (inode->i_sb->s_flags & MS_RDONLY)
221 return ERR_PTR(-EROFS);
222 return journal_try_start(EXT3_JOURNAL(inode), nblocks);
223 }
224
225 /*
226 * The only special thing we need to do here is to make sure that all
227 * journal_stop calls result in the superblock being marked dirty, so
228 * that sync() will call the filesystem's write_super callback if
229 * appropriate.
230 */
__ext3_journal_stop(const char * where,handle_t * handle,struct inode * inode)231 static inline int __ext3_journal_stop(const char *where,
232 handle_t *handle, struct inode *inode)
233 {
234 int err = handle->h_err;
235 int rc = journal_stop(handle);
236
237 inode->i_sb->s_dirt = 1;
238 if (!err)
239 err = rc;
240 if (err)
241 __ext3_std_error(inode->i_sb, where, err);
242 return err;
243 }
244 #define ext3_journal_stop(handle, inode) \
245 __ext3_journal_stop(__FUNCTION__, (handle), (inode))
246
ext3_journal_current_handle(void)247 static inline handle_t *ext3_journal_current_handle(void)
248 {
249 return journal_current_handle();
250 }
251
252 static inline void
ext3_log_start_commit(journal_t * journal,transaction_t * transaction)253 ext3_log_start_commit(journal_t *journal, transaction_t *transaction)
254 {
255 log_start_commit(journal, transaction);
256 }
257
ext3_log_wait_commit(journal_t * journal,tid_t tid)258 static inline void ext3_log_wait_commit(journal_t *journal, tid_t tid)
259 {
260 log_wait_commit(journal, tid);
261 }
262
ext3_journal_extend(handle_t * handle,int nblocks)263 static inline int ext3_journal_extend(handle_t *handle, int nblocks)
264 {
265 return journal_extend(handle, nblocks);
266 }
267
ext3_journal_restart(handle_t * handle,int nblocks)268 static inline int ext3_journal_restart(handle_t *handle, int nblocks)
269 {
270 return journal_restart(handle, nblocks);
271 }
272
ext3_journal_blocks_per_page(struct inode * inode)273 static inline int ext3_journal_blocks_per_page(struct inode *inode)
274 {
275 return journal_blocks_per_page(inode);
276 }
277
ext3_journal_force_commit(journal_t * journal)278 static inline int ext3_journal_force_commit(journal_t *journal)
279 {
280 return journal_force_commit(journal);
281 }
282
283 /* super.c */
284 int ext3_force_commit(struct super_block *sb);
285
ext3_should_journal_data(struct inode * inode)286 static inline int ext3_should_journal_data(struct inode *inode)
287 {
288 if (!S_ISREG(inode->i_mode))
289 return 1;
290 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
291 return 1;
292 if (inode->u.ext3_i.i_flags & EXT3_JOURNAL_DATA_FL)
293 return 1;
294 return 0;
295 }
296
ext3_should_order_data(struct inode * inode)297 static inline int ext3_should_order_data(struct inode *inode)
298 {
299 return (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA);
300 }
301
302
303 #endif /* _LINUX_EXT3_JBD_H */
304