* [PATCH v2] f2fs: cover the checkpoint of device aliasing ioctls with gc_lock
@ 2026-12-01 17:19 Daeho Jeong
0 siblings, 0 replies; only message in thread
From: Daeho Jeong @ 2026-12-01 17:19 UTC (permalink / raw)
To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong, stable, Chao Yu
From: Daeho Jeong <daehojeong@google.com>
f2fs_ioc_reserve_dev_alias() and f2fs_ioc_release_dev_alias() write the
checkpoint at their end after they released gc_lock. All the other
callers of f2fs_write_checkpoint() on a mounted filesystem hold gc_lock,
so only these two checkpoints can run while another task holds gc_lock.
f2fs_ioc_reserve_dev_alias() is such a task: it moves the cursegs out of
the range of the alias device with gc_lock held, before it takes
f2fs_lock_op(). do_checkpoint() copies the positions of the cursegs into
the checkpoint first and writes their summaries later. If the checkpoint
of another alias ioctl is in progress and a curseg is moved in between,
the checkpoint does not match it.
Hold gc_lock for the checkpoint in both ioctls, as the other callers do.
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 reserve ioctl waits for the checkpoint and moves
the curseg after it.
Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device aliasing")
Cc: stable@vger.kernel.org
Suggested-by: Chao Yu <chao@kernel.org>
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
v2:
- cover the checkpoint of the two ioctls with gc_lock instead of taking
f2fs_lock_op() before the cursegs are moved, as Chao suggested. With
gc_lock held for every checkpoint, the cursegs cannot be moved during
a checkpoint, so the change of v1 is not needed.
- v1 was "f2fs: block checkpoint before moving cursegs for device
aliasing", which is in dev-test. This one is based on dev and replaces
it.
With the same debug patch, F2FS_IOC_GARBAGE_COLLECT started f2fs_gc()
during the checkpoint of the release ioctl with v1, and waits for the
checkpoint with v2.
v1: https://lore.kernel.org/linux-f2fs-devel/20261116000019.2299222-1-daeho43@gmail.com/
fs/f2fs/file.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c80dbbe76f8f..4f6e6d611642 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4160,7 +4160,12 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp)
inode_unlock(inode);
mnt_drop_write_file(filp);
- return f2fs_write_checkpoint(sbi, &cpc);
+ /* Hold gc_lock for the checkpoint, as the other callers do. */
+ f2fs_down_write_trace(&sbi->gc_lock, &glc);
+ err = f2fs_write_checkpoint(sbi, &cpc);
+ f2fs_up_write_trace(&sbi->gc_lock, &glc);
+
+ return err;
out_gc_unlock:
spin_lock(&sbi->stat_lock);
@@ -4250,7 +4255,12 @@ static int f2fs_ioc_release_dev_alias(struct file *filp)
inode_unlock(inode);
mnt_drop_write_file(filp);
- return f2fs_write_checkpoint(sbi, &cpc);
+ /* Hold gc_lock for the checkpoint, as the other callers do. */
+ f2fs_down_write_trace(&sbi->gc_lock, &glc);
+ err = f2fs_write_checkpoint(sbi, &cpc);
+ f2fs_up_write_trace(&sbi->gc_lock, &glc);
+
+ return err;
out_inode_unlock:
inode_unlock(inode);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 17:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 17:19 [PATCH v2] f2fs: cover the checkpoint of device aliasing ioctls with gc_lock Daeho Jeong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox