]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - fs/f2fs/sysfs.c
Merge tag 'clk-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux
[linux.git] / fs / f2fs / sysfs.c
index 70945ceb9c0cadd7b166e5b53a3c3208c5da7655..91d649790b1bcd507d432fbbac0b7f9727dc59fd 100644 (file)
@@ -25,6 +25,9 @@ enum {
        DCC_INFO,       /* struct discard_cmd_control */
        NM_INFO,        /* struct f2fs_nm_info */
        F2FS_SBI,       /* struct f2fs_sb_info */
+#ifdef CONFIG_F2FS_STAT_FS
+       STAT_INFO,      /* struct f2fs_stat_info */
+#endif
 #ifdef CONFIG_F2FS_FAULT_INJECTION
        FAULT_INFO_RATE,        /* struct f2fs_fault_info */
        FAULT_INFO_TYPE,        /* struct f2fs_fault_info */
@@ -42,6 +45,9 @@ struct f2fs_attr {
        int id;
 };
 
+static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
+                            struct f2fs_sb_info *sbi, char *buf);
+
 static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
 {
        if (struct_type == GC_THREAD)
@@ -58,6 +64,10 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
        else if (struct_type == FAULT_INFO_RATE ||
                                        struct_type == FAULT_INFO_TYPE)
                return (unsigned char *)&F2FS_OPTION(sbi).fault_info;
+#endif
+#ifdef CONFIG_F2FS_STAT_FS
+       else if (struct_type == STAT_INFO)
+               return (unsigned char *)F2FS_STAT(sbi);
 #endif
        return NULL;
 }
@@ -65,35 +75,15 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
 static ssize_t dirty_segments_show(struct f2fs_attr *a,
                struct f2fs_sb_info *sbi, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%llu\n",
-               (unsigned long long)(dirty_segments(sbi)));
+       return sprintf(buf, "%llu\n",
+                       (unsigned long long)(dirty_segments(sbi)));
 }
 
