| [2] | 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) |
|---|
| 20 | |
|---|
| 21 | /* Allow this file to be included directly into e2fsprogs */ |
|---|
| 22 | #include "jfs_compat.h" |
|---|
| 23 | #define JFS_DEBUG |
|---|
| 24 | #define jfs_debug jbd_debug |
|---|
| 25 | |
|---|
| 26 | #define journal_oom_retry 1 |
|---|
| 27 | |
|---|
| 28 | /* |
|---|
| 29 | * Define JBD_PARANIOD_IOFAIL to cause a kernel BUG() if ext3 finds |
|---|
| 30 | * certain classes of error which can occur due to failed IOs. Under |
|---|
| 31 | * normal use we want ext3 to continue after such errors, because |
|---|
| 32 | * hardware _can_ fail, but for debugging purposes when running tests on |
|---|
| 33 | * known-good hardware we may want to trap these errors. |
|---|
| 34 | */ |
|---|
| 35 | #undef JBD_PARANOID_IOFAIL |
|---|
| 36 | |
|---|
| 37 | /* |
|---|
| 38 | * The default maximum commit age, in seconds. |
|---|
| 39 | */ |
|---|
| 40 | #define JBD_DEFAULT_MAX_COMMIT_AGE 5 |
|---|
| 41 | |
|---|
| 42 | #ifdef CONFIG_JBD_DEBUG |
|---|
| 43 | /* |
|---|
| 44 | * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal |
|---|
| 45 | * consistency checks. By default we don't do this unless |
|---|
| 46 | * CONFIG_JBD_DEBUG is on. |
|---|
| 47 | */ |
|---|
| 48 | #define JBD_EXPENSIVE_CHECKING |
|---|
| 49 | extern int journal_enable_debug; |
|---|
| 50 | |
|---|
| 51 | #define jbd_debug(n, f, a...) \ |
|---|
| 52 | do { \ |
|---|
| 53 | if ((n) <= journal_enable_debug) { \ |
|---|
| 54 | printk (KERN_DEBUG "(%s, %d): %s: ", \ |
|---|
| 55 | __FILE__, __LINE__, __FUNCTION__); \ |
|---|
| 56 | printk (f, ## a); \ |
|---|
| 57 | } \ |
|---|
| 58 | } while (0) |
|---|
| 59 | #else |
|---|
| 60 | #define jbd_debug(f, a...) /**/ |
|---|
| 61 | #endif |
|---|
| 62 | |
|---|
| 63 | extern void * __jbd_kmalloc (const char *where, size_t size, int flags, int retry); |
|---|
| 64 | #define jbd_kmalloc(size, flags) \ |
|---|
| 65 | __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry) |
|---|
| 66 | #define jbd_rep_kmalloc(size, flags) \ |
|---|
| 67 | __jbd_kmalloc(__FUNCTION__, (size), (flags), 1) |
|---|
| 68 | |
|---|
| 69 | #define JFS_MIN_JOURNAL_BLOCKS 1024 |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | /* |
|---|
| 73 | * Internal structures used by the logging mechanism: |
|---|
| 74 | */ |
|---|
| 75 | |
|---|
| 76 | #define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */ |
|---|
| 77 | |
|---|
| 78 | /* |
|---|
| 79 | * On-disk structures |
|---|
| 80 | */ |
|---|
| 81 | |
|---|
| 82 | /* |
|---|
| 83 | * Descriptor block types: |
|---|
| 84 | */ |
|---|
| 85 | |
|---|
| 86 | #define JFS_DESCRIPTOR_BLOCK 1 |
|---|
| 87 | #define JFS_COMMIT_BLOCK 2 |
|---|
| 88 | #define JFS_SUPERBLOCK_V1 3 |
|---|
| 89 | #define JFS_SUPERBLOCK_V2 4 |
|---|
| 90 | #define JFS_REVOKE_BLOCK 5 |
|---|
| 91 | |
|---|
| 92 | /* |
|---|
| 93 | * Standard header for all descriptor blocks: |
|---|
| 94 | */ |
|---|
| 95 | typedef struct journal_header_s |
|---|
| 96 | { |
|---|
| 97 | __be32 h_magic; |
|---|
| 98 | __be32 h_blocktype; |
|---|
| 99 | __be32 h_sequence; |
|---|
| 100 | } journal_header_t; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | /* |
|---|
| 104 | * The block tag: used to describe a single buffer in the journal |
|---|
| 105 | */ |
|---|
| 106 | typedef struct journal_block_tag_s |
|---|
| 107 | { |
|---|
| 108 | __be32 t_blocknr; /* The on-disk block number */ |
|---|
| 109 | __be32 t_flags; /* See below */ |
|---|
| 110 | } journal_block_tag_t; |
|---|
| 111 | |
|---|
| 112 | /* |
|---|
| 113 | * The revoke descriptor: used on disk to describe a series of blocks to |
|---|
| 114 | * be revoked from the log |
|---|
| 115 | */ |
|---|
| 116 | typedef struct journal_revoke_header_s |
|---|
| 117 | { |
|---|
| 118 | journal_header_t r_header; |
|---|
| 119 | __be32 r_count; /* Count of bytes used in the block */ |
|---|
| 120 | } journal_revoke_header_t; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | /* Definitions for the journal tag flags word: */ |
|---|
| 124 | #define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */ |
|---|
| 125 | #define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */ |
|---|
| 126 | #define JFS_FLAG_DELETED 4 /* block deleted by this transaction */ |
|---|
| 127 | #define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */ |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | /* |
|---|
| 131 | * The journal superblock. All fields are in big-endian byte order. |
|---|
| 132 | */ |
|---|
| 133 | typedef struct journal_superblock_s |
|---|
| 134 | { |
|---|
| 135 | /* 0x0000 */ |
|---|
| 136 | journal_header_t s_header; |
|---|
| 137 | |
|---|
| 138 | /* 0x000C */ |
|---|
| 139 | /* Static information describing the journal */ |
|---|
| 140 | __be32 s_blocksize; /* journal device blocksize */ |
|---|
| 141 | __be32 s_maxlen; /* total blocks in journal file */ |
|---|
| 142 | __be32 s_first; /* first block of log information */ |
|---|
| 143 | |
|---|
| 144 | /* 0x0018 */ |
|---|
| 145 | /* Dynamic information describing the current state of the log */ |
|---|
| 146 | __be32 s_sequence; /* first commit ID expected in log */ |
|---|
| 147 | __be32 s_start; /* blocknr of start of log */ |
|---|
| 148 | |
|---|
| 149 | /* 0x0020 */ |
|---|
| 150 | /* Error value, as set by journal_abort(). */ |
|---|
| 151 | __be32 s_errno; |
|---|
| 152 | |
|---|
| 153 | /* 0x0024 */ |
|---|
| 154 | /* Remaining fields are only valid in a version-2 superblock */ |
|---|
| 155 | __be32 s_feature_compat; /* compatible feature set */ |
|---|
| 156 | __be32 s_feature_incompat; /* incompatible feature set */ |
|---|
| 157 | __be32 s_feature_ro_compat; /* readonly-compatible feature set */ |
|---|
| 158 | /* 0x0030 */ |
|---|
| 159 | __u8 s_uuid[16]; /* 128-bit uuid for journal */ |
|---|
| 160 | |
|---|
| 161 | /* 0x0040 */ |
|---|
| 162 | __be32 s_nr_users; /* Nr of filesystems sharing log */ |
|---|
| 163 | |
|---|
| 164 | __be32 s_dynsuper; /* Blocknr of dynamic superblock copy*/ |
|---|
| 165 | |
|---|
| 166 | /* 0x0048 */ |
|---|
| 167 | __be32 s_max_transaction; /* Limit of journal blocks per trans.*/ |
|---|
| 168 | __be32 s_max_trans_data; /* Limit of data blocks per trans. */ |
|---|
| 169 | |
|---|
| 170 | /* 0x0050 */ |
|---|
| 171 | __u32 s_padding[44]; |
|---|
| 172 | |
|---|
| 173 | /* 0x0100 */ |
|---|
| 174 | __u8 s_users[16*48]; /* ids of all fs'es sharing the log */ |
|---|
| 175 | /* 0x0400 */ |
|---|
| 176 | } journal_superblock_t; |
|---|
| 177 | |
|---|
| 178 | #define JFS_HAS_COMPAT_FEATURE(j,mask) \ |
|---|
| 179 | ((j)->j_format_version >= 2 && \ |
|---|
| 180 | ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask)))) |
|---|
| 181 | #define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \ |
|---|
| 182 | ((j)->j_format_version >= 2 && \ |
|---|
| 183 | ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask)))) |
|---|
| 184 | #define JFS_HAS_INCOMPAT_FEATURE(j,mask) \ |
|---|
| 185 | ((j)->j_format_version >= 2 && \ |
|---|
| 186 | ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask)))) |
|---|
| 187 | |
|---|
| 188 | #define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001 |
|---|
| 189 | |
|---|
| 190 | /* Features known to this kernel version: */ |
|---|
| 191 | #define JFS_KNOWN_COMPAT_FEATURES 0 |
|---|
| 192 | #define JFS_KNOWN_ROCOMPAT_FEATURES 0 |
|---|
| 193 | #define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | /* Comparison functions for transaction IDs: perform comparisons using |
|---|
| 197 | * modulo arithmetic so that they work over sequence number wraps. */ |
|---|
| 198 | |
|---|
| 199 | static inline int tid_gt(tid_t x, tid_t y) |
|---|
| 200 | { |
|---|
| 201 | int difference = (x - y); |
|---|
| 202 | return (difference > 0); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | static inline int tid_geq(tid_t x, tid_t y) |
|---|
| 206 | { |
|---|
| 207 | int difference = (x - y); |
|---|
| 208 | return (difference >= 0); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | /* |
|---|
| 213 | * Return the minimum number of blocks which must be free in the journal |
|---|
| 214 | * before a new transaction may be started. Must be called under j_state_lock. |
|---|
| 215 | */ |
|---|
| 216 | static inline int jbd_space_needed(journal_t *journal) |
|---|
| 217 | { |
|---|
| 218 | int nblocks = journal->j_max_transaction_buffers; |
|---|
| 219 | if (journal->j_committing_transaction) |
|---|
| 220 | nblocks += journal->j_committing_transaction-> |
|---|
| 221 | t_outstanding_credits; |
|---|
| 222 | return nblocks; |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | /* |
|---|
| 226 | * Definitions which augment the buffer_head layer |
|---|
| 227 | */ |
|---|
| 228 | |
|---|
| 229 | /* journaling buffer types */ |
|---|
| 230 | #define BJ_None 0 /* Not journaled */ |
|---|
| 231 | #define BJ_SyncData 1 /* Normal data: flush before commit */ |
|---|
| 232 | #define BJ_Metadata 2 /* Normal journaled metadata */ |
|---|
| 233 | #define BJ_Forget 3 /* Buffer superseded by this transaction */ |
|---|
| 234 | #define BJ_IO 4 /* Buffer is for temporary IO use */ |
|---|
| 235 | #define BJ_Shadow 5 /* Buffer contents being shadowed to the log */ |
|---|
| 236 | #define BJ_LogCtl 6 /* Buffer contains log descriptors */ |
|---|
| 237 | #define BJ_Reserved 7 /* Buffer is reserved for access by journal */ |
|---|
| 238 | #define BJ_Locked 8 /* Locked for I/O during commit */ |
|---|
| 239 | #define BJ_Types 9 |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | #endif /* CONFIG_JBD || CONFIG_JBD_MODULE */ |
|---|
| 244 | |
|---|
| 245 | /* |
|---|
| 246 | * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD |
|---|
| 247 | * go here. |
|---|
| 248 | */ |
|---|
| 249 | |
|---|
| 250 | #endif /* _LINUX_JBD_H */ |
|---|