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/journal-head.h>
29 #include <linux/stddef.h>
30 #include <asm/semaphore.h>
33 #define journal_oom_retry 1
36 * Define JBD_PARANOID_WRITES to cause a kernel BUG() check if ext3
37 * finds a buffer unexpectedly dirty. This is useful for debugging, but
38 * can cause spurious kernel panics if there are applications such as
39 * tune2fs modifying our buffer_heads behind our backs.
41 #undef JBD_PARANOID_WRITES
43 #ifdef CONFIG_JBD_DEBUG
45 * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
46 * consistency checks. By default we don't do this unless
47 * CONFIG_JBD_DEBUG is on.
49 #define JBD_EXPENSIVE_CHECKING
50 extern int journal_enable_debug;
52 #define jbd_debug(n, f, a...) \
54 if ((n) <= journal_enable_debug) { \
55 printk (KERN_DEBUG "(%s, %d): %s: ", \
56 __FILE__, __LINE__, __FUNCTION__); \
61 #define jbd_debug(f, a...) /**/
64 extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry);
65 #define jbd_kmalloc(size, flags) \
66 __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
67 #define jbd_rep_kmalloc(size, flags) \
68 __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)
70 #define JFS_MIN_JOURNAL_BLOCKS 1024
75 * typedef handle_t - The handle_t type represents a single atomic update being performed by some process.
77 * All filesystem modifications made by the process go
78 * through this handle. Recursive operations (such as quota operations)
79 * are gathered into a single update.
81 * The buffer credits field is used to account for journaled buffers
82 * being modified by the running process. To ensure that there is
83 * enough log space for all outstanding operations, we need to limit the
84 * number of outstanding buffers possible at any time. When the
85 * operation completes, any buffer credits not used are credited back to
86 * the transaction, so that at all times we know how many buffers the
87 * outstanding updates on a transaction might possibly touch.
89 * This is an opaque datatype.
91 typedef struct handle_s handle_t; /* Atomic operation type */
95 * typedef journal_t - The journal_t maintains all of the journaling state information for a single filesystem.
97 * journal_t is linked to from the fs superblock structure.
99 * We use the journal_t to keep track of all outstanding transaction
100 * activity on the filesystem, and to manage the state of the log
103 * This is an opaque datatype.
105 typedef struct journal_s journal_t; /* Journal control structure */
109 * Internal structures used by the logging mechanism:
112 #define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
119 * Descriptor block types:
122 #define JFS_DESCRIPTOR_BLOCK 1
123 #define JFS_COMMIT_BLOCK 2
124 #define JFS_SUPERBLOCK_V1 3
125 #define JFS_SUPERBLOCK_V2 4
126 #define JFS_REVOKE_BLOCK 5
129 * Standard header for all descriptor blocks:
131 typedef struct journal_header_s
140 * The block tag: used to describe a single buffer in the journal
142 typedef struct journal_block_tag_s
144 __u32 t_blocknr; /* The on-disk block number */
145 __u32 t_flags; /* See below */
146 } journal_block_tag_t;
149 * The revoke descriptor: used on disk to describe a series of blocks to
150 * be revoked from the log
152 typedef struct journal_revoke_header_s
154 journal_header_t r_header;
155 int r_count; /* Count of bytes used in the block */
156 } journal_revoke_header_t;
159 /* Definitions for the journal tag flags word: */
160 #define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */
161 #define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */
162 #define JFS_FLAG_DELETED 4 /* block deleted by this transaction */
163 #define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
167 * The journal superblock. All fields are in big-endian byte order.
169 typedef struct journal_superblock_s
172 journal_header_t s_header;
175 /* Static information describing the journal */
176 __u32 s_blocksize; /* journal device blocksize */
177 __u32 s_maxlen; /* total blocks in journal file */
178 __u32 s_first; /* first block of log information */
181 /* Dynamic information describing the current state of the log */
182 __u32 s_sequence; /* first commit ID expected in log */
183 __u32 s_start; /* blocknr of start of log */
186 /* Error value, as set by journal_abort(). */
190 /* Remaining fields are only valid in a version-2 superblock */
191 __u32 s_feature_compat; /* compatible feature set */
192 __u32 s_feature_incompat; /* incompatible feature set */
193 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
195 __u8 s_uuid[16]; /* 128-bit uuid for journal */
198 __u32 s_nr_users; /* Nr of filesystems sharing log */
200 __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
203 __u32 s_max_transaction; /* Limit of journal blocks per trans.*/
204 __u32 s_max_trans_data; /* Limit of data blocks per trans. */
210 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
212 } journal_superblock_t;
214 #define JFS_HAS_COMPAT_FEATURE(j,mask) \
215 ((j)->j_format_version >= 2 && \
216 ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
217 #define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \
218 ((j)->j_format_version >= 2 && \
219 ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
220 #define JFS_HAS_INCOMPAT_FEATURE(j,mask) \
221 ((j)->j_format_version >= 2 && \
222 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
224 #define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001
226 /* Features known to this kernel version: */
227 #define JFS_KNOWN_COMPAT_FEATURES 0
228 #define JFS_KNOWN_ROCOMPAT_FEATURES 0
229 #define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE
233 #include <linux/fs.h>
234 #include <linux/sched.h>
236 #define JBD_ASSERTIONS
237 #ifdef JBD_ASSERTIONS
238 #define J_ASSERT(assert) \
242 "Assertion failure in %s() at %s:%d: \"%s\"\n", \
243 __FUNCTION__, __FILE__, __LINE__, # assert); \
248 #if defined(CONFIG_BUFFER_DEBUG)
249 void buffer_assertion_failure(struct buffer_head *bh);
250 #define J_ASSERT_BH(bh, expr) \
253 buffer_assertion_failure(bh); \
256 #define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr)
258 #define J_ASSERT_BH(bh, expr) J_ASSERT(expr)
259 #define J_ASSERT_JH(jh, expr) J_ASSERT(expr)
263 #define J_ASSERT(assert) do { } while (0)
264 #endif /* JBD_ASSERTIONS */
266 enum jbd_state_bits {
268 = BH_PrivateStart, /* 1 if being written to log (@@@ DEBUGGING) */
269 BH_Freed, /* 1 if buffer has been freed (truncated) */
270 BH_Revoked, /* 1 if buffer has been revoked from the log */
271 BH_RevokeValid, /* 1 if buffer revoked flag is valid */
272 BH_JBDDirty, /* 1 if buffer is dirty but journaled */
275 /* Return true if the buffer is one which JBD is managing */
276 static inline int buffer_jbd(struct buffer_head *bh)
278 return __buffer_state(bh, JBD);
281 static inline struct buffer_head *jh2bh(struct journal_head *jh)
286 static inline struct journal_head *bh2jh(struct buffer_head *bh)
288 return bh->b_private;
291 #define HAVE_JOURNAL_CALLBACK_STATUS
292 struct journal_callback {
293 struct list_head jcb_list;
294 void (*jcb_func)(struct journal_callback *jcb, int error);
295 /* user data goes here */
298 struct jbd_revoke_table_s;
301 * The handle_t type represents a single atomic update being performed
302 * by some process. All filesystem modifications made by the process go
303 * through this handle. Recursive operations (such as quota operations)
304 * are gathered into a single update.
306 * The buffer credits field is used to account for journaled buffers
307 * being modified by the running process. To ensure that there is
308 * enough log space for all outstanding operations, we need to limit the
309 * number of outstanding buffers possible at any time. When the
310 * operation completes, any buffer credits not used are credited back to
311 * the transaction, so that at all times we know how many buffers the
312 * outstanding updates on a transaction might possibly touch.
314 * struct handle_s - The handle_s type is the concrete type associated with handle_t.
315 * @h_transaction: Which compound transaction is this update a part of?
316 * @h_buffer_credits: Number of remaining buffers we are allowed to dirty.
317 * @h_ref: Reference count on this handle
318 * @h_err: Field for caller's use to track errors through large fs operations
319 * @h_sync: flag for sync-on-close
320 * @h_jdata: flag to force data journaling
321 * @h_aborted: flag indicating fatal error on handle
324 /* Docbook can't yet cope with the bit fields, but will leave the documentation
325 * in so it can be fixed later.
330 /* Which compound transaction is this update a part of? */
331 transaction_t * h_transaction;
333 /* Number of remaining buffers we are allowed to dirty: */
334 int h_buffer_credits;
336 /* Reference count on this handle */
339 /* Field for caller's use to track errors through large fs */
343 /* List of application registered callbacks for this handle.
344 * The function(s) will be called after the transaction that
345 * this handle is part of has been committed to disk.
347 struct list_head h_jcb;
350 unsigned int h_sync: 1; /* sync-on-close */
351 unsigned int h_jdata: 1; /* force data journaling */
352 unsigned int h_aborted: 1; /* fatal error on handle */
356 /* The transaction_t type is the guts of the journaling mechanism. It
357 * tracks a compound transaction through its various states:
359 * RUNNING: accepting new updates
360 * LOCKED: Updates still running but we don't accept new ones
361 * RUNDOWN: Updates are tidying up but have finished requesting
362 * new buffers to modify (state not used for now)
363 * FLUSH: All updates complete, but we are still writing to disk
364 * COMMIT: All data on disk, writing commit record
365 * FINISHED: We still have to keep the transaction for checkpointing.
367 * The transaction keeps track of all of the buffers modified by a
368 * running transaction, and all of the buffers committed but not yet
369 * flushed to home for finished transactions.
374 /* Pointer to the journal for this transaction. */
375 journal_t * t_journal;
377 /* Sequence number for this transaction */
380 /* Transaction's current state */
390 /* Where in the log does this transaction's commit start? */
391 unsigned long t_log_start;
393 /* Doubly-linked circular list of all inodes owned by this
394 transaction */ /* AKPM: unused */
395 struct inode * t_ilist;
397 /* Number of buffers on the t_buffers list */
400 /* Doubly-linked circular list of all buffers reserved but not
401 yet modified by this transaction */
402 struct journal_head * t_reserved_list;
404 /* Doubly-linked circular list of all metadata buffers owned by this
406 struct journal_head * t_buffers;
409 * Doubly-linked circular list of all data buffers still to be
410 * flushed before this transaction can be committed.
411 * Protected by journal_datalist_lock.
413 struct journal_head * t_sync_datalist;
416 * Doubly-linked circular list of all writepage data buffers
417 * still to be written before this transaction can be committed.
418 * Protected by journal_datalist_lock.
420 struct journal_head * t_async_datalist;
422 /* Doubly-linked circular list of all forget buffers (superceded
423 buffers which we can un-checkpoint once this transaction
425 struct journal_head * t_forget;
428 * Doubly-linked circular list of all buffers still to be
429 * flushed before this transaction can be checkpointed.
431 /* Protected by journal_datalist_lock */
432 struct journal_head * t_checkpoint_list;
434 /* Doubly-linked circular list of temporary buffers currently
435 undergoing IO in the log */
436 struct journal_head * t_iobuf_list;
438 /* Doubly-linked circular list of metadata buffers being
439 shadowed by log IO. The IO buffers on the iobuf list and the
440 shadow buffers on this list match each other one for one at
442 struct journal_head * t_shadow_list;
444 /* Doubly-linked circular list of control buffers being written
446 struct journal_head * t_log_list;
448 /* Number of outstanding updates running on this transaction */
451 /* Number of buffers reserved for use by all handles in this
452 * transaction handle but not yet modified. */
453 int t_outstanding_credits;
456 * Forward and backward links for the circular list of all
457 * transactions awaiting checkpoint.
459 /* Protected by journal_datalist_lock */
460 transaction_t *t_cpnext, *t_cpprev;
462 /* When will the transaction expire (become due for commit), in
464 unsigned long t_expires;
466 /* How many handles used this transaction? */
469 /* List of registered callback functions for this transaction.
470 * Called when the transaction is committed. */
471 struct list_head t_jcb;
475 * struct journal_s - The journal_s type is the concrete type associated with journal_t.
476 * @j_flags: General journaling state flags
477 * @j_errno: Is there an outstanding uncleared error on the journal (from a prior abort)?
478 * @j_sb_buffer: First part of superblock buffer
479 * @j_superblock: Second part of superblock buffer
480 * @j_format_version: Version of the superblock format
481 * @j_barrier_count: Number of processes waiting to create a barrier lock
482 * @j_barrier: The barrier lock itself
483 * @j_running_transaction: The current running transaction..
484 * @j_committing_transaction: the transaction we are pushing to disk
485 * @j_checkpoint_transactions: a linked circular list of all transactions waiting for checkpointing
486 * @j_wait_transaction_locked: Wait queue for waiting for a locked transaction to start committing, or for a barrier lock to be released
487 * @j_wait_logspace: Wait queue for waiting for checkpointing to complete
488 * @j_wait_done_commit: Wait queue for waiting for commit to complete
489 * @j_wait_checkpoint: Wait queue to trigger checkpointing
490 * @j_wait_commit: Wait queue to trigger commit
491 * @j_wait_updates: Wait queue to wait for updates to complete
492 * @j_checkpoint_sem: Semaphore for locking against concurrent checkpoints
493 * @j_sem: The main journal lock, used by lock_journal()
494 * @j_head: Journal head - identifies the first unused block in the journal
495 * @j_tail: Journal tail - identifies the oldest still-used block in the journal.
496 * @j_free: Journal free - how many free blocks are there in the journal?
497 * @j_first: The block number of the first usable block
498 * @j_last: The block number one beyond the last usable block
499 * @j_dev: Device where we store the journal
500 * @j_blocksize: blocksize for the location where we store the journal.
501 * @j_blk_offset: starting block offset for into the device where we store the journal
502 * @j_fs_dev: Device which holds the client fs. For internal journal this will be equal to j_dev
503 * @j_maxlen: Total maximum capacity of the journal region on disk.
504 * @j_inode: Optional inode where we store the journal. If present, all journal block numbers are mapped into this inode via bmap().
505 * @j_tail_sequence: Sequence number of the oldest transaction in the log
506 * @j_transaction_sequence: Sequence number of the next transaction to grant
507 * @j_commit_sequence: Sequence number of the most recently committed transaction
508 * @j_commit_request: Sequence number of the most recent transaction wanting commit
509 * @j_uuid: Uuid of client object.
510 * @j_task: Pointer to the current commit thread for this journal
511 * @j_max_transaction_buffers: Maximum number of metadata buffers to allow in a single compound commit transaction
512 * @j_commit_interval: What is the maximum transaction lifetime before we begin a commit?
513 * @j_commit_timer: The timer used to wakeup the commit thread
514 * @j_commit_timer_active: Timer flag
515 * @j_all_journals: Link all journals together - system-wide
516 * @j_revoke: The revoke table - maintains the list of revoked blocks in the current transaction.
521 /* General journaling state flags */
522 unsigned long j_flags;
524 /* Is there an outstanding uncleared error on the journal (from */
525 /* a prior abort)? */
528 /* The superblock buffer */
529 struct buffer_head * j_sb_buffer;
530 journal_superblock_t * j_superblock;
532 /* Version of the superblock format */
533 int j_format_version;
535 /* Number of processes waiting to create a barrier lock */
538 /* The barrier lock itself */
539 struct semaphore j_barrier;
541 /* Transactions: The current running transaction... */
542 transaction_t * j_running_transaction;
544 /* ... the transaction we are pushing to disk ... */
545 transaction_t * j_committing_transaction;
547 /* ... and a linked circular list of all transactions waiting */
548 /* for checkpointing. */
549 /* Protected by journal_datalist_lock */
550 transaction_t * j_checkpoint_transactions;
552 /* Wait queue for waiting for a locked transaction to start */
553 /* committing, or for a barrier lock to be released */
554 wait_queue_head_t j_wait_transaction_locked;
556 /* Wait queue for waiting for checkpointing to complete */
557 wait_queue_head_t j_wait_logspace;
559 /* Wait queue for waiting for commit to complete */
560 wait_queue_head_t j_wait_done_commit;
562 /* Wait queue to trigger checkpointing */
563 wait_queue_head_t j_wait_checkpoint;
565 /* Wait queue to trigger commit */
566 wait_queue_head_t j_wait_commit;
568 /* Wait queue to wait for updates to complete */
569 wait_queue_head_t j_wait_updates;
571 /* Semaphore for locking against concurrent checkpoints */
572 struct semaphore j_checkpoint_sem;
574 /* The main journal lock, used by lock_journal() */
575 struct semaphore j_sem;
577 /* Journal head: identifies the first unused block in the journal. */
578 unsigned long j_head;
580 /* Journal tail: identifies the oldest still-used block in the */
582 unsigned long j_tail;
584 /* Journal free: how many free blocks are there in the journal? */
585 unsigned long j_free;
587 /* Journal start and end: the block numbers of the first usable */
588 /* block and one beyond the last usable block in the journal. */
589 unsigned long j_first, j_last;
591 /* Device, blocksize and starting block offset for the location */
592 /* where we store the journal. */
595 unsigned int j_blk_offset;
597 /* Device which holds the client fs. For internal journal this */
598 /* will be equal to j_dev. */
601 /* Total maximum capacity of the journal region on disk. */
602 unsigned int j_maxlen;
604 /* Optional inode where we store the journal. If present, all */
605 /* journal block numbers are mapped into this inode via */
607 struct inode * j_inode;
609 /* Sequence number of the oldest transaction in the log */
610 tid_t j_tail_sequence;
611 /* Sequence number of the next transaction to grant */
612 tid_t j_transaction_sequence;
613 /* Sequence number of the most recently committed transaction */
614 tid_t j_commit_sequence;
615 /* Sequence number of the most recent transaction wanting commit */
616 tid_t j_commit_request;
618 /* Journal uuid: identifies the object (filesystem, LVM volume */
619 /* etc) backed by this journal. This will eventually be */
620 /* replaced by an array of uuids, allowing us to index multiple */
621 /* devices within a single journal and to perform atomic updates */
626 /* Pointer to the current commit thread for this journal */
627 struct task_struct * j_task;
629 /* Maximum number of metadata buffers to allow in a single */
630 /* compound commit transaction */
631 int j_max_transaction_buffers;
633 /* What is the maximum transaction lifetime before we begin a */
635 unsigned long j_commit_interval;
637 /* The timer used to wakeup the commit thread: */
638 struct timer_list * j_commit_timer;
639 int j_commit_timer_active;
641 /* Link all journals together - system-wide */
642 struct list_head j_all_journals;
644 /* The revoke table: maintains the list of revoked blocks in the */
645 /* current transaction. */
646 struct jbd_revoke_table_s *j_revoke;
650 * Journal flag definitions
652 #define JFS_UNMOUNT 0x001 /* Journal thread is being destroyed */
653 #define JFS_ABORT 0x002 /* Journaling has been aborted for errors. */
654 #define JFS_ACK_ERR 0x004 /* The errno in the sb has been acked */
655 #define JFS_FLUSHED 0x008 /* The journal superblock has been flushed */
656 #define JFS_LOADED 0x010 /* The journal superblock has been loaded */
659 * Function declarations for the journaling transaction and buffer
664 extern void __journal_unfile_buffer(struct journal_head *);
665 extern void journal_unfile_buffer(struct journal_head *);
666 extern void __journal_refile_buffer(struct journal_head *);
667 extern void journal_refile_buffer(struct journal_head *);
668 extern void __journal_file_buffer(struct journal_head *, transaction_t *, int);
669 extern void __journal_free_buffer(struct journal_head *bh);
670 extern void journal_file_buffer(struct journal_head *, transaction_t *, int);
671 extern void __journal_clean_data_list(transaction_t *transaction);
673 /* Log buffer allocation */
674 extern struct journal_head * journal_get_descriptor_buffer(journal_t *);
675 int journal_next_log_block(journal_t *, unsigned long *);
677 /* Commit management */
678 void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate);
679 extern void journal_commit_transaction(journal_t *);
681 /* Checkpoint list management */
682 int __journal_clean_checkpoint_list(journal_t *journal);
683 extern void journal_remove_checkpoint(struct journal_head *);
684 extern void __journal_remove_checkpoint(struct journal_head *);
685 extern void journal_insert_checkpoint(struct journal_head *, transaction_t *);
686 extern void __journal_insert_checkpoint(struct journal_head *,transaction_t *);
690 journal_write_metadata_buffer(transaction_t *transaction,
691 struct journal_head *jh_in,
692 struct journal_head **jh_out,
695 /* Transaction locking */
696 extern void __wait_on_journal (journal_t *);
701 * We need to lock the journal during transaction state changes so that
702 * nobody ever tries to take a handle on the running transaction while
703 * we are in the middle of moving it to the commit phase.
705 * Note that the locking is completely interrupt unsafe. We never touch
706 * journal structures from interrupts.
708 * In 2.2, the BKL was required for lock_journal. This is no longer
712 static inline void lock_journal(journal_t *journal)
714 down(&journal->j_sem);
717 /* This returns zero if we acquired the semaphore */
718 static inline int try_lock_journal(journal_t * journal)
720 return down_trylock(&journal->j_sem);
723 static inline void unlock_journal(journal_t * journal)
729 static inline handle_t *journal_current_handle(void)
731 return current->journal_info;
734 /* The journaling code user interface:
736 * Create and destroy handles
737 * Register buffer modifications against the current transaction.
740 extern handle_t *journal_start(journal_t *, int nblocks);
741 extern handle_t *journal_try_start(journal_t *, int nblocks);
742 extern int journal_restart (handle_t *, int nblocks);
743 extern int journal_extend (handle_t *, int nblocks);
744 extern int journal_get_write_access (handle_t *, struct buffer_head *);
745 extern int journal_get_create_access (handle_t *, struct buffer_head *);
746 extern int journal_get_undo_access (handle_t *, struct buffer_head *);
747 extern int journal_dirty_data (handle_t *,
748 struct buffer_head *, int async);
749 extern int journal_dirty_metadata (handle_t *, struct buffer_head *);
750 extern void journal_release_buffer (handle_t *, struct buffer_head *);
751 extern void journal_forget (handle_t *, struct buffer_head *);
752 extern void journal_sync_buffer (struct buffer_head *);
753 extern int journal_flushpage(journal_t *, struct page *, unsigned long);
754 extern int journal_try_to_free_buffers(journal_t *, struct page *, int);
755 extern int journal_stop(handle_t *);
756 extern int journal_flush (journal_t *);
757 extern void journal_callback_set(handle_t *handle,
758 void (*fn)(struct journal_callback *,int),
759 struct journal_callback *jcb);
761 extern void journal_lock_updates (journal_t *);
762 extern void journal_unlock_updates (journal_t *);
764 extern journal_t * journal_init_dev(kdev_t dev, kdev_t fs_dev,
765 int start, int len, int bsize);
766 extern journal_t * journal_init_inode (struct inode *);
767 extern int journal_update_format (journal_t *);
768 extern int journal_check_used_features
769 (journal_t *, unsigned long, unsigned long, unsigned long);
770 extern int journal_check_available_features
771 (journal_t *, unsigned long, unsigned long, unsigned long);
772 extern int journal_set_features
773 (journal_t *, unsigned long, unsigned long, unsigned long);
774 extern int journal_create (journal_t *);
775 extern int journal_load (journal_t *journal);
776 extern void journal_destroy (journal_t *);
777 extern int journal_recover (journal_t *journal);
778 extern int journal_wipe (journal_t *, int);
779 extern int journal_skip_recovery (journal_t *);
780 extern void journal_update_superblock (journal_t *, int);
781 extern void __journal_abort_hard (journal_t *);
782 extern void __journal_abort_soft (journal_t *, int);
783 extern void journal_abort (journal_t *, int);
784 extern int journal_errno (journal_t *);
785 extern void journal_ack_err (journal_t *);
786 extern int journal_clear_err (journal_t *);
787 extern int journal_bmap(journal_t *, unsigned long, unsigned long *);
788 extern int journal_force_commit(journal_t *);
791 * journal_head management
793 extern struct journal_head
794 *journal_add_journal_head(struct buffer_head *bh);
795 extern void journal_remove_journal_head(struct buffer_head *bh);
796 extern void __journal_remove_journal_head(struct buffer_head *bh);
797 extern void journal_unlock_journal_head(struct journal_head *jh);
799 /* Primary revoke support */
800 #define JOURNAL_REVOKE_DEFAULT_HASH 256
801 extern int journal_init_revoke(journal_t *, int);
802 extern void journal_destroy_revoke_caches(void);
803 extern int journal_init_revoke_caches(void);
805 extern void journal_destroy_revoke(journal_t *);
806 extern int journal_revoke (handle_t *,
807 unsigned long, struct buffer_head *);
808 extern int journal_cancel_revoke(handle_t *, struct journal_head *);
809 extern void journal_write_revoke_records(journal_t *, transaction_t *);
811 /* Recovery revoke support */
812 extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
813 extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
814 extern void journal_clear_revoke(journal_t *);
815 extern void journal_brelse_array(struct buffer_head *b[], int n);
817 /* The log thread user interface:
819 * Request space in the current transaction, and force transaction commit
820 * transitions on demand.
823 extern int log_space_left (journal_t *); /* Called with journal locked */
824 extern tid_t log_start_commit (journal_t *, transaction_t *);
825 extern void log_wait_commit (journal_t *, tid_t);
826 extern int log_do_checkpoint (journal_t *, int);
828 extern void log_wait_for_space(journal_t *, int nblocks);
829 extern void __journal_drop_transaction(journal_t *, transaction_t *);
830 extern int cleanup_journal_tail(journal_t *);
832 /* Reduce journal memory usage by flushing */
833 extern void shrink_journal_memory(void);
835 /* Debugging code only: */
837 #define jbd_ENOSYS() \
839 printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \
840 current->state = TASK_UNINTERRUPTIBLE; \
844 extern void __jbd_unexpected_dirty_buffer(char *, int, struct journal_head *);
845 #define jbd_unexpected_dirty_buffer(jh) \
846 __jbd_unexpected_dirty_buffer(__FUNCTION__, __LINE__, (jh))
851 * Simple test wrapper function to test the JFS_ABORT state flag. This
852 * bit, when set, indicates that we have had a fatal error somewhere,
853 * either inside the journaling layer or indicated to us by the client
854 * (eg. ext3), and that we and should not commit any further
858 static inline int is_journal_aborted(journal_t *journal)
860 return journal->j_flags & JFS_ABORT;
863 static inline int is_handle_aborted(handle_t *handle)
865 if (handle->h_aborted)
867 return is_journal_aborted(handle->h_transaction->t_journal);
870 static inline void journal_abort_handle(handle_t *handle)
872 handle->h_aborted = 1;
875 /* Not all architectures define BUG() */
878 printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
879 * ((char *) 0) = 0; \
883 #endif /* __KERNEL__ */
885 /* Comparison functions for transaction IDs: perform comparisons using
886 * modulo arithmetic so that they work over sequence number wraps. */
888 static inline int tid_gt(tid_t x, tid_t y)
890 int difference = (x - y);
891 return (difference > 0);
894 static inline int tid_geq(tid_t x, tid_t y)
896 int difference = (x - y);
897 return (difference >= 0);
900 extern int journal_blocks_per_page(struct inode *inode);
903 * Definitions which augment the buffer_head layer
906 /* journaling buffer types */
907 #define BJ_None 0 /* Not journaled */
908 #define BJ_SyncData 1 /* Normal data: flush before commit */
909 #define BJ_AsyncData 2 /* writepage data: wait on it before commit */
910 #define BJ_Metadata 3 /* Normal journaled metadata */
911 #define BJ_Forget 4 /* Buffer superceded by this transaction */
912 #define BJ_IO 5 /* Buffer is for temporary IO use */
913 #define BJ_Shadow 6 /* Buffer contents being shadowed to the log */
914 #define BJ_LogCtl 7 /* Buffer contains log descriptors */
915 #define BJ_Reserved 8 /* Buffer is reserved for access by journal */
920 extern spinlock_t jh_splice_lock;
922 * Once `expr1' has been found true, take jh_splice_lock
923 * and then reevaluate everything.
925 #define SPLICE_LOCK(expr1, expr2) \
929 spin_lock(&jh_splice_lock); \
930 ret = (expr1) && (expr2); \
931 spin_unlock(&jh_splice_lock); \
937 * A number of buffer state predicates. They test for
938 * buffer_jbd() because they are used in core kernel code.
940 * These will be racy on SMP unless we're *sure* that the
941 * buffer won't be detached from the journalling system
945 /* Return true if the buffer is on journal list `list' */
946 static inline int buffer_jlist_eq(struct buffer_head *bh, int list)
948 return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list);
951 /* Return true if this bufer is dirty wrt the journal */
952 static inline int buffer_jdirty(struct buffer_head *bh)
954 return buffer_jbd(bh) && __buffer_state(bh, JBDDirty);
957 /* Return true if it's a data buffer which journalling is managing */
958 static inline int buffer_jbd_data(struct buffer_head *bh)
960 return SPLICE_LOCK(buffer_jbd(bh),
961 bh2jh(bh)->b_jlist == BJ_SyncData ||
962 bh2jh(bh)->b_jlist == BJ_AsyncData);
966 #define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock))
968 #define assert_spin_locked(lock) do {} while(0)
971 #define buffer_trace_init(bh) do {} while (0)
972 #define print_buffer_fields(bh) do {} while (0)
973 #define print_buffer_trace(bh) do {} while (0)
974 #define BUFFER_TRACE(bh, info) do {} while (0)
975 #define BUFFER_TRACE2(bh, bh2, info) do {} while (0)
976 #define JBUFFER_TRACE(jh, info) do {} while (0)
978 #endif /* __KERNEL__ */
980 #endif /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */
983 * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD
987 #if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE))
989 #define J_ASSERT(expr) do {} while (0)
990 #define J_ASSERT_BH(bh, expr) do {} while (0)
991 #define buffer_jbd(bh) 0
992 #define buffer_jlist_eq(bh, val) 0
993 #define journal_buffer_journal_lru(bh) 0
995 #endif /* defined(__KERNEL__) && !defined(CONFIG_JBD) */
996 #endif /* _LINUX_JBD_H */