@@ -1341,53 +1341,37 @@ static void journal_fail_superblock(journal_t *journal)
1341
1341
}
1342
1342
1343
1343
/*
1344
- * Read the superblock for a given journal, performing initial
1344
+ * Check the superblock for a given journal, performing initial
1345
1345
* validation of the format.
1346
1346
*/
1347
- static int journal_get_superblock (journal_t * journal )
1347
+ static int journal_check_superblock (journal_t * journal )
1348
1348
{
1349
- struct buffer_head * bh ;
1350
- journal_superblock_t * sb ;
1351
- int err ;
1352
-
1353
- bh = journal -> j_sb_buffer ;
1354
-
1355
- J_ASSERT (bh != NULL );
1356
-
1357
- err = bh_read (bh , 0 );
1358
- if (err < 0 ) {
1359
- printk (KERN_ERR
1360
- "JBD2: IO error reading journal superblock\n" );
1361
- goto out ;
1362
- }
1363
-
1364
- sb = journal -> j_superblock ;
1365
-
1366
- err = - EINVAL ;
1349
+ journal_superblock_t * sb = journal -> j_superblock ;
1350
+ int err = - EINVAL ;
1367
1351
1368
1352
if (sb -> s_header .h_magic != cpu_to_be32 (JBD2_MAGIC_NUMBER ) ||
1369
1353
sb -> s_blocksize != cpu_to_be32 (journal -> j_blocksize )) {
1370
1354
printk (KERN_WARNING "JBD2: no valid journal superblock found\n" );
1371
- goto out ;
1355
+ return err ;
1372
1356
}
1373
1357
1374
1358
if (be32_to_cpu (sb -> s_header .h_blocktype ) != JBD2_SUPERBLOCK_V1 &&
1375
1359
be32_to_cpu (sb -> s_header .h_blocktype ) != JBD2_SUPERBLOCK_V2 ) {
1376
1360
printk (KERN_WARNING "JBD2: unrecognised superblock format ID\n" );
1377
- goto out ;
1361
+ return err ;
1378
1362
}
1379
1363
1380
1364
if (be32_to_cpu (sb -> s_maxlen ) > journal -> j_total_len ) {
1381
1365
printk (KERN_WARNING "JBD2: journal file too short\n" );
1382
- goto out ;
1366
+ return err ;
1383
1367
}
1384
1368
1385
1369
if (be32_to_cpu (sb -> s_first ) == 0 ||
1386
1370
be32_to_cpu (sb -> s_first ) >= journal -> j_total_len ) {
1387
1371
printk (KERN_WARNING
1388
1372
"JBD2: Invalid start block of journal: %u\n" ,
1389
1373
be32_to_cpu (sb -> s_first ));
1390
- goto out ;
1374
+ return err ;
1391
1375
}
1392
1376
1393
1377
/*
@@ -1402,51 +1386,48 @@ static int journal_get_superblock(journal_t *journal)
1402
1386
(sb -> s_feature_incompat &
1403
1387
~cpu_to_be32 (JBD2_KNOWN_INCOMPAT_FEATURES ))) {
1404
1388
printk (KERN_WARNING "JBD2: Unrecognised features on journal\n" );
1405
- goto out ;
1389
+ return err ;
1406
1390
}
1407
1391
1408
1392
if (jbd2_has_feature_csum2 (journal ) &&
1409
1393
jbd2_has_feature_csum3 (journal )) {
1410
1394
/* Can't have checksum v2 and v3 at the same time! */
1411
1395
printk (KERN_ERR "JBD2: Can't enable checksumming v2 and v3 "
1412
1396
"at the same time!\n" );
1413
- goto out ;
1397
+ return err ;
1414
1398
}
1415
1399
1416
1400
if (jbd2_journal_has_csum_v2or3_feature (journal ) &&
1417
1401
jbd2_has_feature_checksum (journal )) {
1418
1402
/* Can't have checksum v1 and v2 on at the same time! */
1419
1403
printk (KERN_ERR "JBD2: Can't enable checksumming v1 and v2/3 "
1420
1404
"at the same time!\n" );
1421
- goto out ;
1405
+ return err ;
1422
1406
}
1423
1407
1424
1408
/* Load the checksum driver */
1425
1409
if (jbd2_journal_has_csum_v2or3_feature (journal )) {
1426
1410
if (sb -> s_checksum_type != JBD2_CRC32C_CHKSUM ) {
1427
1411
printk (KERN_ERR "JBD2: Unknown checksum type\n" );
1428
- goto out ;
1412
+ return err ;
1429
1413
}
1430
1414
1431
1415
journal -> j_chksum_driver = crypto_alloc_shash ("crc32c" , 0 , 0 );
1432
1416
if (IS_ERR (journal -> j_chksum_driver )) {
1433
1417
printk (KERN_ERR "JBD2: Cannot load crc32c driver.\n" );
1434
1418
err = PTR_ERR (journal -> j_chksum_driver );
1435
1419
journal -> j_chksum_driver = NULL ;
1436
- goto out ;
1420
+ return err ;
1437
1421
}
1438
1422
/* Check superblock checksum */
1439
1423
if (sb -> s_checksum != jbd2_superblock_csum (journal , sb )) {
1440
1424
printk (KERN_ERR "JBD2: journal checksum error\n" );
1441
1425
err = - EFSBADCRC ;
1442
- goto out ;
1426
+ return err ;
1443
1427
}
1444
1428
}
1445
- return 0 ;
1446
1429
1447
- out :
1448
- journal_fail_superblock (journal );
1449
- return err ;
1430
+ return 0 ;
1450
1431
}
1451
1432
1452
1433
static int journal_revoke_records_per_block (journal_t * journal )
@@ -1468,17 +1449,31 @@ static int journal_revoke_records_per_block(journal_t *journal)
1468
1449
* Load the on-disk journal superblock and read the key fields into the
1469
1450
* journal_t.
1470
1451
*/
1471
- static int load_superblock (journal_t * journal )
1452
+ static int journal_load_superblock (journal_t * journal )
1472
1453
{
1473
1454
int err ;
1455
+ struct buffer_head * bh ;
1474
1456
journal_superblock_t * sb ;
1475
1457
int num_fc_blocks ;
1476
1458
1477
- err = journal_get_superblock (journal );
1478
- if (err )
1479
- return err ;
1459
+ bh = getblk_unmovable (journal -> j_dev , journal -> j_blk_offset ,
1460
+ journal -> j_blocksize );
1461
+ if (bh )
1462
+ err = bh_read (bh , 0 );
1463
+ if (!bh || err < 0 ) {
1464
+ pr_err ("%s: Cannot read journal superblock\n" , __func__ );
1465
+ brelse (bh );
1466
+ return - EIO ;
1467
+ }
1480
1468
1481
- sb = journal -> j_superblock ;
1469
+ journal -> j_sb_buffer = bh ;
1470
+ sb = (journal_superblock_t * )bh -> b_data ;
1471
+ journal -> j_superblock = sb ;
1472
+ err = journal_check_superblock (journal );
1473
+ if (err ) {
1474
+ journal_fail_superblock (journal );
1475
+ return err ;
1476
+ }
1482
1477
1483
1478
journal -> j_tail_sequence = be32_to_cpu (sb -> s_sequence );
1484
1479
journal -> j_tail = be32_to_cpu (sb -> s_start );
@@ -1524,7 +1519,6 @@ static journal_t *journal_init_common(struct block_device *bdev,
1524
1519
static struct lock_class_key jbd2_trans_commit_key ;
1525
1520
journal_t * journal ;
1526
1521
int err ;
1527
- struct buffer_head * bh ;
1528
1522
int n ;
1529
1523
1530
1524
journal = kzalloc (sizeof (* journal ), GFP_KERNEL );
@@ -1577,16 +1571,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
1577
1571
if (!journal -> j_wbuf )
1578
1572
goto err_cleanup ;
1579
1573
1580
- bh = getblk_unmovable (journal -> j_dev , start , journal -> j_blocksize );
1581
- if (!bh ) {
1582
- pr_err ("%s: Cannot get buffer for journal superblock\n" ,
1583
- __func__ );
1584
- goto err_cleanup ;
1585
- }
1586
- journal -> j_sb_buffer = bh ;
1587
- journal -> j_superblock = (journal_superblock_t * )bh -> b_data ;
1588
-
1589
- err = load_superblock (journal );
1574
+ err = journal_load_superblock (journal );
1590
1575
if (err )
1591
1576
goto err_cleanup ;
1592
1577
0 commit comments