[f2fs-dev] [PATCH AUTOSEL 4.19 05/37] f2fs: fix to do sanity check on valid node/block count

2019-10-25 Thread Sasha Levin
From: Chao Yu 

[ Upstream commit 7b63f72f73af57bb040f03b9713ec9979d8911f4 ]

As Jungyeon reported in bugzilla:

https://bugzilla.kernel.org/show_bug.cgi?id=203229

- Overview
When mounting the attached crafted image, following errors are reported.
Additionally, it hangs on sync after trying to mount it.

The image is intentionally fuzzed from a normal f2fs image for testing.
Compile options for F2FS are as follows.
CONFIG_F2FS_FS=y
CONFIG_F2FS_STAT_FS=y
CONFIG_F2FS_FS_XATTR=y
CONFIG_F2FS_FS_POSIX_ACL=y
CONFIG_F2FS_CHECK_FS=y

- Reproduces
mkdir test
mount -t f2fs tmp.img test
sync

- Kernel message
 kernel BUG at fs/f2fs/recovery.c:591!
 RIP: 0010:recover_data+0x12d8/0x1780
 Call Trace:
  f2fs_recover_fsync_data+0x613/0x710
  f2fs_fill_super+0x1043/0x1aa0
  mount_bdev+0x16d/0x1a0
  mount_fs+0x4a/0x170
  vfs_kern_mount+0x5d/0x100
  do_mount+0x200/0xcf0
  ksys_mount+0x79/0xc0
  __x64_sys_mount+0x1c/0x20
  do_syscall_64+0x43/0xf0
  entry_SYSCALL_64_after_hwframe+0x44/0xa9

With corrupted image wihch has out-of-range valid node/block count, during
recovery, once we failed due to no free space, it will trigger kernel
panic.

Adding sanity check on valid node/block count in f2fs_sanity_check_ckpt()
to detect such condition, so that potential panic can be avoided.

Signed-off-by: Chao Yu 
Signed-off-by: Jaegeuk Kim 
Signed-off-by: Sasha Levin 
---
 fs/f2fs/super.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 6851afc3bf805..3fc96cffe6ac5 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2344,7 +2344,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
unsigned int log_blocks_per_seg;
unsigned int segment_count_main;
unsigned int cp_pack_start_sum, cp_payload;
-   block_t user_block_count;
+   block_t user_block_count, valid_user_blocks;
+   block_t avail_node_count, valid_node_count;
int i, j;
 
total = le32_to_cpu(raw_super->segment_count);
@@ -2379,6 +2380,24 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
return 1;
}
 
+   valid_user_blocks = le64_to_cpu(ckpt->valid_block_count);
+   if (valid_user_blocks > user_block_count) {
+   f2fs_msg(sbi->sb, KERN_ERR,
+   "Wrong valid_user_blocks: %u, user_block_count: %u",
+   valid_user_blocks, user_block_count);
+   return 1;
+   }
+
+   valid_node_count = le32_to_cpu(ckpt->valid_node_count);
+   avail_node_count = sbi->total_node_count - sbi->nquota_files -
+   F2FS_RESERVED_NODE_NUM;
+   if (valid_node_count > avail_node_count) {
+   f2fs_msg(sbi->sb, KERN_ERR,
+   "Wrong valid_node_count: %u, avail_node_count: %u",
+   valid_node_count, avail_node_count);
+   return 1;
+   }
+
main_segs = le32_to_cpu(raw_super->segment_count_main);
blocks_per_seg = sbi->blocks_per_seg;
 
-- 
2.20.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [bug report] compiler warning: fs/f2fs/node.c: In function ‘__set_nat_cache_dirty’: ‘head’ may be used uninitialized

