NFS: Don't run nfs_access_cache_shrinker() when the mask is GFP_NOFS
[safe/jmp/linux-2.6] / fs / sysfs / symlink.c
index a3ba217..b93ec51 100644 (file)
  */
 
 #include <linux/fs.h>
+#include <linux/gfp.h>
 #include <linux/mount.h>
 #include <linux/module.h>
 #include <linux/kobject.h>
 #include <linux/namei.h>
 #include <linux/mutex.h>
+#include <linux/security.h>
 
 #include "sysfs.h"
 
@@ -122,6 +124,44 @@ void sysfs_remove_link(struct kobject * kobj, const char * name)
        sysfs_hash_and_remove(parent_sd, name);
 }
 
+/**
+ *     sysfs_rename_link - rename symlink in object's directory.
+ *     @kobj:  object we're acting for.
+ *     @targ:  object we're pointing to.
+ *     @old:   previous name of the symlink.
+ *     @new:   new name of the symlink.
+ *
+ *     A helper function for the common rename symlink idiom.
+ */
+int sysfs_rename_link(struct kobject *kobj, struct kobject *targ,
+                       const char *old, const char *new)
+{
+       struct sysfs_dirent *parent_sd, *sd = NULL;
+       int result;
+
+       if (!kobj)
+               parent_sd = &sysfs_root;
+       else
+               parent_sd = kobj->sd;
+
+       result = -ENOENT;
+       sd = sysfs_get_dirent(parent_sd, old);
+       if (!sd)
+               goto out;
+
+       result = -EINVAL;
+       if (sysfs_type(sd) != SYSFS_KOBJ_LINK)
+               goto out;
+       if (sd->s_symlink.target_sd->s_dir.kobj != targ)
+               goto out;
+
+       result = sysfs_rename(sd, parent_sd, new);
+
+out:
+       sysfs_put(sd);
+       return result;
+}
+
 static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
                                 struct sysfs_dirent *target_sd, char *path)
 {
@@ -192,8 +232,11 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
        int error = -ENOMEM;
        unsigned long page = get_zeroed_page(GFP_KERNEL);
-       if (page)
+       if (page) {
                error = sysfs_getlink(dentry, (char *) page); 
+               if (error < 0)
+                       free_page((unsigned long)page);
+       }
        nd_set_link(nd, error ? ERR_PTR(error) : (char *)page);
        return NULL;
 }
@@ -206,9 +249,13 @@ static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *co
 }
 
 const struct inode_operations sysfs_symlink_inode_operations = {
-       .readlink = generic_readlink,
-       .follow_link = sysfs_follow_link,
-       .put_link = sysfs_put_link,
+       .setxattr       = sysfs_setxattr,
+       .readlink       = generic_readlink,
+       .follow_link    = sysfs_follow_link,
+       .put_link       = sysfs_put_link,
+       .setattr        = sysfs_setattr,
+       .getattr        = sysfs_getattr,
+       .permission     = sysfs_permission,
 };