resize.c (ff877ea80efa2015b6263766f78ee42c2a1b32f9) | resize.c (2b2d6d019724de6e51ac5bcf22b5ef969daefa8b) |
---|---|
1/* 2 * linux/fs/ext4/resize.c 3 * 4 * Support for resizing an ext4 filesystem while it is mounted. 5 * 6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com> 7 * 8 * This could probably be made into a module, because it is not often in use. --- 59 unchanged lines hidden (view full) --- 68 ext4_warning(sb, __func__, 69 "Block bitmap not in group (block %llu)", 70 (unsigned long long)input->block_bitmap); 71 else if (outside(input->inode_bitmap, start, end)) 72 ext4_warning(sb, __func__, 73 "Inode bitmap not in group (block %llu)", 74 (unsigned long long)input->inode_bitmap); 75 else if (outside(input->inode_table, start, end) || | 1/* 2 * linux/fs/ext4/resize.c 3 * 4 * Support for resizing an ext4 filesystem while it is mounted. 5 * 6 * Copyright (C) 2001, 2002 Andreas Dilger <adilger@clusterfs.com> 7 * 8 * This could probably be made into a module, because it is not often in use. --- 59 unchanged lines hidden (view full) --- 68 ext4_warning(sb, __func__, 69 "Block bitmap not in group (block %llu)", 70 (unsigned long long)input->block_bitmap); 71 else if (outside(input->inode_bitmap, start, end)) 72 ext4_warning(sb, __func__, 73 "Inode bitmap not in group (block %llu)", 74 (unsigned long long)input->inode_bitmap); 75 else if (outside(input->inode_table, start, end) || |
76 outside(itend - 1, start, end)) | 76 outside(itend - 1, start, end)) |
77 ext4_warning(sb, __func__, 78 "Inode table not in group (blocks %llu-%llu)", 79 (unsigned long long)input->inode_table, itend - 1); 80 else if (input->inode_bitmap == input->block_bitmap) 81 ext4_warning(sb, __func__, 82 "Block bitmap same as inode bitmap (%llu)", 83 (unsigned long long)input->block_bitmap); 84 else if (inside(input->block_bitmap, input->inode_table, itend)) --- 14 unchanged lines hidden (view full) --- 99 start, metaend - 1); 100 else if (inside(input->inode_bitmap, start, metaend)) 101 ext4_warning(sb, __func__, 102 "Inode bitmap (%llu) in GDT table" 103 " (%llu-%llu)", 104 (unsigned long long)input->inode_bitmap, 105 start, metaend - 1); 106 else if (inside(input->inode_table, start, metaend) || | 77 ext4_warning(sb, __func__, 78 "Inode table not in group (blocks %llu-%llu)", 79 (unsigned long long)input->inode_table, itend - 1); 80 else if (input->inode_bitmap == input->block_bitmap) 81 ext4_warning(sb, __func__, 82 "Block bitmap same as inode bitmap (%llu)", 83 (unsigned long long)input->block_bitmap); 84 else if (inside(input->block_bitmap, input->inode_table, itend)) --- 14 unchanged lines hidden (view full) --- 99 start, metaend - 1); 100 else if (inside(input->inode_bitmap, start, metaend)) 101 ext4_warning(sb, __func__, 102 "Inode bitmap (%llu) in GDT table" 103 " (%llu-%llu)", 104 (unsigned long long)input->inode_bitmap, 105 start, metaend - 1); 106 else if (inside(input->inode_table, start, metaend) || |
107 inside(itend - 1, start, metaend)) | 107 inside(itend - 1, start, metaend)) |
108 ext4_warning(sb, __func__, 109 "Inode table (%llu-%llu) overlaps" 110 "GDT table (%llu-%llu)", 111 (unsigned long long)input->inode_table, 112 itend - 1, start, metaend - 1); 113 else 114 err = 0; 115 brelse(bh); --- 37 unchanged lines hidden (view full) --- 153 return 0; 154 155 err = ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA); 156 if (err < 0) 157 return err; 158 if (err) { 159 if ((err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA))) 160 return err; | 108 ext4_warning(sb, __func__, 109 "Inode table (%llu-%llu) overlaps" 110 "GDT table (%llu-%llu)", 111 (unsigned long long)input->inode_table, 112 itend - 1, start, metaend - 1); 113 else 114 err = 0; 115 brelse(bh); --- 37 unchanged lines hidden (view full) --- 153 return 0; 154 155 err = ext4_journal_extend(handle, EXT4_MAX_TRANS_DATA); 156 if (err < 0) 157 return err; 158 if (err) { 159 if ((err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA))) 160 return err; |
161 if ((err = ext4_journal_get_write_access(handle, bh))) | 161 if ((err = ext4_journal_get_write_access(handle, bh))) |
162 return err; | 162 return err; |
163 } | 163 } |
164 165 return 0; 166} 167 168/* 169 * Set up the block and inode bitmaps, and the inode table for the new group. 170 * This doesn't need to be part of the main transaction, since we are only 171 * changing blocks outside the actual filesystem. We still do journaling to --- 239 unchanged lines hidden (view full) --- 411 __le32 *data; 412 int err; 413 414 if (test_opt(sb, DEBUG)) 415 printk(KERN_DEBUG 416 "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n", 417 gdb_num); 418 | 164 165 return 0; 166} 167 168/* 169 * Set up the block and inode bitmaps, and the inode table for the new group. 170 * This doesn't need to be part of the main transaction, since we are only 171 * changing blocks outside the actual filesystem. We still do journaling to --- 239 unchanged lines hidden (view full) --- 411 __le32 *data; 412 int err; 413 414 if (test_opt(sb, DEBUG)) 415 printk(KERN_DEBUG 416 "EXT4-fs: ext4_add_new_gdb: adding group block %lu\n", 417 gdb_num); 418 |
419 /* 420 * If we are not using the primary superblock/GDT copy don't resize, 421 * because the user tools have no way of handling this. Probably a 422 * bad time to do it anyways. 423 */ | 419 /* 420 * If we are not using the primary superblock/GDT copy don't resize, 421 * because the user tools have no way of handling this. Probably a 422 * bad time to do it anyways. 423 */ |
424 if (EXT4_SB(sb)->s_sbh->b_blocknr != 425 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) { 426 ext4_warning(sb, __func__, 427 "won't resize using backup superblock at %llu", 428 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr); 429 return -EPERM; 430 } 431 --- 70 unchanged lines hidden (view full) --- 502 kfree(o_group_desc); 503 504 le16_add_cpu(&es->s_reserved_gdt_blocks, -1); 505 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh); 506 507 return 0; 508 509exit_inode: | 424 if (EXT4_SB(sb)->s_sbh->b_blocknr != 425 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) { 426 ext4_warning(sb, __func__, 427 "won't resize using backup superblock at %llu", 428 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr); 429 return -EPERM; 430 } 431 --- 70 unchanged lines hidden (view full) --- 502 kfree(o_group_desc); 503 504 le16_add_cpu(&es->s_reserved_gdt_blocks, -1); 505 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh); 506 507 return 0; 508 509exit_inode: |
510 //ext4_journal_release_buffer(handle, iloc.bh); | 510 /* ext4_journal_release_buffer(handle, iloc.bh); */ |
511 brelse(iloc.bh); 512exit_dindj: | 511 brelse(iloc.bh); 512exit_dindj: |
513 //ext4_journal_release_buffer(handle, dind); | 513 /* ext4_journal_release_buffer(handle, dind); */ |
514exit_primary: | 514exit_primary: |
515 //ext4_journal_release_buffer(handle, *primary); | 515 /* ext4_journal_release_buffer(handle, *primary); */ |
516exit_sbh: | 516exit_sbh: |
517 //ext4_journal_release_buffer(handle, *primary); | 517 /* ext4_journal_release_buffer(handle, *primary); */ |
518exit_dind: 519 brelse(dind); 520exit_bh: 521 brelse(*primary); 522 523 ext4_debug("leaving with error %d\n", err); 524 return err; 525} --- 287 unchanged lines hidden (view full) --- 813 "multiple resizers run on filesystem!"); 814 err = -EBUSY; 815 goto exit_journal; 816 } 817 818 if ((err = ext4_journal_get_write_access(handle, sbi->s_sbh))) 819 goto exit_journal; 820 | 518exit_dind: 519 brelse(dind); 520exit_bh: 521 brelse(*primary); 522 523 ext4_debug("leaving with error %d\n", err); 524 return err; 525} --- 287 unchanged lines hidden (view full) --- 813 "multiple resizers run on filesystem!"); 814 err = -EBUSY; 815 goto exit_journal; 816 } 817 818 if ((err = ext4_journal_get_write_access(handle, sbi->s_sbh))) 819 goto exit_journal; 820 |
821 /* 822 * We will only either add reserved group blocks to a backup group 823 * or remove reserved blocks for the first group in a new group block. 824 * Doing both would be mean more complex code, and sane people don't 825 * use non-sparse filesystems anymore. This is already checked above. 826 */ | 821 /* 822 * We will only either add reserved group blocks to a backup group 823 * or remove reserved blocks for the first group in a new group block. 824 * Doing both would be mean more complex code, and sane people don't 825 * use non-sparse filesystems anymore. This is already checked above. 826 */ |
827 if (gdb_off) { 828 primary = sbi->s_group_desc[gdb_num]; 829 if ((err = ext4_journal_get_write_access(handle, primary))) 830 goto exit_journal; 831 832 if (reserved_gdb && ext4_bg_num_gdb(sb, input->group) && 833 (err = reserve_backup_gdb(handle, inode, input))) 834 goto exit_journal; 835 } else if ((err = add_new_gdb(handle, inode, input, &primary))) 836 goto exit_journal; 837 | 827 if (gdb_off) { 828 primary = sbi->s_group_desc[gdb_num]; 829 if ((err = ext4_journal_get_write_access(handle, primary))) 830 goto exit_journal; 831 832 if (reserved_gdb && ext4_bg_num_gdb(sb, input->group) && 833 (err = reserve_backup_gdb(handle, inode, input))) 834 goto exit_journal; 835 } else if ((err = add_new_gdb(handle, inode, input, &primary))) 836 goto exit_journal; 837 |
838 /* 839 * OK, now we've set up the new group. Time to make it active. 840 * 841 * Current kernels don't lock all allocations via lock_super(), 842 * so we have to be safe wrt. concurrent accesses the group 843 * data. So we need to be careful to set all of the relevant 844 * group descriptor data etc. *before* we enable the group. 845 * 846 * The key field here is sbi->s_groups_count: as long as 847 * that retains its old value, nobody is going to access the new 848 * group. 849 * 850 * So first we update all the descriptor metadata for the new 851 * group; then we update the total disk blocks count; then we 852 * update the groups count to enable the group; then finally we 853 * update the free space counts so that the system can start 854 * using the new disk blocks. 855 */ | 838 /* 839 * OK, now we've set up the new group. Time to make it active. 840 * 841 * Current kernels don't lock all allocations via lock_super(), 842 * so we have to be safe wrt. concurrent accesses the group 843 * data. So we need to be careful to set all of the relevant 844 * group descriptor data etc. *before* we enable the group. 845 * 846 * The key field here is sbi->s_groups_count: as long as 847 * that retains its old value, nobody is going to access the new 848 * group. 849 * 850 * So first we update all the descriptor metadata for the new 851 * group; then we update the total disk blocks count; then we 852 * update the groups count to enable the group; then finally we 853 * update the free space counts so that the system can start 854 * using the new disk blocks. 855 */ |
856 857 /* Update group descriptor block for new group */ 858 gdp = (struct ext4_group_desc *)((char *)primary->b_data + 859 gdb_off * EXT4_DESC_SIZE(sb)); 860 861 ext4_block_bitmap_set(sb, gdp, input->block_bitmap); /* LV FIXME */ 862 ext4_inode_bitmap_set(sb, gdp, input->inode_bitmap); /* LV FIXME */ 863 ext4_inode_table_set(sb, gdp, input->inode_table); /* LV FIXME */ --- 77 unchanged lines hidden (view full) --- 941 update_backups(sb, primary->b_blocknr, primary->b_data, 942 primary->b_size); 943 } 944exit_put: 945 iput(inode); 946 return err; 947} /* ext4_group_add */ 948 | 856 857 /* Update group descriptor block for new group */ 858 gdp = (struct ext4_group_desc *)((char *)primary->b_data + 859 gdb_off * EXT4_DESC_SIZE(sb)); 860 861 ext4_block_bitmap_set(sb, gdp, input->block_bitmap); /* LV FIXME */ 862 ext4_inode_bitmap_set(sb, gdp, input->inode_bitmap); /* LV FIXME */ 863 ext4_inode_table_set(sb, gdp, input->inode_table); /* LV FIXME */ --- 77 unchanged lines hidden (view full) --- 941 update_backups(sb, primary->b_blocknr, primary->b_data, 942 primary->b_size); 943 } 944exit_put: 945 iput(inode); 946 return err; 947} /* ext4_group_add */ 948 |
949/* Extend the filesystem to the new number of blocks specified. This entry | 949/* 950 * Extend the filesystem to the new number of blocks specified. This entry |
950 * point is only used to extend the current filesystem to the end of the last 951 * existing group. It can be accessed via ioctl, or by "remount,resize=<size>" 952 * for emergencies (because it has no dependencies on reserved blocks). 953 * 954 * If we _really_ wanted, we could use default values to call ext4_group_add() 955 * allow the "remount" trick to work for arbitrary resizing, assuming enough 956 * GDT blocks are reserved to grow to the desired size. 957 */ --- 61 unchanged lines hidden (view full) --- 1019 1020 if (o_blocks_count + add < n_blocks_count) 1021 ext4_warning(sb, __func__, 1022 "will only finish group (%llu" 1023 " blocks, %u new)", 1024 o_blocks_count + add, add); 1025 1026 /* See if the device is actually as big as what was requested */ | 951 * point is only used to extend the current filesystem to the end of the last 952 * existing group. It can be accessed via ioctl, or by "remount,resize=<size>" 953 * for emergencies (because it has no dependencies on reserved blocks). 954 * 955 * If we _really_ wanted, we could use default values to call ext4_group_add() 956 * allow the "remount" trick to work for arbitrary resizing, assuming enough 957 * GDT blocks are reserved to grow to the desired size. 958 */ --- 61 unchanged lines hidden (view full) --- 1020 1021 if (o_blocks_count + add < n_blocks_count) 1022 ext4_warning(sb, __func__, 1023 "will only finish group (%llu" 1024 " blocks, %u new)", 1025 o_blocks_count + add, add); 1026 1027 /* See if the device is actually as big as what was requested */ |
1027 bh = sb_bread(sb, o_blocks_count + add -1); | 1028 bh = sb_bread(sb, o_blocks_count + add - 1); |
1028 if (!bh) { 1029 ext4_warning(sb, __func__, 1030 "can't read last block, resize aborted"); 1031 return -ENOSPC; 1032 } 1033 brelse(bh); 1034 1035 /* We will update the superblock, one block bitmap, and --- 85 unchanged lines hidden --- | 1029 if (!bh) { 1030 ext4_warning(sb, __func__, 1031 "can't read last block, resize aborted"); 1032 return -ENOSPC; 1033 } 1034 brelse(bh); 1035 1036 /* We will update the superblock, one block bitmap, and --- 85 unchanged lines hidden --- |