2019-10-25 Thread Chao Yu
On 2019/10/24 17:54, Ardelean, Alexandru wrote:
> On Thu, 2019-10-24 at 17:12 +0800, Chao Yu wrote:
>> [External]
>>
>> On 2019/10/23 22:02, Ardelean, Alexandru wrote:
>>> Seems to have been introduced via:
>>>
>>> 
>>>
>>> commit 780de47cf6cb5f524cd98ec8ffbffc3da5696e17
>>> Author: Chao Yu 
>>> Date:   Tue Mar 20 23:08:30 2018 +0800
>>>
>>> f2fs: don't track new nat entry in nat set
>>> 
>>> Nat entry set is used only in checkpoint(), and during checkpoint()
>>> we
>>> won't flush new nat entry with unallocated address, so we don't
>>> need to
>>> add new nat entry into nat set, then nat_entry_set::entry_cnt can
>>> indicate actual entry count we need to flush in checkpoint().
>>> 
>>> Signed-off-by: Yunlei He 
>>> Signed-off-by: Chao Yu 
>>> Signed-off-by: Jaegeuk Kim 
>>> 
>>>
>>> Compiler warning is:
>>> 
>>>
>>>   CC  fs/f2fs/node.o
>>> In file included from ./include/linux/wait.h:7:0,
>>>  from ./include/linux/wait_bit.h:8,
>>>  from ./include/linux/fs.h:6,
>>>  from fs/f2fs/node.c:11:
>>> fs/f2fs/node.c: In function ‘__set_nat_cache_dirty’:
>>> ./include/linux/list.h:63:13: error: ‘head’ may be used uninitialized
>>> in
>>> this function [-Werror=maybe-uninitialized]
>>>   next->prev = new;
>>>  ^
>>> fs/f2fs/node.c:238:24: note: ‘head’ was declared here
>>>   struct nat_entry_set *head;
>>
>> That's not correct, @head will only be assigned and used if new_ne equals
>> NULL.
> 
> Ack.
> I admit that I don't understand the code, and don't claim to understand it.
> 
> This may be just a weird compiler issue.
> I thought I'd send it just as a heads-up.

I think that's the right thing to do.

> I saw this on a Raspberry Pi branch [after we enabled warnings as errors]:
> https://travis-ci.org/analogdevicesinc/linux/jobs/601844926#L1208
> 
> Looking in the latest f2fs/dev[-test] tree, it looks like the code is
> similar as in 4.19.
> https://github.com/analogdevicesinc/linux/blob/rpi-4.19.y/fs/f2fs/node.c#L235
> 
> Could be that the RPi branch has some more compiler-stuff enabled.
> 
> In any case, feel free to disregard this.
> We will see how we fix this on our end for that branch specifically.

That would make sense, let me know if you have any other suspicious compiler
warnings. :)

Thanks,

> 
> Thanks
> Alex
> 
>>
>> Thanks,
>>
>>> ^
>>> cc1: all warnings being treated as errors
>>> 
>>>
>>> Thanks
>>> Alex
>>>
>>> ___
>>> Linux-f2fs-devel mailing list
>>> Linux-f2fs-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>>>


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 2/2] f2fs: Add f2fs stats to sysfs

2019-10-25 Thread Chao Yu
On 2019/10/25 11:51, Hridya Valsaraju wrote:
> On Thu, Oct 24, 2019 at 2:26 AM Chao Yu  wrote:
>>
>> On 2019/10/24 5:48, Hridya Valsaraju wrote:
>>> Currently f2fs stats are only available from /d/f2fs/status. This patch
>>> adds some of the f2fs stats to sysfs so that they are accessible even
>>> when debugfs is not mounted.
>>
>> Why don't we mount debugfs first?
> 
> Thank you for taking a look at the patch Chao. We will not be mounting
> debugfs for security reasons.

Hi, Hridya,

May I ask is there any use case for those new entries?

So many sysfs entries exist, if there is real use case, how about backuping
entire /d/f2fs/status entry into /proc/fs/f2fs// directory rather than
adding some of stats as a single entry in sysfs directory?

Thanks,

> 
> Regards,
> Hridya
> 
>>
>> Thanks,
> .
> 


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/2] f2fs: support aligned pinned file

