2 * linux/include/linux/jbd.h
4 * Written by Stephen C. Tweedie <sct@redhat.com>
6 * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
8 * This file is part of the Linux kernel and is made available under
9 * the terms of the GNU General Public License, version 2, or at your
10 * option, any later version, incorporated herein by reference.
12 * Definitions for transaction data structures for the buffer cache
13 * filesystem journaling support.
19 #include "jfs_compat.h"
21 #define jfs_debug jbd_debug
24 #define __FUNCTION__ ""
27 #define journal_oom_retry 0
29 #ifdef CONFIG_JBD_DEBUG
31 * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
32 * consistency checks. By default we don't do this unless
33 * CONFIG_JBD_DEBUG is on.
35 #define JBD_EXPENSIVE_CHECKING
36 extern int journal_enable_debug;
38 #define journal_enable_debug (-1)
39 #endif /* !CONFIG_JBD_DEBUG */
42 #define jbd_debug(n, f, a...) \
44 if ((n) <= journal_enable_debug) { \
45 printk (KERN_DEBUG "(%s, %d): %s: ", \
46 __FILE__, __LINE__, __FUNCTION__); \
51 #define jbd_debug(x) /* AIX doesn't do STDC */
52 #endif /* !__STDC__ */
54 extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry);
55 #define jbd_kmalloc(size, flags) \
56 __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
57 #define jbd_rep_kmalloc(size, flags) \
58 __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)
60 #define JBD2_MIN_JOURNAL_BLOCKS 1024
61 #define JBD2_MAX_JOURNAL_BLOCKS (JBD2_MIN_JOURNAL_BLOCKS * 10000)
62 #define JBD2_DEFAULT_FAST_COMMIT_BLOCKS 256
65 * Internal structures used by the logging mechanism:
68 #define JBD2_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
75 * Descriptor block types:
78 #define JBD2_DESCRIPTOR_BLOCK 1
79 #define JBD2_COMMIT_BLOCK 2
80 #define JBD2_SUPERBLOCK_V1 3
81 #define JBD2_SUPERBLOCK_V2 4
82 #define JBD2_REVOKE_BLOCK 5
83 #define JBD2_FC_BLOCK 6
86 * Standard header for all descriptor blocks:
88 typedef struct journal_header_s
98 #define JBD2_CRC32_CHKSUM 1
99 #define JBD2_MD5_CHKSUM 2
100 #define JBD2_SHA1_CHKSUM 3
101 #define JBD2_CRC32C_CHKSUM 4
103 #define JBD2_CRC32_CHKSUM_SIZE 4
105 #define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32))
107 * Commit block header for storing transactional checksums:
109 * NOTE: If FEATURE_COMPAT_CHECKSUM (checksum v1) is set, the h_chksum*
110 * fields are used to store a checksum of the descriptor and data blocks.
112 * If FEATURE_INCOMPAT_CSUM_V2 (checksum v2) is set, then the h_chksum
113 * field is used to store crc32c(uuid+commit_block). Each journal metadata
114 * block gets its own checksum, and data block checksums are stored in
115 * journal_block_tag (in the descriptor). The other h_chksum* fields are
118 * If FEATURE_INCOMPAT_CSUM_V3 is set, the descriptor block uses
119 * journal_block_tag3_t to store a full 32-bit checksum. Everything else
122 * Checksum v1, v2, and v3 are mutually exclusive features.
124 struct commit_header {
128 unsigned char h_chksum_type;
129 unsigned char h_chksum_size;
130 unsigned char h_padding[2];
131 __be32 h_chksum[JBD2_CHECKSUM_BYTES];
133 __be32 h_commit_nsec;
137 * The block tag: used to describe a single buffer in the journal
139 typedef struct journal_block_tag3_s
141 __be32 t_blocknr; /* The on-disk block number */
142 __be32 t_flags; /* See below */
143 __be32 t_blocknr_high; /* most-significant high 32bits. */
144 __be32 t_checksum; /* crc32c(uuid+seq+block) */
145 } journal_block_tag3_t;
147 typedef struct journal_block_tag_s
149 __be32 t_blocknr; /* The on-disk block number */
150 __be16 t_checksum; /* truncated crc32c(uuid+seq+block) */
151 __be16 t_flags; /* See below */
152 __be32 t_blocknr_high; /* most-significant high 32bits. */
153 } journal_block_tag_t;
155 /* Tail of descriptor or revoke block, for checksumming */
156 struct jbd2_journal_block_tail {
161 * The revoke descriptor: used on disk to describe a series of blocks to
162 * be revoked from the log
164 typedef struct journal_revoke_header_s
166 journal_header_t r_header;
167 __be32 r_count; /* Count of bytes used in the block */
168 } jbd2_journal_revoke_header_t;
170 /* Definitions for the journal tag flags word: */
171 #define JBD2_FLAG_ESCAPE 1 /* on-disk block is escaped */
172 #define JBD2_FLAG_SAME_UUID 2 /* block has same uuid as previous */
173 #define JBD2_FLAG_DELETED 4 /* block deleted by this transaction */
174 #define JBD2_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
178 #define JBD2_USERS_MAX 48
179 #define JBD2_USERS_SIZE (UUID_SIZE * JBD2_USERS_MAX)
181 * The journal superblock. All fields are in big-endian byte order.
183 typedef struct journal_superblock_s
186 journal_header_t s_header;
189 /* Static information describing the journal */
190 __be32 s_blocksize; /* journal device blocksize */
191 __be32 s_maxlen; /* total blocks in journal file */
192 __be32 s_first; /* first block of log information */
195 /* Dynamic information describing the current state of the log */
196 __be32 s_sequence; /* first commit ID expected in log */
197 __be32 s_start; /* blocknr of start of log */
200 /* Error value, as set by journal_abort(). */
204 /* Remaining fields are only valid in a version-2 superblock */
205 __be32 s_feature_compat; /* compatible feature set */
206 __be32 s_feature_incompat; /* incompatible feature set */
207 __be32 s_feature_ro_compat; /* readonly-compatible feature set */
209 __u8 s_uuid[16]; /* 128-bit uuid for journal */
212 __be32 s_nr_users; /* Nr of filesystems sharing log */
214 __be32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
217 __be32 s_max_transaction; /* Limit of journal blocks per trans.*/
218 __be32 s_max_trans_data; /* Limit of data blocks per trans. */
221 __u8 s_checksum_type; /* checksum type */
224 __be32 s_num_fc_blks; /* Number of fast commit blocks */
226 __be32 s_padding[41];
227 __be32 s_checksum; /* crc32c(superblock) */
230 __u8 s_users[JBD2_USERS_SIZE]; /* ids of all fs'es sharing the log */
233 } journal_superblock_t;
235 #define JBD2_HAS_COMPAT_FEATURE(j,mask) \
236 ((j)->j_format_version >= 2 && \
237 ((j)->j_superblock->s_feature_compat & ext2fs_cpu_to_be32((mask))))
238 #define JBD2_HAS_RO_COMPAT_FEATURE(j,mask) \
239 ((j)->j_format_version >= 2 && \
240 ((j)->j_superblock->s_feature_ro_compat & ext2fs_cpu_to_be32((mask))))
241 #define JBD2_HAS_INCOMPAT_FEATURE(j,mask) \
242 ((j)->j_format_version >= 2 && \
243 ((j)->j_superblock->s_feature_incompat & ext2fs_cpu_to_be32((mask))))
245 #define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001
247 #define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001
248 #define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002
249 #define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004
250 #define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008
251 #define JBD2_FEATURE_INCOMPAT_CSUM_V3 0x00000010
252 #define JBD2_FEATURE_INCOMPAT_FAST_COMMIT 0x00000020
254 /* Features known to this kernel version: */
255 #define JBD2_KNOWN_COMPAT_FEATURES 0
256 #define JBD2_KNOWN_ROCOMPAT_FEATURES 0
257 #define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE|\
258 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT| \
259 JBD2_FEATURE_INCOMPAT_64BIT|\
260 JBD2_FEATURE_INCOMPAT_CSUM_V2| \
261 JBD2_FEATURE_INCOMPAT_CSUM_V3 | \
262 JBD2_FEATURE_INCOMPAT_FAST_COMMIT)
264 #ifdef NO_INLINE_FUNCS
265 extern size_t journal_tag_bytes(journal_t *journal);
266 extern int jbd2_journal_has_csum_v2or3(journal_t *journal);
267 extern int jbd2_journal_get_num_fc_blks(journal_superblock_t *jsb);
268 extern int tid_gt(tid_t x, tid_t y) EXT2FS_ATTR((unused));
269 extern int tid_geq(tid_t x, tid_t y) EXT2FS_ATTR((unused));
272 #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
273 #ifdef E2FSCK_INCLUDE_INLINE_FUNCS
274 #if (__STDC_VERSION__ >= 199901L)
275 #define _INLINE_ extern inline
277 #define _INLINE_ inline
279 #else /* !E2FSCK_INCLUDE_INLINE FUNCS */
280 #if (__STDC_VERSION__ >= 199901L)
281 #define _INLINE_ inline
284 #define _INLINE_ extern __inline__
285 #else /* For Watcom C */
286 #define _INLINE_ extern inline
287 #endif /* __GNUC__ */
288 #endif /* __STDC_VERSION__ >= 199901L */
289 #endif /* INCLUDE_INLINE_FUNCS */
291 /* journal feature predicate functions */
292 #define JBD2_FEATURE_COMPAT_FUNCS(name, flagname) \
293 _INLINE_ int jbd2_has_feature_##name(journal_t *j); \
294 _INLINE_ int jbd2_has_feature_##name(journal_t *j) \
296 return ((j)->j_format_version >= 2 && \
297 ((j)->j_superblock->s_feature_compat & \
298 ext2fs_cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname)) != 0); \
300 _INLINE_ void jbd2_set_feature_##name(journal_t *j); \
301 _INLINE_ void jbd2_set_feature_##name(journal_t *j) \
303 (j)->j_superblock->s_feature_compat |= \
304 ext2fs_cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname); \
306 _INLINE_ void jbd2_clear_feature_##name(journal_t *j); \
307 _INLINE_ void jbd2_clear_feature_##name(journal_t *j) \
309 (j)->j_superblock->s_feature_compat &= \
310 ~ext2fs_cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname); \
313 #define JBD2_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
314 _INLINE_ int jbd2_has_feature_##name(journal_t *j); \
315 _INLINE_ int jbd2_has_feature_##name(journal_t *j) \
317 return ((j)->j_format_version >= 2 && \
318 ((j)->j_superblock->s_feature_ro_compat & \
319 ext2fs_cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname)) != 0); \
321 _INLINE_ void jbd2_set_feature_##name(journal_t *j); \
322 _INLINE_ void jbd2_set_feature_##name(journal_t *j) \
324 (j)->j_superblock->s_feature_ro_compat |= \
325 ext2fs_cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname); \
327 _INLINE_ void jbd2_clear_feature_##name(journal_t *j); \
328 _INLINE_ void jbd2_clear_feature_##name(journal_t *j) \
330 (j)->j_superblock->s_feature_ro_compat &= \
331 ~ext2fs_cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname); \
334 #define JBD2_FEATURE_INCOMPAT_FUNCS(name, flagname) \
335 _INLINE_ int jbd2_has_feature_##name(journal_t *j); \
336 _INLINE_ int jbd2_has_feature_##name(journal_t *j) \
338 return ((j)->j_format_version >= 2 && \
339 ((j)->j_superblock->s_feature_incompat & \
340 ext2fs_cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname)) != 0); \
342 _INLINE_ void jbd2_set_feature_##name(journal_t *j); \
343 _INLINE_ void jbd2_set_feature_##name(journal_t *j) \
345 (j)->j_superblock->s_feature_incompat |= \
346 ext2fs_cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname); \
348 _INLINE_ void jbd2_clear_feature_##name(journal_t *j); \
349 _INLINE_ void jbd2_clear_feature_##name(journal_t *j) \
351 (j)->j_superblock->s_feature_incompat &= \
352 ~ext2fs_cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname); \
356 #define JBD2_FEATURE_COMPAT_FUNCS(name, flagname) \
357 extern int jbd2_has_feature_##name(journal_t *j); \
358 extern void jbd2_set_feature_##name(journal_t *j); \
359 extern void jbd2_clear_feature_##name(journal_t *j);
361 #define JBD2_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
362 extern int jbd2_has_feature_##name(journal_t *j); \
363 extern void jbd2_set_feature_##name(journal_t *j); \
364 extern void jbd2_clear_feature_##name(journal_t *j);
366 #define JBD2_FEATURE_INCOMPAT_FUNCS(name, flagname) \
367 extern int jbd2_has_feature_##name(journal_t *j); \
368 extern void jbd2_set_feature_##name(journal_t *j); \
369 extern void jbd2_clear_feature_##name(journal_t *j);
371 #endif /* (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) */
373 JBD2_FEATURE_COMPAT_FUNCS(checksum, CHECKSUM)
375 JBD2_FEATURE_INCOMPAT_FUNCS(revoke, REVOKE)
376 JBD2_FEATURE_INCOMPAT_FUNCS(64bit, 64BIT)
377 JBD2_FEATURE_INCOMPAT_FUNCS(async_commit, ASYNC_COMMIT)
378 JBD2_FEATURE_INCOMPAT_FUNCS(csum2, CSUM_V2)
379 JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3)
380 JBD2_FEATURE_INCOMPAT_FUNCS(fast_commit, FAST_COMMIT)
382 #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
384 * helper functions to deal with 32 or 64bit block numbers.
386 _INLINE_ size_t journal_tag_bytes(journal_t *journal)
390 if (jbd2_has_feature_csum3(journal))
391 return sizeof(journal_block_tag3_t);
393 sz = sizeof(journal_block_tag_t);
395 if (jbd2_has_feature_csum2(journal))
398 if (jbd2_has_feature_64bit(journal))
401 return sz - sizeof(__u32);
404 _INLINE_ int jbd2_journal_has_csum_v2or3(journal_t *journal)
406 if (jbd2_has_feature_csum2(journal) || jbd2_has_feature_csum3(journal))
412 _INLINE_ int jbd2_journal_get_num_fc_blks(journal_superblock_t *jsb)
414 int num_fc_blocks = be32_to_cpu(jsb->s_num_fc_blks);
416 return num_fc_blocks ? num_fc_blocks : JBD2_DEFAULT_FAST_COMMIT_BLOCKS;
419 /* Comparison functions for transaction IDs: perform comparisons using
420 * modulo arithmetic so that they work over sequence number wraps. */
422 _INLINE_ int tid_gt(tid_t x, tid_t y)
424 int difference = (x - y);
425 return (difference > 0);
428 _INLINE_ int tid_geq(tid_t x, tid_t y)
430 int difference = (x - y);
431 return (difference >= 0);
433 #endif /* (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) */
437 extern int journal_blocks_per_page(struct inode *inode);
440 * Definitions which augment the buffer_head layer
443 /* journaling buffer types */
444 #define BJ_None 0 /* Not journaled */
445 #define BJ_SyncData 1 /* Normal data: flush before commit */
446 #define BJ_AsyncData 2 /* writepage data: wait on it before commit */
447 #define BJ_Metadata 3 /* Normal journaled metadata */
448 #define BJ_Forget 4 /* Buffer superseded by this transaction */
449 #define BJ_IO 5 /* Buffer is for temporary IO use */
450 #define BJ_Shadow 6 /* Buffer contents being shadowed to the log */
451 #define BJ_LogCtl 7 /* Buffer contains log descriptors */
452 #define BJ_Reserved 8 /* Buffer is reserved for access by journal */
455 extern int jbd_blocks_per_page(struct inode *inode);
457 #endif /* _LINUX_JBD_H */