blob: 8a5de5e3e15524d7a4bde537c50d5c0123f795c7 [file] [log] [blame]
Mike Frysinger1fd98e02005-05-09 22:10:42 +00001/*
2 * linux/include/linux/jbd.h
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00003 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +00004 * 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#ifndef __GNUC__
34#define __FUNCTION__ ""
35#endif
36
37#define journal_oom_retry 1
38
39#ifdef __STDC__
40#ifdef __CONFIG_JBD_DEBUG__E2FS
41/*
42 * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
43 * consistency checks. By default we don't do this unless
44 * __CONFIG_JBD_DEBUG__E2FS is on.
45 */
46#define JBD_EXPENSIVE_CHECKING
47extern int journal_enable_debug;
48
49#define jbd_debug(n, f, a...) \
50 do { \
51 if ((n) <= journal_enable_debug) { \
52 printk (KERN_DEBUG "(%s, %d): %s: ", \
53 __FILE__, __LINE__, __FUNCTION__); \
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000054 printk (f, ## a); \
Mike Frysinger1fd98e02005-05-09 22:10:42 +000055 } \
56 } while (0)
57#else
58#ifdef __GNUC__
59#define jbd_debug(f, a...) /**/
60#else
61#define jbd_debug(f, ...) /**/
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000062#endif
Mike Frysinger1fd98e02005-05-09 22:10:42 +000063#endif
64#else
65#define jbd_debug(x) /* AIX doesn't do STDC */
66#endif
67
68extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry);
69#define jbd_kmalloc(size, flags) \
70 __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
71#define jbd_rep_kmalloc(size, flags) \
72 __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)
73
74#define JFS_MIN_JOURNAL_BLOCKS 1024
75
76#ifdef __KERNEL__
77typedef struct handle_s handle_t; /* Atomic operation type */
78typedef struct journal_s journal_t; /* Journal control structure */
79#endif
80
81/*
82 * Internal structures used by the logging mechanism:
83 */
84
85#define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
86
87/*
88 * On-disk structures
89 */
90
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000091/*
Mike Frysinger1fd98e02005-05-09 22:10:42 +000092 * Descriptor block types:
93 */
94
95#define JFS_DESCRIPTOR_BLOCK 1
96#define JFS_COMMIT_BLOCK 2
97#define JFS_SUPERBLOCK_V1 3
98#define JFS_SUPERBLOCK_V2 4
99#define JFS_REVOKE_BLOCK 5
100
101/*
102 * Standard header for all descriptor blocks:
103 */
104typedef struct journal_header_s
105{
106 __u32 h_magic;
107 __u32 h_blocktype;
108 __u32 h_sequence;
109} journal_header_t;
110
111
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000112/*
113 * The block tag: used to describe a single buffer in the journal
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000114 */
115typedef struct journal_block_tag_s
116{
117 __u32 t_blocknr; /* The on-disk block number */
118 __u32 t_flags; /* See below */
119} journal_block_tag_t;
120
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000121/*
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000122 * The revoke descriptor: used on disk to describe a series of blocks to
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000123 * be revoked from the log
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000124 */
125typedef struct journal_revoke_header_s
126{
127 journal_header_t r_header;
128 int r_count; /* Count of bytes used in the block */
129} journal_revoke_header_t;
130
131
132/* Definitions for the journal tag flags word: */
133#define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */
134#define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */
135#define JFS_FLAG_DELETED 4 /* block deleted by this transaction */
136#define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
137
138
139/*
140 * The journal superblock. All fields are in big-endian byte order.
141 */
142typedef struct journal_superblock_s
143{
144/* 0x0000 */
145 journal_header_t s_header;
146
147/* 0x000C */
148 /* Static information describing the journal */
149 __u32 s_blocksize; /* journal device blocksize */
150 __u32 s_maxlen; /* total blocks in journal file */
151 __u32 s_first; /* first block of log information */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000152
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000153/* 0x0018 */
154 /* Dynamic information describing the current state of the log */
155 __u32 s_sequence; /* first commit ID expected in log */
156 __u32 s_start; /* blocknr of start of log */
157
158/* 0x0020 */
159 /* Error value, as set by journal_abort(). */
160 __s32 s_errno;
161
162/* 0x0024 */
163 /* Remaining fields are only valid in a version-2 superblock */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000164 __u32 s_feature_compat; /* compatible feature set */
165 __u32 s_feature_incompat; /* incompatible feature set */
166 __u32 s_feature_ro_compat; /* readonly-compatible feature set */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000167/* 0x0030 */
168 __u8 s_uuid[16]; /* 128-bit uuid for journal */
169
170/* 0x0040 */
171 __u32 s_nr_users; /* Nr of filesystems sharing log */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000172
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000173 __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000174
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000175/* 0x0048 */
176 __u32 s_max_transaction; /* Limit of journal blocks per trans.*/
177 __u32 s_max_trans_data; /* Limit of data blocks per trans. */
178
179/* 0x0050 */
180 __u32 s_padding[44];
181
182/* 0x0100 */
183 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
184/* 0x0400 */
185} journal_superblock_t;
186
187#define JFS_HAS_COMPAT_FEATURE(j,mask) \
188 ((j)->j_format_version >= 2 && \
189 ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
190#define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \
191 ((j)->j_format_version >= 2 && \
192 ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
193#define JFS_HAS_INCOMPAT_FEATURE(j,mask) \
194 ((j)->j_format_version >= 2 && \
195 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
196
197#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001
198
199/* Features known to this kernel version: */
200#define JFS_KNOWN_COMPAT_FEATURES 0
201#define JFS_KNOWN_ROCOMPAT_FEATURES 0
202#define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE
203
204#ifdef __KERNEL__
205
206#include <linux/fs.h>
207#include <linux/sched.h>
208
209#define JBD_ASSERTIONS
210#ifdef JBD_ASSERTIONS
211#define J_ASSERT(assert) \
212do { \
213 if (!(assert)) { \
214 printk (KERN_EMERG \
215 "Assertion failure in %s() at %s:%d: \"%s\"\n", \
216 __FUNCTION__, __FILE__, __LINE__, # assert); \
217 BUG(); \
218 } \
219} while (0)
220
221#if defined(CONFIG_BUFFER_DEBUG)
222void buffer_assertion_failure(struct buffer_head *bh);
223#define J_ASSERT_BH(bh, expr) \
224 do { \
225 if (!(expr)) \
226 buffer_assertion_failure(bh); \
227 J_ASSERT(expr); \
228 } while (0)
229#define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr)
230#else
231#define J_ASSERT_BH(bh, expr) J_ASSERT(expr)
232#define J_ASSERT_JH(jh, expr) J_ASSERT(expr)
233#endif
234
235#else
236#define J_ASSERT(assert)
237#endif /* JBD_ASSERTIONS */
238
239enum jbd_state_bits {
240 BH_JWrite
241 = BH_PrivateStart, /* 1 if being written to log (@@@ DEBUGGING) */
242 BH_Freed, /* 1 if buffer has been freed (truncated) */
243 BH_Revoked, /* 1 if buffer has been revoked from the log */
244 BH_RevokeValid, /* 1 if buffer revoked flag is valid */
245 BH_JBDDirty, /* 1 if buffer is dirty but journaled */
246};
247
248/* Return true if the buffer is one which JBD is managing */
249static inline int buffer_jbd(struct buffer_head *bh)
250{
251 return __buffer_state(bh, JBD);
252}
253
254static inline struct buffer_head *jh2bh(struct journal_head *jh)
255{
256 return jh->b_bh;
257}
258
259static inline struct journal_head *bh2jh(struct buffer_head *bh)
260{
261 return bh->b_private;
262}
263
264struct jbd_revoke_table_s;
265
266/* The handle_t type represents a single atomic update being performed
267 * by some process. All filesystem modifications made by the process go
268 * through this handle. Recursive operations (such as quota operations)
269 * are gathered into a single update.
270 *
271 * The buffer credits field is used to account for journaled buffers
272 * being modified by the running process. To ensure that there is
273 * enough log space for all outstanding operations, we need to limit the
274 * number of outstanding buffers possible at any time. When the
275 * operation completes, any buffer credits not used are credited back to
276 * the transaction, so that at all times we know how many buffers the
277 * outstanding updates on a transaction might possibly touch. */
278
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000279struct handle_s
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000280{
281 /* Which compound transaction is this update a part of? */
282 transaction_t * h_transaction;
283
284 /* Number of remaining buffers we are allowed to dirty: */
285 int h_buffer_credits;
286
287 /* Reference count on this handle */
288 int h_ref;
289
290 /* Field for caller's use to track errors through large fs
291 operations */
292 int h_err;
293
294 /* Flags */
295 unsigned int h_sync: 1; /* sync-on-close */
296 unsigned int h_jdata: 1; /* force data journaling */
297 unsigned int h_aborted: 1; /* fatal error on handle */
298};
299
300
301/* The transaction_t type is the guts of the journaling mechanism. It
302 * tracks a compound transaction through its various states:
303 *
304 * RUNNING: accepting new updates
305 * LOCKED: Updates still running but we don't accept new ones
306 * RUNDOWN: Updates are tidying up but have finished requesting
307 * new buffers to modify (state not used for now)
308 * FLUSH: All updates complete, but we are still writing to disk
309 * COMMIT: All data on disk, writing commit record
310 * FINISHED: We still have to keep the transaction for checkpointing.
311 *
312 * The transaction keeps track of all of the buffers modified by a
313 * running transaction, and all of the buffers committed but not yet
314 * flushed to home for finished transactions.
315 */
316
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000317struct transaction_s
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000318{
319 /* Pointer to the journal for this transaction. */
320 journal_t * t_journal;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000321
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000322 /* Sequence number for this transaction */
323 tid_t t_tid;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000324
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000325 /* Transaction's current state */
326 enum {
327 T_RUNNING,
328 T_LOCKED,
329 T_RUNDOWN,
330 T_FLUSH,
331 T_COMMIT,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000332 T_FINISHED
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000333 } t_state;
334
335 /* Where in the log does this transaction's commit start? */
336 unsigned long t_log_start;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000337
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000338 /* Doubly-linked circular list of all inodes owned by this
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000339 transaction */ /* AKPM: unused */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000340 struct inode * t_ilist;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000341
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000342 /* Number of buffers on the t_buffers list */
343 int t_nr_buffers;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000344
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000345 /* Doubly-linked circular list of all buffers reserved but not
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000346 yet modified by this transaction */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000347 struct journal_head * t_reserved_list;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000348
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000349 /* Doubly-linked circular list of all metadata buffers owned by this
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000350 transaction */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000351 struct journal_head * t_buffers;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000352
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000353 /*
354 * Doubly-linked circular list of all data buffers still to be
355 * flushed before this transaction can be committed.
356 * Protected by journal_datalist_lock.
357 */
358 struct journal_head * t_sync_datalist;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000359
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000360 /*
361 * Doubly-linked circular list of all writepage data buffers
362 * still to be written before this transaction can be committed.
363 * Protected by journal_datalist_lock.
364 */
365 struct journal_head * t_async_datalist;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000366
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000367 /* Doubly-linked circular list of all forget buffers (superceded
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000368 buffers which we can un-checkpoint once this transaction
369 commits) */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000370 struct journal_head * t_forget;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000371
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000372 /*
373 * Doubly-linked circular list of all buffers still to be
374 * flushed before this transaction can be checkpointed.
375 */
376 /* Protected by journal_datalist_lock */
377 struct journal_head * t_checkpoint_list;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000378
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000379 /* Doubly-linked circular list of temporary buffers currently
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000380 undergoing IO in the log */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000381 struct journal_head * t_iobuf_list;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000382
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000383 /* Doubly-linked circular list of metadata buffers being
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000384 shadowed by log IO. The IO buffers on the iobuf list and the
385 shadow buffers on this list match each other one for one at
386 all times. */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000387 struct journal_head * t_shadow_list;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000388
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000389 /* Doubly-linked circular list of control buffers being written
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000390 to the log. */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000391 struct journal_head * t_log_list;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000392
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000393 /* Number of outstanding updates running on this transaction */
394 int t_updates;
395
396 /* Number of buffers reserved for use by all handles in this
397 * transaction handle but not yet modified. */
398 int t_outstanding_credits;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000399
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000400 /*
401 * Forward and backward links for the circular list of all
402 * transactions awaiting checkpoint.
403 */
404 /* Protected by journal_datalist_lock */
405 transaction_t *t_cpnext, *t_cpprev;
406
407 /* When will the transaction expire (become due for commit), in
408 * jiffies ? */
409 unsigned long t_expires;
410
411 /* How many handles used this transaction? */
412 int t_handle_count;
413};
414
415
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.
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000418 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000419 * 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. */
422
423struct journal_s
424{
425 /* General journaling state flags */
426 unsigned long j_flags;
427
428 /* Is there an outstanding uncleared error on the journal (from
429 * a prior abort)? */
430 int j_errno;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000431
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000432 /* The superblock buffer */
433 struct buffer_head * j_sb_buffer;
434 journal_superblock_t * j_superblock;
435
436 /* Version of the superblock format */
437 int j_format_version;
438
439 /* Number of processes waiting to create a barrier lock */
440 int j_barrier_count;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000441
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000442 /* The barrier lock itself */
443 struct semaphore j_barrier;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000444
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000445 /* Transactions: The current running transaction... */
446 transaction_t * j_running_transaction;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000447
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000448 /* ... the transaction we are pushing to disk ... */
449 transaction_t * j_committing_transaction;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000450
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000451 /* ... and a linked circular list of all transactions waiting
452 * for checkpointing. */
453 /* Protected by journal_datalist_lock */
454 transaction_t * j_checkpoint_transactions;
455
456 /* Wait queue for waiting for a locked transaction to start
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000457 committing, or for a barrier lock to be released */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000458 wait_queue_head_t j_wait_transaction_locked;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000459
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000460 /* Wait queue for waiting for checkpointing to complete */
461 wait_queue_head_t j_wait_logspace;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000462
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000463 /* Wait queue for waiting for commit to complete */
464 wait_queue_head_t j_wait_done_commit;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000465
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000466 /* Wait queue to trigger checkpointing */
467 wait_queue_head_t j_wait_checkpoint;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000468
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000469 /* Wait queue to trigger commit */
470 wait_queue_head_t j_wait_commit;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000471
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000472 /* Wait queue to wait for updates to complete */
473 wait_queue_head_t j_wait_updates;
474
475 /* Semaphore for locking against concurrent checkpoints */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000476 struct semaphore j_checkpoint_sem;
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000477
478 /* The main journal lock, used by lock_journal() */
479 struct semaphore j_sem;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000480
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000481 /* Journal head: identifies the first unused block in the journal. */
482 unsigned long j_head;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000483
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000484 /* Journal tail: identifies the oldest still-used block in the
485 * journal. */
486 unsigned long j_tail;
487
488 /* Journal free: how many free blocks are there in the journal? */
489 unsigned long j_free;
490
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;
494
495 /* Device, blocksize and starting block offset for the location
496 * where we store the journal. */
497 kdev_t j_dev;
498 int j_blocksize;
499 unsigned int j_blk_offset;
500
501 /* Device which holds the client fs. For internal journal this
502 * will be equal to j_dev. */
503 kdev_t j_fs_dev;
504
505 /* Total maximum capacity of the journal region on disk. */
506 unsigned int j_maxlen;
507
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;
512
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;
521
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. */
527
528 __u8 j_uuid[16];
529
530 /* Pointer to the current commit thread for this journal */
531 struct task_struct * j_task;
532
533 /* Maximum number of metadata buffers to allow in a single
534 * compound commit transaction */
535 int j_max_transaction_buffers;
536
537 /* What is the maximum transaction lifetime before we begin a
538 * commit? */
539 unsigned long j_commit_interval;
540
541 /* The timer used to wakeup the commit thread: */
542 struct timer_list * j_commit_timer;
543 int j_commit_timer_active;
544
545 /* Link all journals together - system-wide */
546 struct list_head j_all_journals;
547
548 /* The revoke table: maintains the list of revoked blocks in the
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000549 current transaction. */
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000550 struct jbd_revoke_table_s *j_revoke;
551};
552
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000553/*
554 * Journal flag definitions
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000555 */
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 */
561
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000562/*
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000563 * Function declarations for the journaling transaction and buffer
564 * management
565 */
566
567/* Filing buffers */
568extern void __journal_unfile_buffer(struct journal_head *);
569extern void journal_unfile_buffer(struct journal_head *);
570extern void __journal_refile_buffer(struct journal_head *);
571extern void journal_refile_buffer(struct journal_head *);
572extern void __journal_file_buffer(struct journal_head *, transaction_t *, int);
573extern void __journal_free_buffer(struct journal_head *bh);
574extern void journal_file_buffer(struct journal_head *, transaction_t *, int);
575extern void __journal_clean_data_list(transaction_t *transaction);
576
577/* Log buffer allocation */
578extern struct journal_head * journal_get_descriptor_buffer(journal_t *);
579extern unsigned long journal_next_log_block(journal_t *);
580
581/* Commit management */
582extern void journal_commit_transaction(journal_t *);
583
584/* Checkpoint list management */
585int __journal_clean_checkpoint_list(journal_t *journal);
586extern void journal_remove_checkpoint(struct journal_head *);
587extern void __journal_remove_checkpoint(struct journal_head *);
588extern void journal_insert_checkpoint(struct journal_head *, transaction_t *);
589extern void __journal_insert_checkpoint(struct journal_head *,transaction_t *);
590
591/* Buffer IO */
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000592extern int
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000593journal_write_metadata_buffer(transaction_t *transaction,
594 struct journal_head *jh_in,
595 struct journal_head **jh_out,
596 int blocknr);
597
598/* Transaction locking */
599extern void __wait_on_journal (journal_t *);
600
601/*
602 * Journal locking.
603 *
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
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000606 * we are in the middle of moving it to the commit phase.
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000607 *
608 * Note that the locking is completely interrupt unsafe. We never touch
609 * journal structures from interrupts.
610 *
611 * In 2.2, the BKL was required for lock_journal. This is no longer
612 * the case.
613 */
614
615static inline void lock_journal(journal_t *journal)
616{
617 down(&journal->j_sem);
618}
619
620/* This returns zero if we acquired the semaphore */
621static inline int try_lock_journal(journal_t * journal)
622{
623 return down_trylock(&journal->j_sem);
624}
625
626static inline void unlock_journal(journal_t * journal)
627{
628 up(&journal->j_sem);
629}
630
631
632static inline handle_t *journal_current_handle(void)
633{
634 return current->journal_info;
635}
636
637/* The journaling code user interface:
638 *
639 * Create and destroy handles
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000640 * Register buffer modifications against the current transaction.
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000641 */
642
643extern handle_t *journal_start(journal_t *, int nblocks);
644extern handle_t *journal_try_start(journal_t *, int nblocks);
645extern int journal_restart (handle_t *, int nblocks);
646extern int journal_extend (handle_t *, int nblocks);
647extern int journal_get_write_access (handle_t *, struct buffer_head *);
648extern int journal_get_create_access (handle_t *, struct buffer_head *);
649extern int journal_get_undo_access (handle_t *, struct buffer_head *);
650extern int journal_dirty_data (handle_t *,
651 struct buffer_head *, int async);
652extern int journal_dirty_metadata (handle_t *, struct buffer_head *);
653extern void journal_release_buffer (handle_t *, struct buffer_head *);
654extern void journal_forget (handle_t *, struct buffer_head *);
655extern void journal_sync_buffer (struct buffer_head *);
656extern int journal_flushpage(journal_t *, struct page *, unsigned long);
657extern int journal_try_to_free_buffers(journal_t *, struct page *, int);
658extern int journal_stop(handle_t *);
659extern int journal_flush (journal_t *);
660
661extern void journal_lock_updates (journal_t *);
662extern void journal_unlock_updates (journal_t *);
663
664extern journal_t * journal_init_dev(kdev_t dev, kdev_t fs_dev,
665 int start, int len, int bsize);
666extern journal_t * journal_init_inode (struct inode *);
667extern int journal_update_format (journal_t *);
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000668extern int journal_check_used_features
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000669 (journal_t *, unsigned long, unsigned long, unsigned long);
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000670extern int journal_check_available_features
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000671 (journal_t *, unsigned long, unsigned long, unsigned long);
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000672extern int journal_set_features
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000673 (journal_t *, unsigned long, unsigned long, unsigned long);
674extern int journal_create (journal_t *);
675extern int journal_load (journal_t *journal);
676extern void journal_destroy (journal_t *);
677extern int journal_recover (journal_t *journal);
678extern int journal_wipe (journal_t *, int);
679extern int journal_skip_recovery (journal_t *);
680extern void journal_update_superblock (journal_t *, int);
681extern void __journal_abort (journal_t *);
682extern void journal_abort (journal_t *, int);
683extern int journal_errno (journal_t *);
684extern void journal_ack_err (journal_t *);
685extern int journal_clear_err (journal_t *);
686extern unsigned long journal_bmap(journal_t *journal, unsigned long blocknr);
687extern int journal_force_commit(journal_t *journal);
688
689/*
690 * journal_head management
691 */
692extern struct journal_head
693 *journal_add_journal_head(struct buffer_head *bh);
694extern void journal_remove_journal_head(struct buffer_head *bh);
695extern void __journal_remove_journal_head(struct buffer_head *bh);
696extern void journal_unlock_journal_head(struct journal_head *jh);
697
698/* Primary revoke support */
699#define JOURNAL_REVOKE_DEFAULT_HASH 256
700extern int journal_init_revoke(journal_t *, int);
701extern void journal_destroy_revoke_caches(void);
702extern int journal_init_revoke_caches(void);
703
704extern void journal_destroy_revoke(journal_t *);
705extern int journal_revoke (handle_t *,
706 unsigned long, struct buffer_head *);
707extern int journal_cancel_revoke(handle_t *, struct journal_head *);
708extern void journal_write_revoke_records(journal_t *, transaction_t *);
709
710/* Recovery revoke support */
711extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
712extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
713extern void journal_clear_revoke(journal_t *);
714extern void journal_brelse_array(struct buffer_head *b[], int n);
715
716/* The log thread user interface:
717 *
718 * Request space in the current transaction, and force transaction commit
719 * transitions on demand.
720 */
721
722extern int log_space_left (journal_t *); /* Called with journal locked */
723extern tid_t log_start_commit (journal_t *, transaction_t *);
724extern void log_wait_commit (journal_t *, tid_t);
725extern int log_do_checkpoint (journal_t *, int);
726
727extern void log_wait_for_space(journal_t *, int nblocks);
728extern void __journal_drop_transaction(journal_t *, transaction_t *);
729extern int cleanup_journal_tail(journal_t *);
730
731/* Reduce journal memory usage by flushing */
732extern void shrink_journal_memory(void);
733
734/* Debugging code only: */
735
736#define jbd_ENOSYS() \
737do { \
738 printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \
739 current->state = TASK_UNINTERRUPTIBLE; \
740 schedule(); \
741} while (1)
742
743/*
744 * is_journal_abort
745 *
746 * Simple test wrapper function to test the JFS_ABORT state flag. This
747 * bit, when set, indicates that we have had a fatal error somewhere,
748 * either inside the journaling layer or indicated to us by the client
749 * (eg. ext3), and that we and should not commit any further
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000750 * transactions.
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000751 */
752
753static inline int is_journal_aborted(journal_t *journal)
754{
755 return journal->j_flags & JFS_ABORT;
756}
757
758static inline int is_handle_aborted(handle_t *handle)
759{
760 if (handle->h_aborted)
761 return 1;
762 return is_journal_aborted(handle->h_transaction->t_journal);
763}
764
765static inline void journal_abort_handle(handle_t *handle)
766{
767 handle->h_aborted = 1;
768}
769
770/* Not all architectures define BUG() */
771#ifndef BUG
772#define BUG() do { \
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000773 printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000774 * ((char *) 0) = 0; \
775 } while (0)
776#endif /* BUG */
777
778#else
779
780extern int journal_recover (journal_t *journal);
781extern int journal_skip_recovery (journal_t *);
782
783/* Primary revoke support */
784extern int journal_init_revoke(journal_t *, int);
785extern void journal_destroy_revoke_caches(void);
786extern int journal_init_revoke_caches(void);
787
788/* Recovery revoke support */
789extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
790extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
791extern void journal_clear_revoke(journal_t *);
792extern void journal_brelse_array(struct buffer_head *b[], int n);
793
794extern void journal_destroy_revoke(journal_t *);
795#endif /* __KERNEL__ */
796
797/* Comparison functions for transaction IDs: perform comparisons using
798 * modulo arithmetic so that they work over sequence number wraps. */
799
800static inline int tid_gt(tid_t x, tid_t y)
801{
802 int difference = (x - y);
803 return (difference > 0);
804}
805
806static inline int tid_geq(tid_t x, tid_t y)
807{
808 int difference = (x - y);
809 return (difference >= 0);
810}
811
812extern int journal_blocks_per_page(struct inode *inode);
813
814/*
815 * Definitions which augment the buffer_head layer
816 */
817
818/* journaling buffer types */
819#define BJ_None 0 /* Not journaled */
820#define BJ_SyncData 1 /* Normal data: flush before commit */
821#define BJ_AsyncData 2 /* writepage data: wait on it before commit */
822#define BJ_Metadata 3 /* Normal journaled metadata */
823#define BJ_Forget 4 /* Buffer superceded by this transaction */
824#define BJ_IO 5 /* Buffer is for temporary IO use */
825#define BJ_Shadow 6 /* Buffer contents being shadowed to the log */
826#define BJ_LogCtl 7 /* Buffer contains log descriptors */
827#define BJ_Reserved 8 /* Buffer is reserved for access by journal */
828#define BJ_Types 9
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000829
Mike Frysinger1fd98e02005-05-09 22:10:42 +0000830extern int jbd_blocks_per_page(struct inode *inode);
831
832#ifdef __KERNEL__
833
834extern spinlock_t jh_splice_lock;
835/*
836 * Once `expr1' has been found true, take jh_splice_lock
837 * and then reevaluate everything.
838 */
839#define SPLICE_LOCK(expr1, expr2) \
840 ({ \
841 int ret = (expr1); \
842 if (ret) { \
843 spin_lock(&jh_splice_lock); \
844 ret = (expr1) && (expr2); \
845 spin_unlock(&jh_splice_lock); \
846 } \
847 ret; \
848 })
849
850/*
851 * A number of buffer state predicates. They test for
852 * buffer_jbd() because they are used in core kernel code.
853 *
854 * These will be racy on SMP unless we're *sure* that the
855 * buffer won't be detached from the journalling system
856 * in parallel.
857 */
858
859/* Return true if the buffer is on journal list `list' */
860static inline int buffer_jlist_eq(struct buffer_head *bh, int list)
861{
862 return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list);
863}
864
865/* Return true if this bufer is dirty wrt the journal */
866static inline int buffer_jdirty(struct buffer_head *bh)
867{
868 return buffer_jbd(bh) && __buffer_state(bh, JBDDirty);
869}
870
871/* Return true if it's a data buffer which journalling is managing */
872static inline int buffer_jbd_data(struct buffer_head *bh)
873{
874 return SPLICE_LOCK(buffer_jbd(bh),
875 bh2jh(bh)->b_jlist == BJ_SyncData ||
876 bh2jh(bh)->b_jlist == BJ_AsyncData);
877}
878
879#ifdef CONFIG_SMP
880#define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock))
881#else
882#define assert_spin_locked(lock) do {} while(0)
883#endif
884
885#define buffer_trace_init(bh) do {} while (0)
886#define print_buffer_fields(bh) do {} while (0)
887#define print_buffer_trace(bh) do {} while (0)
888#define BUFFER_TRACE(bh, info) do {} while (0)
889#define BUFFER_TRACE2(bh, bh2, info) do {} while (0)
890#define JBUFFER_TRACE(jh, info) do {} while (0)
891
892#endif /* __KERNEL__ */
893
894#endif /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */
895
896/*
897 * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD
898 * go here.
899 */
900
901#if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE))
902
903#define J_ASSERT(expr) do {} while (0)
904#define J_ASSERT_BH(bh, expr) do {} while (0)
905#define buffer_jbd(bh) 0
906#define buffer_jlist_eq(bh, val) 0
907#define journal_buffer_journal_lru(bh) 0
908
909#endif /* defined(__KERNEL__) && !defined(CONFIG_JBD) */
910#endif /* _LINUX_JBD_H */