Skip to contentSkip to conversation

f2fs: hanlde error case in f2fs_ioc_shutdown

PATCH New Chao Yu 1 participant 2 messages Jan 17, 2018 F2FS file system

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH 1/2 f2fs: hanlde error case in f2fs_ioc_shutdown

From: Chao Yu <[email protected]>

This patch makes f2fs_ioc_shutdown handling error case correctly.

---
 fs/f2fs/file.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/file.c +8 -2
index 94be67591d1f..593a79447907 100644
@@ -1839,14 +1839,20 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg)
 	switch (in) {
 	case F2FS_GOING_DOWN_FULLSYNC:
 		sb = freeze_bdev(sb->s_bdev);
-		if (sb && !IS_ERR(sb)) {
+		if (IS_ERR(sb)) {
+			ret = PTR_ERR(sb);
+			goto out;
+		}
+		if (sb) {
 			f2fs_stop_checkpoint(sbi, false);
 			thaw_bdev(sb->s_bdev, sb);
 		}
 		break;
 	case F2FS_GOING_DOWN_METASYNC:
 		/* do checkpoint only */
-		f2fs_sync_fs(sb, 1);
+		ret = f2fs_sync_fs(sb, 1);
+		if (ret)
+			goto out;
 		f2fs_stop_checkpoint(sbi, false);
 		break;
 	case F2FS_GOING_DOWN_NOSYNC:
Signature · 1 line
2.14.1.145.gb3622a4ee
author maintainer
#1 lore raw

PATCH 2/2 f2fs: stop gc/discard thread after fs shutdown

From: Chao Yu <[email protected]>

Once filesystem shuts down, daemons like gc/discard thread should be aware of it, and do exit, in addtion, drop all pending discards in cache and exit real-time discard mode.

---
 fs/f2fs/f2fs.h    | 1 +
 fs/f2fs/file.c    | 4 ++++
 fs/f2fs/gc.c      | 2 ++
 fs/f2fs/segment.c | 7 +++++++
 4 files changed, 14 insertions(+)
fs/f2fs/f2fs.h +1 -0
index fb4ec1f61925..580d6ce7c594 100644
@@ -2724,6 +2724,7 @@ void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
 bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
 void init_discard_policy(struct discard_policy *dpolicy, int discard_type,
 						unsigned int granularity);
+void drop_discard_cmd(struct f2fs_sb_info *sbi);
 void stop_discard_thread(struct f2fs_sb_info *sbi);
 bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi);
 void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc);
fs/f2fs/file.c +4 -0
index 593a79447907..0a163c13e587 100644
@@ -1866,6 +1866,10 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg)
 		ret = -EINVAL;
 		goto out;
 	}
+
+	drop_discard_cmd(sbi);
+	clear_opt(sbi, DISCARD);
+
 	f2fs_update_time(sbi, REQ_TIME);
 out:
 	mnt_drop_write_file(filp);
fs/f2fs/gc.c +2 -0
index aa720cc44509..b69743e4bd11 100644
@@ -47,6 +47,8 @@ static int gc_thread_func(void *data)
 			continue;
 		if (kthread_should_stop())
 			break;
+		if (unlikely(f2fs_cp_error(sbi)))
+			break;
 
 		if (sbi->sb->s_writers.frozen >= SB_FREEZE_WRITE) {
 			increase_sleep_time(gc_th, &wait_ms);
fs/f2fs/segment.c +7 -0
index 2e8e054db49d..23d9b8ba2673 100644
@@ -1263,6 +1263,11 @@ static bool __drop_discard_cmd(struct f2fs_sb_info *sbi)
 	return dropped;
 }
 
+void drop_discard_cmd(struct f2fs_sb_info *sbi)
+{
+	__drop_discard_cmd(sbi);
+}
+
 static unsigned int __wait_one_discard_bio(struct f2fs_sb_info *sbi,
 							struct discard_cmd *dc)
 {
@@ -1403,6 +1408,8 @@ static int issue_discard_thread(void *data)
 			continue;
 		if (kthread_should_stop())
 			return 0;
+		if (unlikely(f2fs_cp_error(sbi)))
+			break;
 
 		if (dcc->discard_wake) {
 			dcc->discard_wake = 0;
Signature · 1 line
2.14.1.145.gb3622a4ee