]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/sysfs/file.c
sysfs: remove sysfs_addrm_cxt->parent_sd
[karo-tx-linux.git] / fs / sysfs / file.c
index 15ef5eb13663f6828b15e619b5e801b4700a3a82..1656a79ea6c0dcad6767ffcb568ac53a5d5f3fd6 100644 (file)
@@ -466,9 +466,9 @@ void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
        mutex_lock(&sysfs_mutex);
 
        if (sd && dir)
-               sd = sysfs_find_dirent(sd, NULL, dir);
+               sd = sysfs_find_dirent(sd, dir, NULL);
        if (sd && attr)
-               sd = sysfs_find_dirent(sd, NULL, attr);
+               sd = sysfs_find_dirent(sd, attr, NULL);
        if (sd)
                sysfs_notify_dirent(sd);
 
@@ -485,58 +485,15 @@ const struct file_operations sysfs_file_operations = {
        .poll           = sysfs_poll,
 };
 
-static int sysfs_attr_ns(struct kobject *kobj, const struct attribute *attr,
-                        const void **pns)
-{
-       struct sysfs_dirent *dir_sd = kobj->sd;
-       const struct sysfs_ops *ops;
-       const void *ns = NULL;
-       int err;
-
-       if (!dir_sd) {
-               WARN(1, KERN_ERR "sysfs: kobject %s without dirent\n",
-                       kobject_name(kobj));
-               return -ENOENT;
-       }
-
-       err = 0;
-       if (!sysfs_ns_type(dir_sd))
-               goto out;
-
-       err = -EINVAL;
-       if (!kobj->ktype)
-               goto out;
-       ops = kobj->ktype->sysfs_ops;
-       if (!ops)
-               goto out;
-       if (!ops->namespace)
-               goto out;
-
-       err = 0;
-       ns = ops->namespace(kobj, attr);
-out:
-       if (err) {
-               WARN(1, KERN_ERR
-                    "missing sysfs namespace attribute operation for kobject: %s\n",
-                    kobject_name(kobj));
-       }
-       *pns = ns;
-       return err;
-}
-
-int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
-                       const struct attribute *attr, int type, umode_t amode)
+int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
+                          const struct attribute *attr, int type,
+                          umode_t amode, const void *ns)
 {
        umode_t mode = (amode & S_IALLUGO) | S_IFREG;
        struct sysfs_addrm_cxt acxt;
        struct sysfs_dirent *sd;
-       const void *ns;
        int rc;
 
-       rc = sysfs_attr_ns(dir_sd->s_dir.kobj, attr, &ns);
-       if (rc)
-               return rc;
-
        sd = sysfs_new_dirent(attr->name, mode, type);
        if (!sd)
                return -ENOMEM;
@@ -545,8 +502,8 @@ int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
        sd->s_attr.attr = (void *)attr;
        sysfs_dirent_init_lockdep(sd);
 
-       sysfs_addrm_start(&acxt, dir_sd);
-       rc = sysfs_add_one(&acxt, sd);
+       sysfs_addrm_start(&acxt);
+       rc = sysfs_add_one(&acxt, sd, dir_sd);
        sysfs_addrm_finish(&acxt);
 
        if (rc)
@@ -559,23 +516,25 @@ int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
 int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
                   int type)
 {
-       return sysfs_add_file_mode(dir_sd, attr, type, attr->mode);
+       return sysfs_add_file_mode_ns(dir_sd, attr, type, attr->mode, NULL);
 }
 
-
 /**
- *     sysfs_create_file - create an attribute file for an object.
- *     @kobj:  object we're creating for.
- *     @attr:  attribute descriptor.
+ * sysfs_create_file_ns - create an attribute file for an object with custom ns
+ * @kobj: object we're creating for
+ * @attr: attribute descriptor
+ * @ns: namespace the new file should belong to
  */
-int sysfs_create_file(struct kobject *kobj, const struct attribute *attr)
+int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr,
+                        const void *ns)
 {
        BUG_ON(!kobj || !kobj->sd || !attr);
 
-       return sysfs_add_file(kobj->sd, attr, SYSFS_KOBJ_ATTR);
+       return sysfs_add_file_mode_ns(kobj->sd, attr, SYSFS_KOBJ_ATTR,
+                                     attr->mode, ns);
 
 }
-EXPORT_SYMBOL_GPL(sysfs_create_file);
+EXPORT_SYMBOL_GPL(sysfs_create_file_ns);
 
 int sysfs_create_files(struct kobject *kobj, const struct attribute **ptr)
 {
@@ -604,7 +563,7 @@ int sysfs_add_file_to_group(struct kobject *kobj,
        int error;
 
        if (group)
-               dir_sd = sysfs_get_dirent(kobj->sd, NULL, group);
+               dir_sd = sysfs_get_dirent(kobj->sd, group);
        else
                dir_sd = sysfs_get(kobj->sd);
 
@@ -630,17 +589,12 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
 {
        struct sysfs_dirent *sd;
        struct iattr newattrs;
-       const void *ns;
        int rc;
 
-       rc = sysfs_attr_ns(kobj, attr, &ns);
-       if (rc)
-               return rc;
-
        mutex_lock(&sysfs_mutex);
 
        rc = -ENOENT;
-       sd = sysfs_find_dirent(kobj->sd, ns, attr->name);
+       sd = sysfs_find_dirent(kobj->sd, attr->name, NULL);
        if (!sd)
                goto out;
 
@@ -655,22 +609,21 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
 EXPORT_SYMBOL_GPL(sysfs_chmod_file);
 
 /**
- *     sysfs_remove_file - remove an object attribute.
- *     @kobj:  object we're acting for.
- *     @attr:  attribute descriptor.
+ * sysfs_remove_file_ns - remove an object attribute with a custom ns tag
+ * @kobj: object we're acting for
+ * @attr: attribute descriptor
+ * @ns: namespace tag of the file to remove
  *
- *     Hash the attribute name and kill the victim.
+ * Hash the attribute name and namespace tag and kill the victim.
  */
-void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)
+void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
+                         const void *ns)
 {
-       const void *ns;
-
-       if (sysfs_attr_ns(kobj, attr, &ns))
-               return;
+       struct sysfs_dirent *dir_sd = kobj->sd;
 
-       sysfs_hash_and_remove(kobj->sd, ns, attr->name);
+       sysfs_hash_and_remove(dir_sd, attr->name, ns);
 }
-EXPORT_SYMBOL_GPL(sysfs_remove_file);
+EXPORT_SYMBOL_GPL(sysfs_remove_file_ns);
 
 void sysfs_remove_files(struct kobject *kobj, const struct attribute **ptr)
 {
@@ -692,11 +645,11 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
        struct sysfs_dirent *dir_sd;
 
        if (group)
-               dir_sd = sysfs_get_dirent(kobj->sd, NULL, group);
+               dir_sd = sysfs_get_dirent(kobj->sd, group);
        else
                dir_sd = sysfs_get(kobj->sd);
        if (dir_sd) {
-               sysfs_hash_and_remove(dir_sd, NULL, attr->name);
+               sysfs_hash_and_remove(dir_sd, attr->name, NULL);
                sysfs_put(dir_sd);
        }
 }