Skip to contentSkip to conversation

f2fs: trigger correct checkpoint during umount

PATCH In review Jaegeuk Kim 2 participants 5 messages Jan 23, 2015

Subsystems (2)
lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/2 f2fs: trigger correct checkpoint during umount

This patch fixes to trigger checkpoint with umount flag when kill_sb was called. In kill_sb, f2fs_sync_fs was finally called, but at this time, f2fs can't do checkpoint with CP_UMOUNT.
After then, f2fs_put_super is not doing checkpoint, since it is not dirty.

So, this patch adds a flag to indicate f2fs_sync_fs is called during umount.

---
 fs/f2fs/f2fs.h  |  1 +
 fs/f2fs/super.c | 12 ++++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)
fs/f2fs/f2fs.h +1 -0
index c2cf040..1795ce2 100644
@@ -525,6 +525,7 @@ struct f2fs_sb_info {
 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
 	int s_dirty;				/* dirty flag for checkpoint */
 	bool need_fsck;				/* need fsck.f2fs to fix */
+	bool s_closing;				/* specify unmounting */
 
 	/* for node-related operations */
 	struct f2fs_nm_info *nm_info;		/* node manager */
fs/f2fs/super.c +10 -2
index 0e97974..84f95cd 100644
@@ -487,7 +487,8 @@ int f2fs_sync_fs(struct super_block *sb, int sync)
 	if (sync) {
 		struct cp_control cpc;
 
-		cpc.reason = test_opt(sbi, FASTBOOT) ? CP_UMOUNT : CP_SYNC;
+		cpc.reason = (test_opt(sbi, FASTBOOT) || sbi->s_closing) ?
+							CP_UMOUNT : CP_SYNC;
 		mutex_lock(&sbi->gc_mutex);
 		write_checkpoint(sbi, &cpc);
 		mutex_unlock(&sbi->gc_mutex);
@@ -1190,11 +1191,18 @@ static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags,
 	return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super);
 }
 
+static void kill_f2fs_super(struct super_block *sb)
+{
+	if (sb->s_root)
+		F2FS_SB(sb)->s_closing = true;
+	kill_block_super(sb);
+}
+
 static struct file_system_type f2fs_fs_type = {
 	.owner		= THIS_MODULE,
 	.name		= "f2fs",
 	.mount		= f2fs_mount,
-	.kill_sb	= kill_block_super,
+	.kill_sb	= kill_f2fs_super,
 	.fs_flags	= FS_REQUIRES_DEV,
 };
 MODULE_ALIAS_FS("f2fs");
Signature · 1 line
2.1.1
author maintainer
#1 lore raw

PATCH 2/2 f2fs: do checkpoint when umount flag is not set

If the previous checkpoint was done without CP_UMOUNT flag, it needs to do checkpoint with CP_UMOUNT for the next fast boot.

---
 fs/f2fs/checkpoint.c | 3 ++-
 fs/f2fs/super.c      | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
fs/f2fs/checkpoint.c +2 -1
index 9f5317c..231d8c9 100644
@@ -1043,7 +1043,8 @@ void write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 
 	mutex_lock(&sbi->cp_mutex);
 
-	if (!sbi->s_dirty && cpc->reason != CP_DISCARD)
+	if (!sbi->s_dirty &&
+			cpc->reason != CP_DISCARD && cpc->reason != CP_UMOUNT)
 		goto out;
 	if (unlikely(f2fs_cp_error(sbi)))
 		goto out;
fs/f2fs/super.c +2 -1
index 84f95cd..6ef1458 100644
@@ -448,7 +448,8 @@ static void f2fs_put_super(struct super_block *sb)
 	stop_gc_thread(sbi);
 
 	/* We don't need to do checkpoint when it's clean */
