LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [2.6.6-mm3] sysfs backing store ver 0.6
@ 2004-05-17 12:04 Maneesh Soni
2004-05-17 12:05 ` [2.6.6-mm3] sysfs-leaves-mount.patch Maneesh Soni
0 siblings, 1 reply; 7+ messages in thread
From: Maneesh Soni @ 2004-05-17 12:04 UTC (permalink / raw)
To: Andrew Morton; +Cc: Greg KH, LKML
Hello Andrew,
Please find the following patch set for sysfs backing store for 2.6.6-mm3
kernel. I have fixed the rejects and there are also a few code changes.
The main change is related to providing protection against vulnerability of
parent dentry going off before the sysfs file being deleted. If you have
seen there was a oops message reported with 2.6.6-mm1 in which parent
dentry's ref count is zero when it was trying to remove a sysfs link.
http://marc.theaimsgroup.com/?l=linux-kernel&m=108422899203505&w=2
The changes I did are in fs/sysfs/inode.c:sysfs_hash_and_remove() and
sysfs_remove_dir(), where it is now checking s_dentry field of the
corresponding sysfs_dirent to get the dentry (if valid) of the file
being deleted. Apart from being safe against parent dentry going off
before the child, this change also avoids allocating the dentry in the
removal path by not doing the lookup.
Please include the following patches in the next -mm and also note that they
all depend on the fix-sysfs-symlinks.patch, I just mailed.
http://marc.theaimsgroup.com/?l=linux-kernel&m=108479506507825&w=2
Thanks
Maneesh
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696
^ permalink raw reply [flat|nested] 7+ messages in thread
* [2.6.6-mm3] sysfs-leaves-mount.patch
2004-05-17 12:04 [2.6.6-mm3] sysfs backing store ver 0.6 Maneesh Soni
@ 2004-05-17 12:05 ` Maneesh Soni
2004-05-17 12:06 ` [2.6.6-mm3] sysfs-leaves-dir.patch Maneesh Soni
0 siblings, 1 reply; 7+ messages in thread
From: Maneesh Soni @ 2004-05-17 12:05 UTC (permalink / raw)
To: Andrew Morton; +Cc: Greg KH, LKML
=> changes in version 0.6
o Re-diffed for 2.6.6-mm3
=> changes in version 0.5
o Removed ->umount_begin() as mount -o remount does the same function
basically shrink dcache by removing the unsed dentries.
=> changes in version 0.4
o Nil, just re-diffed
=> changes in version 0.3
o Nil, just re-diffed
=> changes in version 0.2
o Nil, just re-diffed
=> changes in version 0.1
o Corrected sysfs_umount_begin(), it doesnot need lock_super() and also the
s_root check is not required. The reason being, that sysfs filesystem is
always mounted internally during init and there is no chance of sysfs super
block going away.
o corrected comments for umount_begin()
============================================================================
o The following patch contains the sysfs_dirent structure definition.
sysfs_dirent can represent kobject, attribute group, text attribute or
binary attribute for kobjects registered with sysfs. sysfs_dirent is
allocated with a ref count (s_count) of 1. Ref count is incremented when
a dentry is associated with the sysfs_dirent and it is decremented when
the corresponding dentry is freed.
o sysfs_dirent's corresponding to the attribute files of a kobject or attribute
group are linked together with s_sibling and are anchored at s_children of
the corresponding kobject's or attribute-group's sysfs_dirent.
o The patch also contains the mount related changes for sysfs backing store.
Because we mount sysfs once while init(), plain umount of sysfs doesnot
free all the un-used dentries (present in LRU list). To use force umount
flag, umount_begin() routine is provided which does a shrink_dcache_parent()
to release all the unused dentries.
fs/sysfs/mount.c | 12 ++++++++++--
include/linux/sysfs.h | 20 ++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff -puN include/linux/sysfs.h~sysfs-leaves-mount include/linux/sysfs.h
--- linux-2.6.6-mm3/include/linux/sysfs.h~sysfs-leaves-mount 2004-05-17 15:26:35.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/include/linux/sysfs.h 2004-05-17 15:26:35.000000000 +0530
@@ -9,6 +9,8 @@
#ifndef _SYSFS_H_
#define _SYSFS_H_
+#include <asm/atomic.h>
+
struct kobject;
struct module;
@@ -47,6 +49,24 @@ sysfs_remove_dir(struct kobject *);
extern int
sysfs_rename_dir(struct kobject *, const char *new_name);
+struct sysfs_dirent {
+ atomic_t s_count;
+ struct list_head s_sibling;
+ struct list_head s_children;
+ void * s_element;
+ int s_type;
+ umode_t s_mode;
+ struct dentry * s_dentry;
+};
+
+#define SYSFS_ROOT 0x0001
+#define SYSFS_KOBJECT 0x0002
+#define SYSFS_KOBJ_ATTR 0x0004
+#define SYSFS_KOBJ_BIN_ATTR 0x0008
+#define SYSFS_KOBJ_ATTR_GROUP 0x0010
+#define SYSFS_KOBJ_LINK 0x0020
+#define SYSFS_NOT_PINNED (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
+
extern int
sysfs_create_file(struct kobject *, const struct attribute *);
diff -puN fs/sysfs/mount.c~sysfs-leaves-mount fs/sysfs/mount.c
--- linux-2.6.6-mm3/fs/sysfs/mount.c~sysfs-leaves-mount 2004-05-17 15:26:35.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/mount.c 2004-05-17 15:26:35.000000000 +0530
@@ -22,6 +22,13 @@ static struct super_operations sysfs_ops
.drop_inode = generic_delete_inode,
};
+struct sysfs_dirent sysfs_root = {
+ .s_sibling = LIST_HEAD_INIT(sysfs_root.s_sibling),
+ .s_children = LIST_HEAD_INIT(sysfs_root.s_children),
+ .s_element = NULL,
+ .s_type = SYSFS_ROOT,
+};
+
static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
{
struct inode *inode;
@@ -35,8 +42,8 @@ static int sysfs_fill_super(struct super
inode = sysfs_new_inode(S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO);
if (inode) {
- inode->i_op = &simple_dir_inode_operations;
- inode->i_fop = &simple_dir_operations;
+ inode->i_op = &sysfs_dir_inode_operations;
+ inode->i_fop = &sysfs_dir_operations;
/* directory inodes start off with i_nlink == 2 (for "." entry) */
inode->i_nlink++;
} else {
@@ -50,6 +57,7 @@ static int sysfs_fill_super(struct super
iput(inode);
return -ENOMEM;
}
+ root->d_fsdata = &sysfs_root;
sb->s_root = root;
return 0;
}
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696
^ permalink raw reply [flat|nested] 7+ messages in thread
* [2.6.6-mm3] sysfs-leaves-dir.patch
2004-05-17 12:05 ` [2.6.6-mm3] sysfs-leaves-mount.patch Maneesh Soni
@ 2004-05-17 12:06 ` Maneesh Soni
2004-05-17 12:06 ` [2.6.6-mm3] sysfs-leaves-file.patch Maneesh Soni
0 siblings, 1 reply; 7+ messages in thread
From: Maneesh Soni @ 2004-05-17 12:06 UTC (permalink / raw)
To: Andrew Morton; +Cc: Greg KH, LKML
=> changes in version 0.6
o Re-diffed for 2.6.6-mm3
o Provided protection against vulneribility of parent going before
the sysfs file being removed in sysfs_remove_dir(). There os less chance
happening this here, but still it will have some code clarity. Now it uses
s_dentry field to check if the file dentry is vaild instead of doing a
lookup. A new routine sysfs_drop_dentry() is introduced for this purpose.
=> changes in version 0.5
o Changed ->read_dir & ->lseek logic. The ->read_dir and ->lseek
logic is now based on the sysfs_dirent tree instead of dentry
based tree. Now we don't have to dget/dput children while
opening a dir. The earlier logic was wrong in the sense as we might
end up in doing dput() for dentrys which were not opened by us.
o Code changes to accomodate latest sysfs changes like in sysfs_rename_dir,
sysfs_remove_dir and symlinks handling.
o BUG_ON in sysfs_d_iput() to check if there are any cases of mismatch
in dentry and ((struct sysfs_dirent *) dentry->d_fsdata)->s_dentry
=> changes in version 0.4
o Do not take reference to kobject while creating a dir dentry for it as it
can lead to rmmod hang or certain modules due to current limitation of
module/kobject refcounting code.
=> changes in version 0.3a
o call sysfs_close_dir_entries() when filldir() returns error in
sysfs_readdir().
=> changes in version 0.3
o corrected dentry ref counting for sysfs_remove_subdir()
=> changes in version 0.2
o sysfs_rename_dir() used to call d_move() with unhashed new_dentry causing
panic in d_move(). Added d_add() call for new_dentry before calling d_move.
o corrected error checking after sysfs_get_dentry() in
sysfs_open_dir_entries().
=> changes in version 0.1
o re-diffed for 2.6.3
=> Changes in last version
o added support for symlink
o changed logic for sysfs_remove_dir
o dir dentries now take a ref on the corresponding kobject so as to have
kobject alive during the lifetime of the dentry.
=====================================================================
o This patch provides the inode operations ->lookup(), ->readdir() and
->llseek() for sysfs directories.
o while sysfs_create_dir() we attach a sysfs_dirent structure to the d_fsdata
filed of dentry corresponding to the kobject's direcotry.
o sysfs_lookup does not hash the dentry and we hash the dentry when we have
attached the sysfs_dirent to it. This was done to cover up a race when
we attach a negative dentry and instantiate it before updating the d_fsdata
field. As after instantiating we can get a successfull lookup for the dentry
but a NULL d_fsdata field. As a result we do not create negative dentries.
o sysfs_readdir() or sysfs_dir_lseek() will bring in the dentries
corresponding to the attribute files if the offset is more than 2. These
are released when we are done with filldir().
o sysfs_d_iput() releases the ref. to the sysfs_dirent() which was taken at
the time of dentry allocation.
fs/sysfs/dir.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 306 insertions(+), 45 deletions(-)
diff -puN fs/sysfs/dir.c~sysfs-leaves-dir fs/sysfs/dir.c
--- linux-2.6.6-mm3/fs/sysfs/dir.c~sysfs-leaves-dir 2004-05-17 15:28:40.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/dir.c 2004-05-17 15:54:30.000000000 +0530
@@ -12,31 +12,181 @@
DECLARE_RWSEM(sysfs_rename_sem);
+struct inode_operations sysfs_dir_inode_operations = {
+ .lookup = sysfs_lookup,
+};
+
+struct file_operations sysfs_dir_operations = {
+ .open = sysfs_dir_open,
+ .release = sysfs_dir_close,
+ .llseek = sysfs_dir_lseek,
+ .read = generic_read_dir,
+ .readdir = sysfs_readdir,
+};
+
+static void sysfs_d_iput(struct dentry * dentry, struct inode * inode)
+{
+ struct sysfs_dirent * sd = dentry->d_fsdata;
+
+ if (sd) {
+ BUG_ON(sd->s_dentry != dentry);
+ sd->s_dentry = NULL;
+ sysfs_put(sd);
+ }
+ iput(inode);
+}
+
+static struct dentry_operations sysfs_dentry_ops = {
+ .d_iput = sysfs_d_iput,
+};
+
+const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)
+{
+ struct attribute * attr;
+ struct bin_attribute * bin_attr;
+ struct sysfs_symlink * sl;
+
+ if (!sd || !sd->s_element)
+ BUG();
+
+ switch (sd->s_type) {
+ case SYSFS_KOBJECT:
+ case SYSFS_KOBJ_ATTR_GROUP:
+ /* Always have a dentry so use that */
+ return sd->s_dentry->d_name.name;
+
+ case SYSFS_KOBJ_ATTR:
+ attr = sd->s_element;
+ return attr->name;
+
+ case SYSFS_KOBJ_BIN_ATTR:
+ bin_attr = sd->s_element;
+ return bin_attr->attr.name;
+
+ case SYSFS_KOBJ_LINK:
+ sl = sd->s_element;
+ return sl->link_name;
+ }
+ return NULL;
+}
+
+static int init_file(struct inode * inode)
+{
+ inode->i_size = PAGE_SIZE;
+ inode->i_fop = &sysfs_file_operations;
+ return 0;
+}
+
static int init_dir(struct inode * inode)
{
- inode->i_op = &simple_dir_inode_operations;
- inode->i_fop = &simple_dir_operations;
+ inode->i_op = &sysfs_dir_inode_operations;
+ inode->i_fop = &sysfs_dir_operations;
/* directory inodes start off with i_nlink == 2 (for "." entry) */
inode->i_nlink++;
return 0;
}
+/* attaches attribute's sysfs_dirent to the dentry corresponding to the
+ * attribute file
+ */
+static int sysfs_attach_attr(struct sysfs_dirent * sd, struct dentry * dentry)
+{
+ struct attribute * attr = NULL;
+ struct bin_attribute * bin_attr = NULL;
+ int (* init) (struct inode *) = NULL;
+ int error = 0;
+
+ if (sd->s_type & SYSFS_KOBJ_BIN_ATTR) {
+ bin_attr = sd->s_element;
+ attr = &bin_attr->attr;
+ } else {
+ attr = sd->s_element;
+ init = init_file;
+ }
+
+ error = sysfs_create(dentry, (attr->mode & S_IALLUGO) | S_IFREG, init);
+ if (error)
+ return error;
+
+ if (bin_attr) {
+ dentry->d_inode->i_size = bin_attr->size;
+ dentry->d_inode->i_fop = &bin_fops;
+ }
+ dentry->d_op = &sysfs_dentry_ops;
+ dentry->d_fsdata = sysfs_get(sd);
+ sd->s_dentry = dentry;
+ d_rehash(dentry);
+
+ return 0;
+}
+
+static int sysfs_attach_link(struct sysfs_dirent * sd, struct dentry * dentry)
+{
+ int err = 0;
+
+ err = sysfs_create(dentry, S_IFLNK|S_IRWXUGO, init_symlink);
+ if (!err) {
+ dentry->d_op = &sysfs_dentry_ops;
+ dentry->d_fsdata = sysfs_get(sd);
+ sd->s_dentry = dentry;
+ d_rehash(dentry);
+ }
+ return err;
+}
+
+struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
+ struct nameidata *nd)
+{
+ struct sysfs_dirent * parent_sd = dentry->d_parent->d_fsdata;
+ struct sysfs_dirent * sd;
+ int err = 0;
+
+ list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
+ if (sd->s_type & SYSFS_NOT_PINNED) {
+ const unsigned char * name = sysfs_get_name(sd);
+
+ if (strcmp(name, dentry->d_name.name))
+ continue;
+
+ if (sd->s_type & SYSFS_KOBJ_LINK)
+ err = sysfs_attach_link(sd, dentry);
+ else
+ err = sysfs_attach_attr(sd, dentry);
+ break;
+ }
+ }
+ return ERR_PTR(err);
+}
+
static int create_dir(struct kobject * k, struct dentry * p,
const char * n, struct dentry ** d)
{
int error;
+ umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
down(&p->d_inode->i_sem);
*d = sysfs_get_dentry(p,n);
if (!IS_ERR(*d)) {
- error = sysfs_create(*d,
- S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO,
- init_dir);
+ error = sysfs_create(*d, mode, init_dir);
if (!error) {
- (*d)->d_fsdata = k;
- p->d_inode->i_nlink++;
+ struct sysfs_dirent * sd, * parent_sd;
+ parent_sd = p->d_fsdata;
+ sd = sysfs_new_dirent(parent_sd, k,
+ (parent_sd->s_element == k) ?
+ SYSFS_KOBJ_ATTR_GROUP :
+ SYSFS_KOBJECT);
+ if (sd) {
+ (*d)->d_fsdata = sysfs_get(sd);
+ (*d)->d_op = &sysfs_dentry_ops;
+ p->d_inode->i_nlink++;
+ sd->s_element = k;
+ sd->s_dentry = *d;
+ sd->s_mode = mode;
+ d_rehash(*d);
+ } else
+ error = -ENOMEM;
}
dput(*d);
} else
@@ -45,7 +195,6 @@ static int create_dir(struct kobject * k
return error;
}
-
int sysfs_create_subdir(struct kobject * k, const char * n, struct dentry ** d)
{
return create_dir(k,k->dentry,n,d);
@@ -79,12 +228,16 @@ int sysfs_create_dir(struct kobject * ko
return error;
}
-
static void remove_dir(struct dentry * d)
{
struct dentry * parent = dget(d->d_parent);
+ struct sysfs_dirent * sd;
+
down(&parent->d_inode->i_sem);
d_delete(d);
+ sd = d->d_fsdata;
+ list_del_init(&sd->s_sibling);
+ sysfs_put(d->d_fsdata);
if (d->d_inode)
simple_rmdir(parent->d_inode,d);
@@ -106,14 +259,14 @@ void sysfs_remove_subdir(struct dentry *
* @kobj: object.
*
* The only thing special about this is that we remove any files in
- * the directory before we remove the directory, and we've inlined
- * what used to be sysfs_rmdir() below, instead of calling separately.
+ * the directory before we remove the directory
*/
void sysfs_remove_dir(struct kobject * kobj)
{
- struct list_head * node;
struct dentry * dentry = dget(kobj->dentry);
+ struct sysfs_dirent * parent_sd = dentry->d_fsdata;
+ struct sysfs_dirent * sd, * tmp;
if (!dentry)
return;
@@ -121,38 +274,13 @@ void sysfs_remove_dir(struct kobject * k
pr_debug("sysfs %s: removing dir\n",dentry->d_name.name);
down(&dentry->d_inode->i_sem);
- spin_lock(&dcache_lock);
-restart:
- node = dentry->d_subdirs.next;
- while (node != &dentry->d_subdirs) {
- struct dentry * d = list_entry(node,struct dentry,d_child);
-
- node = node->next;
- pr_debug(" o %s (%d): ",d->d_name.name,atomic_read(&d->d_count));
- if (!d_unhashed(d) && (d->d_inode)) {
- d = dget_locked(d);
- pr_debug("removing");
-
- /**
- * Unlink and unhash.
- */
- __d_drop(d);
- spin_unlock(&dcache_lock);
- /* release the target kobject in case of
- * a symlink
- */
- if (S_ISLNK(d->d_inode->i_mode))
- kobject_put(d->d_fsdata);
-
- simple_unlink(dentry->d_inode,d);
- dput(d);
- pr_debug(" done\n");
- spin_lock(&dcache_lock);
- /* re-acquired dcache_lock, need to restart */
- goto restart;
- }
- }
- spin_unlock(&dcache_lock);
+ list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
+ if (!sd->s_element)
+ continue;
+ list_del_init(&sd->s_sibling);
+ sysfs_drop_dentry(sd, dentry);
+ sysfs_put(sd);
+ }
up(&dentry->d_inode->i_sem);
remove_dir(dentry);
@@ -182,8 +310,10 @@ int sysfs_rename_dir(struct kobject * ko
if (!IS_ERR(new_dentry)) {
if (!new_dentry->d_inode) {
error = kobject_set_name(kobj,new_name);
- if (!error)
+ if (!error) {
+ d_add(new_dentry, NULL);
d_move(kobj->dentry, new_dentry);
+ }
}
dput(new_dentry);
}
@@ -193,6 +323,137 @@ int sysfs_rename_dir(struct kobject * ko
return error;
}
+int sysfs_dir_open(struct inode *inode, struct file *file)
+{
+ struct dentry * dentry = file->f_dentry;
+ struct sysfs_dirent * parent_sd = dentry->d_fsdata;
+
+ down(&dentry->d_inode->i_sem);
+ file->private_data = sysfs_new_dirent(parent_sd, NULL, 0);
+ up(&dentry->d_inode->i_sem);
+
+ return file->private_data ? 0 : -ENOMEM;
+
+}
+
+int sysfs_dir_close(struct inode *inode, struct file *file)
+{
+ struct dentry * dentry = file->f_dentry;
+ struct sysfs_dirent * cursor = file->private_data;
+
+ down(&dentry->d_inode->i_sem);
+ list_del_init(&cursor->s_sibling);
+ up(&dentry->d_inode->i_sem);
+ sysfs_put(file->private_data);
+
+ return 0;
+}
+
+/* Relationship between s_mode and the DT_xxx types */
+static inline unsigned char dt_type(struct sysfs_dirent *sd)
+{
+ return (sd->s_mode >> 12) & 15;
+}
+
+int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
+{
+ struct dentry *dentry = filp->f_dentry;
+ struct sysfs_dirent * parent_sd = dentry->d_fsdata;
+ struct sysfs_dirent *cursor = filp->private_data;
+ struct list_head *p, *q = &cursor->s_sibling;
+ ino_t ino;
+ int i = filp->f_pos;
+
+ switch (i) {
+ case 0:
+ ino = dentry->d_inode->i_ino;
+ if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
+ break;
+ filp->f_pos++;
+ i++;
+ /* fallthrough */
+ case 1:
+ ino = parent_ino(dentry);
+ if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
+ break;
+ filp->f_pos++;
+ i++;
+ /* fallthrough */
+ default:
+ if (filp->f_pos == 2) {
+ list_del(q);
+ list_add(q, &parent_sd->s_children);
+ }
+ for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
+ struct sysfs_dirent *next;
+ const char * name;
+ int len;
+
+ next = list_entry(p, struct sysfs_dirent,
+ s_sibling);
+ if (!next->s_element)
+ continue;
+
+ name = sysfs_get_name(next);
+ len = strlen(name);
+ if (next->s_dentry)
+ ino = next->s_dentry->d_inode->i_ino;
+ else
+ ino = iunique(sysfs_sb, 2);
+
+ if (filldir(dirent, name, len, filp->f_pos, ino,
+ dt_type(next)) < 0)
+ return 0;
+
+ list_del(q);
+ list_add(q, p);
+ p = q;
+ filp->f_pos++;
+ }
+ }
+ return 0;
+}
+
+loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)
+{
+ struct dentry * dentry = file->f_dentry;
+
+ down(&dentry->d_inode->i_sem);
+ switch (origin) {
+ case 1:
+ offset += file->f_pos;
+ case 0:
+ if (offset >= 0)
+ break;
+ default:
+ up(&file->f_dentry->d_inode->i_sem);
+ return -EINVAL;
+ }
+ if (offset != file->f_pos) {
+ file->f_pos = offset;
+ if (file->f_pos >= 2) {
+ struct sysfs_dirent *sd = dentry->d_fsdata;
+ struct sysfs_dirent *cursor = file->private_data;
+ struct list_head *p;
+ loff_t n = file->f_pos - 2;
+
+ list_del(&cursor->s_sibling);
+ p = sd->s_children.next;
+ while (n && p != &sd->s_children) {
+ struct sysfs_dirent *next;
+ next = list_entry(p, struct sysfs_dirent,
+ s_sibling);
+ if (next->s_element)
+ n--;
+ p = p->next;
+ }
+ list_add_tail(&cursor->s_sibling, p);
+ }
+ }
+ up(&dentry->d_inode->i_sem);
+ return offset;
+}
+
EXPORT_SYMBOL(sysfs_create_dir);
EXPORT_SYMBOL(sysfs_remove_dir);
EXPORT_SYMBOL(sysfs_rename_dir);
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696
^ permalink raw reply [flat|nested] 7+ messages in thread
* [2.6.6-mm3] sysfs-leaves-file.patch
2004-05-17 12:06 ` [2.6.6-mm3] sysfs-leaves-dir.patch Maneesh Soni
@ 2004-05-17 12:06 ` Maneesh Soni
2004-05-17 12:07 ` [2.6.6-mm3] sysfs-leaves-bin.patch Maneesh Soni
0 siblings, 1 reply; 7+ messages in thread
From: Maneesh Soni @ 2004-05-17 12:06 UTC (permalink / raw)
To: Andrew Morton; +Cc: Greg KH, LKML
=> changes in version 0.6
o Re-diffed for 2.6.6-mm3
o Provided protection against vulneribility of parent going before
the sysfs file being removed in sysfs_hash_and_remove(). Now it uses
s_dentry field to check if the file dentry is vaild instead of doing a
lookup. A new routine sysfs_drop_dentry() is introduced for this purpose.
=> changes in version 0.5
o Cahnges to accomodate latest sysfs changes basically using
sysfs_get_kobject() while opening sysfs files.
=> changes in version 0.4
o Made necessary changes for checking DCACHE_SYSFS_CONNECTED flag while
opening the sysfs file in check_perm() and a few changes in variable names
=> changes in version 0.3
o Nil, just re-diffed
=> changes in version 0.2
o Nil, just re-diffed
=> Changes:
o Removed the extra kobject_get from sysfs_release()
=======================================================
o sysfs_create_file() will just link a new sysfs_dirent() structure representing
the attribute file to the kobject's s_children list.
o in sysfs_create() we take extra ref. only for dentries corresponding to
non-regular files or in other words pin only non-leaf dentries.
fs/sysfs/file.c | 65 ++++++++++++++++++++++++++---------------------------
fs/sysfs/inode.c | 67 ++++++++++++++++++++++++++++++++++++-------------------
2 files changed, 77 insertions(+), 55 deletions(-)
diff -puN fs/sysfs/file.c~sysfs-leaves-file fs/sysfs/file.c
--- linux-2.6.6-mm3/fs/sysfs/file.c~sysfs-leaves-file 2004-05-17 15:29:21.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/file.c 2004-05-17 15:29:21.000000000 +0530
@@ -9,14 +9,6 @@
#include "sysfs.h"
-static struct file_operations sysfs_file_operations;
-
-static int init_file(struct inode * inode)
-{
- inode->i_size = PAGE_SIZE;
- inode->i_fop = &sysfs_file_operations;
- return 0;
-}
#define to_subsys(k) container_of(k,struct subsystem,kset.kobj)
#define to_sattr(a) container_of(a,struct subsys_attribute,attr)
@@ -77,8 +69,10 @@ struct sysfs_buffer {
*/
static int fill_read_buffer(struct file * file, struct sysfs_buffer * buffer)
{
- struct attribute * attr = file->f_dentry->d_fsdata;
- struct kobject * kobj = file->f_dentry->d_parent->d_fsdata;
+ struct sysfs_dirent * attr_sd = file->f_dentry->d_fsdata;
+ struct attribute * attr = attr_sd->s_element;
+ struct sysfs_dirent * kobj_sd = file->f_dentry->d_parent->d_fsdata;
+ struct kobject * kobj = kobj_sd->s_element;
struct sysfs_ops * ops = buffer->ops;
int ret = 0;
ssize_t count;
@@ -134,6 +128,9 @@ static int flush_read_buffer(struct sysf
* is in the file's ->d_fsdata. The target object is in the directory's
* ->d_fsdata.
*
+ * It is safe to use ->d_parent->d_fsdata as both dentry and the kobject
+ * are pinned in ->open().
+ *
* We call fill_read_buffer() to allocate and fill the buffer from the
* object's show() method exactly once (if the read is happening from
* the beginning of the file). That should fill the entire buffer with
@@ -198,8 +195,10 @@ fill_write_buffer(struct sysfs_buffer *
static int
flush_write_buffer(struct file * file, struct sysfs_buffer * buffer, size_t count)
{
- struct attribute * attr = file->f_dentry->d_fsdata;
- struct kobject * kobj = file->f_dentry->d_parent->d_fsdata;
+ struct sysfs_dirent * attr_sd = file->f_dentry->d_fsdata;
+ struct attribute * attr = attr_sd->s_element;
+ struct sysfs_dirent * kobj_sd = file->f_dentry->d_parent->d_fsdata;
+ struct kobject * kobj = kobj_sd->s_element;
struct sysfs_ops * ops = buffer->ops;
return ops->store(kobj,attr,buffer->page,count);
@@ -239,7 +238,8 @@ sysfs_write_file(struct file *file, cons
static int check_perm(struct inode * inode, struct file * file)
{
struct kobject *kobj = sysfs_get_kobject(file->f_dentry->d_parent);
- struct attribute * attr = file->f_dentry->d_fsdata;
+ struct sysfs_dirent * attr_sd = file->f_dentry->d_fsdata;
+ struct attribute * attr = attr_sd->s_element;
struct sysfs_buffer * buffer;
struct sysfs_ops * ops = NULL;
int error = 0;
@@ -320,8 +320,10 @@ static int sysfs_open_file(struct inode
static int sysfs_release(struct inode * inode, struct file * filp)
{
- struct kobject * kobj = filp->f_dentry->d_parent->d_fsdata;
- struct attribute * attr = filp->f_dentry->d_fsdata;
+ struct sysfs_dirent * attr_sd = filp->f_dentry->d_fsdata;
+ struct attribute * attr = attr_sd->s_element;
+ struct sysfs_dirent * kobj_sd = filp->f_dentry->d_parent->d_fsdata;
+ struct kobject * kobj = kobj_sd->s_element;
struct sysfs_buffer * buffer = filp->private_data;
if (kobj)
@@ -336,7 +338,7 @@ static int sysfs_release(struct inode *
return 0;
}
-static struct file_operations sysfs_file_operations = {
+struct file_operations sysfs_file_operations = {
.read = sysfs_read_file,
.write = sysfs_write_file,
.llseek = generic_file_llseek,
@@ -345,23 +347,20 @@ static struct file_operations sysfs_file
};
-int sysfs_add_file(struct dentry * dir, const struct attribute * attr)
+int sysfs_add_file(struct dentry * parent, const struct attribute * attr, int t)
{
- struct dentry * dentry;
- int error;
+ struct sysfs_dirent * sd;
+ struct sysfs_dirent * parent_sd = parent->d_fsdata;
+ int error = 0;
- down(&dir->d_inode->i_sem);
- dentry = sysfs_get_dentry(dir,attr->name);
- if (!IS_ERR(dentry)) {
- error = sysfs_create(dentry,
- (attr->mode & S_IALLUGO) | S_IFREG,
- init_file);
- if (!error)
- dentry->d_fsdata = (void *)attr;
- dput(dentry);
- } else
- error = PTR_ERR(dentry);
- up(&dir->d_inode->i_sem);
+ down(&parent->d_inode->i_sem);
+ sd = sysfs_new_dirent(parent_sd, (void *) attr, t);
+ if (!sd)
+ error = -ENOMEM;
+ else
+ sd->s_mode = (attr->mode & S_IALLUGO) | S_IFREG ;
+ up(&parent->d_inode->i_sem);
+
return error;
}
@@ -374,8 +373,8 @@ int sysfs_add_file(struct dentry * dir,
int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
{
- if (kobj && attr)
- return sysfs_add_file(kobj->dentry,attr);
+ if (kobj && kobj->dentry && attr)
+ return sysfs_add_file(kobj->dentry, attr, SYSFS_KOBJ_ATTR);
return -EINVAL;
}
diff -puN fs/sysfs/inode.c~sysfs-leaves-file fs/sysfs/inode.c
--- linux-2.6.6-mm3/fs/sysfs/inode.c~sysfs-leaves-file 2004-05-17 15:29:21.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/inode.c 2004-05-17 15:54:30.000000000 +0530
@@ -11,6 +11,8 @@
#include <linux/pagemap.h>
#include <linux/namei.h>
#include <linux/backing-dev.h>
+#include "sysfs.h"
+
extern struct super_block * sysfs_sb;
static struct address_space_operations sysfs_aops = {
@@ -61,7 +63,8 @@ int sysfs_create(struct dentry * dentry,
error = init(inode);
if (!error) {
d_instantiate(dentry, inode);
- dget(dentry); /* Extra count - pin the dentry in core */
+ if (S_ISDIR(mode))
+ dget(dentry); /* pin only directory dentry in core */
} else
iput(inode);
Done:
@@ -83,31 +86,51 @@ struct dentry * sysfs_get_dentry(struct
return lookup_hash(&qstr,parent);
}
+static struct sysfs_dirent * sysfs_find_dirent(struct sysfs_dirent * parent_sd,
+ const char * name)
+{
+ struct sysfs_dirent *sd;
+
+ list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
+ if (sd->s_element) {
+ if (!strcmp(sysfs_get_name(sd), name))
+ return sd;
+ }
+ }
+ return NULL;
+}
+
+/* Unhashes the dentry corresponding to given sysfs_dirent
+ * Called with parent inode's i_sem held.
+ */
+void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
+{
+ struct dentry * dentry = sd->s_dentry;
+
+ if (dentry) {
+ spin_lock(&dcache_lock);
+ dget_locked(dentry);
+ if (!(d_unhashed(dentry) && dentry->d_inode)) {
+ __d_drop(dentry);
+ spin_unlock(&dcache_lock);
+ simple_unlink(parent->d_inode, dentry);
+ } else {
+ spin_unlock(&dcache_lock);
+ dput(dentry);
+ }
+ }
+}
+
void sysfs_hash_and_remove(struct dentry * dir, const char * name)
{
- struct dentry * victim;
+ struct sysfs_dirent * sd;
down(&dir->d_inode->i_sem);
- victim = sysfs_get_dentry(dir,name);
- if (!IS_ERR(victim)) {
- /* make sure dentry is really there */
- if (victim->d_inode &&
- (victim->d_parent->d_inode == dir->d_inode)) {
- pr_debug("sysfs: Removing %s (%d)\n", victim->d_name.name,
- atomic_read(&victim->d_count));
-
- d_drop(victim);
- /* release the target kobject in case of
- * a symlink
- */
- if (S_ISLNK(victim->d_inode->i_mode))
- kobject_put(victim->d_fsdata);
- simple_unlink(dir->d_inode,victim);
- }
- /*
- * Drop reference from sysfs_get_dentry() above.
- */
- dput(victim);
+ sd = sysfs_find_dirent(dir->d_fsdata, name);
+ if (sd) {
+ list_del_init(&sd->s_sibling);
+ sysfs_drop_dentry(sd, dir);
+ sysfs_put(sd);
}
up(&dir->d_inode->i_sem);
}
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696
^ permalink raw reply [flat|nested] 7+ messages in thread
* [2.6.6-mm3] sysfs-leaves-bin.patch
2004-05-17 12:06 ` [2.6.6-mm3] sysfs-leaves-file.patch Maneesh Soni
@ 2004-05-17 12:07 ` Maneesh Soni
2004-05-17 12:07 ` [2.6.6-mm3] sysfs-leaves-symlink.patch Maneesh Soni
0 siblings, 1 reply; 7+ messages in thread
From: Maneesh Soni @ 2004-05-17 12:07 UTC (permalink / raw)
To: Andrew Morton; +Cc: Greg KH, LKML
=> changes in version 0.6
o Re-diffed for 2.6.6-mm3
=> changes in version 0.5
o Changes to accomodate latest changes in sysfs like doing
module_get/put while open() and release() functions.
=> changes in version 0.4
o Made necessary changes for checking DCACHE_SYSFS_CONNECTED flag while
opening the sysfs file in open() and a few changes in variable names.
=> changes in version 0.3
o Nil, just re-diffed
=> changes in version 0.2
o Nil, just re-diffed
o This patch contains changes required for bin attribute files.
fs/sysfs/bin.c | 52 +++++++++++++++++++---------------------------------
1 files changed, 19 insertions(+), 33 deletions(-)
diff -puN fs/sysfs/bin.c~sysfs-leaves-bin fs/sysfs/bin.c
--- linux-2.6.6-mm3/fs/sysfs/bin.c~sysfs-leaves-bin 2004-05-17 15:29:29.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/bin.c 2004-05-17 15:29:29.000000000 +0530
@@ -17,8 +17,10 @@
static int
fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count)
{
- struct bin_attribute * attr = dentry->d_fsdata;
- struct kobject * kobj = dentry->d_parent->d_fsdata;
+ struct sysfs_dirent * attr_sd = dentry->d_fsdata;
+ struct bin_attribute * attr = attr_sd->s_element;
+ struct sysfs_dirent * kobj_sd = dentry->d_parent->d_fsdata;
+ struct kobject * kobj = kobj_sd->s_element;
return attr->read(kobj, buffer, off, count);
}
@@ -60,8 +62,10 @@ read(struct file * file, char __user * u
static int
flush_write(struct dentry *dentry, char *buffer, loff_t offset, size_t count)
{
- struct bin_attribute *attr = dentry->d_fsdata;
- struct kobject *kobj = dentry->d_parent->d_fsdata;
+ struct sysfs_dirent * attr_sd = dentry->d_fsdata;
+ struct bin_attribute * attr = attr_sd->s_element;
+ struct sysfs_dirent * kobj_sd = dentry->d_parent->d_fsdata;
+ struct kobject * kobj = kobj_sd->s_element;
return attr->write(kobj, buffer, offset, count);
}
@@ -95,7 +99,8 @@ static ssize_t write(struct file * file,
static int open(struct inode * inode, struct file * file)
{
struct kobject *kobj = sysfs_get_kobject(file->f_dentry->d_parent);
- struct bin_attribute * attr = file->f_dentry->d_fsdata;
+ struct sysfs_dirent * attr_sd = file->f_dentry->d_fsdata;
+ struct bin_attribute * attr = attr_sd->s_element;
int error = -EINVAL;
if (!kobj || !attr)
@@ -130,8 +135,10 @@ static int open(struct inode * inode, st
static int release(struct inode * inode, struct file * file)
{
- struct kobject * kobj = file->f_dentry->d_parent->d_fsdata;
- struct bin_attribute * attr = file->f_dentry->d_fsdata;
+ struct sysfs_dirent * sd = file->f_dentry->d_parent->d_fsdata;
+ struct kobject * kobj = sd->s_element;
+ struct sysfs_dirent * attr_sd = file->f_dentry->d_fsdata;
+ struct bin_attribute * attr = attr_sd->s_element;
u8 * buffer = file->private_data;
if (kobj)
@@ -141,7 +148,7 @@ static int release(struct inode * inode,
return 0;
}
-static struct file_operations bin_fops = {
+struct file_operations bin_fops = {
.read = read,
.write = write,
.llseek = generic_file_llseek,
@@ -158,31 +165,10 @@ static struct file_operations bin_fops =
int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr)
{
- struct dentry * dentry;
- struct dentry * parent;
- int error = 0;
-
- if (!kobj || !attr)
- return -EINVAL;
-
- parent = kobj->dentry;
-
- down(&parent->d_inode->i_sem);
- dentry = sysfs_get_dentry(parent,attr->attr.name);
- if (!IS_ERR(dentry)) {
- dentry->d_fsdata = (void *)attr;
- error = sysfs_create(dentry,
- (attr->attr.mode & S_IALLUGO) | S_IFREG,
- NULL);
- if (!error) {
- dentry->d_inode->i_size = attr->size;
- dentry->d_inode->i_fop = &bin_fops;
- }
- dput(dentry);
- } else
- error = PTR_ERR(dentry);
- up(&parent->d_inode->i_sem);
- return error;
+ if (kobj && kobj->dentry && attr)
+ return sysfs_add_file(kobj->dentry, &attr->attr,
+ SYSFS_KOBJ_BIN_ATTR);
+ return -EINVAL;
}
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696
^ permalink raw reply [flat|nested] 7+ messages in thread
* [2.6.6-mm3] sysfs-leaves-symlink.patch
2004-05-17 12:07 ` [2.6.6-mm3] sysfs-leaves-bin.patch Maneesh Soni
@ 2004-05-17 12:07 ` Maneesh Soni
2004-05-17 12:08 ` [2.6.6-mm3] sysfs-leaves-misc.patch Maneesh Soni
0 siblings, 1 reply; 7+ messages in thread
From: Maneesh Soni @ 2004-05-17 12:07 UTC (permalink / raw)
To: Andrew Morton; +Cc: Greg KH, LKML
=> changes in version 0.6
o Re-diffed for 2.6.6-mm3
=> changes in version 0.5
o Use a new struct sysfs_symlink to save information
about the symlink name and the pointer to target kobject.
This was required to accomodate the latest changes in symlink
code in sysfs which implements readlink and follow_link
operations.
=> changes in version 0.4
o Nil, just re-diffed
=> changes in version 0.3
o Nil, just re-diffed
=> changes in version 0.2
o symlink name passed to sysfs_create_link() can be destroyed by the
caller. So, the symlink name should be allocated and copied to the
corresponding sysfs dirent instead of directly using the given name
string. The allocated string is freed when the corresponding sysfs_dirent
is freed through sysfs_put()
=================
o sysfs_create_link() now does not create a dentry but allocates a
sysfs_dirent and links it to the parent kobject.
o sysfs_dirent corresponding to symlink has an array of two string. One of
them is the name of the symlink and the second one is the target path of the
symlink
fs/sysfs/symlink.c | 42 +++++++++++++++++++++++++++++-------------
1 files changed, 29 insertions(+), 13 deletions(-)
diff -puN fs/sysfs/symlink.c~sysfs-leaves-symlink fs/sysfs/symlink.c
--- linux-2.6.6-mm3/fs/sysfs/symlink.c~sysfs-leaves-symlink 2004-05-17 15:29:26.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/symlink.c 2004-05-17 15:29:26.000000000 +0530
@@ -13,7 +13,7 @@ static struct inode_operations sysfs_sym
.follow_link = sysfs_follow_link,
};
-static int init_symlink(struct inode * inode)
+int init_symlink(struct inode * inode)
{
inode->i_op = &sysfs_symlink_inode_operations;
return 0;
@@ -53,6 +53,30 @@ static void fill_object_path(struct kobj
}
}
+static int sysfs_add_link(struct sysfs_dirent * parent_sd, char * name,
+ struct kobject * target)
+{
+ struct sysfs_dirent * sd;
+ struct sysfs_symlink * sl;
+
+ sl = kmalloc(sizeof(*sl), GFP_KERNEL);
+ if (!sl)
+ return -ENOMEM;
+
+ sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL);
+ strcpy(sl->link_name, name);
+ sl->target_kobj = kobject_get(target);
+
+ sd = sysfs_new_dirent(parent_sd, sl, SYSFS_KOBJ_LINK);
+ if (sd) {
+ sd->s_mode = S_IFLNK|S_IRWXUGO;
+ return 0;
+ }
+
+ kfree(sl);
+ return -ENOMEM;
+}
+
/**
* sysfs_create_link - create symlink between two objects.
* @kobj: object whose directory we're creating the link in.
@@ -62,21 +86,13 @@ static void fill_object_path(struct kobj
int sysfs_create_link(struct kobject * kobj, struct kobject * target, char * name)
{
struct dentry * dentry = kobj->dentry;
- struct dentry * d;
int error = 0;
+ if (!name)
+ return -EINVAL;
+
down(&dentry->d_inode->i_sem);
- d = sysfs_get_dentry(dentry,name);
- if (!IS_ERR(d)) {
- error = sysfs_create(d, S_IFLNK|S_IRWXUGO, init_symlink);
- if (!error)
- /*
- * associate the link dentry with the target kobject
- */
- d->d_fsdata = kobject_get(target);
- dput(d);
- } else
- error = PTR_ERR(d);
+ error = sysfs_add_link(dentry->d_fsdata, name, target);
up(&dentry->d_inode->i_sem);
return error;
}
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696
^ permalink raw reply [flat|nested] 7+ messages in thread
* [2.6.6-mm3] sysfs-leaves-misc.patch
2004-05-17 12:07 ` [2.6.6-mm3] sysfs-leaves-symlink.patch Maneesh Soni
@ 2004-05-17 12:08 ` Maneesh Soni
0 siblings, 0 replies; 7+ messages in thread
From: Maneesh Soni @ 2004-05-17 12:08 UTC (permalink / raw)
To: Andrew Morton; +Cc: Greg KH, LKML
=> changes in version 0.6
o Re-diffed for 2.6.6-mm3
o Removed sysfs_remove_dirent()
o Added extern definition for the new sysfs_drop_dentry()
=> changes in version 0.5
o New additions like struct sysfs_symlink. and changes to
sysfs_get_kobject()
=> changes in version 0.4
o Nil, just re-diffed
=> changes in version 0.3
o Corrected dentry ref counting for sysfs_create_group() and
sysfs_remove_group().
=> changes in Version 0.2
o Provided error checking after sysfs_get_dentry() call in
sysfs_remove_group().
o kfree the symlink name while freeing the corresponding sysfs_dirent in
sysfs_put().
================
o This patch has the changes required for attribute groups and misc. routines.
fs/sysfs/group.c | 18 ++++++++-----
fs/sysfs/sysfs.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 82 insertions(+), 10 deletions(-)
diff -puN fs/sysfs/group.c~sysfs-leaves-misc fs/sysfs/group.c
--- linux-2.6.6-mm3/fs/sysfs/group.c~sysfs-leaves-misc 2004-05-17 15:29:32.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/group.c 2004-05-17 15:29:32.000000000 +0530
@@ -10,7 +10,7 @@
#include <linux/kobject.h>
#include <linux/module.h>
-#include <linux/dcache.h>
+#include <linux/fs.h>
#include <linux/err.h>
#include "sysfs.h"
@@ -31,7 +31,7 @@ static int create_files(struct dentry *
int error = 0;
for (attr = grp->attrs; *attr && !error; attr++) {
- error = sysfs_add_file(dir,*attr);
+ error = sysfs_add_file(dir, *attr, SYSFS_KOBJ_ATTR);
}
if (error)
remove_files(dir,grp);
@@ -70,11 +70,15 @@ void sysfs_remove_group(struct kobject *
else
dir = dget(kobj->dentry);
- remove_files(dir,grp);
- if (grp->name)
- sysfs_remove_subdir(dir);
- /* release the ref. taken in this routine */
- dput(dir);
+ if (!IS_ERR(dir)) {
+ if (dir && dir->d_inode) {
+ remove_files(dir,grp);
+ if (grp->name)
+ sysfs_remove_subdir(dir);
+ /* release the ref. taken in this routine */
+ dput(dir);
+ }
+ }
}
diff -puN fs/sysfs/sysfs.h~sysfs-leaves-misc fs/sysfs/sysfs.h
--- linux-2.6.6-mm3/fs/sysfs/sysfs.h~sysfs-leaves-misc 2004-05-17 15:29:32.000000000 +0530
+++ linux-2.6.6-mm3-maneesh/fs/sysfs/sysfs.h 2004-05-17 15:56:18.000000000 +0530
@@ -1,28 +1,96 @@
+#include <linux/fs.h>
extern struct vfsmount * sysfs_mount;
+extern struct super_block * sysfs_sb;
extern struct inode * sysfs_new_inode(mode_t mode);
extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
extern struct dentry * sysfs_get_dentry(struct dentry *, const char *);
+extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
-extern int sysfs_add_file(struct dentry * dir, const struct attribute * attr);
extern void sysfs_hash_and_remove(struct dentry * dir, const char * name);
extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
extern void sysfs_remove_subdir(struct dentry *);
+extern int sysfs_dir_open(struct inode *inode, struct file *file);
+extern int sysfs_dir_close(struct inode *inode, struct file *file);
+extern loff_t sysfs_dir_lseek(struct file *, loff_t, int);
+extern int sysfs_readdir(struct file *, void *, filldir_t);
+extern void sysfs_umount_begin(struct super_block *);
+extern const unsigned char * sysfs_get_name(struct sysfs_dirent *);
+extern struct dentry * sysfs_lookup(struct inode *, struct dentry *, struct nameidata *);
+extern void sysfs_drop_dentry(struct sysfs_dirent *, struct dentry *);
+extern int sysfs_symlink(struct inode *, struct dentry *, const char *);
+extern int init_symlink(struct inode *);
extern int sysfs_readlink(struct dentry *, char __user *, int );
extern int sysfs_follow_link(struct dentry *, struct nameidata *);
extern struct rw_semaphore sysfs_rename_sem;
+extern struct file_operations sysfs_file_operations;
+extern struct file_operations bin_fops;
+extern struct inode_operations sysfs_dir_inode_operations;
+extern struct file_operations sysfs_dir_operations;
+
+struct sysfs_symlink {
+ char * link_name;
+ struct kobject * target_kobj;
+};
+
+static inline
+struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent * p, void * e, int t)
+{
+ struct sysfs_dirent * sd;
+
+ sd = kmalloc(sizeof(*sd), GFP_KERNEL);
+ if (!sd)
+ return NULL;
+ memset(sd, 0, sizeof(*sd));
+ atomic_set(&sd->s_count, 1);
+ sd->s_element = e;
+ sd->s_type = t;
+ sd->s_dentry = NULL;
+ INIT_LIST_HEAD(&sd->s_children);
+ list_add(&sd->s_sibling, &p->s_children);
+
+ return sd;
+}
+
+static inline 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 inline void sysfs_put(struct sysfs_dirent * sd)
+{
+ if (atomic_dec_and_test(&sd->s_count)) {
+ if (sd->s_type & SYSFS_KOBJ_LINK) {
+ struct sysfs_symlink * sl = sd->s_element;
+ kfree(sl->link_name);
+ kobject_put(sl->target_kobj);
+ kfree(sl);
+ }
+ kfree(sd);
+ }
+}
static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
{
struct kobject * kobj = NULL;
spin_lock(&dcache_lock);
- if (!d_unhashed(dentry))
- kobj = kobject_get(dentry->d_fsdata);
+ if (!d_unhashed(dentry)) {
+ struct sysfs_dirent * sd = dentry->d_fsdata;
+ if (sd->s_type & SYSFS_KOBJ_LINK) {
+ struct sysfs_symlink * sl = sd->s_element;
+ kobj = kobject_get(sl->target_kobj);
+ } else
+ kobj = kobject_get(sd->s_element);
+ }
spin_unlock(&dcache_lock);
return kobj;
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044999 Fax: 91-80-25268553
T/L : 9243696
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-05-17 12:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-17 12:04 [2.6.6-mm3] sysfs backing store ver 0.6 Maneesh Soni
2004-05-17 12:05 ` [2.6.6-mm3] sysfs-leaves-mount.patch Maneesh Soni
2004-05-17 12:06 ` [2.6.6-mm3] sysfs-leaves-dir.patch Maneesh Soni
2004-05-17 12:06 ` [2.6.6-mm3] sysfs-leaves-file.patch Maneesh Soni
2004-05-17 12:07 ` [2.6.6-mm3] sysfs-leaves-bin.patch Maneesh Soni
2004-05-17 12:07 ` [2.6.6-mm3] sysfs-leaves-symlink.patch Maneesh Soni
2004-05-17 12:08 ` [2.6.6-mm3] sysfs-leaves-misc.patch Maneesh Soni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).