-static ssize_t unusable_show(struct f2fs_attr *a,
+static ssize_t free_segments_show(struct f2fs_attr *a,
                struct f2fs_sb_info *sbi, char *buf)
 {
-       block_t unusable;
-
-       if (test_opt(sbi, DISABLE_CHECKPOINT))
-               unusable = sbi->unusable_block_count;
-       else
-               unusable = f2fs_get_unusable_blocks(sbi);
-       return snprintf(buf, PAGE_SIZE, "%llu\n",
-               (unsigned long long)unusable);
-}
-
-static ssize_t encoding_show(struct f2fs_attr *a,
-               struct f2fs_sb_info *sbi, char *buf)
-{
-#ifdef CONFIG_UNICODE
-       if (f2fs_sb_has_casefold(sbi))
-               return snprintf(buf, PAGE_SIZE, "%s (%d.%d.%d)\n",
-                       sbi->s_encoding->charset,
-                       (sbi->s_encoding->version >> 16) & 0xff,
-                       (sbi->s_encoding->version >> 8) & 0xff,
-                       sbi->s_encoding->version & 0xff);
-#endif
-       return snprintf(buf, PAGE_SIZE, "(none)");
+       return sprintf(buf, "%llu\n",
+                       (unsigned long long)(free_segments(sbi)));
 }
 
 static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
@@ -102,10 +92,10 @@ static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
        struct super_block *sb = sbi->sb;
 
        if (!sb->s_bdev->bd_part)
-               return snprintf(buf, PAGE_SIZE, "0\n");
+               return sprintf(buf, "0\n");
 
-       return snprintf(buf, PAGE_SIZE, "%llu\n",
-               (unsigned long long)(sbi->kbytes_written +
+       return sprintf(buf, "%llu\n",
+                       (unsigned long long)(sbi->kbytes_written +
                        BD_PART_WRITTEN(sbi)));
 }
 
@@ -116,7 +106,7 @@ static ssize_t features_show(struct f2fs_attr *a,
        int len = 0;
 
        if (!sb->s_bdev->bd_part)
-               return snprintf(buf, PAGE_SIZE, "0\n");
+               return sprintf(buf, "0\n");
 
        if (f2fs_sb_has_encrypt(sbi))
                len += snprintf(buf, PAGE_SIZE - len, "%s",
@@ -154,6 +144,9 @@ static ssize_t features_show(struct f2fs_attr *a,
        if (f2fs_sb_has_casefold(sbi))
                len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
                                len ? ", " : "", "casefold");
+       if (f2fs_sb_has_compression(sbi))
+               len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
+                               len ? ", " : "", "compression");
        len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
                                len ? ", " : "", "pin_file");
        len += snprintf(buf + len, PAGE_SIZE - len, "\n");
@@ -163,9 +156,66 @@ static ssize_t features_show(struct f2fs_attr *a,
 static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
                                        struct f2fs_sb_info *sbi, char *buf)
 {
-       return snprintf(buf, PAGE_SIZE, "%u\n", sbi->current_reserved_blocks);
+       return sprintf(buf, "%u\n", sbi->current_reserved_blocks);
+}
+
+static ssize_t unusable_show(struct f2fs_attr *a,
+               struct f2fs_sb_info *sbi, char *buf)
+{
+       block_t unusable;
+
+       if (test_opt(sbi, DISABLE_CHECKPOINT))
+               unusable = sbi->unusable_block_count;
+       else
+               unusable = f2fs_get_unusable_blocks(sbi);
+       return sprintf(buf, "%llu\n", (unsigned long long)unusable);
+}
+
+static ssize_t encoding_show(struct f2fs_attr *a,
+               struct f2fs_sb_info *sbi, char *buf)
+{
+#ifdef CONFIG_UNICODE
+       if (f2fs_sb_has_casefold(sbi))
+               return snprintf(buf, PAGE_SIZE, "%s (%d.%d.%d)\n",
+                       sbi->s_encoding->charset,
+                       (sbi->s_encoding->version >> 16) & 0xff,
+                       (sbi->s_encoding->version >> 8) & 0xff,
+                       sbi->s_encoding->version & 0xff);
+#endif
+       return sprintf(buf, "(none)");
 }
 
+#ifdef CONFIG_F2FS_STAT_FS
+static ssize_t moved_blocks_foreground_show(struct f2fs_attr *a,
+                               struct f2fs_sb_info *sbi, char *buf)
+{
+       struct f2fs_stat_info *si = F2FS_STAT(sbi);
+
+       return sprintf(buf, "%llu\n",
+               (unsigned long long)(si->tot_blks -
+                       (si->bg_data_blks + si->bg_node_blks)));
+}
+
+static ssize_t moved_blocks_background_show(struct f2fs_attr *a,
+                               struct f2fs_sb_info *sbi, char *buf)
+{
+       struct f2fs_stat_info *si = F2FS_STAT(sbi);
+
+       return sprintf(buf, "%llu\n",
+               (unsigned long long)(si->bg_data_blks + si->bg_node_blks));
+}
+
+static ssize_t avg_vblocks_show(struct f2fs_attr *a,
+               struct f2fs_sb_info *sbi, char *buf)
+{
+       struct f2fs_stat_info *si = F2FS_STAT(sbi);
+
+       si->dirty_count = dirty_segments(sbi);
+       f2fs_update_sit_info(sbi);
+       return sprintf(buf, "%llu\n", (unsigned long long)(si->avg_vblocks));
+}
+#endif
+
 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
                        struct f2fs_sb_info *sbi, char *buf)
 {
@@ -199,7 +249,7 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 
        ui = (unsigned int *)(ptr + a->offset);
 
-       return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
+       return sprintf(buf, "%u\n", *ui);
 }
 
 static ssize_t __sbi_store(struct f2fs_attr *a,
@@ -389,6 +439,7 @@ enum feat_id {
        FEAT_VERITY,
        FEAT_SB_CHECKSUM,
        FEAT_CASEFOLD,
+       FEAT_COMPRESSION,
 };
 
 static ssize_t f2fs_feature_show(struct f2fs_attr *a,
@@ -408,7 +459,8 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,
        case FEAT_VERITY:
        case FEAT_SB_CHECKSUM:
        case FEAT_CASEFOLD:
-               return snprintf(buf, PAGE_SIZE, "supported\n");
+       case FEAT_COMPRESSION:
+               return sprintf(buf, "supported\n");
        }
        return 0;
 }
@@ -437,6 +489,14 @@ static struct f2fs_attr f2fs_attr_##_name = {                      \
        .id     = _id,                                          \
 }
 
