From: Daniel Phillips <phillips@istop.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>,
Joel Becker <Joel.Becker@oracle.com>, Greg KH <greg@kroah.com>
Subject: [RFC][PATCH 4 of 4] Configfs is really sysfs
Date: Wed, 31 Aug 2005 09:03:09 +1000 [thread overview]
Message-ID: <200508310903.10197.phillips@istop.com> (raw)
In-Reply-To: <200508310859.55746.phillips@istop.com>
A kernel code example that uses the modified configfs to define a simple
configuration interface. Note the use of kobjects and ksets instead of
config_items and config_groups.
Also notice how much code is required to get a simple value from
userspace to kernel space. This is a big problem that needs to be
addressed soon, before we end up with tens or hundreds of thousands of
lines of code code bloat just to get and set variables from user space.
Regards,
Daniel
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/configfs.h>
struct ddbond_info {
struct kobject item;
int controlsock;
};
static inline struct ddbond_info *to_ddbond_info(struct kobject *item)
{
return container_of(item, struct ddbond_info, item);
}
static ssize_t ddbond_info_attr_show(struct kobject *item,
struct attribute *attr, char *page)
{
ssize_t count;
struct ddbond_info *ddbond_info = to_ddbond_info(item);
count = sprintf(page, "%d\n", ddbond_info->controlsock);
return count;
}
static ssize_t ddbond_info_attr_store(struct kobject *item,
struct attribute *attr, const char *page, size_t count)
{
struct ddbond_info *ddbond_info = to_ddbond_info(item);
unsigned long tmp;
char *p = (char *)page;
tmp = simple_strtoul(p, &p, 10);
if (!p || (*p && (*p != '\n')))
return -EINVAL;
if (tmp > INT_MAX)
return -ERANGE;
ddbond_info->controlsock = tmp;
return count;
}
static void ddbond_info_release(struct kobject *item)
{
kfree(to_ddbond_info(item));
}
static struct kobj_type ddbond_info_type = {
.sysfs_ops = &(struct sysfs_ops){
.show = ddbond_info_attr_show,
.store = ddbond_info_attr_store,
.release = ddbond_info_release,
},
.default_attrs = (struct attribute *[]){
&(struct attribute){
.owner = THIS_MODULE,
.name = "sockname",
.mode = S_IRUGO | S_IWUSR,
},
NULL,
},
.ct_owner = THIS_MODULE,
};
static struct kobject *ddbond_make_item(struct kset *group, const char *name)
{
struct ddbond_info *ddbond_info;
if (!(ddbond_info = kcalloc(1, sizeof(struct ddbond_info), GFP_KERNEL)))
return NULL;
kobject_init_type_name(&ddbond_info->item, name, &ddbond_info_type);
return &ddbond_info->item;
}
static ssize_t ddbond_description(struct kobject *item,
struct attribute *attr, char *page)
{
return sprintf(page,
"A ddbond block server has two components: a userspace server and a kernel\n"
"io daemon. First start the server and give it the name of a socket it will\n"
"create, then create a ddbond directory and write the same name into the\n"
"socket attribute\n");
}
static struct kobj_type ddbond_type = {
.sysfs_ops = &(struct sysfs_ops){
.show = ddbond_description,
},
.ct_group_ops = &(struct configfs_group_operations){
.make_item = ddbond_make_item,
},
.default_attrs = (struct attribute *[]){
&(struct attribute){
.owner = THIS_MODULE,
.name = "description",
.mode = S_IRUGO,
},
NULL,
}
};
static struct subsystem ddbond_subsys = {
.kset = {
.kobj = {
.k_name = "ddbond",
.ktype = &ddbond_type,
},
},
};
static int __init init_ddbond_config(void)
{
int ret;
config_group_init(&ddbond_subsys.kset);
init_rwsem(&ddbond_subsys.rwsem);
if ((ret = configfs_register_subsystem(&ddbond_subsys)))
printk(KERN_ERR "Error %d while registering subsystem %s\n",
ret, ddbond_subsys.kset.kobj.k_name);
return ret;
}
static void __exit exit_ddbond_config(void)
{
configfs_unregister_subsystem(&ddbond_subsys);
}
module_init(init_ddbond_config);
module_exit(exit_ddbond_config);
MODULE_LICENSE("GPL");
next prev parent reply other threads:[~2005-08-30 23:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-30 22:54 [RFC][PATCH 1 of 4] Configfs is really sysfs Daniel Phillips
2005-08-30 22:57 ` [RFC][PATCH 2 " Daniel Phillips
2005-08-30 22:59 ` [RFC][PATCH 3 " Daniel Phillips
2005-08-30 23:03 ` Daniel Phillips [this message]
2005-08-30 23:30 ` [RFC][PATCH 4 " Daniel Phillips
2005-08-30 23:06 ` [RFC][PATCH 3 " Stephen Hemminger
2005-08-30 23:18 ` Daniel Phillips
2005-08-30 23:10 ` Daniel Phillips
2005-08-30 23:22 ` [RFC][PATCH 2 " Daniel Phillips
2005-08-30 23:13 ` [RFC][PATCH 1 " Joel Becker
2005-08-30 23:25 ` Daniel Phillips
2005-08-30 23:35 ` Daniel Phillips
2005-08-30 23:28 ` Andrew Morton
2005-08-30 23:34 ` viro
2005-08-30 23:51 ` Daniel Phillips
2005-08-30 23:37 ` Daniel Phillips
2005-08-31 0:03 ` Joel Becker
2005-09-04 3:53 ` Joel Becker
2005-09-04 4:12 ` Joel Becker
2005-09-04 4:41 ` Joel Becker
2005-09-04 4:54 ` Joel Becker
2005-09-07 20:31 ` 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=200508310903.10197.phillips@istop.com \
--to=phillips@istop.com \
--cc=Joel.Becker@oracle.com \
--cc=akpm@osdl.org \
--cc=greg@kroah.com \
--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: 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