@@ -191,6 +191,7 @@ static int ext4_init_block_bitmap(struct super_block *sb,
191
191
/* If checksum is bad mark all blocks used to prevent allocation
192
192
* essentially implementing a per-group read-only flag. */
193
193
if (!ext4_group_desc_csum_verify (sb , block_group , gdp )) {
194
+ ext4_error (sb , "Checksum bad for group %u" , block_group );
194
195
grp = ext4_get_group_info (sb , block_group );
195
196
if (!EXT4_MB_GRP_BBITMAP_CORRUPT (grp ))
196
197
percpu_counter_sub (& sbi -> s_freeclusters_counter ,
@@ -203,7 +204,7 @@ static int ext4_init_block_bitmap(struct super_block *sb,
203
204
count );
204
205
}
205
206
set_bit (EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT , & grp -> bb_state );
206
- return - EIO ;
207
+ return - EFSBADCRC ;
207
208
}
208
209
memset (bh -> b_data , 0 , sb -> s_blocksize );
209
210
@@ -213,7 +214,7 @@ static int ext4_init_block_bitmap(struct super_block *sb,
213
214
214
215
start = ext4_group_first_block_no (sb , block_group );
215
216
216
- if (EXT4_HAS_INCOMPAT_FEATURE (sb , EXT4_FEATURE_INCOMPAT_FLEX_BG ))
217
+ if (ext4_has_feature_flex_bg (sb ))
217
218
flex_bg = 1 ;
218
219
219
220
/* Set bits for block and inode bitmaps, and inode table */
@@ -322,7 +323,7 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
322
323
ext4_fsblk_t blk ;
323
324
ext4_fsblk_t group_first_block ;
324
325
325
- if (EXT4_HAS_INCOMPAT_FEATURE (sb , EXT4_FEATURE_INCOMPAT_FLEX_BG )) {
326
+ if (ext4_has_feature_flex_bg (sb )) {
326
327
/* with FLEX_BG, the inode/block bitmaps and itable
327
328
* blocks may not be in the group at all
328
329
* so the bitmap validation will be skipped for those groups
@@ -360,42 +361,45 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
360
361
return 0 ;
361
362
}
362
363
363
- static void ext4_validate_block_bitmap (struct super_block * sb ,
364
- struct ext4_group_desc * desc ,
365
- ext4_group_t block_group ,
366
- struct buffer_head * bh )
364
+ static int ext4_validate_block_bitmap (struct super_block * sb ,
365
+ struct ext4_group_desc * desc ,
366
+ ext4_group_t block_group ,
367
+ struct buffer_head * bh )
367
368
{
368
369
ext4_fsblk_t blk ;
369
370
struct ext4_group_info * grp = ext4_get_group_info (sb , block_group );
370
371
struct ext4_sb_info * sbi = EXT4_SB (sb );
371
372
372
- if (buffer_verified (bh ) || EXT4_MB_GRP_BBITMAP_CORRUPT (grp ))
373
- return ;
373
+ if (buffer_verified (bh ))
374
+ return 0 ;
375
+ if (EXT4_MB_GRP_BBITMAP_CORRUPT (grp ))
376
+ return - EFSCORRUPTED ;
374
377
375
378
ext4_lock_group (sb , block_group );
376
- blk = ext4_valid_block_bitmap ( sb , desc , block_group , bh );
377
- if ( unlikely ( blk != 0 )) {
379
+ if ( unlikely (! ext4_block_bitmap_csum_verify ( sb , block_group ,
380
+ desc , bh ) )) {
378
381
ext4_unlock_group (sb , block_group );
379
- ext4_error (sb , "bg %u: block %llu: invalid block bitmap" ,
380
- block_group , blk );
382
+ ext4_error (sb , "bg %u: bad block bitmap checksum" , block_group );
381
383
if (!EXT4_MB_GRP_BBITMAP_CORRUPT (grp ))
382
384
percpu_counter_sub (& sbi -> s_freeclusters_counter ,
383
385
grp -> bb_free );
384
386
set_bit (EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT , & grp -> bb_state );
385
- return ;
387
+ return - EFSBADCRC ;
386
388
}
387
- if ( unlikely (! ext4_block_bitmap_csum_verify ( sb , block_group ,
388
- desc , bh ) )) {
389
+ blk = ext4_valid_block_bitmap ( sb , desc , block_group , bh );
390
+ if ( unlikely ( blk != 0 )) {
389
391
ext4_unlock_group (sb , block_group );
390
- ext4_error (sb , "bg %u: bad block bitmap checksum" , block_group );
392
+ ext4_error (sb , "bg %u: block %llu: invalid block bitmap" ,
393
+ block_group , blk );
391
394
if (!EXT4_MB_GRP_BBITMAP_CORRUPT (grp ))
392
395
percpu_counter_sub (& sbi -> s_freeclusters_counter ,
393
396
grp -> bb_free );
394
397
set_bit (EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT , & grp -> bb_state );
395
- return ;
398
+ return - EFSCORRUPTED ;
396
399
}
397
400
set_buffer_verified (bh );
398
401
ext4_unlock_group (sb , block_group );
402
+ return 0 ;
399
403
}
400
404
401
405
/**
@@ -414,17 +418,18 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
414
418
struct ext4_group_desc * desc ;
415
419
struct buffer_head * bh ;
416
420
ext4_fsblk_t bitmap_blk ;
421
+ int err ;
417
422
418
423
desc = ext4_get_group_desc (sb , block_group , NULL );
419
424
if (!desc )
420
- return NULL ;
425
+ return ERR_PTR ( - EFSCORRUPTED ) ;
421
426
bitmap_blk = ext4_block_bitmap (sb , desc );
422
427
bh = sb_getblk (sb , bitmap_blk );
423
428
if (unlikely (!bh )) {
424
429
ext4_error (sb , "Cannot get buffer for block bitmap - "
425
430
"block_group = %u, block_bitmap = %llu" ,
426
431
block_group , bitmap_blk );
427
- return NULL ;
432
+ return ERR_PTR ( - ENOMEM ) ;
428
433
}
429
434
430
435
if (bitmap_uptodate (bh ))
@@ -437,15 +442,14 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
437
442
}
438
443
ext4_lock_group (sb , block_group );
439
444
if (desc -> bg_flags & cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) {
440
- int err ;
441
445
442
446
err = ext4_init_block_bitmap (sb , bh , block_group , desc );
443
447
set_bitmap_uptodate (bh );
444
448
set_buffer_uptodate (bh );
445
449
ext4_unlock_group (sb , block_group );
446
450
unlock_buffer (bh );
447
451
if (err )
448
- ext4_error ( sb , "Checksum bad for grp %u" , block_group ) ;
452
+ goto out ;
449
453
goto verify ;
450
454
}
451
455
ext4_unlock_group (sb , block_group );
@@ -468,11 +472,13 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
468
472
submit_bh (READ | REQ_META | REQ_PRIO , bh );
469
473
return bh ;
470
474
verify :
471
- ext4_validate_block_bitmap (sb , desc , block_group , bh );
472
- if (buffer_verified (bh ))
473
- return bh ;
475
+ err = ext4_validate_block_bitmap (sb , desc , block_group , bh );
476
+ if (err )
477
+ goto out ;
478
+ return bh ;
479
+ out :
474
480
put_bh (bh );
475
- return NULL ;
481
+ return ERR_PTR ( err ) ;
476
482
}
477
483
478
484
/* Returns 0 on success, 1 on error */
@@ -485,32 +491,32 @@ int ext4_wait_block_bitmap(struct super_block *sb, ext4_group_t block_group,
485
491
return 0 ;
486
492
desc = ext4_get_group_desc (sb , block_group , NULL );
487
493
if (!desc )
488
- return 1 ;
494
+ return - EFSCORRUPTED ;
489
495
wait_on_buffer (bh );
490
496
if (!buffer_uptodate (bh )) {
491
497
ext4_error (sb , "Cannot read block bitmap - "
492
498
"block_group = %u, block_bitmap = %llu" ,
493
499
block_group , (unsigned long long ) bh -> b_blocknr );
494
- return 1 ;
500
+ return - EIO ;
495
501
}
496
502
clear_buffer_new (bh );
497
503
/* Panic or remount fs read-only if block bitmap is invalid */
498
- ext4_validate_block_bitmap (sb , desc , block_group , bh );
499
- /* ...but check for error just in case errors=continue. */
500
- return !buffer_verified (bh );
504
+ return ext4_validate_block_bitmap (sb , desc , block_group , bh );
501
505
}
502
506
503
507
struct buffer_head *
504
508
ext4_read_block_bitmap (struct super_block * sb , ext4_group_t block_group )
505
509
{
506
510
struct buffer_head * bh ;
511
+ int err ;
507
512
508
513
bh = ext4_read_block_bitmap_nowait (sb , block_group );
509
- if (!bh )
510
- return NULL ;
511
- if (ext4_wait_block_bitmap (sb , block_group , bh )) {
514
+ if (IS_ERR (bh ))
515
+ return bh ;
516
+ err = ext4_wait_block_bitmap (sb , block_group , bh );
517
+ if (err ) {
512
518
put_bh (bh );
513
- return NULL ;
519
+ return ERR_PTR ( err ) ;
514
520
}
515
521
return bh ;
516
522
}
@@ -681,8 +687,10 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
681
687
desc_count += ext4_free_group_clusters (sb , gdp );
682
688
brelse (bitmap_bh );
683
689
bitmap_bh = ext4_read_block_bitmap (sb , i );
684
- if (bitmap_bh == NULL )
690
+ if (IS_ERR (bitmap_bh )) {
691
+ bitmap_bh = NULL ;
685
692
continue ;
693
+ }
686
694
687
695
x = ext4_count_free (bitmap_bh -> b_data ,
688
696
EXT4_CLUSTERS_PER_GROUP (sb ) / 8 );
@@ -740,14 +748,13 @@ int ext4_bg_has_super(struct super_block *sb, ext4_group_t group)
740
748
741
749
if (group == 0 )
742
750
return 1 ;
743
- if (EXT4_HAS_COMPAT_FEATURE (sb , EXT4_FEATURE_COMPAT_SPARSE_SUPER2 )) {
751
+ if (ext4_has_feature_sparse_super2 (sb )) {
744
752
if (group == le32_to_cpu (es -> s_backup_bgs [0 ]) ||
745
753
group == le32_to_cpu (es -> s_backup_bgs [1 ]))
746
754
return 1 ;
747
755
return 0 ;
748
756
}
749
- if ((group <= 1 ) || !EXT4_HAS_RO_COMPAT_FEATURE (sb ,
750
- EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER ))
757
+ if ((group <= 1 ) || !ext4_has_feature_sparse_super (sb ))
751
758
return 1 ;
752
759
if (!(group & 1 ))
753
760
return 0 ;
@@ -776,7 +783,7 @@ static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
776
783
if (!ext4_bg_has_super (sb , group ))
777
784
return 0 ;
778
785
779
- if (EXT4_HAS_INCOMPAT_FEATURE (sb , EXT4_FEATURE_INCOMPAT_META_BG ))
786
+ if (ext4_has_feature_meta_bg (sb ))
780
787
return le32_to_cpu (EXT4_SB (sb )-> s_es -> s_first_meta_bg );
781
788
else
782
789
return EXT4_SB (sb )-> s_gdb_count ;
@@ -797,8 +804,7 @@ unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
797
804
le32_to_cpu (EXT4_SB (sb )-> s_es -> s_first_meta_bg );
798
805
unsigned long metagroup = group / EXT4_DESC_PER_BLOCK (sb );
799
806
800
- if (!EXT4_HAS_INCOMPAT_FEATURE (sb ,EXT4_FEATURE_INCOMPAT_META_BG ) ||
801
- metagroup < first_meta_bg )
807
+ if (!ext4_has_feature_meta_bg (sb ) || metagroup < first_meta_bg )
802
808
return ext4_bg_num_gdb_nometa (sb , group );
803
809
804
810
return ext4_bg_num_gdb_meta (sb ,group );
@@ -818,7 +824,7 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
818
824
/* Check for superblock and gdt backups in this group */
819
825
num = ext4_bg_has_super (sb , block_group );
820
826
821
- if (!EXT4_HAS_INCOMPAT_FEATURE (sb , EXT4_FEATURE_INCOMPAT_META_BG ) ||
827
+ if (!ext4_has_feature_meta_bg (sb ) ||
822
828
block_group < le32_to_cpu (sbi -> s_es -> s_first_meta_bg ) *
823
829
sbi -> s_desc_per_block ) {
824
830
if (num ) {
0 commit comments