aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/dir.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-12-11 14:11:58 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-11 20:39:20 -0500
commitc637b8acbe079edb477d887041755b489036f146 (patch)
tree7d6e856930752574bb1d56b56bea5a2bf816de72 /fs/kernfs/dir.c
parenta797bfc30532388e8a11ca726df60cdd77aa8675 (diff)
kernfs: s/sysfs/kernfs/ in internal functions and whatever is left
kernfs has just been separated out from sysfs and we're already in full conflict mode. Nothing can make the situation any worse. Let's take the chance to name things properly. This patch performs the following renames. * s/sysfs_*()/kernfs_*()/ in all internal functions * s/sysfs/kernfs/ in internal strings, comments and whatever is remaining * Uniformly rename various vfs operations so that they're consistently named and distinguishable. This patch is strictly rename only and doesn't introduce any functional difference. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/kernfs/dir.c')
-rw-r--r--fs/kernfs/dir.c212
1 files changed, 107 insertions, 105 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index d3c66237474f..6520066c49ea 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -22,13 +22,13 @@ DEFINE_MUTEX(kernfs_mutex);
22#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb) 22#define rb_to_kn(X) rb_entry((X), struct kernfs_node, rb)
23 23
24/** 24/**
25 * sysfs_name_hash 25 * kernfs_name_hash
26 * @name: Null terminated string to hash 26 * @name: Null terminated string to hash
27 * @ns: Namespace tag to hash 27 * @ns: Namespace tag to hash
28 * 28 *
29 * Returns 31 bit hash of ns + name (so it fits in an off_t ) 29 * Returns 31 bit hash of ns + name (so it fits in an off_t )
30 */ 30 */
31static unsigned int sysfs_name_hash(const char *name, const void *ns) 31static unsigned int kernfs_name_hash(const char *name, const void *ns)
32{ 32{
33 unsigned long hash = init_name_hash(); 33 unsigned long hash = init_name_hash();
34 unsigned int len = strlen(name); 34 unsigned int len = strlen(name);
@@ -44,8 +44,8 @@ static unsigned int sysfs_name_hash(const char *name, const void *ns)
44 return hash; 44 return hash;
45} 45}
46 46
47static int sysfs_name_compare(unsigned int hash, const char *name, 47static int kernfs_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->hash) 50 if (hash != kn->hash)
51 return hash - kn->hash; 51 return hash - kn->hash;
@@ -54,14 +54,14 @@ static int sysfs_name_compare(unsigned int hash, const char *name,
54 return strcmp(name, kn->name); 54 return strcmp(name, kn->name);
55} 55}
56 56
57static int sysfs_sd_compare(const struct kernfs_node *left, 57static int kernfs_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->hash, left->name, left->ns, right); 60 return kernfs_name_compare(left->hash, left->name, left->ns, right);
61} 61}
62 62
63/** 63/**
64 * sysfs_link_sibling - link kernfs_node into sibling rbtree 64 * kernfs_link_sibling - link kernfs_node into sibling rbtree
65 * @kn: kernfs_node of interest 65 * @kn: kernfs_node of interest
66 * 66 *
67 * Link @kn into its sibling rbtree which starts from 67 * Link @kn into its sibling rbtree which starts from
@@ -73,7 +73,7 @@ static int sysfs_sd_compare(const struct kernfs_node *left,
73 * RETURNS: 73 * RETURNS:
74 * 0 on susccess -EEXIST on failure. 74 * 0 on susccess -EEXIST on failure.
75 */ 75 */
76static int sysfs_link_sibling(struct kernfs_node *kn) 76static int kernfs_link_sibling(struct kernfs_node *kn)
77{ 77{
78 struct rb_node **node = &kn->parent->dir.children.rb_node; 78 struct rb_node **node = &kn->parent->dir.children.rb_node;
79 struct rb_node *parent = NULL; 79 struct rb_node *parent = NULL;
@@ -87,7 +87,7 @@ static int sysfs_link_sibling(struct kernfs_node *kn)
87 87
88 pos = rb_to_kn(*node); 88 pos = rb_to_kn(*node);
89 parent = *node; 89 parent = *node;
90 result = sysfs_sd_compare(kn, pos); 90 result = kernfs_sd_compare(kn, pos);
91 if (result < 0) 91 if (result < 0)
92 node = &pos->rb.rb_left; 92 node = &pos->rb.rb_left;
93 else if (result > 0) 93 else if (result > 0)
@@ -102,7 +102,7 @@ static int sysfs_link_sibling(struct kernfs_node *kn)
102} 102}
103 103
104/** 104/**
105 * sysfs_unlink_sibling - unlink kernfs_node from sibling rbtree 105 * kernfs_unlink_sibling - unlink kernfs_node from sibling rbtree
106 * @kn: kernfs_node of interest 106 * @kn: kernfs_node of interest
107 * 107 *
108 * Unlink @kn from its sibling rbtree which starts from 108 * Unlink @kn from its sibling rbtree which starts from
@@ -111,7 +111,7 @@ static int sysfs_link_sibling(struct kernfs_node *kn)
111 * Locking: 111 * Locking:
112 * mutex_lock(kernfs_mutex) 112 * mutex_lock(kernfs_mutex)
113 */ 113 */
114static void sysfs_unlink_sibling(struct kernfs_node *kn) 114static void kernfs_unlink_sibling(struct kernfs_node *kn)
115{ 115{
116 if (kernfs_type(kn) == KERNFS_DIR) 116 if (kernfs_type(kn) == KERNFS_DIR)
117 kn->parent->dir.subdirs--; 117 kn->parent->dir.subdirs--;
@@ -120,7 +120,7 @@ static void sysfs_unlink_sibling(struct kernfs_node *kn)
120} 120}
121 121
122/** 122/**
123 * sysfs_get_active - get an active reference to kernfs_node 123 * kernfs_get_active - get an active reference to kernfs_node
124 * @kn: kernfs_node to get an active reference to 124 * @kn: kernfs_node to get an active reference to
125 * 125 *
126 * Get an active reference of @kn. This function is noop if @kn 126 * Get an active reference of @kn. This function is noop if @kn
@@ -129,7 +129,7 @@ static void sysfs_unlink_sibling(struct kernfs_node *kn)
129 * RETURNS: 129 * RETURNS:
130 * Pointer to @kn on success, NULL on failure. 130 * Pointer to @kn on success, NULL on failure.
131 */ 131 */
132struct kernfs_node *sysfs_get_active(struct kernfs_node *kn) 132struct kernfs_node *kernfs_get_active(struct kernfs_node *kn)
133{ 133{
134 if (unlikely(!kn)) 134 if (unlikely(!kn))
135 return NULL; 135 return NULL;
@@ -143,13 +143,13 @@ struct kernfs_node *sysfs_get_active(struct kernfs_node *kn)
143} 143}
144 144
145/** 145/**
146 * sysfs_put_active - put an active reference to kernfs_node 146 * kernfs_put_active - put an active reference to kernfs_node
147 * @kn: kernfs_node to put an active reference to 147 * @kn: kernfs_node to put an active reference to
148 * 148 *
149 * Put an active reference to @kn. This function is noop if @kn 149 * Put an active reference to @kn. This function is noop if @kn
150 * is NULL. 150 * is NULL.
151 */ 151 */
152void sysfs_put_active(struct kernfs_node *kn) 152void kernfs_put_active(struct kernfs_node *kn)
153{ 153{
154 int v; 154 int v;
155 155
@@ -170,12 +170,12 @@ void sysfs_put_active(struct kernfs_node *kn)
170} 170}
171 171
172/** 172/**
173 * sysfs_deactivate - deactivate kernfs_node 173 * kernfs_deactivate - deactivate kernfs_node
174 * @kn: kernfs_node to deactivate 174 * @kn: kernfs_node to deactivate
175 * 175 *
176 * Deny new active references and drain existing ones. 176 * Deny new active references and drain existing ones.
177 */ 177 */
178static void sysfs_deactivate(struct kernfs_node *kn) 178static void kernfs_deactivate(struct kernfs_node *kn)
179{ 179{
180 DECLARE_COMPLETION_ONSTACK(wait); 180 DECLARE_COMPLETION_ONSTACK(wait);
181 int v; 181 int v;
@@ -235,9 +235,8 @@ void kernfs_put(struct kernfs_node *kn)
235 */ 235 */
236 parent = kn->parent; 236 parent = kn->parent;
237 237
238 WARN(!(kn->flags & KERNFS_REMOVED), 238 WARN(!(kn->flags & KERNFS_REMOVED), "kernfs: free using entry: %s/%s\n",
239 "sysfs: free using entry: %s/%s\n", 239 parent ? parent->name : "", kn->name);
240 parent ? parent->name : "", kn->name);
241 240
242 if (kernfs_type(kn) == KERNFS_LINK) 241 if (kernfs_type(kn) == KERNFS_LINK)
243 kernfs_put(kn->symlink.target_kn); 242 kernfs_put(kn->symlink.target_kn);
@@ -265,13 +264,13 @@ void kernfs_put(struct kernfs_node *kn)
265} 264}
266EXPORT_SYMBOL_GPL(kernfs_put); 265EXPORT_SYMBOL_GPL(kernfs_put);
267 266
268static int sysfs_dentry_delete(const struct dentry *dentry) 267static int kernfs_dop_delete(const struct dentry *dentry)
269{ 268{
270 struct kernfs_node *kn = dentry->d_fsdata; 269 struct kernfs_node *kn = dentry->d_fsdata;
271 return !(kn && !(kn->flags & KERNFS_REMOVED)); 270 return !(kn && !(kn->flags & KERNFS_REMOVED));
272} 271}
273 272
274static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags) 273static int kernfs_dop_revalidate(struct dentry *dentry, unsigned int flags)
275{ 274{
276 struct kernfs_node *kn; 275 struct kernfs_node *kn;
277 276
@@ -281,19 +280,19 @@ static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
281 kn = dentry->d_fsdata; 280 kn = dentry->d_fsdata;
282 mutex_lock(&kernfs_mutex); 281 mutex_lock(&kernfs_mutex);
283 282
284 /* The sysfs dirent has been deleted */ 283 /* The kernfs node has been deleted */
285 if (kn->flags & KERNFS_REMOVED) 284 if (kn->flags & KERNFS_REMOVED)
286 goto out_bad; 285 goto out_bad;
287 286
288 /* The sysfs dirent has been moved? */ 287 /* The kernfs node has been moved? */
289 if (dentry->d_parent->d_fsdata != kn->parent) 288 if (dentry->d_parent->d_fsdata != kn->parent)
290 goto out_bad; 289 goto out_bad;
291 290
292 /* The sysfs dirent has been renamed */ 291 /* The kernfs node has been renamed */
293 if (strcmp(dentry->d_name.name, kn->name) != 0) 292 if (strcmp(dentry->d_name.name, kn->name) != 0)
294 goto out_bad; 293 goto out_bad;
295 294
296 /* The sysfs dirent has been moved to a different namespace */ 295 /* The kernfs node has been moved to a different namespace */
297 if (kn->parent && kernfs_ns_enabled(kn->parent) && 296 if (kn->parent && kernfs_ns_enabled(kn->parent) &&
298 kernfs_info(dentry->d_sb)->ns != kn->ns) 297 kernfs_info(dentry->d_sb)->ns != kn->ns)
299 goto out_bad; 298 goto out_bad;
@@ -302,9 +301,10 @@ static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
302out_valid: 301out_valid:
303 return 1; 302 return 1;
304out_bad: 303out_bad:
305 /* Remove the dentry from the dcache hashes. 304 /*
305 * Remove the dentry from the dcache hashes.
306 * If this is a deleted dentry we use d_drop instead of d_delete 306 * If this is a deleted dentry we use d_drop instead of d_delete
307 * so sysfs doesn't need to cope with negative dentries. 307 * so kernfs doesn't need to cope with negative dentries.
308 * 308 *
309 * If this is a dentry that has simply been renamed we 309 * If this is a dentry that has simply been renamed we
310 * use d_drop to remove it from the dcache lookup on its 310 * use d_drop to remove it from the dcache lookup on its
@@ -324,19 +324,19 @@ out_bad:
324 return 0; 324 return 0;
325} 325}
326 326
327static void sysfs_dentry_release(struct dentry *dentry) 327static void kernfs_dop_release(struct dentry *dentry)
328{ 328{
329 kernfs_put(dentry->d_fsdata); 329 kernfs_put(dentry->d_fsdata);
330} 330}
331 331
332const struct dentry_operations kernfs_dops = { 332const struct dentry_operations kernfs_dops = {
333 .d_revalidate = sysfs_dentry_revalidate, 333 .d_revalidate = kernfs_dop_revalidate,
334 .d_delete = sysfs_dentry_delete, 334 .d_delete = kernfs_dop_delete,
335 .d_release = sysfs_dentry_release, 335 .d_release = kernfs_dop_release,
336}; 336};
337 337
338struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root, 338struct kernfs_node *kernfs_new_node(struct kernfs_root *root, const char *name,
339 const char *name, umode_t mode, int type) 339 umode_t mode, int type)
340{ 340{
341 char *dup_name = NULL; 341 char *dup_name = NULL;
342 struct kernfs_node *kn; 342 struct kernfs_node *kn;
@@ -374,7 +374,7 @@ struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
374} 374}
375 375
376/** 376/**
377 * sysfs_addrm_start - prepare for kernfs_node add/remove 377 * kernfs_addrm_start - prepare for kernfs_node add/remove
378 * @acxt: pointer to kernfs_addrm_cxt to be used 378 * @acxt: pointer to kernfs_addrm_cxt to be used
379 * 379 *
380 * This function is called when the caller is about to add or remove 380 * This function is called when the caller is about to add or remove
@@ -385,7 +385,7 @@ struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
385 * Kernel thread context (may sleep). kernfs_mutex is locked on 385 * Kernel thread context (may sleep). kernfs_mutex is locked on
386 * return. 386 * return.
387 */ 387 */
388void sysfs_addrm_start(struct kernfs_addrm_cxt *acxt) 388void kernfs_addrm_start(struct kernfs_addrm_cxt *acxt)
389 __acquires(kernfs_mutex) 389 __acquires(kernfs_mutex)
390{ 390{
391 memset(acxt, 0, sizeof(*acxt)); 391 memset(acxt, 0, sizeof(*acxt));
@@ -394,7 +394,7 @@ void sysfs_addrm_start(struct kernfs_addrm_cxt *acxt)
394} 394}
395 395
396/** 396/**
397 * sysfs_add_one - add kernfs_node to parent without warning 397 * kernfs_add_one - add kernfs_node to parent without warning
398 * @acxt: addrm context to use 398 * @acxt: addrm context to use
399 * @kn: kernfs_node to be added 399 * @kn: kernfs_node to be added
400 * @parent: the parent kernfs_node to add @kn to 400 * @parent: the parent kernfs_node to add @kn to
@@ -404,17 +404,17 @@ void sysfs_addrm_start(struct kernfs_addrm_cxt *acxt)
404 * of the parent. 404 * of the parent.
405 * 405 *
406 * This function should be called between calls to 406 * This function should be called between calls to
407 * sysfs_addrm_start() and sysfs_addrm_finish() and should be 407 * kernfs_addrm_start() and kernfs_addrm_finish() and should be passed
408 * passed the same @acxt as passed to sysfs_addrm_start(). 408 * the same @acxt as passed to kernfs_addrm_start().
409 * 409 *
410 * LOCKING: 410 * LOCKING:
411 * Determined by sysfs_addrm_start(). 411 * Determined by kernfs_addrm_start().
412 * 412 *
413 * RETURNS: 413 * RETURNS:
414 * 0 on success, -EEXIST if entry with the given name already 414 * 0 on success, -EEXIST if entry with the given name already
415 * exists. 415 * exists.
416 */ 416 */
417int sysfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn, 417int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
418 struct kernfs_node *parent) 418 struct kernfs_node *parent)
419{ 419{
420 bool has_ns = kernfs_ns_enabled(parent); 420 bool has_ns = kernfs_ns_enabled(parent);
@@ -422,7 +422,7 @@ int sysfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
422 int ret; 422 int ret;
423 423
424 if (has_ns != (bool)kn->ns) { 424 if (has_ns != (bool)kn->ns) {
425 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 425 WARN(1, KERN_WARNING "kernfs: ns %s in '%s' for '%s'\n",
426 has_ns ? "required" : "invalid", parent->name, kn->name); 426 has_ns ? "required" : "invalid", parent->name, kn->name);
427 return -EINVAL; 427 return -EINVAL;
428 } 428 }
@@ -430,11 +430,11 @@ int sysfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
430 if (kernfs_type(parent) != KERNFS_DIR) 430 if (kernfs_type(parent) != KERNFS_DIR)
431 return -EINVAL; 431 return -EINVAL;
432 432
433 kn->hash = sysfs_name_hash(kn->name, kn->ns); 433 kn->hash = kernfs_name_hash(kn->name, kn->ns);
434 kn->parent = parent; 434 kn->parent = parent;
435 kernfs_get(parent); 435 kernfs_get(parent);
436 436
437 ret = sysfs_link_sibling(kn); 437 ret = kernfs_link_sibling(kn);
438 if (ret) 438 if (ret)
439 return ret; 439 return ret;
440 440
@@ -452,7 +452,7 @@ int sysfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
452} 452}
453 453
454/** 454/**
455 * sysfs_remove_one - remove kernfs_node from parent 455 * kernfs_remove_one - remove kernfs_node from parent
456 * @acxt: addrm context to use 456 * @acxt: addrm context to use
457 * @kn: kernfs_node to be removed 457 * @kn: kernfs_node to be removed
458 * 458 *
@@ -460,14 +460,14 @@ int sysfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
460 * directory. @kn is unlinked from the children list. 460 * directory. @kn is unlinked from the children list.
461 * 461 *
462 * This function should be called between calls to 462 * This function should be called between calls to
463 * sysfs_addrm_start() and sysfs_addrm_finish() and should be 463 * kernfs_addrm_start() and kernfs_addrm_finish() and should be
464 * passed the same @acxt as passed to sysfs_addrm_start(). 464 * passed the same @acxt as passed to kernfs_addrm_start().
465 * 465 *
466 * LOCKING: 466 * LOCKING:
467 * Determined by sysfs_addrm_start(). 467 * Determined by kernfs_addrm_start().
468 */ 468 */
469static void sysfs_remove_one(struct kernfs_addrm_cxt *acxt, 469static void kernfs_remove_one(struct kernfs_addrm_cxt *acxt,
470 struct kernfs_node *kn) 470 struct kernfs_node *kn)
471{ 471{
472 struct kernfs_iattrs *ps_iattr; 472 struct kernfs_iattrs *ps_iattr;
473 473
@@ -479,7 +479,7 @@ static void sysfs_remove_one(struct kernfs_addrm_cxt *acxt,
479 return; 479 return;
480 480
481 if (kn->parent) { 481 if (kn->parent) {
482 sysfs_unlink_sibling(kn); 482 kernfs_unlink_sibling(kn);
483 483
484 /* Update timestamps on the parent */ 484 /* Update timestamps on the parent */
485 ps_iattr = kn->parent->iattr; 485 ps_iattr = kn->parent->iattr;
@@ -495,20 +495,20 @@ static void sysfs_remove_one(struct kernfs_addrm_cxt *acxt,
495} 495}
496 496
497/** 497/**
498 * sysfs_addrm_finish - finish up kernfs_node add/remove 498 * kernfs_addrm_finish - finish up kernfs_node add/remove
499 * @acxt: addrm context to finish up 499 * @acxt: addrm context to finish up
500 * 500 *
501 * Finish up kernfs_node add/remove. Resources acquired by 501 * Finish up kernfs_node add/remove. Resources acquired by
502 * sysfs_addrm_start() are released and removed kernfs_nodes are 502 * kernfs_addrm_start() are released and removed kernfs_nodes are
503 * cleaned up. 503 * cleaned up.
504 * 504 *
505 * LOCKING: 505 * LOCKING:
506 * kernfs_mutex is released. 506 * kernfs_mutex is released.
507 */ 507 */
508void sysfs_addrm_finish(struct kernfs_addrm_cxt *acxt) 508void kernfs_addrm_finish(struct kernfs_addrm_cxt *acxt)
509 __releases(kernfs_mutex) 509 __releases(kernfs_mutex)
510{ 510{
511 /* release resources acquired by sysfs_addrm_start() */ 511 /* release resources acquired by kernfs_addrm_start() */
512 mutex_unlock(&kernfs_mutex); 512 mutex_unlock(&kernfs_mutex);
513 513
514 /* kill removed kernfs_nodes */ 514 /* kill removed kernfs_nodes */
@@ -517,8 +517,8 @@ void sysfs_addrm_finish(struct kernfs_addrm_cxt *acxt)
517 517
518 acxt->removed = kn->u.removed_list; 518 acxt->removed = kn->u.removed_list;
519 519
520 sysfs_deactivate(kn); 520 kernfs_deactivate(kn);
521 sysfs_unmap_bin_file(kn); 521 kernfs_unmap_bin_file(kn);
522 kernfs_put(kn); 522 kernfs_put(kn);
523 } 523 }
524} 524}
@@ -543,18 +543,18 @@ static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
543 lockdep_assert_held(&kernfs_mutex); 543 lockdep_assert_held(&kernfs_mutex);
544 544
545 if (has_ns != (bool)ns) { 545 if (has_ns != (bool)ns) {
546 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 546 WARN(1, KERN_WARNING "kernfs: ns %s in '%s' for '%s'\n",
547 has_ns ? "required" : "invalid", parent->name, name); 547 has_ns ? "required" : "invalid", parent->name, name);
548 return NULL; 548 return NULL;
549 } 549 }
550 550
551 hash = sysfs_name_hash(name, ns); 551 hash = kernfs_name_hash(name, ns);
552 while (node) { 552 while (node) {
553 struct kernfs_node *kn; 553 struct kernfs_node *kn;
554 int result; 554 int result;
555 555
556 kn = rb_to_kn(node); 556 kn = rb_to_kn(node);
557 result = sysfs_name_compare(hash, name, ns, kn); 557 result = kernfs_name_compare(hash, name, ns, kn);
558 if (result < 0) 558 if (result < 0)
559 node = node->rb_left; 559 node = node->rb_left;
560 else if (result > 0) 560 else if (result > 0)
@@ -607,7 +607,7 @@ struct kernfs_root *kernfs_create_root(void *priv)
607 607
608 ida_init(&root->ino_ida); 608 ida_init(&root->ino_ida);
609 609
610 kn = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, KERNFS_DIR); 610 kn = kernfs_new_node(root, "", S_IFDIR | S_IRUGO | S_IXUGO, KERNFS_DIR);
611 if (!kn) { 611 if (!kn) {
612 ida_destroy(&root->ino_ida); 612 ida_destroy(&root->ino_ida);
613 kfree(root); 613 kfree(root);
@@ -654,7 +654,7 @@ struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
654 int rc; 654 int rc;
655 655
656 /* allocate */ 656 /* allocate */
657 kn = sysfs_new_dirent(kernfs_root(parent), name, mode, KERNFS_DIR); 657 kn = kernfs_new_node(kernfs_root(parent), name, mode, KERNFS_DIR);
658 if (!kn) 658 if (!kn)
659 return ERR_PTR(-ENOMEM); 659 return ERR_PTR(-ENOMEM);
660 660
@@ -663,9 +663,9 @@ struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
663 kn->priv = priv; 663 kn->priv = priv;
664 664
665 /* link in */ 665 /* link in */
666 sysfs_addrm_start(&acxt); 666 kernfs_addrm_start(&acxt);
667 rc = sysfs_add_one(&acxt, kn, parent); 667 rc = kernfs_add_one(&acxt, kn, parent);
668 sysfs_addrm_finish(&acxt); 668 kernfs_addrm_finish(&acxt);
669 669
670 if (!rc) 670 if (!rc)
671 return kn; 671 return kn;
@@ -674,8 +674,9 @@ struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
674 return ERR_PTR(rc); 674 return ERR_PTR(rc);
675} 675}
676 676
677static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry, 677static struct dentry *kernfs_iop_lookup(struct inode *dir,
678 unsigned int flags) 678 struct dentry *dentry,
679 unsigned int flags)
679{ 680{
680 struct dentry *ret = NULL; 681 struct dentry *ret = NULL;
681 struct kernfs_node *parent = dentry->d_parent->d_fsdata; 682 struct kernfs_node *parent = dentry->d_parent->d_fsdata;
@@ -699,7 +700,7 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
699 dentry->d_fsdata = kn; 700 dentry->d_fsdata = kn;
700 701
701 /* attach dentry and inode */ 702 /* attach dentry and inode */
702 inode = sysfs_get_inode(dir->i_sb, kn); 703 inode = kernfs_get_inode(dir->i_sb, kn);
703 if (!inode) { 704 if (!inode) {
704 ret = ERR_PTR(-ENOMEM); 705 ret = ERR_PTR(-ENOMEM);
705 goto out_unlock; 706 goto out_unlock;
@@ -713,17 +714,17 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
713} 714}
714 715
715const struct inode_operations kernfs_dir_iops = { 716const struct inode_operations kernfs_dir_iops = {
716 .lookup = sysfs_lookup, 717 .lookup = kernfs_iop_lookup,
717 .permission = sysfs_permission, 718 .permission = kernfs_iop_permission,
718 .setattr = sysfs_setattr, 719 .setattr = kernfs_iop_setattr,
719 .getattr = sysfs_getattr, 720 .getattr = kernfs_iop_getattr,
720 .setxattr = sysfs_setxattr, 721 .setxattr = kernfs_iop_setxattr,
721 .removexattr = sysfs_removexattr, 722 .removexattr = kernfs_iop_removexattr,
722 .getxattr = sysfs_getxattr, 723 .getxattr = kernfs_iop_getxattr,
723 .listxattr = sysfs_listxattr, 724 .listxattr = kernfs_iop_listxattr,
724}; 725};
725 726
726static struct kernfs_node *sysfs_leftmost_descendant(struct kernfs_node *pos) 727static struct kernfs_node *kernfs_leftmost_descendant(struct kernfs_node *pos)
727{ 728{
728 struct kernfs_node *last; 729 struct kernfs_node *last;
729 730
@@ -746,7 +747,7 @@ static struct kernfs_node *sysfs_leftmost_descendant(struct kernfs_node *pos)
746} 747}
747 748
748/** 749/**
749 * sysfs_next_descendant_post - find the next descendant for post-order walk 750 * kernfs_next_descendant_post - find the next descendant for post-order walk
750 * @pos: the current position (%NULL to initiate traversal) 751 * @pos: the current position (%NULL to initiate traversal)
751 * @root: kernfs_node whose descendants to walk 752 * @root: kernfs_node whose descendants to walk
752 * 753 *
@@ -754,8 +755,8 @@ static struct kernfs_node *sysfs_leftmost_descendant(struct kernfs_node *pos)
754 * descendants. @root is included in the iteration and the last node to be 755 * descendants. @root is included in the iteration and the last node to be
755 * visited. 756 * visited.
756 */ 757 */
757static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos, 758static struct kernfs_node *kernfs_next_descendant_post(struct kernfs_node *pos,
758 struct kernfs_node *root) 759 struct kernfs_node *root)
759{ 760{
760 struct rb_node *rbn; 761 struct rb_node *rbn;
761 762
@@ -763,7 +764,7 @@ static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos,
763 764
764 /* if first iteration, visit leftmost descendant which may be root */ 765 /* if first iteration, visit leftmost descendant which may be root */
765 if (!pos) 766 if (!pos)
766 return sysfs_leftmost_descendant(root); 767 return kernfs_leftmost_descendant(root);
767 768
768 /* if we visited @root, we're done */ 769 /* if we visited @root, we're done */
769 if (pos == root) 770 if (pos == root)
@@ -772,7 +773,7 @@ static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos,
772 /* if there's an unvisited sibling, visit its leftmost descendant */ 773 /* if there's an unvisited sibling, visit its leftmost descendant */
773 rbn = rb_next(&pos->rb); 774 rbn = rb_next(&pos->rb);
774 if (rbn) 775 if (rbn)
775 return sysfs_leftmost_descendant(rb_to_kn(rbn)); 776 return kernfs_leftmost_descendant(rb_to_kn(rbn));
776 777
777 /* no sibling left, visit parent */ 778 /* no sibling left, visit parent */
778 return pos->parent; 779 return pos->parent;
@@ -786,14 +787,14 @@ static void __kernfs_remove(struct kernfs_addrm_cxt *acxt,
786 if (!kn) 787 if (!kn)
787 return; 788 return;
788 789
789 pr_debug("sysfs %s: removing\n", kn->name); 790 pr_debug("kernfs %s: removing\n", kn->name);
790 791
791 next = NULL; 792 next = NULL;
792 do { 793 do {
793 pos = next; 794 pos = next;
794 next = sysfs_next_descendant_post(pos, kn); 795 next = kernfs_next_descendant_post(pos, kn);
795 if (pos) 796 if (pos)
796 sysfs_remove_one(acxt, pos); 797 kernfs_remove_one(acxt, pos);
797 } while (next); 798 } while (next);
798} 799}
799 800
@@ -807,9 +808,9 @@ void kernfs_remove(struct kernfs_node *kn)
807{ 808{
808 struct kernfs_addrm_cxt acxt; 809 struct kernfs_addrm_cxt acxt;
809 810
810 sysfs_addrm_start(&acxt); 811 kernfs_addrm_start(&acxt);
811 __kernfs_remove(&acxt, kn); 812 __kernfs_remove(&acxt, kn);
812 sysfs_addrm_finish(&acxt); 813 kernfs_addrm_finish(&acxt);
813} 814}
814 815
815/** 816/**
@@ -828,18 +829,18 @@ int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
828 struct kernfs_node *kn; 829 struct kernfs_node *kn;
829 830
830 if (!parent) { 831 if (!parent) {
831 WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n", 832 WARN(1, KERN_WARNING "kernfs: can not remove '%s', no directory\n",
832 name); 833 name);
833 return -ENOENT; 834 return -ENOENT;
834 } 835 }
835 836
836 sysfs_addrm_start(&acxt); 837 kernfs_addrm_start(&acxt);
837 838
838 kn = kernfs_find_ns(parent, name, ns); 839 kn = kernfs_find_ns(parent, name, ns);
839 if (kn) 840 if (kn)
840 __kernfs_remove(&acxt, kn); 841 __kernfs_remove(&acxt, kn);
841 842
842 sysfs_addrm_finish(&acxt); 843 kernfs_addrm_finish(&acxt);
843 844
844 if (kn) 845 if (kn)
845 return 0; 846 return 0;
@@ -884,13 +885,13 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
884 /* 885 /*
885 * Move to the appropriate place in the appropriate directories rbtree. 886 * Move to the appropriate place in the appropriate directories rbtree.
886 */ 887 */
887 sysfs_unlink_sibling(kn); 888 kernfs_unlink_sibling(kn);
888 kernfs_get(new_parent); 889 kernfs_get(new_parent);
889 kernfs_put(kn->parent); 890 kernfs_put(kn->parent);
890 kn->ns = new_ns; 891 kn->ns = new_ns;
891 kn->hash = sysfs_name_hash(kn->name, kn->ns); 892 kn->hash = kernfs_name_hash(kn->name, kn->ns);
892 kn->parent = new_parent; 893 kn->parent = new_parent;
893 sysfs_link_sibling(kn); 894 kernfs_link_sibling(kn);
894 895
895 error = 0; 896 error = 0;
896 out: 897 out:
@@ -904,13 +905,13 @@ static inline unsigned char dt_type(struct kernfs_node *kn)
904 return (kn->mode >> 12) & 15; 905 return (kn->mode >> 12) & 15;
905} 906}
906 907
907static int sysfs_dir_release(struct inode *inode, struct file *filp) 908static int kernfs_dir_fop_release(struct inode *inode, struct file *filp)
908{ 909{
909 kernfs_put(filp->private_data); 910 kernfs_put(filp->private_data);
910 return 0; 911 return 0;
911} 912}
912 913
913static struct kernfs_node *sysfs_dir_pos(const void *ns, 914static struct kernfs_node *kernfs_dir_pos(const void *ns,
914 struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos) 915 struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
915{ 916{
916 if (pos) { 917 if (pos) {
@@ -944,10 +945,10 @@ static struct kernfs_node *sysfs_dir_pos(const void *ns,
944 return pos; 945 return pos;
945} 946}
946 947
947static struct kernfs_node *sysfs_dir_next_pos(const void *ns, 948static struct kernfs_node *kernfs_dir_next_pos(const void *ns,
948 struct kernfs_node *parent, ino_t ino, struct kernfs_node *pos) 949 struct kernfs_node *parent, ino_t ino, struct kernfs_node *pos)
949{ 950{
950 pos = sysfs_dir_pos(ns, parent, ino, pos); 951 pos = kernfs_dir_pos(ns, parent, ino, pos);
951 if (pos) 952 if (pos)
952 do { 953 do {
953 struct rb_node *node = rb_next(&pos->rb); 954 struct rb_node *node = rb_next(&pos->rb);
@@ -959,7 +960,7 @@ static struct kernfs_node *sysfs_dir_next_pos(const void *ns,
959 return pos; 960 return pos;
960} 961}
961 962
962static int sysfs_readdir(struct file *file, struct dir_context *ctx) 963static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)
963{ 964{
964 struct dentry *dentry = file->f_path.dentry; 965 struct dentry *dentry = file->f_path.dentry;
965 struct kernfs_node *parent = dentry->d_fsdata; 966 struct kernfs_node *parent = dentry->d_fsdata;
@@ -973,9 +974,9 @@ static int sysfs_readdir(struct file *file, struct dir_context *ctx)
973 if (kernfs_ns_enabled(parent)) 974 if (kernfs_ns_enabled(parent))
974 ns = kernfs_info(dentry->d_sb)->ns; 975 ns = kernfs_info(dentry->d_sb)->ns;
975 976
976 for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos); 977 for (pos = kernfs_dir_pos(ns, parent, ctx->pos, pos);
977 pos; 978 pos;
978 pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) { 979 pos = kernfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
979 const char *name = pos->name; 980 const char *name = pos->name;
980 unsigned int type = dt_type(pos); 981 unsigned int type = dt_type(pos);
981 int len = strlen(name); 982 int len = strlen(name);
@@ -996,7 +997,8 @@ static int sysfs_readdir(struct file *file, struct dir_context *ctx)
996 return 0; 997 return 0;
997} 998}
998 999
999static loff_t sysfs_dir_llseek(struct file *file, loff_t offset, int whence) 1000static loff_t kernfs_dir_fop_llseek(struct file *file, loff_t offset,
1001 int whence)
1000{ 1002{
1001 struct inode *inode = file_inode(file); 1003 struct inode *inode = file_inode(file);
1002 loff_t ret; 1004 loff_t ret;
@@ -1010,7 +1012,7 @@ static loff_t sysfs_dir_llseek(struct file *file, loff_t offset, int whence)
1010 1012
1011const struct file_operations kernfs_dir_fops = { 1013const struct file_operations kernfs_dir_fops = {
1012 .read = generic_read_dir, 1014 .read = generic_read_dir,
1013 .iterate = sysfs_readdir, 1015 .iterate = kernfs_fop_readdir,
1014 .release = sysfs_dir_release, 1016 .release = kernfs_dir_fop_release,
1015 .llseek = sysfs_dir_llseek, 1017 .llseek = kernfs_dir_fop_llseek,
1016}; 1018};