2 * journal.c --- code for handling the "ext3" journal
4 * Copyright (C) 2000 Andreas Dilger
5 * Copyright (C) 2000 Theodore Ts'o
7 * Parts of the code are based on fs/jfs/journal.c by Stephen C. Tweedie
8 * Copyright (C) 1999 Red Hat Software
10 * This file may be redistributed under the terms of the
11 * GNU General Public License version 2 or at your discretion
16 #ifdef HAVE_SYS_MOUNT_H
17 #include <sys/param.h>
18 #include <sys/mount.h>
19 #define MNT_FL (MS_MGC_VAL | MS_RDONLY)
21 #ifdef HAVE_SYS_STAT_H
25 #define E2FSCK_INCLUDE_INLINE_FUNCS
26 #include "uuid/uuid.h"
29 #ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jfs-debug */
30 static int bh_count = 0;
33 #if EXT2_FLAT_INCLUDES
36 #include "blkid/blkid.h"
40 * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths.
41 * This creates a larger static binary, and a smaller binary using
42 * shared libraries. It's also probably slightly less CPU-efficient,
43 * which is why it's not on by default. But, it's a good way of
44 * testing the functions in inode_io.c and fileio.c.
48 /* Checksumming functions */
49 static int ext2fs_journal_verify_csum_type(journal_t *j,
50 journal_superblock_t *jsb)
52 if (!journal_has_csum_v2or3(j))
55 return jsb->s_checksum_type == JBD2_CRC32C_CHKSUM;
58 static __u32 ext2fs_journal_sb_csum(journal_superblock_t *jsb)
62 old_crc = jsb->s_checksum;
64 crc = ext2fs_crc32c_le(~0, (unsigned char *)jsb,
65 sizeof(journal_superblock_t));
66 jsb->s_checksum = old_crc;
71 static int ext2fs_journal_sb_csum_verify(journal_t *j,
72 journal_superblock_t *jsb)
74 __u32 provided, calculated;
76 if (!journal_has_csum_v2or3(j))
79 provided = ext2fs_be32_to_cpu(jsb->s_checksum);
80 calculated = ext2fs_journal_sb_csum(jsb);
82 return provided == calculated;
85 static errcode_t ext2fs_journal_sb_csum_set(journal_t *j,
86 journal_superblock_t *jsb)
90 if (!journal_has_csum_v2or3(j))
93 crc = ext2fs_journal_sb_csum(jsb);
94 jsb->s_checksum = ext2fs_cpu_to_be32(crc);
98 /* Kernel compatibility functions for handling the journal. These allow us
99 * to use the recovery.c file virtually unchanged from the kernel, so we
100 * don't have to do much to keep kernel and user recovery in sync.
102 int journal_bmap(journal_t *journal, blk64_t block, unsigned long long *phys)
108 struct inode *inode = journal->j_inode;
117 retval = ext2fs_bmap2(inode->i_fs, inode->i_ino,
118 &inode->i_ext2, NULL, 0, block, 0, &pblk);
124 struct buffer_head *getblk(kdev_t kdev, blk64_t blocknr, int blocksize)
126 struct buffer_head *bh;
127 int bufsize = sizeof(*bh) + kdev->k_fs->blocksize -
131 retval = ext2fs_get_memzero(bufsize, &bh);
135 #ifdef CONFIG_JBD_DEBUG
136 if (journal_enable_debug >= 3)
139 jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n",
140 (unsigned long long) blocknr, blocksize, bh_count);
142 bh->b_fs = kdev->k_fs;
143 if (kdev->k_dev == K_DEV_FS)
144 bh->b_io = kdev->k_fs->io;
146 bh->b_io = kdev->k_fs->journal_io;
147 bh->b_size = blocksize;
148 bh->b_blocknr = blocknr;
153 int sync_blockdev(kdev_t kdev)
157 if (kdev->k_dev == K_DEV_FS)
160 io = kdev->k_fs->journal_io;
162 return io_channel_flush(io) ? EIO : 0;
165 void ll_rw_block(int rw, int nr, struct buffer_head *bhp[])
168 struct buffer_head *bh;
170 for (; nr > 0; --nr) {
172 if (rw == READ && !bh->b_uptodate) {
173 jfs_debug(3, "reading block %llu/%p\n",
174 bh->b_blocknr, (void *) bh);
175 retval = io_channel_read_blk64(bh->b_io,
179 com_err(bh->b_fs->device_name, retval,
180 "while reading block %llu\n",
182 bh->b_err = (int) retval;
186 } else if (rw == WRITE && bh->b_dirty) {
187 jfs_debug(3, "writing block %llu/%p\n",
190 retval = io_channel_write_blk64(bh->b_io,
194 com_err(bh->b_fs->device_name, retval,
195 "while writing block %llu\n",
197 bh->b_err = (int) retval;
203 jfs_debug(3, "no-op %s for block %llu\n",
204 rw == READ ? "read" : "write",
210 void mark_buffer_dirty(struct buffer_head *bh)
215 static void mark_buffer_clean(struct buffer_head *bh)
220 void brelse(struct buffer_head *bh)
223 ll_rw_block(WRITE, 1, &bh);
224 jfs_debug(3, "freeing block %llu/%p (total %d)\n",
225 bh->b_blocknr, (void *) bh, --bh_count);
226 ext2fs_free_mem(&bh);
229 int buffer_uptodate(struct buffer_head *bh)
231 return bh->b_uptodate;
234 void mark_buffer_uptodate(struct buffer_head *bh, int val)
236 bh->b_uptodate = val;
239 void wait_on_buffer(struct buffer_head *bh)
242 ll_rw_block(READ, 1, &bh);
246 static void ext2fs_clear_recover(ext2_filsys fs, int error)
248 fs->super->s_feature_incompat &= ~EXT3_FEATURE_INCOMPAT_RECOVER;
250 /* if we had an error doing journal recovery, we need a full fsck */
252 fs->super->s_state &= ~EXT2_VALID_FS;
253 ext2fs_mark_super_dirty(fs);
257 * This is a helper function to check the validity of the journal.
259 struct process_block_struct {
260 e2_blkcnt_t last_block;
263 static int process_journal_block(ext2_filsys fs,
265 e2_blkcnt_t blockcnt,
266 blk64_t ref_block EXT2FS_ATTR((unused)),
267 int ref_offset EXT2FS_ATTR((unused)),
270 struct process_block_struct *p;
271 blk64_t blk = *block_nr;
273 p = (struct process_block_struct *) priv_data;
275 if (!blk || blk < fs->super->s_first_data_block ||
276 blk >= ext2fs_blocks_count(fs->super))
280 p->last_block = blockcnt;
284 static errcode_t ext2fs_get_journal(ext2_filsys fs, journal_t **ret_journal)
286 struct process_block_struct pb;
287 struct ext2_super_block *sb = fs->super;
288 struct ext2_super_block jsuper;
289 struct buffer_head *bh;
290 struct inode *j_inode = NULL;
291 struct kdev_s *dev_fs = NULL, *dev_journal;
292 const char *journal_name = 0;
293 journal_t *journal = NULL;
294 errcode_t retval = 0;
295 io_manager io_ptr = 0;
296 unsigned long long start = 0;
298 int tried_backup_jnl = 0;
300 retval = ext2fs_get_memzero(sizeof(journal_t), &journal);
304 retval = ext2fs_get_memzero(2 * sizeof(struct kdev_s), &dev_fs);
307 dev_journal = dev_fs+1;
309 dev_fs->k_fs = dev_journal->k_fs = fs;
310 dev_fs->k_dev = K_DEV_FS;
311 dev_journal->k_dev = K_DEV_JOURNAL;
313 journal->j_dev = dev_journal;
314 journal->j_fs_dev = dev_fs;
315 journal->j_inode = NULL;
316 journal->j_blocksize = fs->blocksize;
318 if (uuid_is_null(sb->s_journal_uuid)) {
319 if (!sb->s_journal_inum) {
320 retval = EXT2_ET_BAD_INODE_NUM;
323 retval = ext2fs_get_memzero(sizeof(*j_inode), &j_inode);
328 j_inode->i_ino = sb->s_journal_inum;
330 retval = ext2fs_read_inode(fs, sb->s_journal_inum,
334 if (sb->s_jnl_backup_type != EXT3_JNL_BACKUP_BLOCKS ||
337 memset(&j_inode->i_ext2, 0, sizeof(struct ext2_inode));
338 memcpy(&j_inode->i_ext2.i_block[0], sb->s_jnl_blocks,
340 j_inode->i_ext2.i_size_high = sb->s_jnl_blocks[15];
341 j_inode->i_ext2.i_size = sb->s_jnl_blocks[16];
342 j_inode->i_ext2.i_links_count = 1;
343 j_inode->i_ext2.i_mode = LINUX_S_IFREG | 0600;
346 if (!j_inode->i_ext2.i_links_count ||
347 !LINUX_S_ISREG(j_inode->i_ext2.i_mode)) {
348 retval = EXT2_ET_NO_JOURNAL;
349 goto try_backup_journal;
351 if (EXT2_I_SIZE(&j_inode->i_ext2) / journal->j_blocksize <
352 JFS_MIN_JOURNAL_BLOCKS) {
353 retval = EXT2_ET_JOURNAL_TOO_SMALL;
354 goto try_backup_journal;
357 retval = ext2fs_block_iterate3(fs, j_inode->i_ino,
359 process_journal_block, &pb);
360 if ((pb.last_block + 1) * fs->blocksize <
361 (int) EXT2_I_SIZE(&j_inode->i_ext2)) {
362 retval = EXT2_ET_JOURNAL_TOO_SMALL;
363 goto try_backup_journal;
365 if (tried_backup_jnl && (fs->flags & EXT2_FLAG_RW)) {
366 retval = ext2fs_write_inode(fs, sb->s_journal_inum,
372 journal->j_maxlen = EXT2_I_SIZE(&j_inode->i_ext2) /
373 journal->j_blocksize;
376 retval = ext2fs_inode_io_intern2(fs, sb->s_journal_inum,
382 io_ptr = inode_io_manager;
384 journal->j_inode = j_inode;
385 fs->journal_io = fs->io;
386 retval = (errcode_t)journal_bmap(journal, 0, &start);
392 if (!fs->journal_name) {
396 blkid_get_cache(&blkid, NULL);
397 uuid_unparse(sb->s_journal_uuid, uuid);
398 fs->journal_name = blkid_get_devname(blkid,
400 if (!fs->journal_name)
401 fs->journal_name = blkid_devno_to_devname(sb->s_journal_dev);
402 blkid_put_cache(blkid);
404 journal_name = fs->journal_name;
407 retval = EXT2_ET_LOAD_EXT_JOURNAL;
411 jfs_debug(1, "Using journal file %s\n", journal_name);
412 io_ptr = unix_io_manager;
416 test_io_backing_manager = io_ptr;
417 io_ptr = test_io_manager;
423 retval = io_ptr->open(journal_name, fs->flags & EXT2_FLAG_RW,
429 io_channel_set_blksize(fs->journal_io, fs->blocksize);
434 start = ext2fs_journal_sb_start(fs->blocksize) - 1;
435 bh = getblk(dev_journal, start, fs->blocksize);
437 retval = EXT2_ET_NO_MEMORY;
440 ll_rw_block(READ, 1, &bh);
446 memcpy(&jsuper, start ? bh->b_data :
447 bh->b_data + SUPERBLOCK_OFFSET,
449 #ifdef WORDS_BIGENDIAN
450 if (jsuper.s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
451 ext2fs_swap_super(&jsuper);
453 if (jsuper.s_magic != EXT2_SUPER_MAGIC ||
454 !(jsuper.s_feature_incompat &
455 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
456 retval = EXT2_ET_LOAD_EXT_JOURNAL;
460 /* Make sure the journal UUID is correct */
461 if (memcmp(jsuper.s_uuid, fs->super->s_journal_uuid,
462 sizeof(jsuper.s_uuid))) {
463 retval = EXT2_ET_LOAD_EXT_JOURNAL;
468 /* Check the superblock checksum */
469 if (jsuper.s_feature_ro_compat &
470 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) {
471 struct struct_ext2_filsys fsx;
472 struct ext2_super_block superx;
475 p = start ? bh->b_data : bh->b_data + SUPERBLOCK_OFFSET;
476 memcpy(&fsx, fs, sizeof(fsx));
477 memcpy(&superx, fs->super, sizeof(superx));
479 fsx.super->s_feature_ro_compat |=
480 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM;
481 if (!ext2fs_superblock_csum_verify(&fsx, p)) {
482 retval = EXT2_ET_LOAD_EXT_JOURNAL;
489 maxlen = ext2fs_blocks_count(&jsuper);
490 journal->j_maxlen = (maxlen < 1ULL << 32) ? maxlen :
495 bh = getblk(dev_journal, start, journal->j_blocksize);
497 retval = EXT2_ET_NO_MEMORY;
501 journal->j_sb_buffer = bh;
502 journal->j_superblock = (journal_superblock_t *)bh->b_data;
506 ext2fs_free_mem(&j_inode);
509 *ret_journal = journal;
514 ext2fs_free_mem(&dev_fs);
516 ext2fs_free_mem(&j_inode);
518 ext2fs_free_mem(&journal);
522 static errcode_t ext2fs_journal_fix_bad_inode(ext2_filsys fs)
524 struct ext2_super_block *sb = fs->super;
525 int recover = fs->super->s_feature_incompat &
526 EXT3_FEATURE_INCOMPAT_RECOVER;
527 int has_journal = fs->super->s_feature_compat &
528 EXT3_FEATURE_COMPAT_HAS_JOURNAL;
530 if (has_journal || sb->s_journal_inum) {
531 /* The journal inode is bogus, remove and force full fsck */
532 return EXT2_ET_BAD_INODE_NUM;
533 } else if (recover) {
534 return EXT2_ET_UNSUPP_FEATURE;
539 #define V1_SB_SIZE 0x0024
540 static void clear_v2_journal_fields(journal_t *journal)
542 ext2_filsys fs = journal->j_dev->k_fs;
544 memset(((char *) journal->j_superblock) + V1_SB_SIZE, 0,
545 fs->blocksize-V1_SB_SIZE);
546 mark_buffer_dirty(journal->j_sb_buffer);
550 static errcode_t ext2fs_journal_load(journal_t *journal)
552 ext2_filsys fs = journal->j_dev->k_fs;
553 journal_superblock_t *jsb;
554 struct buffer_head *jbh = journal->j_sb_buffer;
556 ll_rw_block(READ, 1, &jbh);
560 jsb = journal->j_superblock;
561 /* If we don't even have JFS_MAGIC, we probably have a wrong inode */
562 if (jsb->s_header.h_magic != htonl(JFS_MAGIC_NUMBER))
563 return ext2fs_journal_fix_bad_inode(fs);
565 switch (ntohl(jsb->s_header.h_blocktype)) {
566 case JFS_SUPERBLOCK_V1:
567 journal->j_format_version = 1;
568 if (jsb->s_feature_compat ||
569 jsb->s_feature_incompat ||
570 jsb->s_feature_ro_compat ||
572 clear_v2_journal_fields(journal);
575 case JFS_SUPERBLOCK_V2:
576 journal->j_format_version = 2;
577 if (ntohl(jsb->s_nr_users) > 1 &&
578 uuid_is_null(fs->super->s_journal_uuid))
579 clear_v2_journal_fields(journal);
580 if (ntohl(jsb->s_nr_users) > 1)
581 return EXT2_ET_JOURNAL_UNSUPP_VERSION;
585 * These should never appear in a journal super block, so if
586 * they do, the journal is badly corrupted.
588 case JFS_DESCRIPTOR_BLOCK:
589 case JFS_COMMIT_BLOCK:
590 case JFS_REVOKE_BLOCK:
591 return EXT2_ET_CORRUPT_SUPERBLOCK;
593 /* If we don't understand the superblock major type, but there
594 * is a magic number, then it is likely to be a new format we
595 * just don't understand, so leave it alone. */
597 return EXT2_ET_JOURNAL_UNSUPP_VERSION;
600 if (JFS_HAS_INCOMPAT_FEATURE(journal, ~JFS_KNOWN_INCOMPAT_FEATURES))
601 return EXT2_ET_UNSUPP_FEATURE;
603 if (JFS_HAS_RO_COMPAT_FEATURE(journal, ~JFS_KNOWN_ROCOMPAT_FEATURES))
604 return EXT2_ET_RO_UNSUPP_FEATURE;
606 /* Checksum v1-3 are mutually exclusive features. */
607 if (JFS_HAS_INCOMPAT_FEATURE(journal, JFS_FEATURE_INCOMPAT_CSUM_V2) &&
608 JFS_HAS_INCOMPAT_FEATURE(journal, JFS_FEATURE_INCOMPAT_CSUM_V3))
609 return EXT2_ET_CORRUPT_SUPERBLOCK;
611 if (journal_has_csum_v2or3(journal) &&
612 JFS_HAS_COMPAT_FEATURE(journal, JFS_FEATURE_COMPAT_CHECKSUM))
613 return EXT2_ET_CORRUPT_SUPERBLOCK;
615 if (!ext2fs_journal_verify_csum_type(journal, jsb) ||
616 !ext2fs_journal_sb_csum_verify(journal, jsb))
617 return EXT2_ET_CORRUPT_SUPERBLOCK;
619 if (journal_has_csum_v2or3(journal))
620 journal->j_csum_seed = jbd2_chksum(journal, ~0, jsb->s_uuid,
621 sizeof(jsb->s_uuid));
623 /* We have now checked whether we know enough about the journal
624 * format to be able to proceed safely, so any other checks that
625 * fail we should attempt to recover from. */
626 if (jsb->s_blocksize != htonl(journal->j_blocksize))
627 return EXT2_ET_CORRUPT_SUPERBLOCK;
629 if (ntohl(jsb->s_maxlen) < journal->j_maxlen)
630 journal->j_maxlen = ntohl(jsb->s_maxlen);
631 else if (ntohl(jsb->s_maxlen) > journal->j_maxlen)
632 return EXT2_ET_CORRUPT_SUPERBLOCK;
634 journal->j_tail_sequence = ntohl(jsb->s_sequence);
635 journal->j_transaction_sequence = journal->j_tail_sequence;
636 journal->j_tail = ntohl(jsb->s_start);
637 journal->j_first = ntohl(jsb->s_first);
638 journal->j_last = ntohl(jsb->s_maxlen);
643 static void ext2fs_journal_release(ext2_filsys fs, journal_t *journal,
646 journal_superblock_t *jsb;
649 mark_buffer_clean(journal->j_sb_buffer);
650 else if (fs->flags & EXT2_FLAG_RW) {
651 jsb = journal->j_superblock;
652 jsb->s_sequence = htonl(journal->j_tail_sequence);
654 jsb->s_start = 0; /* this marks the journal as empty */
655 ext2fs_journal_sb_csum_set(journal, jsb);
656 mark_buffer_dirty(journal->j_sb_buffer);
658 brelse(journal->j_sb_buffer);
660 if (fs && fs->journal_io) {
661 if (fs->io != fs->journal_io)
662 io_channel_close(fs->journal_io);
663 fs->journal_io = NULL;
667 if (journal->j_inode)
668 ext2fs_free_mem(&journal->j_inode);
670 if (journal->j_fs_dev)
671 ext2fs_free_mem(&journal->j_fs_dev);
672 ext2fs_free_mem(&journal);
676 * This function makes sure that the superblock fields regarding the
677 * journal are consistent.
679 static errcode_t ext2fs_check_ext3_journal(ext2_filsys fs)
681 struct ext2_super_block *sb = fs->super;
683 int recover = fs->super->s_feature_incompat &
684 EXT3_FEATURE_INCOMPAT_RECOVER;
687 /* If we don't have any journal features, don't do anything more */
688 if (!(sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
689 !recover && sb->s_journal_inum == 0 && sb->s_journal_dev == 0 &&
690 uuid_is_null(sb->s_journal_uuid))
693 retval = ext2fs_get_journal(fs, &journal);
697 retval = ext2fs_journal_load(journal);
702 * We want to make the flags consistent here. We will not leave with
703 * needs_recovery set but has_journal clear. We can't get in a loop
704 * with -y, -n, or -p, only if a user isn't making up their mind.
706 if (!(sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
707 retval = EXT2_ET_JOURNAL_FLAGS_WRONG;
711 if (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL &&
712 !(sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) &&
713 journal->j_superblock->s_start != 0) {
714 retval = EXT2_ET_JOURNAL_FLAGS_WRONG;
719 * If we don't need to do replay the journal, check to see if
720 * the journal's errno is set; if so, we need to mark the file
721 * system as being corrupt and clear the journal's s_errno.
723 if (!(sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER) &&
724 journal->j_superblock->s_errno) {
725 fs->super->s_state |= EXT2_ERROR_FS;
726 ext2fs_mark_super_dirty(fs);
727 journal->j_superblock->s_errno = 0;
728 ext2fs_journal_sb_csum_set(journal, journal->j_superblock);
729 mark_buffer_dirty(journal->j_sb_buffer);
733 ext2fs_journal_release(fs, journal, 0, retval ? 1 : 0);
737 static errcode_t recover_ext3_journal(ext2_filsys fs)
742 journal_init_revoke_caches();
743 retval = ext2fs_get_journal(fs, &journal);
747 retval = ext2fs_journal_load(journal);
751 retval = journal_init_revoke(journal, 1024);
755 retval = -journal_recover(journal);
759 if (journal->j_failed_commit) {
760 journal->j_superblock->s_errno = -EINVAL;
761 mark_buffer_dirty(journal->j_sb_buffer);
765 journal_destroy_revoke(journal);
766 journal_destroy_revoke_caches();
767 ext2fs_journal_release(fs, journal, 1, 0);
771 errcode_t ext2fs_run_ext3_journal(ext2_filsys *fsp)
773 ext2_filsys fs = *fsp;
774 io_manager io_ptr = fs->io->manager;
775 errcode_t retval, recover_retval;
777 unsigned long long kbytes_written = 0;
782 if (!(fs->flags & EXT2_FLAG_RW))
783 return EXT2_ET_FILE_RO;
785 if (fs->flags & EXT2_FLAG_DIRTY)
786 ext2fs_flush(fs); /* Force out any modifications */
788 recover_retval = recover_ext3_journal(fs);
791 * Reload the filesystem context to get up-to-date data from disk
792 * because journal recovery will change the filesystem under us.
794 if (fs->super->s_kbytes_written &&
795 fs->io->manager->get_stats)
796 fs->io->manager->get_stats(fs->io, &stats);
797 if (stats && stats->bytes_written)
798 kbytes_written = stats->bytes_written >> 10;
801 fsname = strdup(fs->device_name);
803 fsblocksize = fs->blocksize;
805 retval = ext2fs_open(fsname, fsflags,
806 0, fsblocksize, io_ptr,
813 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
814 fs->super->s_kbytes_written += kbytes_written;
816 /* Set the superblock flags */
817 ext2fs_clear_recover(fs, recover_retval != 0);
820 * Do one last sanity check, and propagate journal->s_errno to
821 * the EXT2_ERROR_FS flag in the fs superblock if needed.
823 retval = ext2fs_check_ext3_journal(fs);
824 return retval ? retval : recover_retval;
827 errcode_t ext2fs_open_journal(ext2_filsys fs, journal_t **j)
832 journal_init_revoke_caches();
833 retval = ext2fs_get_journal(fs, &journal);
837 retval = ext2fs_journal_load(journal);
841 retval = journal_init_revoke(journal, 1024);
845 if (journal->j_failed_commit) {
846 journal->j_superblock->s_errno = -EINVAL;
847 mark_buffer_dirty(journal->j_sb_buffer);
854 journal_destroy_revoke(journal);
855 journal_destroy_revoke_caches();
856 ext2fs_journal_release(fs, journal, 1, 0);
860 errcode_t ext2fs_close_journal(ext2_filsys fs, journal_t **j)
862 journal_t *journal = *j;
864 journal_destroy_revoke(journal);
865 journal_destroy_revoke_caches();
866 ext2fs_journal_release(fs, journal, 0, 0);
872 void jbd2_commit_block_csum_set(journal_t *j, struct buffer_head *bh)
874 struct commit_header *h;
877 if (!journal_has_csum_v2or3(j))
880 h = (struct commit_header *)(bh->b_data);
881 h->h_chksum_type = 0;
882 h->h_chksum_size = 0;
884 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
885 h->h_chksum[0] = ext2fs_cpu_to_be32(csum);
888 void jbd2_revoke_csum_set(journal_t *j, struct buffer_head *bh)
890 struct journal_revoke_tail *tail;
893 if (!journal_has_csum_v2or3(j))
896 tail = (struct journal_revoke_tail *)(bh->b_data + j->j_blocksize -
897 sizeof(struct journal_revoke_tail));
898 tail->r_checksum = 0;
899 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
900 tail->r_checksum = ext2fs_cpu_to_be32(csum);
903 void jbd2_descr_block_csum_set(journal_t *j, struct buffer_head *bh)
905 struct journal_block_tail *tail;
908 if (!journal_has_csum_v2or3(j))
911 tail = (struct journal_block_tail *)(bh->b_data + j->j_blocksize -
912 sizeof(struct journal_block_tail));
913 tail->t_checksum = 0;
914 csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize);
915 tail->t_checksum = ext2fs_cpu_to_be32(csum);
918 void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
919 struct buffer_head *bh, __u32 sequence)
921 journal_block_tag3_t *tag3 = (journal_block_tag3_t *)tag;
925 if (!journal_has_csum_v2or3(j))
928 seq = ext2fs_cpu_to_be32(sequence);
929 csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq));
930 csum32 = jbd2_chksum(j, csum32, bh->b_data, bh->b_size);
932 if (JFS_HAS_INCOMPAT_FEATURE(j, JFS_FEATURE_INCOMPAT_CSUM_V3))
933 tag3->t_checksum = ext2fs_cpu_to_be32(csum32);
935 tag->t_checksum = ext2fs_cpu_to_be16(csum32);