-	if (sbi->s_dirty) {
+	if (sbi->s_dirty ||
+			!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) {
 		struct cp_control cpc = {
 			.reason = CP_UMOUNT,
 		};
Signature · 1 line
2.1.1
Reviewed-by on v1 2/2
#2 lore raw

RE: [f2fs-dev] [PATCH 2/2] f2fs: do checkpoint when umount flag is not set

Quoted 8 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, January 23, 2015 8:09 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 2/2] f2fs: do checkpoint when umount flag is not set

Quoted 4 lines

If the previous checkpoint was done without CP_UMOUNT flag, it needs to do checkpoint with CP_UMOUNT for the next fast boot.

Quoted 24 lines
---
 fs/f2fs/checkpoint.c | 3 ++-
 fs/f2fs/super.c      | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
fs/f2fs/checkpoint.c +2 -1
index 9f5317c..231d8c9 100644
@@ -1043,7 +1043,8 @@ void write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 
 	mutex_lock(&sbi->cp_mutex);
 
-	if (!sbi->s_dirty && cpc->reason != CP_DISCARD)
+	if (!sbi->s_dirty &&
+			cpc->reason != CP_DISCARD && cpc->reason != CP_UMOUNT)
 		goto out;
 	if (unlikely(f2fs_cp_error(sbi)))
 		goto out;
fs/f2fs/super.c +0 -0
index 84f95cd..6ef1458 100644

fs/f2fs/super.c static void f2fs_put_super(struct super_block *sb) · line 450

Quoted 3 lines
fs/f2fs/super.c +0 -0
@@ -448,7 +448,8 @@ static void f2fs_put_super(struct super_block *sb)
 	stop_gc_thread(sbi);
 
 	/* We don't need to do checkpoint when it's clean */

Better to update the annotation above.

Thanks,
Yu

Quoted 9 lines
fs/f2fs/super.c +2 -2
-	if (sbi->s_dirty) {
+	if (sbi->s_dirty ||
+			!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) {
 		struct cp_control cpc = {
 			.reason = CP_UMOUNT,
 		};
--

2.1.1

author maintainer
#3 lore raw

Re: [f2fs-dev] [PATCH 2/2] f2fs: do checkpoint when umount flag is not set

Quoted 41 lines · Chao Yu
Quoted 8 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, January 23, 2015 8:09 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 2/2] f2fs: do checkpoint when umount flag is not set

Quoted 4 lines

If the previous checkpoint was done without CP_UMOUNT flag, it needs to do checkpoint with CP_UMOUNT for the next fast boot.

Quoted 26 lines
---
 fs/f2fs/checkpoint.c | 3 ++-
 fs/f2fs/super.c      | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
fs/f2fs/checkpoint.c +2 -1
index 9f5317c..231d8c9 100644
@@ -1043,7 +1043,8 @@ void write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 
 	mutex_lock(&sbi->cp_mutex);
 
-	if (!sbi->s_dirty && cpc->reason != CP_DISCARD)
+	if (!sbi->s_dirty &&
+			cpc->reason != CP_DISCARD && cpc->reason != CP_UMOUNT)
 		goto out;
 	if (unlikely(f2fs_cp_error(sbi)))
 		goto out;
fs/f2fs/super.c +0 -0
index 84f95cd..6ef1458 100644
@@ -448,7 +448,8 @@ static void f2fs_put_super(struct super_block *sb)
 	stop_gc_thread(sbi);
 
Quoted 3 lines

fs/f2fs/super.c static void f2fs_put_super(struct super_block *sb) · line 450

Quoted 1 line
fs/f2fs/super.c +0 -0
 	/* We don't need to do checkpoint when it's clean */

Better to update the annotation above.

Added some comments. :)

Thanks,

Quoted 13 lines

Thanks,
Yu

Quoted 9 lines
fs/f2fs/super.c +2 -2
-	if (sbi->s_dirty) {
+	if (sbi->s_dirty ||
+			!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) {
 		struct cp_control cpc = {
 			.reason = CP_UMOUNT,
 		};
--

2.1.1

Reviewed-by on v1 1/2
#4 lore raw
In reply to Jaegeuk Kim
Quoted 8 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, January 23, 2015 8:09 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 1/2] f2fs: trigger correct checkpoint during umount

Quoted 6 lines

This patch fixes to trigger checkpoint with umount flag when kill_sb was called. In kill_sb, f2fs_sync_fs was finally called, but at this time, f2fs can't do checkpoint with CP_UMOUNT.
After then, f2fs_put_super is not doing checkpoint, since it is not dirty.

So, this patch adds a flag to indicate f2fs_sync_fs is called during umount.

Nice catch!

Quoted 2 lines