summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-23 22:21:50 (GMT)
committerPawel Osmialowski <p.osmialowsk@mcdsrvbld02.digital.local>2015-03-27 13:37:25 (GMT)
commit426887cf836d180b4e9aee11984656dd728c95d7 (patch)
treeeaa6c0dfb8151aa9749fccdbf5090d282832a4f8
parent43041b5e368bf7e80bf0c493723b14d0be2d6b86 (diff)
downloadlinux-3.10-426887cf836d180b4e9aee11984656dd728c95d7.zip
linux-3.10-426887cf836d180b4e9aee11984656dd728c95d7.tar.gz
linux-3.10-426887cf836d180b4e9aee11984656dd728c95d7.tar.bz2
sysfs, kernfs: introduce kernfs_create_link()
Separate out kernfs symlink interface - kernfs_create_link() - which takes and returns sysfs_dirents, from sysfs_do_create_link_sd(). sysfs_do_create_link_sd() now just determines the parent and target sysfs_dirents and invokes the new interface and handles dup warning. This patch doesn't introduce behavior changes. v2: Dummy implementation for !CONFIG_SYSFS updated to return -ENOSYS. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/sysfs/symlink.c76
-rw-r--r--include/linux/kernfs.h9
2 files changed, 55 insertions, 30 deletions
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 71583fc..41138e9 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -21,14 +21,48 @@
#include "sysfs.h"
+/**
+ * kernfs_create_link - create a symlink
+ * @parent: directory to create the symlink in
+ * @name: name of the symlink
+ * @target: target node for the symlink to point to
+ *
+ * Returns the created node on success, ERR_PTR() value on error.
+ */
+struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
+ const char *name,
+ struct sysfs_dirent *target)
+{
+ struct sysfs_dirent *sd;
+ struct sysfs_addrm_cxt acxt;
+ int error;
+
+ sd = sysfs_new_dirent(name, S_IFLNK|S_IRWXUGO, SYSFS_KOBJ_LINK);
+ if (!sd)
+ return ERR_PTR(-ENOMEM);
+
+ if (parent->s_flags & SYSFS_FLAG_NS)
+ sd->s_ns = target->s_ns;
+ sd->s_symlink.target_sd = target;
+ sysfs_get(target); /* ref owned by symlink */
+
+ sysfs_addrm_start(&acxt);
+ error = __sysfs_add_one(&acxt, sd, parent);
+ sysfs_addrm_finish(&acxt);
+
+ if (!error)
+ return sd;
+
+ sysfs_put(sd);
+ return ERR_PTR(error);
+}
+
+
static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
struct kobject *target,
const char *name, int warn)
{
- struct sysfs_dirent *target_sd = NULL;
- struct sysfs_dirent *sd = NULL;
- struct sysfs_addrm_cxt acxt;
- int error;
+ struct sysfs_dirent *sd, *target_sd = NULL;
BUG_ON(!name || !parent_sd);
@@ -42,36 +76,18 @@ static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
target_sd = sysfs_get(target->sd);
spin_unlock(&sysfs_symlink_target_lock);
- error = -ENOENT;
if (!target_sd)
- goto out_put;
+ return -ENOENT;
- error = -ENOMEM;
- sd = sysfs_new_dirent(name, S_IFLNK|S_IRWXUGO, SYSFS_KOBJ_LINK);
- if (!sd)
- goto out_put;
-
- if (parent_sd->s_flags & SYSFS_FLAG_NS)
- sd->s_ns = target_sd->s_ns;
- sd->s_symlink.target_sd = target_sd;
- target_sd = NULL; /* reference is now owned by the symlink */
-
- sysfs_addrm_start(&acxt);
- if (warn)
- error = sysfs_add_one(&acxt, sd, parent_sd);
- else
- error = __sysfs_add_one(&acxt, sd, parent_sd);
- sysfs_addrm_finish(&acxt);
-
- if (error)
- goto out_put;
+ sd = kernfs_create_link(parent_sd, name, target_sd);
+ sysfs_put(target_sd);
- return 0;
+ if (!IS_ERR(sd))
+ return 0;
- out_put:
- sysfs_put(target_sd);
- sysfs_put(sd);
- return error;
+ if (warn && PTR_ERR(sd) == -EEXIST)
+ sysfs_warn_dup(parent_sd, name);
+ return PTR_ERR(sd);
}
/**
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index 83e151a..fe6290d 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -8,17 +8,26 @@
#define __LINUX_KERNFS_H
#include <linux/kernel.h>
+#include <linux/err.h>
struct sysfs_dirent;
#ifdef CONFIG_SYSFS
+struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent,
+ const char *name,
+ struct sysfs_dirent *target);
void kernfs_remove(struct sysfs_dirent *sd);
int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name,
const void *ns);
#else /* CONFIG_SYSFS */
+static inline struct sysfs_dirent *
+kernfs_create_link(struct sysfs_dirent *parent, const char *name,
+ struct sysfs_dirent *target)
+{ return ERR_PTR(-ENOSYS); }
+
static inline void kernfs_remove(struct sysfs_dirent *sd) { }
static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent,