Re: [RFC][PATCH 3 of 4] Configfs is really sysfs
On Tuesday 30 August 2005 19:06, Stephen Hemminger wrote: > On Wed, 31 Aug 2005 08:59:55 +1000 > > Daniel Phillips <[EMAIL PROTECTED]> wrote: > > Configfs rewritten as a single file and updated to use kobjects instead > > of its own clone of kobjects (config_items). > > Some style issues: > Mixed case in labels I certainly agree. This is strictly for comparison purposes and so I did not clean up the stylistic problems from the original... this time. > Bad identation I did lindent it however :-) > > + Done: > > Why the mixed case label? It shall die. > > +void config_group_init_type_name(struct kset *group, const char *name, > > struct kobj_type *type) +{ > > + kobject_set_name(>kobj, name); > > + group->kobj.ktype = type; > > + config_group_init(group); > > +} > > Use tabs not one space for indent. Urk. Kmail did that to me, it has been broken that way for a year or so. I will have to repost the whole set from a mailer that works. Regards, Daniel - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC][PATCH 3 of 4] Configfs is really sysfs
On Wednesday 31 August 2005 08:59, Daniel Phillips wrote: > -obj-$(CONFIG_CONFIGFS_FS) += configfs.o > +obj-$(CONFIG_CONFIGFS_FS) += configfs.o ddbond.config.o This should just be: +obj-$(CONFIG_CONFIGFS_FS) += configfs.o However, the wrong version does provide a convenient way of compiling the example, I just... have... to... remember to delete it next time. Regards, Daniel - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC][PATCH 3 of 4] Configfs is really sysfs
On Wed, 31 Aug 2005 08:59:55 +1000 Daniel Phillips <[EMAIL PROTECTED]> wrote: > Configfs rewritten as a single file and updated to use kobjects instead of its > own clone of kobjects (config_items). > Some style issues: Mixed case in labels Bad identation > +static int sysfs_create(struct dentry *dentry, int mode, int (*init) (struct > inode *)) > +{ > + int error = 0; > + struct inode *inode = NULL; > + if (dentry) { > + if (!dentry->d_inode) { > + if ((inode = sysfs_new_inode(mode))) { > + if (dentry->d_parent > + && dentry->d_parent->d_inode) { > + struct inode *p_inode = > + dentry->d_parent->d_inode; > + p_inode->i_mtime = p_inode->i_ctime = > + CURRENT_TIME; > + } > + goto Proceed; > + } else > + error = -ENOMEM; > + } else > + error = -EEXIST; > + } else > + error = -ENOENT; > + goto Done; > + > + Proceed: > + if (init) > + error = init(inode); > + if (!error) { > + d_instantiate(dentry, inode); > + if (S_ISDIR(mode) || S_ISLNK(mode)) /* pin link and directory > dentries */ > + dget(dentry); > + } else > + iput(inode); > + Done: Why the mixed case label? > + return error; > +} > +/* > + * configfs client helpers > + */ > + > +void config_group_init_type_name(struct kset *group, const char *name, > struct kobj_type *type) > +{ > + kobject_set_name(>kobj, name); > + group->kobj.ktype = type; > + config_group_init(group); > +} Use tabs not one space for indent. > +void config_group_init(struct kset *group) > +{ > + kobject_init(>kobj); > + INIT_LIST_HEAD(>cg_children); > +} > + > +void kobject_init_type_name(struct kobject *kobj, const char *name, struct > kobj_type *type) > +{ > + kobject_set_name(kobj, name); > + kobj->ktype = type; > + kobject_init(kobj); > +} > + > +EXPORT_SYMBOL(configfs_register_subsystem); > +EXPORT_SYMBOL(configfs_unregister_subsystem); > +EXPORT_SYMBOL(config_group_init_type_name); > +EXPORT_SYMBOL(config_group_init); > +EXPORT_SYMBOL(kobject_init_type_name); > - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC][PATCH 3 of 4] Configfs is really sysfs
Configfs rewritten as a single file and updated to use kobjects instead of its own clone of kobjects (config_items). diff -up --recursive 2.6.13-rc5-mm1.clean/fs/configfs/Makefile 2.6.13-rc5-mm1/fs/configfs/Makefile --- 2.6.13-rc5-mm1.clean/fs/configfs/Makefile 2005-08-09 18:23:30.0 -0400 +++ 2.6.13-rc5-mm1/fs/configfs/Makefile 2005-08-29 17:26:02.0 -0400 @@ -2,6 +2,5 @@ # Makefile for the configfs virtual filesystem # -obj-$(CONFIG_CONFIGFS_FS) += configfs.o +obj-$(CONFIG_CONFIGFS_FS) += configfs.o ddbond.config.o -configfs-objs := inode.o file.o dir.o symlink.o mount.o item.o diff -up --recursive 2.6.13-rc5-mm1.clean/fs/configfs/configfs.c 2.6.13-rc5-mm1/fs/configfs/configfs.c --- 2.6.13-rc5-mm1.clean/fs/configfs/configfs.c 2005-08-30 17:50:30.0 -0400 +++ 2.6.13-rc5-mm1/fs/configfs/configfs.c 2005-08-29 21:36:47.0 -0400 @@ -0,0 +1,1897 @@ +/* + * Based on sysfs: + * sysfs Copyright (C) 2001, 2002, 2003 Patrick Mochel + * + * configfs Copyright (C) 2005 Oracle. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define CONFIGFS_ROOT 0x0001 +#define CONFIGFS_DIR 0x0002 +#define CONFIGFS_ITEM_ATTR 0x0004 +#define CONFIGFS_ITEM_LINK 0x0020 +#define CONFIGFS_USET_DIR 0x0040 +#define CONFIGFS_USET_DEFAULT 0x0080 +#define CONFIGFS_USET_DROPPING 0x0100 +#define CONFIGFS_NOT_PINNED(CONFIGFS_ITEM_ATTR) + +struct sysfs_symlink { + struct list_head sl_list; + struct kobject *sl_target; +}; + +static inline struct kobject *to_kobj(struct dentry *dentry) +{ + struct sysfs_dirent *sd = dentry->d_fsdata; + return ((struct kobject *)sd->s_element); +} + +static inline struct attribute *to_attr(struct dentry *dentry) +{ + struct sysfs_dirent *sd = dentry->d_fsdata; + return ((struct attribute *)sd->s_element); +} + +static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) +{ + struct kobject *kobj = NULL; + + spin_lock(_lock); + if (!d_unhashed(dentry)) { + struct sysfs_dirent *sd = dentry->d_fsdata; + if (sd->s_type & CONFIGFS_ITEM_LINK) { + struct sysfs_symlink *sl = sd->s_element; + kobj = kobject_get(sl->sl_target); + } else + kobj = kobject_get(sd->s_element); + } + spin_unlock(_lock); + + return kobj; +} + +static kmem_cache_t *sysfs_dir_cachep; + +static void release_sysfs_dirent(struct sysfs_dirent *sd) +{ + if ((sd->s_type & CONFIGFS_ROOT)) + return; + kmem_cache_free(sysfs_dir_cachep, sd); +} + +static struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) +{ + if (sd) { + WARN_ON(!atomic_read(>s_count)); + atomic_inc(>s_count); + } + return sd; +} + +static void sysfs_put(struct sysfs_dirent *sd) +{ + WARN_ON(!atomic_read(>s_count)); + if (atomic_dec_and_test(>s_count)) + release_sysfs_dirent(sd); +} + +/* + * inode.c - basic inode and dentry operations. + */ + +static struct super_block *sysfs_sb; + +static struct address_space_operations sysfs_aops = { + .readpage = simple_readpage, + .prepare_write = simple_prepare_write, + .commit_write = simple_commit_write +}; + +static struct backing_dev_info sysfs_backing_dev_info = { + .ra_pages = 0, /* No readahead */ + .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, +}; + +static struct inode *sysfs_new_inode(mode_t mode) +{ + struct inode *inode = new_inode(sysfs_sb); + if (inode) { + inode->i_blksize = PAGE_CACHE_SIZE; + inode->i_blocks = 0; + inode->i_mode = mode; + inode->i_uid = 0; + inode->i_gid = 0; + inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; + inode->i_mapping->a_ops = _aops; + inode->i_mapping->backing_dev_info = _backing_dev_info; + } + return inode; +} + +static int sysfs_create(struct dentry *dentry, int mode, int (*init) (struct inode *)) +{ + int error = 0; + struct inode *inode = NULL; + if (dentry) { + if (!dentry->d_inode) { + if ((inode = sysfs_new_inode(mode))) { + if (dentry->d_parent + && dentry->d_parent->d_inode) { + struct inode *p_inode = + dentry->d_parent->d_inode; + p_inode->i_mtime = p_inode->i_ctime = + CURRENT_TIME; + } + goto Proceed; + } else + error = -ENOMEM; + } else + error = -EEXIST; + }
[RFC][PATCH 3 of 4] Configfs is really sysfs
Configfs rewritten as a single file and updated to use kobjects instead of its own clone of kobjects (config_items). diff -up --recursive 2.6.13-rc5-mm1.clean/fs/configfs/Makefile 2.6.13-rc5-mm1/fs/configfs/Makefile --- 2.6.13-rc5-mm1.clean/fs/configfs/Makefile 2005-08-09 18:23:30.0 -0400 +++ 2.6.13-rc5-mm1/fs/configfs/Makefile 2005-08-29 17:26:02.0 -0400 @@ -2,6 +2,5 @@ # Makefile for the configfs virtual filesystem # -obj-$(CONFIG_CONFIGFS_FS) += configfs.o +obj-$(CONFIG_CONFIGFS_FS) += configfs.o ddbond.config.o -configfs-objs := inode.o file.o dir.o symlink.o mount.o item.o diff -up --recursive 2.6.13-rc5-mm1.clean/fs/configfs/configfs.c 2.6.13-rc5-mm1/fs/configfs/configfs.c --- 2.6.13-rc5-mm1.clean/fs/configfs/configfs.c 2005-08-30 17:50:30.0 -0400 +++ 2.6.13-rc5-mm1/fs/configfs/configfs.c 2005-08-29 21:36:47.0 -0400 @@ -0,0 +1,1897 @@ +/* + * Based on sysfs: + * sysfs Copyright (C) 2001, 2002, 2003 Patrick Mochel + * + * configfs Copyright (C) 2005 Oracle. All rights reserved. + */ + +#include linux/fs.h +#include linux/namei.h +#include linux/module.h +#include linux/mount.h +#include linux/backing-dev.h +#include linux/pagemap.h +#include linux/configfs.h + +#define CONFIGFS_ROOT 0x0001 +#define CONFIGFS_DIR 0x0002 +#define CONFIGFS_ITEM_ATTR 0x0004 +#define CONFIGFS_ITEM_LINK 0x0020 +#define CONFIGFS_USET_DIR 0x0040 +#define CONFIGFS_USET_DEFAULT 0x0080 +#define CONFIGFS_USET_DROPPING 0x0100 +#define CONFIGFS_NOT_PINNED(CONFIGFS_ITEM_ATTR) + +struct sysfs_symlink { + struct list_head sl_list; + struct kobject *sl_target; +}; + +static inline struct kobject *to_kobj(struct dentry *dentry) +{ + struct sysfs_dirent *sd = dentry-d_fsdata; + return ((struct kobject *)sd-s_element); +} + +static inline struct attribute *to_attr(struct dentry *dentry) +{ + struct sysfs_dirent *sd = dentry-d_fsdata; + return ((struct attribute *)sd-s_element); +} + +static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) +{ + struct kobject *kobj = NULL; + + spin_lock(dcache_lock); + if (!d_unhashed(dentry)) { + struct sysfs_dirent *sd = dentry-d_fsdata; + if (sd-s_type CONFIGFS_ITEM_LINK) { + struct sysfs_symlink *sl = sd-s_element; + kobj = kobject_get(sl-sl_target); + } else + kobj = kobject_get(sd-s_element); + } + spin_unlock(dcache_lock); + + return kobj; +} + +static kmem_cache_t *sysfs_dir_cachep; + +static void release_sysfs_dirent(struct sysfs_dirent *sd) +{ + if ((sd-s_type CONFIGFS_ROOT)) + return; + kmem_cache_free(sysfs_dir_cachep, sd); +} + +static struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) +{ + if (sd) { + WARN_ON(!atomic_read(sd-s_count)); + atomic_inc(sd-s_count); + } + return sd; +} + +static void sysfs_put(struct sysfs_dirent *sd) +{ + WARN_ON(!atomic_read(sd-s_count)); + if (atomic_dec_and_test(sd-s_count)) + release_sysfs_dirent(sd); +} + +/* + * inode.c - basic inode and dentry operations. + */ + +static struct super_block *sysfs_sb; + +static struct address_space_operations sysfs_aops = { + .readpage = simple_readpage, + .prepare_write = simple_prepare_write, + .commit_write = simple_commit_write +}; + +static struct backing_dev_info sysfs_backing_dev_info = { + .ra_pages = 0, /* No readahead */ + .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, +}; + +static struct inode *sysfs_new_inode(mode_t mode) +{ + struct inode *inode = new_inode(sysfs_sb); + if (inode) { + inode-i_blksize = PAGE_CACHE_SIZE; + inode-i_blocks = 0; + inode-i_mode = mode; + inode-i_uid = 0; + inode-i_gid = 0; + inode-i_atime = inode-i_mtime = inode-i_ctime = CURRENT_TIME; + inode-i_mapping-a_ops = sysfs_aops; + inode-i_mapping-backing_dev_info = sysfs_backing_dev_info; + } + return inode; +} + +static int sysfs_create(struct dentry *dentry, int mode, int (*init) (struct inode *)) +{ + int error = 0; + struct inode *inode = NULL; + if (dentry) { + if (!dentry-d_inode) { + if ((inode = sysfs_new_inode(mode))) { + if (dentry-d_parent +dentry-d_parent-d_inode) { + struct inode *p_inode = + dentry-d_parent-d_inode; + p_inode-i_mtime = p_inode-i_ctime = + CURRENT_TIME; + } + goto Proceed; + } else +
Re: [RFC][PATCH 3 of 4] Configfs is really sysfs
On Wed, 31 Aug 2005 08:59:55 +1000 Daniel Phillips [EMAIL PROTECTED] wrote: Configfs rewritten as a single file and updated to use kobjects instead of its own clone of kobjects (config_items). Some style issues: Mixed case in labels Bad identation +static int sysfs_create(struct dentry *dentry, int mode, int (*init) (struct inode *)) +{ + int error = 0; + struct inode *inode = NULL; + if (dentry) { + if (!dentry-d_inode) { + if ((inode = sysfs_new_inode(mode))) { + if (dentry-d_parent + dentry-d_parent-d_inode) { + struct inode *p_inode = + dentry-d_parent-d_inode; + p_inode-i_mtime = p_inode-i_ctime = + CURRENT_TIME; + } + goto Proceed; + } else + error = -ENOMEM; + } else + error = -EEXIST; + } else + error = -ENOENT; + goto Done; + + Proceed: + if (init) + error = init(inode); + if (!error) { + d_instantiate(dentry, inode); + if (S_ISDIR(mode) || S_ISLNK(mode)) /* pin link and directory dentries */ + dget(dentry); + } else + iput(inode); + Done: Why the mixed case label? + return error; +} +/* + * configfs client helpers + */ + +void config_group_init_type_name(struct kset *group, const char *name, struct kobj_type *type) +{ + kobject_set_name(group-kobj, name); + group-kobj.ktype = type; + config_group_init(group); +} Use tabs not one space for indent. +void config_group_init(struct kset *group) +{ + kobject_init(group-kobj); + INIT_LIST_HEAD(group-cg_children); +} + +void kobject_init_type_name(struct kobject *kobj, const char *name, struct kobj_type *type) +{ + kobject_set_name(kobj, name); + kobj-ktype = type; + kobject_init(kobj); +} + +EXPORT_SYMBOL(configfs_register_subsystem); +EXPORT_SYMBOL(configfs_unregister_subsystem); +EXPORT_SYMBOL(config_group_init_type_name); +EXPORT_SYMBOL(config_group_init); +EXPORT_SYMBOL(kobject_init_type_name); - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC][PATCH 3 of 4] Configfs is really sysfs
On Wednesday 31 August 2005 08:59, Daniel Phillips wrote: -obj-$(CONFIG_CONFIGFS_FS) += configfs.o +obj-$(CONFIG_CONFIGFS_FS) += configfs.o ddbond.config.o This should just be: +obj-$(CONFIG_CONFIGFS_FS) += configfs.o However, the wrong version does provide a convenient way of compiling the example, I just... have... to... remember to delete it next time. Regards, Daniel - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC][PATCH 3 of 4] Configfs is really sysfs
On Tuesday 30 August 2005 19:06, Stephen Hemminger wrote: On Wed, 31 Aug 2005 08:59:55 +1000 Daniel Phillips [EMAIL PROTECTED] wrote: Configfs rewritten as a single file and updated to use kobjects instead of its own clone of kobjects (config_items). Some style issues: Mixed case in labels I certainly agree. This is strictly for comparison purposes and so I did not clean up the stylistic problems from the original... this time. Bad identation I did lindent it however :-) + Done: Why the mixed case label? It shall die. +void config_group_init_type_name(struct kset *group, const char *name, struct kobj_type *type) +{ + kobject_set_name(group-kobj, name); + group-kobj.ktype = type; + config_group_init(group); +} Use tabs not one space for indent. Urk. Kmail did that to me, it has been broken that way for a year or so. I will have to repost the whole set from a mailer that works. Regards, Daniel - To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/