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