| .. | .. |
|---|
| 53 | 53 | return -EPERM; |
|---|
| 54 | 54 | |
|---|
| 55 | 55 | /* |
|---|
| 56 | + * If the reserved GDT blocks is non-zero, the resize_inode feature |
|---|
| 57 | + * should always be set. |
|---|
| 58 | + */ |
|---|
| 59 | + if (EXT4_SB(sb)->s_es->s_reserved_gdt_blocks && |
|---|
| 60 | + !ext4_has_feature_resize_inode(sb)) { |
|---|
| 61 | + ext4_error(sb, "resize_inode disabled but reserved GDT blocks non-zero"); |
|---|
| 62 | + return -EFSCORRUPTED; |
|---|
| 63 | + } |
|---|
| 64 | + |
|---|
| 65 | + /* |
|---|
| 56 | 66 | * If we are not using the primary superblock/GDT copy don't resize, |
|---|
| 57 | 67 | * because the user tools have no way of handling this. Probably a |
|---|
| 58 | 68 | * bad time to do it anyways. |
|---|
| .. | .. |
|---|
| 72 | 82 | ext4_warning(sb, "There are errors in the filesystem, " |
|---|
| 73 | 83 | "so online resizing is not allowed"); |
|---|
| 74 | 84 | return -EPERM; |
|---|
| 85 | + } |
|---|
| 86 | + |
|---|
| 87 | + if (ext4_has_feature_sparse_super2(sb)) { |
|---|
| 88 | + ext4_msg(sb, KERN_ERR, "Online resizing not supported with sparse_super2"); |
|---|
| 89 | + return -EOPNOTSUPP; |
|---|
| 75 | 90 | } |
|---|
| 76 | 91 | |
|---|
| 77 | 92 | if (test_and_set_bit_lock(EXT4_FLAGS_RESIZING, |
|---|
| .. | .. |
|---|
| 415 | 430 | return bh; |
|---|
| 416 | 431 | } |
|---|
| 417 | 432 | |
|---|
| 418 | | -/* |
|---|
| 419 | | - * If we have fewer than thresh credits, extend by EXT4_MAX_TRANS_DATA. |
|---|
| 420 | | - * If that fails, restart the transaction & regain write access for the |
|---|
| 421 | | - * buffer head which is used for block_bitmap modifications. |
|---|
| 422 | | - */ |
|---|
| 423 | | -static int extend_or_restart_transaction(handle_t *handle, int thresh) |
|---|
| 433 | +static int ext4_resize_ensure_credits_batch(handle_t *handle, int credits) |
|---|
| 424 | 434 | { |
|---|
| 425 | | - int err; |
|---|
| 426 | | - |
|---|
| 427 | | - if (ext4_handle_has_enough_credits(handle, thresh)) |
|---|
| 428 | | - return 0; |
|---|
| 429 | | - |
|---|
| 430 | | - err = ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA); |
|---|
| 431 | | - if (err < 0) |
|---|
| 432 | | - return err; |
|---|
| 433 | | - if (err) { |
|---|
| 434 | | - err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA); |
|---|
| 435 | | - if (err) |
|---|
| 436 | | - return err; |
|---|
| 437 | | - } |
|---|
| 438 | | - |
|---|
| 439 | | - return 0; |
|---|
| 435 | + return ext4_journal_ensure_credits_fn(handle, credits, |
|---|
| 436 | + EXT4_MAX_TRANS_DATA, 0, 0); |
|---|
| 440 | 437 | } |
|---|
| 441 | 438 | |
|---|
| 442 | 439 | /* |
|---|
| .. | .. |
|---|
| 478 | 475 | continue; |
|---|
| 479 | 476 | } |
|---|
| 480 | 477 | |
|---|
| 481 | | - err = extend_or_restart_transaction(handle, 1); |
|---|
| 482 | | - if (err) |
|---|
| 478 | + err = ext4_resize_ensure_credits_batch(handle, 1); |
|---|
| 479 | + if (err < 0) |
|---|
| 483 | 480 | return err; |
|---|
| 484 | 481 | |
|---|
| 485 | 482 | bh = sb_getblk(sb, flex_gd->groups[group].block_bitmap); |
|---|
| .. | .. |
|---|
| 571 | 568 | struct buffer_head *gdb; |
|---|
| 572 | 569 | |
|---|
| 573 | 570 | ext4_debug("update backup group %#04llx\n", block); |
|---|
| 574 | | - err = extend_or_restart_transaction(handle, 1); |
|---|
| 575 | | - if (err) |
|---|
| 571 | + err = ext4_resize_ensure_credits_batch(handle, 1); |
|---|
| 572 | + if (err < 0) |
|---|
| 576 | 573 | goto out; |
|---|
| 577 | 574 | |
|---|
| 578 | 575 | gdb = sb_getblk(sb, block); |
|---|
| .. | .. |
|---|
| 629 | 626 | |
|---|
| 630 | 627 | /* Initialize block bitmap of the @group */ |
|---|
| 631 | 628 | block = group_data[i].block_bitmap; |
|---|
| 632 | | - err = extend_or_restart_transaction(handle, 1); |
|---|
| 633 | | - if (err) |
|---|
| 629 | + err = ext4_resize_ensure_credits_batch(handle, 1); |
|---|
| 630 | + if (err < 0) |
|---|
| 634 | 631 | goto out; |
|---|
| 635 | 632 | |
|---|
| 636 | 633 | bh = bclean(handle, sb, block); |
|---|
| .. | .. |
|---|
| 658 | 655 | |
|---|
| 659 | 656 | /* Initialize inode bitmap of the @group */ |
|---|
| 660 | 657 | block = group_data[i].inode_bitmap; |
|---|
| 661 | | - err = extend_or_restart_transaction(handle, 1); |
|---|
| 662 | | - if (err) |
|---|
| 658 | + err = ext4_resize_ensure_credits_batch(handle, 1); |
|---|
| 659 | + if (err < 0) |
|---|
| 663 | 660 | goto out; |
|---|
| 664 | 661 | /* Mark unused entries in inode bitmap used */ |
|---|
| 665 | 662 | bh = bclean(handle, sb, block); |
|---|
| .. | .. |
|---|
| 871 | 868 | if (unlikely(err)) |
|---|
| 872 | 869 | goto errout; |
|---|
| 873 | 870 | |
|---|
| 874 | | - n_group_desc = ext4_kvmalloc((gdb_num + 1) * |
|---|
| 875 | | - sizeof(struct buffer_head *), |
|---|
| 876 | | - GFP_NOFS); |
|---|
| 871 | + n_group_desc = kvmalloc((gdb_num + 1) * sizeof(struct buffer_head *), |
|---|
| 872 | + GFP_KERNEL); |
|---|
| 877 | 873 | if (!n_group_desc) { |
|---|
| 878 | 874 | err = -ENOMEM; |
|---|
| 879 | 875 | ext4_warning(sb, "not enough memory for %lu groups", |
|---|
| .. | .. |
|---|
| 949 | 945 | gdb_bh = ext4_sb_bread(sb, gdblock, 0); |
|---|
| 950 | 946 | if (IS_ERR(gdb_bh)) |
|---|
| 951 | 947 | return PTR_ERR(gdb_bh); |
|---|
| 952 | | - n_group_desc = ext4_kvmalloc((gdb_num + 1) * |
|---|
| 953 | | - sizeof(struct buffer_head *), |
|---|
| 954 | | - GFP_NOFS); |
|---|
| 948 | + n_group_desc = kvmalloc((gdb_num + 1) * sizeof(struct buffer_head *), |
|---|
| 949 | + GFP_KERNEL); |
|---|
| 955 | 950 | if (!n_group_desc) { |
|---|
| 956 | 951 | brelse(gdb_bh); |
|---|
| 957 | 952 | err = -ENOMEM; |
|---|
| .. | .. |
|---|
| 1142 | 1137 | ext4_fsblk_t backup_block; |
|---|
| 1143 | 1138 | |
|---|
| 1144 | 1139 | /* Out of journal space, and can't get more - abort - so sad */ |
|---|
| 1145 | | - if (ext4_handle_valid(handle) && |
|---|
| 1146 | | - handle->h_buffer_credits == 0 && |
|---|
| 1147 | | - ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA) && |
|---|
| 1148 | | - (err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA))) |
|---|
| 1140 | + err = ext4_resize_ensure_credits_batch(handle, 1); |
|---|
| 1141 | + if (err < 0) |
|---|
| 1149 | 1142 | break; |
|---|
| 1150 | 1143 | |
|---|
| 1151 | 1144 | if (meta_bg == 0) |
|---|
| .. | .. |
|---|
| 1267 | 1260 | if (unlikely(!bh)) |
|---|
| 1268 | 1261 | return NULL; |
|---|
| 1269 | 1262 | if (!bh_uptodate_or_lock(bh)) { |
|---|
| 1270 | | - if (bh_submit_read(bh) < 0) { |
|---|
| 1263 | + if (ext4_read_bh(bh, 0, NULL) < 0) { |
|---|
| 1271 | 1264 | brelse(bh); |
|---|
| 1272 | 1265 | return NULL; |
|---|
| 1273 | 1266 | } |
|---|
| .. | .. |
|---|
| 1468 | 1461 | * Update the fs overhead information |
|---|
| 1469 | 1462 | */ |
|---|
| 1470 | 1463 | ext4_calculate_overhead(sb); |
|---|
| 1464 | + es->s_overhead_clusters = cpu_to_le32(sbi->s_overhead); |
|---|
| 1471 | 1465 | |
|---|
| 1472 | 1466 | if (test_opt(sb, DEBUG)) |
|---|
| 1473 | 1467 | printk(KERN_DEBUG "EXT4-fs: added group %u:" |
|---|
| .. | .. |
|---|
| 1799 | 1793 | ext4_msg(sb, KERN_ERR, |
|---|
| 1800 | 1794 | "filesystem too large to resize to %llu blocks safely", |
|---|
| 1801 | 1795 | n_blocks_count); |
|---|
| 1802 | | - if (sizeof(sector_t) < 8) |
|---|
| 1803 | | - ext4_warning(sb, "CONFIG_LBDAF not enabled"); |
|---|
| 1804 | 1796 | return -EINVAL; |
|---|
| 1805 | 1797 | } |
|---|
| 1806 | 1798 | |
|---|
| .. | .. |
|---|
| 1832 | 1824 | o_blocks_count + add, add); |
|---|
| 1833 | 1825 | |
|---|
| 1834 | 1826 | /* See if the device is actually as big as what was requested */ |
|---|
| 1835 | | - bh = sb_bread(sb, o_blocks_count + add - 1); |
|---|
| 1836 | | - if (!bh) { |
|---|
| 1827 | + bh = ext4_sb_bread(sb, o_blocks_count + add - 1, 0); |
|---|
| 1828 | + if (IS_ERR(bh)) { |
|---|
| 1837 | 1829 | ext4_warning(sb, "can't read last block, resize aborted"); |
|---|
| 1838 | 1830 | return -ENOSPC; |
|---|
| 1839 | 1831 | } |
|---|
| .. | .. |
|---|
| 1958 | 1950 | int meta_bg; |
|---|
| 1959 | 1951 | |
|---|
| 1960 | 1952 | /* See if the device is actually as big as what was requested */ |
|---|
| 1961 | | - bh = sb_bread(sb, n_blocks_count - 1); |
|---|
| 1962 | | - if (!bh) { |
|---|
| 1953 | + bh = ext4_sb_bread(sb, n_blocks_count - 1, 0); |
|---|
| 1954 | + if (IS_ERR(bh)) { |
|---|
| 1963 | 1955 | ext4_warning(sb, "can't read last block, resize aborted"); |
|---|
| 1964 | 1956 | return -ENOSPC; |
|---|
| 1965 | 1957 | } |
|---|
| 1966 | 1958 | brelse(bh); |
|---|
| 1959 | + |
|---|
| 1960 | + /* |
|---|
| 1961 | + * For bigalloc, trim the requested size to the nearest cluster |
|---|
| 1962 | + * boundary to avoid creating an unusable filesystem. We do this |
|---|
| 1963 | + * silently, instead of returning an error, to avoid breaking |
|---|
| 1964 | + * callers that blindly resize the filesystem to the full size of |
|---|
| 1965 | + * the underlying block device. |
|---|
| 1966 | + */ |
|---|
| 1967 | + if (ext4_has_feature_bigalloc(sb)) |
|---|
| 1968 | + n_blocks_count &= ~((1 << EXT4_CLUSTER_BITS(sb)) - 1); |
|---|
| 1967 | 1969 | |
|---|
| 1968 | 1970 | retry: |
|---|
| 1969 | 1971 | o_blocks_count = ext4_blocks_count(es); |
|---|
| .. | .. |
|---|
| 2066 | 2068 | goto out; |
|---|
| 2067 | 2069 | } |
|---|
| 2068 | 2070 | |
|---|
| 2069 | | - if (ext4_blocks_count(es) == n_blocks_count) |
|---|
| 2071 | + if (ext4_blocks_count(es) == n_blocks_count && n_blocks_count_retry == 0) |
|---|
| 2070 | 2072 | goto out; |
|---|
| 2071 | 2073 | |
|---|
| 2072 | 2074 | err = ext4_alloc_flex_bg_array(sb, n_group + 1); |
|---|