From mboxrd@z Thu Jan 1 00:00:00 1970 From: Goldwyn Rodrigues Date: Wed, 11 May 2016 07:04:29 -0500 Subject: [Ocfs2-devel] [PATCH 1/5] ocfs2: Provisions for sysfs entries In-Reply-To: <57330F0C.8080102@huawei.com> References: <1462902759-27084-1-git-send-email-rgoldwyn@suse.de> <1462902759-27084-2-git-send-email-rgoldwyn@suse.de> <57330F0C.8080102@huawei.com> Message-ID: <57331FCD.3030206@suse.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ocfs2-devel@oss.oracle.com On 05/11/2016 05:53 AM, Joseph Qi wrote: > On 2016/5/11 1:52, Goldwyn Rodrigues wrote: >> From: Goldwyn Rodrigues >> >> This adds /sys/fs/ocfs2/ to the sys filesystem. This >> is done by adding the kobj into the ocfs2_super. All other >> files are added in this directory. >> >> Introduce ocfs2_sb_attr which encompasses the store() and show() functions. >> Move all the important data structures with respect to filechecks >> to ocfs2_super. >> >> More superblock information should move in here. >> >> Signed-off-by: Goldwyn Rodrigues >> --- >> fs/ocfs2/Makefile | 3 +- >> fs/ocfs2/ocfs2.h | 4 +++ >> fs/ocfs2/super.c | 7 +++-- >> fs/ocfs2/sysfs.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> fs/ocfs2/sysfs.h | 9 ++++++ >> 5 files changed, 111 insertions(+), 4 deletions(-) >> create mode 100644 fs/ocfs2/sysfs.c >> create mode 100644 fs/ocfs2/sysfs.h >> >> diff --git a/fs/ocfs2/Makefile b/fs/ocfs2/Makefile >> index e27e652..716ed45 100644 >> --- a/fs/ocfs2/Makefile >> +++ b/fs/ocfs2/Makefile >> @@ -41,7 +41,8 @@ ocfs2-objs := \ >> quota_local.o \ >> quota_global.o \ >> xattr.o \ >> - acl.o \ >> + acl.o \ >> + sysfs.o \ >> filecheck.o >> >> ocfs2_stackglue-objs := stackglue.o >> diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h >> index e63af7d..8e66cdf 100644 >> --- a/fs/ocfs2/ocfs2.h >> +++ b/fs/ocfs2/ocfs2.h >> @@ -37,6 +37,7 @@ >> #include >> #include >> #include >> +#include >> >> /* For union ocfs2_dlm_lksb */ >> #include "stackglue.h" >> @@ -472,6 +473,9 @@ struct ocfs2_super >> * workqueue and schedule on our own. >> */ >> struct workqueue_struct *ocfs2_wq; >> + >> + struct kobject kobj; >> + struct completion kobj_unregister; >> }; >> >> #define OCFS2_SB(sb) ((struct ocfs2_super *)(sb)->s_fs_info) >> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c >> index d7cae33..96b7a9f 100644 >> --- a/fs/ocfs2/super.c >> +++ b/fs/ocfs2/super.c >> @@ -75,6 +75,7 @@ >> >> #include "buffer_head_io.h" >> #include "filecheck.h" >> +#include "sysfs.h" >> >> static struct kmem_cache *ocfs2_inode_cachep; >> struct kmem_cache *ocfs2_dquot_cachep; >> @@ -1200,8 +1201,8 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) >> /* Start this when the mount is almost sure of being successful */ >> ocfs2_orphan_scan_start(osb); >> >> - /* Create filecheck sysfile /sys/fs/ocfs2//filecheck */ >> - ocfs2_filecheck_create_sysfs(sb); >> + /* Create sysfs entries */ >> + ocfs2_sysfs_sb_init(sb); >> >> return status; >> >> @@ -1651,9 +1652,9 @@ static void ocfs2_put_super(struct super_block *sb) >> { >> trace_ocfs2_put_super(sb); >> >> + ocfs2_sysfs_sb_exit(sb); >> ocfs2_sync_blockdev(sb); >> ocfs2_dismount_volume(sb, 0); >> - ocfs2_filecheck_remove_sysfs(sb); >> } >> >> static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf) >> diff --git a/fs/ocfs2/sysfs.c b/fs/ocfs2/sysfs.c >> new file mode 100644 >> index 0000000..f0b7435 >> --- /dev/null >> +++ b/fs/ocfs2/sysfs.c >> @@ -0,0 +1,92 @@ >> +#include "ocfs2.h" >> +#include "sysfs.h" >> + >> +struct ocfs2_sb_attr { >> + struct attribute attr; >> + ssize_t (*show)(struct ocfs2_super *, struct ocfs2_sb_attr *, >> + char *buf); >> + ssize_t (*store)(struct ocfs2_super *, struct ocfs2_sb_attr *, >> + const char *buf, size_t count); >> +}; >> + >> +#define OCFS2_SB_ATTR(_name, _mode) \ >> +struct ocfs2_sb_attr sb_attr_##_name = __ATTR(name, _mode, _show, _store) >> + >> +#define OCFS2_SB_ATTR_RO(_name) \ >> +struct ocfs2_sb_attr sb_attr_##_name = __ATTR_RO(_name) >> + >> +static ssize_t ocfs2_sb_attr_show(struct kobject *kobj, >> + struct attribute *attr, char *buf) >> +{ >> + struct ocfs2_sb_attr *oa = >> + container_of(attr, struct ocfs2_sb_attr, attr); >> + struct ocfs2_super *osb = container_of(kobj, struct ocfs2_super, kobj); >> + if (!oa->show) >> + return -EIO; >> + >> + return oa->show(osb, oa, buf); >> +} >> + >> +static ssize_t ocfs2_sb_attr_store(struct kobject *kobj, >> + struct attribute *attr, const char *buf, size_t count) >> +{ >> + struct ocfs2_sb_attr *oa = >> + container_of(attr, struct ocfs2_sb_attr, attr); >> + struct ocfs2_super *osb = container_of(kobj, struct ocfs2_super, kobj); >> + if (!oa->show) > Should it be "!oa->store" here? > Yes, you are right. Thanks for pointing it out. I will fix this. -- Goldwyn