2019-10-25 Thread Jaegeuk Kim
On 10/24, Chao Yu wrote:
> Hi Jaegeuk,
> 
> On 2019/10/23 1:16, Jaegeuk Kim wrote:
> > This patch supports 2MB-aligned pinned file, which can guarantee no GC at 
> > all
> > by allocating fully valid 2MB segment.
> > 
> > Signed-off-by: Jaegeuk Kim 
> > ---
> >  fs/f2fs/f2fs.h |  4 +++-
> >  fs/f2fs/file.c | 39 ++-
> >  fs/f2fs/recovery.c |  2 +-
> >  fs/f2fs/segment.c  | 21 -
> >  fs/f2fs/segment.h  |  2 ++
> >  fs/f2fs/super.c|  1 +
> >  fs/f2fs/sysfs.c|  2 ++
> >  7 files changed, 63 insertions(+), 8 deletions(-)
> > 
> > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > index ca342f4c7db1..c681f51e351b 100644
> > --- a/fs/f2fs/f2fs.h
> > +++ b/fs/f2fs/f2fs.h
> > @@ -890,6 +890,7 @@ enum {
> > CURSEG_WARM_NODE,   /* direct node blocks of normal files */
> > CURSEG_COLD_NODE,   /* indirect node blocks */
> > NO_CHECK_TYPE,
> > +   CURSEG_COLD_DATA_PINNED,/* cold data for pinned file */
> >  };
> >  
> >  struct flush_cmd {
> > @@ -1301,6 +1302,7 @@ struct f2fs_sb_info {
> >  
> > /* threshold for gc trials on pinned files */
> > u64 gc_pin_file_threshold;
> > +   struct rw_semaphore pin_sem;
> >  
> > /* maximum # of trials to find a victim segment for SSR and GC */
> > unsigned int max_victim_search;
> > @@ -3116,7 +3118,7 @@ void f2fs_release_discard_addrs(struct f2fs_sb_info 
> > *sbi);
> >  int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
> >  void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
> > unsigned int start, unsigned int end);
> > -void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
> > +void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi, int type);
> >  int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
> >  bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
> > struct cp_control *cpc);
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > index 29bc0a542759..f6c038e8a6a7 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -1545,12 +1545,41 @@ static int expand_inode_data(struct inode *inode, 
> > loff_t offset,
> > if (off_end)
> > map.m_len++;
> >  
> > -   if (f2fs_is_pinned_file(inode))
> > -   map.m_seg_type = CURSEG_COLD_DATA;
> > +   if (!map.m_len)
> > +   return 0;
> > +
> > +   if (f2fs_is_pinned_file(inode)) {
> > +   block_t len = (map.m_len >> sbi->log_blocks_per_seg) <<
> > +   sbi->log_blocks_per_seg;
> > +   block_t done = 0;
> > +
> > +   if (map.m_len % sbi->blocks_per_seg)
> > +   len += sbi->blocks_per_seg;
> >  
> > -   err = f2fs_map_blocks(inode, , 1, (f2fs_is_pinned_file(inode) ?
> > -   F2FS_GET_BLOCK_PRE_DIO :
> > -   F2FS_GET_BLOCK_PRE_AIO));
> > +   map.m_len = sbi->blocks_per_seg;
> > +next_alloc:
> > +   mutex_lock(>gc_mutex);
> > +   err = f2fs_gc(sbi, true, false, NULL_SEGNO);
> > +   if (err && err != -ENODATA && err != -EAGAIN)
> > +   goto out_err;
> 
> To grab enough free space?
> 
> Shouldn't we call
> 
>   if (has_not_enough_free_secs(sbi, 0, 0)) {
>   mutex_lock(>gc_mutex);
>   f2fs_gc(sbi, false, false, NULL_SEGNO);
>   }

The above calls gc all the time. Do we need this?

> 
> > +
> > +   down_write(>pin_sem);
> > +   map.m_seg_type = CURSEG_COLD_DATA_PINNED;
> > +   f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA);
> > +   err = f2fs_map_blocks(inode, , 1, F2FS_GET_BLOCK_PRE_DIO);
> > +   up_write(>pin_sem);
> > +
> > +   done += map.m_len;
> > +   len -= map.m_len;
> > +   map.m_lblk += map.m_len;
> > +   if (!err && len)
> > +   goto next_alloc;
> > +
> > +   map.m_len = done;
> > +   } else {
> > +   err = f2fs_map_blocks(inode, , 1, F2FS_GET_BLOCK_PRE_AIO);
> > +   }
> > +out_err:
> > if (err) {
> > pgoff_t last_off;
> >  
> > diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
> > index 783773e4560d..76477f71d4ee 100644
> > --- a/fs/f2fs/recovery.c
> > +++ b/fs/f2fs/recovery.c
> > @@ -711,7 +711,7 @@ static int recover_data(struct f2fs_sb_info *sbi, 
> > struct list_head *inode_list,
> > f2fs_put_page(page, 1);
> > }
> > if (!err)
> > -   f2fs_allocate_new_segments(sbi);
> > +   f2fs_allocate_new_segments(sbi, NO_CHECK_TYPE);
> > return err;
> >  }
> >  
> > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> > index 25c750cd0272..253d72c2663c 100644
> > --- a/fs/f2fs/segment.c
> > +++ b/fs/f2fs/segment.c
> > @@ -2690,7 +2690,7 @@ void allocate_segment_for_resize(struct f2fs_sb_info 
> > *sbi, int type,
> > up_read(_I(sbi)->curseg_lock);
> >  }
> >  
> 

