From: Yangtao Li <frank.li@vivo.com>
To: gregkh@linuxfoundation.org, xiang@kernel.org,
Chao Yu <chao@kernel.org>, Yue Hu <huyue2@coolpad.com>,
Jeffle Xu <jefflexu@linux.alibaba.com>
Cc: damien.lemoal@opensource.wdc.com, frank.li@vivo.com,
jth@kernel.org, linux-erofs@lists.ozlabs.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
naohiro.aota@wdc.com, rafael@kernel.org
Subject: Re: [PATCH 2/3] erofs: convert to use kobject_is_added()
Date: Fri, 7 Apr 2023 15:23:03 +0800 [thread overview]
Message-ID: <20230407072303.34570-1-frank.li@vivo.com> (raw)
In-Reply-To: <2023040602-stack-overture-d418@gregkh>
Hi all,
> Later, I thought I could send some demo code that strips the kobject in sbi into a pointer.
I made the following modifications, not sure if I'm going the right way.
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 1db018f8c2e8..8e1799f690c0 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -165,8 +165,7 @@ struct erofs_sb_info {
u32 feature_incompat;
/* sysfs support */
- struct kobject s_kobj; /* /sys/fs/erofs/<devname> */
- struct completion s_kobj_unregister;
+ struct filesystem_kobject *f_kobj;
/* fscache support */
struct fscache_volume *volume;
diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index 435e515c0792..70e915906012 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -8,6 +8,33 @@
#include "internal.h"
+//maybe we should add following thins to include/linux/filesystem_kobject.h ?
+struct filesystem_kobject {
+ struct kobject kobject;
+ void *private;
+};
+
+void filesystem_kobject_put(struct filesystem_kobject *f_kobj)
+{
+ if (f_kobj)
+ kobject_put(&f_kobj->kobject);
+}
+
+void filesystem_kobject_set_private(struct filesystem_kobject *f_kobj, void *p)
+{
+ f_kobj->private = p;
+}
+
+void *filesystem_kobject_get_private(struct filesystem_kobject *f_kobj)
+{
+ return f_kobj->private;
+}
+
+struct kobject *filesystem_kobject_get_kobject(struct filesystem_kobject *f_kobj)
+{
+ return &f_kobj->kobject;
+}
+
enum {
attr_feature,
attr_pointer_ui,
@@ -107,8 +134,9 @@ static unsigned char *__struct_ptr(struct erofs_sb_info *sbi,
static ssize_t erofs_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
- struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
- s_kobj);
+ struct filesystem_kobject *f_kobject = container_of(kobj, struct filesystem_kobject,
+ kobject);
+ struct erofs_sb_info *sbi = filesystem_kobject_get_private(f_kobject);
struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
@@ -130,8 +158,9 @@ static ssize_t erofs_attr_show(struct kobject *kobj,
static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t len)
{
- struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
- s_kobj);
+ struct filesystem_kobject *f_kobject = container_of(kobj, struct filesystem_kobject,
+ kobject);
+ struct erofs_sb_info *sbi = filesystem_kobject_get_private(f_kobject);
struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
unsigned long t;
@@ -169,9 +198,12 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
static void erofs_sb_release(struct kobject *kobj)
{
- struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
- s_kobj);
- complete(&sbi->s_kobj_unregister);
+ struct filesystem_kobject *f_kobject = container_of(kobj, struct filesystem_kobject,
+ kobject);
+ struct erofs_sb_info *sbi = filesystem_kobject_get_private(f_kobject);
+
+ kfree(f_kobject);
+ sbi->f_kobj = NULL;
}
static const struct sysfs_ops erofs_attr_ops = {
@@ -205,6 +237,7 @@ static struct kobject erofs_feat = {
int erofs_register_sysfs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
+ struct kobject *kobj;
char *name;
char *str = NULL;
int err;
@@ -222,17 +255,24 @@ int erofs_register_sysfs(struct super_block *sb)
} else {
name = sb->s_id;
}
- sbi->s_kobj.kset = &erofs_root;
- init_completion(&sbi->s_kobj_unregister);
- err = kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL, "%s", name);
+
+ sbi->f_kobj = kzalloc(sizeof(struct filesystem_kobject), GFP_KERNEL);
+ if (!sbi->f_kobj) {
+ kfree(str);
+ return -ENOMEM;
+ }
+ filesystem_kobject_set_private(sbi->f_kobj, sbi);
+ kobj = filesystem_kobject_get_kobject(sbi->f_kobj);
+ kobj->kset = &erofs_root;
+
+ err = kobject_init_and_add(&sbi->f_kobj->kobject, &erofs_sb_ktype, NULL, "%s", name);
kfree(str);
if (err)
goto put_sb_kobj;
return 0;
put_sb_kobj:
- kobject_put(&sbi->s_kobj);
- wait_for_completion(&sbi->s_kobj_unregister);
+ filesystem_kobject_put(sbi->f_kobj);
return err;
}
@@ -240,11 +280,7 @@ void erofs_unregister_sysfs(struct super_block *sb)
{
struct erofs_sb_info *sbi = EROFS_SB(sb);
- if (sbi->s_kobj.state_in_sysfs) {
- kobject_del(&sbi->s_kobj);
- kobject_put(&sbi->s_kobj);
- wait_for_completion(&sbi->s_kobj_unregister);
- }
+ filesystem_kobject_put(sbi->f_kobj);
}
int __init erofs_init_sysfs(void)
next prev parent reply other threads:[~2023-04-07 7:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 9:30 [PATCH 1/3] kobject: introduce kobject_is_added() Yangtao Li
2023-04-06 9:30 ` [PATCH 2/3] erofs: convert to use kobject_is_added() Yangtao Li
2023-04-06 10:03 ` Greg KH
2023-04-06 10:13 ` Gao Xiang
2023-04-06 10:27 ` Greg KH
2023-04-06 10:55 ` Gao Xiang
2023-04-06 11:19 ` Greg KH
2023-04-06 12:07 ` Yangtao Li
2023-04-06 13:50 ` Yangtao Li
2023-04-06 14:31 ` Greg KH
2023-04-06 17:52 ` Yangtao Li
2023-04-07 6:09 ` Yangtao Li
2023-04-07 7:23 ` Yangtao Li [this message]
2023-04-06 9:30 ` [PATCH 3/3] zonefs: " Yangtao Li
2023-04-06 10:05 ` Greg KH
2023-04-06 10:13 ` Damien Le Moal
2023-04-06 10:26 ` Greg KH
2023-04-06 10:58 ` Damien Le Moal
2023-04-06 11:18 ` Greg KH
2023-04-06 11:23 ` Damien Le Moal
2023-04-06 9:59 ` [PATCH 1/3] kobject: introduce kobject_is_added() Greg KH
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=20230407072303.34570-1-frank.li@vivo.com \
--to=frank.li@vivo.com \
--cc=chao@kernel.org \
--cc=damien.lemoal@opensource.wdc.com \
--cc=gregkh@linuxfoundation.org \
--cc=huyue2@coolpad.com \
--cc=jefflexu@linux.alibaba.com \
--cc=jth@kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
--cc=rafael@kernel.org \
--cc=xiang@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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®