mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 18:20:25 +02:00 
			
		
		
		
	f2fs: avoid using native allocate_segment_by_default()
As we did for other cases, in fix_curseg_write_pointer(), let's use wrapped f2fs_allocate_new_section() instead of native allocate_segment_by_default(), by this way, it fixes to cover segment allocation with curseg_lock and sentry_lock. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
		
							parent
							
								
									a7b4e506dc
								
							
						
					
					
						commit
						509f1010e4
					
				
					 3 changed files with 12 additions and 10 deletions
				
			
		| 
						 | 
					@ -3395,7 +3395,7 @@ void f2fs_get_new_segment(struct f2fs_sb_info *sbi,
 | 
				
			||||||
			unsigned int *newseg, bool new_sec, int dir);
 | 
								unsigned int *newseg, bool new_sec, int dir);
 | 
				
			||||||
void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
 | 
					void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
 | 
				
			||||||
					unsigned int start, unsigned int end);
 | 
										unsigned int start, unsigned int end);
 | 
				
			||||||
void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type);
 | 
					void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force);
 | 
				
			||||||
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
 | 
					void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
 | 
				
			||||||
int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
 | 
					int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
 | 
				
			||||||
bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
 | 
					bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1664,7 +1664,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
 | 
				
			||||||
		down_write(&sbi->pin_sem);
 | 
							down_write(&sbi->pin_sem);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		f2fs_lock_op(sbi);
 | 
							f2fs_lock_op(sbi);
 | 
				
			||||||
		f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED);
 | 
							f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false);
 | 
				
			||||||
		f2fs_unlock_op(sbi);
 | 
							f2fs_unlock_op(sbi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		map.m_seg_type = CURSEG_COLD_DATA_PINNED;
 | 
							map.m_seg_type = CURSEG_COLD_DATA_PINNED;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2933,7 +2933,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
 | 
					static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
 | 
				
			||||||
								bool new_sec)
 | 
											bool new_sec, bool force)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct curseg_info *curseg = CURSEG_I(sbi, type);
 | 
						struct curseg_info *curseg = CURSEG_I(sbi, type);
 | 
				
			||||||
	unsigned int old_segno;
 | 
						unsigned int old_segno;
 | 
				
			||||||
| 
						 | 
					@ -2941,7 +2941,7 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
 | 
				
			||||||
	if (!curseg->inited)
 | 
						if (!curseg->inited)
 | 
				
			||||||
		goto alloc;
 | 
							goto alloc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (curseg->next_blkoff ||
 | 
						if (force || curseg->next_blkoff ||
 | 
				
			||||||
		get_valid_blocks(sbi, curseg->segno, new_sec))
 | 
							get_valid_blocks(sbi, curseg->segno, new_sec))
 | 
				
			||||||
		goto alloc;
 | 
							goto alloc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2953,16 +2953,17 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
 | 
				
			||||||
	locate_dirty_segment(sbi, old_segno);
 | 
						locate_dirty_segment(sbi, old_segno);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void __allocate_new_section(struct f2fs_sb_info *sbi, int type)
 | 
					static void __allocate_new_section(struct f2fs_sb_info *sbi,
 | 
				
			||||||
 | 
											int type, bool force)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	__allocate_new_segment(sbi, type, true);
 | 
						__allocate_new_segment(sbi, type, true, force);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type)
 | 
					void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	down_read(&SM_I(sbi)->curseg_lock);
 | 
						down_read(&SM_I(sbi)->curseg_lock);
 | 
				
			||||||
	down_write(&SIT_I(sbi)->sentry_lock);
 | 
						down_write(&SIT_I(sbi)->sentry_lock);
 | 
				
			||||||
	__allocate_new_section(sbi, type);
 | 
						__allocate_new_section(sbi, type, force);
 | 
				
			||||||
	up_write(&SIT_I(sbi)->sentry_lock);
 | 
						up_write(&SIT_I(sbi)->sentry_lock);
 | 
				
			||||||
	up_read(&SM_I(sbi)->curseg_lock);
 | 
						up_read(&SM_I(sbi)->curseg_lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -2974,7 +2975,7 @@ void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
 | 
				
			||||||
	down_read(&SM_I(sbi)->curseg_lock);
 | 
						down_read(&SM_I(sbi)->curseg_lock);
 | 
				
			||||||
	down_write(&SIT_I(sbi)->sentry_lock);
 | 
						down_write(&SIT_I(sbi)->sentry_lock);
 | 
				
			||||||
	for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++)
 | 
						for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++)
 | 
				
			||||||
		__allocate_new_segment(sbi, i, false);
 | 
							__allocate_new_segment(sbi, i, false, false);
 | 
				
			||||||
	up_write(&SIT_I(sbi)->sentry_lock);
 | 
						up_write(&SIT_I(sbi)->sentry_lock);
 | 
				
			||||||
	up_read(&SM_I(sbi)->curseg_lock);
 | 
						up_read(&SM_I(sbi)->curseg_lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -4844,7 +4845,8 @@ static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	f2fs_notice(sbi, "Assign new section to curseg[%d]: "
 | 
						f2fs_notice(sbi, "Assign new section to curseg[%d]: "
 | 
				
			||||||
		    "curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
 | 
							    "curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
 | 
				
			||||||
	allocate_segment_by_default(sbi, type, true);
 | 
					
 | 
				
			||||||
 | 
						f2fs_allocate_new_section(sbi, type, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* check consistency of the zone curseg pointed to */
 | 
						/* check consistency of the zone curseg pointed to */
 | 
				
			||||||
	if (check_zone_write_pointer(sbi, zbd, &zone))
 | 
						if (check_zone_write_pointer(sbi, zbd, &zone))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue