aboutsummaryrefslogtreecommitdiffstats
path: root/fs/kernfs/dir.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-12-11 14:11:53 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-11 18:28:36 -0500
commit324a56e16e44baecac3ca799fd216154145c14bf (patch)
tree4fb43421bfe884cf4e245e3a4672295bae4c7bd9 /fs/kernfs/dir.c
parenta8b1c0193602b7ecdeaa7aa8c15c9c3da33244c8 (diff)
kernfs: s/sysfs_dirent/kernfs_node/ and rename its friends accordingly
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_elem_dir/kernfs_elem_dir/ * s/sysfs_elem_symlink/kernfs_elem_symlink/ * s/sysfs_elem_attr/kernfs_elem_file/ * s/sysfs_dirent/kernfs_node/ * s/sd/kn/ in kernfs proper * s/parent_sd/parent/ * s/target_sd/target/ * s/dir_sd/parent/ * s/to_sysfs_dirent()/rb_to_kn()/ * misc renames of local vars when they conflict with the above Because md, mic and gpio dig into sysfs details, this patch ends up modifying them. All are sysfs_dirent renames and trivial. While we can avoid these by introducing a dummy wrapping struct sysfs_dirent around kernfs_node, given the limited usage outside kernfs and sysfs proper, I don't think such workaround is called for. This patch is strictly rename only and doesn't introduce any functional difference. - mic / gpio renames were missing. Spotted by kbuild test robot. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Neil Brown <neilb@suse.de> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Ashutosh Dixit <ashutosh.dixit@intel.com> Cc: kbuild test robot <fengguang.wu@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/kernfs/dir.c')
-rw-r--r--fs/kernfs/dir.c542
1 files changed, 271 insertions, 271 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index a441e3be8052..800ebf521472 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 to_sysfs_dirent(X) rb_entry((X), struct sysfs_dirent, s_rb) 22#define rb_to_kn(X) rb_entry((X), struct kernfs_node, s_rb)
23 23
24/** 24/**
25 * sysfs_name_hash 25 * sysfs_name_hash
@@ -45,28 +45,28 @@ static unsigned int sysfs_name_hash(const char *name, const void *ns)
45} 45}
46 46
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 sysfs_dirent *sd) 48 const void *ns, const struct kernfs_node *kn)
49{ 49{
50 if (hash != sd->s_hash) 50 if (hash != kn->s_hash)
51 return hash - sd->s_hash; 51 return hash - kn->s_hash;
52 if (ns != sd->s_ns) 52 if (ns != kn->s_ns)
53 return ns - sd->s_ns; 53 return ns - kn->s_ns;
54 return strcmp(name, sd->s_name); 54 return strcmp(name, kn->s_name);
55} 55}
56 56
57static int sysfs_sd_compare(const struct sysfs_dirent *left, 57static int sysfs_sd_compare(const struct kernfs_node *left,
58 const struct sysfs_dirent *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->s_hash, left->s_name, left->s_ns,
61 right); 61 right);
62} 62}
63 63
64/** 64/**
65 * sysfs_link_sibling - link sysfs_dirent into sibling rbtree 65 * sysfs_link_sibling - link kernfs_node into sibling rbtree
66 * @sd: sysfs_dirent of interest 66 * @kn: kernfs_node of interest
67 * 67 *
68 * Link @sd into its sibling rbtree which starts from 68 * Link @kn into its sibling rbtree which starts from
69 * sd->s_parent->s_dir.children. 69 * @kn->s_parent->s_dir.children.
70 * 70 *
71 * Locking: 71 * Locking:
72 * mutex_lock(sysfs_mutex) 72 * mutex_lock(sysfs_mutex)
@@ -74,21 +74,21 @@ static int sysfs_sd_compare(const struct sysfs_dirent *left,
74 * RETURNS: 74 * RETURNS:
75 * 0 on susccess -EEXIST on failure. 75 * 0 on susccess -EEXIST on failure.
76 */ 76 */
77static int sysfs_link_sibling(struct sysfs_dirent *sd) 77static int sysfs_link_sibling(struct kernfs_node *kn)
78{ 78{
79 struct rb_node **node = &sd->s_parent->s_dir.children.rb_node; 79 struct rb_node **node = &kn->s_parent->s_dir.children.rb_node;
80 struct rb_node *parent = NULL; 80 struct rb_node *parent = NULL;
81 81
82 if (sysfs_type(sd) == SYSFS_DIR) 82 if (sysfs_type(kn) == SYSFS_DIR)
83 sd->s_parent->s_dir.subdirs++; 83 kn->s_parent->s_dir.subdirs++;
84 84
85 while (*node) { 85 while (*node) {
86 struct sysfs_dirent *pos; 86 struct kernfs_node *pos;
87 int result; 87 int result;
88 88
89 pos = to_sysfs_dirent(*node); 89 pos = rb_to_kn(*node);
90 parent = *node; 90 parent = *node;
91 result = sysfs_sd_compare(sd, pos); 91 result = sysfs_sd_compare(kn, pos);
92 if (result < 0) 92 if (result < 0)
93 node = &pos->s_rb.rb_left; 93 node = &pos->s_rb.rb_left;
94 else if (result > 0) 94 else if (result > 0)
@@ -97,168 +97,169 @@ static int sysfs_link_sibling(struct sysfs_dirent *sd)
97 return -EEXIST; 97 return -EEXIST;
98 } 98 }
99 /* add new node and rebalance the tree */ 99 /* add new node and rebalance the tree */
100 rb_link_node(&sd->s_rb, parent, node); 100 rb_link_node(&kn->s_rb, parent, node);
101 rb_insert_color(&sd->s_rb, &sd->s_parent->s_dir.children); 101 rb_insert_color(&kn->s_rb, &kn->s_parent->s_dir.children);
102 return 0; 102 return 0;
103} 103}
104 104
105/** 105/**
106 * sysfs_unlink_sibling - unlink sysfs_dirent from sibling rbtree 106 * sysfs_unlink_sibling - unlink kernfs_node from sibling rbtree
107 * @sd: sysfs_dirent of interest 107 * @kn: kernfs_node of interest
108 * 108 *
109 * Unlink @sd from its sibling rbtree which starts from 109 * Unlink @kn from its sibling rbtree which starts from
110 * sd->s_parent->s_dir.children. 110 * kn->s_parent->s_dir.children.
111 * 111 *
112 * Locking: 112 * Locking:
113 * mutex_lock(sysfs_mutex) 113 * mutex_lock(sysfs_mutex)
114 */ 114 */
115static void sysfs_unlink_sibling(struct sysfs_dirent *sd) 115static void sysfs_unlink_sibling(struct kernfs_node *kn)
116{ 116{
117 if (sysfs_type(sd) == SYSFS_DIR) 117 if (sysfs_type(kn) == SYSFS_DIR)
118 sd->s_parent->s_dir.subdirs--; 118 kn->s_parent->s_dir.subdirs--;
119 119
120 rb_erase(&sd->s_rb, &sd->s_parent->s_dir.children); 120 rb_erase(&kn->s_rb, &kn->s_parent->s_dir.children);
121} 121}
122 122
123/** 123/**
124 * sysfs_get_active - get an active reference to sysfs_dirent 124 * sysfs_get_active - get an active reference to kernfs_node
125 * @sd: sysfs_dirent to get an active reference to 125 * @kn: kernfs_node to get an active reference to
126 * 126 *
127 * Get an active reference of @sd. This function is noop if @sd 127 * Get an active reference of @kn. This function is noop if @kn
128 * is NULL. 128 * is NULL.
129 * 129 *
130 * RETURNS: 130 * RETURNS:
131 * Pointer to @sd on success, NULL on failure. 131 * Pointer to @kn on success, NULL on failure.
132 */ 132 */
133struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd) 133struct kernfs_node *sysfs_get_active(struct kernfs_node *kn)
134{ 134{
135 if (unlikely(!sd)) 135 if (unlikely(!kn))
136 return NULL; 136 return NULL;
137 137
138 if (!atomic_inc_unless_negative(&sd->s_active)) 138 if (!atomic_inc_unless_negative(&kn->s_active))
139 return NULL; 139 return NULL;
140 140
141 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 141 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
142 rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_); 142 rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_);
143 return sd; 143 return kn;
144} 144}
145 145
146/** 146/**
147 * sysfs_put_active - put an active reference to sysfs_dirent 147 * sysfs_put_active - put an active reference to kernfs_node
148 * @sd: sysfs_dirent to put an active reference to 148 * @kn: kernfs_node to put an active reference to
149 * 149 *
150 * Put an active reference to @sd. This function is noop if @sd 150 * Put an active reference to @kn. This function is noop if @kn
151 * is NULL. 151 * is NULL.
152 */ 152 */
153void sysfs_put_active(struct sysfs_dirent *sd) 153void sysfs_put_active(struct kernfs_node *kn)
154{ 154{
155 int v; 155 int v;
156 156
157 if (unlikely(!sd)) 157 if (unlikely(!kn))
158 return; 158 return;
159 159
160 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 160 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
161 rwsem_release(&sd->dep_map, 1, _RET_IP_); 161 rwsem_release(&kn->dep_map, 1, _RET_IP_);
162 v = atomic_dec_return(&sd->s_active); 162 v = atomic_dec_return(&kn->s_active);
163 if (likely(v != SD_DEACTIVATED_BIAS)) 163 if (likely(v != SD_DEACTIVATED_BIAS))
164 return; 164 return;
165 165
166 /* atomic_dec_return() is a mb(), we'll always see the updated 166 /*
167 * sd->u.completion. 167 * atomic_dec_return() is a mb(), we'll always see the updated
168 * kn->u.completion.
168 */ 169 */
169 complete(sd->u.completion); 170 complete(kn->u.completion);
170} 171}
171 172
172/** 173/**
173 * sysfs_deactivate - deactivate sysfs_dirent 174 * sysfs_deactivate - deactivate kernfs_node
174 * @sd: sysfs_dirent to deactivate 175 * @kn: kernfs_node to deactivate
175 * 176 *
176 * Deny new active references and drain existing ones. 177 * Deny new active references and drain existing ones.
177 */ 178 */
178static void sysfs_deactivate(struct sysfs_dirent *sd) 179static void sysfs_deactivate(struct kernfs_node *kn)
179{ 180{
180 DECLARE_COMPLETION_ONSTACK(wait); 181 DECLARE_COMPLETION_ONSTACK(wait);
181 int v; 182 int v;
182 183
183 BUG_ON(!(sd->s_flags & SYSFS_FLAG_REMOVED)); 184 BUG_ON(!(kn->s_flags & SYSFS_FLAG_REMOVED));
184 185
185 if (!(sysfs_type(sd) & SYSFS_ACTIVE_REF)) 186 if (!(sysfs_type(kn) & SYSFS_ACTIVE_REF))
186 return; 187 return;
187 188
188 sd->u.completion = (void *)&wait; 189 kn->u.completion = (void *)&wait;
189 190
190 rwsem_acquire(&sd->dep_map, 0, 0, _RET_IP_); 191 rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
191 /* atomic_add_return() is a mb(), put_active() will always see 192 /* atomic_add_return() is a mb(), put_active() will always see
192 * the updated sd->u.completion. 193 * the updated kn->u.completion.
193 */ 194 */
194 v = atomic_add_return(SD_DEACTIVATED_BIAS, &sd->s_active); 195 v = atomic_add_return(SD_DEACTIVATED_BIAS, &kn->s_active);
195 196
196 if (v != SD_DEACTIVATED_BIAS) { 197 if (v != SD_DEACTIVATED_BIAS) {
197 lock_contended(&sd->dep_map, _RET_IP_); 198 lock_contended(&kn->dep_map, _RET_IP_);
198 wait_for_completion(&wait); 199 wait_for_completion(&wait);
199 } 200 }
200 201
201 lock_acquired(&sd->dep_map, _RET_IP_); 202 lock_acquired(&kn->dep_map, _RET_IP_);
202 rwsem_release(&sd->dep_map, 1, _RET_IP_); 203 rwsem_release(&kn->dep_map, 1, _RET_IP_);
203} 204}
204 205
205/** 206/**
206 * kernfs_get - get a reference count on a sysfs_dirent 207 * kernfs_get - get a reference count on a kernfs_node
207 * @sd: the target sysfs_dirent 208 * @kn: the target kernfs_node
208 */ 209 */
209void kernfs_get(struct sysfs_dirent *sd) 210void kernfs_get(struct kernfs_node *kn)
210{ 211{
211 if (sd) { 212 if (kn) {
212 WARN_ON(!atomic_read(&sd->s_count)); 213 WARN_ON(!atomic_read(&kn->s_count));
213 atomic_inc(&sd->s_count); 214 atomic_inc(&kn->s_count);
214 } 215 }
215} 216}
216EXPORT_SYMBOL_GPL(kernfs_get); 217EXPORT_SYMBOL_GPL(kernfs_get);
217 218
218/** 219/**
219 * kernfs_put - put a reference count on a sysfs_dirent 220 * kernfs_put - put a reference count on a kernfs_node
220 * @sd: the target sysfs_dirent 221 * @kn: the target kernfs_node
221 * 222 *
222 * Put a reference count of @sd and destroy it if it reached zero. 223 * Put a reference count of @kn and destroy it if it reached zero.
223 */ 224 */
224void kernfs_put(struct sysfs_dirent *sd) 225void kernfs_put(struct kernfs_node *kn)
225{ 226{
226 struct sysfs_dirent *parent_sd; 227 struct kernfs_node *parent;
227 struct kernfs_root *root; 228 struct kernfs_root *root;
228 229
229 if (!sd || !atomic_dec_and_test(&sd->s_count)) 230 if (!kn || !atomic_dec_and_test(&kn->s_count))
230 return; 231 return;
231 root = kernfs_root(sd); 232 root = kernfs_root(kn);
232 repeat: 233 repeat:
233 /* Moving/renaming is always done while holding reference. 234 /* Moving/renaming is always done while holding reference.
234 * sd->s_parent won't change beneath us. 235 * kn->s_parent won't change beneath us.
235 */ 236 */
236 parent_sd = sd->s_parent; 237 parent = kn->s_parent;
237 238
238 WARN(!(sd->s_flags & SYSFS_FLAG_REMOVED), 239 WARN(!(kn->s_flags & SYSFS_FLAG_REMOVED),
239 "sysfs: free using entry: %s/%s\n", 240 "sysfs: free using entry: %s/%s\n",
240 parent_sd ? parent_sd->s_name : "", sd->s_name); 241 parent ? parent->s_name : "", kn->s_name);
241 242
242 if (sysfs_type(sd) == SYSFS_KOBJ_LINK) 243 if (sysfs_type(kn) == SYSFS_KOBJ_LINK)
243 kernfs_put(sd->s_symlink.target_sd); 244 kernfs_put(kn->s_symlink.target_kn);
244 if (sysfs_type(sd) & SYSFS_COPY_NAME) 245 if (sysfs_type(kn) & SYSFS_COPY_NAME)
245 kfree(sd->s_name); 246 kfree(kn->s_name);
246 if (sd->s_iattr) { 247 if (kn->s_iattr) {
247 if (sd->s_iattr->ia_secdata) 248 if (kn->s_iattr->ia_secdata)
248 security_release_secctx(sd->s_iattr->ia_secdata, 249 security_release_secctx(kn->s_iattr->ia_secdata,
249 sd->s_iattr->ia_secdata_len); 250 kn->s_iattr->ia_secdata_len);
250 simple_xattrs_free(&sd->s_iattr->xattrs); 251 simple_xattrs_free(&kn->s_iattr->xattrs);
251 } 252 }
252 kfree(sd->s_iattr); 253 kfree(kn->s_iattr);
253 ida_simple_remove(&root->ino_ida, sd->s_ino); 254 ida_simple_remove(&root->ino_ida, kn->s_ino);
254 kmem_cache_free(sysfs_dir_cachep, sd); 255 kmem_cache_free(sysfs_dir_cachep, kn);
255 256
256 sd = parent_sd; 257 kn = parent;
257 if (sd) { 258 if (kn) {
258 if (atomic_dec_and_test(&sd->s_count)) 259 if (atomic_dec_and_test(&kn->s_count))
259 goto repeat; 260 goto repeat;
260 } else { 261 } else {
261 /* just released the root sd, free @root too */ 262 /* just released the root kn, free @root too */
262 ida_destroy(&root->ino_ida); 263 ida_destroy(&root->ino_ida);
263 kfree(root); 264 kfree(root);
264 } 265 }
@@ -267,35 +268,35 @@ EXPORT_SYMBOL_GPL(kernfs_put);
267 268
268static int sysfs_dentry_delete(const struct dentry *dentry) 269static int sysfs_dentry_delete(const struct dentry *dentry)
269{ 270{
270 struct sysfs_dirent *sd = dentry->d_fsdata; 271 struct kernfs_node *kn = dentry->d_fsdata;
271 return !(sd && !(sd->s_flags & SYSFS_FLAG_REMOVED)); 272 return !(kn && !(kn->s_flags & SYSFS_FLAG_REMOVED));
272} 273}
273 274
274static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags) 275static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags)
275{ 276{
276 struct sysfs_dirent *sd; 277 struct kernfs_node *kn;
277 278
278 if (flags & LOOKUP_RCU) 279 if (flags & LOOKUP_RCU)
279 return -ECHILD; 280 return -ECHILD;
280 281
281 sd = dentry->d_fsdata; 282 kn = dentry->d_fsdata;
282 mutex_lock(&sysfs_mutex); 283 mutex_lock(&sysfs_mutex);
283 284
284 /* The sysfs dirent has been deleted */ 285 /* The sysfs dirent has been deleted */
285 if (sd->s_flags & SYSFS_FLAG_REMOVED) 286 if (kn->s_flags & SYSFS_FLAG_REMOVED)
286 goto out_bad; 287 goto out_bad;
287 288
288 /* The sysfs dirent has been moved? */ 289 /* The sysfs dirent has been moved? */
289 if (dentry->d_parent->d_fsdata != sd->s_parent) 290 if (dentry->d_parent->d_fsdata != kn->s_parent)
290 goto out_bad; 291 goto out_bad;
291 292
292 /* The sysfs dirent has been renamed */ 293 /* The sysfs dirent has been renamed */
293 if (strcmp(dentry->d_name.name, sd->s_name) != 0) 294 if (strcmp(dentry->d_name.name, kn->s_name) != 0)
294 goto out_bad; 295 goto out_bad;
295 296
296 /* The sysfs dirent has been moved to a different namespace */ 297 /* The sysfs dirent has been moved to a different namespace */
297 if (sd->s_parent && kernfs_ns_enabled(sd->s_parent) && 298 if (kn->s_parent && kernfs_ns_enabled(kn->s_parent) &&
298 sysfs_info(dentry->d_sb)->ns != sd->s_ns) 299 sysfs_info(dentry->d_sb)->ns != kn->s_ns)
299 goto out_bad; 300 goto out_bad;
300 301
301 mutex_unlock(&sysfs_mutex); 302 mutex_unlock(&sysfs_mutex);
@@ -335,11 +336,11 @@ const struct dentry_operations sysfs_dentry_ops = {
335 .d_release = sysfs_dentry_release, 336 .d_release = sysfs_dentry_release,
336}; 337};
337 338
338struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, 339struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
339 const char *name, umode_t mode, int type) 340 const char *name, umode_t mode, int type)
340{ 341{
341 char *dup_name = NULL; 342 char *dup_name = NULL;
342 struct sysfs_dirent *sd; 343 struct kernfs_node *kn;
343 int ret; 344 int ret;
344 345
345 if (type & SYSFS_COPY_NAME) { 346 if (type & SYSFS_COPY_NAME) {
@@ -348,38 +349,38 @@ struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root,
348 return NULL; 349 return NULL;
349 } 350 }
350 351
351 sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); 352 kn = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL);
352 if (!sd) 353 if (!kn)
353 goto err_out1; 354 goto err_out1;
354 355
355 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); 356 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL);
356 if (ret < 0) 357 if (ret < 0)
357 goto err_out2; 358 goto err_out2;
358 sd->s_ino = ret; 359 kn->s_ino = ret;
359 360
360 atomic_set(&sd->s_count, 1); 361 atomic_set(&kn->s_count, 1);
361 atomic_set(&sd->s_active, 0); 362 atomic_set(&kn->s_active, 0);
362 363
363 sd->s_name = name; 364 kn->s_name = name;
364 sd->s_mode = mode; 365 kn->s_mode = mode;
365 sd->s_flags = type | SYSFS_FLAG_REMOVED; 366 kn->s_flags = type | SYSFS_FLAG_REMOVED;
366 367
367 return sd; 368 return kn;
368 369
369 err_out2: 370 err_out2:
370 kmem_cache_free(sysfs_dir_cachep, sd); 371 kmem_cache_free(sysfs_dir_cachep, kn);
371 err_out1: 372 err_out1:
372 kfree(dup_name); 373 kfree(dup_name);
373 return NULL; 374 return NULL;
374} 375}
375 376
376/** 377/**
377 * sysfs_addrm_start - prepare for sysfs_dirent add/remove 378 * sysfs_addrm_start - prepare for kernfs_node add/remove
378 * @acxt: pointer to sysfs_addrm_cxt to be used 379 * @acxt: pointer to sysfs_addrm_cxt to be used
379 * 380 *
380 * This function is called when the caller is about to add or remove 381 * This function is called when the caller is about to add or remove
381 * sysfs_dirent. This function acquires sysfs_mutex. @acxt is used 382 * kernfs_node. This function acquires sysfs_mutex. @acxt is used to
382 * to keep and pass context to other addrm functions. 383 * keep and pass context to other addrm functions.
383 * 384 *
384 * LOCKING: 385 * LOCKING:
385 * Kernel thread context (may sleep). sysfs_mutex is locked on 386 * Kernel thread context (may sleep). sysfs_mutex is locked on
@@ -394,13 +395,13 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
394} 395}
395 396
396/** 397/**
397 * sysfs_add_one - add sysfs_dirent to parent without warning 398 * sysfs_add_one - add kernfs_node to parent without warning
398 * @acxt: addrm context to use 399 * @acxt: addrm context to use
399 * @sd: sysfs_dirent to be added 400 * @kn: kernfs_node to be added
400 * @parent_sd: the parent sysfs_dirent to add @sd to 401 * @parent: the parent kernfs_node to add @kn to
401 * 402 *
402 * Get @parent_sd and set @sd->s_parent to it and increment nlink of 403 * Get @parent and set @kn->s_parent to it and increment nlink of
403 * the parent inode if @sd is a directory and link into the children 404 * the parent inode if @kn is a directory and link into the children
404 * list of the parent. 405 * list of the parent.
405 * 406 *
406 * This function should be called between calls to 407 * This function should be called between calls to
@@ -414,51 +415,51 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
414 * 0 on success, -EEXIST if entry with the given name already 415 * 0 on success, -EEXIST if entry with the given name already
415 * exists. 416 * exists.
416 */ 417 */
417int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, 418int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
418 struct sysfs_dirent *parent_sd) 419 struct kernfs_node *parent)
419{ 420{
420 bool has_ns = kernfs_ns_enabled(parent_sd); 421 bool has_ns = kernfs_ns_enabled(parent);
421 struct sysfs_inode_attrs *ps_iattr; 422 struct sysfs_inode_attrs *ps_iattr;
422 int ret; 423 int ret;
423 424
424 if (has_ns != (bool)sd->s_ns) { 425 if (has_ns != (bool)kn->s_ns) {
425 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 426 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
426 has_ns ? "required" : "invalid", 427 has_ns ? "required" : "invalid",
427 parent_sd->s_name, sd->s_name); 428 parent->s_name, kn->s_name);
428 return -EINVAL; 429 return -EINVAL;
429 } 430 }
430 431
431 if (sysfs_type(parent_sd) != SYSFS_DIR) 432 if (sysfs_type(parent) != SYSFS_DIR)
432 return -EINVAL; 433 return -EINVAL;
433 434
434 sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); 435 kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
435 sd->s_parent = parent_sd; 436 kn->s_parent = parent;
436 kernfs_get(parent_sd); 437 kernfs_get(parent);
437 438
438 ret = sysfs_link_sibling(sd); 439 ret = sysfs_link_sibling(kn);
439 if (ret) 440 if (ret)
440 return ret; 441 return ret;
441 442
442 /* Update timestamps on the parent */ 443 /* Update timestamps on the parent */
443 ps_iattr = parent_sd->s_iattr; 444 ps_iattr = parent->s_iattr;
444 if (ps_iattr) { 445 if (ps_iattr) {
445 struct iattr *ps_iattrs = &ps_iattr->ia_iattr; 446 struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
446 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 447 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
447 } 448 }
448 449
449 /* Mark the entry added into directory tree */ 450 /* Mark the entry added into directory tree */
450 sd->s_flags &= ~SYSFS_FLAG_REMOVED; 451 kn->s_flags &= ~SYSFS_FLAG_REMOVED;
451 452
452 return 0; 453 return 0;
453} 454}
454 455
455/** 456/**
456 * sysfs_remove_one - remove sysfs_dirent from parent 457 * sysfs_remove_one - remove kernfs_node from parent
457 * @acxt: addrm context to use 458 * @acxt: addrm context to use
458 * @sd: sysfs_dirent to be removed 459 * @kn: kernfs_node to be removed
459 * 460 *
460 * Mark @sd removed and drop nlink of parent inode if @sd is a 461 * Mark @kn removed and drop nlink of parent inode if @kn is a
461 * directory. @sd is unlinked from the children list. 462 * directory. @kn is unlinked from the children list.
462 * 463 *
463 * This function should be called between calls to 464 * This function should be called between calls to
464 * sysfs_addrm_start() and sysfs_addrm_finish() and should be 465 * sysfs_addrm_start() and sysfs_addrm_finish() and should be
@@ -468,7 +469,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
468 * Determined by sysfs_addrm_start(). 469 * Determined by sysfs_addrm_start().
469 */ 470 */
470static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, 471static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
471 struct sysfs_dirent *sd) 472 struct kernfs_node *kn)
472{ 473{
473 struct sysfs_inode_attrs *ps_iattr; 474 struct sysfs_inode_attrs *ps_iattr;
474 475
@@ -476,31 +477,31 @@ static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
476 * Removal can be called multiple times on the same node. Only the 477 * Removal can be called multiple times on the same node. Only the
477 * first invocation is effective and puts the base ref. 478 * first invocation is effective and puts the base ref.
478 */ 479 */
479 if (sd->s_flags & SYSFS_FLAG_REMOVED) 480 if (kn->s_flags & SYSFS_FLAG_REMOVED)
480 return; 481 return;
481 482
482 if (sd->s_parent) { 483 if (kn->s_parent) {
483 sysfs_unlink_sibling(sd); 484 sysfs_unlink_sibling(kn);
484 485
485 /* Update timestamps on the parent */ 486 /* Update timestamps on the parent */
486 ps_iattr = sd->s_parent->s_iattr; 487 ps_iattr = kn->s_parent->s_iattr;
487 if (ps_iattr) { 488 if (ps_iattr) {
488 ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; 489 ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME;
489 ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; 490 ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME;
490 } 491 }
491 } 492 }
492 493
493 sd->s_flags |= SYSFS_FLAG_REMOVED; 494 kn->s_flags |= SYSFS_FLAG_REMOVED;
494 sd->u.removed_list = acxt->removed; 495 kn->u.removed_list = acxt->removed;
495 acxt->removed = sd; 496 acxt->removed = kn;
496} 497}
497 498
498/** 499/**
499 * sysfs_addrm_finish - finish up sysfs_dirent add/remove 500 * sysfs_addrm_finish - finish up kernfs_node add/remove
500 * @acxt: addrm context to finish up 501 * @acxt: addrm context to finish up
501 * 502 *
502 * Finish up sysfs_dirent add/remove. Resources acquired by 503 * Finish up kernfs_node add/remove. Resources acquired by
503 * sysfs_addrm_start() are released and removed sysfs_dirents are 504 * sysfs_addrm_start() are released and removed kernfs_nodes are
504 * cleaned up. 505 * cleaned up.
505 * 506 *
506 * LOCKING: 507 * LOCKING:
@@ -512,30 +513,30 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
512 /* release resources acquired by sysfs_addrm_start() */ 513 /* release resources acquired by sysfs_addrm_start() */
513 mutex_unlock(&sysfs_mutex); 514 mutex_unlock(&sysfs_mutex);
514 515
515 /* kill removed sysfs_dirents */ 516 /* kill removed kernfs_nodes */
516 while (acxt->removed) { 517 while (acxt->removed) {
517 struct sysfs_dirent *sd = acxt->removed; 518 struct kernfs_node *kn = acxt->removed;
518 519
519 acxt->removed = sd->u.removed_list; 520 acxt->removed = kn->u.removed_list;
520 521
521 sysfs_deactivate(sd); 522 sysfs_deactivate(kn);
522 sysfs_unmap_bin_file(sd); 523 sysfs_unmap_bin_file(kn);
523 kernfs_put(sd); 524 kernfs_put(kn);
524 } 525 }
525} 526}
526 527
527/** 528/**
528 * kernfs_find_ns - find sysfs_dirent with the given name 529 * kernfs_find_ns - find kernfs_node with the given name
529 * @parent: sysfs_dirent to search under 530 * @parent: kernfs_node to search under
530 * @name: name to look for 531 * @name: name to look for
531 * @ns: the namespace tag to use 532 * @ns: the namespace tag to use
532 * 533 *
533 * Look for sysfs_dirent with name @name under @parent. Returns pointer to 534 * Look for kernfs_node with name @name under @parent. Returns pointer to
534 * the found sysfs_dirent on success, %NULL on failure. 535 * the found kernfs_node on success, %NULL on failure.
535 */ 536 */
536static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent, 537static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent,
537 const unsigned char *name, 538 const unsigned char *name,
538 const void *ns) 539 const void *ns)
539{ 540{
540 struct rb_node *node = parent->s_dir.children.rb_node; 541 struct rb_node *node = parent->s_dir.children.rb_node;
541 bool has_ns = kernfs_ns_enabled(parent); 542 bool has_ns = kernfs_ns_enabled(parent);
@@ -552,42 +553,42 @@ static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent,
552 553
553 hash = sysfs_name_hash(name, ns); 554 hash = sysfs_name_hash(name, ns);
554 while (node) { 555 while (node) {
555 struct sysfs_dirent *sd; 556 struct kernfs_node *kn;
556 int result; 557 int result;
557 558
558 sd = to_sysfs_dirent(node); 559 kn = rb_to_kn(node);
559 result = sysfs_name_compare(hash, name, ns, sd); 560 result = sysfs_name_compare(hash, name, ns, kn);
560 if (result < 0) 561 if (result < 0)
561 node = node->rb_left; 562 node = node->rb_left;
562 else if (result > 0) 563 else if (result > 0)
563 node = node->rb_right; 564 node = node->rb_right;
564 else 565 else
565 return sd; 566 return kn;
566 } 567 }
567 return NULL; 568 return NULL;
568} 569}
569 570
570/** 571/**
571 * kernfs_find_and_get_ns - find and get sysfs_dirent with the given name 572 * kernfs_find_and_get_ns - find and get kernfs_node with the given name
572 * @parent: sysfs_dirent to search under 573 * @parent: kernfs_node to search under
573 * @name: name to look for 574 * @name: name to look for
574 * @ns: the namespace tag to use 575 * @ns: the namespace tag to use
575 * 576 *
576 * Look for sysfs_dirent with name @name under @parent and get a reference 577 * Look for kernfs_node with name @name under @parent and get a reference
577 * if found. This function may sleep and returns pointer to the found 578 * if found. This function may sleep and returns pointer to the found
578 * sysfs_dirent on success, %NULL on failure. 579 * kernfs_node on success, %NULL on failure.
579 */ 580 */
580struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, 581struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
581 const char *name, const void *ns) 582 const char *name, const void *ns)
582{ 583{
583 struct sysfs_dirent *sd; 584 struct kernfs_node *kn;
584 585
585 mutex_lock(&sysfs_mutex); 586 mutex_lock(&sysfs_mutex);
586 sd = kernfs_find_ns(parent, name, ns); 587 kn = kernfs_find_ns(parent, name, ns);
587 kernfs_get(sd); 588 kernfs_get(kn);
588 mutex_unlock(&sysfs_mutex); 589 mutex_unlock(&sysfs_mutex);
589 590
590 return sd; 591 return kn;
591} 592}
592EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns); 593EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
593 594
@@ -601,7 +602,7 @@ EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns);
601struct kernfs_root *kernfs_create_root(void *priv) 602struct kernfs_root *kernfs_create_root(void *priv)
602{ 603{
603 struct kernfs_root *root; 604 struct kernfs_root *root;
604 struct sysfs_dirent *sd; 605 struct kernfs_node *kn;
605 606
606 root = kzalloc(sizeof(*root), GFP_KERNEL); 607 root = kzalloc(sizeof(*root), GFP_KERNEL);
607 if (!root) 608 if (!root)
@@ -609,18 +610,18 @@ struct kernfs_root *kernfs_create_root(void *priv)
609 610
610 ida_init(&root->ino_ida); 611 ida_init(&root->ino_ida);
611 612
612 sd = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR); 613 kn = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR);
613 if (!sd) { 614 if (!kn) {
614 ida_destroy(&root->ino_ida); 615 ida_destroy(&root->ino_ida);
615 kfree(root); 616 kfree(root);
616 return ERR_PTR(-ENOMEM); 617 return ERR_PTR(-ENOMEM);
617 } 618 }
618 619
619 sd->s_flags &= ~SYSFS_FLAG_REMOVED; 620 kn->s_flags &= ~SYSFS_FLAG_REMOVED;
620 sd->priv = priv; 621 kn->priv = priv;
621 sd->s_dir.root = root; 622 kn->s_dir.root = root;
622 623
623 root->sd = sd; 624 root->kn = kn;
624 625
625 return root; 626 return root;
626} 627}
@@ -634,7 +635,7 @@ struct kernfs_root *kernfs_create_root(void *priv)
634 */ 635 */
635void kernfs_destroy_root(struct kernfs_root *root) 636void kernfs_destroy_root(struct kernfs_root *root)
636{ 637{
637 kernfs_remove(root->sd); /* will also free @root */ 638 kernfs_remove(root->kn); /* will also free @root */
638} 639}
639 640
640/** 641/**
@@ -646,33 +647,33 @@ void kernfs_destroy_root(struct kernfs_root *root)
646 * 647 *
647 * Returns the created node on success, ERR_PTR() value on failure. 648 * Returns the created node on success, ERR_PTR() value on failure.
648 */ 649 */
649struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, 650struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
650 const char *name, void *priv, 651 const char *name, void *priv,
651 const void *ns) 652 const void *ns)
652{ 653{
653 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; 654 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
654 struct sysfs_addrm_cxt acxt; 655 struct sysfs_addrm_cxt acxt;
655 struct sysfs_dirent *sd; 656 struct kernfs_node *kn;
656 int rc; 657 int rc;
657 658
658 /* allocate */ 659 /* allocate */
659 sd = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR); 660 kn = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR);
660 if (!sd) 661 if (!kn)
661 return ERR_PTR(-ENOMEM); 662 return ERR_PTR(-ENOMEM);
662 663
663 sd->s_dir.root = parent->s_dir.root; 664 kn->s_dir.root = parent->s_dir.root;
664 sd->s_ns = ns; 665 kn->s_ns = ns;
665 sd->priv = priv; 666 kn->priv = priv;
666 667
667 /* link in */ 668 /* link in */
668 sysfs_addrm_start(&acxt); 669 sysfs_addrm_start(&acxt);
669 rc = sysfs_add_one(&acxt, sd, parent); 670 rc = sysfs_add_one(&acxt, kn, parent);
670 sysfs_addrm_finish(&acxt); 671 sysfs_addrm_finish(&acxt);
671 672
672 if (!rc) 673 if (!rc)
673 return sd; 674 return kn;
674 675
675 kernfs_put(sd); 676 kernfs_put(kn);
676 return ERR_PTR(rc); 677 return ERR_PTR(rc);
677} 678}
678 679
@@ -680,29 +681,28 @@ static struct dentry *sysfs_lookup(struct inode *dir, struct dentry *dentry,
680 unsigned int flags) 681 unsigned int flags)
681{ 682{
682 struct dentry *ret = NULL; 683 struct dentry *ret = NULL;
683 struct dentry *parent = dentry->d_parent; 684 struct kernfs_node *parent = dentry->d_parent->d_fsdata;
684 struct sysfs_dirent *parent_sd = parent->d_fsdata; 685 struct kernfs_node *kn;
685 struct sysfs_dirent *sd;
686 struct inode *inode; 686 struct inode *inode;
687 const void *ns = NULL; 687 const void *ns = NULL;
688 688
689 mutex_lock(&sysfs_mutex); 689 mutex_lock(&sysfs_mutex);
690 690
691 if (kernfs_ns_enabled(parent_sd)) 691 if (kernfs_ns_enabled(parent))
692 ns = sysfs_info(dir->i_sb)->ns; 692 ns = sysfs_info(dir->i_sb)->ns;
693 693
694 sd = kernfs_find_ns(parent_sd, dentry->d_name.name, ns); 694 kn = kernfs_find_ns(parent, dentry->d_name.name, ns);
695 695
696 /* no such entry */ 696 /* no such entry */
697 if (!sd) { 697 if (!kn) {
698 ret = ERR_PTR(-ENOENT); 698 ret = ERR_PTR(-ENOENT);
699 goto out_unlock; 699 goto out_unlock;
700 } 700 }
701 kernfs_get(sd); 701 kernfs_get(kn);
702 dentry->d_fsdata = sd; 702 dentry->d_fsdata = kn;
703 703
704 /* attach dentry and inode */ 704 /* attach dentry and inode */
705 inode = sysfs_get_inode(dir->i_sb, sd); 705 inode = sysfs_get_inode(dir->i_sb, kn);
706 if (!inode) { 706 if (!inode) {
707 ret = ERR_PTR(-ENOMEM); 707 ret = ERR_PTR(-ENOMEM);
708 goto out_unlock; 708 goto out_unlock;
@@ -726,9 +726,9 @@ const struct inode_operations sysfs_dir_inode_operations = {
726 .listxattr = sysfs_listxattr, 726 .listxattr = sysfs_listxattr,
727}; 727};
728 728
729static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) 729static struct kernfs_node *sysfs_leftmost_descendant(struct kernfs_node *pos)
730{ 730{
731 struct sysfs_dirent *last; 731 struct kernfs_node *last;
732 732
733 while (true) { 733 while (true) {
734 struct rb_node *rbn; 734 struct rb_node *rbn;
@@ -742,7 +742,7 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
742 if (!rbn) 742 if (!rbn)
743 break; 743 break;
744 744
745 pos = to_sysfs_dirent(rbn); 745 pos = rb_to_kn(rbn);
746 } 746 }
747 747
748 return last; 748 return last;
@@ -751,14 +751,14 @@ static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos)
751/** 751/**
752 * sysfs_next_descendant_post - find the next descendant for post-order walk 752 * sysfs_next_descendant_post - find the next descendant for post-order walk
753 * @pos: the current position (%NULL to initiate traversal) 753 * @pos: the current position (%NULL to initiate traversal)
754 * @root: sysfs_dirent whose descendants to walk 754 * @root: kernfs_node whose descendants to walk
755 * 755 *
756 * Find the next descendant to visit for post-order traversal of @root's 756 * Find the next descendant to visit for post-order traversal of @root's
757 * descendants. @root is included in the iteration and the last node to be 757 * descendants. @root is included in the iteration and the last node to be
758 * visited. 758 * visited.
759 */ 759 */
760static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos, 760static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos,
761 struct sysfs_dirent *root) 761 struct kernfs_node *root)
762{ 762{
763 struct rb_node *rbn; 763 struct rb_node *rbn;
764 764
@@ -775,62 +775,62 @@ static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos,
775 /* if there's an unvisited sibling, visit its leftmost descendant */ 775 /* if there's an unvisited sibling, visit its leftmost descendant */
776 rbn = rb_next(&pos->s_rb); 776 rbn = rb_next(&pos->s_rb);
777 if (rbn) 777 if (rbn)
778 return sysfs_leftmost_descendant(to_sysfs_dirent(rbn)); 778 return sysfs_leftmost_descendant(rb_to_kn(rbn));
779 779
780 /* no sibling left, visit parent */ 780 /* no sibling left, visit parent */
781 return pos->s_parent; 781 return pos->s_parent;
782} 782}
783 783
784static void __kernfs_remove(struct sysfs_addrm_cxt *acxt, 784static void __kernfs_remove(struct sysfs_addrm_cxt *acxt,
785 struct sysfs_dirent *sd) 785 struct kernfs_node *kn)
786{ 786{
787 struct sysfs_dirent *pos, *next; 787 struct kernfs_node *pos, *next;
788 788
789 if (!sd) 789 if (!kn)
790 return; 790 return;
791 791
792 pr_debug("sysfs %s: removing\n", sd->s_name); 792 pr_debug("sysfs %s: removing\n", kn->s_name);
793 793
794 next = NULL; 794 next = NULL;
795 do { 795 do {
796 pos = next; 796 pos = next;
797 next = sysfs_next_descendant_post(pos, sd); 797 next = sysfs_next_descendant_post(pos, kn);
798 if (pos) 798 if (pos)
799 sysfs_remove_one(acxt, pos); 799 sysfs_remove_one(acxt, pos);
800 } while (next); 800 } while (next);
801} 801}
802 802
803/** 803/**
804 * kernfs_remove - remove a sysfs_dirent recursively 804 * kernfs_remove - remove a kernfs_node recursively
805 * @sd: the sysfs_dirent to remove 805 * @kn: the kernfs_node to remove
806 * 806 *
807 * Remove @sd along with all its subdirectories and files. 807 * Remove @kn along with all its subdirectories and files.
808 */ 808 */
809void kernfs_remove(struct sysfs_dirent *sd) 809void kernfs_remove(struct kernfs_node *kn)
810{ 810{
811 struct sysfs_addrm_cxt acxt; 811 struct sysfs_addrm_cxt acxt;
812 812
813 sysfs_addrm_start(&acxt); 813 sysfs_addrm_start(&acxt);
814 __kernfs_remove(&acxt, sd); 814 __kernfs_remove(&acxt, kn);
815 sysfs_addrm_finish(&acxt); 815 sysfs_addrm_finish(&acxt);
816} 816}
817 817
818/** 818/**
819 * kernfs_remove_by_name_ns - find a sysfs_dirent by name and remove it 819 * kernfs_remove_by_name_ns - find a kernfs_node by name and remove it
820 * @dir_sd: parent of the target 820 * @parent: parent of the target
821 * @name: name of the sysfs_dirent to remove 821 * @name: name of the kernfs_node to remove
822 * @ns: namespace tag of the sysfs_dirent to remove 822 * @ns: namespace tag of the kernfs_node to remove
823 * 823 *
824 * Look for the sysfs_dirent with @name and @ns under @dir_sd and remove 824 * Look for the kernfs_node with @name and @ns under @parent and remove it.
825 * it. Returns 0 on success, -ENOENT if such entry doesn't exist. 825 * Returns 0 on success, -ENOENT if such entry doesn't exist.
826 */ 826 */
827int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name, 827int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
828 const void *ns) 828 const void *ns)
829{ 829{
830 struct sysfs_addrm_cxt acxt; 830 struct sysfs_addrm_cxt acxt;
831 struct sysfs_dirent *sd; 831 struct kernfs_node *kn;
832 832
833 if (!dir_sd) { 833 if (!parent) {
834 WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n", 834 WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n",
835 name); 835 name);
836 return -ENOENT; 836 return -ENOENT;
@@ -838,13 +838,13 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
838 838
839 sysfs_addrm_start(&acxt); 839 sysfs_addrm_start(&acxt);
840 840
841 sd = kernfs_find_ns(dir_sd, name, ns); 841 kn = kernfs_find_ns(parent, name, ns);
842 if (sd) 842 if (kn)
843 __kernfs_remove(&acxt, sd); 843 __kernfs_remove(&acxt, kn);
844 844
845 sysfs_addrm_finish(&acxt); 845 sysfs_addrm_finish(&acxt);
846 846
847 if (sd) 847 if (kn)
848 return 0; 848 return 0;
849 else 849 else
850 return -ENOENT; 850 return -ENOENT;
@@ -852,12 +852,12 @@ int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name,
852 852
853/** 853/**
854 * kernfs_rename_ns - move and rename a kernfs_node 854 * kernfs_rename_ns - move and rename a kernfs_node
855 * @sd: target node 855 * @kn: target node
856 * @new_parent: new parent to put @sd under 856 * @new_parent: new parent to put @sd under
857 * @new_name: new name 857 * @new_name: new name
858 * @new_ns: new namespace tag 858 * @new_ns: new namespace tag
859 */ 859 */
860int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, 860int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
861 const char *new_name, const void *new_ns) 861 const char *new_name, const void *new_ns)
862{ 862{
863 int error; 863 int error;
@@ -865,35 +865,35 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
865 mutex_lock(&sysfs_mutex); 865 mutex_lock(&sysfs_mutex);
866 866
867 error = 0; 867 error = 0;
868 if ((sd->s_parent == new_parent) && (sd->s_ns == new_ns) && 868 if ((kn->s_parent == new_parent) && (kn->s_ns == new_ns) &&
869 (strcmp(sd->s_name, new_name) == 0)) 869 (strcmp(kn->s_name, new_name) == 0))
870 goto out; /* nothing to rename */ 870 goto out; /* nothing to rename */
871 871
872 error = -EEXIST; 872 error = -EEXIST;
873 if (kernfs_find_ns(new_parent, new_name, new_ns)) 873 if (kernfs_find_ns(new_parent, new_name, new_ns))
874 goto out; 874 goto out;
875 875
876 /* rename sysfs_dirent */ 876 /* rename kernfs_node */
877 if (strcmp(sd->s_name, new_name) != 0) { 877 if (strcmp(kn->s_name, new_name) != 0) {
878 error = -ENOMEM; 878 error = -ENOMEM;
879 new_name = kstrdup(new_name, GFP_KERNEL); 879 new_name = kstrdup(new_name, GFP_KERNEL);
880 if (!new_name) 880 if (!new_name)
881 goto out; 881 goto out;
882 882
883 kfree(sd->s_name); 883 kfree(kn->s_name);
884 sd->s_name = new_name; 884 kn->s_name = new_name;
885 } 885 }
886 886
887 /* 887 /*
888 * Move to the appropriate place in the appropriate directories rbtree. 888 * Move to the appropriate place in the appropriate directories rbtree.
889 */ 889 */
890 sysfs_unlink_sibling(sd); 890 sysfs_unlink_sibling(kn);
891 kernfs_get(new_parent); 891 kernfs_get(new_parent);
892 kernfs_put(sd->s_parent); 892 kernfs_put(kn->s_parent);
893 sd->s_ns = new_ns; 893 kn->s_ns = new_ns;
894 sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); 894 kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns);
895 sd->s_parent = new_parent; 895 kn->s_parent = new_parent;
896 sysfs_link_sibling(sd); 896 sysfs_link_sibling(kn);
897 897
898 error = 0; 898 error = 0;
899 out: 899 out:
@@ -902,9 +902,9 @@ int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent,
902} 902}
903 903
904/* Relationship between s_mode and the DT_xxx types */ 904/* Relationship between s_mode and the DT_xxx types */
905static inline unsigned char dt_type(struct sysfs_dirent *sd) 905static inline unsigned char dt_type(struct kernfs_node *kn)
906{ 906{
907 return (sd->s_mode >> 12) & 15; 907 return (kn->s_mode >> 12) & 15;
908} 908}
909 909
910static int sysfs_dir_release(struct inode *inode, struct file *filp) 910static int sysfs_dir_release(struct inode *inode, struct file *filp)
@@ -913,21 +913,21 @@ static int sysfs_dir_release(struct inode *inode, struct file *filp)
913 return 0; 913 return 0;
914} 914}
915 915
916static struct sysfs_dirent *sysfs_dir_pos(const void *ns, 916static struct kernfs_node *sysfs_dir_pos(const void *ns,
917 struct sysfs_dirent *parent_sd, loff_t hash, struct sysfs_dirent *pos) 917 struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos)
918{ 918{
919 if (pos) { 919 if (pos) {
920 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) && 920 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
921 pos->s_parent == parent_sd && 921 pos->s_parent == parent &&
922 hash == pos->s_hash; 922 hash == pos->s_hash;
923 kernfs_put(pos); 923 kernfs_put(pos);
924 if (!valid) 924 if (!valid)
925 pos = NULL; 925 pos = NULL;
926 } 926 }
927 if (!pos && (hash > 1) && (hash < INT_MAX)) { 927 if (!pos && (hash > 1) && (hash < INT_MAX)) {
928 struct rb_node *node = parent_sd->s_dir.children.rb_node; 928 struct rb_node *node = parent->s_dir.children.rb_node;
929 while (node) { 929 while (node) {
930 pos = to_sysfs_dirent(node); 930 pos = rb_to_kn(node);
931 931
932 if (hash < pos->s_hash) 932 if (hash < pos->s_hash)
933 node = node->rb_left; 933 node = node->rb_left;
@@ -943,22 +943,22 @@ static struct sysfs_dirent *sysfs_dir_pos(const void *ns,
943 if (!node) 943 if (!node)
944 pos = NULL; 944 pos = NULL;
945 else 945 else
946 pos = to_sysfs_dirent(node); 946 pos = rb_to_kn(node);
947 } 947 }
948 return pos; 948 return pos;
949} 949}
950 950
951static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns, 951static struct kernfs_node *sysfs_dir_next_pos(const void *ns,
952 struct sysfs_dirent *parent_sd, ino_t ino, struct sysfs_dirent *pos) 952 struct kernfs_node *parent, ino_t ino, struct kernfs_node *pos)
953{ 953{
954 pos = sysfs_dir_pos(ns, parent_sd, ino, pos); 954 pos = sysfs_dir_pos(ns, parent, ino, pos);
955 if (pos) 955 if (pos)
956 do { 956 do {
957 struct rb_node *node = rb_next(&pos->s_rb); 957 struct rb_node *node = rb_next(&pos->s_rb);
958 if (!node) 958 if (!node)
959 pos = NULL; 959 pos = NULL;
960 else 960 else
961 pos = to_sysfs_dirent(node); 961 pos = rb_to_kn(node);
962 } while (pos && pos->s_ns != ns); 962 } while (pos && pos->s_ns != ns);
963 return pos; 963 return pos;
964} 964}
@@ -966,20 +966,20 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns,
966static int sysfs_readdir(struct file *file, struct dir_context *ctx) 966static int sysfs_readdir(struct file *file, struct dir_context *ctx)
967{ 967{
968 struct dentry *dentry = file->f_path.dentry; 968 struct dentry *dentry = file->f_path.dentry;
969 struct sysfs_dirent *parent_sd = dentry->d_fsdata; 969 struct kernfs_node *parent = dentry->d_fsdata;
970 struct sysfs_dirent *pos = file->private_data; 970 struct kernfs_node *pos = file->private_data;
971 const void *ns = NULL; 971 const void *ns = NULL;
972 972
973 if (!dir_emit_dots(file, ctx)) 973 if (!dir_emit_dots(file, ctx))
974 return 0; 974 return 0;
975 mutex_lock(&sysfs_mutex); 975 mutex_lock(&sysfs_mutex);
976 976
977 if (kernfs_ns_enabled(parent_sd)) 977 if (kernfs_ns_enabled(parent))
978 ns = sysfs_info(dentry->d_sb)->ns; 978 ns = sysfs_info(dentry->d_sb)->ns;
979 979
980 for (pos = sysfs_dir_pos(ns, parent_sd, ctx->pos, pos); 980 for (pos = sysfs_dir_pos(ns, parent, ctx->pos, pos);
981 pos; 981 pos;
982 pos = sysfs_dir_next_pos(ns, parent_sd, ctx->pos, pos)) { 982 pos = sysfs_dir_next_pos(ns, parent, ctx->pos, pos)) {
983 const char *name = pos->s_name; 983 const char *name = pos->s_name;
984 unsigned int type = dt_type(pos); 984 unsigned int type = dt_type(pos);
985 int len = strlen(name); 985 int len = strlen(name);