Re: [f2fs-dev] [PATCH 2/2] f2fs: Add f2fs stats to sysfs

2019-10-25 Thread Jaegeuk Kim
On 10/25, Chao Yu wrote:
> On 2019/10/25 11:51, Hridya Valsaraju wrote:
> > On Thu, Oct 24, 2019 at 2:26 AM Chao Yu  wrote:
> >>
> >> On 2019/10/24 5:48, Hridya Valsaraju wrote:
> >>> Currently f2fs stats are only available from /d/f2fs/status. This patch
> >>> adds some of the f2fs stats to sysfs so that they are accessible even
> >>> when debugfs is not mounted.
> >>
> >> Why don't we mount debugfs first?
> > 
> > Thank you for taking a look at the patch Chao. We will not be mounting
> > debugfs for security reasons.
> 
> Hi, Hridya,
> 
> May I ask is there any use case for those new entries?
> 
> So many sysfs entries exist, if there is real use case, how about backuping
> entire /d/f2fs/status entry into /proc/fs/f2fs// directory rather than
> adding some of stats as a single entry in sysfs directory?

These will be useful to keep a track on f2fs health status by one value
per entry, which doesn't require user-land parsing stuff. Of course, Android
can exploit them by IdleMaint, rollback feature, and so on.

> 
> Thanks,
> 
> > 
> > Regards,
> > Hridya
> > 
> >>
> >> Thanks,
> > .
> > 


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/2] f2fs: delete duplicate information on sysfs nodes

2019-10-25 Thread Jaegeuk Kim
On 10/24, Chao Yu wrote:
> On 2019/10/24 5:48, Hridya Valsaraju wrote:
> > This patch merges the sysfs node documentation present in
> > Documentation/filesystems/f2fs.txt and
> > Documentation/ABI/testing/sysfs-fs-f2fs
> > and deletes the duplicate information from
> > Documentation/filesystems/f2fs.txt. This is to prevent having to update
> > both files when a new sysfs node is added for f2fs.
> > The patch also makes minor formatting changes to
> > Documentation/ABI/testing/sysfs-fs-f2fs.
> 
> Jaegeuk, any particular reason to add duplicated description on f2fs.txt 
> previously?

Not at all, thus, I asked Hridya to consolidate them. :P

> 
> Thanks,


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/2] f2fs: delete duplicate information on sysfs nodes

