Merge branch 'i2c/for-3.20' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa...
[firefly-linux-kernel-4.4.55.git] / fs / f2fs / segment.c
index 877a272a814606920592e9da56b9009489a22952..daee4ab913daf2bcd2883aeee28ff2e8975d02bd 100644 (file)
@@ -505,7 +505,7 @@ static void add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        struct seg_entry *se = get_seg_entry(sbi, cpc->trim_start);
        unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
        unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
-       unsigned long dmap[entries];
+       unsigned long *dmap = SIT_I(sbi)->tmp_map;
        unsigned int start = 0, end = -1;
        bool force = (cpc->reason == CP_DISCARD);
        int i;
@@ -800,7 +800,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
        int go_left = 0;
        int i;
 
-       write_lock(&free_i->segmap_lock);
+       spin_lock(&free_i->segmap_lock);
 
        if (!new_sec && ((*newseg + 1) % sbi->segs_per_sec)) {
                segno = find_next_zero_bit(free_i->free_segmap,
@@ -873,7 +873,7 @@ got_it:
        f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
        __set_inuse(sbi, segno);
        *newseg = segno;
-       write_unlock(&free_i->segmap_lock);
+       spin_unlock(&free_i->segmap_lock);
 }
 
 static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)
@@ -924,7 +924,7 @@ static void __next_free_blkoff(struct f2fs_sb_info *sbi,
 {
        struct seg_entry *se = get_seg_entry(sbi, seg->segno);
        int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-       unsigned long target_map[entries];
+       unsigned long *target_map = SIT_I(sbi)->tmp_map;
        unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
        unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
        int i, pos;
@@ -1855,6 +1855,10 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
                        return -ENOMEM;
        }
 
+       sit_i->tmp_map = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
+       if (!sit_i->tmp_map)
+               return -ENOMEM;
+
        if (sbi->segs_per_sec > 1) {
                sit_i->sec_entries = vzalloc(MAIN_SECS(sbi) *
                                        sizeof(struct sec_entry));
@@ -1919,7 +1923,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi)
        free_i->start_segno = GET_SEGNO_FROM_SEG0(sbi, MAIN_BLKADDR(sbi));
        free_i->free_segments = 0;
        free_i->free_sections = 0;
-       rwlock_init(&free_i->segmap_lock);
+       spin_lock_init(&free_i->segmap_lock);
        return 0;
 }
 
@@ -2236,6 +2240,8 @@ static void destroy_sit_info(struct f2fs_sb_info *sbi)
                        kfree(sit_i->sentries[start].ckpt_valid_map);
                }
        }
+       kfree(sit_i->tmp_map);
+
        vfree(sit_i->sentries);
        vfree(sit_i->sec_entries);
        kfree(sit_i->dirty_sentries_bitmap);