diff options
| -rw-r--r-- | fs/ext4/inode.c | 115 | ||||
| -rw-r--r-- | fs/ext4/mballoc.c | 164 | ||||
| -rw-r--r-- | fs/ext4/migrate.c | 123 | ||||
| -rw-r--r-- | fs/ext4/namei.c | 1 | ||||
| -rw-r--r-- | fs/ext4/super.c | 11 | ||||
| -rw-r--r-- | fs/jbd/commit.c | 14 | ||||
| -rw-r--r-- | fs/jbd2/commit.c | 10 | ||||
| -rw-r--r-- | fs/jbd2/recovery.c | 2 | ||||
| -rw-r--r-- | include/linux/ext4_fs.h | 7 |
9 files changed, 270 insertions, 177 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index f4e387452246..7dd9b50d5ebc 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
| @@ -892,7 +892,16 @@ out: | |||
| 892 | return err; | 892 | return err; |
| 893 | } | 893 | } |
| 894 | 894 | ||
| 895 | #define DIO_CREDITS (EXT4_RESERVE_TRANS_BLOCKS + 32) | 895 | /* Maximum number of blocks we map for direct IO at once. */ |
| 896 | #define DIO_MAX_BLOCKS 4096 | ||
| 897 | /* | ||
| 898 | * Number of credits we need for writing DIO_MAX_BLOCKS: | ||
| 899 | * We need sb + group descriptor + bitmap + inode -> 4 | ||
| 900 | * For B blocks with A block pointers per block we need: | ||
| 901 | * 1 (triple ind.) + (B/A/A + 2) (doubly ind.) + (B/A + 2) (indirect). | ||
| 902 | * If we plug in 4096 for B and 256 for A (for 1KB block size), we get 25. | ||
| 903 | */ | ||
| 904 | #define DIO_CREDITS 25 | ||
| 896 | 905 | ||
| 897 | int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, | 906 | int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, |
| 898 | unsigned long max_blocks, struct buffer_head *bh, | 907 | unsigned long max_blocks, struct buffer_head *bh, |
| @@ -939,49 +948,31 @@ static int ext4_get_block(struct inode *inode, sector_t iblock, | |||
| 939 | struct buffer_head *bh_result, int create) | 948 | struct buffer_head *bh_result, int create) |
| 940 | { | 949 | { |
| 941 | handle_t *handle = ext4_journal_current_handle(); | 950 | handle_t *handle = ext4_journal_current_handle(); |
| 942 | int ret = 0; | 951 | int ret = 0, started = 0; |
| 943 | unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; | 952 | unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; |
| 944 | 953 | ||
| 945 | if (!create) | 954 | if (create && !handle) { |
| 946 | goto get_block; /* A read */ | 955 | /* Direct IO write... */ |
| 947 | 956 | if (max_blocks > DIO_MAX_BLOCKS) | |
| 948 | if (max_blocks == 1) | 957 | max_blocks = DIO_MAX_BLOCKS; |
| 949 | goto get_block; /* A single block get */ | 958 | handle = ext4_journal_start(inode, DIO_CREDITS + |
| 950 | 959 | 2 * EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb)); | |
| 951 | if (handle->h_transaction->t_state == T_LOCKED) { | 960 | if (IS_ERR(handle)) { |
| 952 | /* | ||
| 953 | * Huge direct-io writes can hold off commits for long | ||
| 954 | * periods of time. Let this commit run. | ||
| 955 | */ | ||
| 956 | ext4_journal_stop(handle); | ||
| 957 | handle = ext4_journal_start(inode, DIO_CREDITS); | ||
| 958 | if (IS_ERR(handle)) | ||
| 959 | ret = PTR_ERR(handle); | 961 | ret = PTR_ERR(handle); |
| 960 | goto get_block; | 962 | goto out; |
| 961 | } | ||
| 962 | |||
| 963 | if (handle->h_buffer_credits <= EXT4_RESERVE_TRANS_BLOCKS) { | ||
| 964 | /* | ||
| 965 | * Getting low on buffer credits... | ||
| 966 | */ | ||
| 967 | ret = ext4_journal_extend(handle, DIO_CREDITS); | ||
| 968 | if (ret > 0) { | ||
| 969 | /* | ||
| 970 | * Couldn't extend the transaction. Start a new one. | ||
| 971 | */ | ||
| 972 | ret = ext4_journal_restart(handle, DIO_CREDITS); | ||
| 973 | } | 963 | } |
| 964 | started = 1; | ||
| 974 | } | 965 | } |
| 975 | 966 | ||
| 976 | get_block: | 967 | ret = ext4_get_blocks_wrap(handle, inode, iblock, |
| 977 | if (ret == 0) { | ||
| 978 | ret = ext4_get_blocks_wrap(handle, inode, iblock, | ||
| 979 | max_blocks, bh_result, create, 0); | 968 | max_blocks, bh_result, create, 0); |
| 980 | if (ret > 0) { | 969 | if (ret > 0) { |
| 981 | bh_result->b_size = (ret << inode->i_blkbits); | 970 | bh_result->b_size = (ret << inode->i_blkbits); |
| 982 | ret = 0; | 971 | ret = 0; |
| 983 | } | ||
| 984 | } | 972 | } |
| 973 | if (started) | ||
| 974 | ext4_journal_stop(handle); | ||
| 975 | out: | ||
| 985 | return ret; | 976 | return ret; |
| 986 | } | 977 | } |
| 987 | 978 | ||
| @@ -1671,7 +1662,8 @@ static int ext4_releasepage(struct page *page, gfp_t wait) | |||
| 1671 | * if the machine crashes during the write. | 1662 | * if the machine crashes during the write. |
| 1672 | * | 1663 | * |
| 1673 | * If the O_DIRECT write is intantiating holes inside i_size and the machine | 1664 | * If the O_DIRECT write is intantiating holes inside i_size and the machine |
| 1674 | * crashes then stale disk data _may_ be exposed inside the file. | 1665 | * crashes then stale disk data _may_ be exposed inside the file. But current |
| 1666 | * VFS code falls back into buffered path in that case so we are safe. | ||
| 1675 | */ | 1667 | */ |
| 1676 | static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, | 1668 | static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, |
| 1677 | const struct iovec *iov, loff_t offset, | 1669 | const struct iovec *iov, loff_t offset, |
| @@ -1680,7 +1672,7 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, | |||
| 1680 | struct file *file = iocb->ki_filp; | 1672 | struct file *file = iocb->ki_filp; |
| 1681 | struct inode *inode = file->f_mapping->host; | 1673 | struct inode *inode = file->f_mapping->host; |
| 1682 | struct ext4_inode_info *ei = EXT4_I(inode); | 1674 | struct ext4_inode_info *ei = EXT4_I(inode); |
| 1683 | handle_t *handle = NULL; | 1675 | handle_t *handle; |
| 1684 | ssize_t ret; | 1676 | ssize_t ret; |
| 1685 | int orphan = 0; | 1677 | int orphan = 0; |
| 1686 | size_t count = iov_length(iov, nr_segs); | 1678 | size_t count = iov_length(iov, nr_segs); |
| @@ -1688,17 +1680,21 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, | |||
| 1688 | if (rw == WRITE) { | 1680 | if (rw == WRITE) { |
| 1689 | loff_t final_size = offset + count; | 1681 | loff_t final_size = offset + count; |
| 1690 | 1682 | ||
| 1691 | handle = ext4_journal_start(inode, DIO_CREDITS); | ||
| 1692 | if (IS_ERR(handle)) { | ||
| 1693 | ret = PTR_ERR(handle); | ||
| 1694 | goto out; | ||
| 1695 | } | ||
| 1696 | if (final_size > inode->i_size) { | 1683 | if (final_size > inode->i_size) { |
| 1684 | /* Credits for sb + inode write */ | ||
| 1685 | handle = ext4_journal_start(inode, 2); | ||
| 1686 | if (IS_ERR(handle)) { | ||
| 1687 | ret = PTR_ERR(handle); | ||
| 1688 | goto out; | ||
| 1689 | } | ||
| 1697 | ret = ext4_orphan_add(handle, inode); | 1690 | ret = ext4_orphan_add(handle, inode); |
| 1698 | if (ret) | 1691 | if (ret) { |
| 1699 | goto out_stop; | 1692 | ext4_journal_stop(handle); |
| 1693 | goto out; | ||
| 1694 | } | ||
| 1700 | orphan = 1; | 1695 | orphan = 1; |
| 1701 | ei->i_disksize = inode->i_size; | 1696 | ei->i_disksize = inode->i_size; |
| 1697 | ext4_journal_stop(handle); | ||
| 1702 | } | 1698 | } |
| 1703 | } | 1699 | } |
| 1704 | 1700 | ||
| @@ -1706,18 +1702,21 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb, | |||
| 1706 | offset, nr_segs, | 1702 | offset, nr_segs, |
| 1707 | ext4_get_block, NULL); | 1703 | ext4_get_block, NULL); |
| 1708 | 1704 | ||
| 1709 | /* | 1705 | if (orphan) { |
| 1710 | * Reacquire the handle: ext4_get_block() can restart the transaction | ||
| 1711 | */ | ||
| 1712 | handle = ext4_journal_current_handle(); | ||
| 1713 | |||
| 1714 | out_stop: | ||
| 1715 | if (handle) { | ||
| 1716 | int err; | 1706 | int err; |
| 1717 | 1707 | ||
| 1718 | if (orphan && inode->i_nlink) | 1708 | /* Credits for sb + inode write */ |
| 1709 | handle = ext4_journal_start(inode, 2); | ||
| 1710 | if (IS_ERR(handle)) { | ||
| 1711 | /* This is really bad luck. We've written the data | ||
| 1712 | * but cannot extend i_size. Bail out and pretend | ||
| 1713 | * the write failed... */ | ||
| 1714 | ret = PTR_ERR(handle); | ||
| 1715 | goto out; | ||
| 1716 | } | ||
| 1717 | if (inode->i_nlink) | ||
| 1719 | ext4_orphan_del(handle, inode); | 1718 | ext4_orphan_del(handle, inode); |
| 1720 | if (orphan && ret > 0) { | 1719 | if (ret > 0) { |
| 1721 | loff_t end = offset + ret; | 1720 | loff_t end = offset + ret; |
| 1722 | if (end > inode->i_size) { | 1721 | if (end > inode->i_size) { |
| 1723 | ei->i_disksize = end; | 1722 | ei->i_disksize = end; |
| @@ -2758,13 +2757,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
| 2758 | ei->i_data[block] = raw_inode->i_block[block]; | 2757 | ei->i_data[block] = raw_inode->i_block[block]; |
| 2759 | INIT_LIST_HEAD(&ei->i_orphan); | 2758 | INIT_LIST_HEAD(&ei->i_orphan); |
| 2760 | 2759 | ||
| 2761 | if (inode->i_ino >= EXT4_FIRST_INO(inode->i_sb) + 1 && | 2760 | if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { |
| 2762 | EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { | ||
| 2763 | /* | ||
| 2764 | * When mke2fs creates big inodes it does not zero out | ||
| 2765 | * the unused bytes above EXT4_GOOD_OLD_INODE_SIZE, | ||
| 2766 | * so ignore those first few inodes. | ||
| 2767 | */ | ||
| 2768 | ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); | 2761 | ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); |
| 2769 | if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > | 2762 | if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > |
| 2770 | EXT4_INODE_SIZE(inode->i_sb)) { | 2763 | EXT4_INODE_SIZE(inode->i_sb)) { |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 76e5fedc0a0b..dd0fcfcb35ce 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
| @@ -420,6 +420,7 @@ | |||
| 420 | #define MB_DEFAULT_GROUP_PREALLOC 512 | 420 | #define MB_DEFAULT_GROUP_PREALLOC 512 |
| 421 | 421 | ||
| 422 | static struct kmem_cache *ext4_pspace_cachep; | 422 | static struct kmem_cache *ext4_pspace_cachep; |
| 423 | static struct kmem_cache *ext4_ac_cachep; | ||
| 423 | 424 | ||
| 424 | #ifdef EXT4_BB_MAX_BLOCKS | 425 | #ifdef EXT4_BB_MAX_BLOCKS |
| 425 | #undef EXT4_BB_MAX_BLOCKS | 426 | #undef EXT4_BB_MAX_BLOCKS |
| @@ -680,7 +681,6 @@ static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max) | |||
| 680 | { | 681 | { |
| 681 | char *bb; | 682 | char *bb; |
| 682 | 683 | ||
| 683 | /* FIXME!! is this needed */ | ||
| 684 | BUG_ON(EXT4_MB_BITMAP(e4b) == EXT4_MB_BUDDY(e4b)); | 684 | BUG_ON(EXT4_MB_BITMAP(e4b) == EXT4_MB_BUDDY(e4b)); |
| 685 | BUG_ON(max == NULL); | 685 | BUG_ON(max == NULL); |
| 686 | 686 | ||
| @@ -964,7 +964,7 @@ static void ext4_mb_generate_buddy(struct super_block *sb, | |||
| 964 | grp->bb_fragments = fragments; | 964 | grp->bb_fragments = fragments; |
| 965 | 965 | ||
| 966 | if (free != grp->bb_free) { | 966 | if (free != grp->bb_free) { |
| 967 | printk(KERN_DEBUG | 967 | ext4_error(sb, __FUNCTION__, |
| 968 | "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", | 968 | "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", |
| 969 | group, free, grp->bb_free); | 969 | group, free, grp->bb_free); |
| 970 | grp->bb_free = free; | 970 | grp->bb_free = free; |
| @@ -1821,13 +1821,24 @@ static void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac, | |||
| 1821 | i = ext4_find_next_zero_bit(bitmap, | 1821 | i = ext4_find_next_zero_bit(bitmap, |
| 1822 | EXT4_BLOCKS_PER_GROUP(sb), i); | 1822 | EXT4_BLOCKS_PER_GROUP(sb), i); |
| 1823 | if (i >= EXT4_BLOCKS_PER_GROUP(sb)) { | 1823 | if (i >= EXT4_BLOCKS_PER_GROUP(sb)) { |
| 1824 | BUG_ON(free != 0); | 1824 | /* |
| 1825 | * IF we corrupt the bitmap we won't find any | ||
| 1826 | * free blocks even though group info says we | ||
| 1827 | * we have free blocks | ||
| 1828 | */ | ||
| 1829 | ext4_error(sb, __FUNCTION__, "%d free blocks as per " | ||
| 1830 | "group info. But bitmap says 0\n", | ||
| 1831 | free); | ||
| 1825 | break; | 1832 | break; |
| 1826 | } | 1833 | } |
| 1827 | 1834 | ||
| 1828 | mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); | 1835 | mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); |
| 1829 | BUG_ON(ex.fe_len <= 0); | 1836 | BUG_ON(ex.fe_len <= 0); |
| 1830 | BUG_ON(free < ex.fe_len); | 1837 | if (free < ex.fe_len) { |
| 1838 | ext4_error(sb, __FUNCTION__, "%d free blocks as per " | ||
| 1839 | "group info. But got %d blocks\n", | ||
| 1840 | free, ex.fe_len); | ||
| 1841 | } | ||
| 1831 | 1842 | ||
| 1832 | ext4_mb_measure_extent(ac, &ex, e4b); | 1843 | ext4_mb_measure_extent(ac, &ex, e4b); |
| 1833 | 1844 | ||
| @@ -2959,12 +2970,19 @@ int __init init_ext4_mballoc(void) | |||
| 2959 | if (ext4_pspace_cachep == NULL) | 2970 | if (ext4_pspace_cachep == NULL) |
| 2960 | return -ENOMEM; | 2971 | return -ENOMEM; |
| 2961 | 2972 | ||
| 2973 | ext4_ac_cachep = | ||
| 2974 | kmem_cache_create("ext4_alloc_context", | ||
| 2975 | sizeof(struct ext4_allocation_context), | ||
| 2976 | 0, SLAB_RECLAIM_ACCOUNT, NULL); | ||
| 2977 | if (ext4_ac_cachep == NULL) { | ||
| 2978 | kmem_cache_destroy(ext4_pspace_cachep); | ||
| 2979 | return -ENOMEM; | ||
| 2980 | } | ||
| 2962 | #ifdef CONFIG_PROC_FS | 2981 | #ifdef CONFIG_PROC_FS |
| 2963 | proc_root_ext4 = proc_mkdir(EXT4_ROOT, proc_root_fs); | 2982 | proc_root_ext4 = proc_mkdir(EXT4_ROOT, proc_root_fs); |
| 2964 | if (proc_root_ext4 == NULL) | 2983 | if (proc_root_ext4 == NULL) |
| 2965 | printk(KERN_ERR "EXT4-fs: Unable to create %s\n", EXT4_ROOT); | 2984 | printk(KERN_ERR "EXT4-fs: Unable to create %s\n", EXT4_ROOT); |
| 2966 | #endif | 2985 | #endif |
| 2967 | |||
| 2968 | return 0; | 2986 | return 0; |
| 2969 | } | 2987 | } |
| 2970 | 2988 | ||
| @@ -2972,6 +2990,7 @@ void exit_ext4_mballoc(void) | |||
| 2972 | { | 2990 | { |
| 2973 | /* XXX: synchronize_rcu(); */ | 2991 | /* XXX: synchronize_rcu(); */ |
| 2974 | kmem_cache_destroy(ext4_pspace_cachep); | 2992 | kmem_cache_destroy(ext4_pspace_cachep); |
| 2993 | kmem_cache_destroy(ext4_ac_cachep); | ||
| 2975 | #ifdef CONFIG_PROC_FS | 2994 | #ifdef CONFIG_PROC_FS |
| 2976 | remove_proc_entry(EXT4_ROOT, proc_root_fs); | 2995 | remove_proc_entry(EXT4_ROOT, proc_root_fs); |
| 2977 | #endif | 2996 | #endif |
| @@ -3069,7 +3088,7 @@ static int ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | |||
| 3069 | 3088 | ||
| 3070 | out_err: | 3089 | out_err: |
| 3071 | sb->s_dirt = 1; | 3090 | sb->s_dirt = 1; |
| 3072 | put_bh(bitmap_bh); | 3091 | brelse(bitmap_bh); |
| 3073 | return err; | 3092 | return err; |
| 3074 | } | 3093 | } |
| 3075 | 3094 | ||
| @@ -3354,13 +3373,10 @@ static void ext4_mb_use_group_pa(struct ext4_allocation_context *ac, | |||
| 3354 | ac->ac_pa = pa; | 3373 | ac->ac_pa = pa; |
| 3355 | 3374 | ||
| 3356 | /* we don't correct pa_pstart or pa_plen here to avoid | 3375 | /* we don't correct pa_pstart or pa_plen here to avoid |
| 3357 | * possible race when tte group is being loaded concurrently | 3376 | * possible race when the group is being loaded concurrently |
| 3358 | * instead we correct pa later, after blocks are marked | 3377 | * instead we correct pa later, after blocks are marked |
| 3359 | * in on-disk bitmap -- see ext4_mb_release_context() */ | 3378 | * in on-disk bitmap -- see ext4_mb_release_context() |
| 3360 | /* | 3379 | * Other CPUs are prevented from allocating from this pa by lg_mutex |
| 3361 | * FIXME!! but the other CPUs can look at this particular | ||
| 3362 | * pa and think that it have enought free blocks if we | ||
| 3363 | * don't update pa_free here right ? | ||
| 3364 | */ | 3380 | */ |
| 3365 | mb_debug("use %u/%u from group pa %p\n", pa->pa_lstart-len, len, pa); | 3381 | mb_debug("use %u/%u from group pa %p\n", pa->pa_lstart-len, len, pa); |
| 3366 | } | 3382 | } |
| @@ -3699,7 +3715,7 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | |||
| 3699 | struct buffer_head *bitmap_bh, | 3715 | struct buffer_head *bitmap_bh, |
| 3700 | struct ext4_prealloc_space *pa) | 3716 | struct ext4_prealloc_space *pa) |
| 3701 | { | 3717 | { |
| 3702 | struct ext4_allocation_context ac; | 3718 | struct ext4_allocation_context *ac; |
| 3703 | struct super_block *sb = e4b->bd_sb; | 3719 | struct super_block *sb = e4b->bd_sb; |
| 3704 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 3720 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 3705 | unsigned long end; | 3721 | unsigned long end; |
| @@ -3715,9 +3731,13 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | |||
| 3715 | BUG_ON(group != e4b->bd_group && pa->pa_len != 0); | 3731 | BUG_ON(group != e4b->bd_group && pa->pa_len != 0); |
| 3716 | end = bit + pa->pa_len; | 3732 | end = bit + pa->pa_len; |
| 3717 | 3733 | ||
| 3718 | ac.ac_sb = sb; | 3734 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); |
| 3719 | ac.ac_inode = pa->pa_inode; | 3735 | |
| 3720 | ac.ac_op = EXT4_MB_HISTORY_DISCARD; | 3736 | if (ac) { |
| 3737 | ac->ac_sb = sb; | ||
| 3738 | ac->ac_inode = pa->pa_inode; | ||
| 3739 | ac->ac_op = EXT4_MB_HISTORY_DISCARD; | ||
| 3740 | } | ||
| 3721 | 3741 | ||
| 3722 | while (bit < end) { | 3742 | while (bit < end) { |
| 3723 | bit = ext4_find_next_zero_bit(bitmap_bh->b_data, end, bit); | 3743 | bit = ext4_find_next_zero_bit(bitmap_bh->b_data, end, bit); |
| @@ -3733,24 +3753,28 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | |||
| 3733 | (unsigned) group); | 3753 | (unsigned) group); |
| 3734 | free += next - bit; | 3754 | free += next - bit; |
| 3735 | 3755 | ||
| 3736 | ac.ac_b_ex.fe_group = group; | 3756 | if (ac) { |
| 3737 | ac.ac_b_ex.fe_start = bit; | 3757 | ac->ac_b_ex.fe_group = group; |
| 3738 | ac.ac_b_ex.fe_len = next - bit; | 3758 | ac->ac_b_ex.fe_start = bit; |
| 3739 | ac.ac_b_ex.fe_logical = 0; | 3759 | ac->ac_b_ex.fe_len = next - bit; |
| 3740 | ext4_mb_store_history(&ac); | 3760 | ac->ac_b_ex.fe_logical = 0; |
| 3761 | ext4_mb_store_history(ac); | ||
| 3762 | } | ||
| 3741 | 3763 | ||
| 3742 | mb_free_blocks(pa->pa_inode, e4b, bit, next - bit); | 3764 | mb_free_blocks(pa->pa_inode, e4b, bit, next - bit); |
| 3743 | bit = next + 1; | 3765 | bit = next + 1; |
| 3744 | } | 3766 | } |
| 3745 | if (free != pa->pa_free) { | 3767 | if (free != pa->pa_free) { |
| 3746 | printk(KERN_ERR "pa %p: logic %lu, phys. %lu, len %lu\n", | 3768 | printk(KERN_CRIT "pa %p: logic %lu, phys. %lu, len %lu\n", |
| 3747 | pa, (unsigned long) pa->pa_lstart, | 3769 | pa, (unsigned long) pa->pa_lstart, |
| 3748 | (unsigned long) pa->pa_pstart, | 3770 | (unsigned long) pa->pa_pstart, |
| 3749 | (unsigned long) pa->pa_len); | 3771 | (unsigned long) pa->pa_len); |
| 3750 | printk(KERN_ERR "free %u, pa_free %u\n", free, pa->pa_free); | 3772 | ext4_error(sb, __FUNCTION__, "free %u, pa_free %u\n", |
| 3773 | free, pa->pa_free); | ||
| 3751 | } | 3774 | } |
| 3752 | BUG_ON(free != pa->pa_free); | ||
| 3753 | atomic_add(free, &sbi->s_mb_discarded); | 3775 | atomic_add(free, &sbi->s_mb_discarded); |
| 3776 | if (ac) | ||
| 3777 | kmem_cache_free(ext4_ac_cachep, ac); | ||
| 3754 | 3778 | ||
| 3755 | return err; | 3779 | return err; |
| 3756 | } | 3780 | } |
| @@ -3758,12 +3782,15 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, | |||
| 3758 | static int ext4_mb_release_group_pa(struct ext4_buddy *e4b, | 3782 | static int ext4_mb_release_group_pa(struct ext4_buddy *e4b, |
| 3759 | struct ext4_prealloc_space *pa) | 3783 | struct ext4_prealloc_space *pa) |
| 3760 | { | 3784 | { |
| 3761 | struct ext4_allocation_context ac; | 3785 | struct ext4_allocation_context *ac; |
| 3762 | struct super_block *sb = e4b->bd_sb; | 3786 | struct super_block *sb = e4b->bd_sb; |
| 3763 | ext4_group_t group; | 3787 | ext4_group_t group; |
| 3764 | ext4_grpblk_t bit; | 3788 | ext4_grpblk_t bit; |
| 3765 | 3789 | ||
| 3766 | ac.ac_op = EXT4_MB_HISTORY_DISCARD; | 3790 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); |
| 3791 | |||
| 3792 | if (ac) | ||
| 3793 | ac->ac_op = EXT4_MB_HISTORY_DISCARD; | ||
| 3767 | 3794 | ||
| 3768 | BUG_ON(pa->pa_deleted == 0); | 3795 | BUG_ON(pa->pa_deleted == 0); |
| 3769 | ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit); | 3796 | ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit); |
| @@ -3771,13 +3798,16 @@ static int ext4_mb_release_group_pa(struct ext4_buddy *e4b, | |||
| 3771 | mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len); | 3798 | mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len); |
| 3772 | atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded); | 3799 | atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded); |
| 3773 | 3800 | ||
| 3774 | ac.ac_sb = sb; | 3801 | if (ac) { |
| 3775 | ac.ac_inode = NULL; | 3802 | ac->ac_sb = sb; |
| 3776 | ac.ac_b_ex.fe_group = group; | 3803 | ac->ac_inode = NULL; |
| 3777 | ac.ac_b_ex.fe_start = bit; | 3804 | ac->ac_b_ex.fe_group = group; |
| 3778 | ac.ac_b_ex.fe_len = pa->pa_len; | 3805 | ac->ac_b_ex.fe_start = bit; |
| 3779 | ac.ac_b_ex.fe_logical = 0; | 3806 | ac->ac_b_ex.fe_len = pa->pa_len; |
| 3780 | ext4_mb_store_history(&ac); | 3807 | ac->ac_b_ex.fe_logical = 0; |
| 3808 | ext4_mb_store_history(ac); | ||
| 3809 | kmem_cache_free(ext4_ac_cachep, ac); | ||
| 3810 | } | ||
| 3781 | 3811 | ||
| 3782 | return 0; | 3812 | return 0; |
| 3783 | } | 3813 | } |
| @@ -4231,7 +4261,7 @@ static int ext4_mb_discard_preallocations(struct super_block *sb, int needed) | |||
| 4231 | ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, | 4261 | ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, |
| 4232 | struct ext4_allocation_request *ar, int *errp) | 4262 | struct ext4_allocation_request *ar, int *errp) |
| 4233 | { | 4263 | { |
| 4234 | struct ext4_allocation_context ac; | 4264 | struct ext4_allocation_context *ac = NULL; |
| 4235 | struct ext4_sb_info *sbi; | 4265 | struct ext4_sb_info *sbi; |
| 4236 | struct super_block *sb; | 4266 | struct super_block *sb; |
| 4237 | ext4_fsblk_t block = 0; | 4267 | ext4_fsblk_t block = 0; |
| @@ -4257,53 +4287,60 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, | |||
| 4257 | } | 4287 | } |
| 4258 | inquota = ar->len; | 4288 | inquota = ar->len; |
| 4259 | 4289 | ||
| 4290 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); | ||
| 4291 | if (!ac) { | ||
| 4292 | *errp = -ENOMEM; | ||
| 4293 | return 0; | ||
| 4294 | } | ||
| 4295 | |||
| 4260 | ext4_mb_poll_new_transaction(sb, handle); | 4296 | ext4_mb_poll_new_transaction(sb, handle); |
| 4261 | 4297 | ||
| 4262 | *errp = ext4_mb_initialize_context(&ac, ar); | 4298 | *errp = ext4_mb_initialize_context(ac, ar); |
| 4263 | if (*errp) { | 4299 | if (*errp) { |
| 4264 | ar->len = 0; | 4300 | ar->len = 0; |
| 4265 | goto out; | 4301 | goto out; |
| 4266 | } | 4302 | } |
| 4267 | 4303 | ||
| 4268 | ac.ac_op = EXT4_MB_HISTORY_PREALLOC; | 4304 | ac->ac_op = EXT4_MB_HISTORY_PREALLOC; |
| 4269 | if (!ext4_mb_use_preallocated(&ac)) { | 4305 | if (!ext4_mb_use_preallocated(ac)) { |
| 4270 | 4306 | ||
| 4271 | ac.ac_op = EXT4_MB_HISTORY_ALLOC; | 4307 | ac->ac_op = EXT4_MB_HISTORY_ALLOC; |
| 4272 | ext4_mb_normalize_request(&ac, ar); | 4308 | ext4_mb_normalize_request(ac, ar); |
| 4273 | 4309 | ||
| 4274 | repeat: | 4310 | repeat: |
| 4275 | /* allocate space in core */ | 4311 | /* allocate space in core */ |
| 4276 | ext4_mb_regular_allocator(&ac); | 4312 | ext4_mb_regular_allocator(ac); |
| 4277 | 4313 | ||
| 4278 | /* as we've just preallocated more space than | 4314 | /* as we've just preallocated more space than |
| 4279 | * user requested orinally, we store allocated | 4315 | * user requested orinally, we store allocated |
| 4280 | * space in a special descriptor */ | 4316 | * space in a special descriptor */ |
| 4281 | if (ac.ac_status == AC_STATUS_FOUND && | 4317 | if (ac->ac_status == AC_STATUS_FOUND && |
| 4282 | ac.ac_o_ex.fe_len < ac.ac_b_ex.fe_len) | 4318 | ac->ac_o_ex.fe_len < ac->ac_b_ex.fe_len) |
| 4283 | ext4_mb_new_preallocation(&ac); | 4319 | ext4_mb_new_preallocation(ac); |
| 4284 | } | 4320 | } |
| 4285 | 4321 | ||
| 4286 | if (likely(ac.ac_status == AC_STATUS_FOUND)) { | 4322 | if (likely(ac->ac_status == AC_STATUS_FOUND)) { |
| 4287 | ext4_mb_mark_diskspace_used(&ac, handle); | 4323 | ext4_mb_mark_diskspace_used(ac, handle); |
| 4288 | *errp = 0; | 4324 | *errp = 0; |
| 4289 | block = ext4_grp_offs_to_block(sb, &ac.ac_b_ex); | 4325 | block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); |
| 4290 | ar->len = ac.ac_b_ex.fe_len; | 4326 | ar->len = ac->ac_b_ex.fe_len; |
| 4291 | } else { | 4327 | } else { |
| 4292 | freed = ext4_mb_discard_preallocations(sb, ac.ac_o_ex.fe_len); | 4328 | freed = ext4_mb_discard_preallocations(sb, ac->ac_o_ex.fe_len); |
| 4293 | if (freed) | 4329 | if (freed) |
| 4294 | goto repeat; | 4330 | goto repeat; |
| 4295 | *errp = -ENOSPC; | 4331 | *errp = -ENOSPC; |
| 4296 | ac.ac_b_ex.fe_len = 0; | 4332 | ac->ac_b_ex.fe_len = 0; |
| 4297 | ar->len = 0; | 4333 | ar->len = 0; |
| 4298 | ext4_mb_show_ac(&ac); | 4334 | ext4_mb_show_ac(ac); |
| 4299 | } | 4335 | } |
| 4300 | 4336 | ||
| 4301 | ext4_mb_release_context(&ac); | 4337 | ext4_mb_release_context(ac); |
| 4302 | 4338 | ||
| 4303 | out: | 4339 | out: |
| 4304 | if (ar->len < inquota) | 4340 | if (ar->len < inquota) |
| 4305 | DQUOT_FREE_BLOCK(ar->inode, inquota - ar->len); | 4341 | DQUOT_FREE_BLOCK(ar->inode, inquota - ar->len); |
| 4306 | 4342 | ||
| 4343 | kmem_cache_free(ext4_ac_cachep, ac); | ||
| 4307 | return block; | 4344 | return block; |
| 4308 | } | 4345 | } |
| 4309 | static void ext4_mb_poll_new_transaction(struct super_block *sb, | 4346 | static void ext4_mb_poll_new_transaction(struct super_block *sb, |
| @@ -4405,9 +4442,9 @@ void ext4_mb_free_blocks(handle_t *handle, struct inode *inode, | |||
| 4405 | unsigned long block, unsigned long count, | 4442 | unsigned long block, unsigned long count, |
| 4406 | int metadata, unsigned long *freed) | 4443 | int metadata, unsigned long *freed) |
| 4407 | { | 4444 | { |
| 4408 | struct buffer_head *bitmap_bh = 0; | 4445 | struct buffer_head *bitmap_bh = NULL; |
| 4409 | struct super_block *sb = inode->i_sb; | 4446 | struct super_block *sb = inode->i_sb; |
| 4410 | struct ext4_allocation_context ac; | 4447 | struct ext4_allocation_context *ac = NULL; |
| 4411 | struct ext4_group_desc *gdp; | 4448 | struct ext4_group_desc *gdp; |
| 4412 | struct ext4_super_block *es; | 4449 | struct ext4_super_block *es; |
| 4413 | unsigned long overflow; | 4450 | unsigned long overflow; |
| @@ -4436,9 +4473,12 @@ void ext4_mb_free_blocks(handle_t *handle, struct inode *inode, | |||
| 4436 | 4473 | ||
| 4437 | ext4_debug("freeing block %lu\n", block); | 4474 | ext4_debug("freeing block %lu\n", block); |
| 4438 | 4475 | ||
| 4439 | ac.ac_op = EXT4_MB_HISTORY_FREE; | 4476 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); |
| 4440 | ac.ac_inode = inode; | 4477 | if (ac) { |
| 4441 | ac.ac_sb = sb; | 4478 | ac->ac_op = EXT4_MB_HISTORY_FREE; |
| 4479 | ac->ac_inode = inode; | ||
| 4480 | ac->ac_sb = sb; | ||
| 4481 | } | ||
| 4442 | 4482 | ||
| 4443 | do_more: | 4483 | do_more: |
| 4444 | overflow = 0; | 4484 | overflow = 0; |
| @@ -4504,10 +4544,12 @@ do_more: | |||
| 4504 | BUFFER_TRACE(bitmap_bh, "dirtied bitmap block"); | 4544 | BUFFER_TRACE(bitmap_bh, "dirtied bitmap block"); |
| 4505 | err = ext4_journal_dirty_metadata(handle, bitmap_bh); | 4545 | err = ext4_journal_dirty_metadata(handle, bitmap_bh); |
| 4506 | 4546 | ||
| 4507 | ac.ac_b_ex.fe_group = block_group; | 4547 | if (ac) { |
| 4508 | ac.ac_b_ex.fe_start = bit; | 4548 | ac->ac_b_ex.fe_group = block_group; |
| 4509 | ac.ac_b_ex.fe_len = count; | 4549 | ac->ac_b_ex.fe_start = bit; |
| 4510 | ext4_mb_store_history(&ac); | 4550 | ac->ac_b_ex.fe_len = count; |
| 4551 | ext4_mb_store_history(ac); | ||
| 4552 | } | ||
| 4511 | 4553 | ||
| 4512 | if (metadata) { | 4554 | if (metadata) { |
| 4513 | /* blocks being freed are metadata. these blocks shouldn't | 4555 | /* blocks being freed are metadata. these blocks shouldn't |
| @@ -4548,5 +4590,7 @@ do_more: | |||
| 4548 | error_return: | 4590 | error_return: |
| 4549 | brelse(bitmap_bh); | 4591 | brelse(bitmap_bh); |
| 4550 | ext4_std_error(sb, err); | 4592 | ext4_std_error(sb, err); |
| 4593 | if (ac) | ||
| 4594 | kmem_cache_free(ext4_ac_cachep, ac); | ||
| 4551 | return; | 4595 | return; |
| 4552 | } | 4596 | } |
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index 3ebc2332f52e..8c6c685b9d22 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c | |||
| @@ -61,10 +61,9 @@ static int finish_range(handle_t *handle, struct inode *inode, | |||
| 61 | retval = ext4_journal_restart(handle, needed); | 61 | retval = ext4_journal_restart(handle, needed); |
| 62 | if (retval) | 62 | if (retval) |
| 63 | goto err_out; | 63 | goto err_out; |
| 64 | } | 64 | } else if (needed) { |
| 65 | if (needed) { | ||
| 66 | retval = ext4_journal_extend(handle, needed); | 65 | retval = ext4_journal_extend(handle, needed); |
| 67 | if (retval != 0) { | 66 | if (retval) { |
| 68 | /* | 67 | /* |
| 69 | * IF not able to extend the journal restart the journal | 68 | * IF not able to extend the journal restart the journal |
| 70 | */ | 69 | */ |
| @@ -220,6 +219,26 @@ static int update_tind_extent_range(handle_t *handle, struct inode *inode, | |||
| 220 | 219 | ||
| 221 | } | 220 | } |
| 222 | 221 | ||
| 222 | static int extend_credit_for_blkdel(handle_t *handle, struct inode *inode) | ||
| 223 | { | ||
| 224 | int retval = 0, needed; | ||
| 225 | |||
| 226 | if (handle->h_buffer_credits > EXT4_RESERVE_TRANS_BLOCKS) | ||
| 227 | return 0; | ||
| 228 | /* | ||
| 229 | * We are freeing a blocks. During this we touch | ||
| 230 | * superblock, group descriptor and block bitmap. | ||
| 231 | * So allocate a credit of 3. We may update | ||
| 232 | * quota (user and group). | ||
| 233 | */ | ||
| 234 | needed = 3 + 2*EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb); | ||
| 235 | |||
| 236 | if (ext4_journal_extend(handle, needed) != 0) | ||
| 237 | retval = ext4_journal_restart(handle, needed); | ||
| 238 | |||
| 239 | return retval; | ||
| 240 | } | ||
| 241 | |||
| 223 | static int free_dind_blocks(handle_t *handle, | 242 | static int free_dind_blocks(handle_t *handle, |
| 224 | struct inode *inode, __le32 i_data) | 243 | struct inode *inode, __le32 i_data) |
| 225 | { | 244 | { |
| @@ -234,11 +253,14 @@ static int free_dind_blocks(handle_t *handle, | |||
| 234 | 253 | ||
| 235 | tmp_idata = (__le32 *)bh->b_data; | 254 | tmp_idata = (__le32 *)bh->b_data; |
| 236 | for (i = 0; i < max_entries; i++) { | 255 | for (i = 0; i < max_entries; i++) { |
| 237 | if (tmp_idata[i]) | 256 | if (tmp_idata[i]) { |
| 257 | extend_credit_for_blkdel(handle, inode); | ||
| 238 | ext4_free_blocks(handle, inode, | 258 | ext4_free_blocks(handle, inode, |
| 239 | le32_to_cpu(tmp_idata[i]), 1, 1); | 259 | le32_to_cpu(tmp_idata[i]), 1, 1); |
| 260 | } | ||
| 240 | } | 261 | } |
| 241 | put_bh(bh); | 262 | put_bh(bh); |
| 263 | extend_credit_for_blkdel(handle, inode); | ||
| 242 | ext4_free_blocks(handle, inode, le32_to_cpu(i_data), 1, 1); | 264 | ext4_free_blocks(handle, inode, le32_to_cpu(i_data), 1, 1); |
| 243 | return 0; | 265 | return 0; |
| 244 | } | 266 | } |
| @@ -267,29 +289,32 @@ static int free_tind_blocks(handle_t *handle, | |||
| 267 | } | 289 | } |
| 268 | } | 290 | } |
| 269 | put_bh(bh); | 291 | put_bh(bh); |
| 292 | extend_credit_for_blkdel(handle, inode); | ||
| 270 | ext4_free_blocks(handle, inode, le32_to_cpu(i_data), 1, 1); | 293 | ext4_free_blocks(handle, inode, le32_to_cpu(i_data), 1, 1); |
| 271 | return 0; | 294 | return 0; |
| 272 | } | 295 | } |
| 273 | 296 | ||
| 274 | static int free_ind_block(handle_t *handle, struct inode *inode) | 297 | static int free_ind_block(handle_t *handle, struct inode *inode, __le32 *i_data) |
| 275 | { | 298 | { |
| 276 | int retval; | 299 | int retval; |
| 277 | struct ext4_inode_info *ei = EXT4_I(inode); | ||
| 278 | 300 | ||
| 279 | if (ei->i_data[EXT4_IND_BLOCK]) | 301 | /* ei->i_data[EXT4_IND_BLOCK] */ |
| 302 | if (i_data[0]) { | ||
| 303 | extend_credit_for_blkdel(handle, inode); | ||
| 280 | ext4_free_blocks(handle, inode, | 304 | ext4_free_blocks(handle, inode, |
| 281 | le32_to_cpu(ei->i_data[EXT4_IND_BLOCK]), 1, 1); | 305 | le32_to_cpu(i_data[0]), 1, 1); |
| 306 | } | ||
| 282 | 307 | ||
| 283 | if (ei->i_data[EXT4_DIND_BLOCK]) { | 308 | /* ei->i_data[EXT4_DIND_BLOCK] */ |
| 284 | retval = free_dind_blocks(handle, inode, | 309 | if (i_data[1]) { |
| 285 | ei->i_data[EXT4_DIND_BLOCK]); | 310 | retval = free_dind_blocks(handle, inode, i_data[1]); |
| 286 | if (retval) | 311 | if (retval) |
| 287 | return retval; | 312 | return retval; |
| 288 | } | 313 | } |
| 289 | 314 | ||
| 290 | if (ei->i_data[EXT4_TIND_BLOCK]) { | 315 | /* ei->i_data[EXT4_TIND_BLOCK] */ |
| 291 | retval = free_tind_blocks(handle, inode, | 316 | if (i_data[2]) { |
| 292 | ei->i_data[EXT4_TIND_BLOCK]); | 317 | retval = free_tind_blocks(handle, inode, i_data[2]); |
| 293 | if (retval) | 318 | if (retval) |
| 294 | return retval; | 319 | return retval; |
| 295 | } | 320 | } |
| @@ -297,15 +322,13 @@ static int free_ind_block(handle_t *handle, struct inode *inode) | |||
| 297 | } | 322 | } |
| 298 | 323 | ||
| 299 | static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, | 324 | static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, |
| 300 | struct inode *tmp_inode, int retval) | 325 | struct inode *tmp_inode) |
| 301 | { | 326 | { |
| 327 | int retval; | ||
| 328 | __le32 i_data[3]; | ||
| 302 | struct ext4_inode_info *ei = EXT4_I(inode); | 329 | struct ext4_inode_info *ei = EXT4_I(inode); |
| 303 | struct ext4_inode_info *tmp_ei = EXT4_I(tmp_inode); | 330 | struct ext4_inode_info *tmp_ei = EXT4_I(tmp_inode); |
| 304 | 331 | ||
| 305 | retval = free_ind_block(handle, inode); | ||
| 306 | if (retval) | ||
| 307 | goto err_out; | ||
| 308 | |||
| 309 | /* | 332 | /* |
| 310 | * One credit accounted for writing the | 333 | * One credit accounted for writing the |
| 311 | * i_data field of the original inode | 334 | * i_data field of the original inode |
| @@ -317,6 +340,11 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, | |||
| 317 | goto err_out; | 340 | goto err_out; |
| 318 | } | 341 | } |
| 319 | 342 | ||
| 343 | i_data[0] = ei->i_data[EXT4_IND_BLOCK]; | ||
| 344 | i_data[1] = ei->i_data[EXT4_DIND_BLOCK]; | ||
| 345 | i_data[2] = ei->i_data[EXT4_TIND_BLOCK]; | ||
| 346 | |||
| 347 | down_write(&EXT4_I(inode)->i_data_sem); | ||
| 320 | /* | 348 | /* |
| 321 | * We have the extent map build with the tmp inode. | 349 | * We have the extent map build with the tmp inode. |
| 322 | * Now copy the i_data across | 350 | * Now copy the i_data across |
| @@ -336,8 +364,15 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, | |||
| 336 | spin_lock(&inode->i_lock); | 364 | spin_lock(&inode->i_lock); |
| 337 | inode->i_blocks += tmp_inode->i_blocks; | 365 | inode->i_blocks += tmp_inode->i_blocks; |
| 338 | spin_unlock(&inode->i_lock); | 366 | spin_unlock(&inode->i_lock); |
| 367 | up_write(&EXT4_I(inode)->i_data_sem); | ||
| 339 | 368 | ||
| 369 | /* | ||
| 370 | * We mark the inode dirty after, because we decrement the | ||
| 371 | * i_blocks when freeing the indirect meta-data blocks | ||
| 372 | */ | ||
| 373 | retval = free_ind_block(handle, inode, i_data); | ||
| 340 | ext4_mark_inode_dirty(handle, inode); | 374 | ext4_mark_inode_dirty(handle, inode); |
| 375 | |||
| 341 | err_out: | 376 | err_out: |
| 342 | return retval; | 377 | return retval; |
| 343 | } | 378 | } |
| @@ -365,6 +400,7 @@ static int free_ext_idx(handle_t *handle, struct inode *inode, | |||
| 365 | } | 400 | } |
| 366 | } | 401 | } |
| 367 | put_bh(bh); | 402 | put_bh(bh); |
| 403 | extend_credit_for_blkdel(handle, inode); | ||
| 368 | ext4_free_blocks(handle, inode, block, 1, 1); | 404 | ext4_free_blocks(handle, inode, block, 1, 1); |
| 369 | return retval; | 405 | return retval; |
| 370 | } | 406 | } |
| @@ -414,7 +450,12 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp, | |||
| 414 | if ((EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) | 450 | if ((EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)) |
| 415 | return -EINVAL; | 451 | return -EINVAL; |
| 416 | 452 | ||
| 417 | down_write(&EXT4_I(inode)->i_data_sem); | 453 | if (S_ISLNK(inode->i_mode) && inode->i_blocks == 0) |
| 454 | /* | ||
| 455 | * don't migrate fast symlink | ||
| 456 | */ | ||
| 457 | return retval; | ||
| 458 | |||
| 418 | handle = ext4_journal_start(inode, | 459 | handle = ext4_journal_start(inode, |
| 419 | EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + | 460 | EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + |
| 420 | EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 + | 461 | EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 + |
| @@ -448,13 +489,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp, | |||
| 448 | ext4_orphan_add(handle, tmp_inode); | 489 | ext4_orphan_add(handle, tmp_inode); |
| 449 | ext4_journal_stop(handle); | 490 | ext4_journal_stop(handle); |
| 450 | 491 | ||
| 451 | ei = EXT4_I(inode); | ||
| 452 | i_data = ei->i_data; | ||
| 453 | memset(&lb, 0, sizeof(lb)); | ||
| 454 | |||
| 455 | /* 32 bit block address 4 bytes */ | ||
| 456 | max_entries = inode->i_sb->s_blocksize >> 2; | ||
| 457 | |||
| 458 | /* | 492 | /* |
| 459 | * start with one credit accounted for | 493 | * start with one credit accounted for |
| 460 | * superblock modification. | 494 | * superblock modification. |
| @@ -463,7 +497,20 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp, | |||
| 463 | * trascation that created the inode. Later as and | 497 | * trascation that created the inode. Later as and |
| 464 | * when we add extents we extent the journal | 498 | * when we add extents we extent the journal |
| 465 | */ | 499 | */ |
| 500 | /* | ||
| 501 | * inode_mutex prevent write and truncate on the file. Read still goes | ||
| 502 | * through. We take i_data_sem in ext4_ext_swap_inode_data before we | ||
| 503 | * switch the inode format to prevent read. | ||
| 504 | */ | ||
| 505 | mutex_lock(&(inode->i_mutex)); | ||
| 466 | handle = ext4_journal_start(inode, 1); | 506 | handle = ext4_journal_start(inode, 1); |
| 507 | |||
| 508 | ei = EXT4_I(inode); | ||
| 509 | i_data = ei->i_data; | ||
| 510 | memset(&lb, 0, sizeof(lb)); | ||
| 511 | |||
| 512 | /* 32 bit block address 4 bytes */ | ||
| 513 | max_entries = inode->i_sb->s_blocksize >> 2; | ||
| 467 | for (i = 0; i < EXT4_NDIR_BLOCKS; i++, blk_count++) { | 514 | for (i = 0; i < EXT4_NDIR_BLOCKS; i++, blk_count++) { |
| 468 | if (i_data[i]) { | 515 | if (i_data[i]) { |
| 469 | retval = update_extent_range(handle, tmp_inode, | 516 | retval = update_extent_range(handle, tmp_inode, |
| @@ -501,19 +548,6 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp, | |||
| 501 | */ | 548 | */ |
| 502 | retval = finish_range(handle, tmp_inode, &lb); | 549 | retval = finish_range(handle, tmp_inode, &lb); |
| 503 | err_out: | 550 | err_out: |
| 504 | /* | ||
| 505 | * We are either freeing extent information or indirect | ||
| 506 | * blocks. During this we touch superblock, group descriptor | ||
| 507 | * and block bitmap. Later we mark the tmp_inode dirty | ||
| 508 | * via ext4_ext_tree_init. So allocate a credit of 4 | ||
| 509 | * We may update quota (user and group). | ||
| 510 | * | ||
| 511 | * FIXME!! we may be touching bitmaps in different block groups. | ||
| 512 | */ | ||
| 513 | if (ext4_journal_extend(handle, | ||
| 514 | 4 + 2*EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb)) != 0) | ||
| 515 | ext4_journal_restart(handle, | ||
| 516 | 4 + 2*EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb)); | ||
| 517 | if (retval) | 551 | if (retval) |
| 518 | /* | 552 | /* |
| 519 | * Failure case delete the extent information with the | 553 | * Failure case delete the extent information with the |
| @@ -522,7 +556,11 @@ err_out: | |||
| 522 | free_ext_block(handle, tmp_inode); | 556 | free_ext_block(handle, tmp_inode); |
| 523 | else | 557 | else |
| 524 | retval = ext4_ext_swap_inode_data(handle, inode, | 558 | retval = ext4_ext_swap_inode_data(handle, inode, |
| 525 | tmp_inode, retval); | 559 | tmp_inode); |
| 560 | |||
| 561 | /* We mark the tmp_inode dirty via ext4_ext_tree_init. */ | ||
| 562 | if (ext4_journal_extend(handle, 1) != 0) | ||
| 563 | ext4_journal_restart(handle, 1); | ||
| 526 | 564 | ||
| 527 | /* | 565 | /* |
| 528 | * Mark the tmp_inode as of size zero | 566 | * Mark the tmp_inode as of size zero |
| @@ -550,8 +588,7 @@ err_out: | |||
| 550 | tmp_inode->i_nlink = 0; | 588 | tmp_inode->i_nlink = 0; |
| 551 | 589 | ||
| 552 | ext4_journal_stop(handle); | 590 | ext4_journal_stop(handle); |
| 553 | 591 | mutex_unlock(&(inode->i_mutex)); | |
| 554 | up_write(&EXT4_I(inode)->i_data_sem); | ||
| 555 | 592 | ||
| 556 | if (tmp_inode) | 593 | if (tmp_inode) |
| 557 | iput(tmp_inode); | 594 | iput(tmp_inode); |
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index d153bb5922fc..a9347fb43bcc 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
| @@ -2223,6 +2223,7 @@ retry: | |||
| 2223 | inode->i_op = &ext4_fast_symlink_inode_operations; | 2223 | inode->i_op = &ext4_fast_symlink_inode_operations; |
| 2224 | memcpy((char*)&EXT4_I(inode)->i_data,symname,l); | 2224 | memcpy((char*)&EXT4_I(inode)->i_data,symname,l); |
| 2225 | inode->i_size = l-1; | 2225 | inode->i_size = l-1; |
| 2226 | EXT4_I(inode)->i_flags &= ~EXT4_EXTENTS_FL; | ||
| 2226 | } | 2227 | } |
| 2227 | EXT4_I(inode)->i_disksize = inode->i_size; | 2228 | EXT4_I(inode)->i_disksize = inode->i_size; |
| 2228 | err = ext4_add_nondir(handle, dentry, inode); | 2229 | err = ext4_add_nondir(handle, dentry, inode); |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 93beb865c20d..0072da75221f 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
| @@ -1919,6 +1919,17 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) | |||
| 1919 | printk(KERN_WARNING | 1919 | printk(KERN_WARNING |
| 1920 | "EXT4-fs warning: feature flags set on rev 0 fs, " | 1920 | "EXT4-fs warning: feature flags set on rev 0 fs, " |
| 1921 | "running e2fsck is recommended\n"); | 1921 | "running e2fsck is recommended\n"); |
| 1922 | |||
| 1923 | /* | ||
| 1924 | * Since ext4 is still considered development code, we require | ||
| 1925 | * that the TEST_FILESYS flag in s->flags be set. | ||
| 1926 | */ | ||
| 1927 | if (!(le32_to_cpu(es->s_flags) & EXT2_FLAGS_TEST_FILESYS)) { | ||
| 1928 | printk(KERN_WARNING "EXT4-fs: %s: not marked " | ||
| 1929 | "OK to use with test code.\n", sb->s_id); | ||
| 1930 | goto failed_mount; | ||
| 1931 | } | ||
| 1932 | |||
| 1922 | /* | 1933 | /* |
| 1923 | * Check feature flags regardless of the revision level, since we | 1934 | * Check feature flags regardless of the revision level, since we |
| 1924 | * previously didn't change the revision level when setting the flags, | 1935 | * previously didn't change the revision level when setting the flags, |
diff --git a/fs/jbd/commit.c b/fs/jbd/commit.c index 8e08efcaede2..a38c7186c570 100644 --- a/fs/jbd/commit.c +++ b/fs/jbd/commit.c | |||
| @@ -104,7 +104,8 @@ static int journal_write_commit_record(journal_t *journal, | |||
| 104 | { | 104 | { |
| 105 | struct journal_head *descriptor; | 105 | struct journal_head *descriptor; |
| 106 | struct buffer_head *bh; | 106 | struct buffer_head *bh; |
| 107 | int i, ret; | 107 | journal_header_t *header; |
| 108 | int ret; | ||
| 108 | int barrier_done = 0; | 109 | int barrier_done = 0; |
| 109 | 110 | ||
| 110 | if (is_journal_aborted(journal)) | 111 | if (is_journal_aborted(journal)) |
| @@ -116,13 +117,10 @@ static int journal_write_commit_record(journal_t *journal, | |||
| 116 | 117 | ||
| 117 | bh = jh2bh(descriptor); | 118 | bh = jh2bh(descriptor); |
| 118 | 119 | ||
| 119 | /* AKPM: buglet - add `i' to tmp! */ | 120 | header = (journal_header_t *)(bh->b_data); |
| 120 | for (i = 0; i < bh->b_size; i += 512) { | 121 | header->h_magic = cpu_to_be32(JFS_MAGIC_NUMBER); |
| 121 | journal_header_t *tmp = (journal_header_t*)bh->b_data; | 122 | header->h_blocktype = cpu_to_be32(JFS_COMMIT_BLOCK); |
| 122 | tmp->h_magic = cpu_to_be32(JFS_MAGIC_NUMBER); | 123 | header->h_sequence = cpu_to_be32(commit_transaction->t_tid); |
| 123 | tmp->h_blocktype = cpu_to_be32(JFS_COMMIT_BLOCK); | ||
| 124 | tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid); | ||
| 125 | } | ||
| 126 | 124 | ||
| 127 | JBUFFER_TRACE(descriptor, "write commit block"); | 125 | JBUFFER_TRACE(descriptor, "write commit block"); |
| 128 | set_buffer_dirty(bh); | 126 | set_buffer_dirty(bh); |
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 4f302d279279..a8173081f831 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c | |||
| @@ -136,18 +136,20 @@ static int journal_submit_commit_record(journal_t *journal, | |||
| 136 | 136 | ||
| 137 | JBUFFER_TRACE(descriptor, "submit commit block"); | 137 | JBUFFER_TRACE(descriptor, "submit commit block"); |
| 138 | lock_buffer(bh); | 138 | lock_buffer(bh); |
| 139 | 139 | get_bh(bh); | |
| 140 | set_buffer_dirty(bh); | 140 | set_buffer_dirty(bh); |
| 141 | set_buffer_uptodate(bh); | 141 | set_buffer_uptodate(bh); |
| 142 | bh->b_end_io = journal_end_buffer_io_sync; | 142 | bh->b_end_io = journal_end_buffer_io_sync; |
| 143 | 143 | ||
| 144 | if (journal->j_flags & JBD2_BARRIER && | 144 | if (journal->j_flags & JBD2_BARRIER && |
| 145 | !JBD2_HAS_COMPAT_FEATURE(journal, | 145 | !JBD2_HAS_INCOMPAT_FEATURE(journal, |
| 146 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { | 146 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { |
| 147 | set_buffer_ordered(bh); | 147 | set_buffer_ordered(bh); |
| 148 | barrier_done = 1; | 148 | barrier_done = 1; |
| 149 | } | 149 | } |
| 150 | ret = submit_bh(WRITE, bh); | 150 | ret = submit_bh(WRITE, bh); |
| 151 | if (barrier_done) | ||
| 152 | clear_buffer_ordered(bh); | ||
| 151 | 153 | ||
| 152 | /* is it possible for another commit to fail at roughly | 154 | /* is it possible for another commit to fail at roughly |
| 153 | * the same time as this one? If so, we don't want to | 155 | * the same time as this one? If so, we don't want to |
| @@ -166,7 +168,6 @@ static int journal_submit_commit_record(journal_t *journal, | |||
| 166 | spin_unlock(&journal->j_state_lock); | 168 | spin_unlock(&journal->j_state_lock); |
| 167 | 169 | ||
| 168 | /* And try again, without the barrier */ | 170 | /* And try again, without the barrier */ |
| 169 | clear_buffer_ordered(bh); | ||
| 170 | set_buffer_uptodate(bh); | 171 | set_buffer_uptodate(bh); |
| 171 | set_buffer_dirty(bh); | 172 | set_buffer_dirty(bh); |
| 172 | ret = submit_bh(WRITE, bh); | 173 | ret = submit_bh(WRITE, bh); |
| @@ -872,7 +873,8 @@ wait_for_iobuf: | |||
| 872 | if (err) | 873 | if (err) |
| 873 | __jbd2_journal_abort_hard(journal); | 874 | __jbd2_journal_abort_hard(journal); |
| 874 | } | 875 | } |
| 875 | err = journal_wait_on_commit_record(cbh); | 876 | if (!err && !is_journal_aborted(journal)) |
| 877 | err = journal_wait_on_commit_record(cbh); | ||
| 876 | 878 | ||
| 877 | if (err) | 879 | if (err) |
| 878 | jbd2_journal_abort(journal, err); | 880 | jbd2_journal_abort(journal, err); |
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index d36356f7d222..146411387ada 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c | |||
| @@ -641,7 +641,7 @@ static int do_one_pass(journal_t *journal, | |||
| 641 | if (chksum_err) { | 641 | if (chksum_err) { |
| 642 | info->end_transaction = next_commit_ID; | 642 | info->end_transaction = next_commit_ID; |
| 643 | 643 | ||
| 644 | if (!JBD2_HAS_COMPAT_FEATURE(journal, | 644 | if (!JBD2_HAS_INCOMPAT_FEATURE(journal, |
| 645 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)){ | 645 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)){ |
| 646 | printk(KERN_ERR | 646 | printk(KERN_ERR |
| 647 | "JBD: Transaction %u " | 647 | "JBD: Transaction %u " |
diff --git a/include/linux/ext4_fs.h b/include/linux/ext4_fs.h index c4f635a4dd25..250032548597 100644 --- a/include/linux/ext4_fs.h +++ b/include/linux/ext4_fs.h | |||
| @@ -490,6 +490,13 @@ do { \ | |||
| 490 | #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ | 490 | #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */ |
| 491 | 491 | ||
| 492 | /* | 492 | /* |
| 493 | * Misc. filesystem flags | ||
| 494 | */ | ||
| 495 | #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */ | ||
| 496 | #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */ | ||
| 497 | #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */ | ||
| 498 | |||
| 499 | /* | ||
| 493 | * Mount flags | 500 | * Mount flags |
| 494 | */ | 501 | */ |
| 495 | #define EXT4_MOUNT_CHECK 0x00001 /* Do mount-time checks */ | 502 | #define EXT4_MOUNT_CHECK 0x00001 /* Do mount-time checks */ |
