2 * linux/include/linux/ext3_jbd.h
4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
6 * Copyright 1998--1999 Red Hat corp --- All Rights Reserved
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.
12 * Ext3-specific journaling extensions.
15 #ifndef _LINUX_EXT3_JBD_H
16 #define _LINUX_EXT3_JBD_H
19 #include <linux/jbd.h>
20 #include <linux/ext3_fs.h>
22 #define EXT3_JOURNAL(inode) (EXT3_SB((inode)->i_sb)->s_journal)
24 /* Define the number of blocks we need to account to a transaction to
25 * modify one block of data.
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. */
31 #define EXT3_SINGLEDATA_TRANS_BLOCKS 8U
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. */
39 #define EXT3_DATA_TRANS_BLOCKS (3 * EXT3_SINGLEDATA_TRANS_BLOCKS - 2)
41 extern int ext3_writepage_trans_blocks(struct inode *inode);
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. */
47 #define EXT3_DELETE_TRANS_BLOCKS (2 * EXT3_DATA_TRANS_BLOCKS + 64)
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. */
55 #define EXT3_MAX_TRANS_DATA 64U
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
64 #define EXT3_RESERVE_TRANS_BLOCKS 12U
67 ext3_mark_iloc_dirty(handle_t *handle,
69 struct ext3_iloc *iloc);
72 * On success, We end up with an outstanding reference count against
73 * iloc->bh. This _must_ be cleaned up later.
76 int ext3_reserve_inode_write(handle_t *handle, struct inode *inode,
77 struct ext3_iloc *iloc);
79 int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode);
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
88 static inline void ext3_journal_abort_handle(const char *caller,
90 struct buffer_head *bh,
95 const char *errstr = ext3_decode_error(NULL, err, nbuf);
97 printk(KERN_ERR "%s: aborting transaction: %s in %s",
98 caller, errstr, err_fn);
101 BUFFER_TRACE(bh, "abort");
102 journal_abort_handle(handle);
108 __ext3_journal_get_undo_access(const char *where,
109 handle_t *handle, struct buffer_head *bh)
111 int err = journal_get_undo_access(handle, bh);
113 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
118 __ext3_journal_get_write_access(const char *where,
119 handle_t *handle, struct buffer_head *bh)
121 int err = journal_get_write_access(handle, bh);
123 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
128 __ext3_journal_dirty_data(const char *where,
129 handle_t *handle, struct buffer_head *bh, int async)
131 int err = journal_dirty_data(handle, bh, async);
133 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
138 ext3_journal_forget(handle_t *handle, struct buffer_head *bh)
140 journal_forget(handle, bh);
144 __ext3_journal_revoke(const char *where, handle_t *handle,
145 unsigned long blocknr, struct buffer_head *bh)
147 int err = journal_revoke(handle, blocknr, bh);
149 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
154 __ext3_journal_get_create_access(const char *where,
155 handle_t *handle, struct buffer_head *bh)
157 int err = journal_get_create_access(handle, bh);
159 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
164 __ext3_journal_dirty_metadata(const char *where,
165 handle_t *handle, struct buffer_head *bh)
167 int err = journal_dirty_metadata(handle, bh);
169 ext3_journal_abort_handle(where, __FUNCTION__, bh, handle,err);
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))
190 * Wrappers for journal_start/end.
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
197 static inline handle_t *ext3_journal_start(struct inode *inode, int nblocks)
201 if (inode->i_sb->s_flags & MS_RDONLY)
202 return ERR_PTR(-EROFS);
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);
214 return journal_start(journal, nblocks);
217 static inline handle_t *
218 ext3_journal_try_start(struct inode *inode, int nblocks)
220 if (inode->i_sb->s_flags & MS_RDONLY)
221 return ERR_PTR(-EROFS);
222 return journal_try_start(EXT3_JOURNAL(inode), nblocks);
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
231 static inline int __ext3_journal_stop(const char *where,
232 handle_t *handle, struct inode *inode)
234 int err = handle->h_err;
235 int rc = journal_stop(handle);
237 inode->i_sb->s_dirt = 1;
241 __ext3_std_error(inode->i_sb, where, err);
244 #define ext3_journal_stop(handle, inode) \
245 __ext3_journal_stop(__FUNCTION__, (handle), (inode))
247 static inline handle_t *ext3_journal_current_handle(void)
249 return journal_current_handle();
253 ext3_log_start_commit(journal_t *journal, transaction_t *transaction)
255 log_start_commit(journal, transaction);
258 static inline void ext3_log_wait_commit(journal_t *journal, tid_t tid)
260 log_wait_commit(journal, tid);
263 static inline int ext3_journal_extend(handle_t *handle, int nblocks)
265 return journal_extend(handle, nblocks);
268 static inline int ext3_journal_restart(handle_t *handle, int nblocks)
270 return journal_restart(handle, nblocks);
273 static inline int ext3_journal_blocks_per_page(struct inode *inode)
275 return journal_blocks_per_page(inode);
278 static inline int ext3_journal_force_commit(journal_t *journal)
280 return journal_force_commit(journal);
284 int ext3_force_commit(struct super_block *sb);
286 static inline int ext3_should_journal_data(struct inode *inode)
288 if (!S_ISREG(inode->i_mode))
290 if (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA)
292 if (inode->u.ext3_i.i_flags & EXT3_JOURNAL_DATA_FL)
297 static inline int ext3_should_order_data(struct inode *inode)
299 return (test_opt(inode->i_sb, DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA);
303 #endif /* _LINUX_EXT3_JBD_H */