18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/* -*- mode: c; c-basic-offset: 8; -*-
38c2ecf20Sopenharmony_ci * vim: noexpandtab sw=8 ts=8 sts=0:
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * journal.h
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Defines journalling api and structures.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (C) 2003, 2005 Oracle.  All rights reserved.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef OCFS2_JOURNAL_H
138c2ecf20Sopenharmony_ci#define OCFS2_JOURNAL_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/fs.h>
168c2ecf20Sopenharmony_ci#include <linux/jbd2.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cienum ocfs2_journal_state {
198c2ecf20Sopenharmony_ci	OCFS2_JOURNAL_FREE = 0,
208c2ecf20Sopenharmony_ci	OCFS2_JOURNAL_LOADED,
218c2ecf20Sopenharmony_ci	OCFS2_JOURNAL_IN_SHUTDOWN,
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistruct ocfs2_super;
258c2ecf20Sopenharmony_cistruct ocfs2_dinode;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * The recovery_list is a simple linked list of node numbers to recover.
298c2ecf20Sopenharmony_ci * It is protected by the recovery_lock.
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct ocfs2_recovery_map {
338c2ecf20Sopenharmony_ci	unsigned int rm_used;
348c2ecf20Sopenharmony_ci	unsigned int *rm_entries;
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct ocfs2_journal {
398c2ecf20Sopenharmony_ci	enum ocfs2_journal_state   j_state;    /* Journals current state   */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	journal_t                 *j_journal; /* The kernels journal type */
428c2ecf20Sopenharmony_ci	struct inode              *j_inode;   /* Kernel inode pointing to
438c2ecf20Sopenharmony_ci					       * this journal             */
448c2ecf20Sopenharmony_ci	struct ocfs2_super        *j_osb;     /* pointer to the super
458c2ecf20Sopenharmony_ci					       * block for the node
468c2ecf20Sopenharmony_ci					       * we're currently
478c2ecf20Sopenharmony_ci					       * running on -- not
488c2ecf20Sopenharmony_ci					       * necessarily the super
498c2ecf20Sopenharmony_ci					       * block from the node
508c2ecf20Sopenharmony_ci					       * which we usually run
518c2ecf20Sopenharmony_ci					       * from (recovery,
528c2ecf20Sopenharmony_ci					       * etc)                     */
538c2ecf20Sopenharmony_ci	struct buffer_head        *j_bh;      /* Journal disk inode block */
548c2ecf20Sopenharmony_ci	atomic_t                  j_num_trans; /* Number of transactions
558c2ecf20Sopenharmony_ci					        * currently in the system. */
568c2ecf20Sopenharmony_ci	spinlock_t                j_lock;
578c2ecf20Sopenharmony_ci	unsigned long             j_trans_id;
588c2ecf20Sopenharmony_ci	struct rw_semaphore       j_trans_barrier;
598c2ecf20Sopenharmony_ci	wait_queue_head_t         j_checkpointed;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	/* both fields protected by j_lock*/
628c2ecf20Sopenharmony_ci	struct list_head          j_la_cleanups;
638c2ecf20Sopenharmony_ci	struct work_struct        j_recovery_work;
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciextern spinlock_t trans_inc_lock;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* wrap j_trans_id so we never have it equal to zero. */
698c2ecf20Sopenharmony_cistatic inline unsigned long ocfs2_inc_trans_id(struct ocfs2_journal *j)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	unsigned long old_id;
728c2ecf20Sopenharmony_ci	spin_lock(&trans_inc_lock);
738c2ecf20Sopenharmony_ci	old_id = j->j_trans_id++;
748c2ecf20Sopenharmony_ci	if (unlikely(!j->j_trans_id))
758c2ecf20Sopenharmony_ci		j->j_trans_id = 1;
768c2ecf20Sopenharmony_ci	spin_unlock(&trans_inc_lock);
778c2ecf20Sopenharmony_ci	return old_id;
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline void ocfs2_set_ci_lock_trans(struct ocfs2_journal *journal,
818c2ecf20Sopenharmony_ci					   struct ocfs2_caching_info *ci)
828c2ecf20Sopenharmony_ci{
838c2ecf20Sopenharmony_ci	spin_lock(&trans_inc_lock);
848c2ecf20Sopenharmony_ci	ci->ci_last_trans = journal->j_trans_id;
858c2ecf20Sopenharmony_ci	spin_unlock(&trans_inc_lock);
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* Used to figure out whether it's safe to drop a metadata lock on an
898c2ecf20Sopenharmony_ci * cached object. Returns true if all the object's changes have been
908c2ecf20Sopenharmony_ci * checkpointed to disk. You should be holding the spinlock on the
918c2ecf20Sopenharmony_ci * metadata lock while calling this to be sure that nobody can take
928c2ecf20Sopenharmony_ci * the lock and put it on another transaction. */
938c2ecf20Sopenharmony_cistatic inline int ocfs2_ci_fully_checkpointed(struct ocfs2_caching_info *ci)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	int ret;
968c2ecf20Sopenharmony_ci	struct ocfs2_journal *journal =
978c2ecf20Sopenharmony_ci		OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	spin_lock(&trans_inc_lock);
1008c2ecf20Sopenharmony_ci	ret = time_after(journal->j_trans_id, ci->ci_last_trans);
1018c2ecf20Sopenharmony_ci	spin_unlock(&trans_inc_lock);
1028c2ecf20Sopenharmony_ci	return ret;
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/* convenience function to check if an object backed by struct
1068c2ecf20Sopenharmony_ci * ocfs2_caching_info  is still new (has never hit disk) Will do you a
1078c2ecf20Sopenharmony_ci * favor and set created_trans = 0 when you've
1088c2ecf20Sopenharmony_ci * been checkpointed.  returns '1' if the ci is still new. */
1098c2ecf20Sopenharmony_cistatic inline int ocfs2_ci_is_new(struct ocfs2_caching_info *ci)
1108c2ecf20Sopenharmony_ci{
1118c2ecf20Sopenharmony_ci	int ret;
1128c2ecf20Sopenharmony_ci	struct ocfs2_journal *journal =
1138c2ecf20Sopenharmony_ci		OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	spin_lock(&trans_inc_lock);
1168c2ecf20Sopenharmony_ci	ret = !(time_after(journal->j_trans_id, ci->ci_created_trans));
1178c2ecf20Sopenharmony_ci	if (!ret)
1188c2ecf20Sopenharmony_ci		ci->ci_created_trans = 0;
1198c2ecf20Sopenharmony_ci	spin_unlock(&trans_inc_lock);
1208c2ecf20Sopenharmony_ci	return ret;
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci/* Wrapper for inodes so we can check system files */
1248c2ecf20Sopenharmony_cistatic inline int ocfs2_inode_is_new(struct inode *inode)
1258c2ecf20Sopenharmony_ci{
1268c2ecf20Sopenharmony_ci	/* System files are never "new" as they're written out by
1278c2ecf20Sopenharmony_ci	 * mkfs. This helps us early during mount, before we have the
1288c2ecf20Sopenharmony_ci	 * journal open and j_trans_id could be junk. */
1298c2ecf20Sopenharmony_ci	if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE)
1308c2ecf20Sopenharmony_ci		return 0;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	return ocfs2_ci_is_new(INODE_CACHE(inode));
1338c2ecf20Sopenharmony_ci}
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cistatic inline void ocfs2_ci_set_new(struct ocfs2_super *osb,
1368c2ecf20Sopenharmony_ci				    struct ocfs2_caching_info *ci)
1378c2ecf20Sopenharmony_ci{
1388c2ecf20Sopenharmony_ci	spin_lock(&trans_inc_lock);
1398c2ecf20Sopenharmony_ci	ci->ci_created_trans = osb->journal->j_trans_id;
1408c2ecf20Sopenharmony_ci	spin_unlock(&trans_inc_lock);
1418c2ecf20Sopenharmony_ci}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/* Exported only for the journal struct init code in super.c. Do not call. */
1448c2ecf20Sopenharmony_civoid ocfs2_orphan_scan_init(struct ocfs2_super *osb);
1458c2ecf20Sopenharmony_civoid ocfs2_orphan_scan_start(struct ocfs2_super *osb);
1468c2ecf20Sopenharmony_civoid ocfs2_orphan_scan_stop(struct ocfs2_super *osb);
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_civoid ocfs2_complete_recovery(struct work_struct *work);
1498c2ecf20Sopenharmony_civoid ocfs2_wait_for_recovery(struct ocfs2_super *osb);
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ciint ocfs2_recovery_init(struct ocfs2_super *osb);
1528c2ecf20Sopenharmony_civoid ocfs2_recovery_exit(struct ocfs2_super *osb);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ciint ocfs2_compute_replay_slots(struct ocfs2_super *osb);
1558c2ecf20Sopenharmony_civoid ocfs2_free_replay_slots(struct ocfs2_super *osb);
1568c2ecf20Sopenharmony_ci/*
1578c2ecf20Sopenharmony_ci *  Journal Control:
1588c2ecf20Sopenharmony_ci *  Initialize, Load, Shutdown, Wipe a journal.
1598c2ecf20Sopenharmony_ci *
1608c2ecf20Sopenharmony_ci *  ocfs2_journal_init     - Initialize journal structures in the OSB.
1618c2ecf20Sopenharmony_ci *  ocfs2_journal_load     - Load the given journal off disk. Replay it if
1628c2ecf20Sopenharmony_ci *                          there's transactions still in there.
1638c2ecf20Sopenharmony_ci *  ocfs2_journal_shutdown - Shutdown a journal, this will flush all
1648c2ecf20Sopenharmony_ci *                          uncommitted, uncheckpointed transactions.
1658c2ecf20Sopenharmony_ci *  ocfs2_journal_wipe     - Wipe transactions from a journal. Optionally
1668c2ecf20Sopenharmony_ci *                          zero out each block.
1678c2ecf20Sopenharmony_ci *  ocfs2_recovery_thread  - Perform recovery on a node. osb is our own osb.
1688c2ecf20Sopenharmony_ci *  ocfs2_mark_dead_nodes - Start recovery on nodes we won't get a heartbeat
1698c2ecf20Sopenharmony_ci *                          event on.
1708c2ecf20Sopenharmony_ci *  ocfs2_start_checkpoint - Kick the commit thread to do a checkpoint.
1718c2ecf20Sopenharmony_ci */
1728c2ecf20Sopenharmony_civoid   ocfs2_set_journal_params(struct ocfs2_super *osb);
1738c2ecf20Sopenharmony_ciint    ocfs2_journal_init(struct ocfs2_journal *journal,
1748c2ecf20Sopenharmony_ci			  int *dirty);
1758c2ecf20Sopenharmony_civoid   ocfs2_journal_shutdown(struct ocfs2_super *osb);
1768c2ecf20Sopenharmony_ciint    ocfs2_journal_wipe(struct ocfs2_journal *journal,
1778c2ecf20Sopenharmony_ci			  int full);
1788c2ecf20Sopenharmony_ciint    ocfs2_journal_load(struct ocfs2_journal *journal, int local,
1798c2ecf20Sopenharmony_ci			  int replayed);
1808c2ecf20Sopenharmony_ciint    ocfs2_check_journals_nolocks(struct ocfs2_super *osb);
1818c2ecf20Sopenharmony_civoid   ocfs2_recovery_thread(struct ocfs2_super *osb,
1828c2ecf20Sopenharmony_ci			     int node_num);
1838c2ecf20Sopenharmony_ciint    ocfs2_mark_dead_nodes(struct ocfs2_super *osb);
1848c2ecf20Sopenharmony_civoid   ocfs2_complete_mount_recovery(struct ocfs2_super *osb);
1858c2ecf20Sopenharmony_civoid ocfs2_complete_quota_recovery(struct ocfs2_super *osb);
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic inline void ocfs2_start_checkpoint(struct ocfs2_super *osb)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	wake_up(&osb->checkpoint_event);
1908c2ecf20Sopenharmony_ci}
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cistatic inline void ocfs2_checkpoint_inode(struct inode *inode)
1938c2ecf20Sopenharmony_ci{
1948c2ecf20Sopenharmony_ci	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	if (ocfs2_mount_local(osb))
1978c2ecf20Sopenharmony_ci		return;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	if (!ocfs2_ci_fully_checkpointed(INODE_CACHE(inode))) {
2008c2ecf20Sopenharmony_ci		/* WARNING: This only kicks off a single
2018c2ecf20Sopenharmony_ci		 * checkpoint. If someone races you and adds more
2028c2ecf20Sopenharmony_ci		 * metadata to the journal, you won't know, and will
2038c2ecf20Sopenharmony_ci		 * wind up waiting *a lot* longer than necessary. Right
2048c2ecf20Sopenharmony_ci		 * now we only use this in clear_inode so that's
2058c2ecf20Sopenharmony_ci		 * OK. */
2068c2ecf20Sopenharmony_ci		ocfs2_start_checkpoint(osb);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci		wait_event(osb->journal->j_checkpointed,
2098c2ecf20Sopenharmony_ci			   ocfs2_ci_fully_checkpointed(INODE_CACHE(inode)));
2108c2ecf20Sopenharmony_ci	}
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci/*
2148c2ecf20Sopenharmony_ci *  Transaction Handling:
2158c2ecf20Sopenharmony_ci *  Manage the lifetime of a transaction handle.
2168c2ecf20Sopenharmony_ci *
2178c2ecf20Sopenharmony_ci *  ocfs2_start_trans      - Begin a transaction. Give it an upper estimate of
2188c2ecf20Sopenharmony_ci *                          the number of blocks that will be changed during
2198c2ecf20Sopenharmony_ci *                          this handle.
2208c2ecf20Sopenharmony_ci *  ocfs2_commit_trans - Complete a handle. It might return -EIO if
2218c2ecf20Sopenharmony_ci *                       the journal was aborted. The majority of paths don't
2228c2ecf20Sopenharmony_ci *                       check the return value as an error there comes too
2238c2ecf20Sopenharmony_ci *                       late to do anything (and will be picked up in a
2248c2ecf20Sopenharmony_ci *                       later transaction).
2258c2ecf20Sopenharmony_ci *  ocfs2_extend_trans     - Extend a handle by nblocks credits. This may
2268c2ecf20Sopenharmony_ci *                          commit the handle to disk in the process, but will
2278c2ecf20Sopenharmony_ci *                          not release any locks taken during the transaction.
2288c2ecf20Sopenharmony_ci *  ocfs2_journal_access* - Notify the handle that we want to journal this
2298c2ecf20Sopenharmony_ci *                          buffer. Will have to call ocfs2_journal_dirty once
2308c2ecf20Sopenharmony_ci *                          we've actually dirtied it. Type is one of . or .
2318c2ecf20Sopenharmony_ci *                          Always call the specific flavor of
2328c2ecf20Sopenharmony_ci *                          ocfs2_journal_access_*() unless you intend to
2338c2ecf20Sopenharmony_ci *                          manage the checksum by hand.
2348c2ecf20Sopenharmony_ci *  ocfs2_journal_dirty    - Mark a journalled buffer as having dirty data.
2358c2ecf20Sopenharmony_ci *  ocfs2_jbd2_inode_add_write  - Mark an inode with range so that its data goes
2368c2ecf20Sopenharmony_ci *                                out before the current handle commits.
2378c2ecf20Sopenharmony_ci */
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci/* You must always start_trans with a number of buffs > 0, but it's
2408c2ecf20Sopenharmony_ci * perfectly legal to go through an entire transaction without having
2418c2ecf20Sopenharmony_ci * dirtied any buffers. */
2428c2ecf20Sopenharmony_cihandle_t		    *ocfs2_start_trans(struct ocfs2_super *osb,
2438c2ecf20Sopenharmony_ci					       int max_buffs);
2448c2ecf20Sopenharmony_ciint			     ocfs2_commit_trans(struct ocfs2_super *osb,
2458c2ecf20Sopenharmony_ci						handle_t *handle);
2468c2ecf20Sopenharmony_ciint			     ocfs2_extend_trans(handle_t *handle, int nblocks);
2478c2ecf20Sopenharmony_ciint			     ocfs2_allocate_extend_trans(handle_t *handle,
2488c2ecf20Sopenharmony_ci						int thresh);
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/*
2518c2ecf20Sopenharmony_ci * Define an arbitrary limit for the amount of data we will anticipate
2528c2ecf20Sopenharmony_ci * writing to any given transaction.  For unbounded transactions such as
2538c2ecf20Sopenharmony_ci * fallocate(2) we can write more than this, but we always
2548c2ecf20Sopenharmony_ci * start off at the maximum transaction size and grow the transaction
2558c2ecf20Sopenharmony_ci * optimistically as we go.
2568c2ecf20Sopenharmony_ci */
2578c2ecf20Sopenharmony_ci#define OCFS2_MAX_TRANS_DATA	64U
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci/*
2608c2ecf20Sopenharmony_ci * Create access is for when we get a newly created buffer and we're
2618c2ecf20Sopenharmony_ci * not gonna read it off disk, but rather fill it ourselves.  Right
2628c2ecf20Sopenharmony_ci * now, we don't do anything special with this (it turns into a write
2638c2ecf20Sopenharmony_ci * request), but this is a good placeholder in case we do...
2648c2ecf20Sopenharmony_ci *
2658c2ecf20Sopenharmony_ci * Write access is for when we read a block off disk and are going to
2668c2ecf20Sopenharmony_ci * modify it. This way the journalling layer knows it may need to make
2678c2ecf20Sopenharmony_ci * a copy of that block (if it's part of another, uncommitted
2688c2ecf20Sopenharmony_ci * transaction) before we do so.
2698c2ecf20Sopenharmony_ci */
2708c2ecf20Sopenharmony_ci#define OCFS2_JOURNAL_ACCESS_CREATE 0
2718c2ecf20Sopenharmony_ci#define OCFS2_JOURNAL_ACCESS_WRITE  1
2728c2ecf20Sopenharmony_ci#define OCFS2_JOURNAL_ACCESS_UNDO   2
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci/* ocfs2_inode */
2768c2ecf20Sopenharmony_ciint ocfs2_journal_access_di(handle_t *handle, struct ocfs2_caching_info *ci,
2778c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2788c2ecf20Sopenharmony_ci/* ocfs2_extent_block */
2798c2ecf20Sopenharmony_ciint ocfs2_journal_access_eb(handle_t *handle, struct ocfs2_caching_info *ci,
2808c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2818c2ecf20Sopenharmony_ci/* ocfs2_refcount_block */
2828c2ecf20Sopenharmony_ciint ocfs2_journal_access_rb(handle_t *handle, struct ocfs2_caching_info *ci,
2838c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2848c2ecf20Sopenharmony_ci/* ocfs2_group_desc */
2858c2ecf20Sopenharmony_ciint ocfs2_journal_access_gd(handle_t *handle, struct ocfs2_caching_info *ci,
2868c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2878c2ecf20Sopenharmony_ci/* ocfs2_xattr_block */
2888c2ecf20Sopenharmony_ciint ocfs2_journal_access_xb(handle_t *handle, struct ocfs2_caching_info *ci,
2898c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2908c2ecf20Sopenharmony_ci/* quota blocks */
2918c2ecf20Sopenharmony_ciint ocfs2_journal_access_dq(handle_t *handle, struct ocfs2_caching_info *ci,
2928c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2938c2ecf20Sopenharmony_ci/* dirblock */
2948c2ecf20Sopenharmony_ciint ocfs2_journal_access_db(handle_t *handle, struct ocfs2_caching_info *ci,
2958c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2968c2ecf20Sopenharmony_ci/* ocfs2_dx_root_block */
2978c2ecf20Sopenharmony_ciint ocfs2_journal_access_dr(handle_t *handle, struct ocfs2_caching_info *ci,
2988c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
2998c2ecf20Sopenharmony_ci/* ocfs2_dx_leaf */
3008c2ecf20Sopenharmony_ciint ocfs2_journal_access_dl(handle_t *handle, struct ocfs2_caching_info *ci,
3018c2ecf20Sopenharmony_ci			    struct buffer_head *bh, int type);
3028c2ecf20Sopenharmony_ci/* Anything that has no ecc */
3038c2ecf20Sopenharmony_ciint ocfs2_journal_access(handle_t *handle, struct ocfs2_caching_info *ci,
3048c2ecf20Sopenharmony_ci			 struct buffer_head *bh, int type);
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci/*
3078c2ecf20Sopenharmony_ci * A word about the journal_access/journal_dirty "dance". It is
3088c2ecf20Sopenharmony_ci * entirely legal to journal_access a buffer more than once (as long
3098c2ecf20Sopenharmony_ci * as the access type is the same -- I'm not sure what will happen if
3108c2ecf20Sopenharmony_ci * access type is different but this should never happen anyway) It is
3118c2ecf20Sopenharmony_ci * also legal to journal_dirty a buffer more than once. In fact, you
3128c2ecf20Sopenharmony_ci * can even journal_access a buffer after you've done a
3138c2ecf20Sopenharmony_ci * journal_access/journal_dirty pair. The only thing you cannot do
3148c2ecf20Sopenharmony_ci * however, is journal_dirty a buffer which you haven't yet passed to
3158c2ecf20Sopenharmony_ci * journal_access at least once.
3168c2ecf20Sopenharmony_ci *
3178c2ecf20Sopenharmony_ci * That said, 99% of the time this doesn't matter and this is what the
3188c2ecf20Sopenharmony_ci * path looks like:
3198c2ecf20Sopenharmony_ci *
3208c2ecf20Sopenharmony_ci *	<read a bh>
3218c2ecf20Sopenharmony_ci *	ocfs2_journal_access(handle, bh,	OCFS2_JOURNAL_ACCESS_WRITE);
3228c2ecf20Sopenharmony_ci *	<modify the bh>
3238c2ecf20Sopenharmony_ci * 	ocfs2_journal_dirty(handle, bh);
3248c2ecf20Sopenharmony_ci */
3258c2ecf20Sopenharmony_civoid ocfs2_journal_dirty(handle_t *handle, struct buffer_head *bh);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/*
3288c2ecf20Sopenharmony_ci *  Credit Macros:
3298c2ecf20Sopenharmony_ci *  Convenience macros to calculate number of credits needed.
3308c2ecf20Sopenharmony_ci *
3318c2ecf20Sopenharmony_ci *  For convenience sake, I have a set of macros here which calculate
3328c2ecf20Sopenharmony_ci *  the *maximum* number of sectors which will be changed for various
3338c2ecf20Sopenharmony_ci *  metadata updates.
3348c2ecf20Sopenharmony_ci */
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci/* simple file updates like chmod, etc. */
3378c2ecf20Sopenharmony_ci#define OCFS2_INODE_UPDATE_CREDITS 1
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci/* extended attribute block update */
3408c2ecf20Sopenharmony_ci#define OCFS2_XATTR_BLOCK_UPDATE_CREDITS 1
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci/* Update of a single quota block */
3438c2ecf20Sopenharmony_ci#define OCFS2_QUOTA_BLOCK_UPDATE_CREDITS 1
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci/* global quotafile inode update, data block */
3468c2ecf20Sopenharmony_ci#define OCFS2_QINFO_WRITE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + \
3478c2ecf20Sopenharmony_ci				   OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci#define OCFS2_LOCAL_QINFO_WRITE_CREDITS OCFS2_QUOTA_BLOCK_UPDATE_CREDITS
3508c2ecf20Sopenharmony_ci/*
3518c2ecf20Sopenharmony_ci * The two writes below can accidentally see global info dirty due
3528c2ecf20Sopenharmony_ci * to set_info() quotactl so make them prepared for the writes.
3538c2ecf20Sopenharmony_ci */
3548c2ecf20Sopenharmony_ci/* quota data block, global info */
3558c2ecf20Sopenharmony_ci/* Write to local quota file */
3568c2ecf20Sopenharmony_ci#define OCFS2_QWRITE_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \
3578c2ecf20Sopenharmony_ci			      OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci/* global quota data block, local quota data block, global quota inode,
3608c2ecf20Sopenharmony_ci * global quota info */
3618c2ecf20Sopenharmony_ci#define OCFS2_QSYNC_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \
3628c2ecf20Sopenharmony_ci			     2 * OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistatic inline int ocfs2_quota_trans_credits(struct super_block *sb)
3658c2ecf20Sopenharmony_ci{
3668c2ecf20Sopenharmony_ci	int credits = 0;
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci	if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA))
3698c2ecf20Sopenharmony_ci		credits += OCFS2_QWRITE_CREDITS;
3708c2ecf20Sopenharmony_ci	if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA))
3718c2ecf20Sopenharmony_ci		credits += OCFS2_QWRITE_CREDITS;
3728c2ecf20Sopenharmony_ci	return credits;
3738c2ecf20Sopenharmony_ci}
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci/* group extend. inode update and last group update. */
3768c2ecf20Sopenharmony_ci#define OCFS2_GROUP_EXTEND_CREDITS	(OCFS2_INODE_UPDATE_CREDITS + 1)
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci/* group add. inode update and the new group update. */
3798c2ecf20Sopenharmony_ci#define OCFS2_GROUP_ADD_CREDITS	(OCFS2_INODE_UPDATE_CREDITS + 1)
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci/* get one bit out of a suballocator: dinode + group descriptor +
3828c2ecf20Sopenharmony_ci * prev. group desc. if we relink. */
3838c2ecf20Sopenharmony_ci#define OCFS2_SUBALLOC_ALLOC (3)
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic inline int ocfs2_inline_to_extents_credits(struct super_block *sb)
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	return OCFS2_SUBALLOC_ALLOC + OCFS2_INODE_UPDATE_CREDITS +
3888c2ecf20Sopenharmony_ci	       ocfs2_quota_trans_credits(sb);
3898c2ecf20Sopenharmony_ci}
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci/* dinode + group descriptor update. We don't relink on free yet. */
3928c2ecf20Sopenharmony_ci#define OCFS2_SUBALLOC_FREE  (2)
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci#define OCFS2_TRUNCATE_LOG_UPDATE OCFS2_INODE_UPDATE_CREDITS
3958c2ecf20Sopenharmony_ci#define OCFS2_TRUNCATE_LOG_FLUSH_ONE_REC (OCFS2_SUBALLOC_FREE 		      \
3968c2ecf20Sopenharmony_ci					 + OCFS2_TRUNCATE_LOG_UPDATE)
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_cistatic inline int ocfs2_remove_extent_credits(struct super_block *sb)
3998c2ecf20Sopenharmony_ci{
4008c2ecf20Sopenharmony_ci	return OCFS2_TRUNCATE_LOG_UPDATE + OCFS2_INODE_UPDATE_CREDITS +
4018c2ecf20Sopenharmony_ci	       ocfs2_quota_trans_credits(sb);
4028c2ecf20Sopenharmony_ci}
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci/* data block for new dir/symlink, allocation of directory block, dx_root
4058c2ecf20Sopenharmony_ci * update for free list */
4068c2ecf20Sopenharmony_ci#define OCFS2_DIR_LINK_ADDITIONAL_CREDITS (1 + OCFS2_SUBALLOC_ALLOC + 1)
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistatic inline int ocfs2_add_dir_index_credits(struct super_block *sb)
4098c2ecf20Sopenharmony_ci{
4108c2ecf20Sopenharmony_ci	/* 1 block for index, 2 allocs (data, metadata), 1 clusters
4118c2ecf20Sopenharmony_ci	 * worth of blocks for initial extent. */
4128c2ecf20Sopenharmony_ci	return 1 + 2 * OCFS2_SUBALLOC_ALLOC +
4138c2ecf20Sopenharmony_ci		ocfs2_clusters_to_blocks(sb, 1);
4148c2ecf20Sopenharmony_ci}
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci/* parent fe, parent block, new file entry, index leaf, inode alloc fe, inode
4178c2ecf20Sopenharmony_ci * alloc group descriptor + mkdir/symlink blocks + dir blocks + xattr
4188c2ecf20Sopenharmony_ci * blocks + quota update */
4198c2ecf20Sopenharmony_cistatic inline int ocfs2_mknod_credits(struct super_block *sb, int is_dir,
4208c2ecf20Sopenharmony_ci				      int xattr_credits)
4218c2ecf20Sopenharmony_ci{
4228c2ecf20Sopenharmony_ci	int dir_credits = OCFS2_DIR_LINK_ADDITIONAL_CREDITS;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	if (is_dir)
4258c2ecf20Sopenharmony_ci		dir_credits += ocfs2_add_dir_index_credits(sb);
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci	return 4 + OCFS2_SUBALLOC_ALLOC + dir_credits + xattr_credits +
4288c2ecf20Sopenharmony_ci	       ocfs2_quota_trans_credits(sb);
4298c2ecf20Sopenharmony_ci}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/* local alloc metadata change + main bitmap updates */
4328c2ecf20Sopenharmony_ci#define OCFS2_WINDOW_MOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS                 \
4338c2ecf20Sopenharmony_ci				  + OCFS2_SUBALLOC_ALLOC + OCFS2_SUBALLOC_FREE)
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci/* used when we don't need an allocation change for a dir extend. One
4368c2ecf20Sopenharmony_ci * for the dinode, one for the new block. */
4378c2ecf20Sopenharmony_ci#define OCFS2_SIMPLE_DIR_EXTEND_CREDITS (2)
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci/* file update (nlink, etc) + directory mtime/ctime + dir entry block + quota
4408c2ecf20Sopenharmony_ci * update on dir + index leaf + dx root update for free list +
4418c2ecf20Sopenharmony_ci * previous dirblock update in the free list */
4428c2ecf20Sopenharmony_cistatic inline int ocfs2_link_credits(struct super_block *sb)
4438c2ecf20Sopenharmony_ci{
4448c2ecf20Sopenharmony_ci	return 2 * OCFS2_INODE_UPDATE_CREDITS + 4 +
4458c2ecf20Sopenharmony_ci	       ocfs2_quota_trans_credits(sb);
4468c2ecf20Sopenharmony_ci}
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci/* inode + dir inode (if we unlink a dir), + dir entry block + orphan
4498c2ecf20Sopenharmony_ci * dir inode link + dir inode index leaf + dir index root */
4508c2ecf20Sopenharmony_cistatic inline int ocfs2_unlink_credits(struct super_block *sb)
4518c2ecf20Sopenharmony_ci{
4528c2ecf20Sopenharmony_ci	/* The quota update from ocfs2_link_credits is unused here... */
4538c2ecf20Sopenharmony_ci	return 2 * OCFS2_INODE_UPDATE_CREDITS + 3 + ocfs2_link_credits(sb);
4548c2ecf20Sopenharmony_ci}
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci/* dinode + orphan dir dinode + inode alloc dinode + orphan dir entry +
4578c2ecf20Sopenharmony_ci * inode alloc group descriptor + orphan dir index root +
4588c2ecf20Sopenharmony_ci * orphan dir index leaf */
4598c2ecf20Sopenharmony_ci#define OCFS2_DELETE_INODE_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 4)
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci/* dinode + orphan dir dinode + extent tree leaf block + orphan dir entry +
4628c2ecf20Sopenharmony_ci * orphan dir index root + orphan dir index leaf */
4638c2ecf20Sopenharmony_ci#define OCFS2_INODE_ADD_TO_ORPHAN_CREDITS  (2 * OCFS2_INODE_UPDATE_CREDITS + 4)
4648c2ecf20Sopenharmony_ci#define OCFS2_INODE_DEL_FROM_ORPHAN_CREDITS  OCFS2_INODE_ADD_TO_ORPHAN_CREDITS
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci/* dinode update, old dir dinode update, new dir dinode update, old
4678c2ecf20Sopenharmony_ci * dir dir entry, new dir dir entry, dir entry update for renaming
4688c2ecf20Sopenharmony_ci * directory + target unlink + 3 x dir index leaves */
4698c2ecf20Sopenharmony_cistatic inline int ocfs2_rename_credits(struct super_block *sb)
4708c2ecf20Sopenharmony_ci{
4718c2ecf20Sopenharmony_ci	return 3 * OCFS2_INODE_UPDATE_CREDITS + 6 + ocfs2_unlink_credits(sb);
4728c2ecf20Sopenharmony_ci}
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci/* global bitmap dinode, group desc., relinked group,
4758c2ecf20Sopenharmony_ci * suballocator dinode, group desc., relinked group,
4768c2ecf20Sopenharmony_ci * dinode, xattr block */
4778c2ecf20Sopenharmony_ci#define OCFS2_XATTR_BLOCK_CREATE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + \
4788c2ecf20Sopenharmony_ci					  + OCFS2_INODE_UPDATE_CREDITS \
4798c2ecf20Sopenharmony_ci					  + OCFS2_XATTR_BLOCK_UPDATE_CREDITS)
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci/* inode update, removal of dx root block from allocator */
4828c2ecf20Sopenharmony_ci#define OCFS2_DX_ROOT_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS +	\
4838c2ecf20Sopenharmony_ci				      OCFS2_SUBALLOC_FREE)
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_cistatic inline int ocfs2_calc_dxi_expand_credits(struct super_block *sb)
4868c2ecf20Sopenharmony_ci{
4878c2ecf20Sopenharmony_ci	int credits = 1 + OCFS2_SUBALLOC_ALLOC;
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	credits += ocfs2_clusters_to_blocks(sb, 1);
4908c2ecf20Sopenharmony_ci	credits += ocfs2_quota_trans_credits(sb);
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	return credits;
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci/* inode update, new refcount block and its allocation credits. */
4968c2ecf20Sopenharmony_ci#define OCFS2_REFCOUNT_TREE_CREATE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1 \
4978c2ecf20Sopenharmony_ci					    + OCFS2_SUBALLOC_ALLOC)
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci/* inode and the refcount block update. */
5008c2ecf20Sopenharmony_ci#define OCFS2_REFCOUNT_TREE_SET_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci/*
5038c2ecf20Sopenharmony_ci * inode and the refcount block update.
5048c2ecf20Sopenharmony_ci * It doesn't include the credits for sub alloc change.
5058c2ecf20Sopenharmony_ci * So if we need to free the bit, OCFS2_SUBALLOC_FREE needs to be added.
5068c2ecf20Sopenharmony_ci */
5078c2ecf20Sopenharmony_ci#define OCFS2_REFCOUNT_TREE_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci/* 2 metadata alloc, 2 new blocks and root refcount block */
5108c2ecf20Sopenharmony_ci#define OCFS2_EXPAND_REFCOUNT_TREE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + 3)
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci/*
5138c2ecf20Sopenharmony_ci * Please note that the caller must make sure that root_el is the root
5148c2ecf20Sopenharmony_ci * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
5158c2ecf20Sopenharmony_ci * the result may be wrong.
5168c2ecf20Sopenharmony_ci */
5178c2ecf20Sopenharmony_cistatic inline int ocfs2_calc_extend_credits(struct super_block *sb,
5188c2ecf20Sopenharmony_ci					    struct ocfs2_extent_list *root_el)
5198c2ecf20Sopenharmony_ci{
5208c2ecf20Sopenharmony_ci	int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks;
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci	/* bitmap dinode, group desc. + relinked group. */
5238c2ecf20Sopenharmony_ci	bitmap_blocks = OCFS2_SUBALLOC_ALLOC;
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci	/* we might need to shift tree depth so lets assume an
5268c2ecf20Sopenharmony_ci	 * absolute worst case of complete fragmentation.  Even with
5278c2ecf20Sopenharmony_ci	 * that, we only need one update for the dinode, and then
5288c2ecf20Sopenharmony_ci	 * however many metadata chunks needed * a remaining suballoc
5298c2ecf20Sopenharmony_ci	 * alloc. */
5308c2ecf20Sopenharmony_ci	sysfile_bitmap_blocks = 1 +
5318c2ecf20Sopenharmony_ci		(OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(root_el);
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci	/* this does not include *new* metadata blocks, which are
5348c2ecf20Sopenharmony_ci	 * accounted for in sysfile_bitmap_blocks. root_el +
5358c2ecf20Sopenharmony_ci	 * prev. last_eb_blk + blocks along edge of tree.
5368c2ecf20Sopenharmony_ci	 * calc_symlink_credits passes because we just need 1
5378c2ecf20Sopenharmony_ci	 * credit for the dinode there. */
5388c2ecf20Sopenharmony_ci	extent_blocks = 1 + 1 + le16_to_cpu(root_el->l_tree_depth);
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci	return bitmap_blocks + sysfile_bitmap_blocks + extent_blocks +
5418c2ecf20Sopenharmony_ci	       ocfs2_quota_trans_credits(sb);
5428c2ecf20Sopenharmony_ci}
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_cistatic inline int ocfs2_calc_symlink_credits(struct super_block *sb)
5458c2ecf20Sopenharmony_ci{
5468c2ecf20Sopenharmony_ci	int blocks = ocfs2_mknod_credits(sb, 0, 0);
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci	/* links can be longer than one block so we may update many
5498c2ecf20Sopenharmony_ci	 * within our single allocated extent. */
5508c2ecf20Sopenharmony_ci	blocks += ocfs2_clusters_to_blocks(sb, 1);
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	return blocks + ocfs2_quota_trans_credits(sb);
5538c2ecf20Sopenharmony_ci}
5548c2ecf20Sopenharmony_ci
5558c2ecf20Sopenharmony_cistatic inline int ocfs2_calc_group_alloc_credits(struct super_block *sb,
5568c2ecf20Sopenharmony_ci						 unsigned int cpg)
5578c2ecf20Sopenharmony_ci{
5588c2ecf20Sopenharmony_ci	int blocks;
5598c2ecf20Sopenharmony_ci	int bitmap_blocks = OCFS2_SUBALLOC_ALLOC + 1;
5608c2ecf20Sopenharmony_ci	/* parent inode update + new block group header + bitmap inode update
5618c2ecf20Sopenharmony_ci	   + bitmap blocks affected */
5628c2ecf20Sopenharmony_ci	blocks = 1 + 1 + 1 + bitmap_blocks;
5638c2ecf20Sopenharmony_ci	return blocks;
5648c2ecf20Sopenharmony_ci}
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci/*
5678c2ecf20Sopenharmony_ci * Allocating a discontiguous block group requires the credits from
5688c2ecf20Sopenharmony_ci * ocfs2_calc_group_alloc_credits() as well as enough credits to fill
5698c2ecf20Sopenharmony_ci * the group descriptor's extent list.  The caller already has started
5708c2ecf20Sopenharmony_ci * the transaction with ocfs2_calc_group_alloc_credits().  They extend
5718c2ecf20Sopenharmony_ci * it with these credits.
5728c2ecf20Sopenharmony_ci */
5738c2ecf20Sopenharmony_cistatic inline int ocfs2_calc_bg_discontig_credits(struct super_block *sb)
5748c2ecf20Sopenharmony_ci{
5758c2ecf20Sopenharmony_ci	return ocfs2_extent_recs_per_gd(sb);
5768c2ecf20Sopenharmony_ci}
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_cistatic inline int ocfs2_jbd2_inode_add_write(handle_t *handle, struct inode *inode,
5798c2ecf20Sopenharmony_ci					     loff_t start_byte, loff_t length)
5808c2ecf20Sopenharmony_ci{
5818c2ecf20Sopenharmony_ci	return jbd2_journal_inode_ranged_write(handle,
5828c2ecf20Sopenharmony_ci					       &OCFS2_I(inode)->ip_jinode,
5838c2ecf20Sopenharmony_ci					       start_byte, length);
5848c2ecf20Sopenharmony_ci}
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_cistatic inline int ocfs2_begin_ordered_truncate(struct inode *inode,
5878c2ecf20Sopenharmony_ci					       loff_t new_size)
5888c2ecf20Sopenharmony_ci{
5898c2ecf20Sopenharmony_ci	return jbd2_journal_begin_ordered_truncate(
5908c2ecf20Sopenharmony_ci				OCFS2_SB(inode->i_sb)->journal->j_journal,
5918c2ecf20Sopenharmony_ci				&OCFS2_I(inode)->ip_jinode,
5928c2ecf20Sopenharmony_ci				new_size);
5938c2ecf20Sopenharmony_ci}
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_cistatic inline void ocfs2_update_inode_fsync_trans(handle_t *handle,
5968c2ecf20Sopenharmony_ci						  struct inode *inode,
5978c2ecf20Sopenharmony_ci						  int datasync)
5988c2ecf20Sopenharmony_ci{
5998c2ecf20Sopenharmony_ci	struct ocfs2_inode_info *oi = OCFS2_I(inode);
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci	if (!is_handle_aborted(handle)) {
6028c2ecf20Sopenharmony_ci		oi->i_sync_tid = handle->h_transaction->t_tid;
6038c2ecf20Sopenharmony_ci		if (datasync)
6048c2ecf20Sopenharmony_ci			oi->i_datasync_tid = handle->h_transaction->t_tid;
6058c2ecf20Sopenharmony_ci	}
6068c2ecf20Sopenharmony_ci}
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci#endif /* OCFS2_JOURNAL_H */
609