aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/kernfs/dir.c')
-rw-r--r--fs/kernfs/dir.c198
1 files changed, 97 insertions, 101 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 800ebf521472..51fff9d2b334 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -19,7 +19,7 @@
19 19
20DEFINE_MUTEX(sysfs_mutex); 20DEFINE_MUTEX(sysfs_mutex);
21 21
22#define rb_to_kn(X) rb_entry((X), struct kernfs_node, s_rb) 22#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb)
23 23
24/** 24/**
25 * sysfs_name_hash 25 * sysfs_name_hash
@@ -47,18 +47,17 @@ static unsigned int sysfs_name_hash(const char *name, const void *ns)
47static int sysfs_name_compare(unsigned int hash, const char *name, 47static int sysfs_name_compare(unsigned int hash, const char *name,
48 const void *ns, const struct kernfs_node *kn) 48 const void *ns, const struct kernfs_node *kn)
49{ 49{
50 if (hash != kn->s_hash) 50 if (hash != kn->hash)
51 return hash - kn->s_hash; 51 return hash - kn->hash;
52 if (ns != kn->s_ns) 52 if (ns != kn->ns)
53 return ns - kn->s_ns; 53 return ns - kn->ns;
54 return strcmp(name, kn->s_name); 54 return strcmp(name, kn->name);
55} 55}
56 56
57static int sysfs_sd_compare(const struct kernfs_node *left, 57static int sysfs_sd_compare(const struct kernfs_node *left,
58 const struct kernfs_node *right) 58 const struct kernfs_node *right)
59{ 59{
60 return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns, 60 return sysfs_name_compare(left->hash, left->name, left->ns, right);
61 right);
62} 61}
63 62
64/** 63/**
@@ -66,7 +65,7 @@ static int sysfs_sd_compare(const struct kernfs_node *left,
66 * @kn: kernfs_node of interest 65 * @kn: kernfs_node of interest
67 * 66 *
68 * Link @kn into its sibling rbtree which starts from 67 * Link @kn into its sibling rbtree which starts from
69 * @kn->s_parent->s_dir.children. 68 * @kn->parent->dir.children.
70 * 69 *
71 * Locking: 70 * Locking:
72 * mutex_lock(sysfs_mutex) 71 * mutex_lock(sysfs_mutex)
@@ -76,11 +75,11 @@ static int sysfs_sd_compare(const struct kernfs_node *left,
76 */ 75 */
77static int sysfs_link_sibling(struct kernfs_node *kn) 76static int sysfs_link_sibling(struct kernfs_node *kn)
78{ 77{
79 struct rb_node **node = &kn->s_parent->s_dir.children.rb_node; 78 struct rb_node **node = &kn->parent->dir.children.rb_node;
80 struct rb_node *parent = NULL; 79 struct rb_node *parent = NULL;
81 80
82 if (sysfs_type(kn) == SYSFS_DIR) 81 if (sysfs_type(kn) == SYSFS_DIR)
83 kn->s_parent->s_dir.subdirs++; 82 kn->parent->dir.subdirs++;
84 83
85 while (*node) { 84 while (*node) {
86 struct kernfs_node *pos; 85 struct kernfs_node *pos;
@@ -90,15 +89,15 @@ static int sysfs_link_sibling(struct kernfs_node *kn)
90 parent = *node; 89 parent = *node;
91 result = sysfs_sd_compare(kn, pos); 90 result = sysfs_sd_compare(kn, pos);
92 if (result < 0) 91 if (result < 0)
93 node = &pos->s_rb.rb_left; 92 node = &pos->rb.rb_left;
94 else if (result > 0) 93 else if (result > 0)
95 node = &pos->s_rb.rb_right; 94 node = &pos->rb.rb_right;
96 else 95 else
97 return -EEXIST; 96 return -EEXIST;
98 } 97 }
99 /* add new node and rebalance the tree */ 98 /* add new node and rebalance the tree */
100 rb_link_node(&kn->s_rb, parent, node); 99 rb_link_node(&kn->rb, parent, node);
101 rb_insert_color(&kn->s_rb, &kn->s_parent->s_dir.children); 100 rb_insert_color(&kn->rb, &kn->parent->dir.children);
102 return 0; 101 return 0;
103} 102}
104 103
@@ -107,7 +106,7 @@ static int sysfs_link_sibling(struct kernfs_node *kn)
107 * @kn: kernfs_node of interest 106 * @kn: kernfs_node of interest
108 * 107 *
109 * Unlink @kn from its sibling rbtree which starts from 108 * Unlink @kn from its sibling rbtree which starts from
110 * kn->s_parent->s_dir.children. 109 * kn->parent->dir.children.
111 * 110 *
112 * Locking: 111 * Locking:
113 * mutex_lock(sysfs_mutex) 112 * mutex_lock(sysfs_mutex)
@@ -115,9 +114,9 @@ static int sysfs_link_sibling(struct kernfs_node *kn)
115static void sysfs_unlink_sibling(struct kernfs_node *kn) 114static void sysfs_unlink_sibling(struct kernfs_node *kn)
116{ 115{
117 if (sysfs_type(kn) == SYSFS_DIR) 116 if (sysfs_type(kn) == SYSFS_DIR)
118 kn->s_parent->s_dir.subdirs--; 117 kn->parent->dir.subdirs--;
119 118
120 rb_erase(&kn->s_rb, &kn->s_parent->s_dir.children); 119 rb_erase(&kn->rb, &kn->parent->dir.children);
121} 120}
122 121
123/** 122/**
@@ -135,10 +134,10 @@ struct kernfs_node *sysfs_get_active(struct kernfs_node *kn)
135 if (unlikely(!kn)) 134 if (unlikely(!kn))
136 return NULL; 135 return NULL;
137 136
138 if (!atomic_inc_unless_negative(&kn->s_active)) 137 if (!atomic_inc_unless_negative(&kn->active))
139 return NULL; 138 return NULL;
140 139
141 if (kn->s_flags & SYSFS_FLAG_LOCKDEP) 140 if (kn->flags & SYSFS_FLAG_LOCKDEP)
142 rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_); 141 rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_);
143 return kn; 142 return kn;
144} 143}
@@ -157,9 +156,9 @@ void sysfs_put_active(struct kernfs_node *kn)
157 if (unlikely(!kn)) 156 if (unlikely(!kn))
158 return; 157 return;
159 158
160 if (kn->s_flags & SYSFS_FLAG_LOCKDEP) 159 if (kn->flags & SYSFS_FLAG_LOCKDEP)
161 rwsem_release(&kn->dep_map, 1, _RET_IP_); 160 rwsem_release(&kn->dep_map, 1, _RET_IP_);
162 v = atomic_dec_return(&kn->s_active); 161 v = atomic_dec_return(&kn->active);
163 if (likely(v != SD_DEACTIVATED_BIAS)) 162 if (likely(v != SD_DEACTIVATED_BIAS))
164 return; 163 return;
165 164
@@ -181,7 +180,7 @@ static void sysfs_deactivate(struct kernfs_node *kn)
181 DECLARE_COMPLETION_ONSTACK(wait); 180 DECLARE_COMPLETION_ONSTACK(wait);
182 int v; 181 int v;
183 182
184 BUG_ON(!(kn->s_flags & SYSFS_FLAG_REMOVED)); 183 BUG_ON(!(kn->flags & SYSFS_FLAG_REMOVED));
185 184
186 if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF)) 185 if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF))
187 return; 186 return;
@@ -192,7 +191,7 @@ static void sysfs_deactivate(struct kernfs_node *kn)
192 /* atomic_add_return() is a mb(), put_active() will always see 191 /* atomic_add_return() is a mb(), put_active() will always see
193 * the updated kn->u.completion. 192 * the updated kn->u.completion.
194 */ 193 */
195 v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->s_active); 194 v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->active);
196 195
197 if (v != SD_DEACTIVATED_BIAS) { 196 if (v != SD_DEACTIVATED_BIAS) {
198 lock_contended(&kn->dep_map, _RET_IP_); 197 lock_contended(&kn->dep_map, _RET_IP_);
@@ -210,8 +209,8 @@ static void sysfs_deactivate(struct kernfs_node *kn)
210void kernfs_get(struct kernfs_node *kn) 209void kernfs_get(struct kernfs_node *kn)
211{ 210{
212 if (kn) { 211 if (kn) {
213 WARN_ON(!atomic_read(&kn->s_count)); 212 WARN_ON(!atomic_read(&kn->count));
214 atomic_inc(&kn->s_count); 213 atomic_inc(&kn->count);
215 } 214 }
216} 215}
217EXPORT_SYMBOL_GPL(kernfs_get); 216EXPORT_SYMBOL_GPL(kernfs_get);
@@ -227,36 +226,36 @@ void kernfs_put(struct kernfs_node *kn)
227 struct kernfs_node *parent; 226 struct kernfs_node *parent;
228 struct kernfs_root *root; 227 struct kernfs_root *root;
229 228
230 if (!kn || !atomic_dec_and_test(&kn->s_count)) 229 if (!kn || !atomic_dec_and_test(&kn->count))
231 return; 230 return;
232 root = kernfs_root(kn); 231 root = kernfs_root(kn);
233 repeat: 232 repeat:
234 /* Moving/renaming is always done while holding reference. 233 /* Moving/renaming is always done while holding reference.
235 * kn->s_parent won't change beneath us. 234 * kn->parent won't change beneath us.
236 */ 235 */
237 parent = kn->s_parent; 236 parent = kn->parent;
238 237
239 WARN(!(kn->s_flags & SYSFS_FLAG_REMOVED), 238 WARN(!(kn->flags & SYSFS_FLAG_REMOVED),
240 "sysfs: free using entry: %s/%s\n", 239 "sysfs: free using entry: %s/%s\n",
241 parent ? parent->s_name : "", kn->s_name); 240 parent ? parent->name : "", kn->name);
242 241
243 if (sysfs_type(kn) == SYSFS_KOBJ_LINK) 242 if (sysfs_type(kn) == SYSFS_KOBJ_LINK)
244 kernfs_put(kn->s_symlink.target_kn); 243 kernfs_put(kn->symlink.target_kn);
245 if (sysfs_type(kn) & SYSFS_COPY_NAME) 244 if (sysfs_type(kn) & SYSFS_COPY_NAME)
246 kfree(kn->s_name); 245 kfree(kn->name);
247 if (kn->s_iattr) { 246 if (kn->iattr) {
248 if (kn->s_iattr->ia_secdata) 247 if (kn->iattr->ia_secdata)
249 security_release_secctx(kn->s_iattr->ia_secdata, 248 security_release_secctx(kn->iattr->ia_secdata,
250 kn->s_iattr->ia_secdata_len); 249 kn->iattr->ia_secdata_len);
251 simple_xattrs_free(&kn->s_iattr->xattrs); 250 simple_xattrs_free(&kn->iattr->xattrs);
252 } 251 }
253 kfree(kn->s_iattr); 252 kfree(kn->iattr);
254 ida_simple_remove(&root->ino_ida, kn->s_ino); 253 ida_simple_remove(&root->ino_ida, kn->ino);
255 kmem_cache_free(sysfs_dir_cachep, kn); 254 kmem_cache_free(sysfs_dir_cachep, kn);
256 255
257 kn = parent; 256 kn = parent;
258 if (kn) { 257 if (kn) {
259 if (atomic_dec_and_test(&kn->s_count)) 258 if (atomic_dec_and_test(&kn->count))
260 goto repeat; 259 goto repeat;
261 } else { 260 } else {
262 /* just released the root kn, free @root too */ 261 /* just released the root kn, free @root too */
@@ -269,7 +268,7 @@ EXPORT_SYMBOL_GPL(kernfs_put);
269static int sysfs_dentry_delete(const struct dentry *dentry) 268static int sysfs_dentry_delete(const struct dentry *dentry)
270{ 269{
271 struct kernfs_node *kn = dentry->d_fsdata; 270 struct kernfs_node *kn = dentry->d_fsdata;
272 return !(kn && !(kn->s_flags & SYSFS_FLAG_REMOVED)); 271 return !(kn && !(kn->flags & SYSFS_FLAG_REMOVED));
273} 272}
274 273
275static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags) 274static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
@@ -283,20 +282,20 @@ static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
283 mutex_lock(&sysfs_mutex); 282 mutex_lock(&sysfs_mutex);
284 283
285 /* The sysfs dirent has been deleted */ 284 /* The sysfs dirent has been deleted */
286 if (kn->s_flags & SYSFS_FLAG_REMOVED) 285 if (kn->flags & SYSFS_FLAG_REMOVED)
287 goto out_bad; 286 goto out_bad;
288 287
289 /* The sysfs dirent has been moved? */ 288 /* The sysfs dirent has been moved? */
290 if (dentry->d_parent->d_fsdata != kn->s_parent) 289 if (dentry->d_parent->d_fsdata != kn->parent)
291 goto out_bad; 290 goto out_bad;
292 291
293 /* The sysfs dirent has been renamed */ 292 /* The sysfs dirent has been renamed */
294 if (strcmp(dentry->d_name.name, kn->s_name) != 0) 293 if (strcmp(dentry->d_name.name, kn->name) != 0)
295 goto out_bad; 294 goto out_bad;
296 295
297 /* The sysfs dirent has been moved to a different namespace */ 296 /* The sysfs dirent has been moved to a different namespace */
298 if (kn->s_parent && kernfs_ns_enabled(kn->s_parent) && 297 if (kn->parent && kernfs_ns_enabled(kn->parent) &&
299 sysfs_info(dentry->d_sb)->ns != kn->s_ns) 298 sysfs_info(dentry->d_sb)->ns != kn->ns)
300 goto out_bad; 299 goto out_bad;
301 300
302 mutex_unlock(&sysfs_mutex); 301 mutex_unlock(&sysfs_mutex);
@@ -356,14 +355,14 @@ struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
356 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); 355 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL);
357 if (ret < 0) 356 if (ret < 0)
358 goto err_out2; 357 goto err_out2;
359 kn->s_ino = ret; 358 kn->ino = ret;
360 359
361 atomic_set(&kn->s_count, 1); 360 atomic_set(&kn->count, 1);
362 atomic_set(&kn->s_active, 0); 361 atomic_set(&kn->active, 0);
363 362
364 kn->s_name = name; 363 kn->name = name;
365 kn->s_mode = mode; 364 kn->mode = mode;
366 kn->s_flags = type | SYSFS_FLAG_REMOVED; 365 kn->flags = type | SYSFS_FLAG_REMOVED;
367 366
368 return kn; 367 return kn;
369 368
@@ -400,9 +399,9 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
400 * @kn: kernfs_node to be added 399 * @kn: kernfs_node to be added
401 * @parent: the parent kernfs_node to add @kn to 400 * @parent: the parent kernfs_node to add @kn to
402 * 401 *
403 * Get @parent and set @kn->s_parent to it and increment nlink of 402 * Get @parent and set @kn->parent to it and increment nlink of the
404 * the parent inode if @kn is a directory and link into the children 403 * parent inode if @kn is a directory and link into the children list
405 * list of the parent. 404 * of the parent.
406 * 405 *
407 * This function should be called between calls to 406 * This function should be called between calls to
408 * sysfs_addrm_start() and sysfs_addrm_finish() and should be 407 * sysfs_addrm_start() and sysfs_addrm_finish() and should be
@@ -422,18 +421,17 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
422 struct sysfs_inode_attrs *ps_iattr; 421 struct sysfs_inode_attrs *ps_iattr;
423 int ret; 422 int ret;
424 423
425 if (has_ns != (bool)kn->s_ns) { 424 if (has_ns != (bool)kn->ns) {
426 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 425 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
427 has_ns ? "required" : "invalid", 426 has_ns ? "required" : "invalid", parent->name, kn->name);
428 parent->s_name, kn->s_name);
429 return -EINVAL; 427 return -EINVAL;
430 } 428 }
431 429
432 if (sysfs_type(parent) != SYSFS_DIR) 430 if (sysfs_type(parent) != SYSFS_DIR)
433 return -EINVAL; 431 return -EINVAL;
434 432
435 kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns); 433 kn->hash = sysfs_name_hash(kn->name, kn->ns);
436 kn->s_parent = parent; 434 kn->parent = parent;
437 kernfs_get(parent); 435 kernfs_get(parent);
438 436
439 ret = sysfs_link_sibling(kn); 437 ret = sysfs_link_sibling(kn);
@@ -441,14 +439,14 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
441 return ret; 439 return ret;
442 440
443 /* Update timestamps on the parent */ 441 /* Update timestamps on the parent */
444 ps_iattr = parent->s_iattr; 442 ps_iattr = parent->iattr;
445 if (ps_iattr) { 443 if (ps_iattr) {
446 struct iattr *ps_iattrs = &ps_iattr->ia_iattr; 444 struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
447 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 445 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
448 } 446 }
449 447
450 /* Mark the entry added into directory tree */ 448 /* Mark the entry added into directory tree */
451 kn->s_flags &= ~SYSFS_FLAG_REMOVED; 449 kn->flags &= ~SYSFS_FLAG_REMOVED;
452 450
453 return 0; 451 return 0;
454} 452}
@@ -477,21 +475,21 @@ static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
477 * Removal can be called multiple times on the same node. Only the 475 * Removal can be called multiple times on the same node. Only the
478 * first invocation is effective and puts the base ref. 476 * first invocation is effective and puts the base ref.
479 */ 477 */
480 if (kn->s_flags & SYSFS_FLAG_REMOVED) 478 if (kn->flags & SYSFS_FLAG_REMOVED)
481 return; 479 return;
482 480
483 if (kn->s_parent) { 481 if (kn->parent) {
484 sysfs_unlink_sibling(kn); 482 sysfs_unlink_sibling(kn);
485 483
486 /* Update timestamps on the parent */ 484 /* Update timestamps on the parent */
487 ps_iattr = kn->s_parent->s_iattr; 485 ps_iattr = kn->parent->iattr;
488 if (ps_iattr) { 486 if (ps_iattr) {
489 ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; 487 ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME;
490 ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; 488 ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME;
491 } 489 }
492 } 490 }
493 491
494 kn->s_flags |= SYSFS_FLAG_REMOVED; 492 kn->flags |= SYSFS_FLAG_REMOVED;
495 kn->u.removed_list = acxt->removed; 493 kn->u.removed_list = acxt->removed;
496 acxt->removed = kn; 494 acxt->removed = kn;
497} 495}
@@ -538,7 +536,7 @@ static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
538 const unsigned char *name, 536 const unsigned char *name,
539 const void *ns) 537 const void *ns)
540{ 538{
541 struct rb_node *node = parent->s_dir.children.rb_node; 539 struct rb_node *node = parent->dir.children.rb_node;
542 bool has_ns = kernfs_ns_enabled(parent); 540 bool has_ns = kernfs_ns_enabled(parent);
543 unsigned int hash; 541 unsigned int hash;
544 542
@@ -546,8 +544,7 @@ static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
546 544
547 if (has_ns != (bool)ns) { 545 if (has_ns != (bool)ns) {
548 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 546 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
549 has_ns ? "required" : "invalid", 547 has_ns ? "required" : "invalid", parent->name, name);
550 parent->s_name, name);
551 return NULL; 548 return NULL;
552 } 549 }
553 550
@@ -617,9 +614,9 @@ struct kernfs_root *kernfs_create_root(void *priv)
617 return ERR_PTR(-ENOMEM); 614 return ERR_PTR(-ENOMEM);
618 } 615 }
619 616
620 kn->s_flags &= ~SYSFS_FLAG_REMOVED; 617 kn->flags &= ~SYSFS_FLAG_REMOVED;
621 kn->priv = priv; 618 kn->priv = priv;
622 kn->s_dir.root = root; 619 kn->dir.root = root;
623 620
624 root->kn = kn; 621 root->kn = kn;
625 622
@@ -661,8 +658,8 @@ struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
661 if (!kn) 658 if (!kn)
662 return ERR_PTR(-ENOMEM); 659 return ERR_PTR(-ENOMEM);
663 660
664 kn->s_dir.root = parent->s_dir.root; 661 kn->dir.root = parent->dir.root;
665 kn->s_ns = ns; 662 kn->ns = ns;
666 kn->priv = priv; 663 kn->priv = priv;
667 664
668 /* link in */ 665 /* link in */
@@ -738,7 +735,7 @@ static struct kernfs_node *sysfs_leftmost_descendant(struct kernfs_node *pos)
738 if (sysfs_type(pos) != SYSFS_DIR) 735 if (sysfs_type(pos) != SYSFS_DIR)
739 break; 736 break;
740 737
741 rbn = rb_first(&pos->s_dir.children); 738 rbn = rb_first(&pos->dir.children);
742 if (!rbn) 739 if (!rbn)
743 break; 740 break;
744 741
@@ -773,12 +770,12 @@ static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos,
773 return NULL; 770 return NULL;
774 771
775 /* if there's an unvisited sibling, visit its leftmost descendant */ 772 /* if there's an unvisited sibling, visit its leftmost descendant */
776 rbn = rb_next(&pos->s_rb); 773 rbn = rb_next(&pos->rb);
777 if (rbn) 774 if (rbn)
778 return sysfs_leftmost_descendant(rb_to_kn(rbn)); 775 return sysfs_leftmost_descendant(rb_to_kn(rbn));
779 776
780 /* no sibling left, visit parent */ 777 /* no sibling left, visit parent */
781 return pos->s_parent; 778 return pos->parent;
782} 779}
783 780
784static void __kernfs_remove(struct sysfs_addrm_cxt *acxt, 781static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
@@ -789,7 +786,7 @@ static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
789 if (!kn) 786 if (!kn)
790 return; 787 return;
791 788
792 pr_debug("sysfs %s: removing\n", kn->s_name); 789 pr_debug("sysfs %s: removing\n", kn->name);
793 790
794 next = NULL; 791 next = NULL;
795 do { 792 do {
@@ -865,8 +862,8 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
865 mutex_lock(&sysfs_mutex); 862 mutex_lock(&sysfs_mutex);
866 863
867 error = 0; 864 error = 0;
868 if ((kn->s_parent == new_parent) && (kn->s_ns == new_ns) && 865 if ((kn->parent == new_parent) && (kn->ns == new_ns) &&
869 (strcmp(kn->s_name, new_name) == 0)) 866 (strcmp(kn->name, new_name) == 0))
870 goto out; /* nothing to rename */ 867 goto out; /* nothing to rename */
871 868
872 error = -EEXIST; 869 error = -EEXIST;
@@ -874,14 +871,14 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
874 goto out; 871 goto out;
875 872
876 /* rename kernfs_node */ 873 /* rename kernfs_node */
877 if (strcmp(kn->s_name, new_name) != 0) { 874 if (strcmp(kn->name, new_name) != 0) {
878 error = -ENOMEM; 875 error = -ENOMEM;
879 new_name = kstrdup(new_name, GFP_KERNEL); 876 new_name = kstrdup(new_name, GFP_KERNEL);
880 if (!new_name) 877 if (!new_name)
881 goto out; 878 goto out;
882 879
883 kfree(kn->s_name); 880 kfree(kn->name);
884 kn->s_name = new_name; 881 kn->name = new_name;
885 } 882 }
886 883
887 /* 884 /*
@@ -889,10 +886,10 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
889 */ 886 */
890 sysfs_unlink_sibling(kn); 887 sysfs_unlink_sibling(kn);
891 kernfs_get(new_parent); 888 kernfs_get(new_parent);
892 kernfs_put(kn->s_parent); 889 kernfs_put(kn->parent);
893 kn->s_ns = new_ns; 890 kn->ns = new_ns;
894 kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns); 891 kn->hash = sysfs_name_hash(kn->name, kn->ns);
895 kn->s_parent = new_parent; 892 kn->parent = new_parent;
896 sysfs_link_sibling(kn); 893 sysfs_link_sibling(kn);
897 894
898 error = 0; 895 error = 0;
@@ -904,7 +901,7 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
904/* Relationship between s_mode and the DT_xxx types */ 901/* Relationship between s_mode and the DT_xxx types */
905static inline unsigned char dt_type(struct kernfs_node *kn) 902static inline unsigned char dt_type(struct kernfs_node *kn)
906{ 903{
907 return (kn->s_mode >> 12) & 15; 904 return (kn->mode >> 12) & 15;
908} 905}
909 906
910static int sysfs_dir_release(struct inode *inode, struct file *filp) 907static int sysfs_dir_release(struct inode *inode, struct file *filp)
@@ -917,29 +914,28 @@ static struct kernfs_node *sysfs_dir_pos(const void *ns,
917 struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos) 914 struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
918{ 915{
919 if (pos) { 916 if (pos) {
920 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) && 917 int valid = !(pos->flags & SYSFS_FLAG_REMOVED) &&
921 pos->s_parent == parent && 918 pos->parent == parent && hash == pos->hash;
922 hash == pos->s_hash;
923 kernfs_put(pos); 919 kernfs_put(pos);
924 if (!valid) 920 if (!valid)
925 pos = NULL; 921 pos = NULL;
926 } 922 }
927 if (!pos && (hash > 1) && (hash < INT_MAX)) { 923 if (!pos && (hash > 1) && (hash < INT_MAX)) {
928 struct rb_node *node = parent->s_dir.children.rb_node; 924 struct rb_node *node = parent->dir.children.rb_node;
929 while (node) { 925 while (node) {
930 pos = rb_to_kn(node); 926 pos = rb_to_kn(node);
931 927
932 if (hash < pos->s_hash) 928 if (hash < pos->hash)
933 node = node->rb_left; 929 node = node->rb_left;
934 else if (hash > pos->s_hash) 930 else if (hash > pos->hash)
935 node = node->rb_right; 931 node = node->rb_right;
936 else 932 else
937 break; 933 break;
938 } 934 }
939 } 935 }
940 /* Skip over entries in the wrong namespace */ 936 /* Skip over entries in the wrong namespace */
941 while (pos && pos->s_ns != ns) { 937 while (pos && pos->ns != ns) {
942 struct rb_node *node = rb_next(&pos->s_rb); 938 struct rb_node *node = rb_next(&pos->rb);
943 if (!node) 939 if (!node)
944 pos = NULL; 940 pos = NULL;
945 else 941 else
@@ -954,12 +950,12 @@ static struct kernfs_node *sysfs_dir_next_pos(const void *ns,
954 pos = sysfs_dir_pos(ns, parent, ino, pos); 950 pos = sysfs_dir_pos(ns, parent, ino, pos);
955 if (pos) 951 if (pos)
956 do { 952 do {
957 struct rb_node *node = rb_next(&pos->s_rb); 953 struct rb_node *node = rb_next(&pos->rb);
958 if (!node) 954 if (!node)
959 pos = NULL; 955 pos = NULL;
960 else 956 else
961 pos = rb_to_kn(node); 957 pos = rb_to_kn(node);
962 } while (pos && pos->s_ns != ns); 958 } while (pos && pos->ns != ns);
963 return pos; 959 return pos;
964} 960}
965 961
@@ -980,12 +976,12 @@ static int sysfs_readdir(struct file *file, struct dir_context *ctx)
980 for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos); 976 for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos);
981 pos; 977 pos;
982 pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) { 978 pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
983 const char *name = pos->s_name; 979 const char *name = pos->name;
984 unsigned int type = dt_type(pos); 980 unsigned int type = dt_type(pos);
985 int len = strlen(name); 981 int len = strlen(name);
986 ino_t ino = pos->s_ino; 982 ino_t ino = pos->ino;
987 983
988 ctx->pos = pos->s_hash; 984 ctx->pos = pos->hash;
989 file->private_data = pos; 985 file->private_data = pos;
990 kernfs_get(pos); 986 kernfs_get(pos);
991 987