diff options
Diffstat (limited to 'fs/sysfs')
| -rw-r--r-- | fs/sysfs/bin.c | 13 | ||||
| -rw-r--r-- | fs/sysfs/dir.c | 12 | ||||
| -rw-r--r-- | fs/sysfs/inode.c | 26 | ||||
| -rw-r--r-- | fs/sysfs/symlink.c | 14 | ||||
| -rw-r--r-- | fs/sysfs/sysfs.h | 2 |
5 files changed, 47 insertions, 20 deletions
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c index c16a93c353c0..98022e41cda1 100644 --- a/fs/sysfs/bin.c +++ b/fs/sysfs/bin.c | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | #include <linux/errno.h> | 11 | #include <linux/errno.h> |
| 12 | #include <linux/fs.h> | 12 | #include <linux/fs.h> |
| 13 | #include <linux/kernel.h> | ||
| 13 | #include <linux/kobject.h> | 14 | #include <linux/kobject.h> |
| 14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
| 15 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
| @@ -176,7 +177,6 @@ const struct file_operations bin_fops = { | |||
| 176 | * sysfs_create_bin_file - create binary file for object. | 177 | * sysfs_create_bin_file - create binary file for object. |
| 177 | * @kobj: object. | 178 | * @kobj: object. |
| 178 | * @attr: attribute descriptor. | 179 | * @attr: attribute descriptor. |
| 179 | * | ||
| 180 | */ | 180 | */ |
| 181 | 181 | ||
| 182 | int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr) | 182 | int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr) |
| @@ -191,13 +191,16 @@ int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr) | |||
| 191 | * sysfs_remove_bin_file - remove binary file for object. | 191 | * sysfs_remove_bin_file - remove binary file for object. |
| 192 | * @kobj: object. | 192 | * @kobj: object. |
| 193 | * @attr: attribute descriptor. | 193 | * @attr: attribute descriptor. |
| 194 | * | ||
| 195 | */ | 194 | */ |
| 196 | 195 | ||
| 197 | int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr) | 196 | void sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr) |
| 198 | { | 197 | { |
| 199 | sysfs_hash_and_remove(kobj->dentry,attr->attr.name); | 198 | if (sysfs_hash_and_remove(kobj->dentry, attr->attr.name) < 0) { |
| 200 | return 0; | 199 | printk(KERN_ERR "%s: " |
| 200 | "bad dentry or inode or no such file: \"%s\"\n", | ||
| 201 | __FUNCTION__, attr->attr.name); | ||
| 202 | dump_stack(); | ||
| 203 | } | ||
| 201 | } | 204 | } |
| 202 | 205 | ||
| 203 | EXPORT_SYMBOL_GPL(sysfs_create_bin_file); | 206 | EXPORT_SYMBOL_GPL(sysfs_create_bin_file); |
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 610b5bdbe75b..5f3d725d1125 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
| @@ -43,7 +43,7 @@ static struct sysfs_dirent * sysfs_new_dirent(struct sysfs_dirent * parent_sd, | |||
| 43 | 43 | ||
| 44 | memset(sd, 0, sizeof(*sd)); | 44 | memset(sd, 0, sizeof(*sd)); |
| 45 | atomic_set(&sd->s_count, 1); | 45 | atomic_set(&sd->s_count, 1); |
| 46 | atomic_set(&sd->s_event, 0); | 46 | atomic_set(&sd->s_event, 1); |
| 47 | INIT_LIST_HEAD(&sd->s_children); | 47 | INIT_LIST_HEAD(&sd->s_children); |
| 48 | list_add(&sd->s_sibling, &parent_sd->s_children); | 48 | list_add(&sd->s_sibling, &parent_sd->s_children); |
| 49 | sd->s_element = element; | 49 | sd->s_element = element; |
| @@ -430,10 +430,9 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
| 430 | i++; | 430 | i++; |
| 431 | /* fallthrough */ | 431 | /* fallthrough */ |
| 432 | default: | 432 | default: |
| 433 | if (filp->f_pos == 2) { | 433 | if (filp->f_pos == 2) |
| 434 | list_del(q); | 434 | list_move(q, &parent_sd->s_children); |
| 435 | list_add(q, &parent_sd->s_children); | 435 | |
| 436 | } | ||
| 437 | for (p=q->next; p!= &parent_sd->s_children; p=p->next) { | 436 | for (p=q->next; p!= &parent_sd->s_children; p=p->next) { |
| 438 | struct sysfs_dirent *next; | 437 | struct sysfs_dirent *next; |
| 439 | const char * name; | 438 | const char * name; |
| @@ -455,8 +454,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
| 455 | dt_type(next)) < 0) | 454 | dt_type(next)) < 0) |
| 456 | return 0; | 455 | return 0; |
| 457 | 456 | ||
| 458 | list_del(q); | 457 | list_move(q, p); |
| 459 | list_add(q, p); | ||
| 460 | p = q; | 458 | p = q; |
| 461 | filp->f_pos++; | 459 | filp->f_pos++; |
| 462 | } | 460 | } |
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index f0b347bd12ca..e79e38d52c00 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
| @@ -12,11 +12,12 @@ | |||
| 12 | #include <linux/namei.h> | 12 | #include <linux/namei.h> |
| 13 | #include <linux/backing-dev.h> | 13 | #include <linux/backing-dev.h> |
| 14 | #include <linux/capability.h> | 14 | #include <linux/capability.h> |
| 15 | #include <linux/errno.h> | ||
| 15 | #include "sysfs.h" | 16 | #include "sysfs.h" |
| 16 | 17 | ||
| 17 | extern struct super_block * sysfs_sb; | 18 | extern struct super_block * sysfs_sb; |
| 18 | 19 | ||
| 19 | static struct address_space_operations sysfs_aops = { | 20 | static const struct address_space_operations sysfs_aops = { |
| 20 | .readpage = simple_readpage, | 21 | .readpage = simple_readpage, |
| 21 | .prepare_write = simple_prepare_write, | 22 | .prepare_write = simple_prepare_write, |
| 22 | .commit_write = simple_commit_write | 23 | .commit_write = simple_commit_write |
| @@ -109,15 +110,26 @@ static inline void set_inode_attr(struct inode * inode, struct iattr * iattr) | |||
| 109 | inode->i_ctime = iattr->ia_ctime; | 110 | inode->i_ctime = iattr->ia_ctime; |
| 110 | } | 111 | } |
| 111 | 112 | ||
| 113 | |||
| 114 | /* | ||
| 115 | * sysfs has a different i_mutex lock order behavior for i_mutex than other | ||
| 116 | * filesystems; sysfs i_mutex is called in many places with subsystem locks | ||
| 117 | * held. At the same time, many of the VFS locking rules do not apply to | ||
| 118 | * sysfs at all (cross directory rename for example). To untangle this mess | ||
| 119 | * (which gives false positives in lockdep), we're giving sysfs inodes their | ||
| 120 | * own class for i_mutex. | ||
| 121 | */ | ||
| 122 | static struct lock_class_key sysfs_inode_imutex_key; | ||
| 123 | |||
| 112 | struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent * sd) | 124 | struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent * sd) |
| 113 | { | 125 | { |
| 114 | struct inode * inode = new_inode(sysfs_sb); | 126 | struct inode * inode = new_inode(sysfs_sb); |
| 115 | if (inode) { | 127 | if (inode) { |
| 116 | inode->i_blksize = PAGE_CACHE_SIZE; | ||
| 117 | inode->i_blocks = 0; | 128 | inode->i_blocks = 0; |
| 118 | inode->i_mapping->a_ops = &sysfs_aops; | 129 | inode->i_mapping->a_ops = &sysfs_aops; |
| 119 | inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; | 130 | inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; |
| 120 | inode->i_op = &sysfs_inode_operations; | 131 | inode->i_op = &sysfs_inode_operations; |
| 132 | lockdep_set_class(&inode->i_mutex, &sysfs_inode_imutex_key); | ||
| 121 | 133 | ||
| 122 | if (sd->s_iattr) { | 134 | if (sd->s_iattr) { |
| 123 | /* sysfs_dirent has non-default attributes | 135 | /* sysfs_dirent has non-default attributes |
| @@ -222,17 +234,18 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent) | |||
| 222 | } | 234 | } |
| 223 | } | 235 | } |
| 224 | 236 | ||
| 225 | void sysfs_hash_and_remove(struct dentry * dir, const char * name) | 237 | int sysfs_hash_and_remove(struct dentry * dir, const char * name) |
| 226 | { | 238 | { |
| 227 | struct sysfs_dirent * sd; | 239 | struct sysfs_dirent * sd; |
| 228 | struct sysfs_dirent * parent_sd; | 240 | struct sysfs_dirent * parent_sd; |
| 241 | int found = 0; | ||
| 229 | 242 | ||
| 230 | if (!dir) | 243 | if (!dir) |
| 231 | return; | 244 | return -ENOENT; |
| 232 | 245 | ||
| 233 | if (dir->d_inode == NULL) | 246 | if (dir->d_inode == NULL) |
| 234 | /* no inode means this hasn't been made visible yet */ | 247 | /* no inode means this hasn't been made visible yet */ |
| 235 | return; | 248 | return -ENOENT; |
| 236 | 249 | ||
| 237 | parent_sd = dir->d_fsdata; | 250 | parent_sd = dir->d_fsdata; |
| 238 | mutex_lock(&dir->d_inode->i_mutex); | 251 | mutex_lock(&dir->d_inode->i_mutex); |
| @@ -243,8 +256,11 @@ void sysfs_hash_and_remove(struct dentry * dir, const char * name) | |||
| 243 | list_del_init(&sd->s_sibling); | 256 | list_del_init(&sd->s_sibling); |
| 244 | sysfs_drop_dentry(sd, dir); | 257 | sysfs_drop_dentry(sd, dir); |
| 245 | sysfs_put(sd); | 258 | sysfs_put(sd); |
| 259 | found = 1; | ||
| 246 | break; | 260 | break; |
| 247 | } | 261 | } |
| 248 | } | 262 | } |
| 249 | mutex_unlock(&dir->d_inode->i_mutex); | 263 | mutex_unlock(&dir->d_inode->i_mutex); |
| 264 | |||
| 265 | return found ? 0 : -ENOENT; | ||
| 250 | } | 266 | } |
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c index d2eac3ceed5f..f50e3cc2ded8 100644 --- a/fs/sysfs/symlink.c +++ b/fs/sysfs/symlink.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | #include <linux/fs.h> | 5 | #include <linux/fs.h> |
| 6 | #include <linux/mount.h> | ||
| 6 | #include <linux/module.h> | 7 | #include <linux/module.h> |
| 7 | #include <linux/kobject.h> | 8 | #include <linux/kobject.h> |
| 8 | #include <linux/namei.h> | 9 | #include <linux/namei.h> |
| @@ -82,10 +83,19 @@ exit1: | |||
| 82 | */ | 83 | */ |
| 83 | int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name) | 84 | int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name) |
| 84 | { | 85 | { |
| 85 | struct dentry * dentry = kobj->dentry; | 86 | struct dentry *dentry = NULL; |
| 86 | int error = -EEXIST; | 87 | int error = -EEXIST; |
| 87 | 88 | ||
| 88 | BUG_ON(!kobj || !kobj->dentry || !name); | 89 | BUG_ON(!name); |
| 90 | |||
| 91 | if (!kobj) { | ||
| 92 | if (sysfs_mount && sysfs_mount->mnt_sb) | ||
| 93 | dentry = sysfs_mount->mnt_sb->s_root; | ||
| 94 | } else | ||
| 95 | dentry = kobj->dentry; | ||
| 96 | |||
| 97 | if (!dentry) | ||
| 98 | return -EFAULT; | ||
| 89 | 99 | ||
| 90 | mutex_lock(&dentry->d_inode->i_mutex); | 100 | mutex_lock(&dentry->d_inode->i_mutex); |
| 91 | if (!sysfs_dirent_exist(dentry->d_fsdata, name)) | 101 | if (!sysfs_dirent_exist(dentry->d_fsdata, name)) |
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 3651ffb5ec09..6f3d6bd52887 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
| @@ -10,7 +10,7 @@ extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *, | |||
| 10 | umode_t, int); | 10 | umode_t, int); |
| 11 | 11 | ||
| 12 | extern int sysfs_add_file(struct dentry *, const struct attribute *, int); | 12 | extern int sysfs_add_file(struct dentry *, const struct attribute *, int); |
| 13 | extern void sysfs_hash_and_remove(struct dentry * dir, const char * name); | 13 | extern int sysfs_hash_and_remove(struct dentry * dir, const char * name); |
| 14 | extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name); | 14 | extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name); |
| 15 | 15 | ||
| 16 | extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **); | 16 | extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **); |
