journal.h revision 0cf2f7632b1789b811ab20b611c4156e6de2b055
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. */ 70ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh unsigned long j_trans_id; 71ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh struct rw_semaphore j_trans_barrier; 72ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh wait_queue_head_t j_checkpointed; 73ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 74ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spinlock_t j_lock; 75ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh struct list_head j_la_cleanups; 76ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh struct work_struct j_recovery_work; 77ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh}; 78ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 79ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehextern spinlock_t trans_inc_lock; 80ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 81ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* wrap j_trans_id so we never have it equal to zero. */ 82ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline unsigned long ocfs2_inc_trans_id(struct ocfs2_journal *j) 83ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 84ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh unsigned long old_id; 85ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_lock(&trans_inc_lock); 86ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh old_id = j->j_trans_id++; 87ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh if (unlikely(!j->j_trans_id)) 88ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh j->j_trans_id = 1; 89ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_unlock(&trans_inc_lock); 90ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh return old_id; 91ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 92ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 930cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline void ocfs2_set_ci_lock_trans(struct ocfs2_journal *journal, 940cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker struct ocfs2_caching_info *ci) 95ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 96ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_lock(&trans_inc_lock); 970cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker ci->ci_last_trans = journal->j_trans_id; 98ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_unlock(&trans_inc_lock); 99ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 100ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 101ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* Used to figure out whether it's safe to drop a metadata lock on an 1020cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * cached object. Returns true if all the object's changes have been 103ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * checkpointed to disk. You should be holding the spinlock on the 104ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * metadata lock while calling this to be sure that nobody can take 105ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * the lock and put it on another transaction. */ 1060cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline int ocfs2_ci_fully_checkpointed(struct ocfs2_caching_info *ci) 107ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 108ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int ret; 1090cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker struct ocfs2_journal *journal = 1100cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal; 111ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 112ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_lock(&trans_inc_lock); 1130cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker ret = time_after(journal->j_trans_id, ci->ci_last_trans); 114ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_unlock(&trans_inc_lock); 115ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh return ret; 116ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 117ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 1180cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker/* convenience function to check if an object backed by struct 1190cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * ocfs2_caching_info is still new (has never hit disk) Will do you a 1200cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * favor and set created_trans = 0 when you've 1210cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker * been checkpointed. returns '1' if the ci is still new. */ 1220cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline int ocfs2_ci_is_new(struct ocfs2_caching_info *ci) 123ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 124ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int ret; 1250cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker struct ocfs2_journal *journal = 1260cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker OCFS2_SB(ocfs2_metadata_cache_get_super(ci))->journal; 1270cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker 1280cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker spin_lock(&trans_inc_lock); 1290cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker ret = !(time_after(journal->j_trans_id, ci->ci_created_trans)); 1300cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker if (!ret) 1310cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker ci->ci_created_trans = 0; 1320cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker spin_unlock(&trans_inc_lock); 1330cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker return ret; 1340cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker} 135ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 1360cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker/* Wrapper for inodes so we can check system files */ 1370cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline int ocfs2_inode_is_new(struct inode *inode) 1380cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker{ 139ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* System files are never "new" as they're written out by 140ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * mkfs. This helps us early during mount, before we have the 141ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal open and j_trans_id could be junk. */ 142ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SYSTEM_FILE) 143ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh return 0; 1440cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker 1450cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker return ocfs2_ci_is_new(INODE_CACHE(inode)); 146ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 147ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 1480cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerstatic inline void ocfs2_ci_set_new(struct ocfs2_super *osb, 1490cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker struct ocfs2_caching_info *ci) 150ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 151ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_lock(&trans_inc_lock); 1520cf2f7632b1789b811ab20b611c4156e6de2b055Joel Becker ci->ci_created_trans = osb->journal->j_trans_id; 153ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh spin_unlock(&trans_inc_lock); 154ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 155ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 156ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* Exported only for the journal struct init code in super.c. Do not call. */ 157df152c241df9e9d2b9a65d37bd02961abe7f591aSunil Mushranvoid ocfs2_orphan_scan_init(struct ocfs2_super *osb); 1588b712cd58adfe6aeeb0be4ecc011dc35620719e7Jeff Mahoneyvoid ocfs2_orphan_scan_start(struct ocfs2_super *osb); 15983273932fbefb6ceef9c0b82ac4d23900728f4d9Srinivas Eedavoid ocfs2_orphan_scan_stop(struct ocfs2_super *osb); 16083273932fbefb6ceef9c0b82ac4d23900728f4d9Srinivas Eedavoid ocfs2_orphan_scan_exit(struct ocfs2_super *osb); 16183273932fbefb6ceef9c0b82ac4d23900728f4d9Srinivas Eeda 162c4028958b6ecad064b1a6303a6a5906d4fe48d73David Howellsvoid ocfs2_complete_recovery(struct work_struct *work); 163553abd046af609191a91af7289d87d477adc659fJoel Beckervoid ocfs2_wait_for_recovery(struct ocfs2_super *osb); 164553abd046af609191a91af7289d87d477adc659fJoel Becker 165553abd046af609191a91af7289d87d477adc659fJoel Beckerint ocfs2_recovery_init(struct ocfs2_super *osb); 166553abd046af609191a91af7289d87d477adc659fJoel Beckervoid ocfs2_recovery_exit(struct ocfs2_super *osb); 167ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 1689140db04ef185f934acf2b1b15b3dd5e6a6bfc22Srinivas Eedaint ocfs2_compute_replay_slots(struct ocfs2_super *osb); 169ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* 170ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Journal Control: 171ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Initialize, Load, Shutdown, Wipe a journal. 172ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * 173ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_journal_init - Initialize journal structures in the OSB. 174ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_journal_load - Load the given journal off disk. Replay it if 175ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * there's transactions still in there. 176ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_journal_shutdown - Shutdown a journal, this will flush all 177ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * uncommitted, uncheckpointed transactions. 178ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_journal_wipe - Wipe transactions from a journal. Optionally 179ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * zero out each block. 180ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_recovery_thread - Perform recovery on a node. osb is our own osb. 181ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_mark_dead_nodes - Start recovery on nodes we won't get a heartbeat 182ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * event on. 183ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_start_checkpoint - Kick the commit thread to do a checkpoint. 184ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */ 185ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid ocfs2_set_journal_params(struct ocfs2_super *osb); 186ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint ocfs2_journal_init(struct ocfs2_journal *journal, 187ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int *dirty); 188ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid ocfs2_journal_shutdown(struct ocfs2_super *osb); 189ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint ocfs2_journal_wipe(struct ocfs2_journal *journal, 190ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int full); 191539d8264093560b917ee3afe4c7f74e5da09d6a5Sunil Mushranint ocfs2_journal_load(struct ocfs2_journal *journal, int local, 192539d8264093560b917ee3afe4c7f74e5da09d6a5Sunil Mushran int replayed); 193ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint ocfs2_check_journals_nolocks(struct ocfs2_super *osb); 194ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid ocfs2_recovery_thread(struct ocfs2_super *osb, 195ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int node_num); 196ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehint ocfs2_mark_dead_nodes(struct ocfs2_super *osb); 197ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehvoid ocfs2_complete_mount_recovery(struct ocfs2_super *osb); 1982205363dce7447b8e85f1ead14387664c1a98753Jan Karavoid ocfs2_complete_quota_recovery(struct ocfs2_super *osb); 199ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 200ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline void ocfs2_start_checkpoint(struct ocfs2_super *osb) 201ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 202ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh atomic_set(&osb->needs_checkpoint, 1); 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 217ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * wind up waiting *alot* 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); 261ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 262ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* 263ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Create access is for when we get a newly created buffer and we're 264ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * not gonna read it off disk, but rather fill it ourselves. Right 265ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * now, we don't do anything special with this (it turns into a write 266ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * request), but this is a good placeholder in case we do... 267ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * 268ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Write access is for when we read a block off disk and are going to 269ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * modify it. This way the journalling layer knows it may need to make 270ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * a copy of that block (if it's part of another, uncommitted 271ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * transaction) before we do so. 272ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */ 273ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_CREATE 0 274ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_WRITE 1 275ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_JOURNAL_ACCESS_UNDO 2 276ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 27713723d00e374c2a6d6ccb5af6de965e89c3e1b01Joel Becker 27850655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_inode */ 2790cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_di(handle_t *handle, struct ocfs2_caching_info *ci, 28013723d00e374c2a6d6ccb5af6de965e89c3e1b01Joel Becker struct buffer_head *bh, int type); 28150655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_extent_block */ 2820cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_eb(handle_t *handle, struct ocfs2_caching_info *ci, 28350655ae9e91d272d48997bada59efe166aa5e343Joel Becker struct buffer_head *bh, int type); 28450655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_group_desc */ 2850cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_gd(handle_t *handle, struct ocfs2_caching_info *ci, 28650655ae9e91d272d48997bada59efe166aa5e343Joel Becker struct buffer_head *bh, int type); 28750655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* ocfs2_xattr_block */ 2880cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_xb(handle_t *handle, struct ocfs2_caching_info *ci, 28950655ae9e91d272d48997bada59efe166aa5e343Joel Becker struct buffer_head *bh, int type); 29050655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* quota blocks */ 2910cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_dq(handle_t *handle, struct ocfs2_caching_info *ci, 29250655ae9e91d272d48997bada59efe166aa5e343Joel Becker struct buffer_head *bh, int type); 29350655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* dirblock */ 2940cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_db(handle_t *handle, struct ocfs2_caching_info *ci, 29550655ae9e91d272d48997bada59efe166aa5e343Joel Becker struct buffer_head *bh, int type); 2969b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* ocfs2_dx_root_block */ 2970cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_dr(handle_t *handle, struct ocfs2_caching_info *ci, 2989b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh struct buffer_head *bh, int type); 2999b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* ocfs2_dx_leaf */ 3000cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access_dl(handle_t *handle, struct ocfs2_caching_info *ci, 3019b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh struct buffer_head *bh, int type); 30250655ae9e91d272d48997bada59efe166aa5e343Joel Becker/* Anything that has no ecc */ 3030cf2f7632b1789b811ab20b611c4156e6de2b055Joel Beckerint ocfs2_journal_access(handle_t *handle, struct ocfs2_caching_info *ci, 30450655ae9e91d272d48997bada59efe166aa5e343Joel Becker struct buffer_head *bh, int type); 30550655ae9e91d272d48997bada59efe166aa5e343Joel Becker 306ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* 307ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * A word about the journal_access/journal_dirty "dance". It is 308ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * entirely legal to journal_access a buffer more than once (as long 309ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * as the access type is the same -- I'm not sure what will happen if 310ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * access type is different but this should never happen anyway) It is 311ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * also legal to journal_dirty a buffer more than once. In fact, you 312ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * can even journal_access a buffer after you've done a 313ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal_access/journal_dirty pair. The only thing you cannot do 314ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * however, is journal_dirty a buffer which you haven't yet passed to 315ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * journal_access at least once. 316ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * 317ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * That said, 99% of the time this doesn't matter and this is what the 318ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * path looks like: 319ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * 320ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * <read a bh> 321ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_journal_access(handle, bh, OCFS2_JOURNAL_ACCESS_WRITE); 322ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * <modify the bh> 323ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * ocfs2_journal_dirty(handle, bh); 324ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */ 3251fabe1481fac9e01bf8bffa60a2307ef379aa5deMark Fashehint ocfs2_journal_dirty(handle_t *handle, 326ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh struct buffer_head *bh); 327ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 328ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* 329ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Credit Macros: 330ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * Convenience macros to calculate number of credits needed. 331ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * 332ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * For convenience sake, I have a set of macros here which calculate 333ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * the *maximum* number of sectors which will be changed for various 334ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * metadata updates. 335ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh */ 336ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 337ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* simple file updates like chmod, etc. */ 338ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_INODE_UPDATE_CREDITS 1 339ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 340cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang/* extended attribute block update */ 341cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang#define OCFS2_XATTR_BLOCK_UPDATE_CREDITS 1 342cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang 3430584974a77796581eb3a64b6c5005edac4a95128Jan Kara/* Update of a single quota block */ 3440584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QUOTA_BLOCK_UPDATE_CREDITS 1 3450584974a77796581eb3a64b6c5005edac4a95128Jan Kara 346a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* global quotafile inode update, data block */ 3470584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QINFO_WRITE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + \ 3480584974a77796581eb3a64b6c5005edac4a95128Jan Kara OCFS2_QUOTA_BLOCK_UPDATE_CREDITS) 349a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara 3500584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_LOCAL_QINFO_WRITE_CREDITS OCFS2_QUOTA_BLOCK_UPDATE_CREDITS 351a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* 352a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara * The two writes below can accidentally see global info dirty due 353a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara * to set_info() quotactl so make them prepared for the writes. 354a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara */ 355a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* quota data block, global info */ 356a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* Write to local quota file */ 3570584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QWRITE_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \ 3580584974a77796581eb3a64b6c5005edac4a95128Jan Kara OCFS2_QUOTA_BLOCK_UPDATE_CREDITS) 359a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara 360a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* global quota data block, local quota data block, global quota inode, 361a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara * global quota info */ 3620584974a77796581eb3a64b6c5005edac4a95128Jan Kara#define OCFS2_QSYNC_CREDITS (OCFS2_QINFO_WRITE_CREDITS + \ 3630584974a77796581eb3a64b6c5005edac4a95128Jan Kara 2 * OCFS2_QUOTA_BLOCK_UPDATE_CREDITS) 364a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara 365a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_quota_trans_credits(struct super_block *sb) 366a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{ 367a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara int credits = 0; 368a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara 369a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) 370a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara credits += OCFS2_QWRITE_CREDITS; 371a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara if (OCFS2_HAS_RO_COMPAT_FEATURE(sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) 372a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara credits += OCFS2_QWRITE_CREDITS; 373a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara return credits; 374a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara} 375a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara 376d659072f736837e56b6433d58e5315ad1d4d5ccfTao Ma/* group extend. inode update and last group update. */ 377d659072f736837e56b6433d58e5315ad1d4d5ccfTao Ma#define OCFS2_GROUP_EXTEND_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1) 378d659072f736837e56b6433d58e5315ad1d4d5ccfTao Ma 3797909f2bf835376a20d6dbf853eb459a27566eba2Tao Ma/* group add. inode update and the new group update. */ 3807909f2bf835376a20d6dbf853eb459a27566eba2Tao Ma#define OCFS2_GROUP_ADD_CREDITS (OCFS2_INODE_UPDATE_CREDITS + 1) 3817909f2bf835376a20d6dbf853eb459a27566eba2Tao Ma 382ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* get one bit out of a suballocator: dinode + group descriptor + 383ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * prev. group desc. if we relink. */ 384ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SUBALLOC_ALLOC (3) 385ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 386a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_inline_to_extents_credits(struct super_block *sb) 387a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{ 388a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara return OCFS2_SUBALLOC_ALLOC + OCFS2_INODE_UPDATE_CREDITS + 389a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara ocfs2_quota_trans_credits(sb); 390a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara} 3911afc32b952335f665327a1a9001ba1b44bb76fd9Mark Fasheh 392ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode + group descriptor update. We don't relink on free yet. */ 393ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SUBALLOC_FREE (2) 394ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 395ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_TRUNCATE_LOG_UPDATE OCFS2_INODE_UPDATE_CREDITS 396ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_TRUNCATE_LOG_FLUSH_ONE_REC (OCFS2_SUBALLOC_FREE \ 397ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh + OCFS2_TRUNCATE_LOG_UPDATE) 398ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 399a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_remove_extent_credits(struct super_block *sb) 400a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{ 401a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara return OCFS2_TRUNCATE_LOG_UPDATE + OCFS2_INODE_UPDATE_CREDITS + 402a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara ocfs2_quota_trans_credits(sb); 403a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara} 404063c4561f52a74de686fe0ff2f96f4f54c9fecd2Mark Fasheh 405ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* data block for new dir/symlink, 2 for bitmap updates (bitmap fe + 406e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh * bitmap block for the new bit) dx_root update for free list */ 407e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh#define OCFS2_DIR_LINK_ADDITIONAL_CREDITS (1 + 2 + 1) 408ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 4099b7895efac906d66d19856194e1ba61f37e231a4Mark Fashehstatic inline int ocfs2_add_dir_index_credits(struct super_block *sb) 4109b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh{ 4119b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh /* 1 block for index, 2 allocs (data, metadata), 1 clusters 4129b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh * worth of blocks for initial extent. */ 4139b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh return 1 + 2 * OCFS2_SUBALLOC_ALLOC + 4149b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh ocfs2_clusters_to_blocks(sb, 1); 4159b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh} 4169b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh 4179b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* parent fe, parent block, new file entry, index leaf, inode alloc fe, inode 4189b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh * alloc group descriptor + mkdir/symlink blocks + dir blocks + xattr 4199b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh * blocks + quota update */ 4209b7895efac906d66d19856194e1ba61f37e231a4Mark Fashehstatic inline int ocfs2_mknod_credits(struct super_block *sb, int is_dir, 4219b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh int xattr_credits) 422a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{ 4239b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh int dir_credits = OCFS2_DIR_LINK_ADDITIONAL_CREDITS; 4249b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh 4259b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh if (is_dir) 4269b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh dir_credits += ocfs2_add_dir_index_credits(sb); 4279b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh 4289b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh return 4 + OCFS2_SUBALLOC_ALLOC + dir_credits + xattr_credits + 429a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara ocfs2_quota_trans_credits(sb); 430a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara} 431ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 432ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* local alloc metadata change + main bitmap updates */ 433ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_WINDOW_MOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS \ 434ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh + OCFS2_SUBALLOC_ALLOC + OCFS2_SUBALLOC_FREE) 435ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 436ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* used when we don't need an allocation change for a dir extend. One 437ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * for the dinode, one for the new block. */ 438ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#define OCFS2_SIMPLE_DIR_EXTEND_CREDITS (2) 439ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 440a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara/* file update (nlink, etc) + directory mtime/ctime + dir entry block + quota 441e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh * update on dir + index leaf + dx root update for free list */ 442a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_link_credits(struct super_block *sb) 443a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{ 444e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh return 2*OCFS2_INODE_UPDATE_CREDITS + 3 + 445a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara ocfs2_quota_trans_credits(sb); 446a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara} 447ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 448ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* inode + dir inode (if we unlink a dir), + dir entry block + orphan 449e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh * dir inode link + dir inode index leaf + dir index root */ 450a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_unlink_credits(struct super_block *sb) 451a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{ 452a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara /* The quota update from ocfs2_link_credits is unused here... */ 453e7c17e43090afe558c40bfb66637744c27bd2aebMark Fasheh return 2 * OCFS2_INODE_UPDATE_CREDITS + 3 + ocfs2_link_credits(sb); 454a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara} 455ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 456ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode + orphan dir dinode + inode alloc dinode + orphan dir entry + 457dfa13f39b798fee68250abe1aed851395c8b51b5Joel Becker * inode alloc group descriptor + orphan dir index root + 458dfa13f39b798fee68250abe1aed851395c8b51b5Joel Becker * orphan dir index leaf */ 459dfa13f39b798fee68250abe1aed851395c8b51b5Joel Becker#define OCFS2_DELETE_INODE_CREDITS (3 * OCFS2_INODE_UPDATE_CREDITS + 4) 460ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 461ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh/* dinode update, old dir dinode update, new dir dinode update, old 462ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * dir dir entry, new dir dir entry, dir entry update for renaming 4639b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh * directory + target unlink + 3 x dir index leaves */ 464a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Karastatic inline int ocfs2_rename_credits(struct super_block *sb) 465a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara{ 4669b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh return 3 * OCFS2_INODE_UPDATE_CREDITS + 6 + ocfs2_unlink_credits(sb); 467a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara} 468ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 469cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang/* global bitmap dinode, group desc., relinked group, 470cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang * suballocator dinode, group desc., relinked group, 471cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang * dinode, xattr block */ 472cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang#define OCFS2_XATTR_BLOCK_CREATE_CREDITS (OCFS2_SUBALLOC_ALLOC * 2 + \ 473cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang + OCFS2_INODE_UPDATE_CREDITS \ 474cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang + OCFS2_XATTR_BLOCK_UPDATE_CREDITS) 475cf1d6c763fbcb115263114302485ad17e7933d87Tiger Yang 4769b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh/* inode update, removal of dx root block from allocator */ 4779b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh#define OCFS2_DX_ROOT_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + \ 4789b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh OCFS2_SUBALLOC_FREE) 4799b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh 4804ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fashehstatic inline int ocfs2_calc_dxi_expand_credits(struct super_block *sb) 4814ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh{ 4824ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh int credits = 1 + OCFS2_SUBALLOC_ALLOC; 4834ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh 4844ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh credits += ocfs2_clusters_to_blocks(sb, 1); 4854ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh credits += ocfs2_quota_trans_credits(sb); 4864ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh 4874ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh return credits; 4884ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh} 4894ed8a6bb083bfcc21f1ed66a474b03c0386e4b34Mark Fasheh 490811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma/* 491811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma * Please note that the caller must make sure that root_el is the root 492811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise 493811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma * the result may be wrong. 494811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma */ 495ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_extend_credits(struct super_block *sb, 496811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma struct ocfs2_extent_list *root_el, 497ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh u32 bits_wanted) 498ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 499811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma int bitmap_blocks, sysfile_bitmap_blocks, extent_blocks; 500ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 501ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* bitmap dinode, group desc. + relinked group. */ 502ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh bitmap_blocks = OCFS2_SUBALLOC_ALLOC; 503ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 504ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* we might need to shift tree depth so lets assume an 505ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * absolute worst case of complete fragmentation. Even with 506ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * that, we only need one update for the dinode, and then 507ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * however many metadata chunks needed * a remaining suballoc 508ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * alloc. */ 509ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh sysfile_bitmap_blocks = 1 + 510811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma (OCFS2_SUBALLOC_ALLOC - 1) * ocfs2_extend_meta_needed(root_el); 511ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 512ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* this does not include *new* metadata blocks, which are 513811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma * accounted for in sysfile_bitmap_blocks. root_el + 514ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * prev. last_eb_blk + blocks along edge of tree. 515ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * calc_symlink_credits passes because we just need 1 516ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * credit for the dinode there. */ 517811f933df1e55615fd0bb4818f31e3868a8e6e23Tao Ma extent_blocks = 1 + 1 + le16_to_cpu(root_el->l_tree_depth); 518ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 519a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara return bitmap_blocks + sysfile_bitmap_blocks + extent_blocks + 520a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara ocfs2_quota_trans_credits(sb); 521ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 522ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 523ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_symlink_credits(struct super_block *sb) 524ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 5259b7895efac906d66d19856194e1ba61f37e231a4Mark Fasheh int blocks = ocfs2_mknod_credits(sb, 0, 0); 526ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 527ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* links can be longer than one block so we may update many 528ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh * within our single allocated extent. */ 529ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh blocks += ocfs2_clusters_to_blocks(sb, 1); 530ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 531a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara return blocks + ocfs2_quota_trans_credits(sb); 532ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 533ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 534ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_group_alloc_credits(struct super_block *sb, 535ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh unsigned int cpg) 536ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 537ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int blocks; 538ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int bitmap_blocks = OCFS2_SUBALLOC_ALLOC + 1; 539ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* parent inode update + new block group header + bitmap inode update 540ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh + bitmap blocks affected */ 541ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh blocks = 1 + 1 + 1 + bitmap_blocks; 542ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh return blocks; 543ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 544ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 545ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fashehstatic inline int ocfs2_calc_tree_trunc_credits(struct super_block *sb, 546ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh unsigned int clusters_to_del, 547ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh struct ocfs2_dinode *fe, 548ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh struct ocfs2_extent_list *last_el) 549ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh{ 550ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* for dinode + all headers in this pass + update to next leaf */ 551ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh u16 next_free = le16_to_cpu(last_el->l_next_free_rec); 552ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh u16 tree_depth = le16_to_cpu(fe->id2.i_list.l_tree_depth); 553ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int credits = 1 + tree_depth + 1; 554ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh int i; 555ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 556ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh i = next_free - 1; 557ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh BUG_ON(i < 0); 558ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 559ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* We may be deleting metadata blocks, so metadata alloc dinode + 560ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh one desc. block for each possible delete. */ 561ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh if (tree_depth && next_free == 1 && 562e48edee2d8eab812f31f0ff62c6ba635ca2e1e21Mark Fasheh ocfs2_rec_clusters(last_el, &last_el->l_recs[i]) == clusters_to_del) 563ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh credits += 1 + tree_depth; 564ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 565ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh /* update to the truncate log. */ 566ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh credits += OCFS2_TRUNCATE_LOG_UPDATE; 567ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 568a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara credits += ocfs2_quota_trans_credits(sb); 569a90714c150e3ce677c57a9dac3ab1ec342c75a95Jan Kara 570ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh return credits; 571ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh} 572ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh 5732b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Beckerstatic inline int ocfs2_jbd2_file_inode(handle_t *handle, struct inode *inode) 5742b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker{ 5752b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker return jbd2_journal_file_inode(handle, &OCFS2_I(inode)->ip_jinode); 5762b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker} 5772b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker 5782b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Beckerstatic inline int ocfs2_begin_ordered_truncate(struct inode *inode, 5792b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker loff_t new_size) 5802b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker{ 5817f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara return jbd2_journal_begin_ordered_truncate( 5827f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara OCFS2_SB(inode->i_sb)->journal->j_journal, 5837f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara &OCFS2_I(inode)->ip_jinode, 5847f5aa215088b817add9c71914b83650bdd49f8a9Jan Kara new_size); 5852b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker} 5862b4e30fbde425828b17f0e9c8f8e3fd3ecb2bc75Joel Becker 587ccd979bdbce9fba8412beb3f1de68a9d0171b12cMark Fasheh#endif /* OCFS2_JOURNAL_H */ 588