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