aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/dir.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-09-11 22:29:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 18:30:22 -0400
commite34ff4906199d2ebd248ae897ae34f52bea151c9 (patch)
tree2ae9507f68e08651b3f960de51b77a1d84e21453 /fs/sysfs/dir.c
parent58292cbe6669d74498a5f08db13e57cb3bcfb81d (diff)
sysfs: remove ktype->namespace() invocations in directory code
For some unrecognizable reason, namespace information is communicated to sysfs through ktype->namespace() callback when there's *nothing* which needs the use of a callback. The whole sequence of operations is completely synchronous and sysfs operations simply end up calling back into the layer which just invoked it in order to find out the namespace information, which is completely backwards, obfuscates what's going on and unnecessarily tangles two separate layers. This patch doesn't remove ktype->namespace() but shifts its handling to kobject layer. We probably want to get rid of the callback in the long term. This patch adds an explicit param to sysfs_{create|rename|move}_dir() and renames them to sysfs_{create|rename|move}_dir_ns(), respectively. ktype->namespace() invocations are moved to the calling sites of the above functions. A new helper kboject_namespace() is introduced which directly tests kobj_ns_type_operations->type which should give the same result as testing sysfs_fs_type(parent_sd) and returns @kobj's namespace tag as necessary. kobject_namespace() is extern as it will be used from another file in the following patches. This patch should be an equivalent conversion without any functional difference. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs/dir.c')
-rw-r--r--fs/sysfs/dir.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 834c64cb7f88..878ac3afe1b8 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -730,14 +730,14 @@ static enum kobj_ns_type sysfs_read_ns_type(struct kobject *kobj)
730} 730}
731 731
732/** 732/**
733 * sysfs_create_dir - create a directory for an object. 733 * sysfs_create_dir_ns - create a directory for an object with a namespace tag
734 * @kobj: object we're creating directory for. 734 * @kobj: object we're creating directory for
735 * @ns: the namespace tag to use
735 */ 736 */
736int sysfs_create_dir(struct kobject *kobj) 737int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
737{ 738{
738 enum kobj_ns_type type; 739 enum kobj_ns_type type;
739 struct sysfs_dirent *parent_sd, *sd; 740 struct sysfs_dirent *parent_sd, *sd;
740 const void *ns = NULL;
741 int error = 0; 741 int error = 0;
742 742
743 BUG_ON(!kobj); 743 BUG_ON(!kobj);
@@ -750,8 +750,6 @@ int sysfs_create_dir(struct kobject *kobj)
750 if (!parent_sd) 750 if (!parent_sd)
751 return -ENOENT; 751 return -ENOENT;
752 752
753 if (sysfs_ns_type(parent_sd))
754 ns = kobj->ktype->namespace(kobj);
755 type = sysfs_read_ns_type(kobj); 753 type = sysfs_read_ns_type(kobj);
756 754
757 error = create_dir(kobj, parent_sd, type, ns, kobject_name(kobj), &sd); 755 error = create_dir(kobj, parent_sd, type, ns, kobject_name(kobj), &sd);
@@ -909,26 +907,21 @@ int sysfs_rename(struct sysfs_dirent *sd,
909 return error; 907 return error;
910} 908}
911 909
912int sysfs_rename_dir(struct kobject *kobj, const char *new_name) 910int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
911 const void *new_ns)
913{ 912{
914 struct sysfs_dirent *parent_sd = kobj->sd->s_parent; 913 struct sysfs_dirent *parent_sd = kobj->sd->s_parent;
915 const void *new_ns = NULL;
916
917 if (sysfs_ns_type(parent_sd))
918 new_ns = kobj->ktype->namespace(kobj);
919 914
920 return sysfs_rename(kobj->sd, parent_sd, new_ns, new_name); 915 return sysfs_rename(kobj->sd, parent_sd, new_ns, new_name);
921} 916}
922 917
923int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj) 918int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
919 const void *new_ns)
924{ 920{
925 struct sysfs_dirent *sd = kobj->sd; 921 struct sysfs_dirent *sd = kobj->sd;
926 struct sysfs_dirent *new_parent_sd; 922 struct sysfs_dirent *new_parent_sd;
927 const void *new_ns = NULL;
928 923
929 BUG_ON(!sd->s_parent); 924 BUG_ON(!sd->s_parent);
930 if (sysfs_ns_type(sd->s_parent))
931 new_ns = kobj->ktype->namespace(kobj);
932 new_parent_sd = new_parent_kobj && new_parent_kobj->sd ? 925 new_parent_sd = new_parent_kobj && new_parent_kobj->sd ?
933 new_parent_kobj->sd : &sysfs_root; 926 new_parent_kobj->sd : &sysfs_root;
934 927