aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/dir.c37
-rw-r--r--fs/sysfs/file.c17
-rw-r--r--fs/sysfs/inode.c9
-rw-r--r--fs/sysfs/symlink.c5
4 files changed, 34 insertions, 34 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 59734ba1ee60..49bd219275db 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -99,7 +99,7 @@ static int create_dir(struct kobject * k, struct dentry * p,
99 int error; 99 int error;
100 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; 100 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
101 101
102 down(&p->d_inode->i_sem); 102 mutex_lock(&p->d_inode->i_mutex);
103 *d = lookup_one_len(n, p, strlen(n)); 103 *d = lookup_one_len(n, p, strlen(n));
104 if (!IS_ERR(*d)) { 104 if (!IS_ERR(*d)) {
105 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, SYSFS_DIR); 105 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, SYSFS_DIR);
@@ -112,13 +112,17 @@ static int create_dir(struct kobject * k, struct dentry * p,
112 } 112 }
113 } 113 }
114 if (error && (error != -EEXIST)) { 114 if (error && (error != -EEXIST)) {
115 sysfs_put((*d)->d_fsdata); 115 struct sysfs_dirent *sd = (*d)->d_fsdata;
116 if (sd) {
117 list_del_init(&sd->s_sibling);
118 sysfs_put(sd);
119 }
116 d_drop(*d); 120 d_drop(*d);
117 } 121 }
118 dput(*d); 122 dput(*d);
119 } else 123 } else
120 error = PTR_ERR(*d); 124 error = PTR_ERR(*d);
121 up(&p->d_inode->i_sem); 125 mutex_unlock(&p->d_inode->i_mutex);
122 return error; 126 return error;
123} 127}
124 128
@@ -242,7 +246,7 @@ static void remove_dir(struct dentry * d)
242 struct dentry * parent = dget(d->d_parent); 246 struct dentry * parent = dget(d->d_parent);
243 struct sysfs_dirent * sd; 247 struct sysfs_dirent * sd;
244 248
245 down(&parent->d_inode->i_sem); 249 mutex_lock(&parent->d_inode->i_mutex);
246 d_delete(d); 250 d_delete(d);
247 sd = d->d_fsdata; 251 sd = d->d_fsdata;
248 list_del_init(&sd->s_sibling); 252 list_del_init(&sd->s_sibling);
@@ -253,7 +257,7 @@ static void remove_dir(struct dentry * d)
253 pr_debug(" o %s removing done (%d)\n",d->d_name.name, 257 pr_debug(" o %s removing done (%d)\n",d->d_name.name,
254 atomic_read(&d->d_count)); 258 atomic_read(&d->d_count));
255 259
256 up(&parent->d_inode->i_sem); 260 mutex_unlock(&parent->d_inode->i_mutex);
257 dput(parent); 261 dput(parent);
258} 262}
259 263
@@ -282,7 +286,7 @@ void sysfs_remove_dir(struct kobject * kobj)
282 return; 286 return;
283 287
284 pr_debug("sysfs %s: removing dir\n",dentry->d_name.name); 288 pr_debug("sysfs %s: removing dir\n",dentry->d_name.name);
285 down(&dentry->d_inode->i_sem); 289 mutex_lock(&dentry->d_inode->i_mutex);
286 parent_sd = dentry->d_fsdata; 290 parent_sd = dentry->d_fsdata;
287 list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) { 291 list_for_each_entry_safe(sd, tmp, &parent_sd->s_children, s_sibling) {
288 if (!sd->s_element || !(sd->s_type & SYSFS_NOT_PINNED)) 292 if (!sd->s_element || !(sd->s_type & SYSFS_NOT_PINNED))
@@ -291,7 +295,7 @@ void sysfs_remove_dir(struct kobject * kobj)
291 sysfs_drop_dentry(sd, dentry); 295 sysfs_drop_dentry(sd, dentry);
292 sysfs_put(sd); 296 sysfs_put(sd);
293 } 297 }
294 up(&dentry->d_inode->i_sem); 298 mutex_unlock(&dentry->d_inode->i_mutex);
295 299
296 remove_dir(dentry); 300 remove_dir(dentry);
297 /** 301 /**
@@ -314,7 +318,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
314 down_write(&sysfs_rename_sem); 318 down_write(&sysfs_rename_sem);
315 parent = kobj->parent->dentry; 319 parent = kobj->parent->dentry;
316 320
317 down(&parent->d_inode->i_sem); 321 mutex_lock(&parent->d_inode->i_mutex);
318 322
319 new_dentry = lookup_one_len(new_name, parent, strlen(new_name)); 323 new_dentry = lookup_one_len(new_name, parent, strlen(new_name));
320 if (!IS_ERR(new_dentry)) { 324 if (!IS_ERR(new_dentry)) {
@@ -330,7 +334,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
330 error = -EEXIST; 334 error = -EEXIST;
331 dput(new_dentry); 335 dput(new_dentry);
332 } 336 }
333 up(&parent->d_inode->i_sem); 337 mutex_unlock(&parent->d_inode->i_mutex);
334 up_write(&sysfs_rename_sem); 338 up_write(&sysfs_rename_sem);
335 339
336 return error; 340 return error;
@@ -341,9 +345,9 @@ static int sysfs_dir_open(struct inode *inode, struct file *file)
341 struct dentry * dentry = file->f_dentry; 345 struct dentry * dentry = file->f_dentry;
342 struct sysfs_dirent * parent_sd = dentry->d_fsdata; 346 struct sysfs_dirent * parent_sd = dentry->d_fsdata;
343 347
344 down(&dentry->d_inode->i_sem); 348 mutex_lock(&dentry->d_inode->i_mutex);
345 file->private_data = sysfs_new_dirent(parent_sd, NULL); 349 file->private_data = sysfs_new_dirent(parent_sd, NULL);
346 up(&dentry->d_inode->i_sem); 350 mutex_unlock(&dentry->d_inode->i_mutex);
347 351
348 return file->private_data ? 0 : -ENOMEM; 352 return file->private_data ? 0 : -ENOMEM;
349 353
@@ -354,9 +358,9 @@ static int sysfs_dir_close(struct inode *inode, struct file *file)
354 struct dentry * dentry = file->f_dentry; 358 struct dentry * dentry = file->f_dentry;
355 struct sysfs_dirent * cursor = file->private_data; 359 struct sysfs_dirent * cursor = file->private_data;
356 360
357 down(&dentry->d_inode->i_sem); 361 mutex_lock(&dentry->d_inode->i_mutex);
358 list_del_init(&cursor->s_sibling); 362 list_del_init(&cursor->s_sibling);
359 up(&dentry->d_inode->i_sem); 363 mutex_unlock(&dentry->d_inode->i_mutex);
360 364
361 release_sysfs_dirent(cursor); 365 release_sysfs_dirent(cursor);
362 366
@@ -432,7 +436,7 @@ static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)
432{ 436{
433 struct dentry * dentry = file->f_dentry; 437 struct dentry * dentry = file->f_dentry;
434 438
435 down(&dentry->d_inode->i_sem); 439 mutex_lock(&dentry->d_inode->i_mutex);
436 switch (origin) { 440 switch (origin) {
437 case 1: 441 case 1:
438 offset += file->f_pos; 442 offset += file->f_pos;
@@ -440,7 +444,7 @@ static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)
440 if (offset >= 0) 444 if (offset >= 0)
441 break; 445 break;
442 default: 446 default:
443 up(&file->f_dentry->d_inode->i_sem); 447 mutex_unlock(&file->f_dentry->d_inode->i_mutex);
444 return -EINVAL; 448 return -EINVAL;
445 } 449 }
446 if (offset != file->f_pos) { 450 if (offset != file->f_pos) {
@@ -464,7 +468,7 @@ static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)
464 list_add_tail(&cursor->s_sibling, p); 468 list_add_tail(&cursor->s_sibling, p);
465 } 469 }
466 } 470 }
467 up(&dentry->d_inode->i_sem); 471 mutex_unlock(&dentry->d_inode->i_mutex);
468 return offset; 472 return offset;
469} 473}
470 474
@@ -479,4 +483,3 @@ struct file_operations sysfs_dir_operations = {
479EXPORT_SYMBOL_GPL(sysfs_create_dir); 483EXPORT_SYMBOL_GPL(sysfs_create_dir);
480EXPORT_SYMBOL_GPL(sysfs_remove_dir); 484EXPORT_SYMBOL_GPL(sysfs_remove_dir);
481EXPORT_SYMBOL_GPL(sysfs_rename_dir); 485EXPORT_SYMBOL_GPL(sysfs_rename_dir);
482
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 4013d7905e84..d0e3d8495165 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -364,9 +364,9 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type)
364 umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; 364 umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
365 int error = 0; 365 int error = 0;
366 366
367 down(&dir->d_inode->i_sem); 367 mutex_lock(&dir->d_inode->i_mutex);
368 error = sysfs_make_dirent(parent_sd, NULL, (void *) attr, mode, type); 368 error = sysfs_make_dirent(parent_sd, NULL, (void *) attr, mode, type);
369 up(&dir->d_inode->i_sem); 369 mutex_unlock(&dir->d_inode->i_mutex);
370 370
371 return error; 371 return error;
372} 372}
@@ -398,7 +398,7 @@ int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
398 struct dentry * victim; 398 struct dentry * victim;
399 int res = -ENOENT; 399 int res = -ENOENT;
400 400
401 down(&dir->d_inode->i_sem); 401 mutex_lock(&dir->d_inode->i_mutex);
402 victim = lookup_one_len(attr->name, dir, strlen(attr->name)); 402 victim = lookup_one_len(attr->name, dir, strlen(attr->name));
403 if (!IS_ERR(victim)) { 403 if (!IS_ERR(victim)) {
404 /* make sure dentry is really there */ 404 /* make sure dentry is really there */
@@ -420,7 +420,7 @@ int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
420 */ 420 */
421 dput(victim); 421 dput(victim);
422 } 422 }
423 up(&dir->d_inode->i_sem); 423 mutex_unlock(&dir->d_inode->i_mutex);
424 424
425 return res; 425 return res;
426} 426}
@@ -441,22 +441,22 @@ int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
441 struct iattr newattrs; 441 struct iattr newattrs;
442 int res = -ENOENT; 442 int res = -ENOENT;
443 443
444 down(&dir->d_inode->i_sem); 444 mutex_lock(&dir->d_inode->i_mutex);
445 victim = lookup_one_len(attr->name, dir, strlen(attr->name)); 445 victim = lookup_one_len(attr->name, dir, strlen(attr->name));
446 if (!IS_ERR(victim)) { 446 if (!IS_ERR(victim)) {
447 if (victim->d_inode && 447 if (victim->d_inode &&
448 (victim->d_parent->d_inode == dir->d_inode)) { 448 (victim->d_parent->d_inode == dir->d_inode)) {
449 inode = victim->d_inode; 449 inode = victim->d_inode;
450 down(&inode->i_sem); 450 mutex_lock(&inode->i_mutex);
451 newattrs.ia_mode = (mode & S_IALLUGO) | 451 newattrs.ia_mode = (mode & S_IALLUGO) |
452 (inode->i_mode & ~S_IALLUGO); 452 (inode->i_mode & ~S_IALLUGO);
453 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; 453 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
454 res = notify_change(victim, &newattrs); 454 res = notify_change(victim, &newattrs);
455 up(&inode->i_sem); 455 mutex_unlock(&inode->i_mutex);
456 } 456 }
457 dput(victim); 457 dput(victim);
458 } 458 }
459 up(&dir->d_inode->i_sem); 459 mutex_unlock(&dir->d_inode->i_mutex);
460 460
461 return res; 461 return res;
462} 462}
@@ -480,4 +480,3 @@ void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr)
480EXPORT_SYMBOL_GPL(sysfs_create_file); 480EXPORT_SYMBOL_GPL(sysfs_create_file);
481EXPORT_SYMBOL_GPL(sysfs_remove_file); 481EXPORT_SYMBOL_GPL(sysfs_remove_file);
482EXPORT_SYMBOL_GPL(sysfs_update_file); 482EXPORT_SYMBOL_GPL(sysfs_update_file);
483
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 970a33f03299..689f7bcfaf30 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -11,6 +11,7 @@
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
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 "sysfs.h" 15#include "sysfs.h"
15 16
16extern struct super_block * sysfs_sb; 17extern struct super_block * sysfs_sb;
@@ -201,7 +202,7 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)
201 202
202/* 203/*
203 * Unhashes the dentry corresponding to given sysfs_dirent 204 * Unhashes the dentry corresponding to given sysfs_dirent
204 * Called with parent inode's i_sem held. 205 * Called with parent inode's i_mutex held.
205 */ 206 */
206void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent) 207void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
207{ 208{
@@ -232,7 +233,7 @@ void sysfs_hash_and_remove(struct dentry * dir, const char * name)
232 /* no inode means this hasn't been made visible yet */ 233 /* no inode means this hasn't been made visible yet */
233 return; 234 return;
234 235
235 down(&dir->d_inode->i_sem); 236 mutex_lock(&dir->d_inode->i_mutex);
236 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { 237 list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
237 if (!sd->s_element) 238 if (!sd->s_element)
238 continue; 239 continue;
@@ -243,7 +244,5 @@ void sysfs_hash_and_remove(struct dentry * dir, const char * name)
243 break; 244 break;
244 } 245 }
245 } 246 }
246 up(&dir->d_inode->i_sem); 247 mutex_unlock(&dir->d_inode->i_mutex);
247} 248}
248
249
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index de402fa915f2..e38d6338a20d 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -86,9 +86,9 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
86 86
87 BUG_ON(!kobj || !kobj->dentry || !name); 87 BUG_ON(!kobj || !kobj->dentry || !name);
88 88
89 down(&dentry->d_inode->i_sem); 89 mutex_lock(&dentry->d_inode->i_mutex);
90 error = sysfs_add_link(dentry, name, target); 90 error = sysfs_add_link(dentry, name, target);
91 up(&dentry->d_inode->i_sem); 91 mutex_unlock(&dentry->d_inode->i_mutex);
92 return error; 92 return error;
93} 93}
94 94
@@ -177,4 +177,3 @@ struct inode_operations sysfs_symlink_inode_operations = {
177 177
178EXPORT_SYMBOL_GPL(sysfs_create_link); 178EXPORT_SYMBOL_GPL(sysfs_create_link);
179EXPORT_SYMBOL_GPL(sysfs_remove_link); 179EXPORT_SYMBOL_GPL(sysfs_remove_link);
180