+#define F2FS_STAT_ATTR(_struct_type, _struct_name, _name, _elname)     \
+static struct f2fs_attr f2fs_attr_##_name = {                  \
+       .attr = {.name = __stringify(_name), .mode = 0444 },    \
+       .show = f2fs_sbi_show,                                  \
+       .struct_type = _struct_type,                            \
+       .offset = offsetof(struct _struct_name, _elname),       \
+}
+
 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_urgent_sleep_time,
                                                        urgent_sleep_time);
 F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
@@ -478,11 +538,21 @@ F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
 #endif
 F2FS_GENERAL_RO_ATTR(dirty_segments);
+F2FS_GENERAL_RO_ATTR(free_segments);
 F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
 F2FS_GENERAL_RO_ATTR(features);
 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
 F2FS_GENERAL_RO_ATTR(unusable);
 F2FS_GENERAL_RO_ATTR(encoding);
+#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);
+F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_foreground_calls, call_count);
+F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, gc_background_calls, bg_gc);
+F2FS_GENERAL_RO_ATTR(moved_blocks_background);
+F2FS_GENERAL_RO_ATTR(moved_blocks_foreground);
+F2FS_GENERAL_RO_ATTR(avg_vblocks);
+#endif
 
 #ifdef CONFIG_FS_ENCRYPTION
 F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
@@ -503,6 +573,7 @@ F2FS_FEATURE_RO_ATTR(verity, FEAT_VERITY);
 #endif
 F2FS_FEATURE_RO_ATTR(sb_checksum, FEAT_SB_CHECKSUM);
 F2FS_FEATURE_RO_ATTR(casefold, FEAT_CASEFOLD);
+F2FS_FEATURE_RO_ATTR(compression, FEAT_COMPRESSION);
 
 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
 static struct attribute *f2fs_attrs[] = {
@@ -543,12 +614,22 @@ static struct attribute *f2fs_attrs[] = {
        ATTR_LIST(inject_type),
 #endif
        ATTR_LIST(dirty_segments),
+       ATTR_LIST(free_segments),
        ATTR_LIST(unusable),
        ATTR_LIST(lifetime_write_kbytes),
        ATTR_LIST(features),
        ATTR_LIST(reserved_blocks),
        ATTR_LIST(current_reserved_blocks),
        ATTR_LIST(encoding),
+#ifdef CONFIG_F2FS_STAT_FS
+       ATTR_LIST(cp_foreground_calls),
+       ATTR_LIST(cp_background_calls),
+       ATTR_LIST(gc_foreground_calls),
+       ATTR_LIST(gc_background_calls),
+       ATTR_LIST(moved_blocks_foreground),
+       ATTR_LIST(moved_blocks_background),
+       ATTR_LIST(avg_vblocks),
+#endif
        NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
@@ -573,6 +654,7 @@ static struct attribute *f2fs_feat_attrs[] = {
 #endif
        ATTR_LIST(sb_checksum),
        ATTR_LIST(casefold),
+       ATTR_LIST(compression),
        NULL,
 };
 ATTRIBUTE_GROUPS(f2fs_feat);
@@ -733,10 +815,12 @@ int __init f2fs_init_sysfs(void)
 
        ret = kobject_init_and_add(&f2fs_feat, &f2fs_feat_ktype,
                                   NULL, "features");
-       if (ret)
+       if (ret) {
+               kobject_put(&f2fs_feat);
                kset_unregister(&f2fs_kset);
-       else
+       } else {
                f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
+       }
        return ret;
 }
 
@@ -757,8 +841,11 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
        init_completion(&sbi->s_kobj_unregister);
        err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL,
                                "%s", sb->s_id);
-       if (err)
+       if (err) {
+               kobject_put(&sbi->s_kobj);
+               wait_for_completion(&sbi->s_kobj_unregister);
                return err;
+       }
 
        if (f2fs_proc_root)
                sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
@@ -786,4 +873,5 @@ void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)
                remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
        }
        kobject_del(&sbi->s_kobj);
+       kobject_put(&sbi->s_kobj);
 }