2019-10-25 Thread Chao Yu
On 2019/10/26 2:23, Jaegeuk Kim wrote:
> On 10/24, Chao Yu wrote:
>> On 2019/10/24 5:48, Hridya Valsaraju wrote:
>>> This patch merges the sysfs node documentation present in
>>> Documentation/filesystems/f2fs.txt and
>>> Documentation/ABI/testing/sysfs-fs-f2fs
>>> and deletes the duplicate information from
>>> Documentation/filesystems/f2fs.txt. This is to prevent having to update
>>> both files when a new sysfs node is added for f2fs.
>>> The patch also makes minor formatting changes to
>>> Documentation/ABI/testing/sysfs-fs-f2fs.
>>
>> Jaegeuk, any particular reason to add duplicated description on f2fs.txt 
>> previously?
> 
> Not at all, thus, I asked Hridya to consolidate them. :P

Alright...

Reviewed-by: Chao Yu 

Thanks,

> 
>>
>> Thanks,
> .
> 


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 2/2] f2fs: Add f2fs stats to sysfs

2019-10-25 Thread Chao Yu
On 2019/10/26 2:22, Jaegeuk Kim wrote:
> On 10/25, Chao Yu wrote:
>> On 2019/10/25 11:51, Hridya Valsaraju wrote:
>>> On Thu, Oct 24, 2019 at 2:26 AM Chao Yu  wrote:

 On 2019/10/24 5:48, Hridya Valsaraju wrote:
> Currently f2fs stats are only available from /d/f2fs/status. This patch
> adds some of the f2fs stats to sysfs so that they are accessible even
> when debugfs is not mounted.

 Why don't we mount debugfs first?
>>>
>>> Thank you for taking a look at the patch Chao. We will not be mounting
>>> debugfs for security reasons.
>>
>> Hi, Hridya,
>>
>> May I ask is there any use case for those new entries?
>>
>> So many sysfs entries exist, if there is real use case, how about backuping
>> entire /d/f2fs/status entry into /proc/fs/f2fs// directory rather than
>> adding some of stats as a single entry in sysfs directory?
> 
> These will be useful to keep a track on f2fs health status by one value
> per entry, which doesn't require user-land parsing stuff. Of course, Android
> can exploit them by IdleMaint, rollback feature, and so on.

Alright, I suggest to add a sub-directory for those statistic entries, we can
manage them more easily isolated from those existed switch entries.

Thanks,

> 
>>
>> Thanks,
>>
>>>
>>> Regards,
>>> Hridya
>>>

 Thanks,
>>> .
>>>
> .
> 


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH 1/2] f2fs: support aligned pinned file

