journal.h revision 1afc32b952335f665327a1a9001ba1b44bb76fd9
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>
30ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#include <linux/jbd.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
41ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstruct ocfs2_journal {
42ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	enum ocfs2_journal_state   j_state;    /* Journals current state   */
43ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
44ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	journal_t                 *j_journal; /* The kernels journal type */
45ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct inode              *j_inode;   /* Kernel inode pointing to
46ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * this journal             */
47ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct ocfs2_super        *j_osb;     /* pointer to the super
48ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * block for the node
49ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * we're currently
50ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * running on -- not
51ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * necessarily the super
52ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * block from the node
53ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * which we usually run
54ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * from (recovery,
55ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       * etc)                     */
56ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct buffer_head        *j_bh;      /* Journal disk inode block */
57ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	atomic_t                  j_num_trans; /* Number of transactions
58ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					        * currently in the system. */
59ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	unsigned long             j_trans_id;
60ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct rw_semaphore       j_trans_barrier;
61ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	wait_queue_head_t         j_checkpointed;
62ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
63ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spinlock_t                j_lock;
64ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct list_head          j_la_cleanups;
65ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct work_struct        j_recovery_work;
66ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh};
67ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
68ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehextern spinlock_t trans_inc_lock;
69ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
70ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* wrap j_trans_id so we never have it equal to zero. */
71ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline unsigned long ocfs2_inc_trans_id(struct ocfs2_journal *j)
72ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
73ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	unsigned long old_id;
74ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
75ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	old_id = j->j_trans_id++;
76ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (unlikely(!j->j_trans_id))
77ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		j->j_trans_id = 1;
78ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
79ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return old_id;
80ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
81ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
82ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline void ocfs2_set_inode_lock_trans(struct ocfs2_journal *journal,
83ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					      struct inode *inode)
84ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
85ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
86ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	OCFS2_I(inode)->ip_last_trans = journal->j_trans_id;
87ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
88ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
89ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
90ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* Used to figure out whether it's safe to drop a metadata lock on an
91ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * inode. Returns true if all the inodes changes have been
92ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * checkpointed to disk. You should be holding the spinlock on the
93ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * metadata lock while calling this to be sure that nobody can take
94ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * the lock and put it on another transaction. */
95ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_inode_fully_checkpointed(struct inode *inode)
96ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
97ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int ret;
98ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct ocfs2_journal *journal = OCFS2_SB(inode->i_sb)->journal;
99ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
100ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
101ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	ret = time_after(journal->j_trans_id, OCFS2_I(inode)->ip_last_trans);
102ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
103ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return ret;
104ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
105ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
106ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* convenience function to check if an inode is still new (has never
107ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * hit disk) Will do you a favor and set created_trans = 0 when you've
108ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * been checkpointed.  returns '1' if the inode is still new. */
109ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_inode_is_new(struct inode *inode)
110ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
111ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int ret;
112ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
113ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* System files are never "new" as they're written out by
114ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * mkfs. This helps us early during mount, before we have the
115ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * journal open and j_trans_id could be junk. */
116ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE)
117ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		return 0;
118ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
119ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	ret = !(time_after(OCFS2_SB(inode->i_sb)->journal->j_trans_id,
120ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			   OCFS2_I(inode)->ip_created_trans));
121ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (!ret)
122ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		OCFS2_I(inode)->ip_created_trans = 0;
123ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
124ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return ret;
125ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
126ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
127ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline void ocfs2_inode_set_new(struct ocfs2_super *osb,
128ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh				       struct inode *inode)
129ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
130ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_lock(&trans_inc_lock);
131ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	OCFS2_I(inode)->ip_created_trans = osb->journal->j_trans_id;
132ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	spin_unlock(&trans_inc_lock);
133ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
134ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
135ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* Exported only for the journal struct init code in super.c. Do not call. */
136c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsvoid ocfs2_complete_recovery(struct work_struct *work);
137ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
138ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
139ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Journal Control:
140ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Initialize, Load, Shutdown, Wipe a journal.
141ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
142ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_init     - Initialize journal structures in the OSB.
143ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_load     - Load the given journal off disk. Replay it if
144ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          there's transactions still in there.
145ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_shutdown - Shutdown a journal, this will flush all
146ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          uncommitted, uncheckpointed transactions.
147ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_wipe     - Wipe transactions from a journal. Optionally
148ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          zero out each block.
149ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_recovery_thread  - Perform recovery on a node. osb is our own osb.
150ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_mark_dead_nodes - Start recovery on nodes we won't get a heartbeat
151ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          event on.
152ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_start_checkpoint - Kick the commit thread to do a checkpoint.
153ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
154ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_set_journal_params(struct ocfs2_super *osb);
155ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_journal_init(struct ocfs2_journal *journal,
156ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			  int *dirty);
157ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_journal_shutdown(struct ocfs2_super *osb);
158ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_journal_wipe(struct ocfs2_journal *journal,
159ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			  int full);
160c271c5c22b0a7ca45fda15f1f4d258bca36a5b94Sunil Mushranint    ocfs2_journal_load(struct ocfs2_journal *journal, int local);
161ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_check_journals_nolocks(struct ocfs2_super *osb);
162ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_recovery_thread(struct ocfs2_super *osb,
163ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			     int node_num);
164ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint    ocfs2_mark_dead_nodes(struct ocfs2_super *osb);
165ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid   ocfs2_complete_mount_recovery(struct ocfs2_super *osb);
166ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
167ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline void ocfs2_start_checkpoint(struct ocfs2_super *osb)
168ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
169ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	atomic_set(&osb->needs_checkpoint, 1);
170ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	wake_up(&osb->checkpoint_event);
171ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
172ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
173ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline void ocfs2_checkpoint_inode(struct inode *inode)
174ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
175ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
176ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
177c271c5c22b0a7ca45fda15f1f4d258bca36a5b94Sunil Mushran	if (ocfs2_mount_local(osb))
178c271c5c22b0a7ca45fda15f1f4d258bca36a5b94Sunil Mushran		return;
179c271c5c22b0a7ca45fda15f1f4d258bca36a5b94Sunil Mushran
180ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (!ocfs2_inode_fully_checkpointed(inode)) {
181ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		/* WARNING: This only kicks off a single
182ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * checkpoint. If someone races you and adds more
183ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * metadata to the journal, you won't know, and will
184ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * wind up waiting *alot* longer than necessary. Right
185ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * now we only use this in clear_inode so that's
186ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		 * OK. */
187ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		ocfs2_start_checkpoint(osb);
188ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
189ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		wait_event(osb->journal->j_checkpointed,
190ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			   ocfs2_inode_fully_checkpointed(inode));
191ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	}
192ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
193ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
194ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
195ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Transaction Handling:
196ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Manage the lifetime of a transaction handle.
197ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
198ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_start_trans      - Begin a transaction. Give it an upper estimate of
199ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          the number of blocks that will be changed during
200ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          this handle.
2011fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *  ocfs2_commit_trans - Complete a handle. It might return -EIO if
2021fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       the journal was aborted. The majority of paths don't
2031fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       check the return value as an error there comes too
2041fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       late to do anything (and will be picked up in a
2051fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh *                       later transaction).
206ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_extend_trans     - Extend a handle by nblocks credits. This may
207ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          commit the handle to disk in the process, but will
208ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          not release any locks taken during the transaction.
209ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_access   - Notify the handle that we want to journal this
210ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          buffer. Will have to call ocfs2_journal_dirty once
211ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                          we've actually dirtied it. Type is one of . or .
212ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_dirty    - Mark a journalled buffer as having dirty data.
213ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  ocfs2_journal_dirty_data - Indicate that a data buffer should go out before
214ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *                             the current handle commits.
215ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
216ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
217ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* You must always start_trans with a number of buffs > 0, but it's
218ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * perfectly legal to go through an entire transaction without having
219ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * dirtied any buffers. */
2201fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fashehhandle_t		    *ocfs2_start_trans(struct ocfs2_super *osb,
221ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					       int max_buffs);
2221fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fashehint			     ocfs2_commit_trans(struct ocfs2_super *osb,
2231fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fasheh						handle_t *handle);
2241fc581467e52546195c7ee8233a34d63c1cc1322Mark Fashehint			     ocfs2_extend_trans(handle_t *handle, int nblocks);
225ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
226ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
227ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Create access is for when we get a newly created buffer and we're
228ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * not gonna read it off disk, but rather fill it ourselves.  Right
229ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * now, we don't do anything special with this (it turns into a write
230ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * request), but this is a good placeholder in case we do...
231ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
232ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Write access is for when we read a block off disk and are going to
233ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * modify it. This way the journalling layer knows it may need to make
234ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * a copy of that block (if it's part of another, uncommitted
235ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * transaction) before we do so.
236ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
237ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_CREATE 0
238ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_WRITE  1
239ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_UNDO   2
240ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
2411fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fashehint                  ocfs2_journal_access(handle_t *handle,
242ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					  struct inode *inode,
243ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					  struct buffer_head *bh,
244ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					  int type);
245ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
246ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * A word about the journal_access/journal_dirty "dance". It is
247ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * entirely legal to journal_access a buffer more than once (as long
248ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * as the access type is the same -- I'm not sure what will happen if
249ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * access type is different but this should never happen anyway) It is
250ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * also legal to journal_dirty a buffer more than once. In fact, you
251ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * can even journal_access a buffer after you've done a
252ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal_access/journal_dirty pair. The only thing you cannot do
253ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * however, is journal_dirty a buffer which you haven't yet passed to
254ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal_access at least once.
255ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
256ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * That said, 99% of the time this doesn't matter and this is what the
257ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * path looks like:
258ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
259ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *	<read a bh>
260ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *	ocfs2_journal_access(handle, bh,	OCFS2_JOURNAL_ACCESS_WRITE);
261ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *	<modify the bh>
262ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * 	ocfs2_journal_dirty(handle, bh);
263ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
2641fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fashehint                  ocfs2_journal_dirty(handle_t *handle,
265ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					 struct buffer_head *bh);
266ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint                  ocfs2_journal_dirty_data(handle_t *handle,
267ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					      struct buffer_head *bh);
268ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
269ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/*
270ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Credit Macros:
271ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  Convenience macros to calculate number of credits needed.
272ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *
273ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  For convenience sake, I have a set of macros here which calculate
274ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  the *maximum* number of sectors which will be changed for various
275ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh *  metadata updates.
276ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */
277ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
278ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* simple file updates like chmod, etc. */
279ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_INODE_UPDATE_CREDITS 1
280ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
281ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* get one bit out of a suballocator: dinode + group descriptor +
282ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * prev. group desc. if we relink. */
283ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SUBALLOC_ALLOC (3)
284ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
2851afc32b952335f665327a1a9001ba1b44bb76fd9Mark Fasheh#define OCFS2_INLINE_TO_EXTENTS_CREDITS (OCFS2_SUBALLOC_ALLOC		\
2861afc32b952335f665327a1a9001ba1b44bb76fd9Mark Fasheh					 + OCFS2_INODE_UPDATE_CREDITS)
2871afc32b952335f665327a1a9001ba1b44bb76fd9Mark Fasheh
288ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode + group descriptor update. We don't relink on free yet. */
289ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SUBALLOC_FREE  (2)
290ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
291ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_TRUNCATE_LOG_UPDATE OCFS2_INODE_UPDATE_CREDITS
292ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_TRUNCATE_LOG_FLUSH_ONE_REC (OCFS2_SUBALLOC_FREE 		      \
293ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					 + OCFS2_TRUNCATE_LOG_UPDATE)
294ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
295063c4561f52a74de686fe0ff2f96f4f54c9fecd2Mark Fasheh#define OCFS2_REMOVE_EXTENT_CREDITS (OCFS2_TRUNCATE_LOG_UPDATE + OCFS2_INODE_UPDATE_CREDITS)
296063c4561f52a74de686fe0ff2f96f4f54c9fecd2Mark Fasheh
297ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* data block for new dir/symlink, 2 for bitmap updates (bitmap fe +
298ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * bitmap block for the new bit) */
299ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_DIR_LINK_ADDITIONAL_CREDITS (1 + 2)
300ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
301ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* parent fe, parent block, new file entry, inode alloc fe, inode alloc
302ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * group descriptor + mkdir/symlink blocks */
303ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_MKNOD_CREDITS (3 + OCFS2_SUBALLOC_ALLOC                         \
304ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			    + OCFS2_DIR_LINK_ADDITIONAL_CREDITS)
305ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
306ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* local alloc metadata change + main bitmap updates */
307ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_WINDOW_MOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS                 \
308ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh				  + OCFS2_SUBALLOC_ALLOC + OCFS2_SUBALLOC_FREE)
309ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
310ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* used when we don't need an allocation change for a dir extend. One
311ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * for the dinode, one for the new block. */
312ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SIMPLE_DIR_EXTEND_CREDITS (2)
313ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
314e051fda4fd14fe878e6d2183b3a4640febe9e9a8Mark Fasheh/* file update (nlink, etc) + directory mtime/ctime + dir entry block */
315e051fda4fd14fe878e6d2183b3a4640febe9e9a8Mark Fasheh#define OCFS2_LINK_CREDITS  (2*OCFS2_INODE_UPDATE_CREDITS + 1)
316ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
317ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* inode + dir inode (if we unlink a dir), + dir entry block + orphan
318ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * dir inode link */
319ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_UNLINK_CREDITS  (2 * OCFS2_INODE_UPDATE_CREDITS + 1             \
320ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			      + OCFS2_LINK_CREDITS)
321ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
322ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode + orphan dir dinode + inode alloc dinode + orphan dir entry +
323ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * inode alloc group descriptor */
324ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_DELETE_INODE_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 1 + 1)
325ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
326ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode update, old dir dinode update, new dir dinode update, old
327ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * dir dir entry, new dir dir entry, dir entry update for renaming
328ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * directory + target unlink */
329ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_RENAME_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 3              \
330ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh			     + OCFS2_UNLINK_CREDITS)
331ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
332ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_extend_credits(struct super_block *sb,
333ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					    struct ocfs2_dinode *fe,
334ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh					    u32 bits_wanted)
335ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
336ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int bitmap_blocks, sysfile_bitmap_blocks, dinode_blocks;
337ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
338ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* bitmap dinode, group desc. + relinked group. */
339ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	bitmap_blocks = OCFS2_SUBALLOC_ALLOC;
340ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
341ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* we might need to shift tree depth so lets assume an
342ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * absolute worst case of complete fragmentation.  Even with
343ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * that, we only need one update for the dinode, and then
344ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * however many metadata chunks needed * a remaining suballoc
345ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * alloc. */
346ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	sysfile_bitmap_blocks = 1 +
347ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		(OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(fe);
348ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
349ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* this does not include *new* metadata blocks, which are
350ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * accounted for in sysfile_bitmap_blocks. fe +
351ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * prev. last_eb_blk + blocks along edge of tree.
352ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * calc_symlink_credits passes because we just need 1
353ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * credit for the dinode there. */
354ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	dinode_blocks = 1 + 1 + le16_to_cpu(fe->id2.i_list.l_tree_depth);
355ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
356ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return bitmap_blocks + sysfile_bitmap_blocks + dinode_blocks;
357ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
358ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
359ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_symlink_credits(struct super_block *sb)
360ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
361ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int blocks = OCFS2_MKNOD_CREDITS;
362ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
363ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* links can be longer than one block so we may update many
364ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	 * within our single allocated extent. */
365ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	blocks += ocfs2_clusters_to_blocks(sb, 1);
366ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
367ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return blocks;
368ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
369ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
370ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_group_alloc_credits(struct super_block *sb,
371ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						 unsigned int cpg)
372ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
373ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int blocks;
374ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int bitmap_blocks = OCFS2_SUBALLOC_ALLOC + 1;
375ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* parent inode update + new block group header + bitmap inode update
376ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	   + bitmap blocks affected */
377ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	blocks = 1 + 1 + 1 + bitmap_blocks;
378ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return blocks;
379ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
380ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
381ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_tree_trunc_credits(struct super_block *sb,
382ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						unsigned int clusters_to_del,
383ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						struct ocfs2_dinode *fe,
384ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh						struct ocfs2_extent_list *last_el)
385ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{
386ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 	/* for dinode + all headers in this pass + update to next leaf */
387ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	u16 next_free = le16_to_cpu(last_el->l_next_free_rec);
388ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	u16 tree_depth = le16_to_cpu(fe->id2.i_list.l_tree_depth);
389ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int credits = 1 + tree_depth + 1;
390ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	int i;
391ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
392ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	i = next_free - 1;
393ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	BUG_ON(i < 0);
394ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
395ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* We may be deleting metadata blocks, so metadata alloc dinode +
396ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	   one desc. block for each possible delete. */
397ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	if (tree_depth && next_free == 1 &&
398e48edee2d8eab812f31f0ff62c6ba635ca2e1e21Mark Fasheh	    ocfs2_rec_clusters(last_el, &last_el->l_recs[i]) == clusters_to_del)
399ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh		credits += 1 + tree_depth;
400ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
401ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	/* update to the truncate log. */
402ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	credits += OCFS2_TRUNCATE_LOG_UPDATE;
403ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
404ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh	return credits;
405ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}
406ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh
407ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#endif /* OCFS2_JOURNAL_H */
408