journal.h revision 2b1e55c389105b722cccadfa47f5615f57d8887f
1ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* -*- mode: c; c-basic-offset: 8; -*-
2ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * vim: noexpandtab sw=8 ts=8 sts=0:
3ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
4ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal.h
5ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
6ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Defines journalling api and structures.
7ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
8ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Copyright (C) 2003, 2005 Oracle.  All rights reserved.
9ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
10ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * This program is free software; you can redistribute it and/or
11ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * modify it under the terms of the GNU General Public
12ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * License as published by the Free Software Foundation; either
13ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * version 2 of the License, or (at your option) any later version.
14ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
15ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * This program is distributed in the hope that it will be useful,
16ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * but WITHOUT ANY WARRANTY; without even the implied warranty of
17ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * General Public License for more details.
19ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
20ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * You should have received a copy of the GNU General Public
21ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * License along with this program; if not, write to the
22ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Boston, MA 021110-1307, USA.
24ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
25ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
26ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#ifndef OCFS2_JOURNAL_H
27ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_H
28ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
29ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#include <linux/fs.h>
3053ef99cad9878f02f27bb30bc304fc42af8bdd6eMark Fasheh#include <linux/jbd2.h>
31ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
32ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehenum ocfs2_journal_state {
33ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	OCFS2_JOURNAL_FREE = 0,
34ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	OCFS2_JOURNAL_LOADED,
35ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	OCFS2_JOURNAL_IN_SHUTDOWN,
36ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh};
37ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
38ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstruct ocfs2_super;
39ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstruct ocfs2_dinode;
40ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
4196a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran/*
4296a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran * The recovery_list is a simple linked list of node numbers to recover.
4396a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran * It is protected by the recovery_lock.
4496a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran */
4596a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran
4696a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushranstruct ocfs2_recovery_map {
4796a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran	unsigned int rm_used;
4896a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran	unsigned int *rm_entries;
4996a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran};
5096a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran
5196a6c64b5354b804b3ccfd1b31306565a01ebcb1Sunil Mushran
52ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstruct ocfs2_journal {
53ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	enum ocfs2_journal_state   j_state;    /* Journals current state   */
54ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
55ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	journal_t                 *j_journal; /* The kernels journal type */
56ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct inode              *j_inode;   /* Kernel inode pointing to
57ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * this journal             */
58ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct ocfs2_super        *j_osb;     /* pointer to the super
59ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * block for the node
60ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * we're currently
61ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * running on -- not
62ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * necessarily the super
63ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * block from the node
64ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * which we usually run
65ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * from (recovery,
66ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * etc)                     */
67ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct buffer_head        *j_bh;      /* Journal disk inode block */
68ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	atomic_t                  j_num_trans; /* Number of transactions
69ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					        * currently in the system. */
7083fd9c7f65634ac440a6b9b7a63ba562f213ac60Goldwyn Rodrigues	spinlock_t                j_lock;
71ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	unsigned long             j_trans_id;
72ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct rw_semaphore       j_trans_barrier;
73ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	wait_queue_head_t         j_checkpointed;
74ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
7583fd9c7f65634ac440a6b9b7a63ba562f213ac60Goldwyn Rodrigues	/* both fields protected by j_lock*/
76ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct list_head          j_la_cleanups;
77ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct work_struct        j_recovery_work;
78ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh};
79ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
80ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehextern spinlock_t trans_inc_lock;
81ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
82ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* wrap j_trans_id so we never have it equal to zero. */
83ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline unsigned long ocfs2_inc_trans_id(struct ocfs2_journal *j)
84ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
85ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	unsigned long old_id;
86ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
87ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	old_id = j->j_trans_id++;
88ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (unlikely(!j->j_trans_id))
89ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		j->j_trans_id = 1;
90ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
91ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return old_id;
92ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
93ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
940cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline void ocfs2_set_ci_lock_trans(struct ocfs2_journal *journal,
950cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker					   struct ocfs2_caching_info *ci)
96ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
97ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
980cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	ci->ci_last_trans = journal->j_trans_id;
99ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
100ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
101ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
102ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* Used to figure out whether it's safe to drop a metadata lock on an
1030cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * cached object. Returns true if all the object's changes have been
104ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * checkpointed to disk. You should be holding the spinlock on the
105ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * metadata lock while calling this to be sure that nobody can take
106ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * the lock and put it on another transaction. */
1070cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline int ocfs2_ci_fully_checkpointed(struct ocfs2_caching_info *ci)
108ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
109ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int ret;
1100cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	struct ocfs2_journal *journal =
1110cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker		OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal;
112ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
113ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
1140cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	ret = time_after(journal->j_trans_id, ci->ci_last_trans);
115ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
116ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return ret;
117ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
118ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
1190cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker/* convenience function to check if an object backed by struct
1200cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * ocfs2_caching_info  is still new (has never hit disk) Will do you a
1210cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * favor and set created_trans = 0 when you've
1220cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * been checkpointed.  returns '1' if the ci is still new. */
1230cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline int ocfs2_ci_is_new(struct ocfs2_caching_info *ci)
124ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
125ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int ret;
1260cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	struct ocfs2_journal *journal =
1270cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker		OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal;
1280cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker
1290cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	spin_lock(&trans_inc_lock);
1300cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	ret = !(time_after(journal->j_trans_id, ci->ci_created_trans));
1310cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	if (!ret)
1320cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker		ci->ci_created_trans = 0;
1330cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	spin_unlock(&trans_inc_lock);
1340cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	return ret;
1350cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker}
136ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
1370cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker/* Wrapper for inodes so we can check system files */
1380cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline int ocfs2_inode_is_new(struct inode *inode)
1390cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker{
140ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* System files are never "new" as they're written out by
141ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * mkfs. This helps us early during mount, before we have the
142ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * journal open and j_trans_id could be junk. */
143ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE)
144ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		return 0;
1450cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker
1460cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	return ocfs2_ci_is_new(INODE_CACHE(inode));
147ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
148ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
1490cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline void ocfs2_ci_set_new(struct ocfs2_super *osb,
1500cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker				    struct ocfs2_caching_info *ci)
151ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
152ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
1530cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	ci->ci_created_trans = osb->journal->j_trans_id;
154ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
155ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
156ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
157ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* Exported only for the journal struct init code in super.c. Do not call. */
158df152c241df9e9d2b9a65d37bd02961abe7f591aSunil Mushranvoid ocfs2_orphan_scan_init(struct ocfs2_super *osb);
1598b712cd58adfe6aeeb0be4ecc011dc35620719e7Jeff Mahoneyvoid ocfs2_orphan_scan_start(struct ocfs2_super *osb);
16083273932fbefb6ceef9c0b82ac4d23900728f4d9Srinivas Eedavoid ocfs2_orphan_scan_stop(struct ocfs2_super *osb);
16183273932fbefb6ceef9c0b82ac4d23900728f4d9Srinivas Eedavoid ocfs2_orphan_scan_exit(struct ocfs2_super *osb);
16283273932fbefb6ceef9c0b82ac4d23900728f4d9Srinivas Eeda
163c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsvoid ocfs2_complete_recovery(struct work_struct *work);
164553abd046af609191a91af7289d87d477adc659fJoel Beckervoid ocfs2_wait_for_recovery(struct ocfs2_super *osb);
165553abd046af609191a91af7289d87d477adc659fJoel Becker
166553abd046af609191a91af7289d87d477adc659fJoel Beckerint ocfs2_recovery_init(struct ocfs2_super *osb);
167553abd046af609191a91af7289d87d477adc659fJoel Beckervoid ocfs2_recovery_exit(struct ocfs2_super *osb);
168ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
1699140db04ef185f934acf2b1b15b3dd5e6a6bfc22Srinivas Eedaint ocfs2_compute_replay_slots(struct ocfs2_super *osb);
170ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
171ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Journal Control:
172ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Initialize, Load, Shutdown, Wipe a journal.
173ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
174ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_init     - Initialize journal structures in the OSB.
175ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_load     - Load the given journal off disk. Replay it if
176ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          there's transactions still in there.
177ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_shutdown - Shutdown a journal, this will flush all
178ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          uncommitted, uncheckpointed transactions.
179ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_wipe     - Wipe transactions from a journal. Optionally
180ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          zero out each block.
181ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_recovery_thread  - Perform recovery on a node. osb is our own osb.
182ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_mark_dead_nodes - Start recovery on nodes we won't get a heartbeat
183ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          event on.
184ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_start_checkpoint - Kick the commit thread to do a checkpoint.
185ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
186ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_set_journal_params(struct ocfs2_super *osb);
187ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_journal_init(struct ocfs2_journal *journal,
188ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			  int *dirty);
189ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_journal_shutdown(struct ocfs2_super *osb);
190ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_journal_wipe(struct ocfs2_journal *journal,
191ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			  int full);
192539d8264093560b917ee3afe4c7f74e5da09d6a5Sunil Mushranint    ocfs2_journal_load(struct ocfs2_journal *journal, int local,
193539d8264093560b917ee3afe4c7f74e5da09d6a5Sunil Mushran			  int replayed);
194ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_check_journals_nolocks(struct ocfs2_super *osb);
195ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_recovery_thread(struct ocfs2_super *osb,
196ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			     int node_num);
197ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_mark_dead_nodes(struct ocfs2_super *osb);
198ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_complete_mount_recovery(struct ocfs2_super *osb);
1992205363dce7447b8e85f1ead14387664c1a98753Jan Karavoid ocfs2_complete_quota_recovery(struct ocfs2_super *osb);
200ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
201ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline void ocfs2_start_checkpoint(struct ocfs2_super *osb)
202ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
203ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	wake_up(&osb->checkpoint_event);
204ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
205ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
206ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline void ocfs2_checkpoint_inode(struct inode *inode)
207ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
208ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
209ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
210c271c5c22b0a7ca45fda15f1f4d258bca36a5b94Sunil Mushran	if (ocfs2_mount_local(osb))
211c271c5c22b0a7ca45fda15f1f4d258bca36a5b94Sunil Mushran		return;
212c271c5c22b0a7ca45fda15f1f4d258bca36a5b94Sunil Mushran
2130cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker	if (!ocfs2_ci_fully_checkpointed(INODE_CACHE(inode))) {
214ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		/* WARNING: This only kicks off a single
215ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * checkpoint. If someone races you and adds more
216ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * metadata to the journal, you won't know, and will
21725985edcedea6396277003854657b5f3cb31a628Lucas De Marchi		 * wind up waiting *a lot* longer than necessary. Right
218ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * now we only use this in clear_inode so that's
219ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * OK. */
220ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		ocfs2_start_checkpoint(osb);
221ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
222ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		wait_event(osb->journal->j_checkpointed,
2230cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker			   ocfs2_ci_fully_checkpointed(INODE_CACHE(inode)));
224ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	}
225ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
226ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
227ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
228ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Transaction Handling:
229ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Manage the lifetime of a transaction handle.
230ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
231ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_start_trans      - Begin a transaction. Give it an upper estimate of
232ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          the number of blocks that will be changed during
233ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          this handle.
2341fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *  ocfs2_commit_trans - Complete a handle. It might return -EIO if
2351fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       the journal was aborted. The majority of paths don't
2361fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       check the return value as an error there comes too
2371fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       late to do anything (and will be picked up in a
2381fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       later transaction).
239ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_extend_trans     - Extend a handle by nblocks credits. This may
240ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          commit the handle to disk in the process, but will
241ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          not release any locks taken during the transaction.
24250655ae9e91d272d48997bada59efe166aa5e343Joel Becker *  ocfs2_journal_access* - Notify the handle that we want to journal this
243ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          buffer. Will have to call ocfs2_journal_dirty once
244ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          we've actually dirtied it. Type is one of . or .
24550655ae9e91d272d48997bada59efe166aa5e343Joel Becker *                          Always call the specific flavor of
24650655ae9e91d272d48997bada59efe166aa5e343Joel Becker *                          ocfs2_journal_access_*() unless you intend to
24750655ae9e91d272d48997bada59efe166aa5e343Joel Becker *                          manage the checksum by hand.
248ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_dirty    - Mark a journalled buffer as having dirty data.
2492b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker *  ocfs2_jbd2_file_inode  - Mark an inode so that its data goes out before
2502b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker *                           the current handle commits.
251ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
252ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
253ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* You must always start_trans with a number of buffs > 0, but it's
254ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * perfectly legal to go through an entire transaction without having
255ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * dirtied any buffers. */
2561fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fashehhandle_t		    *ocfs2_start_trans(struct ocfs2_super *osb,
257ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       int max_buffs);
2581fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fashehint			     ocfs2_commit_trans(struct ocfs2_super *osb,
2591fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh						handle_t *handle);
2601fc581467e52546195c7ee8233a34d63c1cc1322Mark Fashehint			     ocfs2_extend_trans(handle_t *handle, int nblocks);
2612b1e55c389105b722cccadfa47f5615f57d8887fYounger Liuint			     ocfs2_allocate_extend_trans(handle_t *handle,
2622b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu						int thresh);
2632b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu
2642b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu/*
2652b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu * Define an arbitrary limit for the amount of data we will anticipate
2662b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu * writing to any given transaction.  For unbounded transactions such as
2672b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu * fallocate(2) we can write more than this, but we always
2682b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu * start off at the maximum transaction size and grow the transaction
2692b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu * optimistically as we go.
2702b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu */
2712b1e55c389105b722cccadfa47f5615f57d8887fYounger Liu#define OCFS2_MAX_TRANS_DATA	64U
272ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
273ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
274ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Create access is for when we get a newly created buffer and we're
275ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * not gonna read it off disk, but rather fill it ourselves.  Right
276ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * now, we don't do anything special with this (it turns into a write
277ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * request), but this is a good placeholder in case we do...
278ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
279ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Write access is for when we read a block off disk and are going to
280ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * modify it. This way the journalling layer knows it may need to make
281ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * a copy of that block (if it's part of another, uncommitted
282ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * transaction) before we do so.
283ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
284ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_CREATE 0
285ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_WRITE  1
286ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_UNDO   2
287ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
28813723d00e374c2a6d6ccb5af6de965e89c3e1b01Joel Becker
28950655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_inode */
2900cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_di(handle_t *handle, struct ocfs2_caching_info *ci,
29113723d00e374c2a6d6ccb5af6de965e89c3e1b01Joel Becker			    struct buffer_head *bh, int type);
29250655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_extent_block */
2930cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_eb(handle_t *handle, struct ocfs2_caching_info *ci,
29450655ae9e91d272d48997bada59efe166aa5e343Joel Becker			    struct buffer_head *bh, int type);
29593c97087a646429f4dc0d73298d64674ddd5cde8Tao Ma/* ocfs2_refcount_block */
29693c97087a646429f4dc0d73298d64674ddd5cde8Tao Maint ocfs2_journal_access_rb(handle_t *handle, struct ocfs2_caching_info *ci,
29793c97087a646429f4dc0d73298d64674ddd5cde8Tao Ma			    struct buffer_head *bh, int type);
29850655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_group_desc */
2990cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_gd(handle_t *handle, struct ocfs2_caching_info *ci,
30050655ae9e91d272d48997bada59efe166aa5e343Joel Becker			    struct buffer_head *bh, int type);
30150655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_xattr_block */
3020cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_xb(handle_t *handle, struct ocfs2_caching_info *ci,
30350655ae9e91d272d48997bada59efe166aa5e343Joel Becker			    struct buffer_head *bh, int type);
30450655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* quota blocks */
3050cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_dq(handle_t *handle, struct ocfs2_caching_info *ci,
30650655ae9e91d272d48997bada59efe166aa5e343Joel Becker			    struct buffer_head *bh, int type);
30750655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* dirblock */
3080cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_db(handle_t *handle, struct ocfs2_caching_info *ci,
30950655ae9e91d272d48997bada59efe166aa5e343Joel Becker			    struct buffer_head *bh, int type);
3109b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* ocfs2_dx_root_block */
3110cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_dr(handle_t *handle, struct ocfs2_caching_info *ci,
3129b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh			    struct buffer_head *bh, int type);
3139b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* ocfs2_dx_leaf */
3140cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_dl(handle_t *handle, struct ocfs2_caching_info *ci,
3159b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh			    struct buffer_head *bh, int type);
31650655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* Anything that has no ecc */
3170cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access(handle_t *handle, struct ocfs2_caching_info *ci,
31850655ae9e91d272d48997bada59efe166aa5e343Joel Becker			 struct buffer_head *bh, int type);
31950655ae9e91d272d48997bada59efe166aa5e343Joel Becker
320ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
321ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * A word about the journal_access/journal_dirty "dance". It is
322ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * entirely legal to journal_access a buffer more than once (as long
323ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * as the access type is the same -- I'm not sure what will happen if
324ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * access type is different but this should never happen anyway) It is
325ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * also legal to journal_dirty a buffer more than once. In fact, you
326ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * can even journal_access a buffer after you've done a
327ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal_access/journal_dirty pair. The only thing you cannot do
328ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * however, is journal_dirty a buffer which you haven't yet passed to
329ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal_access at least once.
330ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
331ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * That said, 99% of the time this doesn't matter and this is what the
332ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * path looks like:
333ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
334ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *	<read a bh>
335ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *	ocfs2_journal_access(handle, bh,	OCFS2_JOURNAL_ACCESS_WRITE);
336ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *	<modify the bh>
337ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * 	ocfs2_journal_dirty(handle, bh);
338ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
339ec20cec7a351584ca6c70ead012e73d61f9a8e04Joel Beckervoid ocfs2_journal_dirty(handle_t *handle, struct buffer_head *bh);
340ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
341ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
342ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Credit Macros:
343ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Convenience macros to calculate number of credits needed.
344ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
345ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  For convenience sake, I have a set of macros here which calculate
346ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  the *maximum* number of sectors which will be changed for various
347ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  metadata updates.
348ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
349ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
350ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* simple file updates like chmod, etc. */
351ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_INODE_UPDATE_CREDITS 1
352ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
353cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang/* extended attribute block update */
354cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang#define OCFS2_XATTR_BLOCK_UPDATE_CREDITS 1
355cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang
3560584974a77796581eb3a64b6c5005edac4a95128Jan Kara/* Update of a single quota block */
3570584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QUOTA_BLOCK_UPDATE_CREDITS 1
3580584974a77796581eb3a64b6c5005edac4a95128Jan Kara
359a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* global quotafile inode update, data block */
3600584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QINFO_WRITE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + \
3610584974a77796581eb3a64b6c5005edac4a95128Jan Kara				   OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
362a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara
3630584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_LOCAL_QINFO_WRITE_CREDITS OCFS2_QUOTA_BLOCK_UPDATE_CREDITS
364a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/*
365a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara * The two writes below can accidentally see global info dirty due
366a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara * to set_info() quotactl so make them prepared for the writes.
367a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara */
368a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* quota data block, global info */
369a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* Write to local quota file */
3700584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QWRITE_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \
3710584974a77796581eb3a64b6c5005edac4a95128Jan Kara			      OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
372a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara
373a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* global quota data block, local quota data block, global quota inode,
374a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara * global quota info */
3750584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QSYNC_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \
3760584974a77796581eb3a64b6c5005edac4a95128Jan Kara			     2 * OCFS2_QUOTA_BLOCK_UPDATE_CREDITS)
377a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara
378a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_quota_trans_credits(struct super_block *sb)
379a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{
380a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	int credits = 0;
381a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara
382a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA))
383a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara		credits += OCFS2_QWRITE_CREDITS;
384a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA))
385a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara		credits += OCFS2_QWRITE_CREDITS;
386a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	return credits;
387a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara}
388a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara
389d659072f736837e56b6433d58e5315ad1d4d5ccfTao Ma/* group extend. inode update and last group update. */
390d659072f736837e56b6433d58e5315ad1d4d5ccfTao Ma#define OCFS2_GROUP_EXTEND_CREDITS	(OCFS2_INODE_UPDATE_CREDITS + 1)
391d659072f736837e56b6433d58e5315ad1d4d5ccfTao Ma
3927909f2bf835376a20d6dbf853eb459a27566eba2Tao Ma/* group add. inode update and the new group update. */
3937909f2bf835376a20d6dbf853eb459a27566eba2Tao Ma#define OCFS2_GROUP_ADD_CREDITS	(OCFS2_INODE_UPDATE_CREDITS + 1)
3947909f2bf835376a20d6dbf853eb459a27566eba2Tao Ma
395ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* get one bit out of a suballocator: dinode + group descriptor +
396ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * prev. group desc. if we relink. */
397ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SUBALLOC_ALLOC (3)
398ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
399a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_inline_to_extents_credits(struct super_block *sb)
400a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{
401a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	return OCFS2_SUBALLOC_ALLOC + OCFS2_INODE_UPDATE_CREDITS +
402a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	       ocfs2_quota_trans_credits(sb);
403a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara}
4041afc32b952335f665327a1a9001ba1b44bb76fd9Mark Fasheh
405ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode + group descriptor update. We don't relink on free yet. */
406ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SUBALLOC_FREE  (2)
407ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
408ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_TRUNCATE_LOG_UPDATE OCFS2_INODE_UPDATE_CREDITS
409ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_TRUNCATE_LOG_FLUSH_ONE_REC (OCFS2_SUBALLOC_FREE 		      \
410ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					 + OCFS2_TRUNCATE_LOG_UPDATE)
411ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
412a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_remove_extent_credits(struct super_block *sb)
413a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{
414a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	return OCFS2_TRUNCATE_LOG_UPDATE + OCFS2_INODE_UPDATE_CREDITS +
415a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	       ocfs2_quota_trans_credits(sb);
416a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara}
417063c4561f52a74de686fe0ff2f96f4f54c9fecd2Mark Fasheh
418705773a6656bba66f2a80a44ddaacf9620df8a59Jan Kara/* data block for new dir/symlink, allocation of directory block, dx_root
419705773a6656bba66f2a80a44ddaacf9620df8a59Jan Kara * update for free list */
420705773a6656bba66f2a80a44ddaacf9620df8a59Jan Kara#define OCFS2_DIR_LINK_ADDITIONAL_CREDITS (1 + OCFS2_SUBALLOC_ALLOC + 1)
421ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
4229b7895efac906d66d19856194e1ba61f37e231a4Mark Fashehstatic inline int ocfs2_add_dir_index_credits(struct super_block *sb)
4239b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh{
4249b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	/* 1 block for index, 2 allocs (data, metadata), 1 clusters
4259b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	 * worth of blocks for initial extent. */
4269b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	return 1 + 2 * OCFS2_SUBALLOC_ALLOC +
4279b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh		ocfs2_clusters_to_blocks(sb, 1);
4289b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh}
4299b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh
4309b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* parent fe, parent block, new file entry, index leaf, inode alloc fe, inode
4319b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh * alloc group descriptor + mkdir/symlink blocks + dir blocks + xattr
4329b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh * blocks + quota update */
4339b7895efac906d66d19856194e1ba61f37e231a4Mark Fashehstatic inline int ocfs2_mknod_credits(struct super_block *sb, int is_dir,
4349b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh				      int xattr_credits)
435a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{
4369b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	int dir_credits = OCFS2_DIR_LINK_ADDITIONAL_CREDITS;
4379b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh
4389b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	if (is_dir)
4399b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh		dir_credits += ocfs2_add_dir_index_credits(sb);
4409b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh
4419b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	return 4 + OCFS2_SUBALLOC_ALLOC + dir_credits + xattr_credits +
442a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	       ocfs2_quota_trans_credits(sb);
443a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara}
444ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
445ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* local alloc metadata change + main bitmap updates */
446ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_WINDOW_MOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS                 \
447ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh				  + OCFS2_SUBALLOC_ALLOC + OCFS2_SUBALLOC_FREE)
448ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
449ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* used when we don't need an allocation change for a dir extend. One
450ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * for the dinode, one for the new block. */
451ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SIMPLE_DIR_EXTEND_CREDITS (2)
452ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
453a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* file update (nlink, etc) + directory mtime/ctime + dir entry block + quota
4540393afea31874947b1d149b82d17b7dccac4f210Xiaowei.Hu * update on dir + index leaf + dx root update for free list +
4550393afea31874947b1d149b82d17b7dccac4f210Xiaowei.Hu * previous dirblock update in the free list */
456a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_link_credits(struct super_block *sb)
457a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{
4580393afea31874947b1d149b82d17b7dccac4f210Xiaowei.Hu	return 2*OCFS2_INODE_UPDATE_CREDITS + 4 +
459a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	       ocfs2_quota_trans_credits(sb);
460a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara}
461ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
462ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* inode + dir inode (if we unlink a dir), + dir entry block + orphan
463e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh * dir inode link + dir inode index leaf + dir index root */
464a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_unlink_credits(struct super_block *sb)
465a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{
466a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	/* The quota update from ocfs2_link_credits is unused here... */
467e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh	return 2 * OCFS2_INODE_UPDATE_CREDITS + 3 + ocfs2_link_credits(sb);
468a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara}
469ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
470ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode + orphan dir dinode + inode alloc dinode + orphan dir entry +
471dfa13f39b798fee68250abe1aed851395c8b51b5Joel Becker * inode alloc group descriptor + orphan dir index root +
472dfa13f39b798fee68250abe1aed851395c8b51b5Joel Becker * orphan dir index leaf */
473dfa13f39b798fee68250abe1aed851395c8b51b5Joel Becker#define OCFS2_DELETE_INODE_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 4)
474ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
475ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode update, old dir dinode update, new dir dinode update, old
476ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * dir dir entry, new dir dir entry, dir entry update for renaming
4779b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh * directory + target unlink + 3 x dir index leaves */
478a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_rename_credits(struct super_block *sb)
479a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{
4809b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	return 3 * OCFS2_INODE_UPDATE_CREDITS + 6 + ocfs2_unlink_credits(sb);
481a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara}
482ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
483cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang/* global bitmap dinode, group desc., relinked group,
484cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang * suballocator dinode, group desc., relinked group,
485cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang * dinode, xattr block */
486cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang#define OCFS2_XATTR_BLOCK_CREATE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + \
487cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang					  + OCFS2_INODE_UPDATE_CREDITS \
488cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang					  + OCFS2_XATTR_BLOCK_UPDATE_CREDITS)
489cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang
4909b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* inode update, removal of dx root block from allocator */
4919b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh#define OCFS2_DX_ROOT_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS +	\
4929b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh				      OCFS2_SUBALLOC_FREE)
4939b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh
4944ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fashehstatic inline int ocfs2_calc_dxi_expand_credits(struct super_block *sb)
4954ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh{
4964ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh	int credits = 1 + OCFS2_SUBALLOC_ALLOC;
4974ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh
4984ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh	credits += ocfs2_clusters_to_blocks(sb, 1);
4994ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh	credits += ocfs2_quota_trans_credits(sb);
5004ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh
5014ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh	return credits;
5024ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh}
5034ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh
5048bf396de984e68491569b49770e4fd7aca40ba65Tao Ma/* inode update, new refcount block and its allocation credits. */
5058bf396de984e68491569b49770e4fd7aca40ba65Tao Ma#define OCFS2_REFCOUNT_TREE_CREATE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1 \
5068bf396de984e68491569b49770e4fd7aca40ba65Tao Ma					    + OCFS2_SUBALLOC_ALLOC)
5078bf396de984e68491569b49770e4fd7aca40ba65Tao Ma
5088bf396de984e68491569b49770e4fd7aca40ba65Tao Ma/* inode and the refcount block update. */
5098bf396de984e68491569b49770e4fd7aca40ba65Tao Ma#define OCFS2_REFCOUNT_TREE_SET_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
5108bf396de984e68491569b49770e4fd7aca40ba65Tao Ma
5118bf396de984e68491569b49770e4fd7aca40ba65Tao Ma/*
5128bf396de984e68491569b49770e4fd7aca40ba65Tao Ma * inode and the refcount block update.
5138bf396de984e68491569b49770e4fd7aca40ba65Tao Ma * It doesn't include the credits for sub alloc change.
5148bf396de984e68491569b49770e4fd7aca40ba65Tao Ma * So if we need to free the bit, OCFS2_SUBALLOC_FREE needs to be added.
5158bf396de984e68491569b49770e4fd7aca40ba65Tao Ma */
5168bf396de984e68491569b49770e4fd7aca40ba65Tao Ma#define OCFS2_REFCOUNT_TREE_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1)
5178bf396de984e68491569b49770e4fd7aca40ba65Tao Ma
518bcbbb24a6a5c5b3e7b8e5284e0bfa23f45c32377Tao Ma/* 2 metadata alloc, 2 new blocks and root refcount block */
519bcbbb24a6a5c5b3e7b8e5284e0bfa23f45c32377Tao Ma#define OCFS2_EXPAND_REFCOUNT_TREE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + 3)
520bcbbb24a6a5c5b3e7b8e5284e0bfa23f45c32377Tao Ma
521811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma/*
522811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma * Please note that the caller must make sure that root_el is the root
523811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
524811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma * the result may be wrong.
525811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma */
526ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_extend_credits(struct super_block *sb,
527811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma					    struct ocfs2_extent_list *root_el,
528ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					    u32 bits_wanted)
529ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
530811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma	int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks;
531ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
532ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* bitmap dinode, group desc. + relinked group. */
533ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	bitmap_blocks = OCFS2_SUBALLOC_ALLOC;
534ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
535ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* we might need to shift tree depth so lets assume an
536ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * absolute worst case of complete fragmentation.  Even with
537ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * that, we only need one update for the dinode, and then
538ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * however many metadata chunks needed * a remaining suballoc
539ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * alloc. */
540ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	sysfile_bitmap_blocks = 1 +
541811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma		(OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(root_el);
542ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
543ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* this does not include *new* metadata blocks, which are
544811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma	 * accounted for in sysfile_bitmap_blocks. root_el +
545ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * prev. last_eb_blk + blocks along edge of tree.
546ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * calc_symlink_credits passes because we just need 1
547ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * credit for the dinode there. */
548811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma	extent_blocks = 1 + 1 + le16_to_cpu(root_el->l_tree_depth);
549ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
550a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	return bitmap_blocks + sysfile_bitmap_blocks + extent_blocks +
5516115ea288424c1ead077843b6cd22369dd2e08f9Jie Liu	       ocfs2_quota_trans_credits(sb);
552ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
553ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
554ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_symlink_credits(struct super_block *sb)
555ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
5569b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh	int blocks = ocfs2_mknod_credits(sb, 0, 0);
557ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
558ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* links can be longer than one block so we may update many
559ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * within our single allocated extent. */
560ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	blocks += ocfs2_clusters_to_blocks(sb, 1);
561ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
562a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	return blocks + ocfs2_quota_trans_credits(sb);
563ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
564ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
565ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_group_alloc_credits(struct super_block *sb,
566ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						 unsigned int cpg)
567ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
568ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int blocks;
569ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int bitmap_blocks = OCFS2_SUBALLOC_ALLOC + 1;
570ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* parent inode update + new block group header + bitmap inode update
571ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	   + bitmap blocks affected */
572ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	blocks = 1 + 1 + 1 + bitmap_blocks;
573ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return blocks;
574ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
575ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
5768b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker/*
5778b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker * Allocating a discontiguous block group requires the credits from
5788b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker * ocfs2_calc_group_alloc_credits() as well as enough credits to fill
5798b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker * the group descriptor's extent list.  The caller already has started
5808b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker * the transaction with ocfs2_calc_group_alloc_credits().  They extend
5818b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker * it with these credits.
5828b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker */
5838b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Beckerstatic inline int ocfs2_calc_bg_discontig_credits(struct super_block *sb)
5848b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker{
5858b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker	return ocfs2_extent_recs_per_gd(sb);
5868b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker}
5878b06bc592ebc5a31e8d0b9c2ab17c6e78dde1f86Joel Becker
588ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_tree_trunc_credits(struct super_block *sb,
589ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						unsigned int clusters_to_del,
590ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						struct ocfs2_dinode *fe,
591ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						struct ocfs2_extent_list *last_el)
592ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
593ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 	/* for dinode + all headers in this pass + update to next leaf */
594ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	u16 next_free = le16_to_cpu(last_el->l_next_free_rec);
595ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	u16 tree_depth = le16_to_cpu(fe->id2.i_list.l_tree_depth);
596ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int credits = 1 + tree_depth + 1;
597ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int i;
598ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
599ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	i = next_free - 1;
600ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	BUG_ON(i < 0);
601ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
602ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* We may be deleting metadata blocks, so metadata alloc dinode +
603ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	   one desc. block for each possible delete. */
604ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (tree_depth && next_free == 1 &&
605e48edee2d8eab812f31f0ff62c6ba635ca2e1e21Mark Fasheh	    ocfs2_rec_clusters(last_el, &last_el->l_recs[i]) == clusters_to_del)
606ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		credits += 1 + tree_depth;
607ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
608ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* update to the truncate log. */
609ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	credits += OCFS2_TRUNCATE_LOG_UPDATE;
610ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
611a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara	credits += ocfs2_quota_trans_credits(sb);
612a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara
613ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return credits;
614ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
615ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
6162b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Beckerstatic inline int ocfs2_jbd2_file_inode(handle_t *handle, struct inode *inode)
6172b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker{
6182b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker	return jbd2_journal_file_inode(handle, &OCFS2_I(inode)->ip_jinode);
6192b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker}
6202b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker
6212b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Beckerstatic inline int ocfs2_begin_ordered_truncate(struct inode *inode,
6222b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker					       loff_t new_size)
6232b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker{
6247f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara	return jbd2_journal_begin_ordered_truncate(
6257f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara				OCFS2_SB(inode->i_sb)->journal->j_journal,
6267f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara				&OCFS2_I(inode)->ip_jinode,
6277f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara				new_size);
6282b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker}
6292b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker
630ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#endif /* OCFS2_JOURNAL_H */
631