2019-10-25 Thread Chao Yu
On 2019/10/26 2:18, Jaegeuk Kim wrote:
> On 10/24, Chao Yu wrote:
>> Hi Jaegeuk,
>>
>> On 2019/10/23 1:16, Jaegeuk Kim wrote:
>>> This patch supports 2MB-aligned pinned file, which can guarantee no GC at 
>>> all
>>> by allocating fully valid 2MB segment.
>>>
>>> Signed-off-by: Jaegeuk Kim 
>>> ---
>>>  fs/f2fs/f2fs.h |  4 +++-
>>>  fs/f2fs/file.c | 39 ++-
>>>  fs/f2fs/recovery.c |  2 +-
>>>  fs/f2fs/segment.c  | 21 -
>>>  fs/f2fs/segment.h  |  2 ++
>>>  fs/f2fs/super.c|  1 +
>>>  fs/f2fs/sysfs.c|  2 ++
>>>  7 files changed, 63 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>> index ca342f4c7db1..c681f51e351b 100644
>>> --- a/fs/f2fs/f2fs.h
>>> +++ b/fs/f2fs/f2fs.h
>>> @@ -890,6 +890,7 @@ enum {
>>> CURSEG_WARM_NODE,   /* direct node blocks of normal files */
>>> CURSEG_COLD_NODE,   /* indirect node blocks */
>>> NO_CHECK_TYPE,
>>> +   CURSEG_COLD_DATA_PINNED,/* cold data for pinned file */
>>>  };
>>>  
>>>  struct flush_cmd {
>>> @@ -1301,6 +1302,7 @@ struct f2fs_sb_info {
>>>  
>>> /* threshold for gc trials on pinned files */
>>> u64 gc_pin_file_threshold;
>>> +   struct rw_semaphore pin_sem;
>>>  
>>> /* maximum # of trials to find a victim segment for SSR and GC */
>>> unsigned int max_victim_search;
>>> @@ -3116,7 +3118,7 @@ void f2fs_release_discard_addrs(struct f2fs_sb_info 
>>> *sbi);
>>>  int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
>>>  void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
>>> unsigned int start, unsigned int end);
>>> -void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
>>> +void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi, int type);
>>>  int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
>>>  bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
>>> struct cp_control *cpc);
>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>>> index 29bc0a542759..f6c038e8a6a7 100644
>>> --- a/fs/f2fs/file.c
>>> +++ b/fs/f2fs/file.c
>>> @@ -1545,12 +1545,41 @@ static int expand_inode_data(struct inode *inode, 
>>> loff_t offset,
>>> if (off_end)
>>> map.m_len++;
>>>  
>>> -   if (f2fs_is_pinned_file(inode))
>>> -   map.m_seg_type = CURSEG_COLD_DATA;
>>> +   if (!map.m_len)
>>> +   return 0;
>>> +
>>> +   if (f2fs_is_pinned_file(inode)) {
>>> +   block_t len = (map.m_len >> sbi->log_blocks_per_seg) <<
>>> +   sbi->log_blocks_per_seg;
>>> +   block_t done = 0;
>>> +
>>> +   if (map.m_len % sbi->blocks_per_seg)
>>> +   len += sbi->blocks_per_seg;
>>>  
>>> -   err = f2fs_map_blocks(inode, , 1, (f2fs_is_pinned_file(inode) ?
>>> -   F2FS_GET_BLOCK_PRE_DIO :
>>> -   F2FS_GET_BLOCK_PRE_AIO));
>>> +   map.m_len = sbi->blocks_per_seg;
>>> +next_alloc:
>>> +   mutex_lock(>gc_mutex);
>>> +   err = f2fs_gc(sbi, true, false, NULL_SEGNO);
>>> +   if (err && err != -ENODATA && err != -EAGAIN)
>>> +   goto out_err;
>>
>> To grab enough free space?
>>
>> Shouldn't we call
>>
>>  if (has_not_enough_free_secs(sbi, 0, 0)) {
>>  mutex_lock(>gc_mutex);
>>  f2fs_gc(sbi, false, false, NULL_SEGNO);
>>  }
> 
> The above calls gc all the time. Do we need this?

Hmmm... my concern is why we need to run foreground GC even if there is enough
free space..

> 
>>
>>> +
>>> +   down_write(>pin_sem);
>>> +   map.m_seg_type = CURSEG_COLD_DATA_PINNED;
>>> +   f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA);
>>> +   err = f2fs_map_blocks(inode, , 1, F2FS_GET_BLOCK_PRE_DIO);
>>> +   up_write(>pin_sem);
>>> +
>>> +   done += map.m_len;
>>> +   len -= map.m_len;
>>> +   map.m_lblk += map.m_len;
>>> +   if (!err && len)
>>> +   goto next_alloc;
>>> +
>>> +   map.m_len = done;
>>> +   } else {
>>> +   err = f2fs_map_blocks(inode, , 1, F2FS_GET_BLOCK_PRE_AIO);
>>> +   }
>>> +out_err:
>>> if (err) {
>>> pgoff_t last_off;
>>>  
>>> diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
>>> index 783773e4560d..76477f71d4ee 100644
>>> --- a/fs/f2fs/recovery.c
>>> +++ b/fs/f2fs/recovery.c
>>> @@ -711,7 +711,7 @@ static int recover_data(struct f2fs_sb_info *sbi, 
>>> struct list_head *inode_list,
>>> f2fs_put_page(page, 1);
>>> }
>>> if (!err)
>>> -   f2fs_allocate_new_segments(sbi);
>>> +   f2fs_allocate_new_segments(sbi, NO_CHECK_TYPE);
>>> return err;
>>>  }
>>>  
>>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>>> index 25c750cd0272..253d72c2663c 100644
>>> --- a/fs/f2fs/segment.c
>>> +++ b/fs/f2fs/segment.c
>>> @@