nfsd4.1: fix session memory use calculation
[safe/jmp/linux-2.6] / fs / sysfs / dir.c
index 6b8fe71..5fad489 100644 (file)
@@ -434,6 +434,26 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
 }
 
 /**
+ *     sysfs_pathname - return full path to sysfs dirent
+ *     @sd: sysfs_dirent whose path we want
+ *     @path: caller allocated buffer
+ *
+ *     Gives the name "/" to the sysfs_root entry; any path returned
+ *     is relative to wherever sysfs is mounted.
+ *
+ *     XXX: does no error checking on @path size
+ */
+static char *sysfs_pathname(struct sysfs_dirent *sd, char *path)
+{
+       if (sd->s_parent) {
+               sysfs_pathname(sd->s_parent, path);
+               strcat(path, "/");
+       }
+       strcat(path, sd->s_name);
+       return path;
+}
+
+/**
  *     sysfs_add_one - add sysfs_dirent to parent
  *     @acxt: addrm context to use
  *     @sd: sysfs_dirent to be added
@@ -458,8 +478,16 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
        int ret;
 
        ret = __sysfs_add_one(acxt, sd);
-       WARN(ret == -EEXIST, KERN_WARNING "sysfs: duplicate filename '%s' "
-                      "can not be created\n", sd->s_name);
+       if (ret == -EEXIST) {
+               char *path = kzalloc(PATH_MAX, GFP_KERNEL);
+               WARN(1, KERN_WARNING
+                    "sysfs: cannot create duplicate filename '%s'\n",
+                    (path == NULL) ? sd->s_name :
+                    strcat(strcat(sysfs_pathname(acxt->parent_sd, path), "/"),
+                           sd->s_name));
+               kfree(path);
+       }
+
        return ret;
 }
 
@@ -581,6 +609,7 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
 
                sysfs_drop_dentry(sd);
                sysfs_deactivate(sd);
+               unmap_bin_file(sd);
                sysfs_put(sd);
        }
 }
@@ -731,6 +760,7 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
 const struct inode_operations sysfs_dir_inode_operations = {
        .lookup         = sysfs_lookup,
        .setattr        = sysfs_setattr,
+       .setxattr       = sysfs_setxattr,
 };
 
 static void remove_dir(struct sysfs_dirent *sd)
@@ -864,7 +894,8 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
 
        mutex_lock(&sysfs_rename_mutex);
        BUG_ON(!sd->s_parent);
-       new_parent_sd = new_parent_kobj->sd ? new_parent_kobj->sd : &sysfs_root;
+       new_parent_sd = (new_parent_kobj && new_parent_kobj->sd) ?
+               new_parent_kobj->sd : &sysfs_root;
 
        error = 0;
        if (sd->s_parent == new_parent_sd)
@@ -910,8 +941,10 @@ again:
        /* Remove from old parent's list and insert into new parent's list. */
        sysfs_unlink_sibling(sd);
        sysfs_get(new_parent_sd);
+       drop_nlink(old_parent->d_inode);
        sysfs_put(sd->s_parent);
        sd->s_parent = new_parent_sd;
+       inc_nlink(new_parent->d_inode);
        sysfs_link_sibling(sd);
 
  out_unlock: