aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/dir.c2
-rw-r--r--fs/ext4/extents.c59
-rw-r--r--fs/ext4/ialloc.c22
-rw-r--r--fs/ext4/inode.c56
-rw-r--r--fs/ext4/mballoc.c80
-rw-r--r--fs/ext4/migrate.c5
-rw-r--r--fs/ext4/namei.c18
-rw-r--r--fs/ext4/resize.c1
-rw-r--r--fs/proc/base.c27
9 files changed, 187 insertions, 83 deletions
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 33888bb58144..2c23bade9aa6 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -46,7 +46,7 @@ const struct file_operations ext4_dir_operations = {
46#ifdef CONFIG_COMPAT 46#ifdef CONFIG_COMPAT
47 .compat_ioctl = ext4_compat_ioctl, 47 .compat_ioctl = ext4_compat_ioctl,
48#endif 48#endif
49 .fsync = ext4_sync_file, /* BKL held */ 49 .fsync = ext4_sync_file,
50 .release = ext4_release_dir, 50 .release = ext4_release_dir,
51}; 51};
52 52
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index bc7081f1fbe8..9ae6e67090cd 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -148,6 +148,7 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode,
148{ 148{
149 struct ext4_inode_info *ei = EXT4_I(inode); 149 struct ext4_inode_info *ei = EXT4_I(inode);
150 ext4_fsblk_t bg_start; 150 ext4_fsblk_t bg_start;
151 ext4_fsblk_t last_block;
151 ext4_grpblk_t colour; 152 ext4_grpblk_t colour;
152 int depth; 153 int depth;
153 154
@@ -169,8 +170,13 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode,
169 /* OK. use inode's group */ 170 /* OK. use inode's group */
170 bg_start = (ei->i_block_group * EXT4_BLOCKS_PER_GROUP(inode->i_sb)) + 171 bg_start = (ei->i_block_group * EXT4_BLOCKS_PER_GROUP(inode->i_sb)) +
171 le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_first_data_block); 172 le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_first_data_block);
172 colour = (current->pid % 16) * 173 last_block = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es) - 1;
174
175 if (bg_start + EXT4_BLOCKS_PER_GROUP(inode->i_sb) <= last_block)
176 colour = (current->pid % 16) *
173 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16); 177 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16);
178 else
179 colour = (current->pid % 16) * ((last_block - bg_start) / 16);
174 return bg_start + colour + block; 180 return bg_start + colour + block;
175} 181}
176 182
@@ -349,7 +355,7 @@ static void ext4_ext_show_leaf(struct inode *inode, struct ext4_ext_path *path)
349#define ext4_ext_show_leaf(inode,path) 355#define ext4_ext_show_leaf(inode,path)
350#endif 356#endif
351 357
352static void ext4_ext_drop_refs(struct ext4_ext_path *path) 358void ext4_ext_drop_refs(struct ext4_ext_path *path)
353{ 359{
354 int depth = path->p_depth; 360 int depth = path->p_depth;
355 int i; 361 int i;
@@ -2168,6 +2174,10 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2168 newblock = iblock - ee_block + ext_pblock(ex); 2174 newblock = iblock - ee_block + ext_pblock(ex);
2169 ex2 = ex; 2175 ex2 = ex;
2170 2176
2177 err = ext4_ext_get_access(handle, inode, path + depth);
2178 if (err)
2179 goto out;
2180
2171 /* ex1: ee_block to iblock - 1 : uninitialized */ 2181 /* ex1: ee_block to iblock - 1 : uninitialized */
2172 if (iblock > ee_block) { 2182 if (iblock > ee_block) {
2173 ex1 = ex; 2183 ex1 = ex;
@@ -2200,16 +2210,20 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2200 newdepth = ext_depth(inode); 2210 newdepth = ext_depth(inode);
2201 if (newdepth != depth) { 2211 if (newdepth != depth) {
2202 depth = newdepth; 2212 depth = newdepth;
2203 path = ext4_ext_find_extent(inode, iblock, NULL); 2213 ext4_ext_drop_refs(path);
2214 path = ext4_ext_find_extent(inode, iblock, path);
2204 if (IS_ERR(path)) { 2215 if (IS_ERR(path)) {
2205 err = PTR_ERR(path); 2216 err = PTR_ERR(path);
2206 path = NULL;
2207 goto out; 2217 goto out;
2208 } 2218 }
2209 eh = path[depth].p_hdr; 2219 eh = path[depth].p_hdr;
2210 ex = path[depth].p_ext; 2220 ex = path[depth].p_ext;
2211 if (ex2 != &newex) 2221 if (ex2 != &newex)
2212 ex2 = ex; 2222 ex2 = ex;
2223
2224 err = ext4_ext_get_access(handle, inode, path + depth);
2225 if (err)
2226 goto out;
2213 } 2227 }
2214 allocated = max_blocks; 2228 allocated = max_blocks;
2215 } 2229 }
@@ -2230,9 +2244,6 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2230 ex2->ee_len = cpu_to_le16(allocated); 2244 ex2->ee_len = cpu_to_le16(allocated);
2231 if (ex2 != ex) 2245 if (ex2 != ex)
2232 goto insert; 2246 goto insert;
2233 err = ext4_ext_get_access(handle, inode, path + depth);
2234 if (err)
2235 goto out;
2236 /* 2247 /*
2237 * New (initialized) extent starts from the first block 2248 * New (initialized) extent starts from the first block
2238 * in the current extent. i.e., ex2 == ex 2249 * in the current extent. i.e., ex2 == ex
@@ -2276,9 +2287,22 @@ out:
2276} 2287}
2277 2288
2278/* 2289/*
2290 * Block allocation/map/preallocation routine for extents based files
2291 *
2292 *
2279 * Need to be called with 2293 * Need to be called with
2280 * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block 2294 * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block
2281 * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) 2295 * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem)
2296 *
2297 * return > 0, number of of blocks already mapped/allocated
2298 * if create == 0 and these are pre-allocated blocks
2299 * buffer head is unmapped
2300 * otherwise blocks are mapped
2301 *
2302 * return = 0, if plain look up failed (blocks have not been allocated)
2303 * buffer head is unmapped
2304 *
2305 * return < 0, error case.
2282 */ 2306 */
2283int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, 2307int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2284 ext4_lblk_t iblock, 2308 ext4_lblk_t iblock,
@@ -2623,7 +2647,7 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)
2623 * modify 1 super block, 1 block bitmap and 1 group descriptor. 2647 * modify 1 super block, 1 block bitmap and 1 group descriptor.
2624 */ 2648 */
2625 credits = EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + 3; 2649 credits = EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + 3;
2626 down_write((&EXT4_I(inode)->i_data_sem)); 2650 mutex_lock(&inode->i_mutex);
2627retry: 2651retry:
2628 while (ret >= 0 && ret < max_blocks) { 2652 while (ret >= 0 && ret < max_blocks) {
2629 block = block + ret; 2653 block = block + ret;
@@ -2634,16 +2658,17 @@ retry:
2634 break; 2658 break;
2635 } 2659 }
2636 2660
2637 ret = ext4_ext_get_blocks(handle, inode, block, 2661 ret = ext4_get_blocks_wrap(handle, inode, block,
2638 max_blocks, &map_bh, 2662 max_blocks, &map_bh,
2639 EXT4_CREATE_UNINITIALIZED_EXT, 0); 2663 EXT4_CREATE_UNINITIALIZED_EXT, 0);
2640 WARN_ON(ret <= 0);
2641 if (ret <= 0) { 2664 if (ret <= 0) {
2642 ext4_error(inode->i_sb, "ext4_fallocate", 2665#ifdef EXT4FS_DEBUG
2643 "ext4_ext_get_blocks returned error: " 2666 WARN_ON(ret <= 0);
2644 "inode#%lu, block=%u, max_blocks=%lu", 2667 printk(KERN_ERR "%s: ext4_ext_get_blocks "
2668 "returned error inode#%lu, block=%u, "
2669 "max_blocks=%lu", __func__,
2645 inode->i_ino, block, max_blocks); 2670 inode->i_ino, block, max_blocks);
2646 ret = -EIO; 2671#endif
2647 ext4_mark_inode_dirty(handle, inode); 2672 ext4_mark_inode_dirty(handle, inode);
2648 ret2 = ext4_journal_stop(handle); 2673 ret2 = ext4_journal_stop(handle);
2649 break; 2674 break;
@@ -2680,7 +2705,6 @@ retry:
2680 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 2705 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
2681 goto retry; 2706 goto retry;
2682 2707
2683 up_write((&EXT4_I(inode)->i_data_sem));
2684 /* 2708 /*
2685 * Time to update the file size. 2709 * Time to update the file size.
2686 * Update only when preallocation was requested beyond the file size. 2710 * Update only when preallocation was requested beyond the file size.
@@ -2692,21 +2716,18 @@ retry:
2692 * if no error, we assume preallocation succeeded 2716 * if no error, we assume preallocation succeeded
2693 * completely 2717 * completely
2694 */ 2718 */
2695 mutex_lock(&inode->i_mutex);
2696 i_size_write(inode, offset + len); 2719 i_size_write(inode, offset + len);
2697 EXT4_I(inode)->i_disksize = i_size_read(inode); 2720 EXT4_I(inode)->i_disksize = i_size_read(inode);
2698 mutex_unlock(&inode->i_mutex);
2699 } else if (ret < 0 && nblocks) { 2721 } else if (ret < 0 && nblocks) {
2700 /* Handle partial allocation scenario */ 2722 /* Handle partial allocation scenario */
2701 loff_t newsize; 2723 loff_t newsize;
2702 2724
2703 mutex_lock(&inode->i_mutex);
2704 newsize = (nblocks << blkbits) + i_size_read(inode); 2725 newsize = (nblocks << blkbits) + i_size_read(inode);
2705 i_size_write(inode, EXT4_BLOCK_ALIGN(newsize, blkbits)); 2726 i_size_write(inode, EXT4_BLOCK_ALIGN(newsize, blkbits));
2706 EXT4_I(inode)->i_disksize = i_size_read(inode); 2727 EXT4_I(inode)->i_disksize = i_size_read(inode);
2707 mutex_unlock(&inode->i_mutex);
2708 } 2728 }
2709 } 2729 }
2710 2730
2731 mutex_unlock(&inode->i_mutex);
2711 return ret > 0 ? ret2 : ret; 2732 return ret > 0 ? ret2 : ret;
2712} 2733}
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index da18a74b966a..8036b9b5376b 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -702,7 +702,12 @@ got:
702 ei->i_dir_start_lookup = 0; 702 ei->i_dir_start_lookup = 0;
703 ei->i_disksize = 0; 703 ei->i_disksize = 0;
704 704
705 ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL; 705 /*
706 * Don't inherit extent flag from directory. We set extent flag on
707 * newly created directory and file only if -o extent mount option is
708 * specified
709 */
710 ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
706 if (S_ISLNK(mode)) 711 if (S_ISLNK(mode))
707 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL); 712 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
708 /* dirsync only applies to directories */ 713 /* dirsync only applies to directories */
@@ -745,12 +750,15 @@ got:
745 goto fail_free_drop; 750 goto fail_free_drop;
746 } 751 }
747 if (test_opt(sb, EXTENTS)) { 752 if (test_opt(sb, EXTENTS)) {
748 EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL; 753 /* set extent flag only for directory and file */
749 ext4_ext_tree_init(handle, inode); 754 if (S_ISDIR(mode) || S_ISREG(mode)) {
750 err = ext4_update_incompat_feature(handle, sb, 755 EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL;
751 EXT4_FEATURE_INCOMPAT_EXTENTS); 756 ext4_ext_tree_init(handle, inode);
752 if (err) 757 err = ext4_update_incompat_feature(handle, sb,
753 goto fail; 758 EXT4_FEATURE_INCOMPAT_EXTENTS);
759 if (err)
760 goto fail;
761 }
754 } 762 }
755 763
756 ext4_debug("allocating inode %lu\n", inode->i_ino); 764 ext4_debug("allocating inode %lu\n", inode->i_ino);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 7dd9b50d5ebc..945cbf6cb1fc 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -403,6 +403,7 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
403 __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data; 403 __le32 *start = ind->bh ? (__le32*) ind->bh->b_data : ei->i_data;
404 __le32 *p; 404 __le32 *p;
405 ext4_fsblk_t bg_start; 405 ext4_fsblk_t bg_start;
406 ext4_fsblk_t last_block;
406 ext4_grpblk_t colour; 407 ext4_grpblk_t colour;
407 408
408 /* Try to find previous block */ 409 /* Try to find previous block */
@@ -420,8 +421,13 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)
420 * into the same cylinder group then. 421 * into the same cylinder group then.
421 */ 422 */
422 bg_start = ext4_group_first_block_no(inode->i_sb, ei->i_block_group); 423 bg_start = ext4_group_first_block_no(inode->i_sb, ei->i_block_group);
423 colour = (current->pid % 16) * 424 last_block = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es) - 1;
425
426 if (bg_start + EXT4_BLOCKS_PER_GROUP(inode->i_sb) <= last_block)
427 colour = (current->pid % 16) *
424 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16); 428 (EXT4_BLOCKS_PER_GROUP(inode->i_sb) / 16);
429 else
430 colour = (current->pid % 16) * ((last_block - bg_start) / 16);
425 return bg_start + colour; 431 return bg_start + colour;
426} 432}
427 433
@@ -768,7 +774,6 @@ err_out:
768 * 774 *
769 * `handle' can be NULL if create == 0. 775 * `handle' can be NULL if create == 0.
770 * 776 *
771 * The BKL may not be held on entry here. Be sure to take it early.
772 * return > 0, # of blocks mapped or allocated. 777 * return > 0, # of blocks mapped or allocated.
773 * return = 0, if plain lookup failed. 778 * return = 0, if plain lookup failed.
774 * return < 0, error case. 779 * return < 0, error case.
@@ -903,11 +908,38 @@ out:
903 */ 908 */
904#define DIO_CREDITS 25 909#define DIO_CREDITS 25
905 910
911
912/*
913 *
914 *
915 * ext4_ext4 get_block() wrapper function
916 * It will do a look up first, and returns if the blocks already mapped.
917 * Otherwise it takes the write lock of the i_data_sem and allocate blocks
918 * and store the allocated blocks in the result buffer head and mark it
919 * mapped.
920 *
921 * If file type is extents based, it will call ext4_ext_get_blocks(),
922 * Otherwise, call with ext4_get_blocks_handle() to handle indirect mapping
923 * based files
924 *
925 * On success, it returns the number of blocks being mapped or allocate.
926 * if create==0 and the blocks are pre-allocated and uninitialized block,
927 * the result buffer head is unmapped. If the create ==1, it will make sure
928 * the buffer head is mapped.
929 *
930 * It returns 0 if plain look up failed (blocks have not been allocated), in
931 * that casem, buffer head is unmapped
932 *
933 * It returns the error in case of allocation failure.
934 */
906int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, 935int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
907 unsigned long max_blocks, struct buffer_head *bh, 936 unsigned long max_blocks, struct buffer_head *bh,
908 int create, int extend_disksize) 937 int create, int extend_disksize)
909{ 938{
910 int retval; 939 int retval;
940
941 clear_buffer_mapped(bh);
942
911 /* 943 /*
912 * Try to see if we can get the block without requesting 944 * Try to see if we can get the block without requesting
913 * for new file system block. 945 * for new file system block.
@@ -921,12 +953,26 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
921 inode, block, max_blocks, bh, 0, 0); 953 inode, block, max_blocks, bh, 0, 0);
922 } 954 }
923 up_read((&EXT4_I(inode)->i_data_sem)); 955 up_read((&EXT4_I(inode)->i_data_sem));
924 if (!create || (retval > 0)) 956
957 /* If it is only a block(s) look up */
958 if (!create)
959 return retval;
960
961 /*
962 * Returns if the blocks have already allocated
963 *
964 * Note that if blocks have been preallocated
965 * ext4_ext_get_block() returns th create = 0
966 * with buffer head unmapped.
967 */
968 if (retval > 0 && buffer_mapped(bh))
925 return retval; 969 return retval;
926 970
927 /* 971 /*
928 * We need to allocate new blocks which will result 972 * New blocks allocate and/or writing to uninitialized extent
929 * in i_data update 973 * will possibly result in updating i_data, so we take
974 * the write lock of i_data_sem, and call get_blocks()
975 * with create == 1 flag.
930 */ 976 */
931 down_write((&EXT4_I(inode)->i_data_sem)); 977 down_write((&EXT4_I(inode)->i_data_sem));
932 /* 978 /*
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index dd0fcfcb35ce..ef97f19c2f9d 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -627,21 +627,19 @@ static ext4_fsblk_t ext4_grp_offs_to_block(struct super_block *sb,
627 return block; 627 return block;
628} 628}
629 629
630static inline void *mb_correct_addr_and_bit(int *bit, void *addr)
631{
630#if BITS_PER_LONG == 64 632#if BITS_PER_LONG == 64
631#define mb_correct_addr_and_bit(bit, addr) \ 633 *bit += ((unsigned long) addr & 7UL) << 3;
632{ \ 634 addr = (void *) ((unsigned long) addr & ~7UL);
633 bit += ((unsigned long) addr & 7UL) << 3; \
634 addr = (void *) ((unsigned long) addr & ~7UL); \
635}
636#elif BITS_PER_LONG == 32 635#elif BITS_PER_LONG == 32
637#define mb_correct_addr_and_bit(bit, addr) \ 636 *bit += ((unsigned long) addr & 3UL) << 3;
638{ \ 637 addr = (void *) ((unsigned long) addr & ~3UL);
639 bit += ((unsigned long) addr & 3UL) << 3; \
640 addr = (void *) ((unsigned long) addr & ~3UL); \
641}
642#else 638#else
643#error "how many bits you are?!" 639#error "how many bits you are?!"
644#endif 640#endif
641 return addr;
642}
645 643
646static inline int mb_test_bit(int bit, void *addr) 644static inline int mb_test_bit(int bit, void *addr)
647{ 645{
@@ -649,34 +647,54 @@ static inline int mb_test_bit(int bit, void *addr)
649 * ext4_test_bit on architecture like powerpc 647 * ext4_test_bit on architecture like powerpc
650 * needs unsigned long aligned address 648 * needs unsigned long aligned address
651 */ 649 */
652 mb_correct_addr_and_bit(bit, addr); 650 addr = mb_correct_addr_and_bit(&bit, addr);
653 return ext4_test_bit(bit, addr); 651 return ext4_test_bit(bit, addr);
654} 652}
655 653
656static inline void mb_set_bit(int bit, void *addr) 654static inline void mb_set_bit(int bit, void *addr)
657{ 655{
658 mb_correct_addr_and_bit(bit, addr); 656 addr = mb_correct_addr_and_bit(&bit, addr);
659 ext4_set_bit(bit, addr); 657 ext4_set_bit(bit, addr);
660} 658}
661 659
662static inline void mb_set_bit_atomic(spinlock_t *lock, int bit, void *addr) 660static inline void mb_set_bit_atomic(spinlock_t *lock, int bit, void *addr)
663{ 661{
664 mb_correct_addr_and_bit(bit, addr); 662 addr = mb_correct_addr_and_bit(&bit, addr);
665 ext4_set_bit_atomic(lock, bit, addr); 663 ext4_set_bit_atomic(lock, bit, addr);
666} 664}
667 665
668static inline void mb_clear_bit(int bit, void *addr) 666static inline void mb_clear_bit(int bit, void *addr)
669{ 667{
670 mb_correct_addr_and_bit(bit, addr); 668 addr = mb_correct_addr_and_bit(&bit, addr);
671 ext4_clear_bit(bit, addr); 669 ext4_clear_bit(bit, addr);
672} 670}
673 671
674static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr) 672static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr)
675{ 673{
676 mb_correct_addr_and_bit(bit, addr); 674 addr = mb_correct_addr_and_bit(&bit, addr);
677 ext4_clear_bit_atomic(lock, bit, addr); 675 ext4_clear_bit_atomic(lock, bit, addr);
678} 676}
679 677
678static inline int mb_find_next_zero_bit(void *addr, int max, int start)
679{
680 int fix = 0;
681 addr = mb_correct_addr_and_bit(&fix, addr);
682 max += fix;
683 start += fix;
684
685 return ext4_find_next_zero_bit(addr, max, start) - fix;
686}
687
688static inline int mb_find_next_bit(void *addr, int max, int start)
689{
690 int fix = 0;
691 addr = mb_correct_addr_and_bit(&fix, addr);
692 max += fix;
693 start += fix;
694
695 return ext4_find_next_bit(addr, max, start) - fix;
696}
697
680static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max) 698static void *mb_find_buddy(struct ext4_buddy *e4b, int order, int *max)
681{ 699{
682 char *bb; 700 char *bb;
@@ -906,7 +924,7 @@ static void ext4_mb_mark_free_simple(struct super_block *sb,
906 unsigned short chunk; 924 unsigned short chunk;
907 unsigned short border; 925 unsigned short border;
908 926
909 BUG_ON(len >= EXT4_BLOCKS_PER_GROUP(sb)); 927 BUG_ON(len > EXT4_BLOCKS_PER_GROUP(sb));
910 928
911 border = 2 << sb->s_blocksize_bits; 929 border = 2 << sb->s_blocksize_bits;
912 930
@@ -946,12 +964,12 @@ static void ext4_mb_generate_buddy(struct super_block *sb,
946 964
947 /* initialize buddy from bitmap which is aggregation 965 /* initialize buddy from bitmap which is aggregation
948 * of on-disk bitmap and preallocations */ 966 * of on-disk bitmap and preallocations */
949 i = ext4_find_next_zero_bit(bitmap, max, 0); 967 i = mb_find_next_zero_bit(bitmap, max, 0);
950 grp->bb_first_free = i; 968 grp->bb_first_free = i;
951 while (i < max) { 969 while (i < max) {
952 fragments++; 970 fragments++;
953 first = i; 971 first = i;
954 i = ext4_find_next_bit(bitmap, max, i); 972 i = mb_find_next_bit(bitmap, max, i);
955 len = i - first; 973 len = i - first;
956 free += len; 974 free += len;
957 if (len > 1) 975 if (len > 1)
@@ -959,7 +977,7 @@ static void ext4_mb_generate_buddy(struct super_block *sb,
959 else 977 else
960 grp->bb_counters[0]++; 978 grp->bb_counters[0]++;
961 if (i < max) 979 if (i < max)
962 i = ext4_find_next_zero_bit(bitmap, max, i); 980 i = mb_find_next_zero_bit(bitmap, max, i);
963 } 981 }
964 grp->bb_fragments = fragments; 982 grp->bb_fragments = fragments;
965 983
@@ -967,6 +985,10 @@ static void ext4_mb_generate_buddy(struct super_block *sb,
967 ext4_error(sb, __FUNCTION__, 985 ext4_error(sb, __FUNCTION__,
968 "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", 986 "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n",
969 group, free, grp->bb_free); 987 group, free, grp->bb_free);
988 /*
989 * If we intent to continue, we consider group descritor
990 * corrupt and update bb_free using bitmap value
991 */
970 grp->bb_free = free; 992 grp->bb_free = free;
971 } 993 }
972 994
@@ -1778,7 +1800,7 @@ static void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
1778 buddy = mb_find_buddy(e4b, i, &max); 1800 buddy = mb_find_buddy(e4b, i, &max);
1779 BUG_ON(buddy == NULL); 1801 BUG_ON(buddy == NULL);
1780 1802
1781 k = ext4_find_next_zero_bit(buddy, max, 0); 1803 k = mb_find_next_zero_bit(buddy, max, 0);
1782 BUG_ON(k >= max); 1804 BUG_ON(k >= max);
1783 1805
1784 ac->ac_found++; 1806 ac->ac_found++;
@@ -1818,11 +1840,11 @@ static void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1818 i = e4b->bd_info->bb_first_free; 1840 i = e4b->bd_info->bb_first_free;
1819 1841
1820 while (free && ac->ac_status == AC_STATUS_CONTINUE) { 1842 while (free && ac->ac_status == AC_STATUS_CONTINUE) {
1821 i = ext4_find_next_zero_bit(bitmap, 1843 i = mb_find_next_zero_bit(bitmap,
1822 EXT4_BLOCKS_PER_GROUP(sb), i); 1844 EXT4_BLOCKS_PER_GROUP(sb), i);
1823 if (i >= EXT4_BLOCKS_PER_GROUP(sb)) { 1845 if (i >= EXT4_BLOCKS_PER_GROUP(sb)) {
1824 /* 1846 /*
1825 * IF we corrupt the bitmap we won't find any 1847 * IF we have corrupt bitmap, we won't find any
1826 * free blocks even though group info says we 1848 * free blocks even though group info says we
1827 * we have free blocks 1849 * we have free blocks
1828 */ 1850 */
@@ -1838,6 +1860,12 @@ static void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1838 ext4_error(sb, __FUNCTION__, "%d free blocks as per " 1860 ext4_error(sb, __FUNCTION__, "%d free blocks as per "
1839 "group info. But got %d blocks\n", 1861 "group info. But got %d blocks\n",
1840 free, ex.fe_len); 1862 free, ex.fe_len);
1863 /*
1864 * The number of free blocks differs. This mostly
1865 * indicate that the bitmap is corrupt. So exit
1866 * without claiming the space.
1867 */
1868 break;
1841 } 1869 }
1842 1870
1843 ext4_mb_measure_extent(ac, &ex, e4b); 1871 ext4_mb_measure_extent(ac, &ex, e4b);
@@ -3740,10 +3768,10 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b,
3740 } 3768 }
3741 3769
3742 while (bit < end) { 3770 while (bit < end) {
3743 bit = ext4_find_next_zero_bit(bitmap_bh->b_data, end, bit); 3771 bit = mb_find_next_zero_bit(bitmap_bh->b_data, end, bit);
3744 if (bit >= end) 3772 if (bit >= end)
3745 break; 3773 break;
3746 next = ext4_find_next_bit(bitmap_bh->b_data, end, bit); 3774 next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
3747 if (next > end) 3775 if (next > end)
3748 next = end; 3776 next = end;
3749 start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit + 3777 start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit +
@@ -3771,6 +3799,10 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b,
3771 (unsigned long) pa->pa_len); 3799 (unsigned long) pa->pa_len);
3772 ext4_error(sb, __FUNCTION__, "free %u, pa_free %u\n", 3800 ext4_error(sb, __FUNCTION__, "free %u, pa_free %u\n",
3773 free, pa->pa_free); 3801 free, pa->pa_free);
3802 /*
3803 * pa is already deleted so we use the value obtained
3804 * from the bitmap and continue.
3805 */
3774 } 3806 }
3775 atomic_add(free, &sbi->s_mb_discarded); 3807 atomic_add(free, &sbi->s_mb_discarded);
3776 if (ac) 3808 if (ac)
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
index 8c6c685b9d22..5c1e27de7755 100644
--- a/fs/ext4/migrate.c
+++ b/fs/ext4/migrate.c
@@ -43,6 +43,7 @@ static int finish_range(handle_t *handle, struct inode *inode,
43 43
44 if (IS_ERR(path)) { 44 if (IS_ERR(path)) {
45 retval = PTR_ERR(path); 45 retval = PTR_ERR(path);
46 path = NULL;
46 goto err_out; 47 goto err_out;
47 } 48 }
48 49
@@ -74,6 +75,10 @@ static int finish_range(handle_t *handle, struct inode *inode,
74 } 75 }
75 retval = ext4_ext_insert_extent(handle, inode, path, &newext); 76 retval = ext4_ext_insert_extent(handle, inode, path, &newext);
76err_out: 77err_out:
78 if (path) {
79 ext4_ext_drop_refs(path);
80 kfree(path);
81 }
77 lb->first_pblock = 0; 82 lb->first_pblock = 0;
78 return retval; 83 return retval;
79} 84}
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index a9347fb43bcc..28aa2ed4297e 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1804,12 +1804,8 @@ retry:
1804 inode->i_fop = &ext4_dir_operations; 1804 inode->i_fop = &ext4_dir_operations;
1805 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize; 1805 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
1806 dir_block = ext4_bread (handle, inode, 0, 1, &err); 1806 dir_block = ext4_bread (handle, inode, 0, 1, &err);
1807 if (!dir_block) { 1807 if (!dir_block)
1808 ext4_dec_count(handle, inode); /* is this nlink == 0? */ 1808 goto out_clear_inode;
1809 ext4_mark_inode_dirty(handle, inode);
1810 iput (inode);
1811 goto out_stop;
1812 }
1813 BUFFER_TRACE(dir_block, "get_write_access"); 1809 BUFFER_TRACE(dir_block, "get_write_access");
1814 ext4_journal_get_write_access(handle, dir_block); 1810 ext4_journal_get_write_access(handle, dir_block);
1815 de = (struct ext4_dir_entry_2 *) dir_block->b_data; 1811 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
@@ -1832,7 +1828,8 @@ retry:
1832 ext4_mark_inode_dirty(handle, inode); 1828 ext4_mark_inode_dirty(handle, inode);
1833 err = ext4_add_entry (handle, dentry, inode); 1829 err = ext4_add_entry (handle, dentry, inode);
1834 if (err) { 1830 if (err) {
1835 inode->i_nlink = 0; 1831out_clear_inode:
1832 clear_nlink(inode);
1836 ext4_mark_inode_dirty(handle, inode); 1833 ext4_mark_inode_dirty(handle, inode);
1837 iput (inode); 1834 iput (inode);
1838 goto out_stop; 1835 goto out_stop;
@@ -2164,7 +2161,7 @@ static int ext4_unlink(struct inode * dir, struct dentry *dentry)
2164 dir->i_ctime = dir->i_mtime = ext4_current_time(dir); 2161 dir->i_ctime = dir->i_mtime = ext4_current_time(dir);
2165 ext4_update_dx_flag(dir); 2162 ext4_update_dx_flag(dir);
2166 ext4_mark_inode_dirty(handle, dir); 2163 ext4_mark_inode_dirty(handle, dir);
2167 ext4_dec_count(handle, inode); 2164 drop_nlink(inode);
2168 if (!inode->i_nlink) 2165 if (!inode->i_nlink)
2169 ext4_orphan_add(handle, inode); 2166 ext4_orphan_add(handle, inode);
2170 inode->i_ctime = ext4_current_time(inode); 2167 inode->i_ctime = ext4_current_time(inode);
@@ -2214,7 +2211,7 @@ retry:
2214 err = __page_symlink(inode, symname, l, 2211 err = __page_symlink(inode, symname, l,
2215 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS); 2212 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
2216 if (err) { 2213 if (err) {
2217 ext4_dec_count(handle, inode); 2214 clear_nlink(inode);
2218 ext4_mark_inode_dirty(handle, inode); 2215 ext4_mark_inode_dirty(handle, inode);
2219 iput (inode); 2216 iput (inode);
2220 goto out_stop; 2217 goto out_stop;
@@ -2223,7 +2220,6 @@ retry:
2223 inode->i_op = &ext4_fast_symlink_inode_operations; 2220 inode->i_op = &ext4_fast_symlink_inode_operations;
2224 memcpy((char*)&EXT4_I(inode)->i_data,symname,l); 2221 memcpy((char*)&EXT4_I(inode)->i_data,symname,l);
2225 inode->i_size = l-1; 2222 inode->i_size = l-1;
2226 EXT4_I(inode)->i_flags &= ~EXT4_EXTENTS_FL;
2227 } 2223 }
2228 EXT4_I(inode)->i_disksize = inode->i_size; 2224 EXT4_I(inode)->i_disksize = inode->i_size;
2229 err = ext4_add_nondir(handle, dentry, inode); 2225 err = ext4_add_nondir(handle, dentry, inode);
@@ -2407,7 +2403,7 @@ static int ext4_rename (struct inode * old_dir, struct dentry *old_dentry,
2407 ext4_dec_count(handle, old_dir); 2403 ext4_dec_count(handle, old_dir);
2408 if (new_inode) { 2404 if (new_inode) {
2409 /* checked empty_dir above, can't have another parent, 2405 /* checked empty_dir above, can't have another parent,
2410 * ext3_dec_count() won't work for many-linked dirs */ 2406 * ext4_dec_count() won't work for many-linked dirs */
2411 new_inode->i_nlink = 0; 2407 new_inode->i_nlink = 0;
2412 } else { 2408 } else {
2413 ext4_inc_count(handle, new_dir); 2409 ext4_inc_count(handle, new_dir);
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 9477a2bd6ff2..e29efa0f9d62 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1037,6 +1037,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1037 ext4_warning(sb, __FUNCTION__, 1037 ext4_warning(sb, __FUNCTION__,
1038 "multiple resizers run on filesystem!"); 1038 "multiple resizers run on filesystem!");
1039 unlock_super(sb); 1039 unlock_super(sb);
1040 ext4_journal_stop(handle);
1040 err = -EBUSY; 1041 err = -EBUSY;
1041 goto exit_put; 1042 goto exit_put;
1042 } 1043 }
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 96ee899d6502..91a1bd67ac1d 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -314,9 +314,12 @@ static int proc_pid_schedstat(struct task_struct *task, char *buffer)
314static int lstats_show_proc(struct seq_file *m, void *v) 314static int lstats_show_proc(struct seq_file *m, void *v)
315{ 315{
316 int i; 316 int i;
317 struct task_struct *task = m->private; 317 struct inode *inode = m->private;
318 seq_puts(m, "Latency Top version : v0.1\n"); 318 struct task_struct *task = get_proc_task(inode);
319 319
320 if (!task)
321 return -ESRCH;
322 seq_puts(m, "Latency Top version : v0.1\n");
320 for (i = 0; i < 32; i++) { 323 for (i = 0; i < 32; i++) {
321 if (task->latency_record[i].backtrace[0]) { 324 if (task->latency_record[i].backtrace[0]) {
322 int q; 325 int q;
@@ -341,32 +344,24 @@ static int lstats_show_proc(struct seq_file *m, void *v)
341 } 344 }
342 345
343 } 346 }
347 put_task_struct(task);
344 return 0; 348 return 0;
345} 349}
346 350
347static int lstats_open(struct inode *inode, struct file *file) 351static int lstats_open(struct inode *inode, struct file *file)
348{ 352{
349 int ret; 353 return single_open(file, lstats_show_proc, inode);
350 struct seq_file *m;
351 struct task_struct *task = get_proc_task(inode);
352
353 ret = single_open(file, lstats_show_proc, NULL);
354 if (!ret) {
355 m = file->private_data;
356 m->private = task;
357 }
358 return ret;
359} 354}
360 355
361static ssize_t lstats_write(struct file *file, const char __user *buf, 356static ssize_t lstats_write(struct file *file, const char __user *buf,
362 size_t count, loff_t *offs) 357 size_t count, loff_t *offs)
363{ 358{
364 struct seq_file *m; 359 struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
365 struct task_struct *task;
366 360
367 m = file->private_data; 361 if (!task)
368 task = m->private; 362 return -ESRCH;
369 clear_all_latency_tracing(task); 363 clear_all_latency_tracing(task);
364 put_task_struct(task);
370 365
371 return count; 366 return count;
372} 367}