From: Daeho Jeong <daeho43@gmail.com> To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong <daehojeong@google.com> Subject: [PATCH] f2fs: add symbolic link to kobject in sysfs Date: Tue, 30 Jun 2020 09:56:25 +0900 [thread overview] Message-ID: <20200630005625.2405062-1-daeho43@gmail.com> (raw) From: Daeho Jeong <daehojeong@google.com> Added a symbolic link to directory of sysfs. It will create a symbolic link such as "mount_0" and "mount_1" to each f2fs mount in the order of mounting filesystem. It will provide easy access to sysfs node even if not knowing the specific device node name like sda19 and dm-3. Signed-off-by: Daeho Jeong <daehojeong@google.com> --- fs/f2fs/f2fs.h | 4 ++++ fs/f2fs/sysfs.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 4b28fd42fdbc..7d6c5f8ce16b 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1419,6 +1419,8 @@ struct decompress_io_ctx { #define MAX_COMPRESS_LOG_SIZE 8 #define MAX_COMPRESS_WINDOW_SIZE ((PAGE_SIZE) << MAX_COMPRESS_LOG_SIZE) +#define MOUNT_NAME_SIZE 20 + struct f2fs_sb_info { struct super_block *sb; /* pointer to VFS super block */ struct proc_dir_entry *s_proc; /* proc entry */ @@ -1599,6 +1601,8 @@ struct f2fs_sb_info { /* For sysfs suppport */ struct kobject s_kobj; struct completion s_kobj_unregister; + int s_mount_id; + char s_mount_name[MOUNT_NAME_SIZE]; /* For shrinker support */ struct list_head s_list; diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index ab40e1f89f23..64bbe0b3b830 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -18,6 +18,7 @@ #include <trace/events/f2fs.h> static struct proc_dir_entry *f2fs_proc_root; +static struct ida f2fs_mount_ida; /* Sysfs support for f2fs */ enum { @@ -906,6 +907,9 @@ int __init f2fs_init_sysfs(void) } else { f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); } + + ida_init(&f2fs_mount_ida); + return ret; } @@ -915,6 +919,7 @@ void f2fs_exit_sysfs(void) kset_unregister(&f2fs_kset); remove_proc_entry("fs/f2fs", NULL); f2fs_proc_root = NULL; + ida_destroy(&f2fs_mount_ida); } int f2fs_register_sysfs(struct f2fs_sb_info *sbi) @@ -926,12 +931,22 @@ 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 err1; + + sbi->s_mount_id = ida_simple_get(&f2fs_mount_ida, 0, 0, GFP_KERNEL); + if (sbi->s_mount_id < 0) { + err = sbi->s_mount_id; + goto err1; } + snprintf(sbi->s_mount_name, MOUNT_NAME_SIZE, "mount_%d", + sbi->s_mount_id); + err = sysfs_create_link(&f2fs_kset.kobj, &sbi->s_kobj, + sbi->s_mount_name); + if (err) + goto err2; + if (f2fs_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); @@ -946,6 +961,12 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) victim_bits_seq_show, sb); } return 0; +err2: + ida_simple_remove(&f2fs_mount_ida, sbi->s_mount_id); +err1: + kobject_put(&sbi->s_kobj); + wait_for_completion(&sbi->s_kobj_unregister); + return err; } void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) @@ -957,6 +978,8 @@ 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); } + sysfs_remove_link(&f2fs_kset.kobj, sbi->s_mount_name); + ida_simple_remove(&f2fs_mount_ida, sbi->s_mount_id); kobject_del(&sbi->s_kobj); kobject_put(&sbi->s_kobj); } -- 2.27.0.212.ge8ba1cc988-goog
WARNING: multiple messages have this Message-ID (diff)
From: Daeho Jeong <daeho43@gmail.com> To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong <daehojeong@google.com> Subject: [f2fs-dev] [PATCH] f2fs: add symbolic link to kobject in sysfs Date: Tue, 30 Jun 2020 09:56:25 +0900 [thread overview] Message-ID: <20200630005625.2405062-1-daeho43@gmail.com> (raw) From: Daeho Jeong <daehojeong@google.com> Added a symbolic link to directory of sysfs. It will create a symbolic link such as "mount_0" and "mount_1" to each f2fs mount in the order of mounting filesystem. It will provide easy access to sysfs node even if not knowing the specific device node name like sda19 and dm-3. Signed-off-by: Daeho Jeong <daehojeong@google.com> --- fs/f2fs/f2fs.h | 4 ++++ fs/f2fs/sysfs.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 4b28fd42fdbc..7d6c5f8ce16b 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1419,6 +1419,8 @@ struct decompress_io_ctx { #define MAX_COMPRESS_LOG_SIZE 8 #define MAX_COMPRESS_WINDOW_SIZE ((PAGE_SIZE) << MAX_COMPRESS_LOG_SIZE) +#define MOUNT_NAME_SIZE 20 + struct f2fs_sb_info { struct super_block *sb; /* pointer to VFS super block */ struct proc_dir_entry *s_proc; /* proc entry */ @@ -1599,6 +1601,8 @@ struct f2fs_sb_info { /* For sysfs suppport */ struct kobject s_kobj; struct completion s_kobj_unregister; + int s_mount_id; + char s_mount_name[MOUNT_NAME_SIZE]; /* For shrinker support */ struct list_head s_list; diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index ab40e1f89f23..64bbe0b3b830 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -18,6 +18,7 @@ #include <trace/events/f2fs.h> static struct proc_dir_entry *f2fs_proc_root; +static struct ida f2fs_mount_ida; /* Sysfs support for f2fs */ enum { @@ -906,6 +907,9 @@ int __init f2fs_init_sysfs(void) } else { f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); } + + ida_init(&f2fs_mount_ida); + return ret; } @@ -915,6 +919,7 @@ void f2fs_exit_sysfs(void) kset_unregister(&f2fs_kset); remove_proc_entry("fs/f2fs", NULL); f2fs_proc_root = NULL; + ida_destroy(&f2fs_mount_ida); } int f2fs_register_sysfs(struct f2fs_sb_info *sbi) @@ -926,12 +931,22 @@ 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 err1; + + sbi->s_mount_id = ida_simple_get(&f2fs_mount_ida, 0, 0, GFP_KERNEL); + if (sbi->s_mount_id < 0) { + err = sbi->s_mount_id; + goto err1; } + snprintf(sbi->s_mount_name, MOUNT_NAME_SIZE, "mount_%d", + sbi->s_mount_id); + err = sysfs_create_link(&f2fs_kset.kobj, &sbi->s_kobj, + sbi->s_mount_name); + if (err) + goto err2; + if (f2fs_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); @@ -946,6 +961,12 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) victim_bits_seq_show, sb); } return 0; +err2: + ida_simple_remove(&f2fs_mount_ida, sbi->s_mount_id); +err1: + kobject_put(&sbi->s_kobj); + wait_for_completion(&sbi->s_kobj_unregister); + return err; } void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) @@ -957,6 +978,8 @@ 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); } + sysfs_remove_link(&f2fs_kset.kobj, sbi->s_mount_name); + ida_simple_remove(&f2fs_mount_ida, sbi->s_mount_id); kobject_del(&sbi->s_kobj); kobject_put(&sbi->s_kobj); } -- 2.27.0.212.ge8ba1cc988-goog _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2020-06-30 0:56 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-30 0:56 Daeho Jeong [this message] 2020-06-30 0:56 ` [f2fs-dev] [PATCH] f2fs: add symbolic link to kobject in sysfs Daeho Jeong 2020-07-01 6:36 ` Chao Yu 2020-07-01 6:36 ` Chao Yu 2020-07-01 7:04 ` Daeho Jeong 2020-07-01 7:04 ` Daeho Jeong 2020-07-01 7:15 ` Chao Yu 2020-07-01 7:15 ` Chao Yu 2020-07-01 12:12 ` Daeho Jeong 2020-07-01 12:12 ` Daeho Jeong 2020-07-03 2:02 ` Chao Yu 2020-07-03 2:02 ` Chao Yu 2020-07-03 2:46 ` Daeho Jeong 2020-07-03 2:46 ` Daeho Jeong
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200630005625.2405062-1-daeho43@gmail.com \ --to=daeho43@gmail.com \ --cc=daehojeong@google.com \ --cc=kernel-team@android.com \ --cc=linux-f2fs-devel@lists.sourceforge.net \ --cc=linux-kernel@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.