aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/dir.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-09-11 22:29:09 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 18:34:38 -0400
commitcfec0bc835c84d3d3723d4955587f05a94879b26 (patch)
tree18c1239d9113ebc30ca037b1a0025b95ffb7c405 /fs/sysfs/dir.c
parent388975cccaaf11abd47525f664c76891c440481a (diff)
sysfs: @name comes before @ns
Some internal sysfs functions which take explicit namespace argument are weird in that they place the optional @ns in front of @name which is contrary to the established convention. This is confusing and error-prone especially as @ns and @name may be interchanged without causing compilation warning. Swap the positions of @name and @ns in the following internal functions. sysfs_find_dirent() sysfs_rename() sysfs_hash_and_remove() sysfs_name_hash() sysfs_name_compare() create_dir() This patch doesn't introduce any functional changes. 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.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index fee19d16e4a2..d23e66dfba74 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -35,12 +35,12 @@ static DEFINE_IDA(sysfs_ino_ida);
35 35
36/** 36/**
37 * sysfs_name_hash 37 * sysfs_name_hash
38 * @ns: Namespace tag to hash
39 * @name: Null terminated string to hash 38 * @name: Null terminated string to hash
39 * @ns: Namespace tag to hash
40 * 40 *
41 * Returns 31 bit hash of ns + name (so it fits in an off_t ) 41 * Returns 31 bit hash of ns + name (so it fits in an off_t )
42 */ 42 */
43static unsigned int sysfs_name_hash(const void *ns, const char *name) 43static unsigned int sysfs_name_hash(const char *name, const void *ns)
44{ 44{
45 unsigned long hash = init_name_hash(); 45 unsigned long hash = init_name_hash();
46 unsigned int len = strlen(name); 46 unsigned int len = strlen(name);
@@ -56,8 +56,8 @@ static unsigned int sysfs_name_hash(const void *ns, const char *name)
56 return hash; 56 return hash;
57} 57}
58 58
59static int sysfs_name_compare(unsigned int hash, const void *ns, 59static int sysfs_name_compare(unsigned int hash, const char *name,
60 const char *name, const struct sysfs_dirent *sd) 60 const void *ns, const struct sysfs_dirent *sd)
61{ 61{
62 if (hash != sd->s_hash) 62 if (hash != sd->s_hash)
63 return hash - sd->s_hash; 63 return hash - sd->s_hash;
@@ -69,7 +69,7 @@ static int sysfs_name_compare(unsigned int hash, const void *ns,
69static int sysfs_sd_compare(const struct sysfs_dirent *left, 69static int sysfs_sd_compare(const struct sysfs_dirent *left,
70 const struct sysfs_dirent *right) 70 const struct sysfs_dirent *right)
71{ 71{
72 return sysfs_name_compare(left->s_hash, left->s_ns, left->s_name, 72 return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns,
73 right); 73 right);
74} 74}
75 75
@@ -451,7 +451,7 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
451 struct sysfs_inode_attrs *ps_iattr; 451 struct sysfs_inode_attrs *ps_iattr;
452 int ret; 452 int ret;
453 453
454 sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name); 454 sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
455 sd->s_parent = sysfs_get(acxt->parent_sd); 455 sd->s_parent = sysfs_get(acxt->parent_sd);
456 456
457 ret = sysfs_link_sibling(sd); 457 ret = sysfs_link_sibling(sd);
@@ -596,6 +596,7 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
596 * sysfs_find_dirent - find sysfs_dirent with the given name 596 * sysfs_find_dirent - find sysfs_dirent with the given name
597 * @parent_sd: sysfs_dirent to search under 597 * @parent_sd: sysfs_dirent to search under
598 * @name: name to look for 598 * @name: name to look for
599 * @ns: the namespace tag to use
599 * 600 *
600 * Look for sysfs_dirent with name @name under @parent_sd. 601 * Look for sysfs_dirent with name @name under @parent_sd.
601 * 602 *
@@ -606,19 +607,19 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
606 * Pointer to sysfs_dirent if found, NULL if not. 607 * Pointer to sysfs_dirent if found, NULL if not.
607 */ 608 */
608struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, 609struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
609 const void *ns, 610 const unsigned char *name,
610 const unsigned char *name) 611 const void *ns)
611{ 612{
612 struct rb_node *node = parent_sd->s_dir.children.rb_node; 613 struct rb_node *node = parent_sd->s_dir.children.rb_node;
613 unsigned int hash; 614 unsigned int hash;
614 615
615 hash = sysfs_name_hash(ns, name); 616 hash = sysfs_name_hash(name, ns);
616 while (node) { 617 while (node) {
617 struct sysfs_dirent *sd; 618 struct sysfs_dirent *sd;
618 int result; 619 int result;
619 620
620 sd = to_sysfs_dirent(node); 621 sd = to_sysfs_dirent(node);
621 result = sysfs_name_compare(hash, ns, name, sd); 622 result = sysfs_name_compare(hash, name, ns, sd);
622 if (result < 0) 623 if (result < 0)
623 node = node->rb_left; 624 node = node->rb_left;
624 else if (result > 0) 625 else if (result > 0)
@@ -651,7 +652,7 @@ struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
651 struct sysfs_dirent *sd; 652 struct sysfs_dirent *sd;
652 653
653 mutex_lock(&sysfs_mutex); 654 mutex_lock(&sysfs_mutex);
654 sd = sysfs_find_dirent(parent_sd, ns, name); 655 sd = sysfs_find_dirent(parent_sd, name, ns);
655 sysfs_get(sd); 656 sysfs_get(sd);
656 mutex_unlock(&sysfs_mutex); 657 mutex_unlock(&sysfs_mutex);
657 658
@@ -660,7 +661,8 @@ struct sysfs_dirent *sysfs_get_dirent_ns(struct sysfs_dirent *parent_sd,
660EXPORT_SYMBOL_GPL(sysfs_get_dirent_ns); 661EXPORT_SYMBOL_GPL(sysfs_get_dirent_ns);
661 662
662static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd, 663static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
663 const void *ns, const char *name, struct sysfs_dirent **p_sd) 664 const char *name, const void *ns,
665 struct sysfs_dirent **p_sd)
664{ 666{
665 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; 667 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
666 struct sysfs_addrm_cxt acxt; 668 struct sysfs_addrm_cxt acxt;
@@ -691,7 +693,7 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
691int sysfs_create_subdir(struct kobject *kobj, const char *name, 693int sysfs_create_subdir(struct kobject *kobj, const char *name,
692 struct sysfs_dirent **p_sd) 694 struct sysfs_dirent **p_sd)
693{ 695{
694 return create_dir(kobj, kobj->sd, NULL, name, p_sd); 696 return create_dir(kobj, kobj->sd, name, NULL, p_sd);
695} 697}
696 698
697/** 699/**
@@ -714,7 +716,7 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
714 if (!parent_sd) 716 if (!parent_sd)
715 return -ENOENT; 717 return -ENOENT;
716 718
717 error = create_dir(kobj, parent_sd, ns, kobject_name(kobj), &sd); 719 error = create_dir(kobj, parent_sd, kobject_name(kobj), ns, &sd);
718 if (!error) 720 if (!error)
719 kobj->sd = sd; 721 kobj->sd = sd;
720 return error; 722 return error;
@@ -735,7 +737,7 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
735 if (parent_sd->s_flags & SYSFS_FLAG_HAS_NS) 737 if (parent_sd->s_flags & SYSFS_FLAG_HAS_NS)
736 ns = sysfs_info(dir->i_sb)->ns; 738 ns = sysfs_info(dir->i_sb)->ns;
737 739
738 sd = sysfs_find_dirent(parent_sd, ns, dentry->d_name.name); 740 sd = sysfs_find_dirent(parent_sd, dentry->d_name.name, ns);
739 741
740 /* no such entry */ 742 /* no such entry */
741 if (!sd) { 743 if (!sd) {
@@ -823,9 +825,8 @@ void sysfs_remove_dir(struct kobject *kobj)
823 __sysfs_remove_dir(sd); 825 __sysfs_remove_dir(sd);
824} 826}
825 827
826int sysfs_rename(struct sysfs_dirent *sd, 828int sysfs_rename(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent_sd,
827 struct sysfs_dirent *new_parent_sd, const void *new_ns, 829 const char *new_name, const void *new_ns)
828 const char *new_name)
829{ 830{
830 int error; 831 int error;
831 832
@@ -837,7 +838,7 @@ int sysfs_rename(struct sysfs_dirent *sd,
837 goto out; /* nothing to rename */ 838 goto out; /* nothing to rename */
838 839
839 error = -EEXIST; 840 error = -EEXIST;
840 if (sysfs_find_dirent(new_parent_sd, new_ns, new_name)) 841 if (sysfs_find_dirent(new_parent_sd, new_name, new_ns))
841 goto out; 842 goto out;
842 843
843 /* rename sysfs_dirent */ 844 /* rename sysfs_dirent */
@@ -858,7 +859,7 @@ int sysfs_rename(struct sysfs_dirent *sd,
858 sysfs_get(new_parent_sd); 859 sysfs_get(new_parent_sd);
859 sysfs_put(sd->s_parent); 860 sysfs_put(sd->s_parent);
860 sd->s_ns = new_ns; 861 sd->s_ns = new_ns;
861 sd->s_hash = sysfs_name_hash(sd->s_ns, sd->s_name); 862 sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
862 sd->s_parent = new_parent_sd; 863 sd->s_parent = new_parent_sd;
863 sysfs_link_sibling(sd); 864 sysfs_link_sibling(sd);
864 865
@@ -873,7 +874,7 @@ int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
873{ 874{
874 struct sysfs_dirent *parent_sd = kobj->sd->s_parent; 875 struct sysfs_dirent *parent_sd = kobj->sd->s_parent;
875 876
876 return sysfs_rename(kobj->sd, parent_sd, new_ns, new_name); 877 return sysfs_rename(kobj->sd, parent_sd, new_name, new_ns);
877} 878}
878 879
879int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, 880int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
@@ -886,7 +887,7 @@ int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
886 new_parent_sd = new_parent_kobj && new_parent_kobj->sd ? 887 new_parent_sd = new_parent_kobj && new_parent_kobj->sd ?
887 new_parent_kobj->sd : &sysfs_root; 888 new_parent_kobj->sd : &sysfs_root;
888 889
889 return sysfs_rename(sd, new_parent_sd, new_ns, sd->s_name); 890 return sysfs_rename(sd, new_parent_sd, sd->s_name, new_ns);
890} 891}
891 892
892/* Relationship between s_mode and the DT_xxx types */ 893/* Relationship between s_mode and the DT_xxx types */