blob: ed10991ab0060c5fac4ed580301591f6996965ca [file] [log] [blame]
Dave Kleikamp470decc2006-10-11 01:20:57 -07001/*
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002 * linux/fs/jbd2/journal.c
Dave Kleikamp470decc2006-10-11 01:20:57 -07003 *
4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
5 *
6 * Copyright 1998 Red Hat corp --- All Rights Reserved
7 *
8 * This file is part of the Linux kernel and is made available under
9 * the terms of the GNU General Public License, version 2, or at your
10 * option, any later version, incorporated herein by reference.
11 *
12 * Generic filesystem journal-writing code; part of the ext2fs
13 * journaling system.
14 *
15 * This file manages journals: areas of disk reserved for logging
16 * transactional updates. This includes the kernel journaling thread
17 * which is responsible for scheduling updates to the log.
18 *
19 * We do not actually manage the physical storage of the journal in this
20 * file: that is left to a per-journal policy function, which allows us
21 * to store the journal within a filesystem-specified area for ext2
22 * journaling (ext2 can use a reserved inode for storing the log).
23 */
24
25#include <linux/module.h>
26#include <linux/time.h>
27#include <linux/fs.h>
Mingming Caof7f4bcc2006-10-11 01:20:59 -070028#include <linux/jbd2.h>
Dave Kleikamp470decc2006-10-11 01:20:57 -070029#include <linux/errno.h>
30#include <linux/slab.h>
Dave Kleikamp470decc2006-10-11 01:20:57 -070031#include <linux/init.h>
32#include <linux/mm.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080033#include <linux/freezer.h>
Dave Kleikamp470decc2006-10-11 01:20:57 -070034#include <linux/pagemap.h>
35#include <linux/kthread.h>
36#include <linux/poison.h>
37#include <linux/proc_fs.h>
Johann Lombardi8e85fb32008-01-28 23:58:27 -050038#include <linux/seq_file.h>
Simon Holm Thøgersenc225aa52009-01-11 22:34:01 -050039#include <linux/math64.h>
Theodore Ts'o879c5e62009-06-17 11:47:48 -040040#include <linux/hash.h>
Theodore Ts'od2eecb02009-12-07 10:36:20 -050041#include <linux/log2.h>
42#include <linux/vmalloc.h>
Theodore Ts'o47def822010-07-27 11:56:05 -040043#include <linux/backing-dev.h>
Brian King39e3ac22010-10-27 21:25:12 -040044#include <linux/bitops.h>
Theodore Ts'o670be5a2010-12-17 10:44:16 -050045#include <linux/ratelimit.h>
Theodore Ts'o879c5e62009-06-17 11:47:48 -040046
47#define CREATE_TRACE_POINTS
48#include <trace/events/jbd2.h>
Dave Kleikamp470decc2006-10-11 01:20:57 -070049
50#include <asm/uaccess.h>
51#include <asm/page.h>
52
Theodore Ts'ob6e96d02013-02-09 16:29:20 -050053#ifdef CONFIG_JBD2_DEBUG
54ushort jbd2_journal_enable_debug __read_mostly;
55EXPORT_SYMBOL(jbd2_journal_enable_debug);
56
57module_param_named(jbd2_debug, jbd2_journal_enable_debug, ushort, 0644);
58MODULE_PARM_DESC(jbd2_debug, "Debugging level for jbd2");
59#endif
60
Mingming Caof7f4bcc2006-10-11 01:20:59 -070061EXPORT_SYMBOL(jbd2_journal_extend);
62EXPORT_SYMBOL(jbd2_journal_stop);
63EXPORT_SYMBOL(jbd2_journal_lock_updates);
64EXPORT_SYMBOL(jbd2_journal_unlock_updates);
65EXPORT_SYMBOL(jbd2_journal_get_write_access);
66EXPORT_SYMBOL(jbd2_journal_get_create_access);
67EXPORT_SYMBOL(jbd2_journal_get_undo_access);
Joel Beckere06c8222008-09-11 15:35:47 -070068EXPORT_SYMBOL(jbd2_journal_set_triggers);
Mingming Caof7f4bcc2006-10-11 01:20:59 -070069EXPORT_SYMBOL(jbd2_journal_dirty_metadata);
Mingming Caof7f4bcc2006-10-11 01:20:59 -070070EXPORT_SYMBOL(jbd2_journal_forget);
Dave Kleikamp470decc2006-10-11 01:20:57 -070071#if 0
72EXPORT_SYMBOL(journal_sync_buffer);
73#endif
Mingming Caof7f4bcc2006-10-11 01:20:59 -070074EXPORT_SYMBOL(jbd2_journal_flush);
75EXPORT_SYMBOL(jbd2_journal_revoke);
Dave Kleikamp470decc2006-10-11 01:20:57 -070076
Mingming Caof7f4bcc2006-10-11 01:20:59 -070077EXPORT_SYMBOL(jbd2_journal_init_dev);
78EXPORT_SYMBOL(jbd2_journal_init_inode);
Mingming Caof7f4bcc2006-10-11 01:20:59 -070079EXPORT_SYMBOL(jbd2_journal_check_used_features);
80EXPORT_SYMBOL(jbd2_journal_check_available_features);
81EXPORT_SYMBOL(jbd2_journal_set_features);
Mingming Caof7f4bcc2006-10-11 01:20:59 -070082EXPORT_SYMBOL(jbd2_journal_load);
83EXPORT_SYMBOL(jbd2_journal_destroy);
Mingming Caof7f4bcc2006-10-11 01:20:59 -070084EXPORT_SYMBOL(jbd2_journal_abort);
85EXPORT_SYMBOL(jbd2_journal_errno);
86EXPORT_SYMBOL(jbd2_journal_ack_err);
87EXPORT_SYMBOL(jbd2_journal_clear_err);
88EXPORT_SYMBOL(jbd2_log_wait_commit);
Theodore Ts'o3b799d12009-12-09 20:42:53 -050089EXPORT_SYMBOL(jbd2_log_start_commit);
Mingming Caof7f4bcc2006-10-11 01:20:59 -070090EXPORT_SYMBOL(jbd2_journal_start_commit);
91EXPORT_SYMBOL(jbd2_journal_force_commit_nested);
92EXPORT_SYMBOL(jbd2_journal_wipe);
93EXPORT_SYMBOL(jbd2_journal_blocks_per_page);
94EXPORT_SYMBOL(jbd2_journal_invalidatepage);
95EXPORT_SYMBOL(jbd2_journal_try_to_free_buffers);
96EXPORT_SYMBOL(jbd2_journal_force_commit);
Jan Karac851ed52008-07-11 19:27:31 -040097EXPORT_SYMBOL(jbd2_journal_file_inode);
98EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
99EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
100EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
Theodore Ts'o8aefcd52011-01-10 12:29:43 -0500101EXPORT_SYMBOL(jbd2_inode_cache);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700102
Dave Kleikamp470decc2006-10-11 01:20:57 -0700103static void __journal_abort_soft (journal_t *journal, int errno);
Theodore Ts'od2eecb02009-12-07 10:36:20 -0500104static int jbd2_journal_create_slab(size_t slab_size);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700105
Darrick J. Wong25ed6e82012-05-27 07:48:56 -0400106/* Checksumming functions */
107int jbd2_verify_csum_type(journal_t *j, journal_superblock_t *sb)
108{
109 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
110 return 1;
111
112 return sb->s_checksum_type == JBD2_CRC32C_CHKSUM;
113}
114
Darrick J. Wong4fd5ea42012-05-27 08:08:22 -0400115static __u32 jbd2_superblock_csum(journal_t *j, journal_superblock_t *sb)
116{
117 __u32 csum, old_csum;
118
119 old_csum = sb->s_checksum;
120 sb->s_checksum = 0;
121 csum = jbd2_chksum(j, ~0, (char *)sb, sizeof(journal_superblock_t));
122 sb->s_checksum = old_csum;
123
124 return cpu_to_be32(csum);
125}
126
127int jbd2_superblock_csum_verify(journal_t *j, journal_superblock_t *sb)
128{
129 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
130 return 1;
131
132 return sb->s_checksum == jbd2_superblock_csum(j, sb);
133}
134
135void jbd2_superblock_csum_set(journal_t *j, journal_superblock_t *sb)
136{
137 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
138 return;
139
140 sb->s_checksum = jbd2_superblock_csum(j, sb);
141}
142
Dave Kleikamp470decc2006-10-11 01:20:57 -0700143/*
144 * Helper function used to manage commit timeouts
145 */
146
147static void commit_timeout(unsigned long __data)
148{
149 struct task_struct * p = (struct task_struct *) __data;
150
151 wake_up_process(p);
152}
153
154/*
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700155 * kjournald2: The main thread function used to manage a logging device
Dave Kleikamp470decc2006-10-11 01:20:57 -0700156 * journal.
157 *
158 * This kernel thread is responsible for two things:
159 *
160 * 1) COMMIT: Every so often we need to commit the current state of the
161 * filesystem to disk. The journal thread is responsible for writing
162 * all of the metadata buffers to disk.
163 *
164 * 2) CHECKPOINT: We cannot reuse a used section of the log file until all
165 * of the data in that part of the log has been rewritten elsewhere on
166 * the disk. Flushing these old buffers to reclaim space in the log is
167 * known as checkpointing, and this thread is responsible for that job.
168 */
169
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700170static int kjournald2(void *arg)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700171{
172 journal_t *journal = arg;
173 transaction_t *transaction;
174
175 /*
176 * Set up an interval timer which can be used to trigger a commit wakeup
177 * after the commit interval expires
178 */
179 setup_timer(&journal->j_commit_timer, commit_timeout,
180 (unsigned long)current);
181
Nigel Cunningham35c80422012-02-03 19:59:41 +1100182 set_freezable();
183
Dave Kleikamp470decc2006-10-11 01:20:57 -0700184 /* Record that the journal thread is running */
185 journal->j_task = current;
186 wake_up(&journal->j_wait_done_commit);
187
Dave Kleikamp470decc2006-10-11 01:20:57 -0700188 /*
189 * And now, wait forever for commit wakeup events.
190 */
Theodore Ts'oa931da62010-08-03 21:35:12 -0400191 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700192
193loop:
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700194 if (journal->j_flags & JBD2_UNMOUNT)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700195 goto end_loop;
196
197 jbd_debug(1, "commit_sequence=%d, commit_request=%d\n",
198 journal->j_commit_sequence, journal->j_commit_request);
199
200 if (journal->j_commit_sequence != journal->j_commit_request) {
201 jbd_debug(1, "OK, requests differ\n");
Theodore Ts'oa931da62010-08-03 21:35:12 -0400202 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700203 del_timer_sync(&journal->j_commit_timer);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700204 jbd2_journal_commit_transaction(journal);
Theodore Ts'oa931da62010-08-03 21:35:12 -0400205 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700206 goto loop;
207 }
208
209 wake_up(&journal->j_wait_done_commit);
210 if (freezing(current)) {
211 /*
212 * The simpler the better. Flushing journal isn't a
213 * good idea, because that depends on threads that may
214 * be already stopped.
215 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700216 jbd_debug(1, "Now suspending kjournald2\n");
Theodore Ts'oa931da62010-08-03 21:35:12 -0400217 write_unlock(&journal->j_state_lock);
Tejun Heoa0acae02011-11-21 12:32:22 -0800218 try_to_freeze();
Theodore Ts'oa931da62010-08-03 21:35:12 -0400219 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700220 } else {
221 /*
222 * We assume on resume that commits are already there,
223 * so we don't sleep
224 */
225 DEFINE_WAIT(wait);
226 int should_sleep = 1;
227
228 prepare_to_wait(&journal->j_wait_commit, &wait,
229 TASK_INTERRUPTIBLE);
230 if (journal->j_commit_sequence != journal->j_commit_request)
231 should_sleep = 0;
232 transaction = journal->j_running_transaction;
233 if (transaction && time_after_eq(jiffies,
234 transaction->t_expires))
235 should_sleep = 0;
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700236 if (journal->j_flags & JBD2_UNMOUNT)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700237 should_sleep = 0;
238 if (should_sleep) {
Theodore Ts'oa931da62010-08-03 21:35:12 -0400239 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700240 schedule();
Theodore Ts'oa931da62010-08-03 21:35:12 -0400241 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700242 }
243 finish_wait(&journal->j_wait_commit, &wait);
244 }
245
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700246 jbd_debug(1, "kjournald2 wakes\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -0700247
248 /*
249 * Were we woken up by a commit wakeup event?
250 */
251 transaction = journal->j_running_transaction;
252 if (transaction && time_after_eq(jiffies, transaction->t_expires)) {
253 journal->j_commit_request = transaction->t_tid;
254 jbd_debug(1, "woke because of timeout\n");
255 }
256 goto loop;
257
258end_loop:
Theodore Ts'oa931da62010-08-03 21:35:12 -0400259 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700260 del_timer_sync(&journal->j_commit_timer);
261 journal->j_task = NULL;
262 wake_up(&journal->j_wait_done_commit);
263 jbd_debug(1, "Journal thread exiting.\n");
264 return 0;
265}
266
Pavel Emelianov97f06782007-05-08 00:30:42 -0700267static int jbd2_journal_start_thread(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700268{
Pavel Emelianov97f06782007-05-08 00:30:42 -0700269 struct task_struct *t;
270
Theodore Ts'o90576c02009-09-29 15:51:30 -0400271 t = kthread_run(kjournald2, journal, "jbd2/%s",
272 journal->j_devname);
Pavel Emelianov97f06782007-05-08 00:30:42 -0700273 if (IS_ERR(t))
274 return PTR_ERR(t);
275
Al Viro1076d172008-03-29 03:07:18 +0000276 wait_event(journal->j_wait_done_commit, journal->j_task != NULL);
Pavel Emelianov97f06782007-05-08 00:30:42 -0700277 return 0;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700278}
279
280static void journal_kill_thread(journal_t *journal)
281{
Theodore Ts'oa931da62010-08-03 21:35:12 -0400282 write_lock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700283 journal->j_flags |= JBD2_UNMOUNT;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700284
285 while (journal->j_task) {
286 wake_up(&journal->j_wait_commit);
Theodore Ts'oa931da62010-08-03 21:35:12 -0400287 write_unlock(&journal->j_state_lock);
Al Viro1076d172008-03-29 03:07:18 +0000288 wait_event(journal->j_wait_done_commit, journal->j_task == NULL);
Theodore Ts'oa931da62010-08-03 21:35:12 -0400289 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700290 }
Theodore Ts'oa931da62010-08-03 21:35:12 -0400291 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700292}
293
294/*
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700295 * jbd2_journal_write_metadata_buffer: write a metadata buffer to the journal.
Dave Kleikamp470decc2006-10-11 01:20:57 -0700296 *
297 * Writes a metadata buffer to a given disk block. The actual IO is not
298 * performed but a new buffer_head is constructed which labels the data
299 * to be written with the correct destination disk block.
300 *
301 * Any magic-number escaping which needs to be done will cause a
302 * copy-out here. If the buffer happens to start with the
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700303 * JBD2_MAGIC_NUMBER, then we can't write it to the log directly: the
Dave Kleikamp470decc2006-10-11 01:20:57 -0700304 * magic number is only written to the log for descripter blocks. In
305 * this case, we copy the data and replace the first word with 0, and we
306 * return a result code which indicates that this buffer needs to be
307 * marked as an escaped buffer in the corresponding log descriptor
308 * block. The missing word can then be restored when the block is read
309 * during recovery.
310 *
311 * If the source buffer has already been modified by a new transaction
312 * since we took the last commit snapshot, we use the frozen copy of
313 * that data for IO. If we end up using the existing buffer_head's data
314 * for the write, then we *have* to lock the buffer to prevent anyone
315 * else from using and possibly modifying it while the IO is in
316 * progress.
317 *
318 * The function returns a pointer to the buffer_heads to be used for IO.
319 *
320 * We assume that the journal has already been locked in this function.
321 *
322 * Return value:
323 * <0: Error
324 * >=0: Finished OK
325 *
326 * On success:
327 * Bit 0 set == escape performed on the data
328 * Bit 1 set == buffer copy-out performed (kfree the data after IO)
329 */
330
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700331int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
Dave Kleikamp470decc2006-10-11 01:20:57 -0700332 struct journal_head *jh_in,
333 struct journal_head **jh_out,
Mingming Cao18eba7a2006-10-11 01:21:13 -0700334 unsigned long long blocknr)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700335{
336 int need_copy_out = 0;
337 int done_copy_out = 0;
338 int do_escape = 0;
339 char *mapped_data;
340 struct buffer_head *new_bh;
341 struct journal_head *new_jh;
342 struct page *new_page;
343 unsigned int new_offset;
344 struct buffer_head *bh_in = jh2bh(jh_in);
dingdinghua96577c42009-07-13 17:55:35 -0400345 journal_t *journal = transaction->t_journal;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700346
347 /*
348 * The buffer really shouldn't be locked: only the current committing
349 * transaction is allowed to write it, so nobody else is allowed
350 * to do any IO.
351 *
352 * akpm: except if we're journalling data, and write() output is
353 * also part of a shared mapping, and another thread has
354 * decided to launch a writepage() against this buffer.
355 */
356 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
357
Theodore Ts'o47def822010-07-27 11:56:05 -0400358retry_alloc:
359 new_bh = alloc_buffer_head(GFP_NOFS);
360 if (!new_bh) {
361 /*
362 * Failure is not an option, but __GFP_NOFAIL is going
363 * away; so we retry ourselves here.
364 */
365 congestion_wait(BLK_RW_ASYNC, HZ/50);
366 goto retry_alloc;
367 }
368
dingdinghua96577c42009-07-13 17:55:35 -0400369 /* keep subsequent assertions sane */
370 new_bh->b_state = 0;
371 init_buffer(new_bh, NULL, NULL);
372 atomic_set(&new_bh->b_count, 1);
373 new_jh = jbd2_journal_add_journal_head(new_bh); /* This sleeps */
Dave Kleikamp470decc2006-10-11 01:20:57 -0700374
375 /*
376 * If a new transaction has already done a buffer copy-out, then
377 * we use that version of the data for the commit.
378 */
379 jbd_lock_bh_state(bh_in);
380repeat:
381 if (jh_in->b_frozen_data) {
382 done_copy_out = 1;
383 new_page = virt_to_page(jh_in->b_frozen_data);
384 new_offset = offset_in_page(jh_in->b_frozen_data);
385 } else {
386 new_page = jh2bh(jh_in)->b_page;
387 new_offset = offset_in_page(jh2bh(jh_in)->b_data);
388 }
389
Cong Wang303a8f22011-11-25 23:14:31 +0800390 mapped_data = kmap_atomic(new_page);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700391 /*
Jan Kara13ceef02010-07-14 07:56:33 +0200392 * Fire data frozen trigger if data already wasn't frozen. Do this
393 * before checking for escaping, as the trigger may modify the magic
394 * offset. If a copy-out happens afterwards, it will have the correct
395 * data in the buffer.
Joel Beckere06c8222008-09-11 15:35:47 -0700396 */
Jan Kara13ceef02010-07-14 07:56:33 +0200397 if (!done_copy_out)
398 jbd2_buffer_frozen_trigger(jh_in, mapped_data + new_offset,
399 jh_in->b_triggers);
Joel Beckere06c8222008-09-11 15:35:47 -0700400
401 /*
Dave Kleikamp470decc2006-10-11 01:20:57 -0700402 * Check for escaping
403 */
404 if (*((__be32 *)(mapped_data + new_offset)) ==
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700405 cpu_to_be32(JBD2_MAGIC_NUMBER)) {
Dave Kleikamp470decc2006-10-11 01:20:57 -0700406 need_copy_out = 1;
407 do_escape = 1;
408 }
Cong Wang303a8f22011-11-25 23:14:31 +0800409 kunmap_atomic(mapped_data);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700410
411 /*
412 * Do we need to do a data copy?
413 */
414 if (need_copy_out && !done_copy_out) {
415 char *tmp;
416
417 jbd_unlock_bh_state(bh_in);
Mingming Caoaf1e76d2007-10-16 18:38:25 -0400418 tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
Theodore Ts'oe6ec1162009-12-01 09:04:42 -0500419 if (!tmp) {
420 jbd2_journal_put_journal_head(new_jh);
421 return -ENOMEM;
422 }
Dave Kleikamp470decc2006-10-11 01:20:57 -0700423 jbd_lock_bh_state(bh_in);
424 if (jh_in->b_frozen_data) {
Mingming Caoaf1e76d2007-10-16 18:38:25 -0400425 jbd2_free(tmp, bh_in->b_size);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700426 goto repeat;
427 }
428
429 jh_in->b_frozen_data = tmp;
Cong Wang303a8f22011-11-25 23:14:31 +0800430 mapped_data = kmap_atomic(new_page);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700431 memcpy(tmp, mapped_data + new_offset, jh2bh(jh_in)->b_size);
Cong Wang303a8f22011-11-25 23:14:31 +0800432 kunmap_atomic(mapped_data);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700433
434 new_page = virt_to_page(tmp);
435 new_offset = offset_in_page(tmp);
436 done_copy_out = 1;
Joel Beckere06c8222008-09-11 15:35:47 -0700437
438 /*
439 * This isn't strictly necessary, as we're using frozen
440 * data for the escaping, but it keeps consistency with
441 * b_frozen_data usage.
442 */
443 jh_in->b_frozen_triggers = jh_in->b_triggers;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700444 }
445
446 /*
447 * Did we need to do an escaping? Now we've done all the
448 * copying, we can finally do so.
449 */
450 if (do_escape) {
Cong Wang303a8f22011-11-25 23:14:31 +0800451 mapped_data = kmap_atomic(new_page);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700452 *((unsigned int *)(mapped_data + new_offset)) = 0;
Cong Wang303a8f22011-11-25 23:14:31 +0800453 kunmap_atomic(mapped_data);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700454 }
455
Dave Kleikamp470decc2006-10-11 01:20:57 -0700456 set_bh_page(new_bh, new_page, new_offset);
457 new_jh->b_transaction = NULL;
458 new_bh->b_size = jh2bh(jh_in)->b_size;
459 new_bh->b_bdev = transaction->t_journal->j_dev;
460 new_bh->b_blocknr = blocknr;
461 set_buffer_mapped(new_bh);
462 set_buffer_dirty(new_bh);
463
464 *jh_out = new_jh;
465
466 /*
467 * The to-be-written buffer needs to get moved to the io queue,
468 * and the original buffer whose contents we are shadowing or
469 * copying is moved to the transaction's shadow queue.
470 */
471 JBUFFER_TRACE(jh_in, "file as BJ_Shadow");
dingdinghua96577c42009-07-13 17:55:35 -0400472 spin_lock(&journal->j_list_lock);
473 __jbd2_journal_file_buffer(jh_in, transaction, BJ_Shadow);
474 spin_unlock(&journal->j_list_lock);
475 jbd_unlock_bh_state(bh_in);
476
Dave Kleikamp470decc2006-10-11 01:20:57 -0700477 JBUFFER_TRACE(new_jh, "file as BJ_IO");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700478 jbd2_journal_file_buffer(new_jh, transaction, BJ_IO);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700479
480 return do_escape | (done_copy_out << 1);
481}
482
483/*
484 * Allocation code for the journal file. Manage the space left in the
485 * journal, so that we can begin checkpointing when appropriate.
486 */
487
488/*
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700489 * __jbd2_log_space_left: Return the number of free blocks left in the journal.
Dave Kleikamp470decc2006-10-11 01:20:57 -0700490 *
491 * Called with the journal already locked.
492 *
493 * Called under j_state_lock
494 */
495
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700496int __jbd2_log_space_left(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700497{
498 int left = journal->j_free;
499
Theodore Ts'oa931da62010-08-03 21:35:12 -0400500 /* assert_spin_locked(&journal->j_state_lock); */
Dave Kleikamp470decc2006-10-11 01:20:57 -0700501
502 /*
503 * Be pessimistic here about the number of those free blocks which
504 * might be required for log descriptor control blocks.
505 */
506
507#define MIN_LOG_RESERVED_BLOCKS 32 /* Allow for rounding errors */
508
509 left -= MIN_LOG_RESERVED_BLOCKS;
510
511 if (left <= 0)
512 return 0;
513 left -= (left >> 3);
514 return left;
515}
516
517/*
Theodore Ts'oe4471832011-02-12 08:18:24 -0500518 * Called with j_state_lock locked for writing.
519 * Returns true if a transaction commit was started.
Dave Kleikamp470decc2006-10-11 01:20:57 -0700520 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700521int __jbd2_log_start_commit(journal_t *journal, tid_t target)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700522{
Eric Sandeene7b04ac2013-01-30 00:39:28 -0500523 /* Return if the txn has already requested to be committed */
524 if (journal->j_commit_request == target)
525 return 0;
526
Dave Kleikamp470decc2006-10-11 01:20:57 -0700527 /*
Theodore Ts'odeeeaf12011-05-01 18:16:26 -0400528 * The only transaction we can possibly wait upon is the
529 * currently running transaction (if it exists). Otherwise,
530 * the target tid must be an old one.
Dave Kleikamp470decc2006-10-11 01:20:57 -0700531 */
Theodore Ts'odeeeaf12011-05-01 18:16:26 -0400532 if (journal->j_running_transaction &&
533 journal->j_running_transaction->t_tid == target) {
Dave Kleikamp470decc2006-10-11 01:20:57 -0700534 /*
Andrea Gelminibcf3d0b2010-10-16 15:19:14 +0200535 * We want a new commit: OK, mark the request and wakeup the
Dave Kleikamp470decc2006-10-11 01:20:57 -0700536 * commit thread. We do _not_ do the commit ourselves.
537 */
538
539 journal->j_commit_request = target;
Eryu Guanf2a44522011-11-01 19:09:18 -0400540 jbd_debug(1, "JBD2: requesting commit %d/%d\n",
Dave Kleikamp470decc2006-10-11 01:20:57 -0700541 journal->j_commit_request,
542 journal->j_commit_sequence);
Theodore Ts'o9fff24a2013-02-06 22:30:23 -0500543 journal->j_running_transaction->t_requested = jiffies;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700544 wake_up(&journal->j_wait_commit);
545 return 1;
Theodore Ts'odeeeaf12011-05-01 18:16:26 -0400546 } else if (!tid_geq(journal->j_commit_request, target))
547 /* This should never happen, but if it does, preserve
548 the evidence before kjournald goes into a loop and
549 increments j_commit_sequence beyond all recognition. */
Eryu Guanf2a44522011-11-01 19:09:18 -0400550 WARN_ONCE(1, "JBD2: bad log_start_commit: %u %u %u %u\n",
Theodore Ts'o1be2add2011-05-08 19:37:54 -0400551 journal->j_commit_request,
552 journal->j_commit_sequence,
553 target, journal->j_running_transaction ?
554 journal->j_running_transaction->t_tid : 0);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700555 return 0;
556}
557
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700558int jbd2_log_start_commit(journal_t *journal, tid_t tid)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700559{
560 int ret;
561
Theodore Ts'oa931da62010-08-03 21:35:12 -0400562 write_lock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700563 ret = __jbd2_log_start_commit(journal, tid);
Theodore Ts'oa931da62010-08-03 21:35:12 -0400564 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700565 return ret;
566}
567
568/*
569 * Force and wait upon a commit if the calling process is not within
570 * transaction. This is used for forcing out undo-protected data which contains
571 * bitmaps, when the fs is running out of space.
572 *
573 * We can only force the running transaction if we don't have an active handle;
574 * otherwise, we will deadlock.
575 *
576 * Returns true if a transaction was started.
577 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700578int jbd2_journal_force_commit_nested(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700579{
580 transaction_t *transaction = NULL;
581 tid_t tid;
Theodore Ts'oe4471832011-02-12 08:18:24 -0500582 int need_to_start = 0;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700583
Theodore Ts'oa931da62010-08-03 21:35:12 -0400584 read_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700585 if (journal->j_running_transaction && !current->journal_info) {
586 transaction = journal->j_running_transaction;
Theodore Ts'oe4471832011-02-12 08:18:24 -0500587 if (!tid_geq(journal->j_commit_request, transaction->t_tid))
588 need_to_start = 1;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700589 } else if (journal->j_committing_transaction)
590 transaction = journal->j_committing_transaction;
591
592 if (!transaction) {
Theodore Ts'oa931da62010-08-03 21:35:12 -0400593 read_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700594 return 0; /* Nothing to retry */
595 }
596
597 tid = transaction->t_tid;
Theodore Ts'oa931da62010-08-03 21:35:12 -0400598 read_unlock(&journal->j_state_lock);
Theodore Ts'oe4471832011-02-12 08:18:24 -0500599 if (need_to_start)
600 jbd2_log_start_commit(journal, tid);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700601 jbd2_log_wait_commit(journal, tid);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700602 return 1;
603}
604
605/*
606 * Start a commit of the current running transaction (if any). Returns true
Jan Karac88ccea2009-02-10 11:27:46 -0500607 * if a transaction is going to be committed (or is currently already
608 * committing), and fills its tid in at *ptid
Dave Kleikamp470decc2006-10-11 01:20:57 -0700609 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700610int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700611{
612 int ret = 0;
613
Theodore Ts'oa931da62010-08-03 21:35:12 -0400614 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700615 if (journal->j_running_transaction) {
616 tid_t tid = journal->j_running_transaction->t_tid;
617
Jan Karac88ccea2009-02-10 11:27:46 -0500618 __jbd2_log_start_commit(journal, tid);
619 /* There's a running transaction and we've just made sure
620 * it's commit has been scheduled. */
621 if (ptid)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700622 *ptid = tid;
Jan Karac88ccea2009-02-10 11:27:46 -0500623 ret = 1;
624 } else if (journal->j_committing_transaction) {
Dave Kleikamp470decc2006-10-11 01:20:57 -0700625 /*
Artem Bityutskiy12810ad2012-07-25 18:12:07 +0300626 * If commit has been started, then we have to wait for
627 * completion of that transaction.
Dave Kleikamp470decc2006-10-11 01:20:57 -0700628 */
Jan Karac88ccea2009-02-10 11:27:46 -0500629 if (ptid)
630 *ptid = journal->j_committing_transaction->t_tid;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700631 ret = 1;
632 }
Theodore Ts'oa931da62010-08-03 21:35:12 -0400633 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700634 return ret;
635}
636
637/*
Jan Karabbd2be32011-05-24 11:59:18 -0400638 * Return 1 if a given transaction has not yet sent barrier request
639 * connected with a transaction commit. If 0 is returned, transaction
640 * may or may not have sent the barrier. Used to avoid sending barrier
641 * twice in common cases.
642 */
643int jbd2_trans_will_send_data_barrier(journal_t *journal, tid_t tid)
644{
645 int ret = 0;
646 transaction_t *commit_trans;
647
648 if (!(journal->j_flags & JBD2_BARRIER))
649 return 0;
650 read_lock(&journal->j_state_lock);
651 /* Transaction already committed? */
652 if (tid_geq(journal->j_commit_sequence, tid))
653 goto out;
654 commit_trans = journal->j_committing_transaction;
655 if (!commit_trans || commit_trans->t_tid != tid) {
656 ret = 1;
657 goto out;
658 }
659 /*
660 * Transaction is being committed and we already proceeded to
661 * submitting a flush to fs partition?
662 */
663 if (journal->j_fs_dev != journal->j_dev) {
664 if (!commit_trans->t_need_data_flush ||
665 commit_trans->t_state >= T_COMMIT_DFLUSH)
666 goto out;
667 } else {
668 if (commit_trans->t_state >= T_COMMIT_JFLUSH)
669 goto out;
670 }
671 ret = 1;
672out:
673 read_unlock(&journal->j_state_lock);
674 return ret;
675}
676EXPORT_SYMBOL(jbd2_trans_will_send_data_barrier);
677
678/*
Dave Kleikamp470decc2006-10-11 01:20:57 -0700679 * Wait for a specified commit to complete.
680 * The caller may not hold the journal lock.
681 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700682int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700683{
684 int err = 0;
685
Theodore Ts'oa931da62010-08-03 21:35:12 -0400686 read_lock(&journal->j_state_lock);
Jose R. Santose23291b2007-07-18 08:57:06 -0400687#ifdef CONFIG_JBD2_DEBUG
Dave Kleikamp470decc2006-10-11 01:20:57 -0700688 if (!tid_geq(journal->j_commit_request, tid)) {
689 printk(KERN_EMERG
690 "%s: error: j_commit_request=%d, tid=%d\n",
Harvey Harrison329d2912008-04-17 10:38:59 -0400691 __func__, journal->j_commit_request, tid);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700692 }
Dave Kleikamp470decc2006-10-11 01:20:57 -0700693#endif
Dave Kleikamp470decc2006-10-11 01:20:57 -0700694 while (tid_gt(tid, journal->j_commit_sequence)) {
Eryu Guanf2a44522011-11-01 19:09:18 -0400695 jbd_debug(1, "JBD2: want %d, j_commit_sequence=%d\n",
Dave Kleikamp470decc2006-10-11 01:20:57 -0700696 tid, journal->j_commit_sequence);
697 wake_up(&journal->j_wait_commit);
Theodore Ts'oa931da62010-08-03 21:35:12 -0400698 read_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700699 wait_event(journal->j_wait_done_commit,
700 !tid_gt(tid, journal->j_commit_sequence));
Theodore Ts'oa931da62010-08-03 21:35:12 -0400701 read_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700702 }
Theodore Ts'oa931da62010-08-03 21:35:12 -0400703 read_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700704
705 if (unlikely(is_journal_aborted(journal))) {
706 printk(KERN_EMERG "journal commit I/O error\n");
707 err = -EIO;
708 }
709 return err;
710}
711
712/*
713 * Log buffer allocation routines:
714 */
715
Mingming Cao18eba7a2006-10-11 01:21:13 -0700716int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700717{
718 unsigned long blocknr;
719
Theodore Ts'oa931da62010-08-03 21:35:12 -0400720 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700721 J_ASSERT(journal->j_free > 1);
722
723 blocknr = journal->j_head;
724 journal->j_head++;
725 journal->j_free--;
726 if (journal->j_head == journal->j_last)
727 journal->j_head = journal->j_first;
Theodore Ts'oa931da62010-08-03 21:35:12 -0400728 write_unlock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700729 return jbd2_journal_bmap(journal, blocknr, retp);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700730}
731
732/*
733 * Conversion of logical to physical block numbers for the journal
734 *
735 * On external journals the journal blocks are identity-mapped, so
736 * this is a no-op. If needed, we can use j_blk_offset - everything is
737 * ready.
738 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700739int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
Mingming Cao18eba7a2006-10-11 01:21:13 -0700740 unsigned long long *retp)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700741{
742 int err = 0;
Mingming Cao18eba7a2006-10-11 01:21:13 -0700743 unsigned long long ret;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700744
745 if (journal->j_inode) {
746 ret = bmap(journal->j_inode, blocknr);
747 if (ret)
748 *retp = ret;
749 else {
Dave Kleikamp470decc2006-10-11 01:20:57 -0700750 printk(KERN_ALERT "%s: journal block not found "
751 "at offset %lu on %s\n",
Theodore Ts'o05496762008-09-16 14:36:17 -0400752 __func__, blocknr, journal->j_devname);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700753 err = -EIO;
754 __journal_abort_soft(journal, err);
755 }
756 } else {
757 *retp = blocknr; /* +journal->j_blk_offset */
758 }
759 return err;
760}
761
762/*
763 * We play buffer_head aliasing tricks to write data/metadata blocks to
764 * the journal without copying their contents, but for journal
765 * descriptor blocks we do need to generate bona fide buffers.
766 *
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700767 * After the caller of jbd2_journal_get_descriptor_buffer() has finished modifying
Dave Kleikamp470decc2006-10-11 01:20:57 -0700768 * the buffer's contents they really should run flush_dcache_page(bh->b_page).
769 * But we don't bother doing that, so there will be coherency problems with
770 * mmaps of blockdevs which hold live JBD-controlled filesystems.
771 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700772struct journal_head *jbd2_journal_get_descriptor_buffer(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -0700773{
774 struct buffer_head *bh;
Mingming Cao18eba7a2006-10-11 01:21:13 -0700775 unsigned long long blocknr;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700776 int err;
777
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700778 err = jbd2_journal_next_log_block(journal, &blocknr);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700779
780 if (err)
781 return NULL;
782
783 bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
Jan Kara4b905672009-01-06 14:53:35 -0500784 if (!bh)
785 return NULL;
Dave Kleikamp470decc2006-10-11 01:20:57 -0700786 lock_buffer(bh);
787 memset(bh->b_data, 0, journal->j_blocksize);
788 set_buffer_uptodate(bh);
789 unlock_buffer(bh);
790 BUFFER_TRACE(bh, "return this buffer");
Mingming Caof7f4bcc2006-10-11 01:20:59 -0700791 return jbd2_journal_add_journal_head(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -0700792}
793
Jan Kara79feb522012-03-13 22:22:54 -0400794/*
795 * Return tid of the oldest transaction in the journal and block in the journal
796 * where the transaction starts.
797 *
798 * If the journal is now empty, return which will be the next transaction ID
799 * we will write and where will that transaction start.
800 *
801 * The return value is 0 if journal tail cannot be pushed any further, 1 if
802 * it can.
803 */
804int jbd2_journal_get_log_tail(journal_t *journal, tid_t *tid,
805 unsigned long *block)
806{
807 transaction_t *transaction;
808 int ret;
809
810 read_lock(&journal->j_state_lock);
811 spin_lock(&journal->j_list_lock);
812 transaction = journal->j_checkpoint_transactions;
813 if (transaction) {
814 *tid = transaction->t_tid;
815 *block = transaction->t_log_start;
816 } else if ((transaction = journal->j_committing_transaction) != NULL) {
817 *tid = transaction->t_tid;
818 *block = transaction->t_log_start;
819 } else if ((transaction = journal->j_running_transaction) != NULL) {
820 *tid = transaction->t_tid;
821 *block = journal->j_head;
822 } else {
823 *tid = journal->j_transaction_sequence;
824 *block = journal->j_head;
825 }
826 ret = tid_gt(*tid, journal->j_tail_sequence);
827 spin_unlock(&journal->j_list_lock);
828 read_unlock(&journal->j_state_lock);
829
830 return ret;
831}
832
833/*
834 * Update information in journal structure and in on disk journal superblock
835 * about log tail. This function does not check whether information passed in
836 * really pushes log tail further. It's responsibility of the caller to make
837 * sure provided log tail information is valid (e.g. by holding
838 * j_checkpoint_mutex all the time between computing log tail and calling this
839 * function as is the case with jbd2_cleanup_journal_tail()).
840 *
841 * Requires j_checkpoint_mutex
842 */
843void __jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block)
844{
845 unsigned long freed;
846
847 BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
848
849 /*
850 * We cannot afford for write to remain in drive's caches since as
851 * soon as we update j_tail, next transaction can start reusing journal
852 * space and if we lose sb update during power failure we'd replay
853 * old transaction with possibly newly overwritten data.
854 */
855 jbd2_journal_update_sb_log_tail(journal, tid, block, WRITE_FUA);
856 write_lock(&journal->j_state_lock);
857 freed = block - journal->j_tail;
858 if (block < journal->j_tail)
859 freed += journal->j_last - journal->j_first;
860
861 trace_jbd2_update_log_tail(journal, tid, block, freed);
862 jbd_debug(1,
863 "Cleaning journal tail from %d to %d (offset %lu), "
864 "freeing %lu\n",
865 journal->j_tail_sequence, tid, block, freed);
866
867 journal->j_free += freed;
868 journal->j_tail_sequence = tid;
869 journal->j_tail = block;
870 write_unlock(&journal->j_state_lock);
871}
872
Jan Kara33395782012-03-13 22:45:38 -0400873/*
874 * This is a variaon of __jbd2_update_log_tail which checks for validity of
875 * provided log tail and locks j_checkpoint_mutex. So it is safe against races
876 * with other threads updating log tail.
877 */
878void jbd2_update_log_tail(journal_t *journal, tid_t tid, unsigned long block)
879{
880 mutex_lock(&journal->j_checkpoint_mutex);
881 if (tid_gt(tid, journal->j_tail_sequence))
882 __jbd2_update_log_tail(journal, tid, block);
883 mutex_unlock(&journal->j_checkpoint_mutex);
884}
885
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500886struct jbd2_stats_proc_session {
887 journal_t *journal;
888 struct transaction_stats_s *stats;
889 int start;
890 int max;
891};
892
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500893static void *jbd2_seq_info_start(struct seq_file *seq, loff_t *pos)
894{
895 return *pos ? NULL : SEQ_START_TOKEN;
896}
897
898static void *jbd2_seq_info_next(struct seq_file *seq, void *v, loff_t *pos)
899{
900 return NULL;
901}
902
903static int jbd2_seq_info_show(struct seq_file *seq, void *v)
904{
905 struct jbd2_stats_proc_session *s = seq->private;
906
907 if (v != SEQ_START_TOKEN)
908 return 0;
Theodore Ts'o9fff24a2013-02-06 22:30:23 -0500909 seq_printf(seq, "%lu transactions (%lu requested), "
910 "each up to %u blocks\n",
911 s->stats->ts_tid, s->stats->ts_requested,
912 s->journal->j_max_transaction_buffers);
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500913 if (s->stats->ts_tid == 0)
914 return 0;
915 seq_printf(seq, "average: \n %ums waiting for transaction\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400916 jiffies_to_msecs(s->stats->run.rs_wait / s->stats->ts_tid));
Theodore Ts'o9fff24a2013-02-06 22:30:23 -0500917 seq_printf(seq, " %ums request delay\n",
918 (s->stats->ts_requested == 0) ? 0 :
919 jiffies_to_msecs(s->stats->run.rs_request_delay /
920 s->stats->ts_requested));
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500921 seq_printf(seq, " %ums running transaction\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400922 jiffies_to_msecs(s->stats->run.rs_running / s->stats->ts_tid));
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500923 seq_printf(seq, " %ums transaction was being locked\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400924 jiffies_to_msecs(s->stats->run.rs_locked / s->stats->ts_tid));
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500925 seq_printf(seq, " %ums flushing data (in ordered mode)\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400926 jiffies_to_msecs(s->stats->run.rs_flushing / s->stats->ts_tid));
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500927 seq_printf(seq, " %ums logging transaction\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400928 jiffies_to_msecs(s->stats->run.rs_logging / s->stats->ts_tid));
Simon Holm Thøgersenc225aa52009-01-11 22:34:01 -0500929 seq_printf(seq, " %lluus average transaction commit time\n",
930 div_u64(s->journal->j_average_commit_time, 1000));
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500931 seq_printf(seq, " %lu handles per transaction\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400932 s->stats->run.rs_handle_count / s->stats->ts_tid);
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500933 seq_printf(seq, " %lu blocks per transaction\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400934 s->stats->run.rs_blocks / s->stats->ts_tid);
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500935 seq_printf(seq, " %lu logged blocks per transaction\n",
Theodore Ts'obf699322009-09-30 00:32:06 -0400936 s->stats->run.rs_blocks_logged / s->stats->ts_tid);
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500937 return 0;
938}
939
940static void jbd2_seq_info_stop(struct seq_file *seq, void *v)
941{
942}
943
James Morris88e9d342009-09-22 16:43:43 -0700944static const struct seq_operations jbd2_seq_info_ops = {
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500945 .start = jbd2_seq_info_start,
946 .next = jbd2_seq_info_next,
947 .stop = jbd2_seq_info_stop,
948 .show = jbd2_seq_info_show,
949};
950
951static int jbd2_seq_info_open(struct inode *inode, struct file *file)
952{
953 journal_t *journal = PDE(inode)->data;
954 struct jbd2_stats_proc_session *s;
955 int rc, size;
956
957 s = kmalloc(sizeof(*s), GFP_KERNEL);
958 if (s == NULL)
959 return -ENOMEM;
960 size = sizeof(struct transaction_stats_s);
961 s->stats = kmalloc(size, GFP_KERNEL);
962 if (s->stats == NULL) {
963 kfree(s);
964 return -ENOMEM;
965 }
966 spin_lock(&journal->j_history_lock);
967 memcpy(s->stats, &journal->j_stats, size);
968 s->journal = journal;
969 spin_unlock(&journal->j_history_lock);
970
971 rc = seq_open(file, &jbd2_seq_info_ops);
972 if (rc == 0) {
973 struct seq_file *m = file->private_data;
974 m->private = s;
975 } else {
976 kfree(s->stats);
977 kfree(s);
978 }
979 return rc;
980
981}
982
983static int jbd2_seq_info_release(struct inode *inode, struct file *file)
984{
985 struct seq_file *seq = file->private_data;
986 struct jbd2_stats_proc_session *s = seq->private;
987 kfree(s->stats);
988 kfree(s);
989 return seq_release(inode, file);
990}
991
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700992static const struct file_operations jbd2_seq_info_fops = {
Johann Lombardi8e85fb32008-01-28 23:58:27 -0500993 .owner = THIS_MODULE,
994 .open = jbd2_seq_info_open,
995 .read = seq_read,
996 .llseek = seq_lseek,
997 .release = jbd2_seq_info_release,
998};
999
1000static struct proc_dir_entry *proc_jbd2_stats;
1001
1002static void jbd2_stats_proc_init(journal_t *journal)
1003{
Theodore Ts'o05496762008-09-16 14:36:17 -04001004 journal->j_proc_entry = proc_mkdir(journal->j_devname, proc_jbd2_stats);
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001005 if (journal->j_proc_entry) {
Denis V. Lunev79da3662008-04-29 01:02:11 -07001006 proc_create_data("info", S_IRUGO, journal->j_proc_entry,
1007 &jbd2_seq_info_fops, journal);
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001008 }
1009}
1010
1011static void jbd2_stats_proc_exit(journal_t *journal)
1012{
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001013 remove_proc_entry("info", journal->j_proc_entry);
Theodore Ts'o05496762008-09-16 14:36:17 -04001014 remove_proc_entry(journal->j_devname, proc_jbd2_stats);
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001015}
1016
Dave Kleikamp470decc2006-10-11 01:20:57 -07001017/*
1018 * Management for journal control blocks: functions to create and
1019 * destroy journal_t structures, and to initialise and read existing
1020 * journal blocks from disk. */
1021
1022/* First: create and setup a journal_t object in memory. We initialise
1023 * very few fields yet: that has to wait until we have created the
1024 * journal structures from from scratch, or loaded them from disk. */
1025
1026static journal_t * journal_init_common (void)
1027{
1028 journal_t *journal;
1029 int err;
1030
Andrew Morton3ebfdf82009-12-23 08:05:15 -05001031 journal = kzalloc(sizeof(*journal), GFP_KERNEL);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001032 if (!journal)
Theodore Ts'ob7271b02010-12-18 13:39:38 -05001033 return NULL;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001034
1035 init_waitqueue_head(&journal->j_wait_transaction_locked);
1036 init_waitqueue_head(&journal->j_wait_logspace);
1037 init_waitqueue_head(&journal->j_wait_done_commit);
1038 init_waitqueue_head(&journal->j_wait_checkpoint);
1039 init_waitqueue_head(&journal->j_wait_commit);
1040 init_waitqueue_head(&journal->j_wait_updates);
1041 mutex_init(&journal->j_barrier);
1042 mutex_init(&journal->j_checkpoint_mutex);
1043 spin_lock_init(&journal->j_revoke_lock);
1044 spin_lock_init(&journal->j_list_lock);
Theodore Ts'oa931da62010-08-03 21:35:12 -04001045 rwlock_init(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001046
Mingming Caocd02ff02007-10-16 18:38:25 -04001047 journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
Theodore Ts'o30773842009-01-03 20:27:38 -05001048 journal->j_min_batch_time = 0;
1049 journal->j_max_batch_time = 15000; /* 15ms */
Dave Kleikamp470decc2006-10-11 01:20:57 -07001050
1051 /* The journal is marked for error until we succeed with recovery! */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001052 journal->j_flags = JBD2_ABORT;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001053
1054 /* Set up a default-sized revoke table for the new mount. */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001055 err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001056 if (err) {
1057 kfree(journal);
Theodore Ts'ob7271b02010-12-18 13:39:38 -05001058 return NULL;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001059 }
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001060
Theodore Ts'obf699322009-09-30 00:32:06 -04001061 spin_lock_init(&journal->j_history_lock);
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001062
Dave Kleikamp470decc2006-10-11 01:20:57 -07001063 return journal;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001064}
1065
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001066/* jbd2_journal_init_dev and jbd2_journal_init_inode:
Dave Kleikamp470decc2006-10-11 01:20:57 -07001067 *
1068 * Create a journal structure assigned some fixed set of disk blocks to
1069 * the journal. We don't actually touch those disk blocks yet, but we
1070 * need to set up all of the mapping information to tell the journaling
1071 * system where the journal blocks are.
1072 *
1073 */
1074
1075/**
Randy Dunlap5648ba52008-04-17 10:38:59 -04001076 * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure
Dave Kleikamp470decc2006-10-11 01:20:57 -07001077 * @bdev: Block device on which to create the journal
1078 * @fs_dev: Device which hold journalled filesystem for this journal.
1079 * @start: Block nr Start of journal.
1080 * @len: Length of the journal in blocks.
1081 * @blocksize: blocksize of journalling device
Randy Dunlap5648ba52008-04-17 10:38:59 -04001082 *
1083 * Returns: a newly created journal_t *
Dave Kleikamp470decc2006-10-11 01:20:57 -07001084 *
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001085 * jbd2_journal_init_dev creates a journal which maps a fixed contiguous
Dave Kleikamp470decc2006-10-11 01:20:57 -07001086 * range of blocks on an arbitrary block device.
1087 *
1088 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001089journal_t * jbd2_journal_init_dev(struct block_device *bdev,
Dave Kleikamp470decc2006-10-11 01:20:57 -07001090 struct block_device *fs_dev,
Mingming Cao18eba7a2006-10-11 01:21:13 -07001091 unsigned long long start, int len, int blocksize)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001092{
1093 journal_t *journal = journal_init_common();
1094 struct buffer_head *bh;
Theodore Ts'o05496762008-09-16 14:36:17 -04001095 char *p;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001096 int n;
1097
1098 if (!journal)
1099 return NULL;
1100
1101 /* journal descriptor can store up to n blocks -bzzz */
1102 journal->j_blocksize = blocksize;
yangsheng0587aa32010-11-17 21:46:26 -05001103 journal->j_dev = bdev;
1104 journal->j_fs_dev = fs_dev;
1105 journal->j_blk_offset = start;
1106 journal->j_maxlen = len;
1107 bdevname(journal->j_dev, journal->j_devname);
1108 p = journal->j_devname;
1109 while ((p = strchr(p, '/')))
1110 *p = '!';
Jan Kara4b905672009-01-06 14:53:35 -05001111 jbd2_stats_proc_init(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001112 n = journal->j_blocksize / sizeof(journal_block_tag_t);
1113 journal->j_wbufsize = n;
1114 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
1115 if (!journal->j_wbuf) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001116 printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n",
Harvey Harrison329d2912008-04-17 10:38:59 -04001117 __func__);
Jan Kara4b905672009-01-06 14:53:35 -05001118 goto out_err;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001119 }
Dave Kleikamp470decc2006-10-11 01:20:57 -07001120
1121 bh = __getblk(journal->j_dev, start, journal->j_blocksize);
Jan Kara4b905672009-01-06 14:53:35 -05001122 if (!bh) {
1123 printk(KERN_ERR
1124 "%s: Cannot get buffer for journal superblock\n",
1125 __func__);
1126 goto out_err;
1127 }
Dave Kleikamp470decc2006-10-11 01:20:57 -07001128 journal->j_sb_buffer = bh;
1129 journal->j_superblock = (journal_superblock_t *)bh->b_data;
Jan Kara4b905672009-01-06 14:53:35 -05001130
Dave Kleikamp470decc2006-10-11 01:20:57 -07001131 return journal;
Jan Kara4b905672009-01-06 14:53:35 -05001132out_err:
Tao Ma7b02bec2009-11-10 17:13:22 +08001133 kfree(journal->j_wbuf);
Jan Kara4b905672009-01-06 14:53:35 -05001134 jbd2_stats_proc_exit(journal);
1135 kfree(journal);
1136 return NULL;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001137}
1138
1139/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001140 * journal_t * jbd2_journal_init_inode () - creates a journal which maps to a inode.
Dave Kleikamp470decc2006-10-11 01:20:57 -07001141 * @inode: An inode to create the journal in
1142 *
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001143 * jbd2_journal_init_inode creates a journal which maps an on-disk inode as
Dave Kleikamp470decc2006-10-11 01:20:57 -07001144 * the journal. The inode must exist already, must support bmap() and
1145 * must have all data blocks preallocated.
1146 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001147journal_t * jbd2_journal_init_inode (struct inode *inode)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001148{
1149 struct buffer_head *bh;
1150 journal_t *journal = journal_init_common();
Theodore Ts'o05496762008-09-16 14:36:17 -04001151 char *p;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001152 int err;
1153 int n;
Mingming Cao18eba7a2006-10-11 01:21:13 -07001154 unsigned long long blocknr;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001155
1156 if (!journal)
1157 return NULL;
1158
1159 journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
1160 journal->j_inode = inode;
Theodore Ts'o05496762008-09-16 14:36:17 -04001161 bdevname(journal->j_dev, journal->j_devname);
1162 p = journal->j_devname;
1163 while ((p = strchr(p, '/')))
1164 *p = '!';
1165 p = journal->j_devname + strlen(journal->j_devname);
Theodore Ts'o90576c02009-09-29 15:51:30 -04001166 sprintf(p, "-%lu", journal->j_inode->i_ino);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001167 jbd_debug(1,
1168 "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
1169 journal, inode->i_sb->s_id, inode->i_ino,
1170 (long long) inode->i_size,
1171 inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
1172
1173 journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits;
1174 journal->j_blocksize = inode->i_sb->s_blocksize;
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001175 jbd2_stats_proc_init(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001176
1177 /* journal descriptor can store up to n blocks -bzzz */
1178 n = journal->j_blocksize / sizeof(journal_block_tag_t);
1179 journal->j_wbufsize = n;
1180 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
1181 if (!journal->j_wbuf) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001182 printk(KERN_ERR "%s: Can't allocate bhs for commit thread\n",
Harvey Harrison329d2912008-04-17 10:38:59 -04001183 __func__);
Jan Kara4b905672009-01-06 14:53:35 -05001184 goto out_err;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001185 }
1186
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001187 err = jbd2_journal_bmap(journal, 0, &blocknr);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001188 /* If that failed, give up */
1189 if (err) {
Justin P. Mattock3c26bdb2011-02-26 20:34:05 -08001190 printk(KERN_ERR "%s: Cannot locate journal superblock\n",
Harvey Harrison329d2912008-04-17 10:38:59 -04001191 __func__);
Jan Kara4b905672009-01-06 14:53:35 -05001192 goto out_err;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001193 }
1194
1195 bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
Jan Kara4b905672009-01-06 14:53:35 -05001196 if (!bh) {
1197 printk(KERN_ERR
1198 "%s: Cannot get buffer for journal superblock\n",
1199 __func__);
1200 goto out_err;
1201 }
Dave Kleikamp470decc2006-10-11 01:20:57 -07001202 journal->j_sb_buffer = bh;
1203 journal->j_superblock = (journal_superblock_t *)bh->b_data;
1204
1205 return journal;
Jan Kara4b905672009-01-06 14:53:35 -05001206out_err:
Tao Ma7b02bec2009-11-10 17:13:22 +08001207 kfree(journal->j_wbuf);
Jan Kara4b905672009-01-06 14:53:35 -05001208 jbd2_stats_proc_exit(journal);
1209 kfree(journal);
1210 return NULL;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001211}
1212
1213/*
1214 * If the journal init or create aborts, we need to mark the journal
1215 * superblock as being NULL to prevent the journal destroy from writing
1216 * back a bogus superblock.
1217 */
1218static void journal_fail_superblock (journal_t *journal)
1219{
1220 struct buffer_head *bh = journal->j_sb_buffer;
1221 brelse(bh);
1222 journal->j_sb_buffer = NULL;
1223}
1224
1225/*
1226 * Given a journal_t structure, initialise the various fields for
1227 * startup of a new journaling session. We use this both when creating
1228 * a journal, and after recovering an old journal to reset it for
1229 * subsequent use.
1230 */
1231
1232static int journal_reset(journal_t *journal)
1233{
1234 journal_superblock_t *sb = journal->j_superblock;
Mingming Cao18eba7a2006-10-11 01:21:13 -07001235 unsigned long long first, last;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001236
1237 first = be32_to_cpu(sb->s_first);
1238 last = be32_to_cpu(sb->s_maxlen);
Jan Karaf6f50e22009-07-17 10:40:01 -04001239 if (first + JBD2_MIN_JOURNAL_BLOCKS > last + 1) {
Eryu Guanf2a44522011-11-01 19:09:18 -04001240 printk(KERN_ERR "JBD2: Journal too short (blocks %llu-%llu).\n",
Jan Karaf6f50e22009-07-17 10:40:01 -04001241 first, last);
1242 journal_fail_superblock(journal);
1243 return -EINVAL;
1244 }
Dave Kleikamp470decc2006-10-11 01:20:57 -07001245
1246 journal->j_first = first;
1247 journal->j_last = last;
1248
1249 journal->j_head = first;
1250 journal->j_tail = first;
1251 journal->j_free = last - first;
1252
1253 journal->j_tail_sequence = journal->j_transaction_sequence;
1254 journal->j_commit_sequence = journal->j_transaction_sequence - 1;
1255 journal->j_commit_request = journal->j_commit_sequence;
1256
1257 journal->j_max_transaction_buffers = journal->j_maxlen / 4;
1258
Dave Kleikamp470decc2006-10-11 01:20:57 -07001259 /*
1260 * As a special case, if the on-disk copy is already marked as needing
Jan Kara24bcc892012-03-13 15:41:04 -04001261 * no recovery (s_start == 0), then we can safely defer the superblock
1262 * update until the next commit by setting JBD2_FLUSHED. This avoids
Dave Kleikamp470decc2006-10-11 01:20:57 -07001263 * attempting a write to a potential-readonly device.
1264 */
Jan Kara24bcc892012-03-13 15:41:04 -04001265 if (sb->s_start == 0) {
Eryu Guanf2a44522011-11-01 19:09:18 -04001266 jbd_debug(1, "JBD2: Skipping superblock update on recovered sb "
Dave Kleikamp470decc2006-10-11 01:20:57 -07001267 "(start %ld, seq %d, errno %d)\n",
1268 journal->j_tail, journal->j_tail_sequence,
1269 journal->j_errno);
Jan Kara24bcc892012-03-13 15:41:04 -04001270 journal->j_flags |= JBD2_FLUSHED;
1271 } else {
Jan Karaa78bb112012-03-13 15:43:04 -04001272 /* Lock here to make assertions happy... */
1273 mutex_lock(&journal->j_checkpoint_mutex);
Jan Kara79feb522012-03-13 22:22:54 -04001274 /*
1275 * Update log tail information. We use WRITE_FUA since new
1276 * transaction will start reusing journal space and so we
1277 * must make sure information about current log tail is on
1278 * disk before that.
1279 */
1280 jbd2_journal_update_sb_log_tail(journal,
1281 journal->j_tail_sequence,
1282 journal->j_tail,
1283 WRITE_FUA);
Jan Karaa78bb112012-03-13 15:43:04 -04001284 mutex_unlock(&journal->j_checkpoint_mutex);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001285 }
Jan Kara24bcc892012-03-13 15:41:04 -04001286 return jbd2_journal_start_thread(journal);
1287}
Dave Kleikamp470decc2006-10-11 01:20:57 -07001288
Jan Kara79feb522012-03-13 22:22:54 -04001289static void jbd2_write_superblock(journal_t *journal, int write_op)
Jan Kara24bcc892012-03-13 15:41:04 -04001290{
1291 struct buffer_head *bh = journal->j_sb_buffer;
Jan Kara79feb522012-03-13 22:22:54 -04001292 int ret;
Jan Kara24bcc892012-03-13 15:41:04 -04001293
Jan Kara79feb522012-03-13 22:22:54 -04001294 trace_jbd2_write_superblock(journal, write_op);
1295 if (!(journal->j_flags & JBD2_BARRIER))
1296 write_op &= ~(REQ_FUA | REQ_FLUSH);
1297 lock_buffer(bh);
Theodore Ts'o914258b2008-10-06 21:35:40 -04001298 if (buffer_write_io_error(bh)) {
1299 /*
1300 * Oh, dear. A previous attempt to write the journal
1301 * superblock failed. This could happen because the
1302 * USB device was yanked out. Or it could happen to
1303 * be a transient write error and maybe the block will
1304 * be remapped. Nothing we can do but to retry the
1305 * write and hope for the best.
1306 */
1307 printk(KERN_ERR "JBD2: previous I/O error detected "
1308 "for journal superblock update for %s.\n",
1309 journal->j_devname);
1310 clear_buffer_write_io_error(bh);
1311 set_buffer_uptodate(bh);
1312 }
Jan Kara79feb522012-03-13 22:22:54 -04001313 get_bh(bh);
1314 bh->b_end_io = end_buffer_write_sync;
1315 ret = submit_bh(write_op, bh);
1316 wait_on_buffer(bh);
Jan Kara24bcc892012-03-13 15:41:04 -04001317 if (buffer_write_io_error(bh)) {
Jan Kara24bcc892012-03-13 15:41:04 -04001318 clear_buffer_write_io_error(bh);
1319 set_buffer_uptodate(bh);
Jan Kara79feb522012-03-13 22:22:54 -04001320 ret = -EIO;
1321 }
1322 if (ret) {
1323 printk(KERN_ERR "JBD2: Error %d detected when updating "
1324 "journal superblock for %s.\n", ret,
1325 journal->j_devname);
Jan Kara24bcc892012-03-13 15:41:04 -04001326 }
1327}
Theodore Ts'o914258b2008-10-06 21:35:40 -04001328
Jan Kara24bcc892012-03-13 15:41:04 -04001329/**
1330 * jbd2_journal_update_sb_log_tail() - Update log tail in journal sb on disk.
1331 * @journal: The journal to update.
Jan Kara79feb522012-03-13 22:22:54 -04001332 * @tail_tid: TID of the new transaction at the tail of the log
1333 * @tail_block: The first block of the transaction at the tail of the log
1334 * @write_op: With which operation should we write the journal sb
Jan Kara24bcc892012-03-13 15:41:04 -04001335 *
1336 * Update a journal's superblock information about log tail and write it to
1337 * disk, waiting for the IO to complete.
1338 */
Jan Kara79feb522012-03-13 22:22:54 -04001339void jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
1340 unsigned long tail_block, int write_op)
Jan Kara24bcc892012-03-13 15:41:04 -04001341{
1342 journal_superblock_t *sb = journal->j_superblock;
1343
Jan Karaa78bb112012-03-13 15:43:04 -04001344 BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
Jan Kara79feb522012-03-13 22:22:54 -04001345 jbd_debug(1, "JBD2: updating superblock (start %lu, seq %u)\n",
1346 tail_block, tail_tid);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001347
Jan Kara79feb522012-03-13 22:22:54 -04001348 sb->s_sequence = cpu_to_be32(tail_tid);
1349 sb->s_start = cpu_to_be32(tail_block);
Jan Kara24bcc892012-03-13 15:41:04 -04001350
Jan Kara79feb522012-03-13 22:22:54 -04001351 jbd2_write_superblock(journal, write_op);
Jan Kara24bcc892012-03-13 15:41:04 -04001352
1353 /* Log is no longer empty */
1354 write_lock(&journal->j_state_lock);
1355 WARN_ON(!sb->s_sequence);
1356 journal->j_flags &= ~JBD2_FLUSHED;
1357 write_unlock(&journal->j_state_lock);
1358}
1359
1360/**
1361 * jbd2_mark_journal_empty() - Mark on disk journal as empty.
1362 * @journal: The journal to update.
1363 *
1364 * Update a journal's dynamic superblock fields to show that journal is empty.
1365 * Write updated superblock to disk waiting for IO to complete.
1366 */
1367static void jbd2_mark_journal_empty(journal_t *journal)
1368{
1369 journal_superblock_t *sb = journal->j_superblock;
1370
Jan Karaa78bb112012-03-13 15:43:04 -04001371 BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
Dave Kleikamp470decc2006-10-11 01:20:57 -07001372 read_lock(&journal->j_state_lock);
Eric Sandeeneeecef02012-08-18 22:29:40 -04001373 /* Is it already empty? */
1374 if (sb->s_start == 0) {
1375 read_unlock(&journal->j_state_lock);
1376 return;
1377 }
Jan Kara24bcc892012-03-13 15:41:04 -04001378 jbd_debug(1, "JBD2: Marking journal as empty (seq %d)\n",
1379 journal->j_tail_sequence);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001380
1381 sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
Jan Kara24bcc892012-03-13 15:41:04 -04001382 sb->s_start = cpu_to_be32(0);
1383 read_unlock(&journal->j_state_lock);
1384
Jan Kara79feb522012-03-13 22:22:54 -04001385 jbd2_write_superblock(journal, WRITE_FUA);
Jan Kara24bcc892012-03-13 15:41:04 -04001386
1387 /* Log is no longer empty */
1388 write_lock(&journal->j_state_lock);
1389 journal->j_flags |= JBD2_FLUSHED;
1390 write_unlock(&journal->j_state_lock);
1391}
1392
1393
1394/**
1395 * jbd2_journal_update_sb_errno() - Update error in the journal.
1396 * @journal: The journal to update.
1397 *
1398 * Update a journal's errno. Write updated superblock to disk waiting for IO
1399 * to complete.
1400 */
Theodore Ts'od796c522012-08-05 19:04:57 -04001401void jbd2_journal_update_sb_errno(journal_t *journal)
Jan Kara24bcc892012-03-13 15:41:04 -04001402{
1403 journal_superblock_t *sb = journal->j_superblock;
1404
1405 read_lock(&journal->j_state_lock);
1406 jbd_debug(1, "JBD2: updating superblock error (errno %d)\n",
1407 journal->j_errno);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001408 sb->s_errno = cpu_to_be32(journal->j_errno);
Darrick J. Wong4fd5ea42012-05-27 08:08:22 -04001409 jbd2_superblock_csum_set(journal, sb);
Theodore Ts'oa931da62010-08-03 21:35:12 -04001410 read_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001411
Jan Kara79feb522012-03-13 22:22:54 -04001412 jbd2_write_superblock(journal, WRITE_SYNC);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001413}
Theodore Ts'od796c522012-08-05 19:04:57 -04001414EXPORT_SYMBOL(jbd2_journal_update_sb_errno);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001415
1416/*
1417 * Read the superblock for a given journal, performing initial
1418 * validation of the format.
1419 */
Dave Kleikamp470decc2006-10-11 01:20:57 -07001420static int journal_get_superblock(journal_t *journal)
1421{
1422 struct buffer_head *bh;
1423 journal_superblock_t *sb;
1424 int err = -EIO;
1425
1426 bh = journal->j_sb_buffer;
1427
1428 J_ASSERT(bh != NULL);
1429 if (!buffer_uptodate(bh)) {
1430 ll_rw_block(READ, 1, &bh);
1431 wait_on_buffer(bh);
1432 if (!buffer_uptodate(bh)) {
Eryu Guanf2a44522011-11-01 19:09:18 -04001433 printk(KERN_ERR
1434 "JBD2: IO error reading journal superblock\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -07001435 goto out;
1436 }
1437 }
1438
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001439 if (buffer_verified(bh))
1440 return 0;
1441
Dave Kleikamp470decc2006-10-11 01:20:57 -07001442 sb = journal->j_superblock;
1443
1444 err = -EINVAL;
1445
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001446 if (sb->s_header.h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER) ||
Dave Kleikamp470decc2006-10-11 01:20:57 -07001447 sb->s_blocksize != cpu_to_be32(journal->j_blocksize)) {
Eryu Guanf2a44522011-11-01 19:09:18 -04001448 printk(KERN_WARNING "JBD2: no valid journal superblock found\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -07001449 goto out;
1450 }
1451
1452 switch(be32_to_cpu(sb->s_header.h_blocktype)) {
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001453 case JBD2_SUPERBLOCK_V1:
Dave Kleikamp470decc2006-10-11 01:20:57 -07001454 journal->j_format_version = 1;
1455 break;
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001456 case JBD2_SUPERBLOCK_V2:
Dave Kleikamp470decc2006-10-11 01:20:57 -07001457 journal->j_format_version = 2;
1458 break;
1459 default:
Eryu Guanf2a44522011-11-01 19:09:18 -04001460 printk(KERN_WARNING "JBD2: unrecognised superblock format ID\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -07001461 goto out;
1462 }
1463
1464 if (be32_to_cpu(sb->s_maxlen) < journal->j_maxlen)
1465 journal->j_maxlen = be32_to_cpu(sb->s_maxlen);
1466 else if (be32_to_cpu(sb->s_maxlen) > journal->j_maxlen) {
Eryu Guanf2a44522011-11-01 19:09:18 -04001467 printk(KERN_WARNING "JBD2: journal file too short\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -07001468 goto out;
1469 }
1470
Eryu Guan87622022011-11-01 19:04:59 -04001471 if (be32_to_cpu(sb->s_first) == 0 ||
1472 be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
1473 printk(KERN_WARNING
1474 "JBD2: Invalid start block of journal: %u\n",
1475 be32_to_cpu(sb->s_first));
1476 goto out;
1477 }
1478
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001479 if (JBD2_HAS_COMPAT_FEATURE(journal, JBD2_FEATURE_COMPAT_CHECKSUM) &&
1480 JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) {
1481 /* Can't have checksum v1 and v2 on at the same time! */
1482 printk(KERN_ERR "JBD: Can't enable checksumming v1 and v2 "
1483 "at the same time!\n");
1484 goto out;
1485 }
1486
1487 if (!jbd2_verify_csum_type(journal, sb)) {
1488 printk(KERN_ERR "JBD: Unknown checksum type\n");
1489 goto out;
1490 }
1491
Darrick J. Wong01b5adc2012-05-27 07:50:56 -04001492 /* Load the checksum driver */
1493 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) {
1494 journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
1495 if (IS_ERR(journal->j_chksum_driver)) {
1496 printk(KERN_ERR "JBD: Cannot load crc32c driver.\n");
1497 err = PTR_ERR(journal->j_chksum_driver);
1498 journal->j_chksum_driver = NULL;
1499 goto out;
1500 }
1501 }
1502
Darrick J. Wong4fd5ea42012-05-27 08:08:22 -04001503 /* Check superblock checksum */
1504 if (!jbd2_superblock_csum_verify(journal, sb)) {
1505 printk(KERN_ERR "JBD: journal checksum error\n");
1506 goto out;
1507 }
1508
1509 /* Precompute checksum seed for all metadata */
1510 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
1511 journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
1512 sizeof(sb->s_uuid));
1513
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001514 set_buffer_verified(bh);
1515
Dave Kleikamp470decc2006-10-11 01:20:57 -07001516 return 0;
1517
1518out:
1519 journal_fail_superblock(journal);
1520 return err;
1521}
1522
1523/*
1524 * Load the on-disk journal superblock and read the key fields into the
1525 * journal_t.
1526 */
1527
1528static int load_superblock(journal_t *journal)
1529{
1530 int err;
1531 journal_superblock_t *sb;
1532
1533 err = journal_get_superblock(journal);
1534 if (err)
1535 return err;
1536
1537 sb = journal->j_superblock;
1538
1539 journal->j_tail_sequence = be32_to_cpu(sb->s_sequence);
1540 journal->j_tail = be32_to_cpu(sb->s_start);
1541 journal->j_first = be32_to_cpu(sb->s_first);
1542 journal->j_last = be32_to_cpu(sb->s_maxlen);
1543 journal->j_errno = be32_to_cpu(sb->s_errno);
1544
1545 return 0;
1546}
1547
1548
1549/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001550 * int jbd2_journal_load() - Read journal from disk.
Dave Kleikamp470decc2006-10-11 01:20:57 -07001551 * @journal: Journal to act on.
1552 *
1553 * Given a journal_t structure which tells us which disk blocks contain
1554 * a journal, read the journal from disk to initialise the in-memory
1555 * structures.
1556 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001557int jbd2_journal_load(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001558{
1559 int err;
1560 journal_superblock_t *sb;
1561
1562 err = load_superblock(journal);
1563 if (err)
1564 return err;
1565
1566 sb = journal->j_superblock;
1567 /* If this is a V2 superblock, then we have to check the
1568 * features flags on it. */
1569
1570 if (journal->j_format_version >= 2) {
1571 if ((sb->s_feature_ro_compat &
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001572 ~cpu_to_be32(JBD2_KNOWN_ROCOMPAT_FEATURES)) ||
Dave Kleikamp470decc2006-10-11 01:20:57 -07001573 (sb->s_feature_incompat &
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001574 ~cpu_to_be32(JBD2_KNOWN_INCOMPAT_FEATURES))) {
Eryu Guanf2a44522011-11-01 19:09:18 -04001575 printk(KERN_WARNING
1576 "JBD2: Unrecognised features on journal\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -07001577 return -EINVAL;
1578 }
1579 }
1580
Theodore Ts'od2eecb02009-12-07 10:36:20 -05001581 /*
1582 * Create a slab for this blocksize
1583 */
1584 err = jbd2_journal_create_slab(be32_to_cpu(sb->s_blocksize));
1585 if (err)
1586 return err;
1587
Dave Kleikamp470decc2006-10-11 01:20:57 -07001588 /* Let the recovery code check whether it needs to recover any
1589 * data from the journal. */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001590 if (jbd2_journal_recover(journal))
Dave Kleikamp470decc2006-10-11 01:20:57 -07001591 goto recovery_error;
1592
Theodore Ts'oe6a47422009-11-15 15:31:37 -05001593 if (journal->j_failed_commit) {
1594 printk(KERN_ERR "JBD2: journal transaction %u on %s "
1595 "is corrupt.\n", journal->j_failed_commit,
1596 journal->j_devname);
1597 return -EIO;
1598 }
1599
Dave Kleikamp470decc2006-10-11 01:20:57 -07001600 /* OK, we've finished with the dynamic journal bits:
1601 * reinitialise the dynamic contents of the superblock in memory
1602 * and reset them on disk. */
1603 if (journal_reset(journal))
1604 goto recovery_error;
1605
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001606 journal->j_flags &= ~JBD2_ABORT;
1607 journal->j_flags |= JBD2_LOADED;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001608 return 0;
1609
1610recovery_error:
Eryu Guanf2a44522011-11-01 19:09:18 -04001611 printk(KERN_WARNING "JBD2: recovery failed\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -07001612 return -EIO;
1613}
1614
1615/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001616 * void jbd2_journal_destroy() - Release a journal_t structure.
Dave Kleikamp470decc2006-10-11 01:20:57 -07001617 * @journal: Journal to act on.
1618 *
1619 * Release a journal_t structure once it is no longer in use by the
1620 * journaled object.
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001621 * Return <0 if we couldn't clean up the journal.
Dave Kleikamp470decc2006-10-11 01:20:57 -07001622 */
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001623int jbd2_journal_destroy(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001624{
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001625 int err = 0;
1626
Dave Kleikamp470decc2006-10-11 01:20:57 -07001627 /* Wait for the commit thread to wake up and die. */
1628 journal_kill_thread(journal);
1629
1630 /* Force a final log commit */
1631 if (journal->j_running_transaction)
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001632 jbd2_journal_commit_transaction(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001633
1634 /* Force any old transactions to disk */
1635
1636 /* Totally anal locking here... */
1637 spin_lock(&journal->j_list_lock);
1638 while (journal->j_checkpoint_transactions != NULL) {
1639 spin_unlock(&journal->j_list_lock);
Theodore Ts'o1a0d3782008-11-05 00:09:22 -05001640 mutex_lock(&journal->j_checkpoint_mutex);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001641 jbd2_log_do_checkpoint(journal);
Theodore Ts'o1a0d3782008-11-05 00:09:22 -05001642 mutex_unlock(&journal->j_checkpoint_mutex);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001643 spin_lock(&journal->j_list_lock);
1644 }
1645
1646 J_ASSERT(journal->j_running_transaction == NULL);
1647 J_ASSERT(journal->j_committing_transaction == NULL);
1648 J_ASSERT(journal->j_checkpoint_transactions == NULL);
1649 spin_unlock(&journal->j_list_lock);
1650
Dave Kleikamp470decc2006-10-11 01:20:57 -07001651 if (journal->j_sb_buffer) {
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001652 if (!is_journal_aborted(journal)) {
Jan Karaa78bb112012-03-13 15:43:04 -04001653 mutex_lock(&journal->j_checkpoint_mutex);
Jan Kara24bcc892012-03-13 15:41:04 -04001654 jbd2_mark_journal_empty(journal);
Jan Karaa78bb112012-03-13 15:43:04 -04001655 mutex_unlock(&journal->j_checkpoint_mutex);
1656 } else
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001657 err = -EIO;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001658 brelse(journal->j_sb_buffer);
1659 }
1660
Johann Lombardi8e85fb32008-01-28 23:58:27 -05001661 if (journal->j_proc_entry)
1662 jbd2_stats_proc_exit(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001663 if (journal->j_inode)
1664 iput(journal->j_inode);
1665 if (journal->j_revoke)
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001666 jbd2_journal_destroy_revoke(journal);
Darrick J. Wong01b5adc2012-05-27 07:50:56 -04001667 if (journal->j_chksum_driver)
1668 crypto_free_shash(journal->j_chksum_driver);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001669 kfree(journal->j_wbuf);
1670 kfree(journal);
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001671
1672 return err;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001673}
1674
1675
1676/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001677 *int jbd2_journal_check_used_features () - Check if features specified are used.
Dave Kleikamp470decc2006-10-11 01:20:57 -07001678 * @journal: Journal to check.
1679 * @compat: bitmask of compatible features
1680 * @ro: bitmask of features that force read-only mount
1681 * @incompat: bitmask of incompatible features
1682 *
1683 * Check whether the journal uses all of a given set of
1684 * features. Return true (non-zero) if it does.
1685 **/
1686
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001687int jbd2_journal_check_used_features (journal_t *journal, unsigned long compat,
Dave Kleikamp470decc2006-10-11 01:20:57 -07001688 unsigned long ro, unsigned long incompat)
1689{
1690 journal_superblock_t *sb;
1691
1692 if (!compat && !ro && !incompat)
1693 return 1;
Patrick J. LoPresti1113e1b2010-07-22 15:04:16 -07001694 /* Load journal superblock if it is not loaded yet. */
1695 if (journal->j_format_version == 0 &&
1696 journal_get_superblock(journal) != 0)
1697 return 0;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001698 if (journal->j_format_version == 1)
1699 return 0;
1700
1701 sb = journal->j_superblock;
1702
1703 if (((be32_to_cpu(sb->s_feature_compat) & compat) == compat) &&
1704 ((be32_to_cpu(sb->s_feature_ro_compat) & ro) == ro) &&
1705 ((be32_to_cpu(sb->s_feature_incompat) & incompat) == incompat))
1706 return 1;
1707
1708 return 0;
1709}
1710
1711/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001712 * int jbd2_journal_check_available_features() - Check feature set in journalling layer
Dave Kleikamp470decc2006-10-11 01:20:57 -07001713 * @journal: Journal to check.
1714 * @compat: bitmask of compatible features
1715 * @ro: bitmask of features that force read-only mount
1716 * @incompat: bitmask of incompatible features
1717 *
1718 * Check whether the journaling code supports the use of
1719 * all of a given set of features on this journal. Return true
1720 * (non-zero) if it can. */
1721
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001722int jbd2_journal_check_available_features (journal_t *journal, unsigned long compat,
Dave Kleikamp470decc2006-10-11 01:20:57 -07001723 unsigned long ro, unsigned long incompat)
1724{
Dave Kleikamp470decc2006-10-11 01:20:57 -07001725 if (!compat && !ro && !incompat)
1726 return 1;
1727
Dave Kleikamp470decc2006-10-11 01:20:57 -07001728 /* We can support any known requested features iff the
1729 * superblock is in version 2. Otherwise we fail to support any
1730 * extended sb features. */
1731
1732 if (journal->j_format_version != 2)
1733 return 0;
1734
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001735 if ((compat & JBD2_KNOWN_COMPAT_FEATURES) == compat &&
1736 (ro & JBD2_KNOWN_ROCOMPAT_FEATURES) == ro &&
1737 (incompat & JBD2_KNOWN_INCOMPAT_FEATURES) == incompat)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001738 return 1;
1739
1740 return 0;
1741}
1742
1743/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001744 * int jbd2_journal_set_features () - Mark a given journal feature in the superblock
Dave Kleikamp470decc2006-10-11 01:20:57 -07001745 * @journal: Journal to act on.
1746 * @compat: bitmask of compatible features
1747 * @ro: bitmask of features that force read-only mount
1748 * @incompat: bitmask of incompatible features
1749 *
1750 * Mark a given journal feature as present on the
1751 * superblock. Returns true if the requested features could be set.
1752 *
1753 */
1754
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001755int jbd2_journal_set_features (journal_t *journal, unsigned long compat,
Dave Kleikamp470decc2006-10-11 01:20:57 -07001756 unsigned long ro, unsigned long incompat)
1757{
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001758#define INCOMPAT_FEATURE_ON(f) \
1759 ((incompat & (f)) && !(sb->s_feature_incompat & cpu_to_be32(f)))
1760#define COMPAT_FEATURE_ON(f) \
1761 ((compat & (f)) && !(sb->s_feature_compat & cpu_to_be32(f)))
Dave Kleikamp470decc2006-10-11 01:20:57 -07001762 journal_superblock_t *sb;
1763
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001764 if (jbd2_journal_check_used_features(journal, compat, ro, incompat))
Dave Kleikamp470decc2006-10-11 01:20:57 -07001765 return 1;
1766
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001767 if (!jbd2_journal_check_available_features(journal, compat, ro, incompat))
Dave Kleikamp470decc2006-10-11 01:20:57 -07001768 return 0;
1769
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001770 /* Asking for checksumming v2 and v1? Only give them v2. */
1771 if (incompat & JBD2_FEATURE_INCOMPAT_CSUM_V2 &&
1772 compat & JBD2_FEATURE_COMPAT_CHECKSUM)
1773 compat &= ~JBD2_FEATURE_COMPAT_CHECKSUM;
1774
Dave Kleikamp470decc2006-10-11 01:20:57 -07001775 jbd_debug(1, "Setting new features 0x%lx/0x%lx/0x%lx\n",
1776 compat, ro, incompat);
1777
1778 sb = journal->j_superblock;
1779
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001780 /* If enabling v2 checksums, update superblock */
1781 if (INCOMPAT_FEATURE_ON(JBD2_FEATURE_INCOMPAT_CSUM_V2)) {
1782 sb->s_checksum_type = JBD2_CRC32C_CHKSUM;
1783 sb->s_feature_compat &=
1784 ~cpu_to_be32(JBD2_FEATURE_COMPAT_CHECKSUM);
Darrick J. Wong01b5adc2012-05-27 07:50:56 -04001785
1786 /* Load the checksum driver */
1787 if (journal->j_chksum_driver == NULL) {
1788 journal->j_chksum_driver = crypto_alloc_shash("crc32c",
1789 0, 0);
1790 if (IS_ERR(journal->j_chksum_driver)) {
1791 printk(KERN_ERR "JBD: Cannot load crc32c "
1792 "driver.\n");
1793 journal->j_chksum_driver = NULL;
1794 return 0;
1795 }
1796 }
Darrick J. Wong4fd5ea42012-05-27 08:08:22 -04001797
1798 /* Precompute checksum seed for all metadata */
1799 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
1800 JBD2_FEATURE_INCOMPAT_CSUM_V2))
1801 journal->j_csum_seed = jbd2_chksum(journal, ~0,
1802 sb->s_uuid,
1803 sizeof(sb->s_uuid));
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001804 }
1805
1806 /* If enabling v1 checksums, downgrade superblock */
1807 if (COMPAT_FEATURE_ON(JBD2_FEATURE_COMPAT_CHECKSUM))
1808 sb->s_feature_incompat &=
1809 ~cpu_to_be32(JBD2_FEATURE_INCOMPAT_CSUM_V2);
1810
Dave Kleikamp470decc2006-10-11 01:20:57 -07001811 sb->s_feature_compat |= cpu_to_be32(compat);
1812 sb->s_feature_ro_compat |= cpu_to_be32(ro);
1813 sb->s_feature_incompat |= cpu_to_be32(incompat);
1814
1815 return 1;
Darrick J. Wong25ed6e82012-05-27 07:48:56 -04001816#undef COMPAT_FEATURE_ON
1817#undef INCOMPAT_FEATURE_ON
Dave Kleikamp470decc2006-10-11 01:20:57 -07001818}
1819
Girish Shilamkar818d2762008-01-28 23:58:27 -05001820/*
1821 * jbd2_journal_clear_features () - Clear a given journal feature in the
1822 * superblock
1823 * @journal: Journal to act on.
1824 * @compat: bitmask of compatible features
1825 * @ro: bitmask of features that force read-only mount
1826 * @incompat: bitmask of incompatible features
1827 *
1828 * Clear a given journal feature as present on the
1829 * superblock.
1830 */
1831void jbd2_journal_clear_features(journal_t *journal, unsigned long compat,
1832 unsigned long ro, unsigned long incompat)
1833{
1834 journal_superblock_t *sb;
1835
1836 jbd_debug(1, "Clear features 0x%lx/0x%lx/0x%lx\n",
1837 compat, ro, incompat);
1838
1839 sb = journal->j_superblock;
1840
1841 sb->s_feature_compat &= ~cpu_to_be32(compat);
1842 sb->s_feature_ro_compat &= ~cpu_to_be32(ro);
1843 sb->s_feature_incompat &= ~cpu_to_be32(incompat);
1844}
1845EXPORT_SYMBOL(jbd2_journal_clear_features);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001846
1847/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001848 * int jbd2_journal_flush () - Flush journal
Dave Kleikamp470decc2006-10-11 01:20:57 -07001849 * @journal: Journal to act on.
1850 *
1851 * Flush all data for a given journal to disk and empty the journal.
1852 * Filesystems can use this when remounting readonly to ensure that
1853 * recovery does not need to happen on remount.
1854 */
1855
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001856int jbd2_journal_flush(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001857{
1858 int err = 0;
1859 transaction_t *transaction = NULL;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001860
Theodore Ts'oa931da62010-08-03 21:35:12 -04001861 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001862
1863 /* Force everything buffered to the log... */
1864 if (journal->j_running_transaction) {
1865 transaction = journal->j_running_transaction;
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001866 __jbd2_log_start_commit(journal, transaction->t_tid);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001867 } else if (journal->j_committing_transaction)
1868 transaction = journal->j_committing_transaction;
1869
1870 /* Wait for the log commit to complete... */
1871 if (transaction) {
1872 tid_t tid = transaction->t_tid;
1873
Theodore Ts'oa931da62010-08-03 21:35:12 -04001874 write_unlock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001875 jbd2_log_wait_commit(journal, tid);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001876 } else {
Theodore Ts'oa931da62010-08-03 21:35:12 -04001877 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001878 }
1879
1880 /* ...and flush everything in the log out to disk. */
1881 spin_lock(&journal->j_list_lock);
1882 while (!err && journal->j_checkpoint_transactions != NULL) {
1883 spin_unlock(&journal->j_list_lock);
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001884 mutex_lock(&journal->j_checkpoint_mutex);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001885 err = jbd2_log_do_checkpoint(journal);
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001886 mutex_unlock(&journal->j_checkpoint_mutex);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001887 spin_lock(&journal->j_list_lock);
1888 }
1889 spin_unlock(&journal->j_list_lock);
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001890
1891 if (is_journal_aborted(journal))
1892 return -EIO;
1893
Jan Karaa78bb112012-03-13 15:43:04 -04001894 mutex_lock(&journal->j_checkpoint_mutex);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001895 jbd2_cleanup_journal_tail(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001896
1897 /* Finally, mark the journal as really needing no recovery.
1898 * This sets s_start==0 in the underlying superblock, which is
1899 * the magic code for a fully-recovered superblock. Any future
1900 * commits of data to the journal will restore the current
1901 * s_start value. */
Jan Kara24bcc892012-03-13 15:41:04 -04001902 jbd2_mark_journal_empty(journal);
Jan Karaa78bb112012-03-13 15:43:04 -04001903 mutex_unlock(&journal->j_checkpoint_mutex);
Theodore Ts'oa931da62010-08-03 21:35:12 -04001904 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001905 J_ASSERT(!journal->j_running_transaction);
1906 J_ASSERT(!journal->j_committing_transaction);
1907 J_ASSERT(!journal->j_checkpoint_transactions);
1908 J_ASSERT(journal->j_head == journal->j_tail);
1909 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence);
Theodore Ts'oa931da62010-08-03 21:35:12 -04001910 write_unlock(&journal->j_state_lock);
Hidehiro Kawai44519fa2008-10-10 20:29:13 -04001911 return 0;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001912}
1913
1914/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001915 * int jbd2_journal_wipe() - Wipe journal contents
Dave Kleikamp470decc2006-10-11 01:20:57 -07001916 * @journal: Journal to act on.
1917 * @write: flag (see below)
1918 *
1919 * Wipe out all of the contents of a journal, safely. This will produce
1920 * a warning if the journal contains any valid recovery information.
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001921 * Must be called between journal_init_*() and jbd2_journal_load().
Dave Kleikamp470decc2006-10-11 01:20:57 -07001922 *
1923 * If 'write' is non-zero, then we wipe out the journal on disk; otherwise
1924 * we merely suppress recovery.
1925 */
1926
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001927int jbd2_journal_wipe(journal_t *journal, int write)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001928{
Dave Kleikamp470decc2006-10-11 01:20:57 -07001929 int err = 0;
1930
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001931 J_ASSERT (!(journal->j_flags & JBD2_LOADED));
Dave Kleikamp470decc2006-10-11 01:20:57 -07001932
1933 err = load_superblock(journal);
1934 if (err)
1935 return err;
1936
Dave Kleikamp470decc2006-10-11 01:20:57 -07001937 if (!journal->j_tail)
1938 goto no_recovery;
1939
Eryu Guanf2a44522011-11-01 19:09:18 -04001940 printk(KERN_WARNING "JBD2: %s recovery information on journal\n",
Dave Kleikamp470decc2006-10-11 01:20:57 -07001941 write ? "Clearing" : "Ignoring");
1942
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001943 err = jbd2_journal_skip_recovery(journal);
Jan Karaa78bb112012-03-13 15:43:04 -04001944 if (write) {
1945 /* Lock to make assertions happy... */
1946 mutex_lock(&journal->j_checkpoint_mutex);
Jan Kara24bcc892012-03-13 15:41:04 -04001947 jbd2_mark_journal_empty(journal);
Jan Karaa78bb112012-03-13 15:43:04 -04001948 mutex_unlock(&journal->j_checkpoint_mutex);
1949 }
Dave Kleikamp470decc2006-10-11 01:20:57 -07001950
1951 no_recovery:
1952 return err;
1953}
1954
1955/*
Dave Kleikamp470decc2006-10-11 01:20:57 -07001956 * Journal abort has very specific semantics, which we describe
1957 * for journal abort.
1958 *
Alberto Bertoglibfcd3552009-06-09 00:06:20 -04001959 * Two internal functions, which provide abort to the jbd layer
Dave Kleikamp470decc2006-10-11 01:20:57 -07001960 * itself are here.
1961 */
1962
1963/*
1964 * Quick version for internal journal use (doesn't lock the journal).
1965 * Aborts hard --- we mark the abort as occurred, but do _nothing_ else,
1966 * and don't attempt to make any other journal updates.
1967 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001968void __jbd2_journal_abort_hard(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001969{
1970 transaction_t *transaction;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001971
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001972 if (journal->j_flags & JBD2_ABORT)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001973 return;
1974
1975 printk(KERN_ERR "Aborting journal on device %s.\n",
Theodore Ts'o05496762008-09-16 14:36:17 -04001976 journal->j_devname);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001977
Theodore Ts'oa931da62010-08-03 21:35:12 -04001978 write_lock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001979 journal->j_flags |= JBD2_ABORT;
Dave Kleikamp470decc2006-10-11 01:20:57 -07001980 transaction = journal->j_running_transaction;
1981 if (transaction)
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001982 __jbd2_log_start_commit(journal, transaction->t_tid);
Theodore Ts'oa931da62010-08-03 21:35:12 -04001983 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001984}
1985
1986/* Soft abort: record the abort error status in the journal superblock,
1987 * but don't do any other IO. */
1988static void __journal_abort_soft (journal_t *journal, int errno)
1989{
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001990 if (journal->j_flags & JBD2_ABORT)
Dave Kleikamp470decc2006-10-11 01:20:57 -07001991 return;
1992
1993 if (!journal->j_errno)
1994 journal->j_errno = errno;
1995
Mingming Caof7f4bcc2006-10-11 01:20:59 -07001996 __jbd2_journal_abort_hard(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -07001997
1998 if (errno)
Jan Kara24bcc892012-03-13 15:41:04 -04001999 jbd2_journal_update_sb_errno(journal);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002000}
2001
2002/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002003 * void jbd2_journal_abort () - Shutdown the journal immediately.
Dave Kleikamp470decc2006-10-11 01:20:57 -07002004 * @journal: the journal to shutdown.
2005 * @errno: an error number to record in the journal indicating
2006 * the reason for the shutdown.
2007 *
2008 * Perform a complete, immediate shutdown of the ENTIRE
2009 * journal (not of a single transaction). This operation cannot be
2010 * undone without closing and reopening the journal.
2011 *
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002012 * The jbd2_journal_abort function is intended to support higher level error
Dave Kleikamp470decc2006-10-11 01:20:57 -07002013 * recovery mechanisms such as the ext2/ext3 remount-readonly error
2014 * mode.
2015 *
2016 * Journal abort has very specific semantics. Any existing dirty,
2017 * unjournaled buffers in the main filesystem will still be written to
2018 * disk by bdflush, but the journaling mechanism will be suspended
2019 * immediately and no further transaction commits will be honoured.
2020 *
2021 * Any dirty, journaled buffers will be written back to disk without
2022 * hitting the journal. Atomicity cannot be guaranteed on an aborted
2023 * filesystem, but we _do_ attempt to leave as much data as possible
2024 * behind for fsck to use for cleanup.
2025 *
2026 * Any attempt to get a new transaction handle on a journal which is in
2027 * ABORT state will just result in an -EROFS error return. A
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002028 * jbd2_journal_stop on an existing handle will return -EIO if we have
Dave Kleikamp470decc2006-10-11 01:20:57 -07002029 * entered abort state during the update.
2030 *
2031 * Recursive transactions are not disturbed by journal abort until the
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002032 * final jbd2_journal_stop, which will receive the -EIO error.
Dave Kleikamp470decc2006-10-11 01:20:57 -07002033 *
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002034 * Finally, the jbd2_journal_abort call allows the caller to supply an errno
Dave Kleikamp470decc2006-10-11 01:20:57 -07002035 * which will be recorded (if possible) in the journal superblock. This
2036 * allows a client to record failure conditions in the middle of a
2037 * transaction without having to complete the transaction to record the
2038 * failure to disk. ext3_error, for example, now uses this
2039 * functionality.
2040 *
2041 * Errors which originate from within the journaling layer will NOT
2042 * supply an errno; a null errno implies that absolutely no further
2043 * writes are done to the journal (unless there are any already in
2044 * progress).
2045 *
2046 */
2047
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002048void jbd2_journal_abort(journal_t *journal, int errno)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002049{
2050 __journal_abort_soft(journal, errno);
2051}
2052
2053/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002054 * int jbd2_journal_errno () - returns the journal's error state.
Dave Kleikamp470decc2006-10-11 01:20:57 -07002055 * @journal: journal to examine.
2056 *
Alberto Bertoglibfcd3552009-06-09 00:06:20 -04002057 * This is the errno number set with jbd2_journal_abort(), the last
Dave Kleikamp470decc2006-10-11 01:20:57 -07002058 * time the journal was mounted - if the journal was stopped
2059 * without calling abort this will be 0.
2060 *
2061 * If the journal has been aborted on this mount time -EROFS will
2062 * be returned.
2063 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002064int jbd2_journal_errno(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002065{
2066 int err;
2067
Theodore Ts'oa931da62010-08-03 21:35:12 -04002068 read_lock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002069 if (journal->j_flags & JBD2_ABORT)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002070 err = -EROFS;
2071 else
2072 err = journal->j_errno;
Theodore Ts'oa931da62010-08-03 21:35:12 -04002073 read_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002074 return err;
2075}
2076
2077/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002078 * int jbd2_journal_clear_err () - clears the journal's error state
Dave Kleikamp470decc2006-10-11 01:20:57 -07002079 * @journal: journal to act on.
2080 *
Alberto Bertoglibfcd3552009-06-09 00:06:20 -04002081 * An error must be cleared or acked to take a FS out of readonly
Dave Kleikamp470decc2006-10-11 01:20:57 -07002082 * mode.
2083 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002084int jbd2_journal_clear_err(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002085{
2086 int err = 0;
2087
Theodore Ts'oa931da62010-08-03 21:35:12 -04002088 write_lock(&journal->j_state_lock);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002089 if (journal->j_flags & JBD2_ABORT)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002090 err = -EROFS;
2091 else
2092 journal->j_errno = 0;
Theodore Ts'oa931da62010-08-03 21:35:12 -04002093 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002094 return err;
2095}
2096
2097/**
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002098 * void jbd2_journal_ack_err() - Ack journal err.
Dave Kleikamp470decc2006-10-11 01:20:57 -07002099 * @journal: journal to act on.
2100 *
Alberto Bertoglibfcd3552009-06-09 00:06:20 -04002101 * An error must be cleared or acked to take a FS out of readonly
Dave Kleikamp470decc2006-10-11 01:20:57 -07002102 * mode.
2103 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002104void jbd2_journal_ack_err(journal_t *journal)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002105{
Theodore Ts'oa931da62010-08-03 21:35:12 -04002106 write_lock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002107 if (journal->j_errno)
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002108 journal->j_flags |= JBD2_ACK_ERR;
Theodore Ts'oa931da62010-08-03 21:35:12 -04002109 write_unlock(&journal->j_state_lock);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002110}
2111
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002112int jbd2_journal_blocks_per_page(struct inode *inode)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002113{
2114 return 1 << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
2115}
2116
2117/*
Zach Brownb517bea2006-10-11 01:21:08 -07002118 * helper functions to deal with 32 or 64bit block numbers.
2119 */
2120size_t journal_tag_bytes(journal_t *journal)
2121{
Darrick J. Wongc3900872012-05-27 08:12:12 -04002122 journal_block_tag_t tag;
2123 size_t x = 0;
2124
2125 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
2126 x += sizeof(tag.t_checksum);
2127
Zach Brownb517bea2006-10-11 01:21:08 -07002128 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
Darrick J. Wongc3900872012-05-27 08:12:12 -04002129 return x + JBD2_TAG_SIZE64;
Zach Brownb517bea2006-10-11 01:21:08 -07002130 else
Darrick J. Wongc3900872012-05-27 08:12:12 -04002131 return x + JBD2_TAG_SIZE32;
Zach Brownb517bea2006-10-11 01:21:08 -07002132}
2133
2134/*
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002135 * JBD memory management
2136 *
2137 * These functions are used to allocate block-sized chunks of memory
2138 * used for making copies of buffer_head data. Very often it will be
2139 * page-sized chunks of data, but sometimes it will be in
2140 * sub-page-size chunks. (For example, 16k pages on Power systems
2141 * with a 4k block file system.) For blocks smaller than a page, we
2142 * use a SLAB allocator. There are slab caches for each block size,
2143 * which are allocated at mount time, if necessary, and we only free
2144 * (all of) the slab caches when/if the jbd2 module is unloaded. For
2145 * this reason we don't need to a mutex to protect access to
2146 * jbd2_slab[] allocating or releasing memory; only in
2147 * jbd2_journal_create_slab().
2148 */
2149#define JBD2_MAX_SLABS 8
2150static struct kmem_cache *jbd2_slab[JBD2_MAX_SLABS];
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002151
2152static const char *jbd2_slab_names[JBD2_MAX_SLABS] = {
2153 "jbd2_1k", "jbd2_2k", "jbd2_4k", "jbd2_8k",
2154 "jbd2_16k", "jbd2_32k", "jbd2_64k", "jbd2_128k"
2155};
2156
2157
2158static void jbd2_journal_destroy_slabs(void)
2159{
2160 int i;
2161
2162 for (i = 0; i < JBD2_MAX_SLABS; i++) {
2163 if (jbd2_slab[i])
2164 kmem_cache_destroy(jbd2_slab[i]);
2165 jbd2_slab[i] = NULL;
2166 }
2167}
2168
2169static int jbd2_journal_create_slab(size_t size)
2170{
Thomas Gleixner51dfacde2010-10-16 22:34:39 +02002171 static DEFINE_MUTEX(jbd2_slab_create_mutex);
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002172 int i = order_base_2(size) - 10;
2173 size_t slab_size;
2174
2175 if (size == PAGE_SIZE)
2176 return 0;
2177
2178 if (i >= JBD2_MAX_SLABS)
2179 return -EINVAL;
2180
2181 if (unlikely(i < 0))
2182 i = 0;
Thomas Gleixner51dfacde2010-10-16 22:34:39 +02002183 mutex_lock(&jbd2_slab_create_mutex);
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002184 if (jbd2_slab[i]) {
Thomas Gleixner51dfacde2010-10-16 22:34:39 +02002185 mutex_unlock(&jbd2_slab_create_mutex);
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002186 return 0; /* Already created */
2187 }
2188
2189 slab_size = 1 << (i+10);
2190 jbd2_slab[i] = kmem_cache_create(jbd2_slab_names[i], slab_size,
2191 slab_size, 0, NULL);
Thomas Gleixner51dfacde2010-10-16 22:34:39 +02002192 mutex_unlock(&jbd2_slab_create_mutex);
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002193 if (!jbd2_slab[i]) {
2194 printk(KERN_EMERG "JBD2: no memory for jbd2_slab cache\n");
2195 return -ENOMEM;
2196 }
2197 return 0;
2198}
2199
2200static struct kmem_cache *get_slab(size_t size)
2201{
2202 int i = order_base_2(size) - 10;
2203
2204 BUG_ON(i >= JBD2_MAX_SLABS);
2205 if (unlikely(i < 0))
2206 i = 0;
Bill Pemberton8ac97b72010-04-30 09:34:31 -04002207 BUG_ON(jbd2_slab[i] == NULL);
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002208 return jbd2_slab[i];
2209}
2210
2211void *jbd2_alloc(size_t size, gfp_t flags)
2212{
2213 void *ptr;
2214
2215 BUG_ON(size & (size-1)); /* Must be a power of 2 */
2216
2217 flags |= __GFP_REPEAT;
2218 if (size == PAGE_SIZE)
2219 ptr = (void *)__get_free_pages(flags, 0);
2220 else if (size > PAGE_SIZE) {
2221 int order = get_order(size);
2222
2223 if (order < 3)
2224 ptr = (void *)__get_free_pages(flags, order);
2225 else
2226 ptr = vmalloc(size);
2227 } else
2228 ptr = kmem_cache_alloc(get_slab(size), flags);
2229
2230 /* Check alignment; SLUB has gotten this wrong in the past,
2231 * and this can lead to user data corruption! */
2232 BUG_ON(((unsigned long) ptr) & (size-1));
2233
2234 return ptr;
2235}
2236
2237void jbd2_free(void *ptr, size_t size)
2238{
2239 if (size == PAGE_SIZE) {
2240 free_pages((unsigned long)ptr, 0);
2241 return;
2242 }
2243 if (size > PAGE_SIZE) {
2244 int order = get_order(size);
2245
2246 if (order < 3)
2247 free_pages((unsigned long)ptr, order);
2248 else
2249 vfree(ptr);
2250 return;
2251 }
2252 kmem_cache_free(get_slab(size), ptr);
2253};
2254
2255/*
Dave Kleikamp470decc2006-10-11 01:20:57 -07002256 * Journal_head storage management
2257 */
Christoph Lametere18b8902006-12-06 20:33:20 -08002258static struct kmem_cache *jbd2_journal_head_cache;
Jose R. Santose23291b2007-07-18 08:57:06 -04002259#ifdef CONFIG_JBD2_DEBUG
Dave Kleikamp470decc2006-10-11 01:20:57 -07002260static atomic_t nr_journal_heads = ATOMIC_INIT(0);
2261#endif
2262
Yongqiang Yang4185a2a2012-02-20 17:53:03 -05002263static int jbd2_journal_init_journal_head_cache(void)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002264{
2265 int retval;
2266
Al Viro1076d172008-03-29 03:07:18 +00002267 J_ASSERT(jbd2_journal_head_cache == NULL);
Johann Lombardia920e942006-10-11 01:21:00 -07002268 jbd2_journal_head_cache = kmem_cache_create("jbd2_journal_head",
Dave Kleikamp470decc2006-10-11 01:20:57 -07002269 sizeof(struct journal_head),
2270 0, /* offset */
Mingming Cao77160952008-01-28 23:58:27 -05002271 SLAB_TEMPORARY, /* flags */
Paul Mundt20c2df82007-07-20 10:11:58 +09002272 NULL); /* ctor */
Dave Kleikamp470decc2006-10-11 01:20:57 -07002273 retval = 0;
Al Viro1076d172008-03-29 03:07:18 +00002274 if (!jbd2_journal_head_cache) {
Dave Kleikamp470decc2006-10-11 01:20:57 -07002275 retval = -ENOMEM;
Eryu Guanf2a44522011-11-01 19:09:18 -04002276 printk(KERN_EMERG "JBD2: no memory for journal_head cache\n");
Dave Kleikamp470decc2006-10-11 01:20:57 -07002277 }
2278 return retval;
2279}
2280
Yongqiang Yang4185a2a2012-02-20 17:53:03 -05002281static void jbd2_journal_destroy_journal_head_cache(void)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002282{
Duane Griffin8a9362e2008-04-17 10:38:59 -04002283 if (jbd2_journal_head_cache) {
2284 kmem_cache_destroy(jbd2_journal_head_cache);
2285 jbd2_journal_head_cache = NULL;
2286 }
Dave Kleikamp470decc2006-10-11 01:20:57 -07002287}
2288
2289/*
2290 * journal_head splicing and dicing
2291 */
2292static struct journal_head *journal_alloc_journal_head(void)
2293{
2294 struct journal_head *ret;
Dave Kleikamp470decc2006-10-11 01:20:57 -07002295
Jose R. Santose23291b2007-07-18 08:57:06 -04002296#ifdef CONFIG_JBD2_DEBUG
Dave Kleikamp470decc2006-10-11 01:20:57 -07002297 atomic_inc(&nr_journal_heads);
2298#endif
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002299 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
Al Viro1076d172008-03-29 03:07:18 +00002300 if (!ret) {
Dave Kleikamp470decc2006-10-11 01:20:57 -07002301 jbd_debug(1, "out of memory for journal_head\n");
Theodore Ts'o670be5a2010-12-17 10:44:16 -05002302 pr_notice_ratelimited("ENOMEM in %s, retrying.\n", __func__);
Al Viro1076d172008-03-29 03:07:18 +00002303 while (!ret) {
Dave Kleikamp470decc2006-10-11 01:20:57 -07002304 yield();
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002305 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002306 }
2307 }
2308 return ret;
2309}
2310
2311static void journal_free_journal_head(struct journal_head *jh)
2312{
Jose R. Santose23291b2007-07-18 08:57:06 -04002313#ifdef CONFIG_JBD2_DEBUG
Dave Kleikamp470decc2006-10-11 01:20:57 -07002314 atomic_dec(&nr_journal_heads);
Mingming Caocd02ff02007-10-16 18:38:25 -04002315 memset(jh, JBD2_POISON_FREE, sizeof(*jh));
Dave Kleikamp470decc2006-10-11 01:20:57 -07002316#endif
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002317 kmem_cache_free(jbd2_journal_head_cache, jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002318}
2319
2320/*
2321 * A journal_head is attached to a buffer_head whenever JBD has an
2322 * interest in the buffer.
2323 *
2324 * Whenever a buffer has an attached journal_head, its ->b_state:BH_JBD bit
2325 * is set. This bit is tested in core kernel code where we need to take
2326 * JBD-specific actions. Testing the zeroness of ->b_private is not reliable
2327 * there.
2328 *
2329 * When a buffer has its BH_JBD bit set, its ->b_count is elevated by one.
2330 *
2331 * When a buffer has its BH_JBD bit set it is immune from being released by
2332 * core kernel code, mainly via ->b_count.
2333 *
Jan Karade1b7942011-06-13 15:38:22 -04002334 * A journal_head is detached from its buffer_head when the journal_head's
2335 * b_jcount reaches zero. Running transaction (b_transaction) and checkpoint
2336 * transaction (b_cp_transaction) hold their references to b_jcount.
Dave Kleikamp470decc2006-10-11 01:20:57 -07002337 *
2338 * Various places in the kernel want to attach a journal_head to a buffer_head
2339 * _before_ attaching the journal_head to a transaction. To protect the
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002340 * journal_head in this situation, jbd2_journal_add_journal_head elevates the
Dave Kleikamp470decc2006-10-11 01:20:57 -07002341 * journal_head's b_jcount refcount by one. The caller must call
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002342 * jbd2_journal_put_journal_head() to undo this.
Dave Kleikamp470decc2006-10-11 01:20:57 -07002343 *
2344 * So the typical usage would be:
2345 *
2346 * (Attach a journal_head if needed. Increments b_jcount)
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002347 * struct journal_head *jh = jbd2_journal_add_journal_head(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002348 * ...
Jan Karade1b7942011-06-13 15:38:22 -04002349 * (Get another reference for transaction)
2350 * jbd2_journal_grab_journal_head(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002351 * jh->b_transaction = xxx;
Jan Karade1b7942011-06-13 15:38:22 -04002352 * (Put original reference)
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002353 * jbd2_journal_put_journal_head(jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002354 */
2355
2356/*
2357 * Give a buffer_head a journal_head.
2358 *
Dave Kleikamp470decc2006-10-11 01:20:57 -07002359 * May sleep.
2360 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002361struct journal_head *jbd2_journal_add_journal_head(struct buffer_head *bh)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002362{
2363 struct journal_head *jh;
2364 struct journal_head *new_jh = NULL;
2365
2366repeat:
2367 if (!buffer_jbd(bh)) {
2368 new_jh = journal_alloc_journal_head();
2369 memset(new_jh, 0, sizeof(*new_jh));
2370 }
2371
2372 jbd_lock_bh_journal_head(bh);
2373 if (buffer_jbd(bh)) {
2374 jh = bh2jh(bh);
2375 } else {
2376 J_ASSERT_BH(bh,
2377 (atomic_read(&bh->b_count) > 0) ||
2378 (bh->b_page && bh->b_page->mapping));
2379
2380 if (!new_jh) {
2381 jbd_unlock_bh_journal_head(bh);
2382 goto repeat;
2383 }
2384
2385 jh = new_jh;
2386 new_jh = NULL; /* We consumed it */
2387 set_buffer_jbd(bh);
2388 bh->b_private = jh;
2389 jh->b_bh = bh;
2390 get_bh(bh);
2391 BUFFER_TRACE(bh, "added journal_head");
2392 }
2393 jh->b_jcount++;
2394 jbd_unlock_bh_journal_head(bh);
2395 if (new_jh)
2396 journal_free_journal_head(new_jh);
2397 return bh->b_private;
2398}
2399
2400/*
2401 * Grab a ref against this buffer_head's journal_head. If it ended up not
2402 * having a journal_head, return NULL
2403 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002404struct journal_head *jbd2_journal_grab_journal_head(struct buffer_head *bh)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002405{
2406 struct journal_head *jh = NULL;
2407
2408 jbd_lock_bh_journal_head(bh);
2409 if (buffer_jbd(bh)) {
2410 jh = bh2jh(bh);
2411 jh->b_jcount++;
2412 }
2413 jbd_unlock_bh_journal_head(bh);
2414 return jh;
2415}
2416
2417static void __journal_remove_journal_head(struct buffer_head *bh)
2418{
2419 struct journal_head *jh = bh2jh(bh);
2420
2421 J_ASSERT_JH(jh, jh->b_jcount >= 0);
Jan Karade1b7942011-06-13 15:38:22 -04002422 J_ASSERT_JH(jh, jh->b_transaction == NULL);
2423 J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
2424 J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
2425 J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
2426 J_ASSERT_BH(bh, buffer_jbd(bh));
2427 J_ASSERT_BH(bh, jh2bh(jh) == bh);
2428 BUFFER_TRACE(bh, "remove journal_head");
2429 if (jh->b_frozen_data) {
2430 printk(KERN_WARNING "%s: freeing b_frozen_data\n", __func__);
2431 jbd2_free(jh->b_frozen_data, bh->b_size);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002432 }
Jan Karade1b7942011-06-13 15:38:22 -04002433 if (jh->b_committed_data) {
2434 printk(KERN_WARNING "%s: freeing b_committed_data\n", __func__);
2435 jbd2_free(jh->b_committed_data, bh->b_size);
2436 }
2437 bh->b_private = NULL;
2438 jh->b_bh = NULL; /* debug, really */
2439 clear_buffer_jbd(bh);
2440 journal_free_journal_head(jh);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002441}
2442
2443/*
Jan Karade1b7942011-06-13 15:38:22 -04002444 * Drop a reference on the passed journal_head. If it fell to zero then
Dave Kleikamp470decc2006-10-11 01:20:57 -07002445 * release the journal_head from the buffer_head.
2446 */
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002447void jbd2_journal_put_journal_head(struct journal_head *jh)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002448{
2449 struct buffer_head *bh = jh2bh(jh);
2450
2451 jbd_lock_bh_journal_head(bh);
2452 J_ASSERT_JH(jh, jh->b_jcount > 0);
2453 --jh->b_jcount;
Jan Karade1b7942011-06-13 15:38:22 -04002454 if (!jh->b_jcount) {
Dave Kleikamp470decc2006-10-11 01:20:57 -07002455 __journal_remove_journal_head(bh);
Jan Karade1b7942011-06-13 15:38:22 -04002456 jbd_unlock_bh_journal_head(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002457 __brelse(bh);
Jan Karade1b7942011-06-13 15:38:22 -04002458 } else
2459 jbd_unlock_bh_journal_head(bh);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002460}
2461
2462/*
Jan Karac851ed52008-07-11 19:27:31 -04002463 * Initialize jbd inode head
2464 */
2465void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode)
2466{
2467 jinode->i_transaction = NULL;
2468 jinode->i_next_transaction = NULL;
2469 jinode->i_vfs_inode = inode;
2470 jinode->i_flags = 0;
2471 INIT_LIST_HEAD(&jinode->i_list);
2472}
2473
2474/*
2475 * Function to be called before we start removing inode from memory (i.e.,
2476 * clear_inode() is a fine place to be called from). It removes inode from
2477 * transaction's lists.
2478 */
2479void jbd2_journal_release_jbd_inode(journal_t *journal,
2480 struct jbd2_inode *jinode)
2481{
Jan Karac851ed52008-07-11 19:27:31 -04002482 if (!journal)
2483 return;
2484restart:
2485 spin_lock(&journal->j_list_lock);
2486 /* Is commit writing out inode - we have to wait */
Brian King39e3ac22010-10-27 21:25:12 -04002487 if (test_bit(__JI_COMMIT_RUNNING, &jinode->i_flags)) {
Jan Karac851ed52008-07-11 19:27:31 -04002488 wait_queue_head_t *wq;
2489 DEFINE_WAIT_BIT(wait, &jinode->i_flags, __JI_COMMIT_RUNNING);
2490 wq = bit_waitqueue(&jinode->i_flags, __JI_COMMIT_RUNNING);
2491 prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
2492 spin_unlock(&journal->j_list_lock);
2493 schedule();
2494 finish_wait(wq, &wait.wait);
2495 goto restart;
2496 }
2497
Jan Karac851ed52008-07-11 19:27:31 -04002498 if (jinode->i_transaction) {
2499 list_del(&jinode->i_list);
2500 jinode->i_transaction = NULL;
2501 }
2502 spin_unlock(&journal->j_list_lock);
2503}
2504
Dave Kleikamp470decc2006-10-11 01:20:57 -07002505
Johann Lombardi8e85fb32008-01-28 23:58:27 -05002506#ifdef CONFIG_PROC_FS
2507
2508#define JBD2_STATS_PROC_NAME "fs/jbd2"
2509
2510static void __init jbd2_create_jbd_stats_proc_entry(void)
2511{
2512 proc_jbd2_stats = proc_mkdir(JBD2_STATS_PROC_NAME, NULL);
2513}
2514
2515static void __exit jbd2_remove_jbd_stats_proc_entry(void)
2516{
2517 if (proc_jbd2_stats)
2518 remove_proc_entry(JBD2_STATS_PROC_NAME, NULL);
2519}
2520
2521#else
2522
2523#define jbd2_create_jbd_stats_proc_entry() do {} while (0)
2524#define jbd2_remove_jbd_stats_proc_entry() do {} while (0)
2525
2526#endif
2527
Theodore Ts'o8aefcd52011-01-10 12:29:43 -05002528struct kmem_cache *jbd2_handle_cache, *jbd2_inode_cache;
Dave Kleikamp470decc2006-10-11 01:20:57 -07002529
Yongqiang Yang4185a2a2012-02-20 17:53:03 -05002530static int __init jbd2_journal_init_handle_cache(void)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002531{
Theodore Ts'o8aefcd52011-01-10 12:29:43 -05002532 jbd2_handle_cache = KMEM_CACHE(jbd2_journal_handle, SLAB_TEMPORARY);
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002533 if (jbd2_handle_cache == NULL) {
Theodore Ts'o8aefcd52011-01-10 12:29:43 -05002534 printk(KERN_EMERG "JBD2: failed to create handle cache\n");
2535 return -ENOMEM;
2536 }
2537 jbd2_inode_cache = KMEM_CACHE(jbd2_inode, 0);
2538 if (jbd2_inode_cache == NULL) {
2539 printk(KERN_EMERG "JBD2: failed to create inode cache\n");
2540 kmem_cache_destroy(jbd2_handle_cache);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002541 return -ENOMEM;
2542 }
2543 return 0;
2544}
2545
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002546static void jbd2_journal_destroy_handle_cache(void)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002547{
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002548 if (jbd2_handle_cache)
2549 kmem_cache_destroy(jbd2_handle_cache);
Theodore Ts'o8aefcd52011-01-10 12:29:43 -05002550 if (jbd2_inode_cache)
2551 kmem_cache_destroy(jbd2_inode_cache);
2552
Dave Kleikamp470decc2006-10-11 01:20:57 -07002553}
2554
2555/*
2556 * Module startup and shutdown
2557 */
2558
2559static int __init journal_init_caches(void)
2560{
2561 int ret;
2562
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002563 ret = jbd2_journal_init_revoke_caches();
Dave Kleikamp470decc2006-10-11 01:20:57 -07002564 if (ret == 0)
Yongqiang Yang4185a2a2012-02-20 17:53:03 -05002565 ret = jbd2_journal_init_journal_head_cache();
Dave Kleikamp470decc2006-10-11 01:20:57 -07002566 if (ret == 0)
Yongqiang Yang4185a2a2012-02-20 17:53:03 -05002567 ret = jbd2_journal_init_handle_cache();
Yongqiang Yang0c2022e2012-02-20 17:53:02 -05002568 if (ret == 0)
2569 ret = jbd2_journal_init_transaction_cache();
Dave Kleikamp470decc2006-10-11 01:20:57 -07002570 return ret;
2571}
2572
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002573static void jbd2_journal_destroy_caches(void)
Dave Kleikamp470decc2006-10-11 01:20:57 -07002574{
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002575 jbd2_journal_destroy_revoke_caches();
Yongqiang Yang4185a2a2012-02-20 17:53:03 -05002576 jbd2_journal_destroy_journal_head_cache();
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002577 jbd2_journal_destroy_handle_cache();
Yongqiang Yang0c2022e2012-02-20 17:53:02 -05002578 jbd2_journal_destroy_transaction_cache();
Theodore Ts'od2eecb02009-12-07 10:36:20 -05002579 jbd2_journal_destroy_slabs();
Dave Kleikamp470decc2006-10-11 01:20:57 -07002580}
2581
2582static int __init journal_init(void)
2583{
2584 int ret;
2585
2586 BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);
2587
2588 ret = journal_init_caches();
Duane Griffin620de4e2008-04-29 22:02:47 -04002589 if (ret == 0) {
Duane Griffin620de4e2008-04-29 22:02:47 -04002590 jbd2_create_jbd_stats_proc_entry();
2591 } else {
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002592 jbd2_journal_destroy_caches();
Duane Griffin620de4e2008-04-29 22:02:47 -04002593 }
Dave Kleikamp470decc2006-10-11 01:20:57 -07002594 return ret;
2595}
2596
2597static void __exit journal_exit(void)
2598{
Jose R. Santose23291b2007-07-18 08:57:06 -04002599#ifdef CONFIG_JBD2_DEBUG
Dave Kleikamp470decc2006-10-11 01:20:57 -07002600 int n = atomic_read(&nr_journal_heads);
2601 if (n)
Eryu Guanf2a44522011-11-01 19:09:18 -04002602 printk(KERN_EMERG "JBD2: leaked %d journal_heads!\n", n);
Dave Kleikamp470decc2006-10-11 01:20:57 -07002603#endif
Johann Lombardi8e85fb32008-01-28 23:58:27 -05002604 jbd2_remove_jbd_stats_proc_entry();
Mingming Caof7f4bcc2006-10-11 01:20:59 -07002605 jbd2_journal_destroy_caches();
Dave Kleikamp470decc2006-10-11 01:20:57 -07002606}
2607
Dave Kleikamp470decc2006-10-11 01:20:57 -07002608MODULE_LICENSE("GPL");
2609module_init(journal_init);
2610module_exit(journal_exit);
2611