f2fs: introduce gc_mode sysfs node
authorYangtao Li <frank.li@vivo.com>
Tue, 25 Oct 2022 03:32:16 +0000 (11:32 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 2 Nov 2022 00:56:04 +0000 (17:56 -0700)
Revert "f2fs: make gc_urgent and gc_segment_mode sysfs node readable".

Add a gc_mode sysfs node to show the current gc_mode as a string.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/ABI/testing/sysfs-fs-f2fs
fs/f2fs/f2fs.h
fs/f2fs/sysfs.c

index 53f70eadec96a017b0d7e1f4d2ae9e825c247e53..ef2b3572ba1818574e1b55131163a749040a9b5d 100644 (file)
@@ -640,3 +640,9 @@ Date:               July 2022
 Contact:       "Daeho Jeong" <daehojeong@google.com>
 Description:   Show the accumulated total revoked atomic write block count after boot.
                If you write "0" here, you can initialize to "0".
+
+What:          /sys/fs/f2fs/<disk>/gc_mode
+Date:          October 2022
+Contact:       "Yangtao Li" <frank.li@vivo.com>
+Description:   Show the current gc_mode as a string.
+               This is a read-only entry.
index fa8dc00dfb2b880febdfd8938439a2022dba481e..662b27c19de10bf1993a1610a0d560d17300386c 100644 (file)
@@ -1319,6 +1319,7 @@ enum {
        MAX_TIME,
 };
 
+/* Note that you need to keep synchronization with this gc_mode_names array */
 enum {
        GC_NORMAL,
        GC_IDLE_CB,
index 8095345ebdad53da329f05d453a40729e94a42d1..1fbd41c483282132e63e2ead0466c0ba7aca56d6 100644 (file)
@@ -143,6 +143,12 @@ static ssize_t pending_discard_show(struct f2fs_attr *a,
                                &SM_I(sbi)->dcc_info->discard_cmd_cnt));
 }
 
+static ssize_t gc_mode_show(struct f2fs_attr *a,
+               struct f2fs_sb_info *sbi, char *buf)
+{
+       return sysfs_emit(buf, "%s\n", gc_mode_names[sbi->gc_mode]);
+}
+
 static ssize_t features_show(struct f2fs_attr *a,
                struct f2fs_sb_info *sbi, char *buf)
 {
@@ -332,13 +338,8 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
                return sysfs_emit(buf, "%u\n", sbi->compr_new_inode);
 #endif
 
-       if (!strcmp(a->attr.name, "gc_urgent"))
-               return sysfs_emit(buf, "%s\n",
-                               gc_mode_names[sbi->gc_mode]);
-
        if (!strcmp(a->attr.name, "gc_segment_mode"))
-               return sysfs_emit(buf, "%s\n",
-                               gc_mode_names[sbi->gc_segment_mode]);
+               return sysfs_emit(buf, "%u\n", sbi->gc_segment_mode);
 
        if (!strcmp(a->attr.name, "gc_reclaimed_segments")) {
                return sysfs_emit(buf, "%u\n",
@@ -844,6 +845,7 @@ F2FS_GENERAL_RO_ATTR(encoding);
 F2FS_GENERAL_RO_ATTR(mounted_time_sec);
 F2FS_GENERAL_RO_ATTR(main_blkaddr);
 F2FS_GENERAL_RO_ATTR(pending_discard);
+F2FS_GENERAL_RO_ATTR(gc_mode);
 #ifdef CONFIG_F2FS_STAT_FS
 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count);
 F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count);
@@ -926,6 +928,7 @@ static struct attribute *f2fs_attrs[] = {
        ATTR_LIST(discard_granularity),
        ATTR_LIST(max_ordered_discard),
        ATTR_LIST(pending_discard),
+       ATTR_LIST(gc_mode),
        ATTR_LIST(ipu_policy),
        ATTR_LIST(min_ipu_util),
        ATTR_LIST(min_fsync_blocks),