Re: [f2fs-dev] [PATCH] f2fs: block checkpoint before moving cursegs for device aliasing
From: Chao Yu
Date: Mon Nov 30 2026 - 23:32:11 EST
On 11/16/26 08:00, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@xxxxxxxxxx>
>
> f2fs_ioc_reserve_dev_alias() moves the cursegs out of the range of the
> alias device with gc_lock only, before it takes f2fs_lock_op(). gc_lock
> does not keep every checkpoint away: f2fs_ioc_reserve_dev_alias() and
> f2fs_ioc_release_dev_alias() write the checkpoint at their end after they
> released gc_lock. So the cursegs can be moved while a checkpoint of
> another alias ioctl is in progress.
Oh, why we not cover f2fs_write_checkpoint() w/ gc_lock like we do for other
cases? should we fix this first?
Thanks,
>
> do_checkpoint() copies the positions of the cursegs into the checkpoint
> first and writes their summaries later. If a curseg is moved in between,
> the checkpoint does not match it. Commit b4b10061ef98 ("f2fs: refactor
> resize_fs to avoid meta updates in progress") fixed the same problem in
> f2fs_resize_fs() by taking f2fs_lock_op() before the cursegs are moved.
>
> Do the same here. Take f2fs_lock_op() first, and then move the cursegs.
>
> Test: two alias files, with a debug patch which makes do_checkpoint()
> of the release ioctl sleep after it copied the curseg positions. A
> reserve ioctl on the other alias file moved the warm data curseg during
> that sleep, and the checkpoint recorded the segment the curseg had left.
> With this patch, the curseg is moved after the checkpoint is done.
>
> Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device aliasing")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Daeho Jeong <daehojeong@xxxxxxxxxx>
> ---
> fs/f2fs/file.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 05061254c3b2..75c51b3a4118 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -3905,13 +3905,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp)
> /* Reset the victim information to prevent GC from targeting the range */
> f2fs_reset_gc_victim_resource(sbi, start, end);
>
> - /* Move out cursegs from the target range */
> - for (type = CURSEG_HOT_DATA; type < NR_CURSEG_PERSIST_TYPE; type++) {
> - err = f2fs_allocate_segment_for_resize(sbi, type, start, end);
> - if (err)
> - goto out_gc_unlock;
> - }
> -
> + /* stop CP before moving cursegs, as f2fs_resize_fs() does */
> f2fs_lock_op(sbi, &lc);
>
> if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
> @@ -3920,6 +3914,15 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp)
> goto out_gc_unlock;
> }
>
> + /* Move out cursegs from the target range */
> + for (type = CURSEG_HOT_DATA; type < NR_CURSEG_PERSIST_TYPE; type++) {
> + err = f2fs_allocate_segment_for_resize(sbi, type, start, end);
> + if (err) {
> + f2fs_unlock_op(sbi, &lc);
> + goto out_gc_unlock;
> + }
> + }
> +
> /* do GC to move out valid blocks in the range all at once! */
> err = f2fs_gc_range(sbi, start, end, false, 0, false);
> if (err) {