journal.c (01b5adcebb977bc61b64167adce6d8260c9da33c) | journal.c (4fd5ea43bc11602bfabe2c8f5378586d34bd2b0a) |
---|---|
1/* 2 * linux/fs/jbd2/journal.c 3 * 4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998 5 * 6 * Copyright 1998 Red Hat corp --- All Rights Reserved 7 * 8 * This file is part of the Linux kernel and is made available under --- 92 unchanged lines hidden (view full) --- 101int jbd2_verify_csum_type(journal_t *j, journal_superblock_t *sb) 102{ 103 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) 104 return 1; 105 106 return sb->s_checksum_type == JBD2_CRC32C_CHKSUM; 107} 108 | 1/* 2 * linux/fs/jbd2/journal.c 3 * 4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998 5 * 6 * Copyright 1998 Red Hat corp --- All Rights Reserved 7 * 8 * This file is part of the Linux kernel and is made available under --- 92 unchanged lines hidden (view full) --- 101int jbd2_verify_csum_type(journal_t *j, journal_superblock_t *sb) 102{ 103 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) 104 return 1; 105 106 return sb->s_checksum_type == JBD2_CRC32C_CHKSUM; 107} 108 |
109static __u32 jbd2_superblock_csum(journal_t *j, journal_superblock_t *sb) 110{ 111 __u32 csum, old_csum; 112 113 old_csum = sb->s_checksum; 114 sb->s_checksum = 0; 115 csum = jbd2_chksum(j, ~0, (char *)sb, sizeof(journal_superblock_t)); 116 sb->s_checksum = old_csum; 117 118 return cpu_to_be32(csum); 119} 120 121int jbd2_superblock_csum_verify(journal_t *j, journal_superblock_t *sb) 122{ 123 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) 124 return 1; 125 126 return sb->s_checksum == jbd2_superblock_csum(j, sb); 127} 128 129void jbd2_superblock_csum_set(journal_t *j, journal_superblock_t *sb) 130{ 131 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) 132 return; 133 134 sb->s_checksum = jbd2_superblock_csum(j, sb); 135} 136 |
|
109/* 110 * Helper function used to manage commit timeouts 111 */ 112 113static void commit_timeout(unsigned long __data) 114{ 115 struct task_struct * p = (struct task_struct *) __data; 116 --- 1235 unchanged lines hidden (view full) --- 1352static void jbd2_journal_update_sb_errno(journal_t *journal) 1353{ 1354 journal_superblock_t *sb = journal->j_superblock; 1355 1356 read_lock(&journal->j_state_lock); 1357 jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", 1358 journal->j_errno); 1359 sb->s_errno = cpu_to_be32(journal->j_errno); | 137/* 138 * Helper function used to manage commit timeouts 139 */ 140 141static void commit_timeout(unsigned long __data) 142{ 143 struct task_struct * p = (struct task_struct *) __data; 144 --- 1235 unchanged lines hidden (view full) --- 1380static void jbd2_journal_update_sb_errno(journal_t *journal) 1381{ 1382 journal_superblock_t *sb = journal->j_superblock; 1383 1384 read_lock(&journal->j_state_lock); 1385 jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", 1386 journal->j_errno); 1387 sb->s_errno = cpu_to_be32(journal->j_errno); |
1388 jbd2_superblock_csum_set(journal, sb); |
|
1360 read_unlock(&journal->j_state_lock); 1361 1362 jbd2_write_superblock(journal, WRITE_SYNC); 1363} 1364 1365/* 1366 * Read the superblock for a given journal, performing initial 1367 * validation of the format. --- 76 unchanged lines hidden (view full) --- 1444 if (IS_ERR(journal->j_chksum_driver)) { 1445 printk(KERN_ERR "JBD: Cannot load crc32c driver.\n"); 1446 err = PTR_ERR(journal->j_chksum_driver); 1447 journal->j_chksum_driver = NULL; 1448 goto out; 1449 } 1450 } 1451 | 1389 read_unlock(&journal->j_state_lock); 1390 1391 jbd2_write_superblock(journal, WRITE_SYNC); 1392} 1393 1394/* 1395 * Read the superblock for a given journal, performing initial 1396 * validation of the format. --- 76 unchanged lines hidden (view full) --- 1473 if (IS_ERR(journal->j_chksum_driver)) { 1474 printk(KERN_ERR "JBD: Cannot load crc32c driver.\n"); 1475 err = PTR_ERR(journal->j_chksum_driver); 1476 journal->j_chksum_driver = NULL; 1477 goto out; 1478 } 1479 } 1480 |
1481 /* Check superblock checksum */ 1482 if (!jbd2_superblock_csum_verify(journal, sb)) { 1483 printk(KERN_ERR "JBD: journal checksum error\n"); 1484 goto out; 1485 } 1486 1487 /* Precompute checksum seed for all metadata */ 1488 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) 1489 journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid, 1490 sizeof(sb->s_uuid)); 1491 |
|
1452 set_buffer_verified(bh); 1453 1454 return 0; 1455 1456out: 1457 journal_fail_superblock(journal); 1458 return err; 1459} --- 267 unchanged lines hidden (view full) --- 1727 0, 0); 1728 if (IS_ERR(journal->j_chksum_driver)) { 1729 printk(KERN_ERR "JBD: Cannot load crc32c " 1730 "driver.\n"); 1731 journal->j_chksum_driver = NULL; 1732 return 0; 1733 } 1734 } | 1492 set_buffer_verified(bh); 1493 1494 return 0; 1495 1496out: 1497 journal_fail_superblock(journal); 1498 return err; 1499} --- 267 unchanged lines hidden (view full) --- 1767 0, 0); 1768 if (IS_ERR(journal->j_chksum_driver)) { 1769 printk(KERN_ERR "JBD: Cannot load crc32c " 1770 "driver.\n"); 1771 journal->j_chksum_driver = NULL; 1772 return 0; 1773 } 1774 } |
1775 1776 /* Precompute checksum seed for all metadata */ 1777 if (JBD2_HAS_INCOMPAT_FEATURE(journal, 1778 JBD2_FEATURE_INCOMPAT_CSUM_V2)) 1779 journal->j_csum_seed = jbd2_chksum(journal, ~0, 1780 sb->s_uuid, 1781 sizeof(sb->s_uuid)); |
|
1735 } 1736 1737 /* If enabling v1 checksums, downgrade superblock */ 1738 if (COMPAT_FEATURE_ON(JBD2_FEATURE_COMPAT_CHECKSUM)) 1739 sb->s_feature_incompat &= 1740 ~cpu_to_be32(JBD2_FEATURE_INCOMPAT_CSUM_V2); 1741 1742 sb->s_feature_compat |= cpu_to_be32(compat); --- 835 unchanged lines hidden --- | 1782 } 1783 1784 /* If enabling v1 checksums, downgrade superblock */ 1785 if (COMPAT_FEATURE_ON(JBD2_FEATURE_COMPAT_CHECKSUM)) 1786 sb->s_feature_incompat &= 1787 ~cpu_to_be32(JBD2_FEATURE_INCOMPAT_CSUM_V2); 1788 1789 sb->s_feature_compat |= cpu_to_be32(compat); --- 835 unchanged lines hidden --- |