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>
34 #define __FUNCTION__ ""
37 #define journal_oom_retry 1
40 #ifdef CONFIG_JBD_DEBUG
42 * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
43 * consistency checks. By default we don't do this unless
44 * CONFIG_JBD_DEBUG is on.
46 #define JBD_EXPENSIVE_CHECKING
47 extern int journal_enable_debug;
49 #define jbd_debug(n, f, a...) \
51 if ((n) <= journal_enable_debug) { \
52 printk (KERN_DEBUG "(%s, %d): %s: ", \
53 __FILE__, __LINE__, __FUNCTION__); \
59 #define jbd_debug(f, a...) /**/
61 #define jbd_debug(f, ...) /**/
65 #define jbd_debug(x) /* AIX doesn't do STDC */
68 extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry);
69 #define jbd_kmalloc(size, flags) \
70 __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
71 #define jbd_rep_kmalloc(size, flags) \
72 __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)
74 #define JFS_MIN_JOURNAL_BLOCKS 1024
77 typedef struct handle_s handle_t; /* Atomic operation type */
78 typedef struct journal_s journal_t; /* Journal control structure */
82 * Internal structures used by the logging mechanism:
85 #define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
92 * Descriptor block types:
95 #define JFS_DESCRIPTOR_BLOCK 1
96 #define JFS_COMMIT_BLOCK 2
97 #define JFS_SUPERBLOCK_V1 3
98 #define JFS_SUPERBLOCK_V2 4
99 #define JFS_REVOKE_BLOCK 5
102 * Standard header for all descriptor blocks:
104 typedef struct journal_header_s
114 #define JBD2_CRC32_CHKSUM 1
115 #define JBD2_MD5_CHKSUM 2
116 #define JBD2_SHA1_CHKSUM 3
117 #define JBD2_CRC32C_CHKSUM 4
119 #define JBD2_CRC32_CHKSUM_SIZE 4
121 #define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32))
123 * Commit block header for storing transactional checksums:
125 * NOTE: If FEATURE_COMPAT_CHECKSUM (checksum v1) is set, the h_chksum*
126 * fields are used to store a checksum of the descriptor and data blocks.
128 * If FEATURE_INCOMPAT_CSUM_V2 (checksum v2) is set, then the h_chksum
129 * field is used to store crc32c(uuid+commit_block). Each journal metadata
130 * block gets its own checksum, and data block checksums are stored in
131 * journal_block_tag (in the descriptor). The other h_chksum* fields are
134 * Checksum v1 and v2 are mutually exclusive features.
136 struct commit_header {
140 unsigned char h_chksum_type;
141 unsigned char h_chksum_size;
142 unsigned char h_padding[2];
143 __u32 h_chksum[JBD2_CHECKSUM_BYTES];
149 * The block tag: used to describe a single buffer in the journal
151 typedef struct journal_block_tag_s
153 __u32 t_blocknr; /* The on-disk block number */
154 __u16 t_checksum; /* truncated crc32c(uuid+seq+block) */
155 __u16 t_flags; /* See below */
156 __u32 t_blocknr_high; /* most-significant high 32bits. */
157 } journal_block_tag_t;
159 #define JBD_TAG_SIZE64 (sizeof(journal_block_tag_t))
160 #define JBD_TAG_SIZE32 (8)
162 /* Tail of descriptor block, for checksumming */
163 struct journal_block_tail {
168 * The revoke descriptor: used on disk to describe a series of blocks to
169 * be revoked from the log
171 typedef struct journal_revoke_header_s
173 journal_header_t r_header;
174 int r_count; /* Count of bytes used in the block */
175 } journal_revoke_header_t;
177 /* Tail of revoke block, for checksumming */
178 struct journal_revoke_tail {
182 /* Definitions for the journal tag flags word: */
183 #define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */
184 #define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */
185 #define JFS_FLAG_DELETED 4 /* block deleted by this transaction */
186 #define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
190 * The journal superblock. All fields are in big-endian byte order.
192 typedef struct journal_superblock_s
195 journal_header_t s_header;
198 /* Static information describing the journal */
199 __u32 s_blocksize; /* journal device blocksize */
200 __u32 s_maxlen; /* total blocks in journal file */
201 __u32 s_first; /* first block of log information */
204 /* Dynamic information describing the current state of the log */
205 __u32 s_sequence; /* first commit ID expected in log */
206 __u32 s_start; /* blocknr of start of log */
209 /* Error value, as set by journal_abort(). */
213 /* Remaining fields are only valid in a version-2 superblock */
214 __u32 s_feature_compat; /* compatible feature set */
215 __u32 s_feature_incompat; /* incompatible feature set */
216 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
218 __u8 s_uuid[16]; /* 128-bit uuid for journal */
221 __u32 s_nr_users; /* Nr of filesystems sharing log */
223 __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
226 __u32 s_max_transaction; /* Limit of journal blocks per trans.*/
227 __u32 s_max_trans_data; /* Limit of data blocks per trans. */
230 __u8 s_checksum_type; /* checksum type */
233 __u32 s_checksum; /* crc32c(superblock) */
236 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
238 } journal_superblock_t;
240 #define JFS_HAS_COMPAT_FEATURE(j,mask) \
241 ((j)->j_format_version >= 2 && \
242 ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
243 #define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \
244 ((j)->j_format_version >= 2 && \
245 ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
246 #define JFS_HAS_INCOMPAT_FEATURE(j,mask) \
247 ((j)->j_format_version >= 2 && \
248 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
250 #define JFS_FEATURE_COMPAT_CHECKSUM 0x00000001
252 #define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001
253 #define JFS_FEATURE_INCOMPAT_64BIT 0x00000002
254 #define JFS_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004
255 #define JFS_FEATURE_INCOMPAT_CSUM_V2 0x00000008
257 /* Features known to this kernel version: */
258 #define JFS_KNOWN_COMPAT_FEATURES 0
259 #define JFS_KNOWN_ROCOMPAT_FEATURES 0
260 #define JFS_KNOWN_INCOMPAT_FEATURES (JFS_FEATURE_INCOMPAT_REVOKE|\
261 JFS_FEATURE_INCOMPAT_ASYNC_COMMIT|\
262 JFS_FEATURE_INCOMPAT_64BIT)
266 #include <linux/fs.h>
267 #include <linux/sched.h>
269 #define JBD_ASSERTIONS
270 #ifdef JBD_ASSERTIONS
271 #define J_ASSERT(assert) \
275 "Assertion failure in %s() at %s:%d: \"%s\"\n", \
276 __FUNCTION__, __FILE__, __LINE__, # assert); \
281 #if defined(CONFIG_BUFFER_DEBUG)
282 void buffer_assertion_failure(struct buffer_head *bh);
283 #define J_ASSERT_BH(bh, expr) \
286 buffer_assertion_failure(bh); \
289 #define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr)
291 #define J_ASSERT_BH(bh, expr) J_ASSERT(expr)
292 #define J_ASSERT_JH(jh, expr) J_ASSERT(expr)
296 #define J_ASSERT(assert)
297 #endif /* JBD_ASSERTIONS */
299 enum jbd_state_bits {
301 = BH_PrivateStart, /* 1 if being written to log (@@@ DEBUGGING) */
302 BH_Freed, /* 1 if buffer has been freed (truncated) */
303 BH_Revoked, /* 1 if buffer has been revoked from the log */
304 BH_RevokeValid, /* 1 if buffer revoked flag is valid */
305 BH_JBDDirty, /* 1 if buffer is dirty but journaled */
308 /* Return true if the buffer is one which JBD is managing */
309 static inline int buffer_jbd(struct buffer_head *bh)
311 return __buffer_state(bh, JBD);
314 static inline struct buffer_head *jh2bh(struct journal_head *jh)
319 static inline struct journal_head *bh2jh(struct buffer_head *bh)
321 return bh->b_private;
324 struct jbd_revoke_table_s;
326 /* The handle_t type represents a single atomic update being performed
327 * by some process. All filesystem modifications made by the process go
328 * through this handle. Recursive operations (such as quota operations)
329 * are gathered into a single update.
331 * The buffer credits field is used to account for journaled buffers
332 * being modified by the running process. To ensure that there is
333 * enough log space for all outstanding operations, we need to limit the
334 * number of outstanding buffers possible at any time. When the
335 * operation completes, any buffer credits not used are credited back to
336 * the transaction, so that at all times we know how many buffers the
337 * outstanding updates on a transaction might possibly touch. */
341 /* Which compound transaction is this update a part of? */
342 transaction_t * h_transaction;
344 /* Number of remaining buffers we are allowed to dirty: */
345 int h_buffer_credits;
347 /* Reference count on this handle */
350 /* Field for caller's use to track errors through large fs
355 unsigned int h_sync: 1; /* sync-on-close */
356 unsigned int h_jdata: 1; /* force data journaling */
357 unsigned int h_aborted: 1; /* fatal error on handle */
361 /* The transaction_t type is the guts of the journaling mechanism. It
362 * tracks a compound transaction through its various states:
364 * RUNNING: accepting new updates
365 * LOCKED: Updates still running but we don't accept new ones
366 * RUNDOWN: Updates are tidying up but have finished requesting
367 * new buffers to modify (state not used for now)
368 * FLUSH: All updates complete, but we are still writing to disk
369 * COMMIT: All data on disk, writing commit record
370 * FINISHED: We still have to keep the transaction for checkpointing.
372 * The transaction keeps track of all of the buffers modified by a
373 * running transaction, and all of the buffers committed but not yet
374 * flushed to home for finished transactions.
379 /* Pointer to the journal for this transaction. */
380 journal_t * t_journal;
382 /* Sequence number for this transaction */
385 /* Transaction's current state */
395 /* Where in the log does this transaction's commit start? */
396 unsigned long t_log_start;
398 /* Doubly-linked circular list of all inodes owned by this
399 transaction */ /* AKPM: unused */
400 struct inode * t_ilist;
402 /* Number of buffers on the t_buffers list */
405 /* Doubly-linked circular list of all buffers reserved but not
406 yet modified by this transaction */
407 struct journal_head * t_reserved_list;
409 /* Doubly-linked circular list of all metadata buffers owned by this
411 struct journal_head * t_buffers;
414 * Doubly-linked circular list of all data buffers still to be
415 * flushed before this transaction can be committed.
416 * Protected by journal_datalist_lock.
418 struct journal_head * t_sync_datalist;
421 * Doubly-linked circular list of all writepage data buffers
422 * still to be written before this transaction can be committed.
423 * Protected by journal_datalist_lock.
425 struct journal_head * t_async_datalist;
427 /* Doubly-linked circular list of all forget buffers (superceded
428 buffers which we can un-checkpoint once this transaction
430 struct journal_head * t_forget;
433 * Doubly-linked circular list of all buffers still to be
434 * flushed before this transaction can be checkpointed.
436 /* Protected by journal_datalist_lock */
437 struct journal_head * t_checkpoint_list;
439 /* Doubly-linked circular list of temporary buffers currently
440 undergoing IO in the log */
441 struct journal_head * t_iobuf_list;
443 /* Doubly-linked circular list of metadata buffers being
444 shadowed by log IO. The IO buffers on the iobuf list and the
445 shadow buffers on this list match each other one for one at
447 struct journal_head * t_shadow_list;
449 /* Doubly-linked circular list of control buffers being written
451 struct journal_head * t_log_list;
453 /* Number of outstanding updates running on this transaction */
456 /* Number of buffers reserved for use by all handles in this
457 * transaction handle but not yet modified. */
458 int t_outstanding_credits;
461 * Forward and backward links for the circular list of all
462 * transactions awaiting checkpoint.
464 /* Protected by journal_datalist_lock */
465 transaction_t *t_cpnext, *t_cpprev;
467 /* When will the transaction expire (become due for commit), in
469 unsigned long t_expires;
471 /* How many handles used this transaction? */
476 /* The journal_t maintains all of the journaling state information for a
477 * single filesystem. It is linked to from the fs superblock structure.
479 * We use the journal_t to keep track of all outstanding transaction
480 * activity on the filesystem, and to manage the state of the log
481 * writing process. */
485 /* General journaling state flags */
486 unsigned long j_flags;
488 /* Is there an outstanding uncleared error on the journal (from
492 /* The superblock buffer */
493 struct buffer_head * j_sb_buffer;
494 journal_superblock_t * j_superblock;
496 /* Version of the superblock format */
497 int j_format_version;
499 /* Number of processes waiting to create a barrier lock */
502 /* The barrier lock itself */
503 struct semaphore j_barrier;
505 /* Transactions: The current running transaction... */
506 transaction_t * j_running_transaction;
508 /* ... the transaction we are pushing to disk ... */
509 transaction_t * j_committing_transaction;
511 /* ... and a linked circular list of all transactions waiting
512 * for checkpointing. */
513 /* Protected by journal_datalist_lock */
514 transaction_t * j_checkpoint_transactions;
516 /* Wait queue for waiting for a locked transaction to start
517 committing, or for a barrier lock to be released */
518 wait_queue_head_t j_wait_transaction_locked;
520 /* Wait queue for waiting for checkpointing to complete */
521 wait_queue_head_t j_wait_logspace;
523 /* Wait queue for waiting for commit to complete */
524 wait_queue_head_t j_wait_done_commit;
526 /* Wait queue to trigger checkpointing */
527 wait_queue_head_t j_wait_checkpoint;
529 /* Wait queue to trigger commit */
530 wait_queue_head_t j_wait_commit;
532 /* Wait queue to wait for updates to complete */
533 wait_queue_head_t j_wait_updates;
535 /* Semaphore for locking against concurrent checkpoints */
536 struct semaphore j_checkpoint_sem;
538 /* The main journal lock, used by lock_journal() */
539 struct semaphore j_sem;
541 /* Journal head: identifies the first unused block in the journal. */
542 unsigned long j_head;
544 /* Journal tail: identifies the oldest still-used block in the
546 unsigned long j_tail;
548 /* Journal free: how many free blocks are there in the journal? */
549 unsigned long j_free;
551 /* Journal start and end: the block numbers of the first usable
552 * block and one beyond the last usable block in the journal. */
553 unsigned long j_first, j_last;
555 /* Device, blocksize and starting block offset for the location
556 * where we store the journal. */
559 unsigned int j_blk_offset;
561 /* Device which holds the client fs. For internal journal this
562 * will be equal to j_dev. */
565 /* Total maximum capacity of the journal region on disk. */
566 unsigned int j_maxlen;
568 /* Optional inode where we store the journal. If present, all
569 * journal block numbers are mapped into this inode via
571 struct inode * j_inode;
573 /* Sequence number of the oldest transaction in the log */
574 tid_t j_tail_sequence;
575 /* Sequence number of the next transaction to grant */
576 tid_t j_transaction_sequence;
577 /* Sequence number of the most recently committed transaction */
578 tid_t j_commit_sequence;
579 /* Sequence number of the most recent transaction wanting commit */
580 tid_t j_commit_request;
582 /* Journal uuid: identifies the object (filesystem, LVM volume
583 * etc) backed by this journal. This will eventually be
584 * replaced by an array of uuids, allowing us to index multiple
585 * devices within a single journal and to perform atomic updates
590 /* Pointer to the current commit thread for this journal */
591 struct task_struct * j_task;
593 /* Maximum number of metadata buffers to allow in a single
594 * compound commit transaction */
595 int j_max_transaction_buffers;
597 /* What is the maximum transaction lifetime before we begin a
599 unsigned long j_commit_interval;
601 /* The timer used to wakeup the commit thread: */
602 struct timer_list * j_commit_timer;
603 int j_commit_timer_active;
605 /* Link all journals together - system-wide */
606 struct list_head j_all_journals;
608 /* The revoke table: maintains the list of revoked blocks in the
609 current transaction. */
610 struct jbd_revoke_table_s *j_revoke;
612 /* Failed journal commit ID */
613 unsigned int j_failed_commit;
617 * Journal flag definitions
619 #define JFS_UNMOUNT 0x001 /* Journal thread is being destroyed */
620 #define JFS_ABORT 0x002 /* Journaling has been aborted for errors. */
621 #define JFS_ACK_ERR 0x004 /* The errno in the sb has been acked */
622 #define JFS_FLUSHED 0x008 /* The journal superblock has been flushed */
623 #define JFS_LOADED 0x010 /* The journal superblock has been loaded */
626 * Function declarations for the journaling transaction and buffer
631 extern void __journal_unfile_buffer(struct journal_head *);
632 extern void journal_unfile_buffer(struct journal_head *);
633 extern void __journal_refile_buffer(struct journal_head *);
634 extern void journal_refile_buffer(struct journal_head *);
635 extern void __journal_file_buffer(struct journal_head *, transaction_t *, int);
636 extern void __journal_free_buffer(struct journal_head *bh);
637 extern void journal_file_buffer(struct journal_head *, transaction_t *, int);
638 extern void __journal_clean_data_list(transaction_t *transaction);
640 /* Log buffer allocation */
641 extern struct journal_head * journal_get_descriptor_buffer(journal_t *);
642 extern unsigned long journal_next_log_block(journal_t *);
644 /* Commit management */
645 extern void journal_commit_transaction(journal_t *);
647 /* Checkpoint list management */
648 int __journal_clean_checkpoint_list(journal_t *journal);
649 extern void journal_remove_checkpoint(struct journal_head *);
650 extern void __journal_remove_checkpoint(struct journal_head *);
651 extern void journal_insert_checkpoint(struct journal_head *, transaction_t *);
652 extern void __journal_insert_checkpoint(struct journal_head *,transaction_t *);
656 journal_write_metadata_buffer(transaction_t *transaction,
657 struct journal_head *jh_in,
658 struct journal_head **jh_out,
661 /* Transaction locking */
662 extern void __wait_on_journal (journal_t *);
667 * We need to lock the journal during transaction state changes so that
668 * nobody ever tries to take a handle on the running transaction while
669 * we are in the middle of moving it to the commit phase.
671 * Note that the locking is completely interrupt unsafe. We never touch
672 * journal structures from interrupts.
674 * In 2.2, the BKL was required for lock_journal. This is no longer
678 static inline void lock_journal(journal_t *journal)
680 down(&journal->j_sem);
683 /* This returns zero if we acquired the semaphore */
684 static inline int try_lock_journal(journal_t * journal)
686 return down_trylock(&journal->j_sem);
689 static inline void unlock_journal(journal_t * journal)
695 static inline handle_t *journal_current_handle(void)
697 return current->journal_info;
700 /* The journaling code user interface:
702 * Create and destroy handles
703 * Register buffer modifications against the current transaction.
706 extern handle_t *journal_start(journal_t *, int nblocks);
707 extern handle_t *journal_try_start(journal_t *, int nblocks);
708 extern int journal_restart (handle_t *, int nblocks);
709 extern int journal_extend (handle_t *, int nblocks);
710 extern int journal_get_write_access (handle_t *, struct buffer_head *);
711 extern int journal_get_create_access (handle_t *, struct buffer_head *);
712 extern int journal_get_undo_access (handle_t *, struct buffer_head *);
713 extern int journal_dirty_data (handle_t *,
714 struct buffer_head *, int async);
715 extern int journal_dirty_metadata (handle_t *, struct buffer_head *);
716 extern void journal_release_buffer (handle_t *, struct buffer_head *);
717 extern void journal_forget (handle_t *, struct buffer_head *);
718 extern void journal_sync_buffer (struct buffer_head *);
719 extern int journal_flushpage(journal_t *, struct page *, unsigned long);
720 extern int journal_try_to_free_buffers(journal_t *, struct page *, int);
721 extern int journal_stop(handle_t *);
722 extern int journal_flush (journal_t *);
724 extern void journal_lock_updates (journal_t *);
725 extern void journal_unlock_updates (journal_t *);
727 extern journal_t * journal_init_dev(kdev_t dev, kdev_t fs_dev,
728 int start, int len, int bsize);
729 extern journal_t * journal_init_inode (struct inode *);
730 extern int journal_update_format (journal_t *);
731 extern int journal_check_used_features
732 (journal_t *, unsigned long, unsigned long, unsigned long);
733 extern int journal_check_available_features
734 (journal_t *, unsigned long, unsigned long, unsigned long);
735 extern int journal_set_features
736 (journal_t *, unsigned long, unsigned long, unsigned long);
737 extern int journal_create (journal_t *);
738 extern int journal_load (journal_t *journal);
739 extern void journal_destroy (journal_t *);
740 extern int journal_recover (journal_t *journal);
741 extern int journal_wipe (journal_t *, int);
742 extern int journal_skip_recovery (journal_t *);
743 extern void journal_update_superblock (journal_t *, int);
744 extern void __journal_abort (journal_t *);
745 extern void journal_abort (journal_t *, int);
746 extern int journal_errno (journal_t *);
747 extern void journal_ack_err (journal_t *);
748 extern int journal_clear_err (journal_t *);
749 extern unsigned long journal_bmap(journal_t *journal, unsigned long blocknr);
750 extern int journal_force_commit(journal_t *journal);
753 * journal_head management
755 extern struct journal_head
756 *journal_add_journal_head(struct buffer_head *bh);
757 extern void journal_remove_journal_head(struct buffer_head *bh);
758 extern void __journal_remove_journal_head(struct buffer_head *bh);
759 extern void journal_unlock_journal_head(struct journal_head *jh);
761 /* Primary revoke support */
762 #define JOURNAL_REVOKE_DEFAULT_HASH 256
763 extern int journal_init_revoke(journal_t *, int);
764 extern void journal_destroy_revoke_caches(void);
765 extern int journal_init_revoke_caches(void);
767 extern void journal_destroy_revoke(journal_t *);
768 extern int journal_revoke (handle_t *,
769 unsigned long, struct buffer_head *);
770 extern int journal_cancel_revoke(handle_t *, struct journal_head *);
771 extern void journal_write_revoke_records(journal_t *, transaction_t *);
773 /* Recovery revoke support */
774 extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
775 extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
776 extern void journal_clear_revoke(journal_t *);
777 extern void journal_brelse_array(struct buffer_head *b[], int n);
779 /* The log thread user interface:
781 * Request space in the current transaction, and force transaction commit
782 * transitions on demand.
785 extern int log_space_left (journal_t *); /* Called with journal locked */
786 extern tid_t log_start_commit (journal_t *, transaction_t *);
787 extern void log_wait_commit (journal_t *, tid_t);
788 extern int log_do_checkpoint (journal_t *, int);
790 extern void log_wait_for_space(journal_t *, int nblocks);
791 extern void __journal_drop_transaction(journal_t *, transaction_t *);
792 extern int cleanup_journal_tail(journal_t *);
794 /* Reduce journal memory usage by flushing */
795 extern void shrink_journal_memory(void);
797 /* Debugging code only: */
799 #define jbd_ENOSYS() \
801 printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \
802 current->state = TASK_UNINTERRUPTIBLE; \
809 * Simple test wrapper function to test the JFS_ABORT state flag. This
810 * bit, when set, indicates that we have had a fatal error somewhere,
811 * either inside the journaling layer or indicated to us by the client
812 * (eg. ext3), and that we and should not commit any further
816 static inline int is_journal_aborted(journal_t *journal)
818 return journal->j_flags & JFS_ABORT;
821 static inline int is_handle_aborted(handle_t *handle)
823 if (handle->h_aborted)
825 return is_journal_aborted(handle->h_transaction->t_journal);
828 static inline void journal_abort_handle(handle_t *handle)
830 handle->h_aborted = 1;
833 /* Not all architectures define BUG() */
836 printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
837 * ((char *) 0) = 0; \
843 extern int journal_recover (journal_t *journal);
844 extern int journal_skip_recovery (journal_t *);
846 /* Primary revoke support */
847 extern int journal_init_revoke(journal_t *, int);
848 extern void journal_destroy_revoke_caches(void);
849 extern int journal_init_revoke_caches(void);
851 /* Recovery revoke support */
852 extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
853 extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
854 extern void journal_clear_revoke(journal_t *);
855 extern void journal_brelse_array(struct buffer_head *b[], int n);
857 extern void journal_destroy_revoke(journal_t *);
858 #endif /* __KERNEL__ */
860 static inline int tid_gt(tid_t x, tid_t y) EXT2FS_ATTR((unused));
861 static inline int tid_geq(tid_t x, tid_t y) EXT2FS_ATTR((unused));
863 /* Comparison functions for transaction IDs: perform comparisons using
864 * modulo arithmetic so that they work over sequence number wraps. */
866 static inline int tid_gt(tid_t x, tid_t y)
868 int difference = (x - y);
869 return (difference > 0);
872 static inline int tid_geq(tid_t x, tid_t y)
874 int difference = (x - y);
875 return (difference >= 0);
878 extern int journal_blocks_per_page(struct inode *inode);
881 * Definitions which augment the buffer_head layer
884 /* journaling buffer types */
885 #define BJ_None 0 /* Not journaled */
886 #define BJ_SyncData 1 /* Normal data: flush before commit */
887 #define BJ_AsyncData 2 /* writepage data: wait on it before commit */
888 #define BJ_Metadata 3 /* Normal journaled metadata */
889 #define BJ_Forget 4 /* Buffer superceded by this transaction */
890 #define BJ_IO 5 /* Buffer is for temporary IO use */
891 #define BJ_Shadow 6 /* Buffer contents being shadowed to the log */
892 #define BJ_LogCtl 7 /* Buffer contains log descriptors */
893 #define BJ_Reserved 8 /* Buffer is reserved for access by journal */
896 extern int jbd_blocks_per_page(struct inode *inode);
900 extern spinlock_t jh_splice_lock;
902 * Once `expr1' has been found true, take jh_splice_lock
903 * and then reevaluate everything.
905 #define SPLICE_LOCK(expr1, expr2) \
909 spin_lock(&jh_splice_lock); \
910 ret = (expr1) && (expr2); \
911 spin_unlock(&jh_splice_lock); \
917 * A number of buffer state predicates. They test for
918 * buffer_jbd() because they are used in core kernel code.
920 * These will be racy on SMP unless we're *sure* that the
921 * buffer won't be detached from the journalling system
925 /* Return true if the buffer is on journal list `list' */
926 static inline int buffer_jlist_eq(struct buffer_head *bh, int list)
928 return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list);
931 /* Return true if this bufer is dirty wrt the journal */
932 static inline int buffer_jdirty(struct buffer_head *bh)
934 return buffer_jbd(bh) && __buffer_state(bh, JBDDirty);
937 /* Return true if it's a data buffer which journalling is managing */
938 static inline int buffer_jbd_data(struct buffer_head *bh)
940 return SPLICE_LOCK(buffer_jbd(bh),
941 bh2jh(bh)->b_jlist == BJ_SyncData ||
942 bh2jh(bh)->b_jlist == BJ_AsyncData);
946 #define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock))
948 #define assert_spin_locked(lock) do {} while(0)
951 #define buffer_trace_init(bh) do {} while (0)
952 #define print_buffer_fields(bh) do {} while (0)
953 #define print_buffer_trace(bh) do {} while (0)
954 #define BUFFER_TRACE(bh, info) do {} while (0)
955 #define BUFFER_TRACE2(bh, bh2, info) do {} while (0)
956 #define JBUFFER_TRACE(jh, info) do {} while (0)
958 #endif /* __KERNEL__ */
960 #endif /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */
963 * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD
967 #if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE))
969 #define J_ASSERT(expr) do {} while (0)
970 #define J_ASSERT_BH(bh, expr) do {} while (0)
971 #define buffer_jbd(bh) 0
972 #define buffer_jlist_eq(bh, val) 0
973 #define journal_buffer_journal_lru(bh) 0
975 #endif /* defined(__KERNEL__) && !defined(CONFIG_JBD) */
976 #endif /* _LINUX_JBD_H */