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