2 * linux/include/linux/jbd.h
4 * Written by Stephen C. Tweedie <sct@redhat.com>
6 * Copyright 1998-2000 Red Hat, Inc --- 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 * Definitions for transaction data structures for the buffer cache
13 * filesystem journaling support.
19 #if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || !defined(__KERNEL__)
21 /* Allow this file to be included directly into e2fsprogs */
23 #include "jfs_compat.h"
25 #define jfs_debug jbd_debug
28 #include <linux/buffer_head.h>
29 #include <linux/journal-head.h>
30 #include <linux/stddef.h>
31 #include <asm/semaphore.h>
34 #define journal_oom_retry 1
37 * Define JBD_PARANIOD_IOFAIL to cause a kernel BUG() if ext3 finds
38 * certain classes of error which can occur due to failed IOs. Under
39 * normal use we want ext3 to continue after such errors, because
40 * hardware _can_ fail, but for debugging purposes when running tests on
41 * known-good hardware we may want to trap these errors.
43 #undef JBD_PARANOID_IOFAIL
45 #ifdef CONFIG_JBD_DEBUG
47 * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
48 * consistency checks. By default we don't do this unless
49 * CONFIG_JBD_DEBUG is on.
51 #define JBD_EXPENSIVE_CHECKING
52 extern int journal_enable_debug;
54 #define jbd_debug(n, f, a...) \
56 if ((n) <= journal_enable_debug) { \
57 printk (KERN_DEBUG "(%s, %d): %s: ", \
58 __FILE__, __LINE__, __FUNCTION__); \
63 #define jbd_debug(f, a...) /**/
66 extern void * __jbd_kmalloc (const char *where, size_t size, int flags, int retry);
67 #define jbd_kmalloc(size, flags) \
68 __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
69 #define jbd_rep_kmalloc(size, flags) \
70 __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)
72 #define JFS_MIN_JOURNAL_BLOCKS 1024
77 * typedef handle_t - The handle_t type represents a single atomic update being performed by some process.
79 * All filesystem modifications made by the process go
80 * through this handle. Recursive operations (such as quota operations)
81 * are gathered into a single update.
83 * The buffer credits field is used to account for journaled buffers
84 * being modified by the running process. To ensure that there is
85 * enough log space for all outstanding operations, we need to limit the
86 * number of outstanding buffers possible at any time. When the
87 * operation completes, any buffer credits not used are credited back to
88 * the transaction, so that at all times we know how many buffers the
89 * outstanding updates on a transaction might possibly touch.
91 * This is an opaque datatype.
93 typedef struct handle_s handle_t; /* Atomic operation type */
97 * typedef journal_t - The journal_t maintains all of the journaling state information for a single filesystem.
99 * journal_t is linked to from the fs superblock structure.
101 * We use the journal_t to keep track of all outstanding transaction
102 * activity on the filesystem, and to manage the state of the log
105 * This is an opaque datatype.
107 typedef struct journal_s journal_t; /* Journal control structure */
111 * Internal structures used by the logging mechanism:
114 #define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
121 * Descriptor block types:
124 #define JFS_DESCRIPTOR_BLOCK 1
125 #define JFS_COMMIT_BLOCK 2
126 #define JFS_SUPERBLOCK_V1 3
127 #define JFS_SUPERBLOCK_V2 4
128 #define JFS_REVOKE_BLOCK 5
131 * Standard header for all descriptor blocks:
133 typedef struct journal_header_s
142 * The block tag: used to describe a single buffer in the journal
144 typedef struct journal_block_tag_s
146 __u32 t_blocknr; /* The on-disk block number */
147 __u32 t_flags; /* See below */
148 } journal_block_tag_t;
151 * The revoke descriptor: used on disk to describe a series of blocks to
152 * be revoked from the log
154 typedef struct journal_revoke_header_s
156 journal_header_t r_header;
157 int r_count; /* Count of bytes used in the block */
158 } journal_revoke_header_t;
161 /* Definitions for the journal tag flags word: */
162 #define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */
163 #define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */
164 #define JFS_FLAG_DELETED 4 /* block deleted by this transaction */
165 #define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
169 * The journal superblock. All fields are in big-endian byte order.
171 typedef struct journal_superblock_s
174 journal_header_t s_header;
177 /* Static information describing the journal */
178 __u32 s_blocksize; /* journal device blocksize */
179 __u32 s_maxlen; /* total blocks in journal file */
180 __u32 s_first; /* first block of log information */
183 /* Dynamic information describing the current state of the log */
184 __u32 s_sequence; /* first commit ID expected in log */
185 __u32 s_start; /* blocknr of start of log */
188 /* Error value, as set by journal_abort(). */
192 /* Remaining fields are only valid in a version-2 superblock */
193 __u32 s_feature_compat; /* compatible feature set */
194 __u32 s_feature_incompat; /* incompatible feature set */
195 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
197 __u8 s_uuid[16]; /* 128-bit uuid for journal */
200 __u32 s_nr_users; /* Nr of filesystems sharing log */
202 __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
205 __u32 s_max_transaction; /* Limit of journal blocks per trans.*/
206 __u32 s_max_trans_data; /* Limit of data blocks per trans. */
212 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
214 } journal_superblock_t;
216 #define JFS_HAS_COMPAT_FEATURE(j,mask) \
217 ((j)->j_format_version >= 2 && \
218 ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
219 #define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \
220 ((j)->j_format_version >= 2 && \
221 ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
222 #define JFS_HAS_INCOMPAT_FEATURE(j,mask) \
223 ((j)->j_format_version >= 2 && \
224 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
226 #define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001
228 /* Features known to this kernel version: */
229 #define JFS_KNOWN_COMPAT_FEATURES 0
230 #define JFS_KNOWN_ROCOMPAT_FEATURES 0
231 #define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE
235 #include <linux/fs.h>
236 #include <linux/sched.h>
239 #define JBD_ASSERTIONS
240 #ifdef JBD_ASSERTIONS
241 #define J_ASSERT(assert) \
245 "Assertion failure in %s() at %s:%d: \"%s\"\n", \
246 __FUNCTION__, __FILE__, __LINE__, # assert); \
251 #if defined(CONFIG_BUFFER_DEBUG)
252 void buffer_assertion_failure(struct buffer_head *bh);
253 #define J_ASSERT_BH(bh, expr) \
256 buffer_assertion_failure(bh); \
259 #define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr)
261 #define J_ASSERT_BH(bh, expr) J_ASSERT(expr)
262 #define J_ASSERT_JH(jh, expr) J_ASSERT(expr)
266 #define J_ASSERT(assert) do { } while (0)
267 #endif /* JBD_ASSERTIONS */
269 #if defined(JBD_PARANOID_IOFAIL)
270 #define J_EXPECT(expr, why...) J_ASSERT(expr)
271 #define J_EXPECT_BH(bh, expr, why...) J_ASSERT_BH(bh, expr)
272 #define J_EXPECT_JH(jh, expr, why...) J_ASSERT_JH(jh, expr)
274 #define __journal_expect(expr, why...) \
278 "EXT3-fs unexpected failure: %s;\n",# expr); \
279 printk(KERN_ERR why); \
282 #define J_EXPECT(expr, why...) __journal_expect(expr, ## why)
283 #define J_EXPECT_BH(bh, expr, why...) __journal_expect(expr, ## why)
284 #define J_EXPECT_JH(jh, expr, why...) __journal_expect(expr, ## why)
287 enum jbd_state_bits {
288 BH_JBD /* Has an attached ext3 journal_head */
290 BH_JWrite, /* Being written to log (@@@ DEBUGGING) */
291 BH_Freed, /* Has been freed (truncated) */
292 BH_Revoked, /* Has been revoked from the log */
293 BH_RevokeValid, /* Revoked flag is valid */
294 BH_JBDDirty, /* Is dirty but journaled */
298 BUFFER_FNS(JBDDirty, jbddirty)
299 TAS_BUFFER_FNS(JBDDirty, jbddirty)
300 BUFFER_FNS(Freed, freed)
302 static inline struct buffer_head *jh2bh(struct journal_head *jh)
307 static inline struct journal_head *bh2jh(struct buffer_head *bh)
309 return bh->b_private;
312 #define HAVE_JOURNAL_CALLBACK_STATUS
314 * struct journal_callback - Base structure for callback information.
315 * @jcb_list: list information for other callbacks attached to the same handle.
316 * @jcb_func: Function to call with this callback structure.
318 * This struct is a 'seed' structure for a using with your own callback
319 * structs. If you are using callbacks you must allocate one of these
320 * or another struct of your own definition which has this struct
321 * as it's first element and pass it to journal_callback_set().
323 * This is used internally by jbd to maintain callback information.
325 * See journal_callback_set for more information.
327 struct journal_callback {
328 struct list_head jcb_list;
329 void (*jcb_func)(struct journal_callback *jcb, int error);
330 /* user data goes here */
333 struct jbd_revoke_table_s;
336 * struct handle_s - The handle_s type is the concrete type associated with handle_t.
337 * @h_transaction: Which compound transaction is this update a part of?
338 * @h_buffer_credits: Number of remaining buffers we are allowed to dirty.
339 * @h_ref: Reference count on this handle
340 * @h_jcb: List of application registered callbacks for this handle.
341 * @h_err: Field for caller's use to track errors through large fs operations
342 * @h_sync: flag for sync-on-close
343 * @h_jdata: flag to force data journaling
344 * @h_aborted: flag indicating fatal error on handle
347 /* Docbook can't yet cope with the bit fields, but will leave the documentation
348 * in so it can be fixed later.
353 /* Which compound transaction is this update a part of? */
354 transaction_t * h_transaction;
356 /* Number of remaining buffers we are allowed to dirty: */
357 int h_buffer_credits;
359 /* Reference count on this handle */
362 /* Field for caller's use to track errors through large fs */
366 /* List of application registered callbacks for this handle.
367 * The function(s) will be called after the transaction that
368 * this handle is part of has been committed to disk.
370 struct list_head h_jcb;
373 unsigned int h_sync: 1; /* sync-on-close */
374 unsigned int h_jdata: 1; /* force data journaling */
375 unsigned int h_aborted: 1; /* fatal error on handle */
379 /* The transaction_t type is the guts of the journaling mechanism. It
380 * tracks a compound transaction through its various states:
382 * RUNNING: accepting new updates
383 * LOCKED: Updates still running but we don't accept new ones
384 * RUNDOWN: Updates are tidying up but have finished requesting
385 * new buffers to modify (state not used for now)
386 * FLUSH: All updates complete, but we are still writing to disk
387 * COMMIT: All data on disk, writing commit record
388 * FINISHED: We still have to keep the transaction for checkpointing.
390 * The transaction keeps track of all of the buffers modified by a
391 * running transaction, and all of the buffers committed but not yet
392 * flushed to home for finished transactions.
397 /* Pointer to the journal for this transaction. */
398 journal_t * t_journal;
400 /* Sequence number for this transaction */
403 /* Transaction's current state */
413 /* Where in the log does this transaction's commit start? */
414 unsigned long t_log_start;
416 /* Doubly-linked circular list of all inodes owned by this
417 transaction */ /* AKPM: unused */
418 struct inode * t_ilist;
420 /* Number of buffers on the t_buffers list */
423 /* Doubly-linked circular list of all buffers reserved but not
424 yet modified by this transaction */
425 struct journal_head * t_reserved_list;
427 /* Doubly-linked circular list of all metadata buffers owned by this
429 struct journal_head * t_buffers;
432 * Doubly-linked circular list of all data buffers still to be
433 * flushed before this transaction can be committed.
434 * Protected by journal_datalist_lock.
436 struct journal_head * t_sync_datalist;
438 /* Doubly-linked circular list of all forget buffers (superseded
439 buffers which we can un-checkpoint once this transaction
441 struct journal_head * t_forget;
444 * Doubly-linked circular list of all buffers still to be
445 * flushed before this transaction can be checkpointed.
447 /* Protected by journal_datalist_lock */
448 struct journal_head * t_checkpoint_list;
450 /* Doubly-linked circular list of temporary buffers currently
451 undergoing IO in the log */
452 struct journal_head * t_iobuf_list;
454 /* Doubly-linked circular list of metadata buffers being
455 shadowed by log IO. The IO buffers on the iobuf list and the
456 shadow buffers on this list match each other one for one at
458 struct journal_head * t_shadow_list;
460 /* Doubly-linked circular list of control buffers being written
462 struct journal_head * t_log_list;
464 /* Number of outstanding updates running on this transaction */
467 /* Number of buffers reserved for use by all handles in this
468 * transaction handle but not yet modified. */
469 int t_outstanding_credits;
472 * Forward and backward links for the circular list of all
473 * transactions awaiting checkpoint.
475 /* Protected by journal_datalist_lock */
476 transaction_t *t_cpnext, *t_cpprev;
478 /* When will the transaction expire (become due for commit), in
480 unsigned long t_expires;
482 /* How many handles used this transaction? */
485 /* List of registered callback functions for this transaction.
486 * Called when the transaction is committed. */
487 struct list_head t_jcb;
491 * struct journal_s - The journal_s type is the concrete type associated with journal_t.
492 * @j_flags: General journaling state flags
493 * @j_errno: Is there an outstanding uncleared error on the journal (from a prior abort)?
494 * @j_sb_buffer: First part of superblock buffer
495 * @j_superblock: Second part of superblock buffer
496 * @j_format_version: Version of the superblock format
497 * @j_barrier_count: Number of processes waiting to create a barrier lock
498 * @j_barrier: The barrier lock itself
499 * @j_running_transaction: The current running transaction..
500 * @j_committing_transaction: the transaction we are pushing to disk
501 * @j_checkpoint_transactions: a linked circular list of all transactions waiting for checkpointing
502 * @j_wait_transaction_locked: Wait queue for waiting for a locked transaction to start committing, or for a barrier lock to be released
503 * @j_wait_logspace: Wait queue for waiting for checkpointing to complete
504 * @j_wait_done_commit: Wait queue for waiting for commit to complete
505 * @j_wait_checkpoint: Wait queue to trigger checkpointing
506 * @j_wait_commit: Wait queue to trigger commit
507 * @j_wait_updates: Wait queue to wait for updates to complete
508 * @j_checkpoint_sem: Semaphore for locking against concurrent checkpoints
509 * @j_sem: The main journal lock, used by lock_journal()
510 * @j_head: Journal head - identifies the first unused block in the journal
511 * @j_tail: Journal tail - identifies the oldest still-used block in the journal.
512 * @j_free: Journal free - how many free blocks are there in the journal?
513 * @j_first: The block number of the first usable block
514 * @j_last: The block number one beyond the last usable block
515 * @j_dev: Device where we store the journal
516 * @j_blocksize: blocksize for the location where we store the journal.
517 * @j_blk_offset: starting block offset for into the device where we store the journal
518 * @j_fs_dev: Device which holds the client fs. For internal journal this will be equal to j_dev
519 * @j_maxlen: Total maximum capacity of the journal region on disk.
520 * @j_inode: Optional inode where we store the journal. If present, all journal block numbers are mapped into this inode via bmap().
521 * @j_tail_sequence: Sequence number of the oldest transaction in the log
522 * @j_transaction_sequence: Sequence number of the next transaction to grant
523 * @j_commit_sequence: Sequence number of the most recently committed transaction
524 * @j_commit_request: Sequence number of the most recent transaction wanting commit
525 * @j_uuid: Uuid of client object.
526 * @j_task: Pointer to the current commit thread for this journal
527 * @j_max_transaction_buffers: Maximum number of metadata buffers to allow in a single compound commit transaction
528 * @j_commit_interval: What is the maximum transaction lifetime before we begin a commit?
529 * @j_commit_timer: The timer used to wakeup the commit thread
530 * @j_commit_timer_active: Timer flag
531 * @j_all_journals: Link all journals together - system-wide
532 * @j_revoke: The revoke table - maintains the list of revoked blocks in the current transaction.
537 /* General journaling state flags */
538 unsigned long j_flags;
540 /* Is there an outstanding uncleared error on the journal (from */
541 /* a prior abort)? */
544 /* The superblock buffer */
545 struct buffer_head * j_sb_buffer;
546 journal_superblock_t * j_superblock;
548 /* Version of the superblock format */
549 int j_format_version;
551 /* Number of processes waiting to create a barrier lock */
554 /* The barrier lock itself */
555 struct semaphore j_barrier;
557 /* Transactions: The current running transaction... */
558 transaction_t * j_running_transaction;
560 /* ... the transaction we are pushing to disk ... */
561 transaction_t * j_committing_transaction;
563 /* ... and a linked circular list of all transactions waiting */
564 /* for checkpointing. */
565 /* Protected by journal_datalist_lock */
566 transaction_t * j_checkpoint_transactions;
568 /* Wait queue for waiting for a locked transaction to start */
569 /* committing, or for a barrier lock to be released */
570 wait_queue_head_t j_wait_transaction_locked;
572 /* Wait queue for waiting for checkpointing to complete */
573 wait_queue_head_t j_wait_logspace;
575 /* Wait queue for waiting for commit to complete */
576 wait_queue_head_t j_wait_done_commit;
578 /* Wait queue to trigger checkpointing */
579 wait_queue_head_t j_wait_checkpoint;
581 /* Wait queue to trigger commit */
582 wait_queue_head_t j_wait_commit;
584 /* Wait queue to wait for updates to complete */
585 wait_queue_head_t j_wait_updates;
587 /* Semaphore for locking against concurrent checkpoints */
588 struct semaphore j_checkpoint_sem;
590 /* The main journal lock, used by lock_journal() */
591 struct semaphore j_sem;
593 /* Journal head: identifies the first unused block in the journal. */
594 unsigned long j_head;
596 /* Journal tail: identifies the oldest still-used block in the */
598 unsigned long j_tail;
600 /* Journal free: how many free blocks are there in the journal? */
601 unsigned long j_free;
603 /* Journal start and end: the block numbers of the first usable */
604 /* block and one beyond the last usable block in the journal. */
605 unsigned long j_first, j_last;
607 /* Device, blocksize and starting block offset for the location */
608 /* where we store the journal. */
609 struct block_device * j_dev;
611 unsigned int j_blk_offset;
613 /* Device which holds the client fs. For internal journal this */
614 /* will be equal to j_dev. */
615 struct block_device * j_fs_dev;
617 /* Total maximum capacity of the journal region on disk. */
618 unsigned int j_maxlen;
620 /* Optional inode where we store the journal. If present, all */
621 /* journal block numbers are mapped into this inode via */
623 struct inode * j_inode;
625 /* Sequence number of the oldest transaction in the log */
626 tid_t j_tail_sequence;
627 /* Sequence number of the next transaction to grant */
628 tid_t j_transaction_sequence;
629 /* Sequence number of the most recently committed transaction */
630 tid_t j_commit_sequence;
631 /* Sequence number of the most recent transaction wanting commit */
632 tid_t j_commit_request;
634 /* Journal uuid: identifies the object (filesystem, LVM volume */
635 /* etc) backed by this journal. This will eventually be */
636 /* replaced by an array of uuids, allowing us to index multiple */
637 /* devices within a single journal and to perform atomic updates */
642 /* Pointer to the current commit thread for this journal */
643 struct task_struct * j_task;
645 /* Maximum number of metadata buffers to allow in a single */
646 /* compound commit transaction */
647 int j_max_transaction_buffers;
649 /* What is the maximum transaction lifetime before we begin a */
651 unsigned long j_commit_interval;
653 /* The timer used to wakeup the commit thread: */
654 struct timer_list * j_commit_timer;
655 int j_commit_timer_active;
657 /* Link all journals together - system-wide */
658 struct list_head j_all_journals;
660 /* The revoke table: maintains the list of revoked blocks in the */
661 /* current transaction. */
662 struct jbd_revoke_table_s *j_revoke;
664 /* An opaque pointer to fs-private information. ext3 puts its
665 * superblock pointer here */
670 * Journal flag definitions
672 #define JFS_UNMOUNT 0x001 /* Journal thread is being destroyed */
673 #define JFS_ABORT 0x002 /* Journaling has been aborted for errors. */
674 #define JFS_ACK_ERR 0x004 /* The errno in the sb has been acked */
675 #define JFS_FLUSHED 0x008 /* The journal superblock has been flushed */
676 #define JFS_LOADED 0x010 /* The journal superblock has been loaded */
679 * Function declarations for the journaling transaction and buffer
684 extern void __journal_unfile_buffer(struct journal_head *);
685 extern void journal_unfile_buffer(struct journal_head *);
686 extern void __journal_refile_buffer(struct journal_head *);
687 extern void journal_refile_buffer(struct journal_head *);
688 extern void __journal_file_buffer(struct journal_head *, transaction_t *, int);
689 extern void __journal_free_buffer(struct journal_head *bh);
690 extern void journal_file_buffer(struct journal_head *, transaction_t *, int);
691 extern void __journal_clean_data_list(transaction_t *transaction);
693 /* Log buffer allocation */
694 extern struct journal_head * journal_get_descriptor_buffer(journal_t *);
695 int journal_next_log_block(journal_t *, unsigned long *);
697 /* Commit management */
698 extern void journal_commit_transaction(journal_t *);
700 /* Checkpoint list management */
701 int __journal_clean_checkpoint_list(journal_t *journal);
702 extern void journal_remove_checkpoint(struct journal_head *);
703 extern void __journal_remove_checkpoint(struct journal_head *);
704 extern void journal_insert_checkpoint(struct journal_head *, transaction_t *);
705 extern void __journal_insert_checkpoint(struct journal_head *,transaction_t *);
709 journal_write_metadata_buffer(transaction_t *transaction,
710 struct journal_head *jh_in,
711 struct journal_head **jh_out,
714 /* Transaction locking */
715 extern void __wait_on_journal (journal_t *);
720 * We need to lock the journal during transaction state changes so that
721 * nobody ever tries to take a handle on the running transaction while
722 * we are in the middle of moving it to the commit phase.
724 * Note that the locking is completely interrupt unsafe. We never touch
725 * journal structures from interrupts.
727 * In 2.2, the BKL was required for lock_journal. This is no longer
731 static inline void lock_journal(journal_t *journal)
733 down(&journal->j_sem);
736 /* This returns zero if we acquired the semaphore */
737 static inline int try_lock_journal(journal_t * journal)
739 return down_trylock(&journal->j_sem);
742 static inline void unlock_journal(journal_t * journal)
748 static inline handle_t *journal_current_handle(void)
750 return current->journal_info;
753 /* The journaling code user interface:
755 * Create and destroy handles
756 * Register buffer modifications against the current transaction.
759 extern handle_t *journal_start(journal_t *, int nblocks);
760 extern int journal_restart (handle_t *, int nblocks);
761 extern int journal_extend (handle_t *, int nblocks);
762 extern int journal_get_write_access (handle_t *, struct buffer_head *);
763 extern int journal_get_create_access (handle_t *, struct buffer_head *);
764 extern int journal_get_undo_access (handle_t *, struct buffer_head *);
765 extern int journal_dirty_data (handle_t *, struct buffer_head *);
766 extern int journal_dirty_metadata (handle_t *, struct buffer_head *);
767 extern void journal_release_buffer (handle_t *, struct buffer_head *);
768 extern void journal_forget (handle_t *, struct buffer_head *);
769 extern void journal_sync_buffer (struct buffer_head *);
770 extern int journal_invalidatepage(journal_t *,
771 struct page *, unsigned long);
772 extern int journal_try_to_free_buffers(journal_t *, struct page *, int);
773 extern int journal_stop(handle_t *);
774 extern int journal_flush (journal_t *);
775 extern void journal_callback_set(handle_t *handle,
776 void (*fn)(struct journal_callback *,int),
777 struct journal_callback *jcb);
779 extern void journal_lock_updates (journal_t *);
780 extern void journal_unlock_updates (journal_t *);
782 extern journal_t * journal_init_dev(struct block_device *bdev,
783 struct block_device *fs_dev,
784 int start, int len, int bsize);
785 extern journal_t * journal_init_inode (struct inode *);
786 extern int journal_update_format (journal_t *);
787 extern int journal_check_used_features
788 (journal_t *, unsigned long, unsigned long, unsigned long);
789 extern int journal_check_available_features
790 (journal_t *, unsigned long, unsigned long, unsigned long);
791 extern int journal_set_features
792 (journal_t *, unsigned long, unsigned long, unsigned long);
793 extern int journal_create (journal_t *);
794 extern int journal_load (journal_t *journal);
795 extern void journal_destroy (journal_t *);
796 extern int journal_recover (journal_t *journal);
797 extern int journal_wipe (journal_t *, int);
798 extern int journal_skip_recovery (journal_t *);
799 extern void journal_update_superblock (journal_t *, int);
800 extern void __journal_abort_hard (journal_t *);
801 extern void __journal_abort_soft (journal_t *, int);
802 extern void journal_abort (journal_t *, int);
803 extern int journal_errno (journal_t *);
804 extern void journal_ack_err (journal_t *);
805 extern int journal_clear_err (journal_t *);
806 extern int journal_bmap(journal_t *, unsigned long, unsigned long *);
807 extern int journal_force_commit(journal_t *);
810 * journal_head management
812 extern struct journal_head
813 *journal_add_journal_head(struct buffer_head *bh);
814 extern void journal_remove_journal_head(struct buffer_head *bh);
815 extern void __journal_remove_journal_head(struct buffer_head *bh);
816 extern void journal_unlock_journal_head(struct journal_head *jh);
821 extern kmem_cache_t *jbd_handle_cache;
823 static inline handle_t *jbd_alloc_handle(int gfp_flags)
825 return kmem_cache_alloc(jbd_handle_cache, gfp_flags);
828 static inline void jbd_free_handle(handle_t *handle)
830 kmem_cache_free(jbd_handle_cache, handle);
833 /* Primary revoke support */
834 #define JOURNAL_REVOKE_DEFAULT_HASH 256
835 extern int journal_init_revoke(journal_t *, int);
836 extern void journal_destroy_revoke_caches(void);
837 extern int journal_init_revoke_caches(void);
839 extern void journal_destroy_revoke(journal_t *);
840 extern int journal_revoke (handle_t *,
841 unsigned long, struct buffer_head *);
842 extern int journal_cancel_revoke(handle_t *, struct journal_head *);
843 extern void journal_write_revoke_records(journal_t *, transaction_t *);
845 /* Recovery revoke support */
846 extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
847 extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
848 extern void journal_clear_revoke(journal_t *);
849 extern void journal_brelse_array(struct buffer_head *b[], int n);
851 /* The log thread user interface:
853 * Request space in the current transaction, and force transaction commit
854 * transitions on demand.
857 extern int log_space_left (journal_t *); /* Called with journal locked */
858 extern tid_t log_start_commit (journal_t *, transaction_t *);
859 extern int log_wait_commit (journal_t *, tid_t);
860 extern int log_do_checkpoint (journal_t *, int);
862 extern void log_wait_for_space(journal_t *, int nblocks);
863 extern void __journal_drop_transaction(journal_t *, transaction_t *);
864 extern int cleanup_journal_tail(journal_t *);
866 /* Reduce journal memory usage by flushing */
867 extern void shrink_journal_memory(void);
869 /* Debugging code only: */
871 #define jbd_ENOSYS() \
873 printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \
874 current->state = TASK_UNINTERRUPTIBLE; \
881 * Simple test wrapper function to test the JFS_ABORT state flag. This
882 * bit, when set, indicates that we have had a fatal error somewhere,
883 * either inside the journaling layer or indicated to us by the client
884 * (eg. ext3), and that we and should not commit any further
888 static inline int is_journal_aborted(journal_t *journal)
890 return journal->j_flags & JFS_ABORT;
893 static inline int is_handle_aborted(handle_t *handle)
895 if (handle->h_aborted)
897 return is_journal_aborted(handle->h_transaction->t_journal);
900 static inline void journal_abort_handle(handle_t *handle)
902 handle->h_aborted = 1;
905 #endif /* __KERNEL__ */
907 /* Comparison functions for transaction IDs: perform comparisons using
908 * modulo arithmetic so that they work over sequence number wraps. */
910 static inline int tid_gt(tid_t x, tid_t y)
912 int difference = (x - y);
913 return (difference > 0);
916 static inline int tid_geq(tid_t x, tid_t y)
918 int difference = (x - y);
919 return (difference >= 0);
922 extern int journal_blocks_per_page(struct inode *inode);
925 * Definitions which augment the buffer_head layer
928 /* journaling buffer types */
929 #define BJ_None 0 /* Not journaled */
930 #define BJ_SyncData 1 /* Normal data: flush before commit */
931 #define BJ_Metadata 2 /* Normal journaled metadata */
932 #define BJ_Forget 3 /* Buffer superseded by this transaction */
933 #define BJ_IO 4 /* Buffer is for temporary IO use */
934 #define BJ_Shadow 5 /* Buffer contents being shadowed to the log */
935 #define BJ_LogCtl 6 /* Buffer contains log descriptors */
936 #define BJ_Reserved 7 /* Buffer is reserved for access by journal */
939 extern int jbd_blocks_per_page(struct inode *inode);
943 extern spinlock_t jh_splice_lock;
945 * Once `expr1' has been found true, take jh_splice_lock
946 * and then reevaluate everything.
948 #define SPLICE_LOCK(expr1, expr2) \
952 spin_lock(&jh_splice_lock); \
953 ret = (expr1) && (expr2); \
954 spin_unlock(&jh_splice_lock); \
960 * A number of buffer state predicates. They test for
961 * buffer_jbd() because they are used in core kernel code.
963 * These will be racy on SMP unless we're *sure* that the
964 * buffer won't be detached from the journalling system
968 /* Return true if the buffer is on journal list `list' */
969 static inline int buffer_jlist_eq(struct buffer_head *bh, int list)
971 return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list);
974 /* Return true if this bufer is dirty wrt the journal */
975 static inline int buffer_jdirty(struct buffer_head *bh)
977 return buffer_jbd(bh) && buffer_jbddirty(bh);
980 /* Return true if it's a data buffer which journalling is managing */
981 static inline int buffer_jbd_data(struct buffer_head *bh)
983 return SPLICE_LOCK(buffer_jbd(bh),
984 bh2jh(bh)->b_jlist == BJ_SyncData);
988 #define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock))
990 #define assert_spin_locked(lock) do {} while(0)
993 #define buffer_trace_init(bh) do {} while (0)
994 #define print_buffer_fields(bh) do {} while (0)
995 #define print_buffer_trace(bh) do {} while (0)
996 #define BUFFER_TRACE(bh, info) do {} while (0)
997 #define BUFFER_TRACE2(bh, bh2, info) do {} while (0)
998 #define JBUFFER_TRACE(jh, info) do {} while (0)
1000 #endif /* __KERNEL__ */
1002 #endif /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */
1005 * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD
1009 #if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE))
1011 #define J_ASSERT(expr) do {} while (0)
1012 #define J_ASSERT_BH(bh, expr) do {} while (0)
1013 #define buffer_jbd(bh) 0
1014 #define buffer_jlist_eq(bh, val) 0
1015 #define journal_buffer_journal_lru(bh) 0
1017 #endif /* defined(__KERNEL__) && !defined(CONFIG_JBD) */
1018 #endif /* _LINUX_JBD_H */