Whamcloud - gitweb
Update the group descriptor free block and inode counts when
[tools/e2fsprogs.git] / include / linux / jbd.h
1 /*
2  * linux/include/linux/jbd.h
3  * 
4  * Written by Stephen C. Tweedie <sct@redhat.com>
5  *
6  * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
7  *
8  * This file is part of the Linux kernel and is made available under
9  * the terms of the GNU General Public License, version 2, or at your
10  * option, any later version, incorporated herein by reference.
11  *
12  * Definitions for transaction data structures for the buffer cache
13  * filesystem journaling support.
14  */
15
16 #ifndef _LINUX_JBD_H
17 #define _LINUX_JBD_H
18
19 #if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || !defined(__KERNEL__)
20
21 /* Allow this file to be included directly into e2fsprogs */
22 #ifndef __KERNEL__
23 #include "jfs_compat.h"
24 #define JFS_DEBUG
25 #define jfs_debug jbd_debug
26 #else
27
28 #include <linux/journal-head.h>
29 #include <linux/stddef.h>
30 #include <asm/semaphore.h>
31 #endif
32
33 #define journal_oom_retry 1
34
35 #ifdef CONFIG_JBD_DEBUG
36 /*
37  * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
38  * consistency checks.  By default we don't do this unless
39  * CONFIG_JBD_DEBUG is on.
40  */
41 #define JBD_EXPENSIVE_CHECKING
42 extern int journal_enable_debug;
43
44 #define jbd_debug(n, f, a...)                                           \
45         do {                                                            \
46                 if ((n) <= journal_enable_debug) {                      \
47                         printk (KERN_DEBUG "(%s, %d): %s: ",            \
48                                 __FILE__, __LINE__, __FUNCTION__);      \
49                         printk (f, ## a);                               \
50                 }                                                       \
51         } while (0)
52 #else
53 #define jbd_debug(f, a...)      /**/
54 #endif
55
56 extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry);
57 #define jbd_kmalloc(size, flags) \
58         __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
59 #define jbd_rep_kmalloc(size, flags) \
60         __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)
61
62 #define JFS_MIN_JOURNAL_BLOCKS 1024
63
64 #ifdef __KERNEL__
65 typedef struct handle_s         handle_t;       /* Atomic operation type */
66 typedef struct journal_s        journal_t;      /* Journal control structure */
67 #endif
68
69 /*
70  * Internal structures used by the logging mechanism:
71  */
72
73 #define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
74
75 /*
76  * On-disk structures
77  */
78
79 /* 
80  * Descriptor block types:
81  */
82
83 #define JFS_DESCRIPTOR_BLOCK    1
84 #define JFS_COMMIT_BLOCK        2
85 #define JFS_SUPERBLOCK_V1       3
86 #define JFS_SUPERBLOCK_V2       4
87 #define JFS_REVOKE_BLOCK        5
88
89 /*
90  * Standard header for all descriptor blocks:
91  */
92 typedef struct journal_header_s
93 {
94         __u32           h_magic;
95         __u32           h_blocktype;
96         __u32           h_sequence;
97 } journal_header_t;
98
99
100 /* 
101  * The block tag: used to describe a single buffer in the journal 
102  */
103 typedef struct journal_block_tag_s
104 {
105         __u32           t_blocknr;      /* The on-disk block number */
106         __u32           t_flags;        /* See below */
107 } journal_block_tag_t;
108
109 /* 
110  * The revoke descriptor: used on disk to describe a series of blocks to
111  * be revoked from the log 
112  */
113 typedef struct journal_revoke_header_s
114 {
115         journal_header_t r_header;
116         int              r_count;       /* Count of bytes used in the block */
117 } journal_revoke_header_t;
118
119
120 /* Definitions for the journal tag flags word: */
121 #define JFS_FLAG_ESCAPE         1       /* on-disk block is escaped */
122 #define JFS_FLAG_SAME_UUID      2       /* block has same uuid as previous */
123 #define JFS_FLAG_DELETED        4       /* block deleted by this transaction */
124 #define JFS_FLAG_LAST_TAG       8       /* last tag in this descriptor block */
125
126
127 /*
128  * The journal superblock.  All fields are in big-endian byte order.
129  */
130 typedef struct journal_superblock_s
131 {
132 /* 0x0000 */
133         journal_header_t s_header;
134
135 /* 0x000C */
136         /* Static information describing the journal */
137         __u32   s_blocksize;            /* journal device blocksize */
138         __u32   s_maxlen;               /* total blocks in journal file */
139         __u32   s_first;                /* first block of log information */
140         
141 /* 0x0018 */
142         /* Dynamic information describing the current state of the log */
143         __u32   s_sequence;             /* first commit ID expected in log */
144         __u32   s_start;                /* blocknr of start of log */
145
146 /* 0x0020 */
147         /* Error value, as set by journal_abort(). */
148         __s32   s_errno;
149
150 /* 0x0024 */
151         /* Remaining fields are only valid in a version-2 superblock */
152         __u32   s_feature_compat;       /* compatible feature set */
153         __u32   s_feature_incompat;     /* incompatible feature set */
154         __u32   s_feature_ro_compat;    /* readonly-compatible feature set */
155 /* 0x0030 */
156         __u8    s_uuid[16];             /* 128-bit uuid for journal */
157
158 /* 0x0040 */
159         __u32   s_nr_users;             /* Nr of filesystems sharing log */
160         
161         __u32   s_dynsuper;             /* Blocknr of dynamic superblock copy*/
162         
163 /* 0x0048 */
164         __u32   s_max_transaction;      /* Limit of journal blocks per trans.*/
165         __u32   s_max_trans_data;       /* Limit of data blocks per trans. */
166
167 /* 0x0050 */
168         __u32   s_padding[44];
169
170 /* 0x0100 */
171         __u8    s_users[16*48];         /* ids of all fs'es sharing the log */
172 /* 0x0400 */
173 } journal_superblock_t;
174
175 #define JFS_HAS_COMPAT_FEATURE(j,mask)                                  \
176         ((j)->j_format_version >= 2 &&                                  \
177          ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
178 #define JFS_HAS_RO_COMPAT_FEATURE(j,mask)                               \
179         ((j)->j_format_version >= 2 &&                                  \
180          ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
181 #define JFS_HAS_INCOMPAT_FEATURE(j,mask)                                \
182         ((j)->j_format_version >= 2 &&                                  \
183          ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
184
185 #define JFS_FEATURE_INCOMPAT_REVOKE     0x00000001
186
187 /* Features known to this kernel version: */
188 #define JFS_KNOWN_COMPAT_FEATURES       0
189 #define JFS_KNOWN_ROCOMPAT_FEATURES     0
190 #define JFS_KNOWN_INCOMPAT_FEATURES     JFS_FEATURE_INCOMPAT_REVOKE
191
192 #ifdef __KERNEL__
193
194 #include <linux/fs.h>
195 #include <linux/sched.h>
196
197 #define JBD_ASSERTIONS
198 #ifdef JBD_ASSERTIONS
199 #define J_ASSERT(assert)                                                \
200 do {                                                                    \
201         if (!(assert)) {                                                \
202                 printk (KERN_EMERG                                      \
203                         "Assertion failure in %s() at %s:%d: \"%s\"\n", \
204                         __FUNCTION__, __FILE__, __LINE__, # assert);    \
205                 BUG();                                                  \
206         }                                                               \
207 } while (0)
208
209 #if defined(CONFIG_BUFFER_DEBUG)
210 void buffer_assertion_failure(struct buffer_head *bh);
211 #define J_ASSERT_BH(bh, expr)                                           \
212         do {                                                            \
213                 if (!(expr))                                            \
214                         buffer_assertion_failure(bh);                   \
215                 J_ASSERT(expr);                                         \
216         } while (0)
217 #define J_ASSERT_JH(jh, expr)   J_ASSERT_BH(jh2bh(jh), expr)
218 #else
219 #define J_ASSERT_BH(bh, expr)   J_ASSERT(expr)
220 #define J_ASSERT_JH(jh, expr)   J_ASSERT(expr)
221 #endif
222
223 #else
224 #define J_ASSERT(assert)
225 #endif          /* JBD_ASSERTIONS */
226
227 enum jbd_state_bits {
228         BH_JWrite
229           = BH_PrivateStart,    /* 1 if being written to log (@@@ DEBUGGING) */
230         BH_Freed,               /* 1 if buffer has been freed (truncated) */
231         BH_Revoked,             /* 1 if buffer has been revoked from the log */
232         BH_RevokeValid,         /* 1 if buffer revoked flag is valid */
233         BH_JBDDirty,            /* 1 if buffer is dirty but journaled */
234 };
235
236 /* Return true if the buffer is one which JBD is managing */
237 static inline int buffer_jbd(struct buffer_head *bh)
238 {
239         return __buffer_state(bh, JBD);
240 }
241
242 static inline struct buffer_head *jh2bh(struct journal_head *jh)
243 {
244         return jh->b_bh;
245 }
246
247 static inline struct journal_head *bh2jh(struct buffer_head *bh)
248 {
249         return bh->b_private;
250 }
251
252 struct jbd_revoke_table_s;
253
254 /* The handle_t type represents a single atomic update being performed
255  * by some process.  All filesystem modifications made by the process go
256  * through this handle.  Recursive operations (such as quota operations)
257  * are gathered into a single update.
258  *
259  * The buffer credits field is used to account for journaled buffers
260  * being modified by the running process.  To ensure that there is
261  * enough log space for all outstanding operations, we need to limit the
262  * number of outstanding buffers possible at any time.  When the
263  * operation completes, any buffer credits not used are credited back to
264  * the transaction, so that at all times we know how many buffers the
265  * outstanding updates on a transaction might possibly touch. */
266
267 struct handle_s 
268 {
269         /* Which compound transaction is this update a part of? */
270         transaction_t         * h_transaction;
271
272         /* Number of remaining buffers we are allowed to dirty: */
273         int                     h_buffer_credits;
274
275         /* Reference count on this handle */
276         int                     h_ref;
277
278         /* Field for caller's use to track errors through large fs
279            operations */
280         int                     h_err;
281
282         /* Flags */
283         unsigned int    h_sync:         1;      /* sync-on-close */
284         unsigned int    h_jdata:        1;      /* force data journaling */
285         unsigned int    h_aborted:      1;      /* fatal error on handle */
286 };
287
288
289 /* The transaction_t type is the guts of the journaling mechanism.  It
290  * tracks a compound transaction through its various states:
291  *
292  * RUNNING:     accepting new updates
293  * LOCKED:      Updates still running but we don't accept new ones
294  * RUNDOWN:     Updates are tidying up but have finished requesting
295  *              new buffers to modify (state not used for now)
296  * FLUSH:       All updates complete, but we are still writing to disk
297  * COMMIT:      All data on disk, writing commit record
298  * FINISHED:    We still have to keep the transaction for checkpointing.
299  *
300  * The transaction keeps track of all of the buffers modified by a
301  * running transaction, and all of the buffers committed but not yet
302  * flushed to home for finished transactions.
303  */
304
305 struct transaction_s 
306 {
307         /* Pointer to the journal for this transaction. */
308         journal_t *             t_journal;
309         
310         /* Sequence number for this transaction */
311         tid_t                   t_tid;
312         
313         /* Transaction's current state */
314         enum {
315                 T_RUNNING,
316                 T_LOCKED,
317                 T_RUNDOWN,
318                 T_FLUSH,
319                 T_COMMIT,
320                 T_FINISHED 
321         }                       t_state;
322
323         /* Where in the log does this transaction's commit start? */
324         unsigned long           t_log_start;
325         
326         /* Doubly-linked circular list of all inodes owned by this
327            transaction */       /* AKPM: unused */
328         struct inode *          t_ilist;
329         
330         /* Number of buffers on the t_buffers list */
331         int                     t_nr_buffers;
332         
333         /* Doubly-linked circular list of all buffers reserved but not
334            yet modified by this transaction */
335         struct journal_head *   t_reserved_list;
336         
337         /* Doubly-linked circular list of all metadata buffers owned by this
338            transaction */
339         struct journal_head *   t_buffers;
340         
341         /*
342          * Doubly-linked circular list of all data buffers still to be
343          * flushed before this transaction can be committed.
344          * Protected by journal_datalist_lock.
345          */
346         struct journal_head *   t_sync_datalist;
347         
348         /*
349          * Doubly-linked circular list of all writepage data buffers
350          * still to be written before this transaction can be committed.
351          * Protected by journal_datalist_lock.
352          */
353         struct journal_head *   t_async_datalist;
354         
355         /* Doubly-linked circular list of all forget buffers (superceded
356            buffers which we can un-checkpoint once this transaction
357            commits) */
358         struct journal_head *   t_forget;
359         
360         /*
361          * Doubly-linked circular list of all buffers still to be
362          * flushed before this transaction can be checkpointed.
363          */
364         /* Protected by journal_datalist_lock */
365         struct journal_head *   t_checkpoint_list;
366         
367         /* Doubly-linked circular list of temporary buffers currently
368            undergoing IO in the log */
369         struct journal_head *   t_iobuf_list;
370         
371         /* Doubly-linked circular list of metadata buffers being
372            shadowed by log IO.  The IO buffers on the iobuf list and the
373            shadow buffers on this list match each other one for one at
374            all times. */
375         struct journal_head *   t_shadow_list;
376         
377         /* Doubly-linked circular list of control buffers being written
378            to the log. */
379         struct journal_head *   t_log_list;
380         
381         /* Number of outstanding updates running on this transaction */
382         int                     t_updates;
383
384         /* Number of buffers reserved for use by all handles in this
385          * transaction handle but not yet modified. */
386         int                     t_outstanding_credits;
387         
388         /*
389          * Forward and backward links for the circular list of all
390          * transactions awaiting checkpoint.
391          */
392         /* Protected by journal_datalist_lock */
393         transaction_t           *t_cpnext, *t_cpprev;
394
395         /* When will the transaction expire (become due for commit), in
396          * jiffies ? */
397         unsigned long           t_expires;
398
399         /* How many handles used this transaction? */
400         int t_handle_count;
401 };
402
403
404 /* The journal_t maintains all of the journaling state information for a
405  * single filesystem.  It is linked to from the fs superblock structure.
406  * 
407  * We use the journal_t to keep track of all outstanding transaction
408  * activity on the filesystem, and to manage the state of the log
409  * writing process. */
410
411 struct journal_s
412 {
413         /* General journaling state flags */
414         unsigned long           j_flags;
415
416         /* Is there an outstanding uncleared error on the journal (from
417          * a prior abort)? */
418         int                     j_errno;
419         
420         /* The superblock buffer */
421         struct buffer_head *    j_sb_buffer;
422         journal_superblock_t *  j_superblock;
423
424         /* Version of the superblock format */
425         int                     j_format_version;
426
427         /* Number of processes waiting to create a barrier lock */
428         int                     j_barrier_count;
429         
430         /* The barrier lock itself */
431         struct semaphore        j_barrier;
432         
433         /* Transactions: The current running transaction... */
434         transaction_t *         j_running_transaction;
435         
436         /* ... the transaction we are pushing to disk ... */
437         transaction_t *         j_committing_transaction;
438         
439         /* ... and a linked circular list of all transactions waiting
440          * for checkpointing. */
441         /* Protected by journal_datalist_lock */
442         transaction_t *         j_checkpoint_transactions;
443
444         /* Wait queue for waiting for a locked transaction to start
445            committing, or for a barrier lock to be released */
446         wait_queue_head_t       j_wait_transaction_locked;
447         
448         /* Wait queue for waiting for checkpointing to complete */
449         wait_queue_head_t       j_wait_logspace;
450         
451         /* Wait queue for waiting for commit to complete */
452         wait_queue_head_t       j_wait_done_commit;
453         
454         /* Wait queue to trigger checkpointing */
455         wait_queue_head_t       j_wait_checkpoint;
456         
457         /* Wait queue to trigger commit */
458         wait_queue_head_t       j_wait_commit;
459         
460         /* Wait queue to wait for updates to complete */
461         wait_queue_head_t       j_wait_updates;
462
463         /* Semaphore for locking against concurrent checkpoints */
464         struct semaphore        j_checkpoint_sem;
465
466         /* The main journal lock, used by lock_journal() */
467         struct semaphore        j_sem;
468                 
469         /* Journal head: identifies the first unused block in the journal. */
470         unsigned long           j_head;
471         
472         /* Journal tail: identifies the oldest still-used block in the
473          * journal. */
474         unsigned long           j_tail;
475
476         /* Journal free: how many free blocks are there in the journal? */
477         unsigned long           j_free;
478
479         /* Journal start and end: the block numbers of the first usable
480          * block and one beyond the last usable block in the journal. */
481         unsigned long           j_first, j_last;
482
483         /* Device, blocksize and starting block offset for the location
484          * where we store the journal. */
485         kdev_t                  j_dev;
486         int                     j_blocksize;
487         unsigned int            j_blk_offset;
488
489         /* Device which holds the client fs.  For internal journal this
490          * will be equal to j_dev. */
491         kdev_t                  j_fs_dev;
492
493         /* Total maximum capacity of the journal region on disk. */
494         unsigned int            j_maxlen;
495
496         /* Optional inode where we store the journal.  If present, all
497          * journal block numbers are mapped into this inode via
498          * bmap(). */
499         struct inode *          j_inode;
500
501         /* Sequence number of the oldest transaction in the log */
502         tid_t                   j_tail_sequence;
503         /* Sequence number of the next transaction to grant */
504         tid_t                   j_transaction_sequence;
505         /* Sequence number of the most recently committed transaction */
506         tid_t                   j_commit_sequence;
507         /* Sequence number of the most recent transaction wanting commit */
508         tid_t                   j_commit_request;
509
510         /* Journal uuid: identifies the object (filesystem, LVM volume
511          * etc) backed by this journal.  This will eventually be
512          * replaced by an array of uuids, allowing us to index multiple
513          * devices within a single journal and to perform atomic updates
514          * across them.  */
515
516         __u8                    j_uuid[16];
517
518         /* Pointer to the current commit thread for this journal */
519         struct task_struct *    j_task;
520
521         /* Maximum number of metadata buffers to allow in a single
522          * compound commit transaction */
523         int                     j_max_transaction_buffers;
524
525         /* What is the maximum transaction lifetime before we begin a
526          * commit? */
527         unsigned long           j_commit_interval;
528
529         /* The timer used to wakeup the commit thread: */
530         struct timer_list *     j_commit_timer;
531         int                     j_commit_timer_active;
532
533         /* Link all journals together - system-wide */
534         struct list_head        j_all_journals;
535
536         /* The revoke table: maintains the list of revoked blocks in the
537            current transaction. */
538         struct jbd_revoke_table_s *j_revoke;
539 };
540
541 /* 
542  * Journal flag definitions 
543  */
544 #define JFS_UNMOUNT     0x001   /* Journal thread is being destroyed */
545 #define JFS_ABORT       0x002   /* Journaling has been aborted for errors. */
546 #define JFS_ACK_ERR     0x004   /* The errno in the sb has been acked */
547 #define JFS_FLUSHED     0x008   /* The journal superblock has been flushed */
548 #define JFS_LOADED      0x010   /* The journal superblock has been loaded */
549
550 /* 
551  * Function declarations for the journaling transaction and buffer
552  * management
553  */
554
555 /* Filing buffers */
556 extern void __journal_unfile_buffer(struct journal_head *);
557 extern void journal_unfile_buffer(struct journal_head *);
558 extern void __journal_refile_buffer(struct journal_head *);
559 extern void journal_refile_buffer(struct journal_head *);
560 extern void __journal_file_buffer(struct journal_head *, transaction_t *, int);
561 extern void __journal_free_buffer(struct journal_head *bh);
562 extern void journal_file_buffer(struct journal_head *, transaction_t *, int);
563 extern void __journal_clean_data_list(transaction_t *transaction);
564
565 /* Log buffer allocation */
566 extern struct journal_head * journal_get_descriptor_buffer(journal_t *);
567 extern unsigned long journal_next_log_block(journal_t *);
568
569 /* Commit management */
570 extern void journal_commit_transaction(journal_t *);
571
572 /* Checkpoint list management */
573 int __journal_clean_checkpoint_list(journal_t *journal);
574 extern void journal_remove_checkpoint(struct journal_head *);
575 extern void __journal_remove_checkpoint(struct journal_head *);
576 extern void journal_insert_checkpoint(struct journal_head *, transaction_t *);
577 extern void __journal_insert_checkpoint(struct journal_head *,transaction_t *);
578
579 /* Buffer IO */
580 extern int 
581 journal_write_metadata_buffer(transaction_t       *transaction,
582                               struct journal_head  *jh_in,
583                               struct journal_head **jh_out,
584                               int                  blocknr);
585
586 /* Transaction locking */
587 extern void             __wait_on_journal (journal_t *);
588
589 /*
590  * Journal locking.
591  *
592  * We need to lock the journal during transaction state changes so that
593  * nobody ever tries to take a handle on the running transaction while
594  * we are in the middle of moving it to the commit phase.  
595  *
596  * Note that the locking is completely interrupt unsafe.  We never touch
597  * journal structures from interrupts.
598  *
599  * In 2.2, the BKL was required for lock_journal.  This is no longer
600  * the case.
601  */
602
603 static inline void lock_journal(journal_t *journal)
604 {
605         down(&journal->j_sem);
606 }
607
608 /* This returns zero if we acquired the semaphore */
609 static inline int try_lock_journal(journal_t * journal)
610 {
611         return down_trylock(&journal->j_sem);
612 }
613
614 static inline void unlock_journal(journal_t * journal)
615 {
616         up(&journal->j_sem);
617 }
618
619
620 static inline handle_t *journal_current_handle(void)
621 {
622         return current->journal_info;
623 }
624
625 /* The journaling code user interface:
626  *
627  * Create and destroy handles
628  * Register buffer modifications against the current transaction. 
629  */
630
631 extern handle_t *journal_start(journal_t *, int nblocks);
632 extern handle_t *journal_try_start(journal_t *, int nblocks);
633 extern int       journal_restart (handle_t *, int nblocks);
634 extern int       journal_extend (handle_t *, int nblocks);
635 extern int       journal_get_write_access (handle_t *, struct buffer_head *);
636 extern int       journal_get_create_access (handle_t *, struct buffer_head *);
637 extern int       journal_get_undo_access (handle_t *, struct buffer_head *);
638 extern int       journal_dirty_data (handle_t *,
639                                 struct buffer_head *, int async);
640 extern int       journal_dirty_metadata (handle_t *, struct buffer_head *);
641 extern void      journal_release_buffer (handle_t *, struct buffer_head *);
642 extern void      journal_forget (handle_t *, struct buffer_head *);
643 extern void      journal_sync_buffer (struct buffer_head *);
644 extern int       journal_flushpage(journal_t *, struct page *, unsigned long);
645 extern int       journal_try_to_free_buffers(journal_t *, struct page *, int);
646 extern int       journal_stop(handle_t *);
647 extern int       journal_flush (journal_t *);
648
649 extern void      journal_lock_updates (journal_t *);
650 extern void      journal_unlock_updates (journal_t *);
651
652 extern journal_t * journal_init_dev(kdev_t dev, kdev_t fs_dev,
653                                 int start, int len, int bsize);
654 extern journal_t * journal_init_inode (struct inode *);
655 extern int         journal_update_format (journal_t *);
656 extern int         journal_check_used_features 
657                    (journal_t *, unsigned long, unsigned long, unsigned long);
658 extern int         journal_check_available_features 
659                    (journal_t *, unsigned long, unsigned long, unsigned long);
660 extern int         journal_set_features 
661                    (journal_t *, unsigned long, unsigned long, unsigned long);
662 extern int         journal_create     (journal_t *);
663 extern int         journal_load       (journal_t *journal);
664 extern void        journal_destroy    (journal_t *);
665 extern int         journal_recover    (journal_t *journal);
666 extern int         journal_wipe       (journal_t *, int);
667 extern int         journal_skip_recovery (journal_t *);
668 extern void        journal_update_superblock (journal_t *, int);
669 extern void        __journal_abort      (journal_t *);
670 extern void        journal_abort      (journal_t *, int);
671 extern int         journal_errno      (journal_t *);
672 extern void        journal_ack_err    (journal_t *);
673 extern int         journal_clear_err  (journal_t *);
674 extern unsigned long journal_bmap(journal_t *journal, unsigned long blocknr);
675 extern int          journal_force_commit(journal_t *journal);
676
677 /*
678  * journal_head management
679  */
680 extern struct journal_head
681                 *journal_add_journal_head(struct buffer_head *bh);
682 extern void     journal_remove_journal_head(struct buffer_head *bh);
683 extern void     __journal_remove_journal_head(struct buffer_head *bh);
684 extern void     journal_unlock_journal_head(struct journal_head *jh);
685
686 /* Primary revoke support */
687 #define JOURNAL_REVOKE_DEFAULT_HASH 256
688 extern int         journal_init_revoke(journal_t *, int);
689 extern void        journal_destroy_revoke_caches(void);
690 extern int         journal_init_revoke_caches(void);
691
692 extern void        journal_destroy_revoke(journal_t *);
693 extern int         journal_revoke (handle_t *,
694                                 unsigned long, struct buffer_head *);
695 extern int         journal_cancel_revoke(handle_t *, struct journal_head *);
696 extern void        journal_write_revoke_records(journal_t *, transaction_t *);
697
698 /* Recovery revoke support */
699 extern int         journal_set_revoke(journal_t *, unsigned long, tid_t);
700 extern int         journal_test_revoke(journal_t *, unsigned long, tid_t);
701 extern void        journal_clear_revoke(journal_t *);
702 extern void        journal_brelse_array(struct buffer_head *b[], int n);
703
704 /* The log thread user interface:
705  *
706  * Request space in the current transaction, and force transaction commit
707  * transitions on demand.
708  */
709
710 extern int      log_space_left (journal_t *); /* Called with journal locked */
711 extern tid_t    log_start_commit (journal_t *, transaction_t *);
712 extern void     log_wait_commit (journal_t *, tid_t);
713 extern int      log_do_checkpoint (journal_t *, int);
714
715 extern void     log_wait_for_space(journal_t *, int nblocks);
716 extern void     __journal_drop_transaction(journal_t *, transaction_t *);
717 extern int      cleanup_journal_tail(journal_t *);
718
719 /* Reduce journal memory usage by flushing */
720 extern void shrink_journal_memory(void);
721
722 /* Debugging code only: */
723
724 #define jbd_ENOSYS() \
725 do {                                                                  \
726         printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \
727         current->state = TASK_UNINTERRUPTIBLE;                        \
728         schedule();                                                   \
729 } while (1)
730
731 /*
732  * is_journal_abort
733  *
734  * Simple test wrapper function to test the JFS_ABORT state flag.  This
735  * bit, when set, indicates that we have had a fatal error somewhere,
736  * either inside the journaling layer or indicated to us by the client
737  * (eg. ext3), and that we and should not commit any further
738  * transactions.  
739  */
740
741 static inline int is_journal_aborted(journal_t *journal)
742 {
743         return journal->j_flags & JFS_ABORT;
744 }
745
746 static inline int is_handle_aborted(handle_t *handle)
747 {
748         if (handle->h_aborted)
749                 return 1;
750         return is_journal_aborted(handle->h_transaction->t_journal);
751 }
752
753 static inline void journal_abort_handle(handle_t *handle)
754 {
755         handle->h_aborted = 1;
756 }
757
758 /* Not all architectures define BUG() */
759 #ifndef BUG
760  #define BUG() do { \
761         printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
762         * ((char *) 0) = 0; \
763  } while (0)
764 #endif /* BUG */
765
766 #else
767
768 extern int         journal_recover    (journal_t *journal);
769 extern int         journal_skip_recovery (journal_t *);
770
771 /* Primary revoke support */
772 extern int         journal_init_revoke(journal_t *, int);
773 extern void        journal_destroy_revoke_caches(void);
774 extern int         journal_init_revoke_caches(void);
775
776 /* Recovery revoke support */
777 extern int         journal_set_revoke(journal_t *, unsigned long, tid_t);
778 extern int         journal_test_revoke(journal_t *, unsigned long, tid_t);
779 extern void        journal_clear_revoke(journal_t *);
780 extern void        journal_brelse_array(struct buffer_head *b[], int n);
781
782 extern void        journal_destroy_revoke(journal_t *);
783 #endif /* __KERNEL__   */
784
785 /* Comparison functions for transaction IDs: perform comparisons using
786  * modulo arithmetic so that they work over sequence number wraps. */
787
788 static inline int tid_gt(tid_t x, tid_t y)
789 {
790         int difference = (x - y);
791         return (difference > 0);
792 }
793
794 static inline int tid_geq(tid_t x, tid_t y)
795 {
796         int difference = (x - y);
797         return (difference >= 0);
798 }
799
800 extern int journal_blocks_per_page(struct inode *inode);
801
802 /*
803  * Definitions which augment the buffer_head layer
804  */
805
806 /* journaling buffer types */
807 #define BJ_None         0       /* Not journaled */
808 #define BJ_SyncData     1       /* Normal data: flush before commit */
809 #define BJ_AsyncData    2       /* writepage data: wait on it before commit */
810 #define BJ_Metadata     3       /* Normal journaled metadata */
811 #define BJ_Forget       4       /* Buffer superceded by this transaction */
812 #define BJ_IO           5       /* Buffer is for temporary IO use */
813 #define BJ_Shadow       6       /* Buffer contents being shadowed to the log */
814 #define BJ_LogCtl       7       /* Buffer contains log descriptors */
815 #define BJ_Reserved     8       /* Buffer is reserved for access by journal */
816 #define BJ_Types        9
817  
818 extern int jbd_blocks_per_page(struct inode *inode);
819
820 #ifdef __KERNEL__
821
822 extern spinlock_t jh_splice_lock;
823 /*
824  * Once `expr1' has been found true, take jh_splice_lock
825  * and then reevaluate everything.
826  */
827 #define SPLICE_LOCK(expr1, expr2)                               \
828         ({                                                      \
829                 int ret = (expr1);                              \
830                 if (ret) {                                      \
831                         spin_lock(&jh_splice_lock);             \
832                         ret = (expr1) && (expr2);               \
833                         spin_unlock(&jh_splice_lock);           \
834                 }                                               \
835                 ret;                                            \
836         })
837
838 /*
839  * A number of buffer state predicates.  They test for
840  * buffer_jbd() because they are used in core kernel code.
841  *
842  * These will be racy on SMP unless we're *sure* that the
843  * buffer won't be detached from the journalling system
844  * in parallel.
845  */
846
847 /* Return true if the buffer is on journal list `list' */
848 static inline int buffer_jlist_eq(struct buffer_head *bh, int list)
849 {
850         return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list);
851 }
852
853 /* Return true if this bufer is dirty wrt the journal */
854 static inline int buffer_jdirty(struct buffer_head *bh)
855 {
856         return buffer_jbd(bh) && __buffer_state(bh, JBDDirty);
857 }
858
859 /* Return true if it's a data buffer which journalling is managing */
860 static inline int buffer_jbd_data(struct buffer_head *bh)
861 {
862         return SPLICE_LOCK(buffer_jbd(bh),
863                         bh2jh(bh)->b_jlist == BJ_SyncData ||
864                         bh2jh(bh)->b_jlist == BJ_AsyncData);
865 }
866
867 #ifdef CONFIG_SMP
868 #define assert_spin_locked(lock)        J_ASSERT(spin_is_locked(lock))
869 #else
870 #define assert_spin_locked(lock)        do {} while(0)
871 #endif
872
873 #define buffer_trace_init(bh)   do {} while (0)
874 #define print_buffer_fields(bh) do {} while (0)
875 #define print_buffer_trace(bh)  do {} while (0)
876 #define BUFFER_TRACE(bh, info)  do {} while (0)
877 #define BUFFER_TRACE2(bh, bh2, info)    do {} while (0)
878 #define JBUFFER_TRACE(jh, info) do {} while (0)
879
880 #endif  /* __KERNEL__ */
881
882 #endif  /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */
883
884 /*
885  * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD
886  * go here.
887  */
888
889 #if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE))
890
891 #define J_ASSERT(expr)                  do {} while (0)
892 #define J_ASSERT_BH(bh, expr)           do {} while (0)
893 #define buffer_jbd(bh)                  0
894 #define buffer_jlist_eq(bh, val)        0
895 #define journal_buffer_journal_lru(bh)  0
896
897 #endif  /* defined(__KERNEL__) && !defined(CONFIG_JBD) */
898 #endif  /* _LINUX_JBD_H */