Whamcloud - gitweb
LU-17117 journal: increase revoke block hash size
[tools/e2fsprogs.git] / lib / ext2fs / kernel-jbd.h
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 #include "jfs_compat.h"
20 #define JFS_DEBUG
21 #define jfs_debug jbd_debug
22
23 #ifndef __GNUC__
24 #define __FUNCTION__ ""
25 #endif
26
27 #define journal_oom_retry 0
28
29 #ifdef CONFIG_JBD_DEBUG
30 /*
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.
34  */
35 #define JBD_EXPENSIVE_CHECKING
36 extern int journal_enable_debug;
37 #else
38 #define journal_enable_debug (-1)
39 #endif /* !CONFIG_JBD_DEBUG */
40
41 #ifdef __STDC__
42 #define jbd_debug(n, f, a...)                                           \
43         do {                                                            \
44                 if ((n) <= journal_enable_debug) {                      \
45                         printk (KERN_DEBUG "(%s, %d): %s: ",            \
46                                 __FILE__, __LINE__, __FUNCTION__);      \
47                         printk (f, ## a);                               \
48                 }                                                       \
49         } while (0)
50 #else
51 #define jbd_debug(x)            /* AIX doesn't do STDC */
52 #endif /* !__STDC__ */
53
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)
59
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
63
64 /*
65  * Internal structures used by the logging mechanism:
66  */
67
68 #define JBD2_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
69
70 /*
71  * On-disk structures
72  */
73
74 /*
75  * Descriptor block types:
76  */
77
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
84
85 /*
86  * Standard header for all descriptor blocks:
87  */
88 typedef struct journal_header_s
89 {
90         __be32          h_magic;
91         __be32          h_blocktype;
92         __be32          h_sequence;
93 } journal_header_t;
94
95 /*
96  * Checksum types.
97  */
98 #define JBD2_CRC32_CHKSUM   1
99 #define JBD2_MD5_CHKSUM     2
100 #define JBD2_SHA1_CHKSUM    3
101 #define JBD2_CRC32C_CHKSUM  4
102
103 #define JBD2_CRC32_CHKSUM_SIZE 4
104
105 #define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32))
106 /*
107  * Commit block header for storing transactional checksums:
108  *
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.
111  *
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
116  * not used.
117  *
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
120  * is the same as v2.
121  *
122  * Checksum v1, v2, and v3 are mutually exclusive features.
123  */
124 struct commit_header {
125         __be32          h_magic;
126         __be32          h_blocktype;
127         __be32          h_sequence;
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];
132         __be64          h_commit_sec;
133         __be32          h_commit_nsec;
134 };
135
136 /*
137  * The block tag: used to describe a single buffer in the journal
138  */
139 typedef struct journal_block_tag3_s
140 {
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;
146
147 typedef struct journal_block_tag_s
148 {
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;
154
155 /* Tail of descriptor or revoke block, for checksumming */
156 struct jbd2_journal_block_tail {
157         __be32          t_checksum;
158 };
159
160 /*
161  * The revoke descriptor: used on disk to describe a series of blocks to
162  * be revoked from the log
163  */
164 typedef struct journal_revoke_header_s
165 {
166         journal_header_t r_header;
167         __be32           r_count;       /* Count of bytes used in the block */
168 } jbd2_journal_revoke_header_t;
169
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 */
175
176
177 #define UUID_SIZE 16
178 #define JBD2_USERS_MAX 48
179 #define JBD2_USERS_SIZE (UUID_SIZE * JBD2_USERS_MAX)
180 /*
181  * The journal superblock.  All fields are in big-endian byte order.
182  */
183 typedef struct journal_superblock_s
184 {
185 /* 0x0000 */
186         journal_header_t s_header;
187
188 /* 0x000C */
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 */
193
194 /* 0x0018 */
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 */
198
199 /* 0x0020 */
200         /* Error value, as set by journal_abort(). */
201         __s32   s_errno;
202
203 /* 0x0024 */
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 */
208 /* 0x0030 */
209         __u8    s_uuid[16];             /* 128-bit uuid for journal */
210
211 /* 0x0040 */
212         __be32  s_nr_users;             /* Nr of filesystems sharing log */
213
214         __be32  s_dynsuper;             /* Blocknr of dynamic superblock copy*/
215
216 /* 0x0048 */
217         __be32  s_max_transaction;      /* Limit of journal blocks per trans.*/
218         __be32  s_max_trans_data;       /* Limit of data blocks per trans. */
219
220 /* 0x0050 */
221         __u8    s_checksum_type;        /* checksum type */
222         __u8    s_padding2[3];
223 /* 0x0054 */
224         __be32  s_num_fc_blks;          /* Number of fast commit blocks */
225 /* 0x0058 */
226         __be32  s_padding[41];
227         __be32  s_checksum;             /* crc32c(superblock) */
228
229 /* 0x0100 */
230         __u8    s_users[JBD2_USERS_SIZE];               /* ids of all fs'es sharing the log */
231
232 /* 0x0400 */
233 } journal_superblock_t;
234
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))))
244
245 #define JBD2_FEATURE_COMPAT_CHECKSUM            0x00000001
246
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
253
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)
263
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));
270 #endif
271
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
276 #else
277 #define _INLINE_ inline
278 #endif
279 #else /* !E2FSCK_INCLUDE_INLINE FUNCS */
280 #if (__STDC_VERSION__ >= 199901L)
281 #define _INLINE_ inline
282 #else /* not C99 */
283 #ifdef __GNUC__
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 */
290
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) \
295 { \
296         return ((j)->j_format_version >= 2 && \
297                 ((j)->j_superblock->s_feature_compat & \
298                  ext2fs_cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname)) != 0); \
299 } \
300 _INLINE_ void jbd2_set_feature_##name(journal_t *j); \
301 _INLINE_ void jbd2_set_feature_##name(journal_t *j) \
302 { \
303         (j)->j_superblock->s_feature_compat |= \
304                 ext2fs_cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname); \
305 } \
306 _INLINE_ void jbd2_clear_feature_##name(journal_t *j); \
307 _INLINE_ void jbd2_clear_feature_##name(journal_t *j) \
308 { \
309         (j)->j_superblock->s_feature_compat &= \
310                 ~ext2fs_cpu_to_be32(JBD2_FEATURE_COMPAT_##flagname); \
311 }
312
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) \
316 { \
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); \
320 } \
321 _INLINE_ void jbd2_set_feature_##name(journal_t *j); \
322 _INLINE_ void jbd2_set_feature_##name(journal_t *j) \
323 { \
324         (j)->j_superblock->s_feature_ro_compat |= \
325                 ext2fs_cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname); \
326 } \
327 _INLINE_ void jbd2_clear_feature_##name(journal_t *j); \
328 _INLINE_ void jbd2_clear_feature_##name(journal_t *j) \
329 { \
330         (j)->j_superblock->s_feature_ro_compat &= \
331                 ~ext2fs_cpu_to_be32(JBD2_FEATURE_RO_COMPAT_##flagname); \
332 }
333
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) \
337 { \
338         return ((j)->j_format_version >= 2 && \
339                 ((j)->j_superblock->s_feature_incompat & \
340                  ext2fs_cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname)) != 0); \
341 } \
342 _INLINE_ void jbd2_set_feature_##name(journal_t *j); \
343 _INLINE_ void jbd2_set_feature_##name(journal_t *j) \
344 { \
345         (j)->j_superblock->s_feature_incompat |= \
346                 ext2fs_cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname); \
347 } \
348 _INLINE_ void jbd2_clear_feature_##name(journal_t *j); \
349 _INLINE_ void jbd2_clear_feature_##name(journal_t *j) \
350 { \
351         (j)->j_superblock->s_feature_incompat &= \
352                 ~ext2fs_cpu_to_be32(JBD2_FEATURE_INCOMPAT_##flagname); \
353 }
354
355 #else
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);
360
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);
365
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);
370
371 #endif /* (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) */
372
373 JBD2_FEATURE_COMPAT_FUNCS(checksum,             CHECKSUM)
374
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)
381
382 #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
383 /*
384  * helper functions to deal with 32 or 64bit block numbers.
385  */
386 _INLINE_ size_t journal_tag_bytes(journal_t *journal)
387 {
388         size_t sz;
389
390         if (jbd2_has_feature_csum3(journal))
391                 return sizeof(journal_block_tag3_t);
392
393         sz = sizeof(journal_block_tag_t);
394
395         if (jbd2_has_feature_csum2(journal))
396                 sz += sizeof(__u16);
397
398         if (jbd2_has_feature_64bit(journal))
399                 return sz;
400
401         return sz - sizeof(__u32);
402 }
403
404 _INLINE_ int jbd2_journal_has_csum_v2or3(journal_t *journal)
405 {
406         if (jbd2_has_feature_csum2(journal) || jbd2_has_feature_csum3(journal))
407                 return 1;
408
409         return 0;
410 }
411
412 _INLINE_ int jbd2_journal_get_num_fc_blks(journal_superblock_t *jsb)
413 {
414         int num_fc_blocks = be32_to_cpu(jsb->s_num_fc_blks);
415
416         return num_fc_blocks ? num_fc_blocks : JBD2_DEFAULT_FAST_COMMIT_BLOCKS;
417 }
418
419 /* Comparison functions for transaction IDs: perform comparisons using
420  * modulo arithmetic so that they work over sequence number wraps. */
421
422 _INLINE_ int tid_gt(tid_t x, tid_t y)
423 {
424         int difference = (x - y);
425         return (difference > 0);
426 }
427
428 _INLINE_ int tid_geq(tid_t x, tid_t y)
429 {
430         int difference = (x - y);
431         return (difference >= 0);
432 }
433 #endif /* (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) */
434
435 #undef _INLINE_
436
437 extern int journal_blocks_per_page(struct inode *inode);
438
439 /*
440  * Definitions which augment the buffer_head layer
441  */
442
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 */
453 #define BJ_Types        9
454
455 extern int jbd_blocks_per_page(struct inode *inode);
456
457 #endif  /* _LINUX_JBD_H */