diff options
Diffstat (limited to 'include/linux/jbd2.h')
-rw-r--r-- | include/linux/jbd2.h | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 912c30a8ddb1..f334c7fab967 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/mutex.h> | 31 | #include <linux/mutex.h> |
32 | #include <linux/timer.h> | 32 | #include <linux/timer.h> |
33 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
34 | #include <crypto/hash.h> | ||
34 | #endif | 35 | #endif |
35 | 36 | ||
36 | #define journal_oom_retry 1 | 37 | #define journal_oom_retry 1 |
@@ -147,12 +148,24 @@ typedef struct journal_header_s | |||
147 | #define JBD2_CRC32_CHKSUM 1 | 148 | #define JBD2_CRC32_CHKSUM 1 |
148 | #define JBD2_MD5_CHKSUM 2 | 149 | #define JBD2_MD5_CHKSUM 2 |
149 | #define JBD2_SHA1_CHKSUM 3 | 150 | #define JBD2_SHA1_CHKSUM 3 |
151 | #define JBD2_CRC32C_CHKSUM 4 | ||
150 | 152 | ||
151 | #define JBD2_CRC32_CHKSUM_SIZE 4 | 153 | #define JBD2_CRC32_CHKSUM_SIZE 4 |
152 | 154 | ||
153 | #define JBD2_CHECKSUM_BYTES (32 / sizeof(u32)) | 155 | #define JBD2_CHECKSUM_BYTES (32 / sizeof(u32)) |
154 | /* | 156 | /* |
155 | * Commit block header for storing transactional checksums: | 157 | * Commit block header for storing transactional checksums: |
158 | * | ||
159 | * NOTE: If FEATURE_COMPAT_CHECKSUM (checksum v1) is set, the h_chksum* | ||
160 | * fields are used to store a checksum of the descriptor and data blocks. | ||
161 | * | ||
162 | * If FEATURE_INCOMPAT_CSUM_V2 (checksum v2) is set, then the h_chksum | ||
163 | * field is used to store crc32c(uuid+commit_block). Each journal metadata | ||
164 | * block gets its own checksum, and data block checksums are stored in | ||
165 | * journal_block_tag (in the descriptor). The other h_chksum* fields are | ||
166 | * not used. | ||
167 | * | ||
168 | * Checksum v1 and v2 are mutually exclusive features. | ||
156 | */ | 169 | */ |
157 | struct commit_header { | 170 | struct commit_header { |
158 | __be32 h_magic; | 171 | __be32 h_magic; |
@@ -175,13 +188,19 @@ struct commit_header { | |||
175 | typedef struct journal_block_tag_s | 188 | typedef struct journal_block_tag_s |
176 | { | 189 | { |
177 | __be32 t_blocknr; /* The on-disk block number */ | 190 | __be32 t_blocknr; /* The on-disk block number */ |
178 | __be32 t_flags; /* See below */ | 191 | __be16 t_checksum; /* truncated crc32c(uuid+seq+block) */ |
192 | __be16 t_flags; /* See below */ | ||
179 | __be32 t_blocknr_high; /* most-significant high 32bits. */ | 193 | __be32 t_blocknr_high; /* most-significant high 32bits. */ |
180 | } journal_block_tag_t; | 194 | } journal_block_tag_t; |
181 | 195 | ||
182 | #define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high)) | 196 | #define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high)) |
183 | #define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t)) | 197 | #define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t)) |
184 | 198 | ||
199 | /* Tail of descriptor block, for checksumming */ | ||
200 | struct jbd2_journal_block_tail { | ||
201 | __be32 t_checksum; /* crc32c(uuid+descr_block) */ | ||
202 | }; | ||
203 | |||
185 | /* | 204 | /* |
186 | * The revoke descriptor: used on disk to describe a series of blocks to | 205 | * The revoke descriptor: used on disk to describe a series of blocks to |
187 | * be revoked from the log | 206 | * be revoked from the log |
@@ -192,6 +211,10 @@ typedef struct jbd2_journal_revoke_header_s | |||
192 | __be32 r_count; /* Count of bytes used in the block */ | 211 | __be32 r_count; /* Count of bytes used in the block */ |
193 | } jbd2_journal_revoke_header_t; | 212 | } jbd2_journal_revoke_header_t; |
194 | 213 | ||
214 | /* Tail of revoke block, for checksumming */ | ||
215 | struct jbd2_journal_revoke_tail { | ||
216 | __be32 r_checksum; /* crc32c(uuid+revoke_block) */ | ||
217 | }; | ||
195 | 218 | ||
196 | /* Definitions for the journal tag flags word: */ | 219 | /* Definitions for the journal tag flags word: */ |
197 | #define JBD2_FLAG_ESCAPE 1 /* on-disk block is escaped */ | 220 | #define JBD2_FLAG_ESCAPE 1 /* on-disk block is escaped */ |
@@ -241,7 +264,10 @@ typedef struct journal_superblock_s | |||
241 | __be32 s_max_trans_data; /* Limit of data blocks per trans. */ | 264 | __be32 s_max_trans_data; /* Limit of data blocks per trans. */ |
242 | 265 | ||
243 | /* 0x0050 */ | 266 | /* 0x0050 */ |
244 | __u32 s_padding[44]; | 267 | __u8 s_checksum_type; /* checksum type */ |
268 | __u8 s_padding2[3]; | ||
269 | __u32 s_padding[42]; | ||
270 | __be32 s_checksum; /* crc32c(superblock) */ | ||
245 | 271 | ||
246 | /* 0x0100 */ | 272 | /* 0x0100 */ |
247 | __u8 s_users[16*48]; /* ids of all fs'es sharing the log */ | 273 | __u8 s_users[16*48]; /* ids of all fs'es sharing the log */ |
@@ -263,13 +289,15 @@ typedef struct journal_superblock_s | |||
263 | #define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 | 289 | #define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 |
264 | #define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 | 290 | #define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 |
265 | #define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004 | 291 | #define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004 |
292 | #define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008 | ||
266 | 293 | ||
267 | /* Features known to this kernel version: */ | 294 | /* Features known to this kernel version: */ |
268 | #define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM | 295 | #define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM |
269 | #define JBD2_KNOWN_ROCOMPAT_FEATURES 0 | 296 | #define JBD2_KNOWN_ROCOMPAT_FEATURES 0 |
270 | #define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | \ | 297 | #define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | \ |
271 | JBD2_FEATURE_INCOMPAT_64BIT | \ | 298 | JBD2_FEATURE_INCOMPAT_64BIT | \ |
272 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) | 299 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT | \ |
300 | JBD2_FEATURE_INCOMPAT_CSUM_V2) | ||
273 | 301 | ||
274 | #ifdef __KERNEL__ | 302 | #ifdef __KERNEL__ |
275 | 303 | ||
@@ -939,6 +967,12 @@ struct journal_s | |||
939 | * superblock pointer here | 967 | * superblock pointer here |
940 | */ | 968 | */ |
941 | void *j_private; | 969 | void *j_private; |
970 | |||
971 | /* Reference to checksum algorithm driver via cryptoapi */ | ||
972 | struct crypto_shash *j_chksum_driver; | ||
973 | |||
974 | /* Precomputed journal UUID checksum for seeding other checksums */ | ||
975 | __u32 j_csum_seed; | ||
942 | }; | 976 | }; |
943 | 977 | ||
944 | /* | 978 | /* |
@@ -1268,6 +1302,25 @@ static inline int jbd_space_needed(journal_t *journal) | |||
1268 | 1302 | ||
1269 | extern int jbd_blocks_per_page(struct inode *inode); | 1303 | extern int jbd_blocks_per_page(struct inode *inode); |
1270 | 1304 | ||
1305 | static inline u32 jbd2_chksum(journal_t *journal, u32 crc, | ||
1306 | const void *address, unsigned int length) | ||
1307 | { | ||
1308 | struct { | ||
1309 | struct shash_desc shash; | ||
1310 | char ctx[crypto_shash_descsize(journal->j_chksum_driver)]; | ||
1311 | } desc; | ||
1312 | int err; | ||
1313 | |||
1314 | desc.shash.tfm = journal->j_chksum_driver; | ||
1315 | desc.shash.flags = 0; | ||
1316 | *(u32 *)desc.ctx = crc; | ||
1317 | |||
1318 | err = crypto_shash_update(&desc.shash, address, length); | ||
1319 | BUG_ON(err); | ||
1320 | |||
1321 | return *(u32 *)desc.ctx; | ||
1322 | } | ||
1323 | |||
1271 | #ifdef __KERNEL__ | 1324 | #ifdef __KERNEL__ |
1272 | 1325 | ||
1273 | #define buffer_trace_init(bh) do {} while (0) | 1326 | #define buffer_trace_init(bh) do {} while (0) |