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