aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-08-20 08:36:29 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:51:07 -0400
commit372e88bd1922228e0a55228f6dc8e311d1696fa0 (patch)
tree3f078e13b55a4fc20fe0df5c7e85045554e536bf /fs
parent253280267a7f1ced0c434fb24b7bef92d7d22628 (diff)
sysfs: Move all of inode initialization into sysfs_init_inode
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Tejun Heo <htejun@gmail.com> Cc: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/sysfs/dir.c37
-rw-r--r--fs/sysfs/inode.c48
-rw-r--r--fs/sysfs/mount.c5
3 files changed, 45 insertions, 45 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 54ca4bc02dcf..5a70a93fc2f7 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -748,24 +748,12 @@ int sysfs_create_dir(struct kobject * kobj)
748 return error; 748 return error;
749} 749}
750 750
751static int sysfs_count_nlink(struct sysfs_dirent *sd)
752{
753 struct sysfs_dirent *child;
754 int nr = 0;
755
756 for (child = sd->s_children; child; child = child->s_sibling)
757 if (sysfs_type(child) == SYSFS_DIR)
758 nr++;
759 return nr + 2;
760}
761
762static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry, 751static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
763 struct nameidata *nd) 752 struct nameidata *nd)
764{ 753{
765 struct dentry *ret = NULL; 754 struct dentry *ret = NULL;
766 struct sysfs_dirent *parent_sd = dentry->d_parent->d_fsdata; 755 struct sysfs_dirent *parent_sd = dentry->d_parent->d_fsdata;
767 struct sysfs_dirent *sd; 756 struct sysfs_dirent *sd;
768 struct bin_attribute *bin_attr;
769 struct inode *inode; 757 struct inode *inode;
770 758
771 mutex_lock(&sysfs_mutex); 759 mutex_lock(&sysfs_mutex);
@@ -785,31 +773,6 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
785 goto out_unlock; 773 goto out_unlock;
786 } 774 }
787 775
788 if (inode->i_state & I_NEW) {
789 /* initialize inode according to type */
790 switch (sysfs_type(sd)) {
791 case SYSFS_DIR:
792 inode->i_op = &sysfs_dir_inode_operations;
793 inode->i_fop = &sysfs_dir_operations;
794 inode->i_nlink = sysfs_count_nlink(sd);
795 break;
796 case SYSFS_KOBJ_ATTR:
797 inode->i_size = PAGE_SIZE;
798 inode->i_fop = &sysfs_file_operations;
799 break;
800 case SYSFS_KOBJ_BIN_ATTR:
801 bin_attr = sd->s_elem.bin_attr.bin_attr;
802 inode->i_size = bin_attr->size;
803 inode->i_fop = &bin_fops;
804 break;
805 case SYSFS_KOBJ_LINK:
806 inode->i_op = &sysfs_symlink_inode_operations;
807 break;
808 default:
809 BUG();
810 }
811 }
812
813 sysfs_instantiate(dentry, inode); 776 sysfs_instantiate(dentry, inode);
814 sysfs_attach_dentry(sd, dentry); 777 sysfs_attach_dentry(sd, dentry);
815 778
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index e22db6cd4df7..200e1bf6f932 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -122,8 +122,22 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
122 */ 122 */
123static struct lock_class_key sysfs_inode_imutex_key; 123static struct lock_class_key sysfs_inode_imutex_key;
124 124
125static int sysfs_count_nlink(struct sysfs_dirent *sd)
126{
127 struct sysfs_dirent *child;
128 int nr = 0;
129
130 for (child = sd->s_children; child; child = child->s_sibling)
131 if (sysfs_type(child) == SYSFS_DIR)
132 nr++;
133
134 return nr + 2;
135}
136
125static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) 137static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
126{ 138{
139 struct bin_attribute *bin_attr;
140
127 inode->i_blocks = 0; 141 inode->i_blocks = 0;
128 inode->i_mapping->a_ops = &sysfs_aops; 142 inode->i_mapping->a_ops = &sysfs_aops;
129 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 143 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
@@ -139,6 +153,37 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
139 set_inode_attr(inode, sd->s_iattr); 153 set_inode_attr(inode, sd->s_iattr);
140 } else 154 } else
141 set_default_inode_attr(inode, sd->s_mode); 155 set_default_inode_attr(inode, sd->s_mode);
156
157
158 /* initialize inode according to type */
159 switch (sysfs_type(sd)) {
160 case SYSFS_ROOT:
161 inode->i_op = &sysfs_dir_inode_operations;
162 inode->i_fop = &sysfs_dir_operations;
163 inc_nlink(inode); /* directory, account for "." */
164 break;
165 case SYSFS_DIR:
166 inode->i_op = &sysfs_dir_inode_operations;
167 inode->i_fop = &sysfs_dir_operations;
168 inode->i_nlink = sysfs_count_nlink(sd);
169 break;
170 case SYSFS_KOBJ_ATTR:
171 inode->i_size = PAGE_SIZE;
172 inode->i_fop = &sysfs_file_operations;
173 break;
174 case SYSFS_KOBJ_BIN_ATTR:
175 bin_attr = sd->s_elem.bin_attr.bin_attr;
176 inode->i_size = bin_attr->size;
177 inode->i_fop = &bin_fops;
178 break;
179 case SYSFS_KOBJ_LINK:
180 inode->i_op = &sysfs_symlink_inode_operations;
181 break;
182 default:
183 BUG();
184 }
185
186 unlock_new_inode(inode);
142} 187}
143 188
144/** 189/**
@@ -180,9 +225,6 @@ void sysfs_instantiate(struct dentry *dentry, struct inode *inode)
180{ 225{
181 BUG_ON(!dentry || dentry->d_inode); 226 BUG_ON(!dentry || dentry->d_inode);
182 227
183 if (inode->i_state & I_NEW)
184 unlock_new_inode(inode);
185
186 d_instantiate(dentry, inode); 228 d_instantiate(dentry, inode);
187} 229}
188 230
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 119f39da1ae1..92f407fb1263 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -49,11 +49,6 @@ static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
49 return -ENOMEM; 49 return -ENOMEM;
50 } 50 }
51 51
52 inode->i_op = &sysfs_dir_inode_operations;
53 inode->i_fop = &sysfs_dir_operations;
54 inc_nlink(inode); /* directory, account for "." */
55 unlock_new_inode(inode);
56
57 /* instantiate and link root dentry */ 52 /* instantiate and link root dentry */
58 root = d_alloc_root(inode); 53 root = d_alloc_root(inode);
59 if (!root) { 54 if (!root) {