aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-28 14:54:24 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-29 20:48:14 -0500
commit496f73944a4a974f89d48920bf368aec8841b195 (patch)
treeceaf60c390103523edecb4a3d7ff3f79b3f50171 /fs/sysfs
parenta7dc66dfb4c6d6c1d7c14d5106ce467f1dbd4eba (diff)
sysfs, kernfs: introduce kernfs_create_file[_ns]()
Introduce kernfs interface to create a file which takes and returns sysfs_dirents. The actual file creation part is separated out from sysfs_add_file_mode_ns() into kernfs_create_file_ns(). The former now only decides the kernfs_ops to use and the file's size and invokes the latter. 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>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/file.c53
1 files changed, 42 insertions, 11 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index e2ce6743113a..69cca0f4ccf3 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -912,14 +912,11 @@ static const struct kernfs_ops sysfs_bin_kfops_rw = {
912 912
913int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, 913int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
914 const struct attribute *attr, bool is_bin, 914 const struct attribute *attr, bool is_bin,
915 umode_t amode, const void *ns) 915 umode_t mode, const void *ns)
916{ 916{
917 umode_t mode = (amode & S_IALLUGO) | S_IFREG;
918 const struct kernfs_ops *ops; 917 const struct kernfs_ops *ops;
919 struct sysfs_addrm_cxt acxt;
920 struct sysfs_dirent *sd; 918 struct sysfs_dirent *sd;
921 loff_t size; 919 loff_t size;
922 int rc;
923 920
924 if (!is_bin) { 921 if (!is_bin) {
925 struct kobject *kobj = dir_sd->priv; 922 struct kobject *kobj = dir_sd->priv;
@@ -956,14 +953,47 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
956 size = battr->size; 953 size = battr->size;
957 } 954 }
958 955
959 sd = sysfs_new_dirent(attr->name, mode, SYSFS_KOBJ_ATTR); 956 sd = kernfs_create_file_ns(dir_sd, attr->name, mode, size,
957 ops, (void *)attr, ns);
958 if (IS_ERR(sd)) {
959 if (PTR_ERR(sd) == -EEXIST)
960 sysfs_warn_dup(dir_sd, attr->name);
961 return PTR_ERR(sd);
962 }
963 return 0;
964}
965
966/**
967 * kernfs_create_file_ns - create a file
968 * @parent: directory to create the file in
969 * @name: name of the file
970 * @mode: mode of the file
971 * @size: size of the file
972 * @ops: kernfs operations for the file
973 * @priv: private data for the file
974 * @ns: optional namespace tag of the file
975 *
976 * Returns the created node on success, ERR_PTR() value on error.
977 */
978struct sysfs_dirent *kernfs_create_file_ns(struct sysfs_dirent *parent,
979 const char *name,
980 umode_t mode, loff_t size,
981 const struct kernfs_ops *ops,
982 void *priv, const void *ns)
983{
984 struct sysfs_addrm_cxt acxt;
985 struct sysfs_dirent *sd;
986 int rc;
987
988 sd = sysfs_new_dirent(name, (mode & S_IALLUGO) | S_IFREG,
989 SYSFS_KOBJ_ATTR);
960 if (!sd) 990 if (!sd)
961 return -ENOMEM; 991 return ERR_PTR(-ENOMEM);
962 992
963 sd->s_attr.ops = ops; 993 sd->s_attr.ops = ops;
964 sd->s_attr.size = size; 994 sd->s_attr.size = size;
965 sd->s_ns = ns; 995 sd->s_ns = ns;
966 sd->priv = (void *)attr; 996 sd->priv = priv;
967 sysfs_dirent_init_lockdep(sd); 997 sysfs_dirent_init_lockdep(sd);
968 998
969 /* 999 /*
@@ -977,13 +1007,14 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
977 sd->s_flags |= SYSFS_FLAG_HAS_MMAP; 1007 sd->s_flags |= SYSFS_FLAG_HAS_MMAP;
978 1008
979 sysfs_addrm_start(&acxt); 1009 sysfs_addrm_start(&acxt);
980 rc = sysfs_add_one(&acxt, sd, dir_sd); 1010 rc = __sysfs_add_one(&acxt, sd, parent);
981 sysfs_addrm_finish(&acxt); 1011 sysfs_addrm_finish(&acxt);
982 1012
983 if (rc) 1013 if (rc) {
984 sysfs_put(sd); 1014 sysfs_put(sd);
985 1015 return ERR_PTR(rc);
986 return rc; 1016 }
1017 return sd;
987} 1018}
988 1019
989int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, 1020int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,