.. | .. |
---|
368 | 368 | struct buffer_head *bh) |
---|
369 | 369 | { |
---|
370 | 370 | ext4_fsblk_t blk; |
---|
371 | | - struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); |
---|
| 371 | + struct ext4_group_info *grp; |
---|
| 372 | + |
---|
| 373 | + if (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY) |
---|
| 374 | + return 0; |
---|
| 375 | + |
---|
| 376 | + grp = ext4_get_group_info(sb, block_group); |
---|
372 | 377 | |
---|
373 | 378 | if (buffer_verified(bh)) |
---|
374 | 379 | return 0; |
---|
.. | .. |
---|
379 | 384 | if (buffer_verified(bh)) |
---|
380 | 385 | goto verified; |
---|
381 | 386 | if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group, |
---|
382 | | - desc, bh))) { |
---|
| 387 | + desc, bh) || |
---|
| 388 | + ext4_simulate_fail(sb, EXT4_SIM_BBITMAP_CRC))) { |
---|
383 | 389 | ext4_unlock_group(sb, block_group); |
---|
384 | 390 | ext4_error(sb, "bg %u: bad block bitmap checksum", block_group); |
---|
385 | 391 | ext4_mark_group_bitmap_corrupted(sb, block_group, |
---|
.. | .. |
---|
409 | 415 | * Read the bitmap for a given block_group,and validate the |
---|
410 | 416 | * bits for block/inode/inode tables are set in the bitmaps |
---|
411 | 417 | * |
---|
412 | | - * Return buffer_head on success or NULL in case of failure. |
---|
| 418 | + * Return buffer_head on success or an ERR_PTR in case of failure. |
---|
413 | 419 | */ |
---|
414 | 420 | struct buffer_head * |
---|
415 | | -ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group) |
---|
| 421 | +ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group, |
---|
| 422 | + bool ignore_locked) |
---|
416 | 423 | { |
---|
417 | 424 | struct ext4_group_desc *desc; |
---|
418 | 425 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
---|
.. | .. |
---|
438 | 445 | "block_group = %u, block_bitmap = %llu", |
---|
439 | 446 | block_group, bitmap_blk); |
---|
440 | 447 | return ERR_PTR(-ENOMEM); |
---|
| 448 | + } |
---|
| 449 | + |
---|
| 450 | + if (ignore_locked && buffer_locked(bh)) { |
---|
| 451 | + /* buffer under IO already, return if called for prefetching */ |
---|
| 452 | + put_bh(bh); |
---|
| 453 | + return NULL; |
---|
441 | 454 | } |
---|
442 | 455 | |
---|
443 | 456 | if (bitmap_uptodate(bh)) |
---|
.. | .. |
---|
486 | 499 | * submit the buffer_head for reading |
---|
487 | 500 | */ |
---|
488 | 501 | set_buffer_new(bh); |
---|
489 | | - trace_ext4_read_block_bitmap_load(sb, block_group); |
---|
490 | | - bh->b_end_io = ext4_end_bitmap_read; |
---|
491 | | - get_bh(bh); |
---|
492 | | - submit_bh(REQ_OP_READ, REQ_META | REQ_PRIO, bh); |
---|
| 502 | + trace_ext4_read_block_bitmap_load(sb, block_group, ignore_locked); |
---|
| 503 | + ext4_read_bh_nowait(bh, REQ_META | REQ_PRIO | |
---|
| 504 | + (ignore_locked ? REQ_RAHEAD : 0), |
---|
| 505 | + ext4_end_bitmap_read); |
---|
493 | 506 | return bh; |
---|
494 | 507 | verify: |
---|
495 | 508 | err = ext4_validate_block_bitmap(sb, desc, block_group, bh); |
---|
.. | .. |
---|
501 | 514 | return ERR_PTR(err); |
---|
502 | 515 | } |
---|
503 | 516 | |
---|
504 | | -/* Returns 0 on success, 1 on error */ |
---|
| 517 | +/* Returns 0 on success, -errno on error */ |
---|
505 | 518 | int ext4_wait_block_bitmap(struct super_block *sb, ext4_group_t block_group, |
---|
506 | 519 | struct buffer_head *bh) |
---|
507 | 520 | { |
---|
.. | .. |
---|
513 | 526 | if (!desc) |
---|
514 | 527 | return -EFSCORRUPTED; |
---|
515 | 528 | wait_on_buffer(bh); |
---|
| 529 | + ext4_simulate_fail_bh(sb, bh, EXT4_SIM_BBITMAP_EIO); |
---|
516 | 530 | if (!buffer_uptodate(bh)) { |
---|
517 | | - ext4_error(sb, "Cannot read block bitmap - " |
---|
518 | | - "block_group = %u, block_bitmap = %llu", |
---|
519 | | - block_group, (unsigned long long) bh->b_blocknr); |
---|
| 531 | + ext4_error_err(sb, EIO, "Cannot read block bitmap - " |
---|
| 532 | + "block_group = %u, block_bitmap = %llu", |
---|
| 533 | + block_group, (unsigned long long) bh->b_blocknr); |
---|
520 | 534 | ext4_mark_group_bitmap_corrupted(sb, block_group, |
---|
521 | 535 | EXT4_GROUP_INFO_BBITMAP_CORRUPT); |
---|
522 | 536 | return -EIO; |
---|
.. | .. |
---|
532 | 546 | struct buffer_head *bh; |
---|
533 | 547 | int err; |
---|
534 | 548 | |
---|
535 | | - bh = ext4_read_block_bitmap_nowait(sb, block_group); |
---|
| 549 | + bh = ext4_read_block_bitmap_nowait(sb, block_group, false); |
---|
536 | 550 | if (IS_ERR(bh)) |
---|
537 | 551 | return bh; |
---|
538 | 552 | err = ext4_wait_block_bitmap(sb, block_group, bh); |
---|
.. | .. |
---|
611 | 625 | } |
---|
612 | 626 | |
---|
613 | 627 | /** |
---|
614 | | - * ext4_should_retry_alloc() |
---|
615 | | - * @sb: super block |
---|
616 | | - * @retries number of attemps has been made |
---|
| 628 | + * ext4_should_retry_alloc() - check if a block allocation should be retried |
---|
| 629 | + * @sb: superblock |
---|
| 630 | + * @retries: number of retry attempts made so far |
---|
617 | 631 | * |
---|
618 | | - * ext4_should_retry_alloc() is called when ENOSPC is returned, and if |
---|
619 | | - * it is profitable to retry the operation, this function will wait |
---|
620 | | - * for the current or committing transaction to complete, and then |
---|
621 | | - * return TRUE. We will only retry once. |
---|
| 632 | + * ext4_should_retry_alloc() is called when ENOSPC is returned while |
---|
| 633 | + * attempting to allocate blocks. If there's an indication that a pending |
---|
| 634 | + * journal transaction might free some space and allow another attempt to |
---|
| 635 | + * succeed, this function will wait for the current or committing transaction |
---|
| 636 | + * to complete and then return TRUE. |
---|
622 | 637 | */ |
---|
623 | 638 | int ext4_should_retry_alloc(struct super_block *sb, int *retries) |
---|
624 | 639 | { |
---|
625 | | - if (!ext4_has_free_clusters(EXT4_SB(sb), 1, 0) || |
---|
626 | | - (*retries)++ > 1 || |
---|
627 | | - !EXT4_SB(sb)->s_journal) |
---|
| 640 | + struct ext4_sb_info *sbi = EXT4_SB(sb); |
---|
| 641 | + |
---|
| 642 | + if (!sbi->s_journal) |
---|
628 | 643 | return 0; |
---|
629 | 644 | |
---|
| 645 | + if (++(*retries) > 3) { |
---|
| 646 | + percpu_counter_inc(&sbi->s_sra_exceeded_retry_limit); |
---|
| 647 | + return 0; |
---|
| 648 | + } |
---|
| 649 | + |
---|
| 650 | + /* |
---|
| 651 | + * if there's no indication that blocks are about to be freed it's |
---|
| 652 | + * possible we just missed a transaction commit that did so |
---|
| 653 | + */ |
---|
630 | 654 | smp_mb(); |
---|
631 | | - if (EXT4_SB(sb)->s_mb_free_pending == 0) |
---|
632 | | - return 0; |
---|
| 655 | + if (sbi->s_mb_free_pending == 0) |
---|
| 656 | + return ext4_has_free_clusters(sbi, 1, 0); |
---|
633 | 657 | |
---|
| 658 | + /* |
---|
| 659 | + * it's possible we've just missed a transaction commit here, |
---|
| 660 | + * so ignore the returned status |
---|
| 661 | + */ |
---|
634 | 662 | jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id); |
---|
635 | | - jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal); |
---|
| 663 | + (void) jbd2_journal_force_commit_nested(sbi->s_journal); |
---|
636 | 664 | return 1; |
---|
637 | 665 | } |
---|
638 | 666 | |
---|
.. | .. |
---|
901 | 929 | return bg_start; |
---|
902 | 930 | |
---|
903 | 931 | if (bg_start + EXT4_BLOCKS_PER_GROUP(inode->i_sb) <= last_block) |
---|
904 | | - colour = (current->pid % 16) * |
---|
| 932 | + colour = (task_pid_nr(current) % 16) * |
---|
905 | 933 | (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16); |
---|
906 | 934 | else |
---|
907 | | - colour = (current->pid % 16) * ((last_block - bg_start) / 16); |
---|
| 935 | + colour = (task_pid_nr(current) % 16) * |
---|
| 936 | + ((last_block - bg_start) / 16); |
---|
908 | 937 | return bg_start + colour; |
---|
909 | 938 | } |
---|
910 | 939 | |
---|