2 * linux/fs/jbd2/journal.c
4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
6 * Copyright 1998 Red Hat corp --- All Rights Reserved
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.
12 * Generic filesystem journal-writing code; part of the ext2fs
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.
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).
25 #include <linux/module.h>
26 #include <linux/time.h>
28 #include <linux/jbd2.h>
29 #include <linux/errno.h>
30 #include <linux/slab.h>
31 #include <linux/init.h>
33 #include <linux/freezer.h>
34 #include <linux/pagemap.h>
35 #include <linux/kthread.h>
36 #include <linux/poison.h>
37 #include <linux/proc_fs.h>
38 #include <linux/debugfs.h>
39 #include <linux/seq_file.h>
40 #include <linux/math64.h>
41 #include <linux/hash.h>
43 #define CREATE_TRACE_POINTS
44 #include <trace/events/jbd2.h>
46 #include <asm/uaccess.h>
49 EXPORT_SYMBOL(jbd2_journal_start);
50 EXPORT_SYMBOL(jbd2_journal_restart);
51 EXPORT_SYMBOL(jbd2_journal_extend);
52 EXPORT_SYMBOL(jbd2_journal_stop);
53 EXPORT_SYMBOL(jbd2_journal_lock_updates);
54 EXPORT_SYMBOL(jbd2_journal_unlock_updates);
55 EXPORT_SYMBOL(jbd2_journal_get_write_access);
56 EXPORT_SYMBOL(jbd2_journal_get_create_access);
57 EXPORT_SYMBOL(jbd2_journal_get_undo_access);
58 EXPORT_SYMBOL(jbd2_journal_set_triggers);
59 EXPORT_SYMBOL(jbd2_journal_dirty_metadata);
60 EXPORT_SYMBOL(jbd2_journal_release_buffer);
61 EXPORT_SYMBOL(jbd2_journal_forget);
63 EXPORT_SYMBOL(journal_sync_buffer);
65 EXPORT_SYMBOL(jbd2_journal_flush);
66 EXPORT_SYMBOL(jbd2_journal_revoke);
68 EXPORT_SYMBOL(jbd2_journal_init_dev);
69 EXPORT_SYMBOL(jbd2_journal_init_inode);
70 EXPORT_SYMBOL(jbd2_journal_update_format);
71 EXPORT_SYMBOL(jbd2_journal_check_used_features);
72 EXPORT_SYMBOL(jbd2_journal_check_available_features);
73 EXPORT_SYMBOL(jbd2_journal_set_features);
74 EXPORT_SYMBOL(jbd2_journal_load);
75 EXPORT_SYMBOL(jbd2_journal_destroy);
76 EXPORT_SYMBOL(jbd2_journal_abort);
77 EXPORT_SYMBOL(jbd2_journal_errno);
78 EXPORT_SYMBOL(jbd2_journal_ack_err);
79 EXPORT_SYMBOL(jbd2_journal_clear_err);
80 EXPORT_SYMBOL(jbd2_log_wait_commit);
81 EXPORT_SYMBOL(jbd2_journal_start_commit);
82 EXPORT_SYMBOL(jbd2_journal_force_commit_nested);
83 EXPORT_SYMBOL(jbd2_journal_wipe);
84 EXPORT_SYMBOL(jbd2_journal_blocks_per_page);
85 EXPORT_SYMBOL(jbd2_journal_invalidatepage);
86 EXPORT_SYMBOL(jbd2_journal_try_to_free_buffers);
87 EXPORT_SYMBOL(jbd2_journal_force_commit);
88 EXPORT_SYMBOL(jbd2_journal_file_inode);
89 EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
90 EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
91 EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
93 static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
94 static void __journal_abort_soft (journal_t *journal, int errno);
97 * Helper function used to manage commit timeouts
100 static void commit_timeout(unsigned long __data)
102 struct task_struct * p = (struct task_struct *) __data;
108 * kjournald2: The main thread function used to manage a logging device
111 * This kernel thread is responsible for two things:
113 * 1) COMMIT: Every so often we need to commit the current state of the
114 * filesystem to disk. The journal thread is responsible for writing
115 * all of the metadata buffers to disk.
117 * 2) CHECKPOINT: We cannot reuse a used section of the log file until all
118 * of the data in that part of the log has been rewritten elsewhere on
119 * the disk. Flushing these old buffers to reclaim space in the log is
120 * known as checkpointing, and this thread is responsible for that job.
123 static int kjournald2(void *arg)
125 journal_t *journal = arg;
126 transaction_t *transaction;
129 * Set up an interval timer which can be used to trigger a commit wakeup
130 * after the commit interval expires
132 setup_timer(&journal->j_commit_timer, commit_timeout,
133 (unsigned long)current);
135 /* Record that the journal thread is running */
136 journal->j_task = current;
137 wake_up(&journal->j_wait_done_commit);
140 * And now, wait forever for commit wakeup events.
142 spin_lock(&journal->j_state_lock);
145 if (journal->j_flags & JBD2_UNMOUNT)
148 jbd_debug(1, "commit_sequence=%d, commit_request=%d\n",
149 journal->j_commit_sequence, journal->j_commit_request);
151 if (journal->j_commit_sequence != journal->j_commit_request) {
152 jbd_debug(1, "OK, requests differ\n");
153 spin_unlock(&journal->j_state_lock);
154 del_timer_sync(&journal->j_commit_timer);
155 jbd2_journal_commit_transaction(journal);
156 spin_lock(&journal->j_state_lock);
160 wake_up(&journal->j_wait_done_commit);
161 if (freezing(current)) {
163 * The simpler the better. Flushing journal isn't a
164 * good idea, because that depends on threads that may
165 * be already stopped.
167 jbd_debug(1, "Now suspending kjournald2\n");
168 spin_unlock(&journal->j_state_lock);
170 spin_lock(&journal->j_state_lock);
173 * We assume on resume that commits are already there,
177 int should_sleep = 1;
179 prepare_to_wait(&journal->j_wait_commit, &wait,
181 if (journal->j_commit_sequence != journal->j_commit_request)
183 transaction = journal->j_running_transaction;
184 if (transaction && time_after_eq(jiffies,
185 transaction->t_expires))
187 if (journal->j_flags & JBD2_UNMOUNT)
190 spin_unlock(&journal->j_state_lock);
192 spin_lock(&journal->j_state_lock);
194 finish_wait(&journal->j_wait_commit, &wait);
197 jbd_debug(1, "kjournald2 wakes\n");
200 * Were we woken up by a commit wakeup event?
202 transaction = journal->j_running_transaction;
203 if (transaction && time_after_eq(jiffies, transaction->t_expires)) {
204 journal->j_commit_request = transaction->t_tid;
205 jbd_debug(1, "woke because of timeout\n");
210 spin_unlock(&journal->j_state_lock);
211 del_timer_sync(&journal->j_commit_timer);
212 journal->j_task = NULL;
213 wake_up(&journal->j_wait_done_commit);
214 jbd_debug(1, "Journal thread exiting.\n");
218 static int jbd2_journal_start_thread(journal_t *journal)
220 struct task_struct *t;
222 t = kthread_run(kjournald2, journal, "jbd2/%s",
227 wait_event(journal->j_wait_done_commit, journal->j_task != NULL);
231 static void journal_kill_thread(journal_t *journal)
233 spin_lock(&journal->j_state_lock);
234 journal->j_flags |= JBD2_UNMOUNT;
236 while (journal->j_task) {
237 wake_up(&journal->j_wait_commit);
238 spin_unlock(&journal->j_state_lock);
239 wait_event(journal->j_wait_done_commit, journal->j_task == NULL);
240 spin_lock(&journal->j_state_lock);
242 spin_unlock(&journal->j_state_lock);
246 * jbd2_journal_write_metadata_buffer: write a metadata buffer to the journal.
248 * Writes a metadata buffer to a given disk block. The actual IO is not
249 * performed but a new buffer_head is constructed which labels the data
250 * to be written with the correct destination disk block.
252 * Any magic-number escaping which needs to be done will cause a
253 * copy-out here. If the buffer happens to start with the
254 * JBD2_MAGIC_NUMBER, then we can't write it to the log directly: the
255 * magic number is only written to the log for descripter blocks. In
256 * this case, we copy the data and replace the first word with 0, and we
257 * return a result code which indicates that this buffer needs to be
258 * marked as an escaped buffer in the corresponding log descriptor
259 * block. The missing word can then be restored when the block is read
262 * If the source buffer has already been modified by a new transaction
263 * since we took the last commit snapshot, we use the frozen copy of
264 * that data for IO. If we end up using the existing buffer_head's data
265 * for the write, then we *have* to lock the buffer to prevent anyone
266 * else from using and possibly modifying it while the IO is in
269 * The function returns a pointer to the buffer_heads to be used for IO.
271 * We assume that the journal has already been locked in this function.
278 * Bit 0 set == escape performed on the data
279 * Bit 1 set == buffer copy-out performed (kfree the data after IO)
282 int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
283 struct journal_head *jh_in,
284 struct journal_head **jh_out,
285 unsigned long long blocknr)
287 int need_copy_out = 0;
288 int done_copy_out = 0;
291 struct buffer_head *new_bh;
292 struct journal_head *new_jh;
293 struct page *new_page;
294 unsigned int new_offset;
295 struct buffer_head *bh_in = jh2bh(jh_in);
296 struct jbd2_buffer_trigger_type *triggers;
297 journal_t *journal = transaction->t_journal;
300 * The buffer really shouldn't be locked: only the current committing
301 * transaction is allowed to write it, so nobody else is allowed
304 * akpm: except if we're journalling data, and write() output is
305 * also part of a shared mapping, and another thread has
306 * decided to launch a writepage() against this buffer.
308 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
310 new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL);
311 /* keep subsequent assertions sane */
313 init_buffer(new_bh, NULL, NULL);
314 atomic_set(&new_bh->b_count, 1);
315 new_jh = jbd2_journal_add_journal_head(new_bh); /* This sleeps */
318 * If a new transaction has already done a buffer copy-out, then
319 * we use that version of the data for the commit.
321 jbd_lock_bh_state(bh_in);
323 if (jh_in->b_frozen_data) {
325 new_page = virt_to_page(jh_in->b_frozen_data);
326 new_offset = offset_in_page(jh_in->b_frozen_data);
327 triggers = jh_in->b_frozen_triggers;
329 new_page = jh2bh(jh_in)->b_page;
330 new_offset = offset_in_page(jh2bh(jh_in)->b_data);
331 triggers = jh_in->b_triggers;
334 mapped_data = kmap_atomic(new_page, KM_USER0);
336 * Fire any commit trigger. Do this before checking for escaping,
337 * as the trigger may modify the magic offset. If a copy-out
338 * happens afterwards, it will have the correct data in the buffer.
340 jbd2_buffer_commit_trigger(jh_in, mapped_data + new_offset,
346 if (*((__be32 *)(mapped_data + new_offset)) ==
347 cpu_to_be32(JBD2_MAGIC_NUMBER)) {
351 kunmap_atomic(mapped_data, KM_USER0);
354 * Do we need to do a data copy?
356 if (need_copy_out && !done_copy_out) {
359 jbd_unlock_bh_state(bh_in);
360 tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
361 jbd_lock_bh_state(bh_in);
362 if (jh_in->b_frozen_data) {
363 jbd2_free(tmp, bh_in->b_size);
367 jh_in->b_frozen_data = tmp;
368 mapped_data = kmap_atomic(new_page, KM_USER0);
369 memcpy(tmp, mapped_data + new_offset, jh2bh(jh_in)->b_size);
370 kunmap_atomic(mapped_data, KM_USER0);
372 new_page = virt_to_page(tmp);
373 new_offset = offset_in_page(tmp);
377 * This isn't strictly necessary, as we're using frozen
378 * data for the escaping, but it keeps consistency with
379 * b_frozen_data usage.
381 jh_in->b_frozen_triggers = jh_in->b_triggers;
385 * Did we need to do an escaping? Now we've done all the
386 * copying, we can finally do so.
389 mapped_data = kmap_atomic(new_page, KM_USER0);
390 *((unsigned int *)(mapped_data + new_offset)) = 0;
391 kunmap_atomic(mapped_data, KM_USER0);
394 set_bh_page(new_bh, new_page, new_offset);
395 new_jh->b_transaction = NULL;
396 new_bh->b_size = jh2bh(jh_in)->b_size;
397 new_bh->b_bdev = transaction->t_journal->j_dev;
398 new_bh->b_blocknr = blocknr;
399 set_buffer_mapped(new_bh);
400 set_buffer_dirty(new_bh);
405 * The to-be-written buffer needs to get moved to the io queue,
406 * and the original buffer whose contents we are shadowing or
407 * copying is moved to the transaction's shadow queue.
409 JBUFFER_TRACE(jh_in, "file as BJ_Shadow");
410 spin_lock(&journal->j_list_lock);
411 __jbd2_journal_file_buffer(jh_in, transaction, BJ_Shadow);
412 spin_unlock(&journal->j_list_lock);
413 jbd_unlock_bh_state(bh_in);
415 JBUFFER_TRACE(new_jh, "file as BJ_IO");
416 jbd2_journal_file_buffer(new_jh, transaction, BJ_IO);
418 return do_escape | (done_copy_out << 1);
422 * Allocation code for the journal file. Manage the space left in the
423 * journal, so that we can begin checkpointing when appropriate.
427 * __jbd2_log_space_left: Return the number of free blocks left in the journal.
429 * Called with the journal already locked.
431 * Called under j_state_lock
434 int __jbd2_log_space_left(journal_t *journal)
436 int left = journal->j_free;
438 assert_spin_locked(&journal->j_state_lock);
441 * Be pessimistic here about the number of those free blocks which
442 * might be required for log descriptor control blocks.
445 #define MIN_LOG_RESERVED_BLOCKS 32 /* Allow for rounding errors */
447 left -= MIN_LOG_RESERVED_BLOCKS;
456 * Called under j_state_lock. Returns true if a transaction commit was started.
458 int __jbd2_log_start_commit(journal_t *journal, tid_t target)
461 * Are we already doing a recent enough commit?
463 if (!tid_geq(journal->j_commit_request, target)) {
465 * We want a new commit: OK, mark the request and wakup the
466 * commit thread. We do _not_ do the commit ourselves.
469 journal->j_commit_request = target;
470 jbd_debug(1, "JBD: requesting commit %d/%d\n",
471 journal->j_commit_request,
472 journal->j_commit_sequence);
473 wake_up(&journal->j_wait_commit);
479 int jbd2_log_start_commit(journal_t *journal, tid_t tid)
483 spin_lock(&journal->j_state_lock);
484 ret = __jbd2_log_start_commit(journal, tid);
485 spin_unlock(&journal->j_state_lock);
490 * Force and wait upon a commit if the calling process is not within
491 * transaction. This is used for forcing out undo-protected data which contains
492 * bitmaps, when the fs is running out of space.
494 * We can only force the running transaction if we don't have an active handle;
495 * otherwise, we will deadlock.
497 * Returns true if a transaction was started.
499 int jbd2_journal_force_commit_nested(journal_t *journal)
501 transaction_t *transaction = NULL;
504 spin_lock(&journal->j_state_lock);
505 if (journal->j_running_transaction && !current->journal_info) {
506 transaction = journal->j_running_transaction;
507 __jbd2_log_start_commit(journal, transaction->t_tid);
508 } else if (journal->j_committing_transaction)
509 transaction = journal->j_committing_transaction;
512 spin_unlock(&journal->j_state_lock);
513 return 0; /* Nothing to retry */
516 tid = transaction->t_tid;
517 spin_unlock(&journal->j_state_lock);
518 jbd2_log_wait_commit(journal, tid);
523 * Start a commit of the current running transaction (if any). Returns true
524 * if a transaction is going to be committed (or is currently already
525 * committing), and fills its tid in at *ptid
527 int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
531 spin_lock(&journal->j_state_lock);
532 if (journal->j_running_transaction) {
533 tid_t tid = journal->j_running_transaction->t_tid;
535 __jbd2_log_start_commit(journal, tid);
536 /* There's a running transaction and we've just made sure
537 * it's commit has been scheduled. */
541 } else if (journal->j_committing_transaction) {
543 * If ext3_write_super() recently started a commit, then we
544 * have to wait for completion of that transaction
547 *ptid = journal->j_committing_transaction->t_tid;
550 spin_unlock(&journal->j_state_lock);
555 * Wait for a specified commit to complete.
556 * The caller may not hold the journal lock.
558 int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
562 #ifdef CONFIG_JBD2_DEBUG
563 spin_lock(&journal->j_state_lock);
564 if (!tid_geq(journal->j_commit_request, tid)) {
566 "%s: error: j_commit_request=%d, tid=%d\n",
567 __func__, journal->j_commit_request, tid);
569 spin_unlock(&journal->j_state_lock);
571 spin_lock(&journal->j_state_lock);
572 while (tid_gt(tid, journal->j_commit_sequence)) {
573 jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n",
574 tid, journal->j_commit_sequence);
575 wake_up(&journal->j_wait_commit);
576 spin_unlock(&journal->j_state_lock);
577 wait_event(journal->j_wait_done_commit,
578 !tid_gt(tid, journal->j_commit_sequence));
579 spin_lock(&journal->j_state_lock);
581 spin_unlock(&journal->j_state_lock);
583 if (unlikely(is_journal_aborted(journal))) {
584 printk(KERN_EMERG "journal commit I/O error\n");
591 * Log buffer allocation routines:
594 int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
596 unsigned long blocknr;
598 spin_lock(&journal->j_state_lock);
599 J_ASSERT(journal->j_free > 1);
601 blocknr = journal->j_head;
604 if (journal->j_head == journal->j_last)
605 journal->j_head = journal->j_first;
606 spin_unlock(&journal->j_state_lock);
607 return jbd2_journal_bmap(journal, blocknr, retp);
611 * Conversion of logical to physical block numbers for the journal
613 * On external journals the journal blocks are identity-mapped, so
614 * this is a no-op. If needed, we can use j_blk_offset - everything is
617 int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
618 unsigned long long *retp)
621 unsigned long long ret;
623 if (journal->j_inode) {
624 ret = bmap(journal->j_inode, blocknr);
628 printk(KERN_ALERT "%s: journal block not found "
629 "at offset %lu on %s\n",
630 __func__, blocknr, journal->j_devname);
632 __journal_abort_soft(journal, err);
635 *retp = blocknr; /* +journal->j_blk_offset */
641 * We play buffer_head aliasing tricks to write data/metadata blocks to
642 * the journal without copying their contents, but for journal
643 * descriptor blocks we do need to generate bona fide buffers.
645 * After the caller of jbd2_journal_get_descriptor_buffer() has finished modifying
646 * the buffer's contents they really should run flush_dcache_page(bh->b_page).
647 * But we don't bother doing that, so there will be coherency problems with
648 * mmaps of blockdevs which hold live JBD-controlled filesystems.
650 struct journal_head *jbd2_journal_get_descriptor_buffer(journal_t *journal)
652 struct buffer_head *bh;
653 unsigned long long blocknr;
656 err = jbd2_journal_next_log_block(journal, &blocknr);
661 bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
665 memset(bh->b_data, 0, journal->j_blocksize);
666 set_buffer_uptodate(bh);
668 BUFFER_TRACE(bh, "return this buffer");
669 return jbd2_journal_add_journal_head(bh);
672 struct jbd2_stats_proc_session {
674 struct transaction_stats_s *stats;
679 static void *jbd2_history_skip_empty(struct jbd2_stats_proc_session *s,
680 struct transaction_stats_s *ts,
683 if (ts == s->stats + s->max)
685 if (!first && ts == s->stats + s->start)
687 while (ts->ts_type == 0) {
689 if (ts == s->stats + s->max)
691 if (ts == s->stats + s->start)
698 static void *jbd2_seq_history_start(struct seq_file *seq, loff_t *pos)
700 struct jbd2_stats_proc_session *s = seq->private;
701 struct transaction_stats_s *ts;
705 return SEQ_START_TOKEN;
706 ts = jbd2_history_skip_empty(s, s->stats + s->start, 1);
711 ts = jbd2_history_skip_empty(s, ++ts, 0);
719 static void *jbd2_seq_history_next(struct seq_file *seq, void *v, loff_t *pos)
721 struct jbd2_stats_proc_session *s = seq->private;
722 struct transaction_stats_s *ts = v;
725 if (v == SEQ_START_TOKEN)
726 return jbd2_history_skip_empty(s, s->stats + s->start, 1);
728 return jbd2_history_skip_empty(s, ++ts, 0);
731 static int jbd2_seq_history_show(struct seq_file *seq, void *v)
733 struct transaction_stats_s *ts = v;
734 if (v == SEQ_START_TOKEN) {
735 seq_printf(seq, "%-4s %-5s %-5s %-5s %-5s %-5s %-5s %-6s %-5s "
736 "%-5s %-5s %-5s %-5s %-5s\n", "R/C", "tid",
737 "wait", "run", "lock", "flush", "log", "hndls",
738 "block", "inlog", "ctime", "write", "drop",
742 if (ts->ts_type == JBD2_STATS_RUN)
743 seq_printf(seq, "%-4s %-5lu %-5u %-5u %-5u %-5u %-5u "
744 "%-6lu %-5lu %-5lu\n", "R", ts->ts_tid,
745 jiffies_to_msecs(ts->u.run.rs_wait),
746 jiffies_to_msecs(ts->u.run.rs_running),
747 jiffies_to_msecs(ts->u.run.rs_locked),
748 jiffies_to_msecs(ts->u.run.rs_flushing),
749 jiffies_to_msecs(ts->u.run.rs_logging),
750 ts->u.run.rs_handle_count,
752 ts->u.run.rs_blocks_logged);
753 else if (ts->ts_type == JBD2_STATS_CHECKPOINT)
754 seq_printf(seq, "%-4s %-5lu %48s %-5u %-5lu %-5lu %-5lu\n",
755 "C", ts->ts_tid, " ",
756 jiffies_to_msecs(ts->u.chp.cs_chp_time),
757 ts->u.chp.cs_written, ts->u.chp.cs_dropped,
758 ts->u.chp.cs_forced_to_close);
764 static void jbd2_seq_history_stop(struct seq_file *seq, void *v)
768 static const struct seq_operations jbd2_seq_history_ops = {
769 .start = jbd2_seq_history_start,
770 .next = jbd2_seq_history_next,
771 .stop = jbd2_seq_history_stop,
772 .show = jbd2_seq_history_show,
775 static int jbd2_seq_history_open(struct inode *inode, struct file *file)
777 journal_t *journal = PDE(inode)->data;
778 struct jbd2_stats_proc_session *s;
781 s = kmalloc(sizeof(*s), GFP_KERNEL);
784 size = sizeof(struct transaction_stats_s) * journal->j_history_max;
785 s->stats = kmalloc(size, GFP_KERNEL);
786 if (s->stats == NULL) {
790 spin_lock(&journal->j_history_lock);
791 memcpy(s->stats, journal->j_history, size);
792 s->max = journal->j_history_max;
793 s->start = journal->j_history_cur % s->max;
794 spin_unlock(&journal->j_history_lock);
796 rc = seq_open(file, &jbd2_seq_history_ops);
798 struct seq_file *m = file->private_data;
808 static int jbd2_seq_history_release(struct inode *inode, struct file *file)
810 struct seq_file *seq = file->private_data;
811 struct jbd2_stats_proc_session *s = seq->private;
815 return seq_release(inode, file);
818 static struct file_operations jbd2_seq_history_fops = {
819 .owner = THIS_MODULE,
820 .open = jbd2_seq_history_open,
823 .release = jbd2_seq_history_release,
826 static void *jbd2_seq_info_start(struct seq_file *seq, loff_t *pos)
828 return *pos ? NULL : SEQ_START_TOKEN;
831 static void *jbd2_seq_info_next(struct seq_file *seq, void *v, loff_t *pos)
836 static int jbd2_seq_info_show(struct seq_file *seq, void *v)
838 struct jbd2_stats_proc_session *s = seq->private;
840 if (v != SEQ_START_TOKEN)
842 seq_printf(seq, "%lu transaction, each upto %u blocks\n",
844 s->journal->j_max_transaction_buffers);
845 if (s->stats->ts_tid == 0)
847 seq_printf(seq, "average: \n %ums waiting for transaction\n",
848 jiffies_to_msecs(s->stats->u.run.rs_wait / s->stats->ts_tid));
849 seq_printf(seq, " %ums running transaction\n",
850 jiffies_to_msecs(s->stats->u.run.rs_running / s->stats->ts_tid));
851 seq_printf(seq, " %ums transaction was being locked\n",
852 jiffies_to_msecs(s->stats->u.run.rs_locked / s->stats->ts_tid));
853 seq_printf(seq, " %ums flushing data (in ordered mode)\n",
854 jiffies_to_msecs(s->stats->u.run.rs_flushing / s->stats->ts_tid));
855 seq_printf(seq, " %ums logging transaction\n",
856 jiffies_to_msecs(s->stats->u.run.rs_logging / s->stats->ts_tid));
857 seq_printf(seq, " %lluus average transaction commit time\n",
858 div_u64(s->journal->j_average_commit_time, 1000));
859 seq_printf(seq, " %lu handles per transaction\n",
860 s->stats->u.run.rs_handle_count / s->stats->ts_tid);
861 seq_printf(seq, " %lu blocks per transaction\n",
862 s->stats->u.run.rs_blocks / s->stats->ts_tid);
863 seq_printf(seq, " %lu logged blocks per transaction\n",
864 s->stats->u.run.rs_blocks_logged / s->stats->ts_tid);
868 static void jbd2_seq_info_stop(struct seq_file *seq, void *v)
872 static const struct seq_operations jbd2_seq_info_ops = {
873 .start = jbd2_seq_info_start,
874 .next = jbd2_seq_info_next,
875 .stop = jbd2_seq_info_stop,
876 .show = jbd2_seq_info_show,
879 static int jbd2_seq_info_open(struct inode *inode, struct file *file)
881 journal_t *journal = PDE(inode)->data;
882 struct jbd2_stats_proc_session *s;
885 s = kmalloc(sizeof(*s), GFP_KERNEL);
888 size = sizeof(struct transaction_stats_s);
889 s->stats = kmalloc(size, GFP_KERNEL);
890 if (s->stats == NULL) {
894 spin_lock(&journal->j_history_lock);
895 memcpy(s->stats, &journal->j_stats, size);
896 s->journal = journal;
897 spin_unlock(&journal->j_history_lock);
899 rc = seq_open(file, &jbd2_seq_info_ops);
901 struct seq_file *m = file->private_data;
911 static int jbd2_seq_info_release(struct inode *inode, struct file *file)
913 struct seq_file *seq = file->private_data;
914 struct jbd2_stats_proc_session *s = seq->private;
917 return seq_release(inode, file);
920 static struct file_operations jbd2_seq_info_fops = {
921 .owner = THIS_MODULE,
922 .open = jbd2_seq_info_open,
925 .release = jbd2_seq_info_release,
928 static struct proc_dir_entry *proc_jbd2_stats;
930 static void jbd2_stats_proc_init(journal_t *journal)
932 journal->j_proc_entry = proc_mkdir(journal->j_devname, proc_jbd2_stats);
933 if (journal->j_proc_entry) {
934 proc_create_data("history", S_IRUGO, journal->j_proc_entry,
935 &jbd2_seq_history_fops, journal);
936 proc_create_data("info", S_IRUGO, journal->j_proc_entry,
937 &jbd2_seq_info_fops, journal);
941 static void jbd2_stats_proc_exit(journal_t *journal)
943 remove_proc_entry("info", journal->j_proc_entry);
944 remove_proc_entry("history", journal->j_proc_entry);
945 remove_proc_entry(journal->j_devname, proc_jbd2_stats);
948 static void journal_init_stats(journal_t *journal)
952 if (!proc_jbd2_stats)
955 journal->j_history_max = 100;
956 size = sizeof(struct transaction_stats_s) * journal->j_history_max;
957 journal->j_history = kzalloc(size, GFP_KERNEL);
958 if (!journal->j_history) {
959 journal->j_history_max = 0;
962 spin_lock_init(&journal->j_history_lock);
966 * Management for journal control blocks: functions to create and
967 * destroy journal_t structures, and to initialise and read existing
968 * journal blocks from disk. */
970 /* First: create and setup a journal_t object in memory. We initialise
971 * very few fields yet: that has to wait until we have created the
972 * journal structures from from scratch, or loaded them from disk. */
974 static journal_t * journal_init_common (void)
979 journal = kzalloc(sizeof(*journal), GFP_KERNEL|__GFP_NOFAIL);
983 init_waitqueue_head(&journal->j_wait_transaction_locked);
984 init_waitqueue_head(&journal->j_wait_logspace);
985 init_waitqueue_head(&journal->j_wait_done_commit);
986 init_waitqueue_head(&journal->j_wait_checkpoint);
987 init_waitqueue_head(&journal->j_wait_commit);
988 init_waitqueue_head(&journal->j_wait_updates);
989 mutex_init(&journal->j_barrier);
990 mutex_init(&journal->j_checkpoint_mutex);
991 spin_lock_init(&journal->j_revoke_lock);
992 spin_lock_init(&journal->j_list_lock);
993 spin_lock_init(&journal->j_state_lock);
995 journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
996 journal->j_min_batch_time = 0;
997 journal->j_max_batch_time = 15000; /* 15ms */
999 /* The journal is marked for error until we succeed with recovery! */
1000 journal->j_flags = JBD2_ABORT;
1002 /* Set up a default-sized revoke table for the new mount. */
1003 err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH);
1009 journal_init_stats(journal);
1016 /* jbd2_journal_init_dev and jbd2_journal_init_inode:
1018 * Create a journal structure assigned some fixed set of disk blocks to
1019 * the journal. We don't actually touch those disk blocks yet, but we
1020 * need to set up all of the mapping information to tell the journaling
1021 * system where the journal blocks are.
1026 * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure
1027 * @bdev: Block device on which to create the journal
1028 * @fs_dev: Device which hold journalled filesystem for this journal.
1029 * @start: Block nr Start of journal.
1030 * @len: Length of the journal in blocks.
1031 * @blocksize: blocksize of journalling device
1033 * Returns: a newly created journal_t *
1035 * jbd2_journal_init_dev creates a journal which maps a fixed contiguous
1036 * range of blocks on an arbitrary block device.
1039 journal_t * jbd2_journal_init_dev(struct block_device *bdev,
1040 struct block_device *fs_dev,
1041 unsigned long long start, int len, int blocksize)
1043 journal_t *journal = journal_init_common();
1044 struct buffer_head *bh;
1051 /* journal descriptor can store up to n blocks -bzzz */
1052 journal->j_blocksize = blocksize;
1053 jbd2_stats_proc_init(journal);
1054 n = journal->j_blocksize / sizeof(journal_block_tag_t);
1055 journal->j_wbufsize = n;
1056 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
1057 if (!journal->j_wbuf) {
1058 printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
1062 journal->j_dev = bdev;
1063 journal->j_fs_dev = fs_dev;
1064 journal->j_blk_offset = start;
1065 journal->j_maxlen = len;
1066 bdevname(journal->j_dev, journal->j_devname);
1067 p = journal->j_devname;
1068 while ((p = strchr(p, '/')))
1071 bh = __getblk(journal->j_dev, start, journal->j_blocksize);
1074 "%s: Cannot get buffer for journal superblock\n",
1078 journal->j_sb_buffer = bh;
1079 journal->j_superblock = (journal_superblock_t *)bh->b_data;
1083 jbd2_stats_proc_exit(journal);
1089 * journal_t * jbd2_journal_init_inode () - creates a journal which maps to a inode.
1090 * @inode: An inode to create the journal in
1092 * jbd2_journal_init_inode creates a journal which maps an on-disk inode as
1093 * the journal. The inode must exist already, must support bmap() and
1094 * must have all data blocks preallocated.
1096 journal_t * jbd2_journal_init_inode (struct inode *inode)
1098 struct buffer_head *bh;
1099 journal_t *journal = journal_init_common();
1103 unsigned long long blocknr;
1108 journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
1109 journal->j_inode = inode;
1110 bdevname(journal->j_dev, journal->j_devname);
1111 p = journal->j_devname;
1112 while ((p = strchr(p, '/')))
1114 p = journal->j_devname + strlen(journal->j_devname);
1115 sprintf(p, "-%lu", journal->j_inode->i_ino);
1117 "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
1118 journal, inode->i_sb->s_id, inode->i_ino,
1119 (long long) inode->i_size,
1120 inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
1122 journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits;
1123 journal->j_blocksize = inode->i_sb->s_blocksize;
1124 jbd2_stats_proc_init(journal);
1126 /* journal descriptor can store up to n blocks -bzzz */
1127 n = journal->j_blocksize / sizeof(journal_block_tag_t);
1128 journal->j_wbufsize = n;
1129 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
1130 if (!journal->j_wbuf) {
1131 printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
1136 err = jbd2_journal_bmap(journal, 0, &blocknr);
1137 /* If that failed, give up */
1139 printk(KERN_ERR "%s: Cannnot locate journal superblock\n",
1144 bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
1147 "%s: Cannot get buffer for journal superblock\n",
1151 journal->j_sb_buffer = bh;
1152 journal->j_superblock = (journal_superblock_t *)bh->b_data;
1156 jbd2_stats_proc_exit(journal);
1162 * If the journal init or create aborts, we need to mark the journal
1163 * superblock as being NULL to prevent the journal destroy from writing
1164 * back a bogus superblock.
1166 static void journal_fail_superblock (journal_t *journal)
1168 struct buffer_head *bh = journal->j_sb_buffer;
1170 journal->j_sb_buffer = NULL;
1174 * Given a journal_t structure, initialise the various fields for
1175 * startup of a new journaling session. We use this both when creating
1176 * a journal, and after recovering an old journal to reset it for
1180 static int journal_reset(journal_t *journal)
1182 journal_superblock_t *sb = journal->j_superblock;
1183 unsigned long long first, last;
1185 first = be32_to_cpu(sb->s_first);
1186 last = be32_to_cpu(sb->s_maxlen);
1187 if (first + JBD2_MIN_JOURNAL_BLOCKS > last + 1) {
1188 printk(KERN_ERR "JBD: Journal too short (blocks %llu-%llu).\n",
1190 journal_fail_superblock(journal);
1194 journal->j_first = first;
1195 journal->j_last = last;
1197 journal->j_head = first;
1198 journal->j_tail = first;
1199 journal->j_free = last - first;
1201 journal->j_tail_sequence = journal->j_transaction_sequence;
1202 journal->j_commit_sequence = journal->j_transaction_sequence - 1;
1203 journal->j_commit_request = journal->j_commit_sequence;
1205 journal->j_max_transaction_buffers = journal->j_maxlen / 4;
1207 /* Add the dynamic fields and write it to disk. */
1208 jbd2_journal_update_superblock(journal, 1);
1209 return jbd2_journal_start_thread(journal);
1213 * void jbd2_journal_update_superblock() - Update journal sb on disk.
1214 * @journal: The journal to update.
1215 * @wait: Set to '0' if you don't want to wait for IO completion.
1217 * Update a journal's dynamic superblock fields and write it to disk,
1218 * optionally waiting for the IO to complete.
1220 void jbd2_journal_update_superblock(journal_t *journal, int wait)
1222 journal_superblock_t *sb = journal->j_superblock;
1223 struct buffer_head *bh = journal->j_sb_buffer;
1226 * As a special case, if the on-disk copy is already marked as needing
1227 * no recovery (s_start == 0) and there are no outstanding transactions
1228 * in the filesystem, then we can safely defer the superblock update
1229 * until the next commit by setting JBD2_FLUSHED. This avoids
1230 * attempting a write to a potential-readonly device.
1232 if (sb->s_start == 0 && journal->j_tail_sequence ==
1233 journal->j_transaction_sequence) {
1234 jbd_debug(1,"JBD: Skipping superblock update on recovered sb "
1235 "(start %ld, seq %d, errno %d)\n",
1236 journal->j_tail, journal->j_tail_sequence,
1241 if (buffer_write_io_error(bh)) {
1243 * Oh, dear. A previous attempt to write the journal
1244 * superblock failed. This could happen because the
1245 * USB device was yanked out. Or it could happen to
1246 * be a transient write error and maybe the block will
1247 * be remapped. Nothing we can do but to retry the
1248 * write and hope for the best.
1250 printk(KERN_ERR "JBD2: previous I/O error detected "
1251 "for journal superblock update for %s.\n",
1252 journal->j_devname);
1253 clear_buffer_write_io_error(bh);
1254 set_buffer_uptodate(bh);
1257 spin_lock(&journal->j_state_lock);
1258 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
1259 journal->j_tail, journal->j_tail_sequence, journal->j_errno);
1261 sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
1262 sb->s_start = cpu_to_be32(journal->j_tail);
1263 sb->s_errno = cpu_to_be32(journal->j_errno);
1264 spin_unlock(&journal->j_state_lock);
1266 BUFFER_TRACE(bh, "marking dirty");
1267 mark_buffer_dirty(bh);
1269 sync_dirty_buffer(bh);
1270 if (buffer_write_io_error(bh)) {
1271 printk(KERN_ERR "JBD2: I/O error detected "
1272 "when updating journal superblock for %s.\n",
1273 journal->j_devname);
1274 clear_buffer_write_io_error(bh);
1275 set_buffer_uptodate(bh);
1278 ll_rw_block(SWRITE, 1, &bh);
1281 /* If we have just flushed the log (by marking s_start==0), then
1282 * any future commit will have to be careful to update the
1283 * superblock again to re-record the true start of the log. */
1285 spin_lock(&journal->j_state_lock);
1287 journal->j_flags &= ~JBD2_FLUSHED;
1289 journal->j_flags |= JBD2_FLUSHED;
1290 spin_unlock(&journal->j_state_lock);
1294 * Read the superblock for a given journal, performing initial
1295 * validation of the format.
1298 static int journal_get_superblock(journal_t *journal)
1300 struct buffer_head *bh;
1301 journal_superblock_t *sb;
1304 bh = journal->j_sb_buffer;
1306 J_ASSERT(bh != NULL);
1307 if (!buffer_uptodate(bh)) {
1308 ll_rw_block(READ, 1, &bh);
1310 if (!buffer_uptodate(bh)) {
1312 "JBD: IO error reading journal superblock\n");
1317 sb = journal->j_superblock;
1321 if (sb->s_header.h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER) ||
1322 sb->s_blocksize != cpu_to_be32(journal->j_blocksize)) {
1323 printk(KERN_WARNING "JBD: no valid journal superblock found\n");
1327 switch(be32_to_cpu(sb->s_header.h_blocktype)) {
1328 case JBD2_SUPERBLOCK_V1:
1329 journal->j_format_version = 1;
1331 case JBD2_SUPERBLOCK_V2:
1332 journal->j_format_version = 2;
1335 printk(KERN_WARNING "JBD: unrecognised superblock format ID\n");
1339 if (be32_to_cpu(sb->s_maxlen) < journal->j_maxlen)
1340 journal->j_maxlen = be32_to_cpu(sb->s_maxlen);
1341 else if (be32_to_cpu(sb->s_maxlen) > journal->j_maxlen) {
1342 printk (KERN_WARNING "JBD: journal file too short\n");
1349 journal_fail_superblock(journal);
1354 * Load the on-disk journal superblock and read the key fields into the
1358 static int load_superblock(journal_t *journal)
1361 journal_superblock_t *sb;
1363 err = journal_get_superblock(journal);
1367 sb = journal->j_superblock;
1369 journal->j_tail_sequence = be32_to_cpu(sb->s_sequence);
1370 journal->j_tail = be32_to_cpu(sb->s_start);
1371 journal->j_first = be32_to_cpu(sb->s_first);
1372 journal->j_last = be32_to_cpu(sb->s_maxlen);
1373 journal->j_errno = be32_to_cpu(sb->s_errno);
1380 * int jbd2_journal_load() - Read journal from disk.
1381 * @journal: Journal to act on.
1383 * Given a journal_t structure which tells us which disk blocks contain
1384 * a journal, read the journal from disk to initialise the in-memory
1387 int jbd2_journal_load(journal_t *journal)
1390 journal_superblock_t *sb;
1392 err = load_superblock(journal);
1396 sb = journal->j_superblock;
1397 /* If this is a V2 superblock, then we have to check the
1398 * features flags on it. */
1400 if (journal->j_format_version >= 2) {
1401 if ((sb->s_feature_ro_compat &
1402 ~cpu_to_be32(JBD2_KNOWN_ROCOMPAT_FEATURES)) ||
1403 (sb->s_feature_incompat &
1404 ~cpu_to_be32(JBD2_KNOWN_INCOMPAT_FEATURES))) {
1405 printk (KERN_WARNING
1406 "JBD: Unrecognised features on journal\n");
1411 /* Let the recovery code check whether it needs to recover any
1412 * data from the journal. */
1413 if (jbd2_journal_recover(journal))
1414 goto recovery_error;
1416 /* OK, we've finished with the dynamic journal bits:
1417 * reinitialise the dynamic contents of the superblock in memory
1418 * and reset them on disk. */
1419 if (journal_reset(journal))
1420 goto recovery_error;
1422 journal->j_flags &= ~JBD2_ABORT;
1423 journal->j_flags |= JBD2_LOADED;
1427 printk (KERN_WARNING "JBD: recovery failed\n");
1432 * void jbd2_journal_destroy() - Release a journal_t structure.
1433 * @journal: Journal to act on.
1435 * Release a journal_t structure once it is no longer in use by the
1437 * Return <0 if we couldn't clean up the journal.
1439 int jbd2_journal_destroy(journal_t *journal)
1443 /* Wait for the commit thread to wake up and die. */
1444 journal_kill_thread(journal);
1446 /* Force a final log commit */
1447 if (journal->j_running_transaction)
1448 jbd2_journal_commit_transaction(journal);
1450 /* Force any old transactions to disk */
1452 /* Totally anal locking here... */
1453 spin_lock(&journal->j_list_lock);
1454 while (journal->j_checkpoint_transactions != NULL) {
1455 spin_unlock(&journal->j_list_lock);
1456 mutex_lock(&journal->j_checkpoint_mutex);
1457 jbd2_log_do_checkpoint(journal);
1458 mutex_unlock(&journal->j_checkpoint_mutex);
1459 spin_lock(&journal->j_list_lock);
1462 J_ASSERT(journal->j_running_transaction == NULL);
1463 J_ASSERT(journal->j_committing_transaction == NULL);
1464 J_ASSERT(journal->j_checkpoint_transactions == NULL);
1465 spin_unlock(&journal->j_list_lock);
1467 if (journal->j_sb_buffer) {
1468 if (!is_journal_aborted(journal)) {
1469 /* We can now mark the journal as empty. */
1470 journal->j_tail = 0;
1471 journal->j_tail_sequence =
1472 ++journal->j_transaction_sequence;
1473 jbd2_journal_update_superblock(journal, 1);
1477 brelse(journal->j_sb_buffer);
1480 if (journal->j_proc_entry)
1481 jbd2_stats_proc_exit(journal);
1482 if (journal->j_inode)
1483 iput(journal->j_inode);
1484 if (journal->j_revoke)
1485 jbd2_journal_destroy_revoke(journal);
1486 kfree(journal->j_wbuf);
1494 *int jbd2_journal_check_used_features () - Check if features specified are used.
1495 * @journal: Journal to check.
1496 * @compat: bitmask of compatible features
1497 * @ro: bitmask of features that force read-only mount
1498 * @incompat: bitmask of incompatible features
1500 * Check whether the journal uses all of a given set of
1501 * features. Return true (non-zero) if it does.
1504 int jbd2_journal_check_used_features (journal_t *journal, unsigned long compat,
1505 unsigned long ro, unsigned long incompat)
1507 journal_superblock_t *sb;
1509 if (!compat && !ro && !incompat)
1511 if (journal->j_format_version == 1)
1514 sb = journal->j_superblock;
1516 if (((be32_to_cpu(sb->s_feature_compat) & compat) == compat) &&
1517 ((be32_to_cpu(sb->s_feature_ro_compat) & ro) == ro) &&
1518 ((be32_to_cpu(sb->s_feature_incompat) & incompat) == incompat))
1525 * int jbd2_journal_check_available_features() - Check feature set in journalling layer
1526 * @journal: Journal to check.
1527 * @compat: bitmask of compatible features
1528 * @ro: bitmask of features that force read-only mount
1529 * @incompat: bitmask of incompatible features
1531 * Check whether the journaling code supports the use of
1532 * all of a given set of features on this journal. Return true
1533 * (non-zero) if it can. */
1535 int jbd2_journal_check_available_features (journal_t *journal, unsigned long compat,
1536 unsigned long ro, unsigned long incompat)
1538 journal_superblock_t *sb;
1540 if (!compat && !ro && !incompat)
1543 sb = journal->j_superblock;
1545 /* We can support any known requested features iff the
1546 * superblock is in version 2. Otherwise we fail to support any
1547 * extended sb features. */
1549 if (journal->j_format_version != 2)
1552 if ((compat & JBD2_KNOWN_COMPAT_FEATURES) == compat &&
1553 (ro & JBD2_KNOWN_ROCOMPAT_FEATURES) == ro &&
1554 (incompat & JBD2_KNOWN_INCOMPAT_FEATURES) == incompat)
1561 * int jbd2_journal_set_features () - Mark a given journal feature in the superblock
1562 * @journal: Journal to act on.
1563 * @compat: bitmask of compatible features
1564 * @ro: bitmask of features that force read-only mount
1565 * @incompat: bitmask of incompatible features
1567 * Mark a given journal feature as present on the
1568 * superblock. Returns true if the requested features could be set.
1572 int jbd2_journal_set_features (journal_t *journal, unsigned long compat,
1573 unsigned long ro, unsigned long incompat)
1575 journal_superblock_t *sb;
1577 if (jbd2_journal_check_used_features(journal, compat, ro, incompat))
1580 if (!jbd2_journal_check_available_features(journal, compat, ro, incompat))
1583 jbd_debug(1, "Setting new features 0x%lx/0x%lx/0x%lx\n",
1584 compat, ro, incompat);
1586 sb = journal->j_superblock;
1588 sb->s_feature_compat |= cpu_to_be32(compat);
1589 sb->s_feature_ro_compat |= cpu_to_be32(ro);
1590 sb->s_feature_incompat |= cpu_to_be32(incompat);
1596 * jbd2_journal_clear_features () - Clear a given journal feature in the
1598 * @journal: Journal to act on.
1599 * @compat: bitmask of compatible features
1600 * @ro: bitmask of features that force read-only mount
1601 * @incompat: bitmask of incompatible features
1603 * Clear a given journal feature as present on the
1606 void jbd2_journal_clear_features(journal_t *journal, unsigned long compat,
1607 unsigned long ro, unsigned long incompat)
1609 journal_superblock_t *sb;
1611 jbd_debug(1, "Clear features 0x%lx/0x%lx/0x%lx\n",
1612 compat, ro, incompat);
1614 sb = journal->j_superblock;
1616 sb->s_feature_compat &= ~cpu_to_be32(compat);
1617 sb->s_feature_ro_compat &= ~cpu_to_be32(ro);
1618 sb->s_feature_incompat &= ~cpu_to_be32(incompat);
1620 EXPORT_SYMBOL(jbd2_journal_clear_features);
1623 * int jbd2_journal_update_format () - Update on-disk journal structure.
1624 * @journal: Journal to act on.
1626 * Given an initialised but unloaded journal struct, poke about in the
1627 * on-disk structure to update it to the most recent supported version.
1629 int jbd2_journal_update_format (journal_t *journal)
1631 journal_superblock_t *sb;
1634 err = journal_get_superblock(journal);
1638 sb = journal->j_superblock;
1640 switch (be32_to_cpu(sb->s_header.h_blocktype)) {
1641 case JBD2_SUPERBLOCK_V2:
1643 case JBD2_SUPERBLOCK_V1:
1644 return journal_convert_superblock_v1(journal, sb);
1651 static int journal_convert_superblock_v1(journal_t *journal,
1652 journal_superblock_t *sb)
1654 int offset, blocksize;
1655 struct buffer_head *bh;
1658 "JBD: Converting superblock from version 1 to 2.\n");
1660 /* Pre-initialise new fields to zero */
1661 offset = ((char *) &(sb->s_feature_compat)) - ((char *) sb);
1662 blocksize = be32_to_cpu(sb->s_blocksize);
1663 memset(&sb->s_feature_compat, 0, blocksize-offset);
1665 sb->s_nr_users = cpu_to_be32(1);
1666 sb->s_header.h_blocktype = cpu_to_be32(JBD2_SUPERBLOCK_V2);
1667 journal->j_format_version = 2;
1669 bh = journal->j_sb_buffer;
1670 BUFFER_TRACE(bh, "marking dirty");
1671 mark_buffer_dirty(bh);
1672 sync_dirty_buffer(bh);
1678 * int jbd2_journal_flush () - Flush journal
1679 * @journal: Journal to act on.
1681 * Flush all data for a given journal to disk and empty the journal.
1682 * Filesystems can use this when remounting readonly to ensure that
1683 * recovery does not need to happen on remount.
1686 int jbd2_journal_flush(journal_t *journal)
1689 transaction_t *transaction = NULL;
1690 unsigned long old_tail;
1692 spin_lock(&journal->j_state_lock);
1694 /* Force everything buffered to the log... */
1695 if (journal->j_running_transaction) {
1696 transaction = journal->j_running_transaction;
1697 __jbd2_log_start_commit(journal, transaction->t_tid);
1698 } else if (journal->j_committing_transaction)
1699 transaction = journal->j_committing_transaction;
1701 /* Wait for the log commit to complete... */
1703 tid_t tid = transaction->t_tid;
1705 spin_unlock(&journal->j_state_lock);
1706 jbd2_log_wait_commit(journal, tid);
1708 spin_unlock(&journal->j_state_lock);
1711 /* ...and flush everything in the log out to disk. */
1712 spin_lock(&journal->j_list_lock);
1713 while (!err && journal->j_checkpoint_transactions != NULL) {
1714 spin_unlock(&journal->j_list_lock);
1715 mutex_lock(&journal->j_checkpoint_mutex);
1716 err = jbd2_log_do_checkpoint(journal);
1717 mutex_unlock(&journal->j_checkpoint_mutex);
1718 spin_lock(&journal->j_list_lock);
1720 spin_unlock(&journal->j_list_lock);
1722 if (is_journal_aborted(journal))
1725 jbd2_cleanup_journal_tail(journal);
1727 /* Finally, mark the journal as really needing no recovery.
1728 * This sets s_start==0 in the underlying superblock, which is
1729 * the magic code for a fully-recovered superblock. Any future
1730 * commits of data to the journal will restore the current
1732 spin_lock(&journal->j_state_lock);
1733 old_tail = journal->j_tail;
1734 journal->j_tail = 0;
1735 spin_unlock(&journal->j_state_lock);
1736 jbd2_journal_update_superblock(journal, 1);
1737 spin_lock(&journal->j_state_lock);
1738 journal->j_tail = old_tail;
1740 J_ASSERT(!journal->j_running_transaction);
1741 J_ASSERT(!journal->j_committing_transaction);
1742 J_ASSERT(!journal->j_checkpoint_transactions);
1743 J_ASSERT(journal->j_head == journal->j_tail);
1744 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence);
1745 spin_unlock(&journal->j_state_lock);
1750 * int jbd2_journal_wipe() - Wipe journal contents
1751 * @journal: Journal to act on.
1752 * @write: flag (see below)
1754 * Wipe out all of the contents of a journal, safely. This will produce
1755 * a warning if the journal contains any valid recovery information.
1756 * Must be called between journal_init_*() and jbd2_journal_load().
1758 * If 'write' is non-zero, then we wipe out the journal on disk; otherwise
1759 * we merely suppress recovery.
1762 int jbd2_journal_wipe(journal_t *journal, int write)
1764 journal_superblock_t *sb;
1767 J_ASSERT (!(journal->j_flags & JBD2_LOADED));
1769 err = load_superblock(journal);
1773 sb = journal->j_superblock;
1775 if (!journal->j_tail)
1778 printk (KERN_WARNING "JBD: %s recovery information on journal\n",
1779 write ? "Clearing" : "Ignoring");
1781 err = jbd2_journal_skip_recovery(journal);
1783 jbd2_journal_update_superblock(journal, 1);
1790 * Journal abort has very specific semantics, which we describe
1791 * for journal abort.
1793 * Two internal functions, which provide abort to the jbd layer
1798 * Quick version for internal journal use (doesn't lock the journal).
1799 * Aborts hard --- we mark the abort as occurred, but do _nothing_ else,
1800 * and don't attempt to make any other journal updates.
1802 void __jbd2_journal_abort_hard(journal_t *journal)
1804 transaction_t *transaction;
1806 if (journal->j_flags & JBD2_ABORT)
1809 printk(KERN_ERR "Aborting journal on device %s.\n",
1810 journal->j_devname);
1812 spin_lock(&journal->j_state_lock);
1813 journal->j_flags |= JBD2_ABORT;
1814 transaction = journal->j_running_transaction;
1816 __jbd2_log_start_commit(journal, transaction->t_tid);
1817 spin_unlock(&journal->j_state_lock);
1820 /* Soft abort: record the abort error status in the journal superblock,
1821 * but don't do any other IO. */
1822 static void __journal_abort_soft (journal_t *journal, int errno)
1824 if (journal->j_flags & JBD2_ABORT)
1827 if (!journal->j_errno)
1828 journal->j_errno = errno;
1830 __jbd2_journal_abort_hard(journal);
1833 jbd2_journal_update_superblock(journal, 1);
1837 * void jbd2_journal_abort () - Shutdown the journal immediately.
1838 * @journal: the journal to shutdown.
1839 * @errno: an error number to record in the journal indicating
1840 * the reason for the shutdown.
1842 * Perform a complete, immediate shutdown of the ENTIRE
1843 * journal (not of a single transaction). This operation cannot be
1844 * undone without closing and reopening the journal.
1846 * The jbd2_journal_abort function is intended to support higher level error
1847 * recovery mechanisms such as the ext2/ext3 remount-readonly error
1850 * Journal abort has very specific semantics. Any existing dirty,
1851 * unjournaled buffers in the main filesystem will still be written to
1852 * disk by bdflush, but the journaling mechanism will be suspended
1853 * immediately and no further transaction commits will be honoured.
1855 * Any dirty, journaled buffers will be written back to disk without
1856 * hitting the journal. Atomicity cannot be guaranteed on an aborted
1857 * filesystem, but we _do_ attempt to leave as much data as possible
1858 * behind for fsck to use for cleanup.
1860 * Any attempt to get a new transaction handle on a journal which is in
1861 * ABORT state will just result in an -EROFS error return. A
1862 * jbd2_journal_stop on an existing handle will return -EIO if we have
1863 * entered abort state during the update.
1865 * Recursive transactions are not disturbed by journal abort until the
1866 * final jbd2_journal_stop, which will receive the -EIO error.
1868 * Finally, the jbd2_journal_abort call allows the caller to supply an errno
1869 * which will be recorded (if possible) in the journal superblock. This
1870 * allows a client to record failure conditions in the middle of a
1871 * transaction without having to complete the transaction to record the
1872 * failure to disk. ext3_error, for example, now uses this
1875 * Errors which originate from within the journaling layer will NOT
1876 * supply an errno; a null errno implies that absolutely no further
1877 * writes are done to the journal (unless there are any already in
1882 void jbd2_journal_abort(journal_t *journal, int errno)
1884 __journal_abort_soft(journal, errno);
1888 * int jbd2_journal_errno () - returns the journal's error state.
1889 * @journal: journal to examine.
1891 * This is the errno number set with jbd2_journal_abort(), the last
1892 * time the journal was mounted - if the journal was stopped
1893 * without calling abort this will be 0.
1895 * If the journal has been aborted on this mount time -EROFS will
1898 int jbd2_journal_errno(journal_t *journal)
1902 spin_lock(&journal->j_state_lock);
1903 if (journal->j_flags & JBD2_ABORT)
1906 err = journal->j_errno;
1907 spin_unlock(&journal->j_state_lock);
1912 * int jbd2_journal_clear_err () - clears the journal's error state
1913 * @journal: journal to act on.
1915 * An error must be cleared or acked to take a FS out of readonly
1918 int jbd2_journal_clear_err(journal_t *journal)
1922 spin_lock(&journal->j_state_lock);
1923 if (journal->j_flags & JBD2_ABORT)
1926 journal->j_errno = 0;
1927 spin_unlock(&journal->j_state_lock);
1932 * void jbd2_journal_ack_err() - Ack journal err.
1933 * @journal: journal to act on.
1935 * An error must be cleared or acked to take a FS out of readonly
1938 void jbd2_journal_ack_err(journal_t *journal)
1940 spin_lock(&journal->j_state_lock);
1941 if (journal->j_errno)
1942 journal->j_flags |= JBD2_ACK_ERR;
1943 spin_unlock(&journal->j_state_lock);
1946 int jbd2_journal_blocks_per_page(struct inode *inode)
1948 return 1 << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
1952 * helper functions to deal with 32 or 64bit block numbers.
1954 size_t journal_tag_bytes(journal_t *journal)
1956 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
1957 return JBD2_TAG_SIZE64;
1959 return JBD2_TAG_SIZE32;
1963 * Journal_head storage management
1965 static struct kmem_cache *jbd2_journal_head_cache;
1966 #ifdef CONFIG_JBD2_DEBUG
1967 static atomic_t nr_journal_heads = ATOMIC_INIT(0);
1970 static int journal_init_jbd2_journal_head_cache(void)
1974 J_ASSERT(jbd2_journal_head_cache == NULL);
1975 jbd2_journal_head_cache = kmem_cache_create("jbd2_journal_head",
1976 sizeof(struct journal_head),
1978 SLAB_TEMPORARY, /* flags */
1981 if (!jbd2_journal_head_cache) {
1983 printk(KERN_EMERG "JBD: no memory for journal_head cache\n");
1988 static void jbd2_journal_destroy_jbd2_journal_head_cache(void)
1990 if (jbd2_journal_head_cache) {
1991 kmem_cache_destroy(jbd2_journal_head_cache);
1992 jbd2_journal_head_cache = NULL;
1997 * journal_head splicing and dicing
1999 static struct journal_head *journal_alloc_journal_head(void)
2001 struct journal_head *ret;
2002 static unsigned long last_warning;
2004 #ifdef CONFIG_JBD2_DEBUG
2005 atomic_inc(&nr_journal_heads);
2007 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
2009 jbd_debug(1, "out of memory for journal_head\n");
2010 if (time_after(jiffies, last_warning + 5*HZ)) {
2011 printk(KERN_NOTICE "ENOMEM in %s, retrying.\n",
2013 last_warning = jiffies;
2017 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
2023 static void journal_free_journal_head(struct journal_head *jh)
2025 #ifdef CONFIG_JBD2_DEBUG
2026 atomic_dec(&nr_journal_heads);
2027 memset(jh, JBD2_POISON_FREE, sizeof(*jh));
2029 kmem_cache_free(jbd2_journal_head_cache, jh);
2033 * A journal_head is attached to a buffer_head whenever JBD has an
2034 * interest in the buffer.
2036 * Whenever a buffer has an attached journal_head, its ->b_state:BH_JBD bit
2037 * is set. This bit is tested in core kernel code where we need to take
2038 * JBD-specific actions. Testing the zeroness of ->b_private is not reliable
2041 * When a buffer has its BH_JBD bit set, its ->b_count is elevated by one.
2043 * When a buffer has its BH_JBD bit set it is immune from being released by
2044 * core kernel code, mainly via ->b_count.
2046 * A journal_head may be detached from its buffer_head when the journal_head's
2047 * b_transaction, b_cp_transaction and b_next_transaction pointers are NULL.
2048 * Various places in JBD call jbd2_journal_remove_journal_head() to indicate that the
2049 * journal_head can be dropped if needed.
2051 * Various places in the kernel want to attach a journal_head to a buffer_head
2052 * _before_ attaching the journal_head to a transaction. To protect the
2053 * journal_head in this situation, jbd2_journal_add_journal_head elevates the
2054 * journal_head's b_jcount refcount by one. The caller must call
2055 * jbd2_journal_put_journal_head() to undo this.
2057 * So the typical usage would be:
2059 * (Attach a journal_head if needed. Increments b_jcount)
2060 * struct journal_head *jh = jbd2_journal_add_journal_head(bh);
2062 * jh->b_transaction = xxx;
2063 * jbd2_journal_put_journal_head(jh);
2065 * Now, the journal_head's b_jcount is zero, but it is safe from being released
2066 * because it has a non-zero b_transaction.
2070 * Give a buffer_head a journal_head.
2072 * Doesn't need the journal lock.
2075 struct journal_head *jbd2_journal_add_journal_head(struct buffer_head *bh)
2077 struct journal_head *jh;
2078 struct journal_head *new_jh = NULL;
2081 if (!buffer_jbd(bh)) {
2082 new_jh = journal_alloc_journal_head();
2083 memset(new_jh, 0, sizeof(*new_jh));
2086 jbd_lock_bh_journal_head(bh);
2087 if (buffer_jbd(bh)) {
2091 (atomic_read(&bh->b_count) > 0) ||
2092 (bh->b_page && bh->b_page->mapping));
2095 jbd_unlock_bh_journal_head(bh);
2100 new_jh = NULL; /* We consumed it */
2105 BUFFER_TRACE(bh, "added journal_head");
2108 jbd_unlock_bh_journal_head(bh);
2110 journal_free_journal_head(new_jh);
2111 return bh->b_private;
2115 * Grab a ref against this buffer_head's journal_head. If it ended up not
2116 * having a journal_head, return NULL
2118 struct journal_head *jbd2_journal_grab_journal_head(struct buffer_head *bh)
2120 struct journal_head *jh = NULL;
2122 jbd_lock_bh_journal_head(bh);
2123 if (buffer_jbd(bh)) {
2127 jbd_unlock_bh_journal_head(bh);
2131 static void __journal_remove_journal_head(struct buffer_head *bh)
2133 struct journal_head *jh = bh2jh(bh);
2135 J_ASSERT_JH(jh, jh->b_jcount >= 0);
2138 if (jh->b_jcount == 0) {
2139 if (jh->b_transaction == NULL &&
2140 jh->b_next_transaction == NULL &&
2141 jh->b_cp_transaction == NULL) {
2142 J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
2143 J_ASSERT_BH(bh, buffer_jbd(bh));
2144 J_ASSERT_BH(bh, jh2bh(jh) == bh);
2145 BUFFER_TRACE(bh, "remove journal_head");
2146 if (jh->b_frozen_data) {
2147 printk(KERN_WARNING "%s: freeing "
2150 jbd2_free(jh->b_frozen_data, bh->b_size);
2152 if (jh->b_committed_data) {
2153 printk(KERN_WARNING "%s: freeing "
2154 "b_committed_data\n",
2156 jbd2_free(jh->b_committed_data, bh->b_size);
2158 bh->b_private = NULL;
2159 jh->b_bh = NULL; /* debug, really */
2160 clear_buffer_jbd(bh);
2162 journal_free_journal_head(jh);
2164 BUFFER_TRACE(bh, "journal_head was locked");
2170 * jbd2_journal_remove_journal_head(): if the buffer isn't attached to a transaction
2171 * and has a zero b_jcount then remove and release its journal_head. If we did
2172 * see that the buffer is not used by any transaction we also "logically"
2173 * decrement ->b_count.
2175 * We in fact take an additional increment on ->b_count as a convenience,
2176 * because the caller usually wants to do additional things with the bh
2177 * after calling here.
2178 * The caller of jbd2_journal_remove_journal_head() *must* run __brelse(bh) at some
2179 * time. Once the caller has run __brelse(), the buffer is eligible for
2180 * reaping by try_to_free_buffers().
2182 void jbd2_journal_remove_journal_head(struct buffer_head *bh)
2184 jbd_lock_bh_journal_head(bh);
2185 __journal_remove_journal_head(bh);
2186 jbd_unlock_bh_journal_head(bh);
2190 * Drop a reference on the passed journal_head. If it fell to zero then try to
2191 * release the journal_head from the buffer_head.
2193 void jbd2_journal_put_journal_head(struct journal_head *jh)
2195 struct buffer_head *bh = jh2bh(jh);
2197 jbd_lock_bh_journal_head(bh);
2198 J_ASSERT_JH(jh, jh->b_jcount > 0);
2200 if (!jh->b_jcount && !jh->b_transaction) {
2201 __journal_remove_journal_head(bh);
2204 jbd_unlock_bh_journal_head(bh);
2208 * Initialize jbd inode head
2210 void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode)
2212 jinode->i_transaction = NULL;
2213 jinode->i_next_transaction = NULL;
2214 jinode->i_vfs_inode = inode;
2215 jinode->i_flags = 0;
2216 INIT_LIST_HEAD(&jinode->i_list);
2220 * Function to be called before we start removing inode from memory (i.e.,
2221 * clear_inode() is a fine place to be called from). It removes inode from
2222 * transaction's lists.
2224 void jbd2_journal_release_jbd_inode(journal_t *journal,
2225 struct jbd2_inode *jinode)
2232 spin_lock(&journal->j_list_lock);
2233 /* Is commit writing out inode - we have to wait */
2234 if (jinode->i_flags & JI_COMMIT_RUNNING) {
2235 wait_queue_head_t *wq;
2236 DEFINE_WAIT_BIT(wait, &jinode->i_flags, __JI_COMMIT_RUNNING);
2237 wq = bit_waitqueue(&jinode->i_flags, __JI_COMMIT_RUNNING);
2238 prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
2239 spin_unlock(&journal->j_list_lock);
2241 finish_wait(wq, &wait.wait);
2245 /* Do we need to wait for data writeback? */
2246 if (journal->j_committing_transaction == jinode->i_transaction)
2248 if (jinode->i_transaction) {
2249 list_del(&jinode->i_list);
2250 jinode->i_transaction = NULL;
2252 spin_unlock(&journal->j_list_lock);
2258 #ifdef CONFIG_JBD2_DEBUG
2259 u8 jbd2_journal_enable_debug __read_mostly;
2260 EXPORT_SYMBOL(jbd2_journal_enable_debug);
2262 #define JBD2_DEBUG_NAME "jbd2-debug"
2264 static struct dentry *jbd2_debugfs_dir;
2265 static struct dentry *jbd2_debug;
2267 static void __init jbd2_create_debugfs_entry(void)
2269 jbd2_debugfs_dir = debugfs_create_dir("jbd2", NULL);
2270 if (jbd2_debugfs_dir)
2271 jbd2_debug = debugfs_create_u8(JBD2_DEBUG_NAME, S_IRUGO,
2273 &jbd2_journal_enable_debug);
2276 static void __exit jbd2_remove_debugfs_entry(void)
2278 debugfs_remove(jbd2_debug);
2279 debugfs_remove(jbd2_debugfs_dir);
2284 static void __init jbd2_create_debugfs_entry(void)
2288 static void __exit jbd2_remove_debugfs_entry(void)
2294 #ifdef CONFIG_PROC_FS
2296 #define JBD2_STATS_PROC_NAME "fs/jbd2"
2298 static void __init jbd2_create_jbd_stats_proc_entry(void)
2300 proc_jbd2_stats = proc_mkdir(JBD2_STATS_PROC_NAME, NULL);
2303 static void __exit jbd2_remove_jbd_stats_proc_entry(void)
2305 if (proc_jbd2_stats)
2306 remove_proc_entry(JBD2_STATS_PROC_NAME, NULL);
2311 #define jbd2_create_jbd_stats_proc_entry() do {} while (0)
2312 #define jbd2_remove_jbd_stats_proc_entry() do {} while (0)
2316 struct kmem_cache *jbd2_handle_cache;
2318 static int __init journal_init_handle_cache(void)
2320 jbd2_handle_cache = kmem_cache_create("jbd2_journal_handle",
2323 SLAB_TEMPORARY, /* flags */
2325 if (jbd2_handle_cache == NULL) {
2326 printk(KERN_EMERG "JBD: failed to create handle cache\n");
2332 static void jbd2_journal_destroy_handle_cache(void)
2334 if (jbd2_handle_cache)
2335 kmem_cache_destroy(jbd2_handle_cache);
2339 * Module startup and shutdown
2342 static int __init journal_init_caches(void)
2346 ret = jbd2_journal_init_revoke_caches();
2348 ret = journal_init_jbd2_journal_head_cache();
2350 ret = journal_init_handle_cache();
2354 static void jbd2_journal_destroy_caches(void)
2356 jbd2_journal_destroy_revoke_caches();
2357 jbd2_journal_destroy_jbd2_journal_head_cache();
2358 jbd2_journal_destroy_handle_cache();
2361 static int __init journal_init(void)
2365 BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);
2367 ret = journal_init_caches();
2369 jbd2_create_debugfs_entry();
2370 jbd2_create_jbd_stats_proc_entry();
2372 jbd2_journal_destroy_caches();
2377 static void __exit journal_exit(void)
2379 #ifdef CONFIG_JBD2_DEBUG
2380 int n = atomic_read(&nr_journal_heads);
2382 printk(KERN_EMERG "JBD: leaked %d journal_heads!\n", n);
2384 jbd2_remove_debugfs_entry();
2385 jbd2_remove_jbd_stats_proc_entry();
2386 jbd2_journal_destroy_caches();
2390 * jbd2_dev_to_name is a utility function used by the jbd2 and ext4
2391 * tracing infrastructure to map a dev_t to a device name.
2393 * The caller should use rcu_read_lock() in order to make sure the
2394 * device name stays valid until its done with it. We use
2395 * rcu_read_lock() as well to make sure we're safe in case the caller
2396 * gets sloppy, and because rcu_read_lock() is cheap and can be safely
2399 struct devname_cache {
2400 struct rcu_head rcu;
2402 char devname[BDEVNAME_SIZE];
2404 #define CACHE_SIZE_BITS 6
2405 static struct devname_cache *devcache[1 << CACHE_SIZE_BITS];
2406 static DEFINE_SPINLOCK(devname_cache_lock);
2408 static void free_devcache(struct rcu_head *rcu)
2413 const char *jbd2_dev_to_name(dev_t device)
2415 int i = hash_32(device, CACHE_SIZE_BITS);
2417 struct block_device *bd;
2418 static struct devname_cache *new_dev;
2421 if (devcache[i] && devcache[i]->device == device) {
2422 ret = devcache[i]->devname;
2428 new_dev = kmalloc(sizeof(struct devname_cache), GFP_KERNEL);
2430 return "NODEV-ALLOCFAILURE"; /* Something non-NULL */
2431 spin_lock(&devname_cache_lock);
2433 if (devcache[i]->device == device) {
2435 ret = devcache[i]->devname;
2436 spin_unlock(&devname_cache_lock);
2439 call_rcu(&devcache[i]->rcu, free_devcache);
2441 devcache[i] = new_dev;
2442 devcache[i]->device = device;
2445 bdevname(bd, devcache[i]->devname);
2448 __bdevname(device, devcache[i]->devname);
2449 ret = devcache[i]->devname;
2450 spin_unlock(&devname_cache_lock);
2453 EXPORT_SYMBOL(jbd2_dev_to_name);
2455 MODULE_LICENSE("GPL");
2456 module_init(journal_init);
2457 module_exit(journal_exit);