* Return 0 if the superblock checksum type matches the checksum value of that
  * algorithm. Pass the raw disk superblock data.
  */
-static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
-                                 char *raw_disk_sb)
+int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
+                          const struct btrfs_super_block *disk_sb)
 {
-       struct btrfs_super_block *disk_sb =
-               (struct btrfs_super_block *)raw_disk_sb;
        char result[BTRFS_CSUM_SIZE];
        SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
 
         * BTRFS_SUPER_INFO_SIZE range, we expect that the unused space is
         * filled with zeros and is included in the checksum.
         */
-       crypto_shash_digest(shash, raw_disk_sb + BTRFS_CSUM_SIZE,
+       crypto_shash_digest(shash, (const u8 *)disk_sb + BTRFS_CSUM_SIZE,
                            BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE, result);
 
        if (memcmp(disk_sb->csum, result, fs_info->csum_size))
         * We want to check superblock checksum, the type is stored inside.
         * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).
         */
-       if (btrfs_check_super_csum(fs_info, (u8 *)disk_super)) {
+       if (btrfs_check_super_csum(fs_info, disk_super)) {
                btrfs_err(fs_info, "superblock checksum mismatch");
                err = -EINVAL;
                btrfs_release_disk_super(disk_super);
 
 void btrfs_clean_tree_block(struct extent_buffer *buf);
 void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info);
 int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info);
+int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
+                          const struct btrfs_super_block *disk_sb);
 int __cold open_ctree(struct super_block *sb,
               struct btrfs_fs_devices *fs_devices,
               char *options);
 
 {
        struct btrfs_fs_info *fs_info = dev->fs_info;
        struct btrfs_super_block *sb;
+       u16 csum_type;
        int ret = 0;
 
        /* This should be called with fs still frozen. */
        if (IS_ERR(sb))
                return PTR_ERR(sb);
 
+       /* Verify the checksum. */
+       csum_type = btrfs_super_csum_type(sb);
+       if (csum_type != btrfs_super_csum_type(fs_info->super_copy)) {
+               btrfs_err(fs_info, "csum type changed, has %u expect %u",
+                         csum_type, btrfs_super_csum_type(fs_info->super_copy));
+               ret = -EUCLEAN;
+               goto out;
+       }
+
+       if (btrfs_check_super_csum(fs_info, sb)) {
+               btrfs_err(fs_info, "csum for on-disk super block no longer matches");
+               ret = -EUCLEAN;
+               goto out;
+       }
+
        /* Btrfs_validate_super() includes fsid check against super->fsid. */
        ret = btrfs_validate_super(fs_info, sb, 0);
        if (ret < 0)