xref: /openbmc/linux/fs/ext4/ext4_jbd2.h (revision 9924a92a)
13dcf5451SChristoph Hellwig /*
23dcf5451SChristoph Hellwig  * ext4_jbd2.h
33dcf5451SChristoph Hellwig  *
43dcf5451SChristoph Hellwig  * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
53dcf5451SChristoph Hellwig  *
63dcf5451SChristoph Hellwig  * Copyright 1998--1999 Red Hat corp --- All Rights Reserved
73dcf5451SChristoph Hellwig  *
83dcf5451SChristoph Hellwig  * This file is part of the Linux kernel and is made available under
93dcf5451SChristoph Hellwig  * the terms of the GNU General Public License, version 2, or at your
103dcf5451SChristoph Hellwig  * option, any later version, incorporated herein by reference.
113dcf5451SChristoph Hellwig  *
123dcf5451SChristoph Hellwig  * Ext4-specific journaling extensions.
133dcf5451SChristoph Hellwig  */
143dcf5451SChristoph Hellwig 
153dcf5451SChristoph Hellwig #ifndef _EXT4_JBD2_H
163dcf5451SChristoph Hellwig #define _EXT4_JBD2_H
173dcf5451SChristoph Hellwig 
183dcf5451SChristoph Hellwig #include <linux/fs.h>
193dcf5451SChristoph Hellwig #include <linux/jbd2.h>
203dcf5451SChristoph Hellwig #include "ext4.h"
213dcf5451SChristoph Hellwig 
223dcf5451SChristoph Hellwig #define EXT4_JOURNAL(inode)	(EXT4_SB((inode)->i_sb)->s_journal)
233dcf5451SChristoph Hellwig 
243dcf5451SChristoph Hellwig /* Define the number of blocks we need to account to a transaction to
253dcf5451SChristoph Hellwig  * modify one block of data.
263dcf5451SChristoph Hellwig  *
273dcf5451SChristoph Hellwig  * We may have to touch one inode, one bitmap buffer, up to three
283dcf5451SChristoph Hellwig  * indirection blocks, the group and superblock summaries, and the data
293dcf5451SChristoph Hellwig  * block to complete the transaction.
303dcf5451SChristoph Hellwig  *
313dcf5451SChristoph Hellwig  * For extents-enabled fs we may have to allocate and modify up to
323dcf5451SChristoph Hellwig  * 5 levels of tree + root which are stored in the inode. */
333dcf5451SChristoph Hellwig 
343dcf5451SChristoph Hellwig #define EXT4_SINGLEDATA_TRANS_BLOCKS(sb)				\
353dcf5451SChristoph Hellwig 	(EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)   \
3683982b6fSTheodore Ts'o 	 ? 27U : 8U)
373dcf5451SChristoph Hellwig 
383dcf5451SChristoph Hellwig /* Extended attribute operations touch at most two data buffers,
393dcf5451SChristoph Hellwig  * two bitmap buffers, and two group summaries, in addition to the inode
403dcf5451SChristoph Hellwig  * and the superblock, which are already accounted for. */
413dcf5451SChristoph Hellwig 
423dcf5451SChristoph Hellwig #define EXT4_XATTR_TRANS_BLOCKS		6U
433dcf5451SChristoph Hellwig 
443dcf5451SChristoph Hellwig /* Define the minimum size for a transaction which modifies data.  This
453dcf5451SChristoph Hellwig  * needs to take into account the fact that we may end up modifying two
463dcf5451SChristoph Hellwig  * quota files too (one for the group, one for the user quota).  The
473dcf5451SChristoph Hellwig  * superblock only gets updated once, of course, so don't bother
483dcf5451SChristoph Hellwig  * counting that again for the quota updates. */
493dcf5451SChristoph Hellwig 
503dcf5451SChristoph Hellwig #define EXT4_DATA_TRANS_BLOCKS(sb)	(EXT4_SINGLEDATA_TRANS_BLOCKS(sb) + \
513dcf5451SChristoph Hellwig 					 EXT4_XATTR_TRANS_BLOCKS - 2 + \
525aca07ebSDmitry Monakhov 					 EXT4_MAXQUOTAS_TRANS_BLOCKS(sb))
533dcf5451SChristoph Hellwig 
54a02908f1SMingming Cao /*
55a02908f1SMingming Cao  * Define the number of metadata blocks we need to account to modify data.
56a02908f1SMingming Cao  *
57a02908f1SMingming Cao  * This include super block, inode block, quota blocks and xattr blocks
58a02908f1SMingming Cao  */
59a02908f1SMingming Cao #define EXT4_META_TRANS_BLOCKS(sb)	(EXT4_XATTR_TRANS_BLOCKS + \
605aca07ebSDmitry Monakhov 					EXT4_MAXQUOTAS_TRANS_BLOCKS(sb))
61a02908f1SMingming Cao 
623dcf5451SChristoph Hellwig /* Delete operations potentially hit one directory's namespace plus an
633dcf5451SChristoph Hellwig  * entire inode, plus arbitrary amounts of bitmap/indirection data.  Be
643dcf5451SChristoph Hellwig  * generous.  We can grow the delete transaction later if necessary. */
653dcf5451SChristoph Hellwig 
663dcf5451SChristoph Hellwig #define EXT4_DELETE_TRANS_BLOCKS(sb)	(2 * EXT4_DATA_TRANS_BLOCKS(sb) + 64)
673dcf5451SChristoph Hellwig 
683dcf5451SChristoph Hellwig /* Define an arbitrary limit for the amount of data we will anticipate
693dcf5451SChristoph Hellwig  * writing to any given transaction.  For unbounded transactions such as
703dcf5451SChristoph Hellwig  * write(2) and truncate(2) we can write more than this, but we always
713dcf5451SChristoph Hellwig  * start off at the maximum transaction size and grow the transaction
723dcf5451SChristoph Hellwig  * optimistically as we go. */
733dcf5451SChristoph Hellwig 
743dcf5451SChristoph Hellwig #define EXT4_MAX_TRANS_DATA		64U
753dcf5451SChristoph Hellwig 
763dcf5451SChristoph Hellwig /* We break up a large truncate or write transaction once the handle's
773dcf5451SChristoph Hellwig  * buffer credits gets this low, we need either to extend the
783dcf5451SChristoph Hellwig  * transaction or to start a new one.  Reserve enough space here for
793dcf5451SChristoph Hellwig  * inode, bitmap, superblock, group and indirection updates for at least
803dcf5451SChristoph Hellwig  * one block, plus two quota updates.  Quota allocations are not
813dcf5451SChristoph Hellwig  * needed. */
823dcf5451SChristoph Hellwig 
833dcf5451SChristoph Hellwig #define EXT4_RESERVE_TRANS_BLOCKS	12U
843dcf5451SChristoph Hellwig 
853dcf5451SChristoph Hellwig #define EXT4_INDEX_EXTRA_TRANS_BLOCKS	8
863dcf5451SChristoph Hellwig 
873dcf5451SChristoph Hellwig #ifdef CONFIG_QUOTA
883dcf5451SChristoph Hellwig /* Amount of blocks needed for quota update - we know that the structure was
8921f97697SJan Kara  * allocated so we need to update only data block */
907c319d32SAditya Kali #define EXT4_QUOTA_TRANS_BLOCKS(sb) ((test_opt(sb, QUOTA) ||\
917c319d32SAditya Kali 		EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA)) ?\
927c319d32SAditya Kali 		1 : 0)
933dcf5451SChristoph Hellwig /* Amount of blocks needed for quota insert/delete - we do some block writes
943dcf5451SChristoph Hellwig  * but inode, sb and group updates are done only once */
957c319d32SAditya Kali #define EXT4_QUOTA_INIT_BLOCKS(sb) ((test_opt(sb, QUOTA) ||\
967c319d32SAditya Kali 		EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA)) ?\
977c319d32SAditya Kali 		(DQUOT_INIT_ALLOC*(EXT4_SINGLEDATA_TRANS_BLOCKS(sb)-3)\
987c319d32SAditya Kali 		 +3+DQUOT_INIT_REWRITE) : 0)
995aca07ebSDmitry Monakhov 
1007c319d32SAditya Kali #define EXT4_QUOTA_DEL_BLOCKS(sb) ((test_opt(sb, QUOTA) ||\
1017c319d32SAditya Kali 		EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA)) ?\
1027c319d32SAditya Kali 		(DQUOT_DEL_ALLOC*(EXT4_SINGLEDATA_TRANS_BLOCKS(sb)-3)\
1037c319d32SAditya Kali 		 +3+DQUOT_DEL_REWRITE) : 0)
1043dcf5451SChristoph Hellwig #else
1053dcf5451SChristoph Hellwig #define EXT4_QUOTA_TRANS_BLOCKS(sb) 0
1063dcf5451SChristoph Hellwig #define EXT4_QUOTA_INIT_BLOCKS(sb) 0
1073dcf5451SChristoph Hellwig #define EXT4_QUOTA_DEL_BLOCKS(sb) 0
1083dcf5451SChristoph Hellwig #endif
1095aca07ebSDmitry Monakhov #define EXT4_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_TRANS_BLOCKS(sb))
1105aca07ebSDmitry Monakhov #define EXT4_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_INIT_BLOCKS(sb))
1115aca07ebSDmitry Monakhov #define EXT4_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_DEL_BLOCKS(sb))
1123dcf5451SChristoph Hellwig 
1139924a92aSTheodore Ts'o /*
1149924a92aSTheodore Ts'o  * Ext4 handle operation types -- for logging purposes
1159924a92aSTheodore Ts'o  */
1169924a92aSTheodore Ts'o #define EXT4_HT_MISC             0
1179924a92aSTheodore Ts'o #define EXT4_HT_INODE            1
1189924a92aSTheodore Ts'o #define EXT4_HT_WRITE_PAGE       2
1199924a92aSTheodore Ts'o #define EXT4_HT_MAP_BLOCKS       3
1209924a92aSTheodore Ts'o #define EXT4_HT_DIR              4
1219924a92aSTheodore Ts'o #define EXT4_HT_TRUNCATE         5
1229924a92aSTheodore Ts'o #define EXT4_HT_QUOTA            6
1239924a92aSTheodore Ts'o #define EXT4_HT_RESIZE           7
1249924a92aSTheodore Ts'o #define EXT4_HT_MIGRATE          8
1259924a92aSTheodore Ts'o #define EXT4_HT_MOVE_EXTENTS     9
1269924a92aSTheodore Ts'o #define EXT4_HT_XATTR           10
1279924a92aSTheodore Ts'o #define EXT4_HT_MAX             11
1289924a92aSTheodore Ts'o 
12918aadd47SBobi Jam /**
13018aadd47SBobi Jam  *   struct ext4_journal_cb_entry - Base structure for callback information.
13118aadd47SBobi Jam  *
13218aadd47SBobi Jam  *   This struct is a 'seed' structure for a using with your own callback
13318aadd47SBobi Jam  *   structs. If you are using callbacks you must allocate one of these
13418aadd47SBobi Jam  *   or another struct of your own definition which has this struct
13518aadd47SBobi Jam  *   as it's first element and pass it to ext4_journal_callback_add().
13618aadd47SBobi Jam  */
13718aadd47SBobi Jam struct ext4_journal_cb_entry {
13818aadd47SBobi Jam 	/* list information for other callbacks attached to the same handle */
13918aadd47SBobi Jam 	struct list_head jce_list;
14018aadd47SBobi Jam 
14118aadd47SBobi Jam 	/*  Function to call with this callback structure */
14218aadd47SBobi Jam 	void (*jce_func)(struct super_block *sb,
14318aadd47SBobi Jam 			 struct ext4_journal_cb_entry *jce, int error);
14418aadd47SBobi Jam 
14518aadd47SBobi Jam 	/* user data goes here */
14618aadd47SBobi Jam };
14718aadd47SBobi Jam 
14818aadd47SBobi Jam /**
14918aadd47SBobi Jam  * ext4_journal_callback_add: add a function to call after transaction commit
15018aadd47SBobi Jam  * @handle: active journal transaction handle to register callback on
15118aadd47SBobi Jam  * @func: callback function to call after the transaction has committed:
15218aadd47SBobi Jam  *        @sb: superblock of current filesystem for transaction
15318aadd47SBobi Jam  *        @jce: returned journal callback data
15418aadd47SBobi Jam  *        @rc: journal state at commit (0 = transaction committed properly)
15518aadd47SBobi Jam  * @jce: journal callback data (internal and function private data struct)
15618aadd47SBobi Jam  *
15718aadd47SBobi Jam  * The registered function will be called in the context of the journal thread
15818aadd47SBobi Jam  * after the transaction for which the handle was created has completed.
15918aadd47SBobi Jam  *
16018aadd47SBobi Jam  * No locks are held when the callback function is called, so it is safe to
16118aadd47SBobi Jam  * call blocking functions from within the callback, but the callback should
16218aadd47SBobi Jam  * not block or run for too long, or the filesystem will be blocked waiting for
16318aadd47SBobi Jam  * the next transaction to commit. No journaling functions can be used, or
16418aadd47SBobi Jam  * there is a risk of deadlock.
16518aadd47SBobi Jam  *
16618aadd47SBobi Jam  * There is no guaranteed calling order of multiple registered callbacks on
16718aadd47SBobi Jam  * the same transaction.
16818aadd47SBobi Jam  */
16918aadd47SBobi Jam static inline void ext4_journal_callback_add(handle_t *handle,
17018aadd47SBobi Jam 			void (*func)(struct super_block *sb,
17118aadd47SBobi Jam 				     struct ext4_journal_cb_entry *jce,
17218aadd47SBobi Jam 				     int rc),
17318aadd47SBobi Jam 			struct ext4_journal_cb_entry *jce)
17418aadd47SBobi Jam {
17518aadd47SBobi Jam 	struct ext4_sb_info *sbi =
17618aadd47SBobi Jam 			EXT4_SB(handle->h_transaction->t_journal->j_private);
17718aadd47SBobi Jam 
17818aadd47SBobi Jam 	/* Add the jce to transaction's private list */
17918aadd47SBobi Jam 	jce->jce_func = func;
18018aadd47SBobi Jam 	spin_lock(&sbi->s_md_lock);
18118aadd47SBobi Jam 	list_add_tail(&jce->jce_list, &handle->h_transaction->t_private_list);
18218aadd47SBobi Jam 	spin_unlock(&sbi->s_md_lock);
18318aadd47SBobi Jam }
18418aadd47SBobi Jam 
18518aadd47SBobi Jam /**
18618aadd47SBobi Jam  * ext4_journal_callback_del: delete a registered callback
18718aadd47SBobi Jam  * @handle: active journal transaction handle on which callback was registered
18818aadd47SBobi Jam  * @jce: registered journal callback entry to unregister
18918aadd47SBobi Jam  */
19018aadd47SBobi Jam static inline void ext4_journal_callback_del(handle_t *handle,
19118aadd47SBobi Jam 					     struct ext4_journal_cb_entry *jce)
19218aadd47SBobi Jam {
19318aadd47SBobi Jam 	struct ext4_sb_info *sbi =
19418aadd47SBobi Jam 			EXT4_SB(handle->h_transaction->t_journal->j_private);
19518aadd47SBobi Jam 
19618aadd47SBobi Jam 	spin_lock(&sbi->s_md_lock);
19718aadd47SBobi Jam 	list_del_init(&jce->jce_list);
19818aadd47SBobi Jam 	spin_unlock(&sbi->s_md_lock);
19918aadd47SBobi Jam }
20018aadd47SBobi Jam 
2013dcf5451SChristoph Hellwig int
2023dcf5451SChristoph Hellwig ext4_mark_iloc_dirty(handle_t *handle,
2033dcf5451SChristoph Hellwig 		     struct inode *inode,
2043dcf5451SChristoph Hellwig 		     struct ext4_iloc *iloc);
2053dcf5451SChristoph Hellwig 
2063dcf5451SChristoph Hellwig /*
2073dcf5451SChristoph Hellwig  * On success, We end up with an outstanding reference count against
2083dcf5451SChristoph Hellwig  * iloc->bh.  This _must_ be cleaned up later.
2093dcf5451SChristoph Hellwig  */
2103dcf5451SChristoph Hellwig 
2113dcf5451SChristoph Hellwig int ext4_reserve_inode_write(handle_t *handle, struct inode *inode,
2123dcf5451SChristoph Hellwig 			struct ext4_iloc *iloc);
2133dcf5451SChristoph Hellwig 
2143dcf5451SChristoph Hellwig int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode);
2153dcf5451SChristoph Hellwig 
2163dcf5451SChristoph Hellwig /*
217e4684b3fSTheodore Ts'o  * Wrapper functions with which ext4 calls into JBD.
2183dcf5451SChristoph Hellwig  */
21990c7201bSTheodore Ts'o void ext4_journal_abort_handle(const char *caller, unsigned int line,
22090c7201bSTheodore Ts'o 			       const char *err_fn,
2213dcf5451SChristoph Hellwig 		struct buffer_head *bh, handle_t *handle, int err);
2223dcf5451SChristoph Hellwig 
22390c7201bSTheodore Ts'o int __ext4_journal_get_write_access(const char *where, unsigned int line,
22490c7201bSTheodore Ts'o 				    handle_t *handle, struct buffer_head *bh);
2253dcf5451SChristoph Hellwig 
22690c7201bSTheodore Ts'o int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
22790c7201bSTheodore Ts'o 		  int is_metadata, struct inode *inode,
22890c7201bSTheodore Ts'o 		  struct buffer_head *bh, ext4_fsblk_t blocknr);
22990c7201bSTheodore Ts'o 
23090c7201bSTheodore Ts'o int __ext4_journal_get_create_access(const char *where, unsigned int line,
23190c7201bSTheodore Ts'o 				handle_t *handle, struct buffer_head *bh);
23290c7201bSTheodore Ts'o 
23390c7201bSTheodore Ts'o int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
23490c7201bSTheodore Ts'o 				 handle_t *handle, struct inode *inode,
23590c7201bSTheodore Ts'o 				 struct buffer_head *bh);
23690c7201bSTheodore Ts'o 
23790c7201bSTheodore Ts'o int __ext4_handle_dirty_super(const char *where, unsigned int line,
238b50924c2SArtem Bityutskiy 			      handle_t *handle, struct super_block *sb);
239a0375156STheodore Ts'o 
2403dcf5451SChristoph Hellwig #define ext4_journal_get_write_access(handle, bh) \
24190c7201bSTheodore Ts'o 	__ext4_journal_get_write_access(__func__, __LINE__, (handle), (bh))
242d6797d14STheodore Ts'o #define ext4_forget(handle, is_metadata, inode, bh, block_nr) \
24390c7201bSTheodore Ts'o 	__ext4_forget(__func__, __LINE__, (handle), (is_metadata), (inode), \
24490c7201bSTheodore Ts'o 		      (bh), (block_nr))
2453dcf5451SChristoph Hellwig #define ext4_journal_get_create_access(handle, bh) \
24690c7201bSTheodore Ts'o 	__ext4_journal_get_create_access(__func__, __LINE__, (handle), (bh))
2470390131bSFrank Mayhar #define ext4_handle_dirty_metadata(handle, inode, bh) \
24890c7201bSTheodore Ts'o 	__ext4_handle_dirty_metadata(__func__, __LINE__, (handle), (inode), \
24990c7201bSTheodore Ts'o 				     (bh))
250a0375156STheodore Ts'o #define ext4_handle_dirty_super(handle, sb) \
251b50924c2SArtem Bityutskiy 	__ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb))
2523dcf5451SChristoph Hellwig 
2539924a92aSTheodore Ts'o handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line,
2549924a92aSTheodore Ts'o 				  int type, int nblocks);
255c398eda0STheodore Ts'o int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle);
2563dcf5451SChristoph Hellwig 
257d3d1faf6SCurt Wohlgemuth #define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096)
2580390131bSFrank Mayhar 
259d3d1faf6SCurt Wohlgemuth /* Note:  Do not use this for NULL handles.  This is only to determine if
260d3d1faf6SCurt Wohlgemuth  * a properly allocated handle is using a journal or not. */
2610390131bSFrank Mayhar static inline int ext4_handle_valid(handle_t *handle)
2620390131bSFrank Mayhar {
263d3d1faf6SCurt Wohlgemuth 	if ((unsigned long)handle < EXT4_NOJOURNAL_MAX_REF_COUNT)
2640390131bSFrank Mayhar 		return 0;
2650390131bSFrank Mayhar 	return 1;
2660390131bSFrank Mayhar }
2670390131bSFrank Mayhar 
2680390131bSFrank Mayhar static inline void ext4_handle_sync(handle_t *handle)
2690390131bSFrank Mayhar {
2700390131bSFrank Mayhar 	if (ext4_handle_valid(handle))
2710390131bSFrank Mayhar 		handle->h_sync = 1;
2720390131bSFrank Mayhar }
2730390131bSFrank Mayhar 
2740390131bSFrank Mayhar static inline int ext4_handle_is_aborted(handle_t *handle)
2750390131bSFrank Mayhar {
2760390131bSFrank Mayhar 	if (ext4_handle_valid(handle))
2770390131bSFrank Mayhar 		return is_handle_aborted(handle);
2780390131bSFrank Mayhar 	return 0;
2790390131bSFrank Mayhar }
2800390131bSFrank Mayhar 
2810390131bSFrank Mayhar static inline int ext4_handle_has_enough_credits(handle_t *handle, int needed)
2820390131bSFrank Mayhar {
2830390131bSFrank Mayhar 	if (ext4_handle_valid(handle) && handle->h_buffer_credits < needed)
2840390131bSFrank Mayhar 		return 0;
2850390131bSFrank Mayhar 	return 1;
2860390131bSFrank Mayhar }
2870390131bSFrank Mayhar 
2889924a92aSTheodore Ts'o #define ext4_journal_start_sb(sb, type, nblocks)			\
2899924a92aSTheodore Ts'o 	__ext4_journal_start_sb((sb), __LINE__, (type), (nblocks))
2909924a92aSTheodore Ts'o 
2919924a92aSTheodore Ts'o #define ext4_journal_start(inode, type, nblocks)			\
2929924a92aSTheodore Ts'o 	__ext4_journal_start((inode), __LINE__, (type), (nblocks))
2939924a92aSTheodore Ts'o 
2949924a92aSTheodore Ts'o static inline handle_t *__ext4_journal_start(struct inode *inode,
2959924a92aSTheodore Ts'o 					     unsigned int line, int type,
2969924a92aSTheodore Ts'o 					     int nblocks)
2973dcf5451SChristoph Hellwig {
2989924a92aSTheodore Ts'o 	return __ext4_journal_start_sb(inode->i_sb, line, type, nblocks);
2993dcf5451SChristoph Hellwig }
3003dcf5451SChristoph Hellwig 
3013dcf5451SChristoph Hellwig #define ext4_journal_stop(handle) \
302c398eda0STheodore Ts'o 	__ext4_journal_stop(__func__, __LINE__, (handle))
3033dcf5451SChristoph Hellwig 
3043dcf5451SChristoph Hellwig static inline handle_t *ext4_journal_current_handle(void)
3053dcf5451SChristoph Hellwig {
3063dcf5451SChristoph Hellwig 	return journal_current_handle();
3073dcf5451SChristoph Hellwig }
3083dcf5451SChristoph Hellwig 
3093dcf5451SChristoph Hellwig static inline int ext4_journal_extend(handle_t *handle, int nblocks)
3103dcf5451SChristoph Hellwig {
3110390131bSFrank Mayhar 	if (ext4_handle_valid(handle))
3123dcf5451SChristoph Hellwig 		return jbd2_journal_extend(handle, nblocks);
3130390131bSFrank Mayhar 	return 0;
3143dcf5451SChristoph Hellwig }
3153dcf5451SChristoph Hellwig 
3163dcf5451SChristoph Hellwig static inline int ext4_journal_restart(handle_t *handle, int nblocks)
3173dcf5451SChristoph Hellwig {
3180390131bSFrank Mayhar 	if (ext4_handle_valid(handle))
3193dcf5451SChristoph Hellwig 		return jbd2_journal_restart(handle, nblocks);
3200390131bSFrank Mayhar 	return 0;
3213dcf5451SChristoph Hellwig }
3223dcf5451SChristoph Hellwig 
3233dcf5451SChristoph Hellwig static inline int ext4_journal_blocks_per_page(struct inode *inode)
3243dcf5451SChristoph Hellwig {
3250390131bSFrank Mayhar 	if (EXT4_JOURNAL(inode) != NULL)
3263dcf5451SChristoph Hellwig 		return jbd2_journal_blocks_per_page(inode);
3270390131bSFrank Mayhar 	return 0;
3283dcf5451SChristoph Hellwig }
3293dcf5451SChristoph Hellwig 
3303dcf5451SChristoph Hellwig static inline int ext4_journal_force_commit(journal_t *journal)
3313dcf5451SChristoph Hellwig {
3320390131bSFrank Mayhar 	if (journal)
3333dcf5451SChristoph Hellwig 		return jbd2_journal_force_commit(journal);
3340390131bSFrank Mayhar 	return 0;
3353dcf5451SChristoph Hellwig }
3363dcf5451SChristoph Hellwig 
337678aaf48SJan Kara static inline int ext4_jbd2_file_inode(handle_t *handle, struct inode *inode)
338678aaf48SJan Kara {
3390390131bSFrank Mayhar 	if (ext4_handle_valid(handle))
3408aefcd55STheodore Ts'o 		return jbd2_journal_file_inode(handle, EXT4_I(inode)->jinode);
3410390131bSFrank Mayhar 	return 0;
342678aaf48SJan Kara }
343678aaf48SJan Kara 
344b436b9beSJan Kara static inline void ext4_update_inode_fsync_trans(handle_t *handle,
345b436b9beSJan Kara 						 struct inode *inode,
346b436b9beSJan Kara 						 int datasync)
347b436b9beSJan Kara {
348b436b9beSJan Kara 	struct ext4_inode_info *ei = EXT4_I(inode);
349b436b9beSJan Kara 
350b436b9beSJan Kara 	if (ext4_handle_valid(handle)) {
351b436b9beSJan Kara 		ei->i_sync_tid = handle->h_transaction->t_tid;
352b436b9beSJan Kara 		if (datasync)
353b436b9beSJan Kara 			ei->i_datasync_tid = handle->h_transaction->t_tid;
354b436b9beSJan Kara 	}
355b436b9beSJan Kara }
356b436b9beSJan Kara 
3573dcf5451SChristoph Hellwig /* super.c */
3583dcf5451SChristoph Hellwig int ext4_force_commit(struct super_block *sb);
3593dcf5451SChristoph Hellwig 
3603d2b1582SLukas Czerner /*
3613d2b1582SLukas Czerner  * Ext4 inode journal modes
3623d2b1582SLukas Czerner  */
3633d2b1582SLukas Czerner #define EXT4_INODE_JOURNAL_DATA_MODE	0x01 /* journal data mode */
3643d2b1582SLukas Czerner #define EXT4_INODE_ORDERED_DATA_MODE	0x02 /* ordered data mode */
3653d2b1582SLukas Czerner #define EXT4_INODE_WRITEBACK_DATA_MODE	0x04 /* writeback data mode */
3663d2b1582SLukas Czerner 
3673d2b1582SLukas Czerner static inline int ext4_inode_journal_mode(struct inode *inode)
3683dcf5451SChristoph Hellwig {
3690390131bSFrank Mayhar 	if (EXT4_JOURNAL(inode) == NULL)
3703d2b1582SLukas Czerner 		return EXT4_INODE_WRITEBACK_DATA_MODE;	/* writeback */
3713d2b1582SLukas Czerner 	/* We do not support data journalling with delayed allocation */
3723d2b1582SLukas Czerner 	if (!S_ISREG(inode->i_mode) ||
3733d2b1582SLukas Czerner 	    test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
3743d2b1582SLukas Czerner 		return EXT4_INODE_JOURNAL_DATA_MODE;	/* journal data */
3753d2b1582SLukas Czerner 	if (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) &&
3763d2b1582SLukas Czerner 	    !test_opt(inode->i_sb, DELALLOC))
3773d2b1582SLukas Czerner 		return EXT4_INODE_JOURNAL_DATA_MODE;	/* journal data */
3783d2b1582SLukas Czerner 	if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
3793d2b1582SLukas Czerner 		return EXT4_INODE_ORDERED_DATA_MODE;	/* ordered */
3803d2b1582SLukas Czerner 	if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
3813d2b1582SLukas Czerner 		return EXT4_INODE_WRITEBACK_DATA_MODE;	/* writeback */
3823d2b1582SLukas Czerner 	else
3833d2b1582SLukas Czerner 		BUG();
3843d2b1582SLukas Czerner }
3853d2b1582SLukas Czerner 
3863d2b1582SLukas Czerner static inline int ext4_should_journal_data(struct inode *inode)
3873d2b1582SLukas Czerner {
3883d2b1582SLukas Czerner 	return ext4_inode_journal_mode(inode) & EXT4_INODE_JOURNAL_DATA_MODE;
3893dcf5451SChristoph Hellwig }
3903dcf5451SChristoph Hellwig 
3913dcf5451SChristoph Hellwig static inline int ext4_should_order_data(struct inode *inode)
3923dcf5451SChristoph Hellwig {
3933d2b1582SLukas Czerner 	return ext4_inode_journal_mode(inode) & EXT4_INODE_ORDERED_DATA_MODE;
3943dcf5451SChristoph Hellwig }
3953dcf5451SChristoph Hellwig 
3963dcf5451SChristoph Hellwig static inline int ext4_should_writeback_data(struct inode *inode)
3973dcf5451SChristoph Hellwig {
3983d2b1582SLukas Czerner 	return ext4_inode_journal_mode(inode) & EXT4_INODE_WRITEBACK_DATA_MODE;
3993dcf5451SChristoph Hellwig }
4003dcf5451SChristoph Hellwig 
401744692dcSJiaying Zhang /*
402744692dcSJiaying Zhang  * This function controls whether or not we should try to go down the
403744692dcSJiaying Zhang  * dioread_nolock code paths, which makes it safe to avoid taking
404744692dcSJiaying Zhang  * i_mutex for direct I/O reads.  This only works for extent-based
405206f7ab4SChristoph Hellwig  * files, and it doesn't work if data journaling is enabled, since the
406206f7ab4SChristoph Hellwig  * dioread_nolock code uses b_private to pass information back to the
407206f7ab4SChristoph Hellwig  * I/O completion handler, and this conflicts with the jbd's use of
408206f7ab4SChristoph Hellwig  * b_private.
409744692dcSJiaying Zhang  */
410744692dcSJiaying Zhang static inline int ext4_should_dioread_nolock(struct inode *inode)
411744692dcSJiaying Zhang {
412744692dcSJiaying Zhang 	if (!test_opt(inode->i_sb, DIOREAD_NOLOCK))
413744692dcSJiaying Zhang 		return 0;
414744692dcSJiaying Zhang 	if (!S_ISREG(inode->i_mode))
415744692dcSJiaying Zhang 		return 0;
41612e9b892SDmitry Monakhov 	if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
417744692dcSJiaying Zhang 		return 0;
418744692dcSJiaying Zhang 	if (ext4_should_journal_data(inode))
419744692dcSJiaying Zhang 		return 0;
420744692dcSJiaying Zhang 	return 1;
421744692dcSJiaying Zhang }
422744692dcSJiaying Zhang 
4233dcf5451SChristoph Hellwig #endif	/* _EXT4_JBD2_H */
424