@@ -1336,6 +1336,174 @@ static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink,
1336
1336
return count ;
1337
1337
}
1338
1338
1339
+ /*
1340
+ * If the journal init or create aborts, we need to mark the journal
1341
+ * superblock as being NULL to prevent the journal destroy from writing
1342
+ * back a bogus superblock.
1343
+ */
1344
+ static void journal_fail_superblock (journal_t * journal )
1345
+ {
1346
+ struct buffer_head * bh = journal -> j_sb_buffer ;
1347
+ brelse (bh );
1348
+ journal -> j_sb_buffer = NULL ;
1349
+ }
1350
+
1351
+ /*
1352
+ * Read the superblock for a given journal, performing initial
1353
+ * validation of the format.
1354
+ */
1355
+ static int journal_get_superblock (journal_t * journal )
1356
+ {
1357
+ struct buffer_head * bh ;
1358
+ journal_superblock_t * sb ;
1359
+ int err ;
1360
+
1361
+ bh = journal -> j_sb_buffer ;
1362
+
1363
+ J_ASSERT (bh != NULL );
1364
+ if (buffer_verified (bh ))
1365
+ return 0 ;
1366
+
1367
+ err = bh_read (bh , 0 );
1368
+ if (err < 0 ) {
1369
+ printk (KERN_ERR
1370
+ "JBD2: IO error reading journal superblock\n" );
1371
+ goto out ;
1372
+ }
1373
+
1374
+ sb = journal -> j_superblock ;
1375
+
1376
+ err = - EINVAL ;
1377
+
1378
+ if (sb -> s_header .h_magic != cpu_to_be32 (JBD2_MAGIC_NUMBER ) ||
1379
+ sb -> s_blocksize != cpu_to_be32 (journal -> j_blocksize )) {
1380
+ printk (KERN_WARNING "JBD2: no valid journal superblock found\n" );
1381
+ goto out ;
1382
+ }
1383
+
1384
+ if (be32_to_cpu (sb -> s_header .h_blocktype ) != JBD2_SUPERBLOCK_V1 &&
1385
+ be32_to_cpu (sb -> s_header .h_blocktype ) != JBD2_SUPERBLOCK_V2 ) {
1386
+ printk (KERN_WARNING "JBD2: unrecognised superblock format ID\n" );
1387
+ goto out ;
1388
+ }
1389
+
1390
+ if (be32_to_cpu (sb -> s_maxlen ) > journal -> j_total_len ) {
1391
+ printk (KERN_WARNING "JBD2: journal file too short\n" );
1392
+ goto out ;
1393
+ }
1394
+
1395
+ if (be32_to_cpu (sb -> s_first ) == 0 ||
1396
+ be32_to_cpu (sb -> s_first ) >= journal -> j_total_len ) {
1397
+ printk (KERN_WARNING
1398
+ "JBD2: Invalid start block of journal: %u\n" ,
1399
+ be32_to_cpu (sb -> s_first ));
1400
+ goto out ;
1401
+ }
1402
+
1403
+ if (jbd2_has_feature_csum2 (journal ) &&
1404
+ jbd2_has_feature_csum3 (journal )) {
1405
+ /* Can't have checksum v2 and v3 at the same time! */
1406
+ printk (KERN_ERR "JBD2: Can't enable checksumming v2 and v3 "
1407
+ "at the same time!\n" );
1408
+ goto out ;
1409
+ }
1410
+
1411
+ if (jbd2_journal_has_csum_v2or3_feature (journal ) &&
1412
+ jbd2_has_feature_checksum (journal )) {
1413
+ /* Can't have checksum v1 and v2 on at the same time! */
1414
+ printk (KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 "
1415
+ "at the same time!\n" );
1416
+ goto out ;
1417
+ }
1418
+
1419
+ if (!jbd2_verify_csum_type (journal , sb )) {
1420
+ printk (KERN_ERR "JBD2: Unknown checksum type\n" );
1421
+ goto out ;
1422
+ }
1423
+
1424
+ /* Load the checksum driver */
1425
+ if (jbd2_journal_has_csum_v2or3_feature (journal )) {
1426
+ journal -> j_chksum_driver = crypto_alloc_shash ("crc32c" , 0 , 0 );
1427
+ if (IS_ERR (journal -> j_chksum_driver )) {
1428
+ printk (KERN_ERR "JBD2: Cannot load crc32c driver.\n" );
1429
+ err = PTR_ERR (journal -> j_chksum_driver );
1430
+ journal -> j_chksum_driver = NULL ;
1431
+ goto out ;
1432
+ }
1433
+ /* Check superblock checksum */
1434
+ if (sb -> s_checksum != jbd2_superblock_csum (journal , sb )) {
1435
+ printk (KERN_ERR "JBD2: journal checksum error\n" );
1436
+ err = - EFSBADCRC ;
1437
+ goto out ;
1438
+ }
1439
+ }
1440
+ set_buffer_verified (bh );
1441
+ return 0 ;
1442
+
1443
+ out :
1444
+ journal_fail_superblock (journal );
1445
+ return err ;
1446
+ }
1447
+
1448
+ static int journal_revoke_records_per_block (journal_t * journal )
1449
+ {
1450
+ int record_size ;
1451
+ int space = journal -> j_blocksize - sizeof (jbd2_journal_revoke_header_t );
1452
+
1453
+ if (jbd2_has_feature_64bit (journal ))
1454
+ record_size = 8 ;
1455
+ else
1456
+ record_size = 4 ;
1457
+
1458
+ if (jbd2_journal_has_csum_v2or3 (journal ))
1459
+ space -= sizeof (struct jbd2_journal_block_tail );
1460
+ return space / record_size ;
1461
+ }
1462
+
1463
+ /*
1464
+ * Load the on-disk journal superblock and read the key fields into the
1465
+ * journal_t.
1466
+ */
1467
+ static int load_superblock (journal_t * journal )
1468
+ {
1469
+ int err ;
1470
+ journal_superblock_t * sb ;
1471
+ int num_fc_blocks ;
1472
+
1473
+ err = journal_get_superblock (journal );
1474
+ if (err )
1475
+ return err ;
1476
+
1477
+ sb = journal -> j_superblock ;
1478
+
1479
+ journal -> j_tail_sequence = be32_to_cpu (sb -> s_sequence );
1480
+ journal -> j_tail = be32_to_cpu (sb -> s_start );
1481
+ journal -> j_first = be32_to_cpu (sb -> s_first );
1482
+ journal -> j_errno = be32_to_cpu (sb -> s_errno );
1483
+ journal -> j_last = be32_to_cpu (sb -> s_maxlen );
1484
+
1485
+ if (be32_to_cpu (sb -> s_maxlen ) < journal -> j_total_len )
1486
+ journal -> j_total_len = be32_to_cpu (sb -> s_maxlen );
1487
+ /* Precompute checksum seed for all metadata */
1488
+ if (jbd2_journal_has_csum_v2or3 (journal ))
1489
+ journal -> j_csum_seed = jbd2_chksum (journal , ~0 , sb -> s_uuid ,
1490
+ sizeof (sb -> s_uuid ));
1491
+ journal -> j_revoke_records_per_block =
1492
+ journal_revoke_records_per_block (journal );
1493
+
1494
+ if (jbd2_has_feature_fast_commit (journal )) {
1495
+ journal -> j_fc_last = be32_to_cpu (sb -> s_maxlen );
1496
+ num_fc_blocks = jbd2_journal_get_num_fc_blks (sb );
1497
+ if (journal -> j_last - num_fc_blocks >= JBD2_MIN_JOURNAL_BLOCKS )
1498
+ journal -> j_last = journal -> j_fc_last - num_fc_blocks ;
1499
+ journal -> j_fc_first = journal -> j_last + 1 ;
1500
+ journal -> j_fc_off = 0 ;
1501
+ }
1502
+
1503
+ return 0 ;
1504
+ }
1505
+
1506
+
1339
1507
/*
1340
1508
* Management for journal control blocks: functions to create and
1341
1509
* destroy journal_t structures, and to initialise and read existing
@@ -1521,18 +1689,6 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
1521
1689
return journal ;
1522
1690
}
1523
1691
1524
- /*
1525
- * If the journal init or create aborts, we need to mark the journal
1526
- * superblock as being NULL to prevent the journal destroy from writing
1527
- * back a bogus superblock.
1528
- */
1529
- static void journal_fail_superblock (journal_t * journal )
1530
- {
1531
- struct buffer_head * bh = journal -> j_sb_buffer ;
1532
- brelse (bh );
1533
- journal -> j_sb_buffer = NULL ;
1534
- }
1535
-
1536
1692
/*
1537
1693
* Given a journal_t structure, initialise the various fields for
1538
1694
* startup of a new journaling session. We use this both when creating
@@ -1889,163 +2045,6 @@ void jbd2_journal_update_sb_errno(journal_t *journal)
1889
2045
}
1890
2046
EXPORT_SYMBOL (jbd2_journal_update_sb_errno );
1891
2047
1892
- static int journal_revoke_records_per_block (journal_t * journal )
1893
- {
1894
- int record_size ;
1895
- int space = journal -> j_blocksize - sizeof (jbd2_journal_revoke_header_t );
1896
-
1897
- if (jbd2_has_feature_64bit (journal ))
1898
- record_size = 8 ;
1899
- else
1900
- record_size = 4 ;
1901
-
1902
- if (jbd2_journal_has_csum_v2or3 (journal ))
1903
- space -= sizeof (struct jbd2_journal_block_tail );
1904
- return space / record_size ;
1905
- }
1906
-
1907
- /*
1908
- * Read the superblock for a given journal, performing initial
1909
- * validation of the format.
1910
- */
1911
- static int journal_get_superblock (journal_t * journal )
1912
- {
1913
- struct buffer_head * bh ;
1914
- journal_superblock_t * sb ;
1915
- int err ;
1916
-
1917
- bh = journal -> j_sb_buffer ;
1918
-
1919
- J_ASSERT (bh != NULL );
1920
- if (buffer_verified (bh ))
1921
- return 0 ;
1922
-
1923
- err = bh_read (bh , 0 );
1924
- if (err < 0 ) {
1925
- printk (KERN_ERR
1926
- "JBD2: IO error reading journal superblock\n" );
1927
- goto out ;
1928
- }
1929
-
1930
- sb = journal -> j_superblock ;
1931
-
1932
- err = - EINVAL ;
1933
-
1934
- if (sb -> s_header .h_magic != cpu_to_be32 (JBD2_MAGIC_NUMBER ) ||
1935
- sb -> s_blocksize != cpu_to_be32 (journal -> j_blocksize )) {
1936
- printk (KERN_WARNING "JBD2: no valid journal superblock found\n" );
1937
- goto out ;
1938
- }
1939
-
1940
- if (be32_to_cpu (sb -> s_header .h_blocktype ) != JBD2_SUPERBLOCK_V1 &&
1941
- be32_to_cpu (sb -> s_header .h_blocktype ) != JBD2_SUPERBLOCK_V2 ) {
1942
- printk (KERN_WARNING "JBD2: unrecognised superblock format ID\n" );
1943
- goto out ;
1944
- }
1945
-
1946
- if (be32_to_cpu (sb -> s_maxlen ) > journal -> j_total_len ) {
1947
- printk (KERN_WARNING "JBD2: journal file too short\n" );
1948
- goto out ;
1949
- }
1950
-
1951
- if (be32_to_cpu (sb -> s_first ) == 0 ||
1952
- be32_to_cpu (sb -> s_first ) >= journal -> j_total_len ) {
1953
- printk (KERN_WARNING
1954
- "JBD2: Invalid start block of journal: %u\n" ,
1955
- be32_to_cpu (sb -> s_first ));
1956
- goto out ;
1957
- }
1958
-
1959
- if (jbd2_has_feature_csum2 (journal ) &&
1960
- jbd2_has_feature_csum3 (journal )) {
1961
- /* Can't have checksum v2 and v3 at the same time! */
1962
- printk (KERN_ERR "JBD2: Can't enable checksumming v2 and v3 "
1963
- "at the same time!\n" );
1964
- goto out ;
1965
- }
1966
-
1967
- if (jbd2_journal_has_csum_v2or3_feature (journal ) &&
1968
- jbd2_has_feature_checksum (journal )) {
1969
- /* Can't have checksum v1 and v2 on at the same time! */
1970
- printk (KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 "
1971
- "at the same time!\n" );
1972
- goto out ;
1973
- }
1974
-
1975
- if (!jbd2_verify_csum_type (journal , sb )) {
1976
- printk (KERN_ERR "JBD2: Unknown checksum type\n" );
1977
- goto out ;
1978
- }
1979
-
1980
- /* Load the checksum driver */
1981
- if (jbd2_journal_has_csum_v2or3_feature (journal )) {
1982
- journal -> j_chksum_driver = crypto_alloc_shash ("crc32c" , 0 , 0 );
1983
- if (IS_ERR (journal -> j_chksum_driver )) {
1984
- printk (KERN_ERR "JBD2: Cannot load crc32c driver.\n" );
1985
- err = PTR_ERR (journal -> j_chksum_driver );
1986
- journal -> j_chksum_driver = NULL ;
1987
- goto out ;
1988
- }
1989
- /* Check superblock checksum */
1990
- if (sb -> s_checksum != jbd2_superblock_csum (journal , sb )) {
1991
- printk (KERN_ERR "JBD2: journal checksum error\n" );
1992
- err = - EFSBADCRC ;
1993
- goto out ;
1994
- }
1995
- }
1996
- set_buffer_verified (bh );
1997
- return 0 ;
1998
-
1999
- out :
2000
- journal_fail_superblock (journal );
2001
- return err ;
2002
- }
2003
-
2004
- /*
2005
- * Load the on-disk journal superblock and read the key fields into the
2006
- * journal_t.
2007
- */
2008
-
2009
- static int load_superblock (journal_t * journal )
2010
- {
2011
- int err ;
2012
- journal_superblock_t * sb ;
2013
- int num_fc_blocks ;
2014
-
2015
- err = journal_get_superblock (journal );
2016
- if (err )
2017
- return err ;
2018
-
2019
- sb = journal -> j_superblock ;
2020
-
2021
- journal -> j_tail_sequence = be32_to_cpu (sb -> s_sequence );
2022
- journal -> j_tail = be32_to_cpu (sb -> s_start );
2023
- journal -> j_first = be32_to_cpu (sb -> s_first );
2024
- journal -> j_errno = be32_to_cpu (sb -> s_errno );
2025
- journal -> j_last = be32_to_cpu (sb -> s_maxlen );
2026
-
2027
- if (be32_to_cpu (sb -> s_maxlen ) < journal -> j_total_len )
2028
- journal -> j_total_len = be32_to_cpu (sb -> s_maxlen );
2029
- /* Precompute checksum seed for all metadata */
2030
- if (jbd2_journal_has_csum_v2or3 (journal ))
2031
- journal -> j_csum_seed = jbd2_chksum (journal , ~0 , sb -> s_uuid ,
2032
- sizeof (sb -> s_uuid ));
2033
- journal -> j_revoke_records_per_block =
2034
- journal_revoke_records_per_block (journal );
2035
-
2036
- if (jbd2_has_feature_fast_commit (journal )) {
2037
- journal -> j_fc_last = be32_to_cpu (sb -> s_maxlen );
2038
- num_fc_blocks = jbd2_journal_get_num_fc_blks (sb );
2039
- if (journal -> j_last - num_fc_blocks >= JBD2_MIN_JOURNAL_BLOCKS )
2040
- journal -> j_last = journal -> j_fc_last - num_fc_blocks ;
2041
- journal -> j_fc_first = journal -> j_last + 1 ;
2042
- journal -> j_fc_off = 0 ;
2043
- }
2044
-
2045
- return 0 ;
2046
- }
2047
-
2048
-
2049
2048
/**
2050
2049
* jbd2_journal_load() - Read journal from disk.
2051
2050
* @journal: Journal to act on.
0 commit comments