]> Pileus Git - ~andy/linux/blobdiff - fs/sysfs/dir.c
[NETNS]: Use the per-net ipv6_devconf(_all) in sysctl handlers
[~andy/linux] / fs / sysfs / dir.c
index 4ad9422566a84698af49b70a1aa4ea6c9eb75f6b..4948d9bc405dfbdb23f30dcd5ad47d103f4e5514 100644 (file)
@@ -1,5 +1,13 @@
 /*
- * dir.c - Operations for sysfs directories.
+ * fs/sysfs/dir.c - sysfs core and dir operation implementation
+ *
+ * Copyright (c) 2001-3 Patrick Mochel
+ * Copyright (c) 2007 SUSE Linux Products GmbH
+ * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
+ *
+ * This file is released under the GPLv2.
+ *
+ * Please see Documentation/filesystems/sysfs.txt for more information.
  */
 
 #undef DEBUG
@@ -16,9 +24,9 @@
 
 DEFINE_MUTEX(sysfs_mutex);
 DEFINE_MUTEX(sysfs_rename_mutex);
-spinlock_t sysfs_assoc_lock = SPIN_LOCK_UNLOCKED;
+DEFINE_SPINLOCK(sysfs_assoc_lock);
 
-static spinlock_t sysfs_ino_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(sysfs_ino_lock);
 static DEFINE_IDA(sysfs_ino_ida);
 
 /**
@@ -104,8 +112,7 @@ struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd)
                /* look it up */
                parent = dentry;
                mutex_lock(&parent->d_inode->i_mutex);
-               dentry = lookup_one_len_kern(cur->s_name, parent,
-                                            strlen(cur->s_name));
+               dentry = lookup_one_noperm(cur->s_name, parent);
                mutex_unlock(&parent->d_inode->i_mutex);
                dput(parent);
 
@@ -125,7 +132,7 @@ struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd)
  *     RETURNS:
  *     Pointer to @sd on success, NULL on failure.
  */
-struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
+static struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
 {
        if (unlikely(!sd))
                return NULL;
@@ -154,7 +161,7 @@ struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd)
  *     Put an active reference to @sd.  This function is noop if @sd
  *     is NULL.
  */
-void sysfs_put_active(struct sysfs_dirent *sd)
+static void sysfs_put_active(struct sysfs_dirent *sd)
 {
        struct completion *cmpl;
        int v;
@@ -318,7 +325,6 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
 
        atomic_set(&sd->s_count, 1);
        atomic_set(&sd->s_active, 0);
-       atomic_set(&sd->s_event, 1);
 
        sd->s_name = name;
        sd->s_mode = mode;
@@ -434,7 +440,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
 /**
  *     sysfs_remove_one - remove sysfs_dirent from parent
  *     @acxt: addrm context to use
- *     @sd: sysfs_dirent to be added
+ *     @sd: sysfs_dirent to be removed
  *
  *     Mark @sd removed and drop nlink of parent inode if @sd is a
  *     directory.  @sd is unlinked from the children list.
@@ -672,8 +678,10 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
        sd = sysfs_find_dirent(parent_sd, dentry->d_name.name);
 
        /* no such entry */
-       if (!sd)
+       if (!sd) {
+               ret = ERR_PTR(-ENOENT);
                goto out_unlock;
+       }
 
        /* attach dentry and inode */
        inode = sysfs_get_inode(sd);
@@ -775,6 +783,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
        old_dentry = sysfs_get_dentry(sd);
        if (IS_ERR(old_dentry)) {
                error = PTR_ERR(old_dentry);
+               old_dentry = NULL;
                goto out;
        }
 
@@ -842,6 +851,7 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
        old_dentry = sysfs_get_dentry(sd);
        if (IS_ERR(old_dentry)) {
                error = PTR_ERR(old_dentry);
+               old_dentry = NULL;
                goto out;
        }
        old_parent = old_dentry->d_parent;
@@ -849,6 +859,7 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
        new_parent = sysfs_get_dentry(new_parent_sd);
        if (IS_ERR(new_parent)) {
                error = PTR_ERR(new_parent);
+               new_parent = NULL;
                goto out;
        }
 
@@ -872,7 +883,6 @@ again:
        error = 0;
        d_add(new_dentry, NULL);
        d_move(old_dentry, new_dentry);
-       dput(new_dentry);
 
        /* Remove from old parent's list and insert into new parent's list. */
        sysfs_unlink_sibling(sd);