f2fs: introduce a new per-sb directory in sysfs
PATCH 1/1 f2fs: introduce a new per-sb directory in sysfs
Add a new directory 'stat' in path of /sys/fs/f2fs/<devname>/, later we can add new readonly stat sysfs file into this directory, it will make <devname> directory less mess.
--- fs/f2fs/f2fs.h | 5 +++- fs/f2fs/sysfs.c | 69 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +4 -1
@@ -1510,9 +1510,12 @@ struct f2fs_sb_info {unsigned int node_io_flag;/* For sysfs suppport */ -struct kobject s_kobj; +struct kobject s_kobj;/* /sys/fs/f2fs/<devname> */ struct completion s_kobj_unregister; +struct kobject s_stat_kobj;/* /sys/fs/f2fs/<devname>/stat */ +struct completion s_stat_kobj_unregister; +/* For shrinker support */ struct list_head s_list;int s_ndevs;/* number of devices */
fs/f2fs/sysfs.c +64 -5
99 lines not on this page · raw message
Signature · 1 line
2.26.2
Jaegeuk,
Can you comment on this patch?
Quoted 127 lines · Chao Yu
Add a new directory 'stat' in path of /sys/fs/f2fs/<devname>/, later we can add new readonly stat sysfs file into this directory, it will make <devname> directory less mess.
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/f2fs.h | 5 +++- fs/f2fs/sysfs.c | 69 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-)fs/f2fs/f2fs.h +4
-1@@ -1510,9 +1510,12 @@ struct f2fs_sb_info {unsigned int node_io_flag;/* For sysfs suppport */ -struct kobject s_kobj; +struct kobject s_kobj;/* /sys/fs/f2fs/<devname> */ struct completion s_kobj_unregister; +struct kobject s_stat_kobj;/* /sys/fs/f2fs/<devname>/stat */ +struct completion s_stat_kobj_unregister; +/* For shrinker support */ struct list_head s_list;int s_ndevs;/* number of devices */ fs/f2fs/sysfs.c +59
-5@@ -708,6 +708,11 @@ static struct attribute *f2fs_feat_attrs[] = { };ATTRIBUTE_GROUPS (f2fs_feat); +static struct attribute *f2fs_stat_attrs[] = { +NULL , +}; +ATTRIBUTE_GROUPS (f2fs_stat); +static const struct sysfs_ops f2fs_attr_ops = { .show = f2fs_attr_show, .store = f2fs_attr_store,@@ -736,6 +741,44 @@ static struct kobject f2fs_feat = { .kset = &f2fs_kset, }; +static ssize_t f2fs_stat_attr_show (struct kobject *kobj, +struct attribute *attr,char *buf) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); + +return a->show ? a->show (a, sbi, buf) :0 ; +} + +static ssize_t f2fs_stat_attr_store (struct kobject *kobj,struct attribute *attr, +const char *buf,size_t len) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); + +return a->store ? a->store (a, sbi, buf, len) :0 ; +} + +static void f2fs_stat_kobj_release (struct kobject *kobj) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); +complete (&sbi->s_stat_kobj_unregister); +} + +static const struct sysfs_ops f2fs_stat_attr_ops = { + .show = f2fs_stat_attr_show, + .store = f2fs_stat_attr_store, +}; + +static struct kobj_type f2fs_stat_ktype = { + .default_groups = f2fs_stat_groups, + .sysfs_ops = &f2fs_stat_attr_ops, + .release = f2fs_stat_kobj_release, +}; +static int __maybe_unused segment_info_seq_show (struct seq_file *seq,void *offset) {@@ -942,11 +985,15 @@ 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) { -kobject_put (&sbi->s_kobj); -wait_for_completion (&sbi->s_kobj_unregister); -return err; - } +if (err) + goto put_sb_kobj; + + sbi->s_stat_kobj.kset = &f2fs_kset; +init_completion (&sbi->s_stat_kobj_unregister); + err =kobject_init_and_add (&sbi->s_stat_kobj, &f2fs_stat_ktype, + &sbi->s_kobj,"stat" ); +if (err) + goto put_stat_kobj;if (f2fs_proc_root) sbi->s_proc =proc_mkdir (sb->s_id, f2fs_proc_root);@@ -962,6 +1009,13 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) victim_bits_seq_show, sb); }return 0 ; +put_stat_kobj: +kobject_put (&sbi->s_stat_kobj); +wait_for_completion (&sbi->s_stat_kobj_unregister); +put_sb_kobj: +kobject_put (&sbi->s_kobj); +wait_for_completion (&sbi->s_kobj_unregister); +return err; }void f2fs_unregister_sysfs (struct f2fs_sb_info *sbi)@@ -973,6 +1027,11 @@ void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)remove_proc_entry ("victim_bits" , sbi->s_proc);
fs/f2fs/sysfs.c void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) · line 1037
Quoted 10 lines
fs/f2fs/sysfs.c +5
-0remove_proc_entry (sbi->sb->s_id, f2fs_proc_root); } + +kobject_del (&sbi->s_stat_kobj); +kobject_put (&sbi->s_stat_kobj); +wait_for_completion (&sbi->s_stat_kobj_unregister); +kobject_del (&sbi->s_kobj);kobject_put (&sbi->s_kobj);wait_for_completion (&sbi->s_kobj_unregister);
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerQuoted 3 lines · Chao Yu
Jaegeuk,
Can you comment on this patch?
Waiting for use-case? :)
Quoted 125 lines · Chao Yu
Quoted 123 lines
Add a new directory 'stat' in path of /sys/fs/f2fs/<devname>/, later we can add new readonly stat sysfs file into this directory, it will make <devname> directory less mess.
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/f2fs.h | 5 +++- fs/f2fs/sysfs.c | 69 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-)fs/f2fs/f2fs.h +4
-1@@ -1510,9 +1510,12 @@ struct f2fs_sb_info {unsigned int node_io_flag;/* For sysfs suppport */ -struct kobject s_kobj; +struct kobject s_kobj;/* /sys/fs/f2fs/<devname> */ struct completion s_kobj_unregister; +struct kobject s_stat_kobj;/* /sys/fs/f2fs/<devname>/stat */ +struct completion s_stat_kobj_unregister; +/* For shrinker support */ struct list_head s_list;int s_ndevs;/* number of devices */ fs/f2fs/sysfs.c +60
-5@@ -708,6 +708,11 @@ static struct attribute *f2fs_feat_attrs[] = { };ATTRIBUTE_GROUPS (f2fs_feat); +static struct attribute *f2fs_stat_attrs[] = { +NULL , +}; +ATTRIBUTE_GROUPS (f2fs_stat); +static const struct sysfs_ops f2fs_attr_ops = { .show = f2fs_attr_show, .store = f2fs_attr_store,@@ -736,6 +741,44 @@ static struct kobject f2fs_feat = { .kset = &f2fs_kset, }; +static ssize_t f2fs_stat_attr_show (struct kobject *kobj, +struct attribute *attr,char *buf) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); + +return a->show ? a->show (a, sbi, buf) :0 ; +} + +static ssize_t f2fs_stat_attr_store (struct kobject *kobj,struct attribute *attr, +const char *buf,size_t len) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); + +return a->store ? a->store (a, sbi, buf, len) :0 ; +} + +static void f2fs_stat_kobj_release (struct kobject *kobj) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); +complete (&sbi->s_stat_kobj_unregister); +} + +static const struct sysfs_ops f2fs_stat_attr_ops = { + .show = f2fs_stat_attr_show, + .store = f2fs_stat_attr_store, +}; + +static struct kobj_type f2fs_stat_ktype = { + .default_groups = f2fs_stat_groups, + .sysfs_ops = &f2fs_stat_attr_ops, + .release = f2fs_stat_kobj_release, +}; +static int __maybe_unused segment_info_seq_show (struct seq_file *seq,void *offset) {@@ -942,11 +985,15 @@ 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) { -kobject_put (&sbi->s_kobj); -wait_for_completion (&sbi->s_kobj_unregister); -return err; - } +if (err) + goto put_sb_kobj; + + sbi->s_stat_kobj.kset = &f2fs_kset; +init_completion (&sbi->s_stat_kobj_unregister); + err =kobject_init_and_add (&sbi->s_stat_kobj, &f2fs_stat_ktype, + &sbi->s_kobj,"stat" ); +if (err) + goto put_stat_kobj;if (f2fs_proc_root) sbi->s_proc =proc_mkdir (sb->s_id, f2fs_proc_root);@@ -962,6 +1009,13 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) victim_bits_seq_show, sb); }return 0 ; +put_stat_kobj: +kobject_put (&sbi->s_stat_kobj); +wait_for_completion (&sbi->s_stat_kobj_unregister); +put_sb_kobj: +kobject_put (&sbi->s_kobj); +wait_for_completion (&sbi->s_kobj_unregister); +return err; }void f2fs_unregister_sysfs (struct f2fs_sb_info *sbi)@@ -973,6 +1027,11 @@ void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi)remove_proc_entry ("victim_bits" , sbi->s_proc);remove_proc_entry (sbi->sb->s_id, f2fs_proc_root); } +
Quoted 8 lines
fs/f2fs/sysfs.c void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) · line 1037
Quoted 8 lines
fs/f2fs/sysfs.c +4
-0+kobject_del (&sbi->s_stat_kobj); +kobject_put (&sbi->s_stat_kobj); +wait_for_completion (&sbi->s_stat_kobj_unregister); +kobject_del (&sbi->s_kobj);kobject_put (&sbi->s_kobj);wait_for_completion (&sbi->s_kobj_unregister);
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerQuoted 6 lines · Jaegeuk Kim
Quoted 3 lines · Chao Yu
Jaegeuk,
Can you comment on this patch?
Waiting for use-case? :)
How do you think of duplicating below stats into /sys/fs/f2fs/<devname>/stat/
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); F2FS_GENERAL_RO_ATTR(mounted_time_sec); F2FS_GENERAL_RO_ATTR(main_blkaddr);
#ifdef CONFIG_F2FS_STAT_FSF2FS_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
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerQuoted 9 lines · Chao Yu
Quoted 6 lines · Jaegeuk Kim
Quoted 3 lines · Chao Yu
Jaegeuk,
Can you comment on this patch?
Waiting for use-case? :)
How do you think of duplicating below stats into /sys/fs/f2fs/<devname>/stat/
We can't move them to /stat, since it requires lots of mess. Let's think about new ones only.
Quoted 21 lines
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);F2FS_GENERAL_RO_ATTR(mounted_time_sec);F2FS_GENERAL_RO_ATTR(main_blkaddr);
#ifdefCONFIG_F2FS_STAT_FSF2FS_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);
#endifThanks,