aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/gpio/gpiolib.c4
-rw-r--r--drivers/md/bitmap.c2
-rw-r--r--drivers/md/bitmap.h2
-rw-r--r--drivers/md/md.h10
-rw-r--r--drivers/misc/mic/host/mic_device.h2
-rw-r--r--fs/kernfs/dir.c542
-rw-r--r--fs/kernfs/file.c186
-rw-r--r--fs/kernfs/inode.c123
-rw-r--r--fs/kernfs/kernfs-internal.h40
-rw-r--r--fs/kernfs/mount.c12
-rw-r--r--fs/kernfs/symlink.c64
-rw-r--r--fs/sysfs/dir.c66
-rw-r--r--fs/sysfs/file.c122
-rw-r--r--fs/sysfs/group.c96
-rw-r--r--fs/sysfs/mount.c4
-rw-r--r--fs/sysfs/symlink.c72
-rw-r--r--fs/sysfs/sysfs.h10
-rw-r--r--include/linux/kernfs.h166
-rw-r--r--include/linux/kobject.h2
-rw-r--r--include/linux/sysfs.h20
-rw-r--r--lib/kobject.c2
21 files changed, 774 insertions, 773 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 85f772c0b26a..c8a7c810bade 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -393,7 +393,7 @@ static const DEVICE_ATTR(value, 0644,
393 393
394static irqreturn_t gpio_sysfs_irq(int irq, void *priv) 394static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
395{ 395{
396 struct sysfs_dirent *value_sd = priv; 396 struct kernfs_node *value_sd = priv;
397 397
398 sysfs_notify_dirent(value_sd); 398 sysfs_notify_dirent(value_sd);
399 return IRQ_HANDLED; 399 return IRQ_HANDLED;
@@ -402,7 +402,7 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
402static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, 402static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
403 unsigned long gpio_flags) 403 unsigned long gpio_flags)
404{ 404{
405 struct sysfs_dirent *value_sd; 405 struct kernfs_node *value_sd;
406 unsigned long irq_flags; 406 unsigned long irq_flags;
407 int ret, irq, id; 407 int ret, irq, id;
408 408
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 12dc29ba7399..4195a01b1535 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1635,7 +1635,7 @@ int bitmap_create(struct mddev *mddev)
1635 sector_t blocks = mddev->resync_max_sectors; 1635 sector_t blocks = mddev->resync_max_sectors;
1636 struct file *file = mddev->bitmap_info.file; 1636 struct file *file = mddev->bitmap_info.file;
1637 int err; 1637 int err;
1638 struct sysfs_dirent *bm = NULL; 1638 struct kernfs_node *bm = NULL;
1639 1639
1640 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); 1640 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
1641 1641
diff --git a/drivers/md/bitmap.h b/drivers/md/bitmap.h
index df4aeb6ac6f0..30210b9c4ef9 100644
--- a/drivers/md/bitmap.h
+++ b/drivers/md/bitmap.h
@@ -225,7 +225,7 @@ struct bitmap {
225 wait_queue_head_t overflow_wait; 225 wait_queue_head_t overflow_wait;
226 wait_queue_head_t behind_wait; 226 wait_queue_head_t behind_wait;
227 227
228 struct sysfs_dirent *sysfs_can_clear; 228 struct kernfs_node *sysfs_can_clear;
229}; 229};
230 230
231/* the bitmap API */ 231/* the bitmap API */
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 2f5cc8a7ef3e..389a3c93cdb7 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -106,7 +106,7 @@ struct md_rdev {
106 */ 106 */
107 struct work_struct del_work; /* used for delayed sysfs removal */ 107 struct work_struct del_work; /* used for delayed sysfs removal */
108 108
109 struct sysfs_dirent *sysfs_state; /* handle for 'state' 109 struct kernfs_node *sysfs_state; /* handle for 'state'
110 * sysfs entry */ 110 * sysfs entry */
111 111
112 struct badblocks { 112 struct badblocks {
@@ -376,10 +376,10 @@ struct mddev {
376 sector_t resync_max; /* resync should pause 376 sector_t resync_max; /* resync should pause
377 * when it gets here */ 377 * when it gets here */
378 378
379 struct sysfs_dirent *sysfs_state; /* handle for 'array_state' 379 struct kernfs_node *sysfs_state; /* handle for 'array_state'
380 * file in sysfs. 380 * file in sysfs.
381 */ 381 */
382 struct sysfs_dirent *sysfs_action; /* handle for 'sync_action' */ 382 struct kernfs_node *sysfs_action; /* handle for 'sync_action' */
383 383
384 struct work_struct del_work; /* used for delayed sysfs removal */ 384 struct work_struct del_work; /* used for delayed sysfs removal */
385 385
@@ -498,13 +498,13 @@ struct md_sysfs_entry {
498}; 498};
499extern struct attribute_group md_bitmap_group; 499extern struct attribute_group md_bitmap_group;
500 500
501static inline struct sysfs_dirent *sysfs_get_dirent_safe(struct sysfs_dirent *sd, char *name) 501static inline struct kernfs_node *sysfs_get_dirent_safe(struct kernfs_node *sd, char *name)
502{ 502{
503 if (sd) 503 if (sd)
504 return sysfs_get_dirent(sd, name); 504 return sysfs_get_dirent(sd, name);
505 return sd; 505 return sd;
506} 506}
507static inline void sysfs_notify_dirent_safe(struct sysfs_dirent *sd) 507static inline void sysfs_notify_dirent_safe(struct kernfs_node *sd)
508{ 508{
509 if (sd) 509 if (sd)
510 sysfs_notify_dirent(sd); 510 sysfs_notify_dirent(sd);
diff --git a/drivers/misc/mic/host/mic_device.h b/drivers/misc/mic/host/mic_device.h
index 3574cc375bb9..538e3d3d3c8c 100644
--- a/drivers/misc/mic/host/mic_device.h
+++ b/drivers/misc/mic/host/mic_device.h
@@ -112,7 +112,7 @@ struct mic_device {
112 struct work_struct shutdown_work; 112 struct work_struct shutdown_work;
113 u8 state; 113 u8 state;
114 u8 shutdown_status; 114 u8 shutdown_status;
115 struct sysfs_dirent *state_sysfs; 115 struct kernfs_node *state_sysfs;
116 struct completion reset_wait; 116 struct completion reset_wait;
117 void *log_buf_addr; 117 void *log_buf_addr;
118 int *log_buf_len; 118 int *log_buf_len;
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);
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index fa053151fa96..1bf07ded826a 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -19,9 +19,9 @@
19 19
20/* 20/*
21 * There's one sysfs_open_file for each open file and one sysfs_open_dirent 21 * There's one sysfs_open_file for each open file and one sysfs_open_dirent
22 * for each sysfs_dirent with one or more open files. 22 * for each kernfs_node with one or more open files.
23 * 23 *
24 * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open is 24 * kernfs_node->s_attr.open points to sysfs_open_dirent. s_attr.open is
25 * protected by sysfs_open_dirent_lock. 25 * protected by sysfs_open_dirent_lock.
26 * 26 *
27 * filp->private_data points to seq_file whose ->private points to 27 * filp->private_data points to seq_file whose ->private points to
@@ -44,14 +44,14 @@ static struct sysfs_open_file *sysfs_of(struct file *file)
44} 44}
45 45
46/* 46/*
47 * Determine the kernfs_ops for the given sysfs_dirent. This function must 47 * Determine the kernfs_ops for the given kernfs_node. This function must
48 * be called while holding an active reference. 48 * be called while holding an active reference.
49 */ 49 */
50static const struct kernfs_ops *kernfs_ops(struct sysfs_dirent *sd) 50static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn)
51{ 51{
52 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 52 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
53 lockdep_assert_held(sd); 53 lockdep_assert_held(kn);
54 return sd->s_attr.ops; 54 return kn->s_attr.ops;
55} 55}
56 56
57static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos) 57static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
@@ -64,10 +64,10 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
64 * the ops aren't called concurrently for the same open file. 64 * the ops aren't called concurrently for the same open file.
65 */ 65 */
66 mutex_lock(&of->mutex); 66 mutex_lock(&of->mutex);
67 if (!sysfs_get_active(of->sd)) 67 if (!sysfs_get_active(of->kn))
68 return ERR_PTR(-ENODEV); 68 return ERR_PTR(-ENODEV);
69 69
70 ops = kernfs_ops(of->sd); 70 ops = kernfs_ops(of->kn);
71 if (ops->seq_start) { 71 if (ops->seq_start) {
72 return ops->seq_start(sf, ppos); 72 return ops->seq_start(sf, ppos);
73 } else { 73 } else {
@@ -82,7 +82,7 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
82static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos) 82static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
83{ 83{
84 struct sysfs_open_file *of = sf->private; 84 struct sysfs_open_file *of = sf->private;
85 const struct kernfs_ops *ops = kernfs_ops(of->sd); 85 const struct kernfs_ops *ops = kernfs_ops(of->kn);
86 86
87 if (ops->seq_next) { 87 if (ops->seq_next) {
88 return ops->seq_next(sf, v, ppos); 88 return ops->seq_next(sf, v, ppos);
@@ -99,12 +99,12 @@ static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
99static void kernfs_seq_stop(struct seq_file *sf, void *v) 99static void kernfs_seq_stop(struct seq_file *sf, void *v)
100{ 100{
101 struct sysfs_open_file *of = sf->private; 101 struct sysfs_open_file *of = sf->private;
102 const struct kernfs_ops *ops = kernfs_ops(of->sd); 102 const struct kernfs_ops *ops = kernfs_ops(of->kn);
103 103
104 if (ops->seq_stop) 104 if (ops->seq_stop)
105 ops->seq_stop(sf, v); 105 ops->seq_stop(sf, v);
106 106
107 sysfs_put_active(of->sd); 107 sysfs_put_active(of->kn);
108 mutex_unlock(&of->mutex); 108 mutex_unlock(&of->mutex);
109} 109}
110 110
@@ -112,9 +112,9 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
112{ 112{
113 struct sysfs_open_file *of = sf->private; 113 struct sysfs_open_file *of = sf->private;
114 114
115 of->event = atomic_read(&of->sd->s_attr.open->event); 115 of->event = atomic_read(&of->kn->s_attr.open->event);
116 116
117 return of->sd->s_attr.ops->seq_show(sf, v); 117 return of->kn->s_attr.ops->seq_show(sf, v);
118} 118}
119 119
120static const struct seq_operations kernfs_seq_ops = { 120static const struct seq_operations kernfs_seq_ops = {
@@ -147,19 +147,19 @@ static ssize_t kernfs_file_direct_read(struct sysfs_open_file *of,
147 * the ops aren't called concurrently for the same open file. 147 * the ops aren't called concurrently for the same open file.
148 */ 148 */
149 mutex_lock(&of->mutex); 149 mutex_lock(&of->mutex);
150 if (!sysfs_get_active(of->sd)) { 150 if (!sysfs_get_active(of->kn)) {
151 len = -ENODEV; 151 len = -ENODEV;
152 mutex_unlock(&of->mutex); 152 mutex_unlock(&of->mutex);
153 goto out_free; 153 goto out_free;
154 } 154 }
155 155
156 ops = kernfs_ops(of->sd); 156 ops = kernfs_ops(of->kn);
157 if (ops->read) 157 if (ops->read)
158 len = ops->read(of, buf, len, *ppos); 158 len = ops->read(of, buf, len, *ppos);
159 else 159 else
160 len = -EINVAL; 160 len = -EINVAL;
161 161
162 sysfs_put_active(of->sd); 162 sysfs_put_active(of->kn);
163 mutex_unlock(&of->mutex); 163 mutex_unlock(&of->mutex);
164 164
165 if (len < 0) 165 if (len < 0)
@@ -189,7 +189,7 @@ static ssize_t kernfs_file_read(struct file *file, char __user *user_buf,
189{ 189{
190 struct sysfs_open_file *of = sysfs_of(file); 190 struct sysfs_open_file *of = sysfs_of(file);
191 191
192 if (of->sd->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW) 192 if (of->kn->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW)
193 return seq_read(file, user_buf, count, ppos); 193 return seq_read(file, user_buf, count, ppos);
194 else 194 else
195 return kernfs_file_direct_read(of, user_buf, count, ppos); 195 return kernfs_file_direct_read(of, user_buf, count, ppos);
@@ -234,19 +234,19 @@ static ssize_t kernfs_file_write(struct file *file, const char __user *user_buf,
234 * the ops aren't called concurrently for the same open file. 234 * the ops aren't called concurrently for the same open file.
235 */ 235 */
236 mutex_lock(&of->mutex); 236 mutex_lock(&of->mutex);
237 if (!sysfs_get_active(of->sd)) { 237 if (!sysfs_get_active(of->kn)) {
238 mutex_unlock(&of->mutex); 238 mutex_unlock(&of->mutex);
239 len = -ENODEV; 239 len = -ENODEV;
240 goto out_free; 240 goto out_free;
241 } 241 }
242 242
243 ops = kernfs_ops(of->sd); 243 ops = kernfs_ops(of->kn);
244 if (ops->write) 244 if (ops->write)
245 len = ops->write(of, buf, len, *ppos); 245 len = ops->write(of, buf, len, *ppos);
246 else 246 else
247 len = -EINVAL; 247 len = -EINVAL;
248 248
249 sysfs_put_active(of->sd); 249 sysfs_put_active(of->kn);
250 mutex_unlock(&of->mutex); 250 mutex_unlock(&of->mutex);
251 251
252 if (len > 0) 252 if (len > 0)
@@ -264,13 +264,13 @@ static void kernfs_vma_open(struct vm_area_struct *vma)
264 if (!of->vm_ops) 264 if (!of->vm_ops)
265 return; 265 return;
266 266
267 if (!sysfs_get_active(of->sd)) 267 if (!sysfs_get_active(of->kn))
268 return; 268 return;
269 269
270 if (of->vm_ops->open) 270 if (of->vm_ops->open)
271 of->vm_ops->open(vma); 271 of->vm_ops->open(vma);
272 272
273 sysfs_put_active(of->sd); 273 sysfs_put_active(of->kn);
274} 274}
275 275
276static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) 276static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
@@ -282,14 +282,14 @@ static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
282 if (!of->vm_ops) 282 if (!of->vm_ops)
283 return VM_FAULT_SIGBUS; 283 return VM_FAULT_SIGBUS;
284 284
285 if (!sysfs_get_active(of->sd)) 285 if (!sysfs_get_active(of->kn))
286 return VM_FAULT_SIGBUS; 286 return VM_FAULT_SIGBUS;
287 287
288 ret = VM_FAULT_SIGBUS; 288 ret = VM_FAULT_SIGBUS;
289 if (of->vm_ops->fault) 289 if (of->vm_ops->fault)
290 ret = of->vm_ops->fault(vma, vmf); 290 ret = of->vm_ops->fault(vma, vmf);
291 291
292 sysfs_put_active(of->sd); 292 sysfs_put_active(of->kn);
293 return ret; 293 return ret;
294} 294}
295 295
@@ -303,7 +303,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
303 if (!of->vm_ops) 303 if (!of->vm_ops)
304 return VM_FAULT_SIGBUS; 304 return VM_FAULT_SIGBUS;
305 305
306 if (!sysfs_get_active(of->sd)) 306 if (!sysfs_get_active(of->kn))
307 return VM_FAULT_SIGBUS; 307 return VM_FAULT_SIGBUS;
308 308
309 ret = 0; 309 ret = 0;
@@ -312,7 +312,7 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
312 else 312 else
313 file_update_time(file); 313 file_update_time(file);
314 314
315 sysfs_put_active(of->sd); 315 sysfs_put_active(of->kn);
316 return ret; 316 return ret;
317} 317}
318 318
@@ -326,14 +326,14 @@ static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
326 if (!of->vm_ops) 326 if (!of->vm_ops)
327 return -EINVAL; 327 return -EINVAL;
328 328
329 if (!sysfs_get_active(of->sd)) 329 if (!sysfs_get_active(of->kn))
330 return -EINVAL; 330 return -EINVAL;
331 331
332 ret = -EINVAL; 332 ret = -EINVAL;
333 if (of->vm_ops->access) 333 if (of->vm_ops->access)
334 ret = of->vm_ops->access(vma, addr, buf, len, write); 334 ret = of->vm_ops->access(vma, addr, buf, len, write);
335 335
336 sysfs_put_active(of->sd); 336 sysfs_put_active(of->kn);
337 return ret; 337 return ret;
338} 338}
339 339
@@ -348,14 +348,14 @@ static int kernfs_vma_set_policy(struct vm_area_struct *vma,
348 if (!of->vm_ops) 348 if (!of->vm_ops)
349 return 0; 349 return 0;
350 350
351 if (!sysfs_get_active(of->sd)) 351 if (!sysfs_get_active(of->kn))
352 return -EINVAL; 352 return -EINVAL;
353 353
354 ret = 0; 354 ret = 0;
355 if (of->vm_ops->set_policy) 355 if (of->vm_ops->set_policy)
356 ret = of->vm_ops->set_policy(vma, new); 356 ret = of->vm_ops->set_policy(vma, new);
357 357
358 sysfs_put_active(of->sd); 358 sysfs_put_active(of->kn);
359 return ret; 359 return ret;
360} 360}
361 361
@@ -369,14 +369,14 @@ static struct mempolicy *kernfs_vma_get_policy(struct vm_area_struct *vma,
369 if (!of->vm_ops) 369 if (!of->vm_ops)
370 return vma->vm_policy; 370 return vma->vm_policy;
371 371
372 if (!sysfs_get_active(of->sd)) 372 if (!sysfs_get_active(of->kn))
373 return vma->vm_policy; 373 return vma->vm_policy;
374 374
375 pol = vma->vm_policy; 375 pol = vma->vm_policy;
376 if (of->vm_ops->get_policy) 376 if (of->vm_ops->get_policy)
377 pol = of->vm_ops->get_policy(vma, addr); 377 pol = of->vm_ops->get_policy(vma, addr);
378 378
379 sysfs_put_active(of->sd); 379 sysfs_put_active(of->kn);
380 return pol; 380 return pol;
381} 381}
382 382
@@ -391,14 +391,14 @@ static int kernfs_vma_migrate(struct vm_area_struct *vma,
391 if (!of->vm_ops) 391 if (!of->vm_ops)
392 return 0; 392 return 0;
393 393
394 if (!sysfs_get_active(of->sd)) 394 if (!sysfs_get_active(of->kn))
395 return 0; 395 return 0;
396 396
397 ret = 0; 397 ret = 0;
398 if (of->vm_ops->migrate) 398 if (of->vm_ops->migrate)
399 ret = of->vm_ops->migrate(vma, from, to, flags); 399 ret = of->vm_ops->migrate(vma, from, to, flags);
400 400
401 sysfs_put_active(of->sd); 401 sysfs_put_active(of->kn);
402 return ret; 402 return ret;
403} 403}
404#endif 404#endif
@@ -428,16 +428,16 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
428 * without grabbing @of->mutex by testing HAS_MMAP flag. See the 428 * without grabbing @of->mutex by testing HAS_MMAP flag. See the
429 * comment in kernfs_file_open() for more details. 429 * comment in kernfs_file_open() for more details.
430 */ 430 */
431 if (!(of->sd->s_flags & SYSFS_FLAG_HAS_MMAP)) 431 if (!(of->kn->s_flags & SYSFS_FLAG_HAS_MMAP))
432 return -ENODEV; 432 return -ENODEV;
433 433
434 mutex_lock(&of->mutex); 434 mutex_lock(&of->mutex);
435 435
436 rc = -ENODEV; 436 rc = -ENODEV;
437 if (!sysfs_get_active(of->sd)) 437 if (!sysfs_get_active(of->kn))
438 goto out_unlock; 438 goto out_unlock;
439 439
440 ops = kernfs_ops(of->sd); 440 ops = kernfs_ops(of->kn);
441 rc = ops->mmap(of, vma); 441 rc = ops->mmap(of, vma);
442 442
443 /* 443 /*
@@ -465,7 +465,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
465 of->vm_ops = vma->vm_ops; 465 of->vm_ops = vma->vm_ops;
466 vma->vm_ops = &kernfs_vm_ops; 466 vma->vm_ops = &kernfs_vm_ops;
467out_put: 467out_put:
468 sysfs_put_active(of->sd); 468 sysfs_put_active(of->kn);
469out_unlock: 469out_unlock:
470 mutex_unlock(&of->mutex); 470 mutex_unlock(&of->mutex);
471 471
@@ -474,10 +474,10 @@ out_unlock:
474 474
475/** 475/**
476 * sysfs_get_open_dirent - get or create sysfs_open_dirent 476 * sysfs_get_open_dirent - get or create sysfs_open_dirent
477 * @sd: target sysfs_dirent 477 * @kn: target kernfs_node
478 * @of: sysfs_open_file for this instance of open 478 * @of: sysfs_open_file for this instance of open
479 * 479 *
480 * If @sd->s_attr.open exists, increment its reference count; 480 * If @kn->s_attr.open exists, increment its reference count;
481 * otherwise, create one. @of is chained to the files list. 481 * otherwise, create one. @of is chained to the files list.
482 * 482 *
483 * LOCKING: 483 * LOCKING:
@@ -486,7 +486,7 @@ out_unlock:
486 * RETURNS: 486 * RETURNS:
487 * 0 on success, -errno on failure. 487 * 0 on success, -errno on failure.
488 */ 488 */
489static int sysfs_get_open_dirent(struct sysfs_dirent *sd, 489static int sysfs_get_open_dirent(struct kernfs_node *kn,
490 struct sysfs_open_file *of) 490 struct sysfs_open_file *of)
491{ 491{
492 struct sysfs_open_dirent *od, *new_od = NULL; 492 struct sysfs_open_dirent *od, *new_od = NULL;
@@ -495,12 +495,12 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
495 mutex_lock(&sysfs_open_file_mutex); 495 mutex_lock(&sysfs_open_file_mutex);
496 spin_lock_irq(&sysfs_open_dirent_lock); 496 spin_lock_irq(&sysfs_open_dirent_lock);
497 497
498 if (!sd->s_attr.open && new_od) { 498 if (!kn->s_attr.open && new_od) {
499 sd->s_attr.open = new_od; 499 kn->s_attr.open = new_od;
500 new_od = NULL; 500 new_od = NULL;
501 } 501 }
502 502
503 od = sd->s_attr.open; 503 od = kn->s_attr.open;
504 if (od) { 504 if (od) {
505 atomic_inc(&od->refcnt); 505 atomic_inc(&od->refcnt);
506 list_add_tail(&of->list, &od->files); 506 list_add_tail(&of->list, &od->files);
@@ -528,19 +528,19 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
528 528
529/** 529/**
530 * sysfs_put_open_dirent - put sysfs_open_dirent 530 * sysfs_put_open_dirent - put sysfs_open_dirent
531 * @sd: target sysfs_dirent 531 * @kn: target kernfs_nodet
532 * @of: associated sysfs_open_file 532 * @of: associated sysfs_open_file
533 * 533 *
534 * Put @sd->s_attr.open and unlink @of from the files list. If 534 * Put @kn->s_attr.open and unlink @of from the files list. If
535 * reference count reaches zero, disassociate and free it. 535 * reference count reaches zero, disassociate and free it.
536 * 536 *
537 * LOCKING: 537 * LOCKING:
538 * None. 538 * None.
539 */ 539 */
540static void sysfs_put_open_dirent(struct sysfs_dirent *sd, 540static void sysfs_put_open_dirent(struct kernfs_node *kn,
541 struct sysfs_open_file *of) 541 struct sysfs_open_file *of)
542{ 542{
543 struct sysfs_open_dirent *od = sd->s_attr.open; 543 struct sysfs_open_dirent *od = kn->s_attr.open;
544 unsigned long flags; 544 unsigned long flags;
545 545
546 mutex_lock(&sysfs_open_file_mutex); 546 mutex_lock(&sysfs_open_file_mutex);
@@ -550,7 +550,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
550 list_del(&of->list); 550 list_del(&of->list);
551 551
552 if (atomic_dec_and_test(&od->refcnt)) 552 if (atomic_dec_and_test(&od->refcnt))
553 sd->s_attr.open = NULL; 553 kn->s_attr.open = NULL;
554 else 554 else
555 od = NULL; 555 od = NULL;
556 556
@@ -562,16 +562,16 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd,
562 562
563static int kernfs_file_open(struct inode *inode, struct file *file) 563static int kernfs_file_open(struct inode *inode, struct file *file)
564{ 564{
565 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; 565 struct kernfs_node *kn = file->f_path.dentry->d_fsdata;
566 const struct kernfs_ops *ops; 566 const struct kernfs_ops *ops;
567 struct sysfs_open_file *of; 567 struct sysfs_open_file *of;
568 bool has_read, has_write, has_mmap; 568 bool has_read, has_write, has_mmap;
569 int error = -EACCES; 569 int error = -EACCES;
570 570
571 if (!sysfs_get_active(attr_sd)) 571 if (!sysfs_get_active(kn))
572 return -ENODEV; 572 return -ENODEV;
573 573
574 ops = kernfs_ops(attr_sd); 574 ops = kernfs_ops(kn);
575 575
576 has_read = ops->seq_show || ops->read || ops->mmap; 576 has_read = ops->seq_show || ops->read || ops->mmap;
577 has_write = ops->write || ops->mmap; 577 has_write = ops->write || ops->mmap;
@@ -612,7 +612,7 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
612 else 612 else
613 mutex_init(&of->mutex); 613 mutex_init(&of->mutex);
614 614
615 of->sd = attr_sd; 615 of->kn = kn;
616 of->file = file; 616 of->file = file;
617 617
618 /* 618 /*
@@ -634,12 +634,12 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
634 file->f_mode |= FMODE_PWRITE; 634 file->f_mode |= FMODE_PWRITE;
635 635
636 /* make sure we have open dirent struct */ 636 /* make sure we have open dirent struct */
637 error = sysfs_get_open_dirent(attr_sd, of); 637 error = sysfs_get_open_dirent(kn, of);
638 if (error) 638 if (error)
639 goto err_close; 639 goto err_close;
640 640
641 /* open succeeded, put active references */ 641 /* open succeeded, put active references */
642 sysfs_put_active(attr_sd); 642 sysfs_put_active(kn);
643 return 0; 643 return 0;
644 644
645err_close: 645err_close:
@@ -647,32 +647,32 @@ err_close:
647err_free: 647err_free:
648 kfree(of); 648 kfree(of);
649err_out: 649err_out:
650 sysfs_put_active(attr_sd); 650 sysfs_put_active(kn);
651 return error; 651 return error;
652} 652}
653 653
654static int kernfs_file_release(struct inode *inode, struct file *filp) 654static int kernfs_file_release(struct inode *inode, struct file *filp)
655{ 655{
656 struct sysfs_dirent *sd = filp->f_path.dentry->d_fsdata; 656 struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
657 struct sysfs_open_file *of = sysfs_of(filp); 657 struct sysfs_open_file *of = sysfs_of(filp);
658 658
659 sysfs_put_open_dirent(sd, of); 659 sysfs_put_open_dirent(kn, of);
660 seq_release(inode, filp); 660 seq_release(inode, filp);
661 kfree(of); 661 kfree(of);
662 662
663 return 0; 663 return 0;
664} 664}
665 665
666void sysfs_unmap_bin_file(struct sysfs_dirent *sd) 666void sysfs_unmap_bin_file(struct kernfs_node *kn)
667{ 667{
668 struct sysfs_open_dirent *od; 668 struct sysfs_open_dirent *od;
669 struct sysfs_open_file *of; 669 struct sysfs_open_file *of;
670 670
671 if (!(sd->s_flags & SYSFS_FLAG_HAS_MMAP)) 671 if (!(kn->s_flags & SYSFS_FLAG_HAS_MMAP))
672 return; 672 return;
673 673
674 spin_lock_irq(&sysfs_open_dirent_lock); 674 spin_lock_irq(&sysfs_open_dirent_lock);
675 od = sd->s_attr.open; 675 od = kn->s_attr.open;
676 if (od) 676 if (od)
677 atomic_inc(&od->refcnt); 677 atomic_inc(&od->refcnt);
678 spin_unlock_irq(&sysfs_open_dirent_lock); 678 spin_unlock_irq(&sysfs_open_dirent_lock);
@@ -686,7 +686,7 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd)
686 } 686 }
687 mutex_unlock(&sysfs_open_file_mutex); 687 mutex_unlock(&sysfs_open_file_mutex);
688 688
689 sysfs_put_open_dirent(sd, NULL); 689 sysfs_put_open_dirent(kn, NULL);
690} 690}
691 691
692/* Sysfs attribute files are pollable. The idea is that you read 692/* Sysfs attribute files are pollable. The idea is that you read
@@ -705,16 +705,16 @@ void sysfs_unmap_bin_file(struct sysfs_dirent *sd)
705static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait) 705static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
706{ 706{
707 struct sysfs_open_file *of = sysfs_of(filp); 707 struct sysfs_open_file *of = sysfs_of(filp);
708 struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; 708 struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
709 struct sysfs_open_dirent *od = attr_sd->s_attr.open; 709 struct sysfs_open_dirent *od = kn->s_attr.open;
710 710
711 /* need parent for the kobj, grab both */ 711 /* need parent for the kobj, grab both */
712 if (!sysfs_get_active(attr_sd)) 712 if (!sysfs_get_active(kn))
713 goto trigger; 713 goto trigger;
714 714
715 poll_wait(filp, &od->poll, wait); 715 poll_wait(filp, &od->poll, wait);
716 716
717 sysfs_put_active(attr_sd); 717 sysfs_put_active(kn);
718 718
719 if (of->event != atomic_read(&od->event)) 719 if (of->event != atomic_read(&od->event))
720 goto trigger; 720 goto trigger;
@@ -727,19 +727,19 @@ static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
727 727
728/** 728/**
729 * kernfs_notify - notify a kernfs file 729 * kernfs_notify - notify a kernfs file
730 * @sd: file to notify 730 * @kn: file to notify
731 * 731 *
732 * Notify @sd such that poll(2) on @sd wakes up. 732 * Notify @kn such that poll(2) on @kn wakes up.
733 */ 733 */
734void kernfs_notify(struct sysfs_dirent *sd) 734void kernfs_notify(struct kernfs_node *kn)
735{ 735{
736 struct sysfs_open_dirent *od; 736 struct sysfs_open_dirent *od;
737 unsigned long flags; 737 unsigned long flags;
738 738
739 spin_lock_irqsave(&sysfs_open_dirent_lock, flags); 739 spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
740 740
741 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) { 741 if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) {
742 od = sd->s_attr.open; 742 od = kn->s_attr.open;
743 if (od) { 743 if (od) {
744 atomic_inc(&od->event); 744 atomic_inc(&od->event);
745 wake_up_interruptible(&od->poll); 745 wake_up_interruptible(&od->poll);
@@ -773,51 +773,51 @@ const struct file_operations kernfs_file_operations = {
773 * 773 *
774 * Returns the created node on success, ERR_PTR() value on error. 774 * Returns the created node on success, ERR_PTR() value on error.
775 */ 775 */
776struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, 776struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
777 const char *name, 777 const char *name,
778 umode_t mode, loff_t size, 778 umode_t mode, loff_t size,
779 const struct kernfs_ops *ops, 779 const struct kernfs_ops *ops,
780 void *priv, const void *ns, 780 void *priv, const void *ns,
781 struct lock_class_key *key) 781 struct lock_class_key *key)
782{ 782{
783 struct sysfs_addrm_cxt acxt; 783 struct sysfs_addrm_cxt acxt;
784 struct sysfs_dirent *sd; 784 struct kernfs_node *kn;
785 int rc; 785 int rc;
786 786
787 sd = sysfs_new_dirent(kernfs_root(parent), name, 787 kn = sysfs_new_dirent(kernfs_root(parent), name,
788 (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR); 788 (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR);
789 if (!sd) 789 if (!kn)
790 return ERR_PTR(-ENOMEM); 790 return ERR_PTR(-ENOMEM);
791 791
792 sd->s_attr.ops = ops; 792 kn->s_attr.ops = ops;
793 sd->s_attr.size = size; 793 kn->s_attr.size = size;
794 sd->s_ns = ns; 794 kn->s_ns = ns;
795 sd->priv = priv; 795 kn->priv = priv;
796 796
797#ifdef CONFIG_DEBUG_LOCK_ALLOC 797#ifdef CONFIG_DEBUG_LOCK_ALLOC
798 if (key) { 798 if (key) {
799 lockdep_init_map(&sd->dep_map, "s_active", key, 0); 799 lockdep_init_map(&kn->dep_map, "s_active", key, 0);
800 sd->s_flags |= SYSFS_FLAG_LOCKDEP; 800 kn->s_flags |= SYSFS_FLAG_LOCKDEP;
801 } 801 }
802#endif 802#endif
803 803
804 /* 804 /*
805 * sd->s_attr.ops is accesible only while holding active ref. We 805 * kn->s_attr.ops is accesible only while holding active ref. We
806 * need to know whether some ops are implemented outside active 806 * need to know whether some ops are implemented outside active
807 * ref. Cache their existence in flags. 807 * ref. Cache their existence in flags.
808 */ 808 */
809 if (ops->seq_show) 809 if (ops->seq_show)
810 sd->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW; 810 kn->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW;
811 if (ops->mmap) 811 if (ops->mmap)
812 sd->s_flags |= SYSFS_FLAG_HAS_MMAP; 812 kn->s_flags |= SYSFS_FLAG_HAS_MMAP;
813 813
814 sysfs_addrm_start(&acxt); 814 sysfs_addrm_start(&acxt);
815 rc = sysfs_add_one(&acxt, sd, parent); 815 rc = sysfs_add_one(&acxt, kn, parent);
816 sysfs_addrm_finish(&acxt); 816 sysfs_addrm_finish(&acxt);
817 817
818 if (rc) { 818 if (rc) {
819 kernfs_put(sd); 819 kernfs_put(kn);
820 return ERR_PTR(rc); 820 return ERR_PTR(rc);
821 } 821 }
822 return sd; 822 return kn;
823} 823}
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index 18ad431e8c2a..9e74eed63539 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -46,36 +46,36 @@ void __init sysfs_inode_init(void)
46 panic("failed to init sysfs_backing_dev_info"); 46 panic("failed to init sysfs_backing_dev_info");
47} 47}
48 48
49static struct sysfs_inode_attrs *sysfs_inode_attrs(struct sysfs_dirent *sd) 49static struct sysfs_inode_attrs *sysfs_inode_attrs(struct kernfs_node *kn)
50{ 50{
51 struct iattr *iattrs; 51 struct iattr *iattrs;
52 52
53 if (sd->s_iattr) 53 if (kn->s_iattr)
54 return sd->s_iattr; 54 return kn->s_iattr;
55 55
56 sd->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL); 56 kn->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL);
57 if (!sd->s_iattr) 57 if (!kn->s_iattr)
58 return NULL; 58 return NULL;
59 iattrs = &sd->s_iattr->ia_iattr; 59 iattrs = &kn->s_iattr->ia_iattr;
60 60
61 /* assign default attributes */ 61 /* assign default attributes */
62 iattrs->ia_mode = sd->s_mode; 62 iattrs->ia_mode = kn->s_mode;
63 iattrs->ia_uid = GLOBAL_ROOT_UID; 63 iattrs->ia_uid = GLOBAL_ROOT_UID;
64 iattrs->ia_gid = GLOBAL_ROOT_GID; 64 iattrs->ia_gid = GLOBAL_ROOT_GID;
65 iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME; 65 iattrs->ia_atime = iattrs->ia_mtime = iattrs->ia_ctime = CURRENT_TIME;
66 66
67 simple_xattrs_init(&sd->s_iattr->xattrs); 67 simple_xattrs_init(&kn->s_iattr->xattrs);
68 68
69 return sd->s_iattr; 69 return kn->s_iattr;
70} 70}
71 71
72static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) 72static int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
73{ 73{
74 struct sysfs_inode_attrs *attrs; 74 struct sysfs_inode_attrs *attrs;
75 struct iattr *iattrs; 75 struct iattr *iattrs;
76 unsigned int ia_valid = iattr->ia_valid; 76 unsigned int ia_valid = iattr->ia_valid;
77 77
78 attrs = sysfs_inode_attrs(sd); 78 attrs = sysfs_inode_attrs(kn);
79 if (!attrs) 79 if (!attrs)
80 return -ENOMEM; 80 return -ENOMEM;
81 81
@@ -93,24 +93,24 @@ static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr)
93 iattrs->ia_ctime = iattr->ia_ctime; 93 iattrs->ia_ctime = iattr->ia_ctime;
94 if (ia_valid & ATTR_MODE) { 94 if (ia_valid & ATTR_MODE) {
95 umode_t mode = iattr->ia_mode; 95 umode_t mode = iattr->ia_mode;
96 iattrs->ia_mode = sd->s_mode = mode; 96 iattrs->ia_mode = kn->s_mode = mode;
97 } 97 }
98 return 0; 98 return 0;
99} 99}
100 100
101/** 101/**
102 * kernfs_setattr - set iattr on a node 102 * kernfs_setattr - set iattr on a node
103 * @sd: target node 103 * @kn: target node
104 * @iattr: iattr to set 104 * @iattr: iattr to set
105 * 105 *
106 * Returns 0 on success, -errno on failure. 106 * Returns 0 on success, -errno on failure.
107 */ 107 */
108int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) 108int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
109{ 109{
110 int ret; 110 int ret;
111 111
112 mutex_lock(&sysfs_mutex); 112 mutex_lock(&sysfs_mutex);
113 ret = __kernfs_setattr(sd, iattr); 113 ret = __kernfs_setattr(kn, iattr);
114 mutex_unlock(&sysfs_mutex); 114 mutex_unlock(&sysfs_mutex);
115 return ret; 115 return ret;
116} 116}
@@ -118,10 +118,10 @@ int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr)
118int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) 118int sysfs_setattr(struct dentry *dentry, struct iattr *iattr)
119{ 119{
120 struct inode *inode = dentry->d_inode; 120 struct inode *inode = dentry->d_inode;
121 struct sysfs_dirent *sd = dentry->d_fsdata; 121 struct kernfs_node *kn = dentry->d_fsdata;
122 int error; 122 int error;
123 123
124 if (!sd) 124 if (!kn)
125 return -EINVAL; 125 return -EINVAL;
126 126
127 mutex_lock(&sysfs_mutex); 127 mutex_lock(&sysfs_mutex);
@@ -129,7 +129,7 @@ int sysfs_setattr(struct dentry *dentry, struct iattr *iattr)
129 if (error) 129 if (error)
130 goto out; 130 goto out;
131 131
132 error = __kernfs_setattr(sd, iattr); 132 error = __kernfs_setattr(kn, iattr);
133 if (error) 133 if (error)
134 goto out; 134 goto out;
135 135
@@ -141,14 +141,14 @@ out:
141 return error; 141 return error;
142} 142}
143 143
144static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata, 144static int sysfs_sd_setsecdata(struct kernfs_node *kn, void **secdata,
145 u32 *secdata_len) 145 u32 *secdata_len)
146{ 146{
147 struct sysfs_inode_attrs *attrs; 147 struct sysfs_inode_attrs *attrs;
148 void *old_secdata; 148 void *old_secdata;
149 size_t old_secdata_len; 149 size_t old_secdata_len;
150 150
151 attrs = sysfs_inode_attrs(sd); 151 attrs = sysfs_inode_attrs(kn);
152 if (!attrs) 152 if (!attrs)
153 return -ENOMEM; 153 return -ENOMEM;
154 154
@@ -166,13 +166,13 @@ static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata,
166int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, 166int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
167 size_t size, int flags) 167 size_t size, int flags)
168{ 168{
169 struct sysfs_dirent *sd = dentry->d_fsdata; 169 struct kernfs_node *kn = dentry->d_fsdata;
170 struct sysfs_inode_attrs *attrs; 170 struct sysfs_inode_attrs *attrs;
171 void *secdata; 171 void *secdata;
172 int error; 172 int error;
173 u32 secdata_len = 0; 173 u32 secdata_len = 0;
174 174
175 attrs = sysfs_inode_attrs(sd); 175 attrs = sysfs_inode_attrs(kn);
176 if (!attrs) 176 if (!attrs)
177 return -ENOMEM; 177 return -ENOMEM;
178 178
@@ -188,7 +188,7 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
188 return error; 188 return error;
189 189
190 mutex_lock(&sysfs_mutex); 190 mutex_lock(&sysfs_mutex);
191 error = sysfs_sd_setsecdata(sd, &secdata, &secdata_len); 191 error = sysfs_sd_setsecdata(kn, &secdata, &secdata_len);
192 mutex_unlock(&sysfs_mutex); 192 mutex_unlock(&sysfs_mutex);
193 193
194 if (secdata) 194 if (secdata)
@@ -204,10 +204,10 @@ int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
204 204
205int sysfs_removexattr(struct dentry *dentry, const char *name) 205int sysfs_removexattr(struct dentry *dentry, const char *name)
206{ 206{
207 struct sysfs_dirent *sd = dentry->d_fsdata; 207 struct kernfs_node *kn = dentry->d_fsdata;
208 struct sysfs_inode_attrs *attrs; 208 struct sysfs_inode_attrs *attrs;
209 209
210 attrs = sysfs_inode_attrs(sd); 210 attrs = sysfs_inode_attrs(kn);
211 if (!attrs) 211 if (!attrs)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
@@ -217,10 +217,10 @@ int sysfs_removexattr(struct dentry *dentry, const char *name)
217ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf, 217ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf,
218 size_t size) 218 size_t size)
219{ 219{
220 struct sysfs_dirent *sd = dentry->d_fsdata; 220 struct kernfs_node *kn = dentry->d_fsdata;
221 struct sysfs_inode_attrs *attrs; 221 struct sysfs_inode_attrs *attrs;
222 222
223 attrs = sysfs_inode_attrs(sd); 223 attrs = sysfs_inode_attrs(kn);
224 if (!attrs) 224 if (!attrs)
225 return -ENOMEM; 225 return -ENOMEM;
226 226
@@ -229,10 +229,10 @@ ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf,
229 229
230ssize_t sysfs_listxattr(struct dentry *dentry, char *buf, size_t size) 230ssize_t sysfs_listxattr(struct dentry *dentry, char *buf, size_t size)
231{ 231{
232 struct sysfs_dirent *sd = dentry->d_fsdata; 232 struct kernfs_node *kn = dentry->d_fsdata;
233 struct sysfs_inode_attrs *attrs; 233 struct sysfs_inode_attrs *attrs;
234 234
235 attrs = sysfs_inode_attrs(sd); 235 attrs = sysfs_inode_attrs(kn);
236 if (!attrs) 236 if (!attrs)
237 return -ENOMEM; 237 return -ENOMEM;
238 238
@@ -254,57 +254,58 @@ static inline void set_inode_attr(struct inode *inode, struct iattr *iattr)
254 inode->i_ctime = iattr->ia_ctime; 254 inode->i_ctime = iattr->ia_ctime;
255} 255}
256 256
257static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode) 257static void sysfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
258{ 258{
259 struct sysfs_inode_attrs *attrs = sd->s_iattr; 259 struct sysfs_inode_attrs *attrs = kn->s_iattr;
260 260
261 inode->i_mode = sd->s_mode; 261 inode->i_mode = kn->s_mode;
262 if (attrs) { 262 if (attrs) {
263 /* sysfs_dirent has non-default attributes 263 /*
264 * get them from persistent copy in sysfs_dirent 264 * kernfs_node has non-default attributes get them from
265 * persistent copy in kernfs_node.
265 */ 266 */
266 set_inode_attr(inode, &attrs->ia_iattr); 267 set_inode_attr(inode, &attrs->ia_iattr);
267 security_inode_notifysecctx(inode, attrs->ia_secdata, 268 security_inode_notifysecctx(inode, attrs->ia_secdata,
268 attrs->ia_secdata_len); 269 attrs->ia_secdata_len);
269 } 270 }
270 271
271 if (sysfs_type(sd) == SYSFS_DIR) 272 if (sysfs_type(kn) == SYSFS_DIR)
272 set_nlink(inode, sd->s_dir.subdirs + 2); 273 set_nlink(inode, kn->s_dir.subdirs + 2);
273} 274}
274 275
275int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, 276int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
276 struct kstat *stat) 277 struct kstat *stat)
277{ 278{
278 struct sysfs_dirent *sd = dentry->d_fsdata; 279 struct kernfs_node *kn = dentry->d_fsdata;
279 struct inode *inode = dentry->d_inode; 280 struct inode *inode = dentry->d_inode;
280 281
281 mutex_lock(&sysfs_mutex); 282 mutex_lock(&sysfs_mutex);
282 sysfs_refresh_inode(sd, inode); 283 sysfs_refresh_inode(kn, inode);
283 mutex_unlock(&sysfs_mutex); 284 mutex_unlock(&sysfs_mutex);
284 285
285 generic_fillattr(inode, stat); 286 generic_fillattr(inode, stat);
286 return 0; 287 return 0;
287} 288}
288 289
289static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) 290static void sysfs_init_inode(struct kernfs_node *kn, struct inode *inode)
290{ 291{
291 kernfs_get(sd); 292 kernfs_get(kn);
292 inode->i_private = sd; 293 inode->i_private = kn;
293 inode->i_mapping->a_ops = &sysfs_aops; 294 inode->i_mapping->a_ops = &sysfs_aops;
294 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 295 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
295 inode->i_op = &sysfs_inode_operations; 296 inode->i_op = &sysfs_inode_operations;
296 297
297 set_default_inode_attr(inode, sd->s_mode); 298 set_default_inode_attr(inode, kn->s_mode);
298 sysfs_refresh_inode(sd, inode); 299 sysfs_refresh_inode(kn, inode);
299 300
300 /* initialize inode according to type */ 301 /* initialize inode according to type */
301 switch (sysfs_type(sd)) { 302 switch (sysfs_type(kn)) {
302 case SYSFS_DIR: 303 case SYSFS_DIR:
303 inode->i_op = &sysfs_dir_inode_operations; 304 inode->i_op = &sysfs_dir_inode_operations;
304 inode->i_fop = &sysfs_dir_operations; 305 inode->i_fop = &sysfs_dir_operations;
305 break; 306 break;
306 case SYSFS_KOBJ_ATTR: 307 case SYSFS_KOBJ_ATTR:
307 inode->i_size = sd->s_attr.size; 308 inode->i_size = kn->s_attr.size;
308 inode->i_fop = &kernfs_file_operations; 309 inode->i_fop = &kernfs_file_operations;
309 break; 310 break;
310 case SYSFS_KOBJ_LINK: 311 case SYSFS_KOBJ_LINK:
@@ -318,13 +319,13 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
318} 319}
319 320
320/** 321/**
321 * sysfs_get_inode - get inode for sysfs_dirent 322 * sysfs_get_inode - get inode for kernfs_node
322 * @sb: super block 323 * @sb: super block
323 * @sd: sysfs_dirent to allocate inode for 324 * @kn: kernfs_node to allocate inode for
324 * 325 *
325 * Get inode for @sd. If such inode doesn't exist, a new inode 326 * Get inode for @kn. If such inode doesn't exist, a new inode is
326 * is allocated and basics are initialized. New inode is 327 * allocated and basics are initialized. New inode is returned
327 * returned locked. 328 * locked.
328 * 329 *
329 * LOCKING: 330 * LOCKING:
330 * Kernel thread context (may sleep). 331 * Kernel thread context (may sleep).
@@ -332,44 +333,44 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
332 * RETURNS: 333 * RETURNS:
333 * Pointer to allocated inode on success, NULL on failure. 334 * Pointer to allocated inode on success, NULL on failure.
334 */ 335 */
335struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd) 336struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
336{ 337{
337 struct inode *inode; 338 struct inode *inode;
338 339
339 inode = iget_locked(sb, sd->s_ino); 340 inode = iget_locked(sb, kn->s_ino);
340 if (inode && (inode->i_state & I_NEW)) 341 if (inode && (inode->i_state & I_NEW))
341 sysfs_init_inode(sd, inode); 342 sysfs_init_inode(kn, inode);
342 343
343 return inode; 344 return inode;
344} 345}
345 346
346/* 347/*
347 * The sysfs_dirent serves as both an inode and a directory entry for sysfs. 348 * The kernfs_node serves as both an inode and a directory entry for sysfs.
348 * To prevent the sysfs inode numbers from being freed prematurely we take a 349 * To prevent the sysfs inode numbers from being freed prematurely we take
349 * reference to sysfs_dirent from the sysfs inode. A 350 * a reference to kernfs_node from the sysfs inode. A
350 * super_operations.evict_inode() implementation is needed to drop that 351 * super_operations.evict_inode() implementation is needed to drop that
351 * reference upon inode destruction. 352 * reference upon inode destruction.
352 */ 353 */
353void sysfs_evict_inode(struct inode *inode) 354void sysfs_evict_inode(struct inode *inode)
354{ 355{
355 struct sysfs_dirent *sd = inode->i_private; 356 struct kernfs_node *kn = inode->i_private;
356 357
357 truncate_inode_pages(&inode->i_data, 0); 358 truncate_inode_pages(&inode->i_data, 0);
358 clear_inode(inode); 359 clear_inode(inode);
359 kernfs_put(sd); 360 kernfs_put(kn);
360} 361}
361 362
362int sysfs_permission(struct inode *inode, int mask) 363int sysfs_permission(struct inode *inode, int mask)
363{ 364{
364 struct sysfs_dirent *sd; 365 struct kernfs_node *kn;
365 366
366 if (mask & MAY_NOT_BLOCK) 367 if (mask & MAY_NOT_BLOCK)
367 return -ECHILD; 368 return -ECHILD;
368 369
369 sd = inode->i_private; 370 kn = inode->i_private;
370 371
371 mutex_lock(&sysfs_mutex); 372 mutex_lock(&sysfs_mutex);
372 sysfs_refresh_inode(sd, inode); 373 sysfs_refresh_inode(kn, inode);
373 mutex_unlock(&sysfs_mutex); 374 mutex_unlock(&sysfs_mutex);
374 375
375 return generic_permission(inode, mask); 376 return generic_permission(inode, mask);
diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h
index 910e485b7333..b7ea76c6fb33 100644
--- a/fs/kernfs/kernfs-internal.h
+++ b/fs/kernfs/kernfs-internal.h
@@ -31,24 +31,24 @@ struct sysfs_inode_attrs {
31/* SYSFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ 31/* SYSFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
32 32
33/** 33/**
34 * kernfs_root - find out the kernfs_root a sysfs_dirent belongs to 34 * kernfs_root - find out the kernfs_root a kernfs_node belongs to
35 * @sd: sysfs_dirent of interest 35 * @kn: kernfs_node of interest
36 * 36 *
37 * Return the kernfs_root @sd belongs to. 37 * Return the kernfs_root @kn belongs to.
38 */ 38 */
39static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd) 39static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
40{ 40{
41 /* if parent exists, it's always a dir; otherwise, @sd is a dir */ 41 /* if parent exists, it's always a dir; otherwise, @sd is a dir */
42 if (sd->s_parent) 42 if (kn->s_parent)
43 sd = sd->s_parent; 43 kn = kn->s_parent;
44 return sd->s_dir.root; 44 return kn->s_dir.root;
45} 45}
46 46
47/* 47/*
48 * Context structure to be used while adding/removing nodes. 48 * Context structure to be used while adding/removing nodes.
49 */ 49 */
50struct sysfs_addrm_cxt { 50struct sysfs_addrm_cxt {
51 struct sysfs_dirent *removed; 51 struct kernfs_node *removed;
52}; 52};
53 53
54/* 54/*
@@ -62,10 +62,10 @@ struct sysfs_super_info {
62 struct kernfs_root *root; 62 struct kernfs_root *root;
63 63
64 /* 64 /*
65 * Each sb is associated with one namespace tag, currently the network 65 * Each sb is associated with one namespace tag, currently the
66 * namespace of the task which mounted this sysfs instance. If multiple 66 * network namespace of the task which mounted this sysfs instance.
67 * tags become necessary, make the following an array and compare 67 * If multiple tags become necessary, make the following an array
68 * sysfs_dirent tag against every entry. 68 * and compare kernfs_node tag against every entry.
69 */ 69 */
70 const void *ns; 70 const void *ns;
71}; 71};
@@ -76,7 +76,7 @@ extern struct kmem_cache *sysfs_dir_cachep;
76/* 76/*
77 * inode.c 77 * inode.c
78 */ 78 */
79struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd); 79struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
80void sysfs_evict_inode(struct inode *inode); 80void sysfs_evict_inode(struct inode *inode);
81int sysfs_permission(struct inode *inode, int mask); 81int sysfs_permission(struct inode *inode, int mask);
82int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); 82int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
@@ -98,21 +98,21 @@ extern const struct dentry_operations sysfs_dentry_ops;
98extern const struct file_operations sysfs_dir_operations; 98extern const struct file_operations sysfs_dir_operations;
99extern const struct inode_operations sysfs_dir_inode_operations; 99extern const struct inode_operations sysfs_dir_inode_operations;
100 100
101struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); 101struct kernfs_node *sysfs_get_active(struct kernfs_node *kn);
102void sysfs_put_active(struct sysfs_dirent *sd); 102void sysfs_put_active(struct kernfs_node *kn);
103void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt); 103void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
104int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, 104int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn,
105 struct sysfs_dirent *parent_sd); 105 struct kernfs_node *parent);
106void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); 106void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
107struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, 107struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root,
108 const char *name, umode_t mode, int type); 108 const char *name, umode_t mode, int type);
109 109
110/* 110/*
111 * file.c 111 * file.c
112 */ 112 */
113extern const struct file_operations kernfs_file_operations; 113extern const struct file_operations kernfs_file_operations;
114 114
115void sysfs_unmap_bin_file(struct sysfs_dirent *sd); 115void sysfs_unmap_bin_file(struct kernfs_node *kn);
116 116
117/* 117/*
118 * symlink.c 118 * symlink.c
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 84c83e24bf25..9dbbf37b1af9 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -39,7 +39,7 @@ static int sysfs_fill_super(struct super_block *sb)
39 39
40 /* get root inode, initialize and unlock it */ 40 /* get root inode, initialize and unlock it */
41 mutex_lock(&sysfs_mutex); 41 mutex_lock(&sysfs_mutex);
42 inode = sysfs_get_inode(sb, info->root->sd); 42 inode = sysfs_get_inode(sb, info->root->kn);
43 mutex_unlock(&sysfs_mutex); 43 mutex_unlock(&sysfs_mutex);
44 if (!inode) { 44 if (!inode) {
45 pr_debug("sysfs: could not get root inode\n"); 45 pr_debug("sysfs: could not get root inode\n");
@@ -52,8 +52,8 @@ static int sysfs_fill_super(struct super_block *sb)
52 pr_debug("%s: could not get root dentry!\n", __func__); 52 pr_debug("%s: could not get root dentry!\n", __func__);
53 return -ENOMEM; 53 return -ENOMEM;
54 } 54 }
55 kernfs_get(info->root->sd); 55 kernfs_get(info->root->kn);
56 root->d_fsdata = info->root->sd; 56 root->d_fsdata = info->root->kn;
57 sb->s_root = root; 57 sb->s_root = root;
58 sb->s_d_op = &sysfs_dentry_ops; 58 sb->s_d_op = &sysfs_dentry_ops;
59 return 0; 59 return 0;
@@ -145,7 +145,7 @@ struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
145void kernfs_kill_sb(struct super_block *sb) 145void kernfs_kill_sb(struct super_block *sb)
146{ 146{
147 struct sysfs_super_info *info = sysfs_info(sb); 147 struct sysfs_super_info *info = sysfs_info(sb);
148 struct sysfs_dirent *root_sd = sb->s_root->d_fsdata; 148 struct kernfs_node *root_kn = sb->s_root->d_fsdata;
149 149
150 /* 150 /*
151 * Remove the superblock from fs_supers/s_instances 151 * Remove the superblock from fs_supers/s_instances
@@ -153,13 +153,13 @@ void kernfs_kill_sb(struct super_block *sb)
153 */ 153 */
154 kill_anon_super(sb); 154 kill_anon_super(sb);
155 kfree(info); 155 kfree(info);
156 kernfs_put(root_sd); 156 kernfs_put(root_kn);
157} 157}
158 158
159void __init kernfs_init(void) 159void __init kernfs_init(void)
160{ 160{
161 sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache", 161 sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache",
162 sizeof(struct sysfs_dirent), 162 sizeof(struct kernfs_node),
163 0, SLAB_PANIC, NULL); 163 0, SLAB_PANIC, NULL);
164 sysfs_inode_init(); 164 sysfs_inode_init();
165} 165}
diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
index adf28755b0ee..29dcf5e8debd 100644
--- a/fs/kernfs/symlink.c
+++ b/fs/kernfs/symlink.c
@@ -22,50 +22,50 @@
22 * 22 *
23 * Returns the created node on success, ERR_PTR() value on error. 23 * Returns the created node on success, ERR_PTR() value on error.
24 */ 24 */
25struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, 25struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
26 const char *name, 26 const char *name,
27 struct sysfs_dirent *target) 27 struct kernfs_node *target)
28{ 28{
29 struct sysfs_dirent *sd; 29 struct kernfs_node *kn;
30 struct sysfs_addrm_cxt acxt; 30 struct sysfs_addrm_cxt acxt;
31 int error; 31 int error;
32 32
33 sd = sysfs_new_dirent(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO, 33 kn = sysfs_new_dirent(kernfs_root(parent), name, S_IFLNK|S_IRWXUGO,
34 SYSFS_KOBJ_LINK); 34 SYSFS_KOBJ_LINK);
35 if (!sd) 35 if (!kn)
36 return ERR_PTR(-ENOMEM); 36 return ERR_PTR(-ENOMEM);
37 37
38 if (kernfs_ns_enabled(parent)) 38 if (kernfs_ns_enabled(parent))
39 sd->s_ns = target->s_ns; 39 kn->s_ns = target->s_ns;
40 sd->s_symlink.target_sd = target; 40 kn->s_symlink.target_kn = target;
41 kernfs_get(target); /* ref owned by symlink */ 41 kernfs_get(target); /* ref owned by symlink */
42 42
43 sysfs_addrm_start(&acxt); 43 sysfs_addrm_start(&acxt);
44 error = sysfs_add_one(&acxt, sd, parent); 44 error = sysfs_add_one(&acxt, kn, parent);
45 sysfs_addrm_finish(&acxt); 45 sysfs_addrm_finish(&acxt);
46 46
47 if (!error) 47 if (!error)
48 return sd; 48 return kn;
49 49
50 kernfs_put(sd); 50 kernfs_put(kn);
51 return ERR_PTR(error); 51 return ERR_PTR(error);
52} 52}
53 53
54static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, 54static int sysfs_get_target_path(struct kernfs_node *parent,
55 struct sysfs_dirent *target_sd, char *path) 55 struct kernfs_node *target, char *path)
56{ 56{
57 struct sysfs_dirent *base, *sd; 57 struct kernfs_node *base, *kn;
58 char *s = path; 58 char *s = path;
59 int len = 0; 59 int len = 0;
60 60
61 /* go up to the root, stop at the base */ 61 /* go up to the root, stop at the base */
62 base = parent_sd; 62 base = parent;
63 while (base->s_parent) { 63 while (base->s_parent) {
64 sd = target_sd->s_parent; 64 kn = target->s_parent;
65 while (sd->s_parent && base != sd) 65 while (kn->s_parent && base != kn)
66 sd = sd->s_parent; 66 kn = kn->s_parent;
67 67
68 if (base == sd) 68 if (base == kn)
69 break; 69 break;
70 70
71 strcpy(s, "../"); 71 strcpy(s, "../");
@@ -74,10 +74,10 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
74 } 74 }
75 75
76 /* determine end of target string for reverse fillup */ 76 /* determine end of target string for reverse fillup */
77 sd = target_sd; 77 kn = target;
78 while (sd->s_parent && sd != base) { 78 while (kn->s_parent && kn != base) {
79 len += strlen(sd->s_name) + 1; 79 len += strlen(kn->s_name) + 1;
80 sd = sd->s_parent; 80 kn = kn->s_parent;
81 } 81 }
82 82
83 /* check limits */ 83 /* check limits */
@@ -88,16 +88,16 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
88 return -ENAMETOOLONG; 88 return -ENAMETOOLONG;
89 89
90 /* reverse fillup of target string from target to base */ 90 /* reverse fillup of target string from target to base */
91 sd = target_sd; 91 kn = target;
92 while (sd->s_parent && sd != base) { 92 while (kn->s_parent && kn != base) {
93 int slen = strlen(sd->s_name); 93 int slen = strlen(kn->s_name);
94 94
95 len -= slen; 95 len -= slen;
96 strncpy(s + len, sd->s_name, slen); 96 strncpy(s + len, kn->s_name, slen);
97 if (len) 97 if (len)
98 s[--len] = '/'; 98 s[--len] = '/';
99 99
100 sd = sd->s_parent; 100 kn = kn->s_parent;
101 } 101 }
102 102
103 return 0; 103 return 0;
@@ -105,13 +105,13 @@ static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
105 105
106static int sysfs_getlink(struct dentry *dentry, char *path) 106static int sysfs_getlink(struct dentry *dentry, char *path)
107{ 107{
108 struct sysfs_dirent *sd = dentry->d_fsdata; 108 struct kernfs_node *kn = dentry->d_fsdata;
109 struct sysfs_dirent *parent_sd = sd->s_parent; 109 struct kernfs_node *parent = kn->s_parent;
110 struct sysfs_dirent *target_sd = sd->s_symlink.target_sd; 110 struct kernfs_node *target = kn->s_symlink.target_kn;
111 int error; 111 int error;
112 112
113 mutex_lock(&sysfs_mutex); 113 mutex_lock(&sysfs_mutex);
114 error = sysfs_get_target_path(parent_sd, target_sd, path); 114 error = sysfs_get_target_path(parent, target, path);
115 mutex_unlock(&sysfs_mutex); 115 mutex_unlock(&sysfs_mutex);
116 116
117 return error; 117 return error;
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 2fea501889e7..f1efe3df0de6 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -21,23 +21,23 @@ DEFINE_SPINLOCK(sysfs_symlink_target_lock);
21 21
22/** 22/**
23 * sysfs_pathname - return full path to sysfs dirent 23 * sysfs_pathname - return full path to sysfs dirent
24 * @sd: sysfs_dirent whose path we want 24 * @kn: kernfs_node whose path we want
25 * @path: caller allocated buffer of size PATH_MAX 25 * @path: caller allocated buffer of size PATH_MAX
26 * 26 *
27 * Gives the name "/" to the sysfs_root entry; any path returned 27 * Gives the name "/" to the sysfs_root entry; any path returned
28 * is relative to wherever sysfs is mounted. 28 * is relative to wherever sysfs is mounted.
29 */ 29 */
30static char *sysfs_pathname(struct sysfs_dirent *sd, char *path) 30static char *sysfs_pathname(struct kernfs_node *kn, char *path)
31{ 31{
32 if (sd->s_parent) { 32 if (kn->s_parent) {
33 sysfs_pathname(sd->s_parent, path); 33 sysfs_pathname(kn->s_parent, path);
34 strlcat(path, "/", PATH_MAX); 34 strlcat(path, "/", PATH_MAX);
35 } 35 }
36 strlcat(path, sd->s_name, PATH_MAX); 36 strlcat(path, kn->s_name, PATH_MAX);
37 return path; 37 return path;
38} 38}
39 39
40void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name) 40void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
41{ 41{
42 char *path; 42 char *path;
43 43
@@ -61,26 +61,26 @@ void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name)
61 */ 61 */
62int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) 62int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
63{ 63{
64 struct sysfs_dirent *parent_sd, *sd; 64 struct kernfs_node *parent, *kn;
65 65
66 BUG_ON(!kobj); 66 BUG_ON(!kobj);
67 67
68 if (kobj->parent) 68 if (kobj->parent)
69 parent_sd = kobj->parent->sd; 69 parent = kobj->parent->sd;
70 else 70 else
71 parent_sd = sysfs_root_sd; 71 parent = sysfs_root_kn;
72 72
73 if (!parent_sd) 73 if (!parent)
74 return -ENOENT; 74 return -ENOENT;
75 75
76 sd = kernfs_create_dir_ns(parent_sd, kobject_name(kobj), kobj, ns); 76 kn = kernfs_create_dir_ns(parent, kobject_name(kobj), kobj, ns);
77 if (IS_ERR(sd)) { 77 if (IS_ERR(kn)) {
78 if (PTR_ERR(sd) == -EEXIST) 78 if (PTR_ERR(kn) == -EEXIST)
79 sysfs_warn_dup(parent_sd, kobject_name(kobj)); 79 sysfs_warn_dup(parent, kobject_name(kobj));
80 return PTR_ERR(sd); 80 return PTR_ERR(kn);
81 } 81 }
82 82
83 kobj->sd = sd; 83 kobj->sd = kn;
84 return 0; 84 return 0;
85} 85}
86 86
@@ -94,47 +94,47 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
94 */ 94 */
95void sysfs_remove_dir(struct kobject *kobj) 95void sysfs_remove_dir(struct kobject *kobj)
96{ 96{
97 struct sysfs_dirent *sd = kobj->sd; 97 struct kernfs_node *kn = kobj->sd;
98 98
99 /* 99 /*
100 * In general, kboject owner is responsible for ensuring removal 100 * In general, kboject owner is responsible for ensuring removal
101 * doesn't race with other operations and sysfs doesn't provide any 101 * doesn't race with other operations and sysfs doesn't provide any
102 * protection; however, when @kobj is used as a symlink target, the 102 * protection; however, when @kobj is used as a symlink target, the
103 * symlinking entity usually doesn't own @kobj and thus has no 103 * symlinking entity usually doesn't own @kobj and thus has no
104 * control over removal. @kobj->sd may be removed anytime and 104 * control over removal. @kobj->sd may be removed anytime
105 * symlink code may end up dereferencing an already freed sd. 105 * and symlink code may end up dereferencing an already freed node.
106 * 106 *
107 * sysfs_symlink_target_lock synchronizes @kobj->sd disassociation 107 * sysfs_symlink_target_lock synchronizes @kobj->sd
108 * against symlink operations so that symlink code can safely 108 * disassociation against symlink operations so that symlink code
109 * dereference @kobj->sd. 109 * can safely dereference @kobj->sd.
110 */ 110 */
111 spin_lock(&sysfs_symlink_target_lock); 111 spin_lock(&sysfs_symlink_target_lock);
112 kobj->sd = NULL; 112 kobj->sd = NULL;
113 spin_unlock(&sysfs_symlink_target_lock); 113 spin_unlock(&sysfs_symlink_target_lock);
114 114
115 if (sd) { 115 if (kn) {
116 WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); 116 WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
117 kernfs_remove(sd); 117 kernfs_remove(kn);
118 } 118 }
119} 119}
120 120
121int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, 121int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name,
122 const void *new_ns) 122 const void *new_ns)
123{ 123{
124 struct sysfs_dirent *parent_sd = kobj->sd->s_parent; 124 struct kernfs_node *parent = kobj->sd->s_parent;
125 125
126 return kernfs_rename_ns(kobj->sd, parent_sd, new_name, new_ns); 126 return kernfs_rename_ns(kobj->sd, parent, new_name, new_ns);
127} 127}
128 128
129int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, 129int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj,
130 const void *new_ns) 130 const void *new_ns)
131{ 131{
132 struct sysfs_dirent *sd = kobj->sd; 132 struct kernfs_node *kn = kobj->sd;
133 struct sysfs_dirent *new_parent_sd; 133 struct kernfs_node *new_parent;
134 134
135 BUG_ON(!sd->s_parent); 135 BUG_ON(!kn->s_parent);
136 new_parent_sd = new_parent_kobj && new_parent_kobj->sd ? 136 new_parent = new_parent_kobj && new_parent_kobj->sd ?
137 new_parent_kobj->sd : sysfs_root_sd; 137 new_parent_kobj->sd : sysfs_root_kn;
138 138
139 return kernfs_rename_ns(sd, new_parent_sd, sd->s_name, new_ns); 139 return kernfs_rename_ns(kn, new_parent, kn->s_name, new_ns);
140} 140}
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index a67d1c682fed..be1cc39035bd 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -22,15 +22,15 @@
22#include "../kernfs/kernfs-internal.h" 22#include "../kernfs/kernfs-internal.h"
23 23
24/* 24/*
25 * Determine ktype->sysfs_ops for the given sysfs_dirent. This function 25 * Determine ktype->sysfs_ops for the given kernfs_node. This function
26 * must be called while holding an active reference. 26 * must be called while holding an active reference.
27 */ 27 */
28static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) 28static const struct sysfs_ops *sysfs_file_ops(struct kernfs_node *kn)
29{ 29{
30 struct kobject *kobj = sd->s_parent->priv; 30 struct kobject *kobj = kn->s_parent->priv;
31 31
32 if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 32 if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
33 lockdep_assert_held(sd); 33 lockdep_assert_held(kn);
34 return kobj->ktype ? kobj->ktype->sysfs_ops : NULL; 34 return kobj->ktype ? kobj->ktype->sysfs_ops : NULL;
35} 35}
36 36
@@ -42,8 +42,8 @@ static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd)
42static int sysfs_kf_seq_show(struct seq_file *sf, void *v) 42static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
43{ 43{
44 struct sysfs_open_file *of = sf->private; 44 struct sysfs_open_file *of = sf->private;
45 struct kobject *kobj = of->sd->s_parent->priv; 45 struct kobject *kobj = of->kn->s_parent->priv;
46 const struct sysfs_ops *ops = sysfs_file_ops(of->sd); 46 const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
47 ssize_t count; 47 ssize_t count;
48 char *buf; 48 char *buf;
49 49
@@ -59,7 +59,7 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
59 * if @ops->show() isn't implemented. 59 * if @ops->show() isn't implemented.
60 */ 60 */
61 if (ops->show) { 61 if (ops->show) {
62 count = ops->show(kobj, of->sd->priv, buf); 62 count = ops->show(kobj, of->kn->priv, buf);
63 if (count < 0) 63 if (count < 0)
64 return count; 64 return count;
65 } 65 }
@@ -81,8 +81,8 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
81static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf, 81static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf,
82 size_t count, loff_t pos) 82 size_t count, loff_t pos)
83{ 83{
84 struct bin_attribute *battr = of->sd->priv; 84 struct bin_attribute *battr = of->kn->priv;
85 struct kobject *kobj = of->sd->s_parent->priv; 85 struct kobject *kobj = of->kn->s_parent->priv;
86 loff_t size = file_inode(of->file)->i_size; 86 loff_t size = file_inode(of->file)->i_size;
87 87
88 if (!count) 88 if (!count)
@@ -105,21 +105,21 @@ static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf,
105static ssize_t sysfs_kf_write(struct sysfs_open_file *of, char *buf, 105static ssize_t sysfs_kf_write(struct sysfs_open_file *of, char *buf,
106 size_t count, loff_t pos) 106 size_t count, loff_t pos)
107{ 107{
108 const struct sysfs_ops *ops = sysfs_file_ops(of->sd); 108 const struct sysfs_ops *ops = sysfs_file_ops(of->kn);
109 struct kobject *kobj = of->sd->s_parent->priv; 109 struct kobject *kobj = of->kn->s_parent->priv;
110 110
111 if (!count) 111 if (!count)
112 return 0; 112 return 0;
113 113
114 return ops->store(kobj, of->sd->priv, buf, count); 114 return ops->store(kobj, of->kn->priv, buf, count);
115} 115}
116 116
117/* kernfs write callback for bin sysfs files */ 117/* kernfs write callback for bin sysfs files */
118static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf, 118static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf,
119 size_t count, loff_t pos) 119 size_t count, loff_t pos)
120{ 120{
121 struct bin_attribute *battr = of->sd->priv; 121 struct bin_attribute *battr = of->kn->priv;
122 struct kobject *kobj = of->sd->s_parent->priv; 122 struct kobject *kobj = of->kn->s_parent->priv;
123 loff_t size = file_inode(of->file)->i_size; 123 loff_t size = file_inode(of->file)->i_size;
124 124
125 if (size) { 125 if (size) {
@@ -139,30 +139,30 @@ static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf,
139static int sysfs_kf_bin_mmap(struct sysfs_open_file *of, 139static int sysfs_kf_bin_mmap(struct sysfs_open_file *of,
140 struct vm_area_struct *vma) 140 struct vm_area_struct *vma)
141{ 141{
142 struct bin_attribute *battr = of->sd->priv; 142 struct bin_attribute *battr = of->kn->priv;
143 struct kobject *kobj = of->sd->s_parent->priv; 143 struct kobject *kobj = of->kn->s_parent->priv;
144 144
145 return battr->mmap(of->file, kobj, battr, vma); 145 return battr->mmap(of->file, kobj, battr, vma);
146} 146}
147 147
148void sysfs_notify(struct kobject *k, const char *dir, const char *attr) 148void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr)
149{ 149{
150 struct sysfs_dirent *sd = k->sd, *tmp; 150 struct kernfs_node *kn = kobj->sd, *tmp;
151 151
152 if (sd && dir) 152 if (kn && dir)
153 sd = kernfs_find_and_get(sd, dir); 153 kn = kernfs_find_and_get(kn, dir);
154 else 154 else
155 kernfs_get(sd); 155 kernfs_get(kn);
156 156
157 if (sd && attr) { 157 if (kn && attr) {
158 tmp = kernfs_find_and_get(sd, attr); 158 tmp = kernfs_find_and_get(kn, attr);
159 kernfs_put(sd); 159 kernfs_put(kn);
160 sd = tmp; 160 kn = tmp;
161 } 161 }
162 162
163 if (sd) { 163 if (kn) {
164 kernfs_notify(sd); 164 kernfs_notify(kn);
165 kernfs_put(sd); 165 kernfs_put(kn);
166 } 166 }
167} 167}
168EXPORT_SYMBOL_GPL(sysfs_notify); 168EXPORT_SYMBOL_GPL(sysfs_notify);
@@ -202,17 +202,17 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = {
202 .mmap = sysfs_kf_bin_mmap, 202 .mmap = sysfs_kf_bin_mmap,
203}; 203};
204 204
205int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, 205int sysfs_add_file_mode_ns(struct kernfs_node *parent,
206 const struct attribute *attr, bool is_bin, 206 const struct attribute *attr, bool is_bin,
207 umode_t mode, const void *ns) 207 umode_t mode, const void *ns)
208{ 208{
209 struct lock_class_key *key = NULL; 209 struct lock_class_key *key = NULL;
210 const struct kernfs_ops *ops; 210 const struct kernfs_ops *ops;
211 struct sysfs_dirent *sd; 211 struct kernfs_node *kn;
212 loff_t size; 212 loff_t size;
213 213
214 if (!is_bin) { 214 if (!is_bin) {
215 struct kobject *kobj = dir_sd->priv; 215 struct kobject *kobj = parent->priv;
216 const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; 216 const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops;
217 217
218 /* every kobject with an attribute needs a ktype assigned */ 218 /* every kobject with an attribute needs a ktype assigned */
@@ -252,20 +252,20 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
252 if (!attr->ignore_lockdep) 252 if (!attr->ignore_lockdep)
253 key = attr->key ?: (struct lock_class_key *)&attr->skey; 253 key = attr->key ?: (struct lock_class_key *)&attr->skey;
254#endif 254#endif
255 sd = kernfs_create_file_ns_key(dir_sd, attr->name, mode, size, 255 kn = kernfs_create_file_ns_key(parent, attr->name, mode, size,
256 ops, (void *)attr, ns, key); 256 ops, (void *)attr, ns, key);
257 if (IS_ERR(sd)) { 257 if (IS_ERR(kn)) {
258 if (PTR_ERR(sd) == -EEXIST) 258 if (PTR_ERR(kn) == -EEXIST)
259 sysfs_warn_dup(dir_sd, attr->name); 259 sysfs_warn_dup(parent, attr->name);
260 return PTR_ERR(sd); 260 return PTR_ERR(kn);
261 } 261 }
262 return 0; 262 return 0;
263} 263}
264 264
265int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, 265int sysfs_add_file(struct kernfs_node *parent, const struct attribute *attr,
266 bool is_bin) 266 bool is_bin)
267{ 267{
268 return sysfs_add_file_mode_ns(dir_sd, attr, is_bin, attr->mode, NULL); 268 return sysfs_add_file_mode_ns(parent, attr, is_bin, attr->mode, NULL);
269} 269}
270 270
271/** 271/**
@@ -307,21 +307,21 @@ EXPORT_SYMBOL_GPL(sysfs_create_files);
307int sysfs_add_file_to_group(struct kobject *kobj, 307int sysfs_add_file_to_group(struct kobject *kobj,
308 const struct attribute *attr, const char *group) 308 const struct attribute *attr, const char *group)
309{ 309{
310 struct sysfs_dirent *dir_sd; 310 struct kernfs_node *parent;
311 int error; 311 int error;
312 312
313 if (group) { 313 if (group) {
314 dir_sd = kernfs_find_and_get(kobj->sd, group); 314 parent = kernfs_find_and_get(kobj->sd, group);
315 } else { 315 } else {
316 dir_sd = kobj->sd; 316 parent = kobj->sd;
317 kernfs_get(dir_sd); 317 kernfs_get(parent);
318 } 318 }
319 319
320 if (!dir_sd) 320 if (!parent)
321 return -ENOENT; 321 return -ENOENT;
322 322
323 error = sysfs_add_file(dir_sd, attr, false); 323 error = sysfs_add_file(parent, attr, false);
324 kernfs_put(dir_sd); 324 kernfs_put(parent);
325 325
326 return error; 326 return error;
327} 327}
@@ -337,20 +337,20 @@ EXPORT_SYMBOL_GPL(sysfs_add_file_to_group);
337int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr, 337int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
338 umode_t mode) 338 umode_t mode)
339{ 339{
340 struct sysfs_dirent *sd; 340 struct kernfs_node *kn;
341 struct iattr newattrs; 341 struct iattr newattrs;
342 int rc; 342 int rc;
343 343
344 sd = kernfs_find_and_get(kobj->sd, attr->name); 344 kn = kernfs_find_and_get(kobj->sd, attr->name);
345 if (!sd) 345 if (!kn)
346 return -ENOENT; 346 return -ENOENT;
347 347
348 newattrs.ia_mode = (mode & S_IALLUGO) | (sd->s_mode & ~S_IALLUGO); 348 newattrs.ia_mode = (mode & S_IALLUGO) | (kn->s_mode & ~S_IALLUGO);
349 newattrs.ia_valid = ATTR_MODE; 349 newattrs.ia_valid = ATTR_MODE;
350 350
351 rc = kernfs_setattr(sd, &newattrs); 351 rc = kernfs_setattr(kn, &newattrs);
352 352
353 kernfs_put(sd); 353 kernfs_put(kn);
354 return rc; 354 return rc;
355} 355}
356EXPORT_SYMBOL_GPL(sysfs_chmod_file); 356EXPORT_SYMBOL_GPL(sysfs_chmod_file);
@@ -366,9 +366,9 @@ EXPORT_SYMBOL_GPL(sysfs_chmod_file);
366void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, 366void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr,
367 const void *ns) 367 const void *ns)
368{ 368{
369 struct sysfs_dirent *dir_sd = kobj->sd; 369 struct kernfs_node *parent = kobj->sd;
370 370
371 kernfs_remove_by_name_ns(dir_sd, attr->name, ns); 371 kernfs_remove_by_name_ns(parent, attr->name, ns);
372} 372}
373EXPORT_SYMBOL_GPL(sysfs_remove_file_ns); 373EXPORT_SYMBOL_GPL(sysfs_remove_file_ns);
374 374
@@ -389,18 +389,18 @@ EXPORT_SYMBOL_GPL(sysfs_remove_files);
389void sysfs_remove_file_from_group(struct kobject *kobj, 389void sysfs_remove_file_from_group(struct kobject *kobj,
390 const struct attribute *attr, const char *group) 390 const struct attribute *attr, const char *group)
391{ 391{
392 struct sysfs_dirent *dir_sd; 392 struct kernfs_node *parent;
393 393
394 if (group) { 394 if (group) {
395 dir_sd = kernfs_find_and_get(kobj->sd, group); 395 parent = kernfs_find_and_get(kobj->sd, group);
396 } else { 396 } else {
397 dir_sd = kobj->sd; 397 parent = kobj->sd;
398 kernfs_get(dir_sd); 398 kernfs_get(parent);
399 } 399 }
400 400
401 if (dir_sd) { 401 if (parent) {
402 kernfs_remove_by_name(dir_sd, attr->name); 402 kernfs_remove_by_name(parent, attr->name);
403 kernfs_put(dir_sd); 403 kernfs_put(parent);
404 } 404 }
405} 405}
406EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group); 406EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 7177532b8f7b..4d00d3996477 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -18,7 +18,7 @@
18#include "sysfs.h" 18#include "sysfs.h"
19 19
20 20
21static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 21static void remove_files(struct kernfs_node *parent, struct kobject *kobj,
22 const struct attribute_group *grp) 22 const struct attribute_group *grp)
23{ 23{
24 struct attribute *const *attr; 24 struct attribute *const *attr;
@@ -26,13 +26,13 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
26 26
27 if (grp->attrs) 27 if (grp->attrs)
28 for (attr = grp->attrs; *attr; attr++) 28 for (attr = grp->attrs; *attr; attr++)
29 kernfs_remove_by_name(dir_sd, (*attr)->name); 29 kernfs_remove_by_name(parent, (*attr)->name);
30 if (grp->bin_attrs) 30 if (grp->bin_attrs)
31 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) 31 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++)
32 sysfs_remove_bin_file(kobj, *bin_attr); 32 sysfs_remove_bin_file(kobj, *bin_attr);
33} 33}
34 34
35static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 35static int create_files(struct kernfs_node *parent, struct kobject *kobj,
36 const struct attribute_group *grp, int update) 36 const struct attribute_group *grp, int update)
37{ 37{
38 struct attribute *const *attr; 38 struct attribute *const *attr;
@@ -49,20 +49,20 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
49 * re-adding (if required) the file. 49 * re-adding (if required) the file.
50 */ 50 */
51 if (update) 51 if (update)
52 kernfs_remove_by_name(dir_sd, (*attr)->name); 52 kernfs_remove_by_name(parent, (*attr)->name);
53 if (grp->is_visible) { 53 if (grp->is_visible) {
54 mode = grp->is_visible(kobj, *attr, i); 54 mode = grp->is_visible(kobj, *attr, i);
55 if (!mode) 55 if (!mode)
56 continue; 56 continue;
57 } 57 }
58 error = sysfs_add_file_mode_ns(dir_sd, *attr, false, 58 error = sysfs_add_file_mode_ns(parent, *attr, false,
59 (*attr)->mode | mode, 59 (*attr)->mode | mode,
60 NULL); 60 NULL);
61 if (unlikely(error)) 61 if (unlikely(error))
62 break; 62 break;
63 } 63 }
64 if (error) { 64 if (error) {
65 remove_files(dir_sd, kobj, grp); 65 remove_files(parent, kobj, grp);
66 goto exit; 66 goto exit;
67 } 67 }
68 } 68 }
@@ -76,7 +76,7 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj,
76 break; 76 break;
77 } 77 }
78 if (error) 78 if (error)
79 remove_files(dir_sd, kobj, grp); 79 remove_files(parent, kobj, grp);
80 } 80 }
81exit: 81exit:
82 return error; 82 return error;
@@ -86,7 +86,7 @@ exit:
86static int internal_create_group(struct kobject *kobj, int update, 86static int internal_create_group(struct kobject *kobj, int update,
87 const struct attribute_group *grp) 87 const struct attribute_group *grp)
88{ 88{
89 struct sysfs_dirent *sd; 89 struct kernfs_node *kn;
90 int error; 90 int error;
91 91
92 BUG_ON(!kobj || (!update && !kobj->sd)); 92 BUG_ON(!kobj || (!update && !kobj->sd));
@@ -100,21 +100,21 @@ static int internal_create_group(struct kobject *kobj, int update,
100 return -EINVAL; 100 return -EINVAL;
101 } 101 }
102 if (grp->name) { 102 if (grp->name) {
103 sd = kernfs_create_dir(kobj->sd, grp->name, kobj); 103 kn = kernfs_create_dir(kobj->sd, grp->name, kobj);
104 if (IS_ERR(sd)) { 104 if (IS_ERR(kn)) {
105 if (PTR_ERR(sd) == -EEXIST) 105 if (PTR_ERR(kn) == -EEXIST)
106 sysfs_warn_dup(kobj->sd, grp->name); 106 sysfs_warn_dup(kobj->sd, grp->name);
107 return PTR_ERR(sd); 107 return PTR_ERR(kn);
108 } 108 }
109 } else 109 } else
110 sd = kobj->sd; 110 kn = kobj->sd;
111 kernfs_get(sd); 111 kernfs_get(kn);
112 error = create_files(sd, kobj, grp, update); 112 error = create_files(kn, kobj, grp, update);
113 if (error) { 113 if (error) {
114 if (grp->name) 114 if (grp->name)
115 kernfs_remove(sd); 115 kernfs_remove(kn);
116 } 116 }
117 kernfs_put(sd); 117 kernfs_put(kn);
118 return error; 118 return error;
119} 119}
120 120
@@ -204,27 +204,27 @@ EXPORT_SYMBOL_GPL(sysfs_update_group);
204void sysfs_remove_group(struct kobject *kobj, 204void sysfs_remove_group(struct kobject *kobj,
205 const struct attribute_group *grp) 205 const struct attribute_group *grp)
206{ 206{
207 struct sysfs_dirent *dir_sd = kobj->sd; 207 struct kernfs_node *parent = kobj->sd;
208 struct sysfs_dirent *sd; 208 struct kernfs_node *kn;
209 209
210 if (grp->name) { 210 if (grp->name) {
211 sd = kernfs_find_and_get(dir_sd, grp->name); 211 kn = kernfs_find_and_get(parent, grp->name);
212 if (!sd) { 212 if (!kn) {
213 WARN(!sd, KERN_WARNING 213 WARN(!kn, KERN_WARNING
214 "sysfs group %p not found for kobject '%s'\n", 214 "sysfs group %p not found for kobject '%s'\n",
215 grp, kobject_name(kobj)); 215 grp, kobject_name(kobj));
216 return; 216 return;
217 } 217 }
218 } else { 218 } else {
219 sd = dir_sd; 219 kn = parent;
220 kernfs_get(sd); 220 kernfs_get(kn);
221 } 221 }
222 222
223 remove_files(sd, kobj, grp); 223 remove_files(kn, kobj, grp);
224 if (grp->name) 224 if (grp->name)
225 kernfs_remove(sd); 225 kernfs_remove(kn);
226 226
227 kernfs_put(sd); 227 kernfs_put(kn);
228} 228}
229EXPORT_SYMBOL_GPL(sysfs_remove_group); 229EXPORT_SYMBOL_GPL(sysfs_remove_group);
230 230
@@ -260,22 +260,22 @@ EXPORT_SYMBOL_GPL(sysfs_remove_groups);
260int sysfs_merge_group(struct kobject *kobj, 260int sysfs_merge_group(struct kobject *kobj,
261 const struct attribute_group *grp) 261 const struct attribute_group *grp)
262{ 262{
263 struct sysfs_dirent *dir_sd; 263 struct kernfs_node *parent;
264 int error = 0; 264 int error = 0;
265 struct attribute *const *attr; 265 struct attribute *const *attr;
266 int i; 266 int i;
267 267
268 dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 268 parent = kernfs_find_and_get(kobj->sd, grp->name);
269 if (!dir_sd) 269 if (!parent)
270 return -ENOENT; 270 return -ENOENT;
271 271
272 for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) 272 for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr))
273 error = sysfs_add_file(dir_sd, *attr, false); 273 error = sysfs_add_file(parent, *attr, false);
274 if (error) { 274 if (error) {
275 while (--i >= 0) 275 while (--i >= 0)
276 kernfs_remove_by_name(dir_sd, (*--attr)->name); 276 kernfs_remove_by_name(parent, (*--attr)->name);
277 } 277 }
278 kernfs_put(dir_sd); 278 kernfs_put(parent);
279 279
280 return error; 280 return error;
281} 281}
@@ -289,14 +289,14 @@ EXPORT_SYMBOL_GPL(sysfs_merge_group);
289void sysfs_unmerge_group(struct kobject *kobj, 289void sysfs_unmerge_group(struct kobject *kobj,
290 const struct attribute_group *grp) 290 const struct attribute_group *grp)
291{ 291{
292 struct sysfs_dirent *dir_sd; 292 struct kernfs_node *parent;
293 struct attribute *const *attr; 293 struct attribute *const *attr;
294 294
295 dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 295 parent = kernfs_find_and_get(kobj->sd, grp->name);
296 if (dir_sd) { 296 if (parent) {
297 for (attr = grp->attrs; *attr; ++attr) 297 for (attr = grp->attrs; *attr; ++attr)
298 kernfs_remove_by_name(dir_sd, (*attr)->name); 298 kernfs_remove_by_name(parent, (*attr)->name);
299 kernfs_put(dir_sd); 299 kernfs_put(parent);
300 } 300 }
301} 301}
302EXPORT_SYMBOL_GPL(sysfs_unmerge_group); 302EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
@@ -311,15 +311,15 @@ EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
311int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, 311int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
312 struct kobject *target, const char *link_name) 312 struct kobject *target, const char *link_name)
313{ 313{
314 struct sysfs_dirent *dir_sd; 314 struct kernfs_node *parent;
315 int error = 0; 315 int error = 0;
316 316
317 dir_sd = kernfs_find_and_get(kobj->sd, group_name); 317 parent = kernfs_find_and_get(kobj->sd, group_name);
318 if (!dir_sd) 318 if (!parent)
319 return -ENOENT; 319 return -ENOENT;
320 320
321 error = sysfs_create_link_sd(dir_sd, target, link_name); 321 error = sysfs_create_link_sd(parent, target, link_name);
322 kernfs_put(dir_sd); 322 kernfs_put(parent);
323 323
324 return error; 324 return error;
325} 325}
@@ -334,12 +334,12 @@ EXPORT_SYMBOL_GPL(sysfs_add_link_to_group);
334void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, 334void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
335 const char *link_name) 335 const char *link_name)
336{ 336{
337 struct sysfs_dirent *dir_sd; 337 struct kernfs_node *parent;
338 338
339 dir_sd = kernfs_find_and_get(kobj->sd, group_name); 339 parent = kernfs_find_and_get(kobj->sd, group_name);
340 if (dir_sd) { 340 if (parent) {
341 kernfs_remove_by_name(dir_sd, link_name); 341 kernfs_remove_by_name(parent, link_name);
342 kernfs_put(dir_sd); 342 kernfs_put(parent);
343 } 343 }
344} 344}
345EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); 345EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 8d075272cace..701a56f341c6 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -20,7 +20,7 @@
20#include "sysfs.h" 20#include "sysfs.h"
21 21
22static struct kernfs_root *sysfs_root; 22static struct kernfs_root *sysfs_root;
23struct sysfs_dirent *sysfs_root_sd; 23struct kernfs_node *sysfs_root_kn;
24 24
25static struct dentry *sysfs_mount(struct file_system_type *fs_type, 25static struct dentry *sysfs_mount(struct file_system_type *fs_type,
26 int flags, const char *dev_name, void *data) 26 int flags, const char *dev_name, void *data)
@@ -66,7 +66,7 @@ int __init sysfs_init(void)
66 if (IS_ERR(sysfs_root)) 66 if (IS_ERR(sysfs_root))
67 return PTR_ERR(sysfs_root); 67 return PTR_ERR(sysfs_root);
68 68
69 sysfs_root_sd = sysfs_root->sd; 69 sysfs_root_kn = sysfs_root->kn;
70 70
71 err = register_filesystem(&sysfs_fs_type); 71 err = register_filesystem(&sysfs_fs_type);
72 if (err) { 72 if (err) {
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 1b8c9ed8511a..4ed3d49ad279 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -18,66 +18,66 @@
18 18
19#include "sysfs.h" 19#include "sysfs.h"
20 20
21static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd, 21static int sysfs_do_create_link_sd(struct kernfs_node *parent,
22 struct kobject *target, 22 struct kobject *target_kobj,
23 const char *name, int warn) 23 const char *name, int warn)
24{ 24{
25 struct sysfs_dirent *sd, *target_sd = NULL; 25 struct kernfs_node *kn, *target = NULL;
26 26
27 BUG_ON(!name || !parent_sd); 27 BUG_ON(!name || !parent);
28 28
29 /* 29 /*
30 * We don't own @target and it may be removed at any time. 30 * We don't own @target_kobj and it may be removed at any time.
31 * Synchronize using sysfs_symlink_target_lock. See 31 * Synchronize using sysfs_symlink_target_lock. See
32 * sysfs_remove_dir() for details. 32 * sysfs_remove_dir() for details.
33 */ 33 */
34 spin_lock(&sysfs_symlink_target_lock); 34 spin_lock(&sysfs_symlink_target_lock);
35 if (target->sd) { 35 if (target_kobj->sd) {
36 target_sd = target->sd; 36 target = target_kobj->sd;
37 kernfs_get(target_sd); 37 kernfs_get(target);
38 } 38 }
39 spin_unlock(&sysfs_symlink_target_lock); 39 spin_unlock(&sysfs_symlink_target_lock);
40 40
41 if (!target_sd) 41 if (!target)
42 return -ENOENT; 42 return -ENOENT;
43 43
44 sd = kernfs_create_link(parent_sd, name, target_sd); 44 kn = kernfs_create_link(parent, name, target);
45 kernfs_put(target_sd); 45 kernfs_put(target);
46 46
47 if (!IS_ERR(sd)) 47 if (!IS_ERR(kn))
48 return 0; 48 return 0;
49 49
50 if (warn && PTR_ERR(sd) == -EEXIST) 50 if (warn && PTR_ERR(kn) == -EEXIST)
51 sysfs_warn_dup(parent_sd, name); 51 sysfs_warn_dup(parent, name);
52 return PTR_ERR(sd); 52 return PTR_ERR(kn);
53} 53}
54 54
55/** 55/**
56 * sysfs_create_link_sd - create symlink to a given object. 56 * sysfs_create_link_sd - create symlink to a given object.
57 * @sd: directory we're creating the link in. 57 * @kn: directory we're creating the link in.
58 * @target: object we're pointing to. 58 * @target: object we're pointing to.
59 * @name: name of the symlink. 59 * @name: name of the symlink.
60 */ 60 */
61int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, 61int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target,
62 const char *name) 62 const char *name)
63{ 63{
64 return sysfs_do_create_link_sd(sd, target, name, 1); 64 return sysfs_do_create_link_sd(kn, target, name, 1);
65} 65}
66 66
67static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target, 67static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
68 const char *name, int warn) 68 const char *name, int warn)
69{ 69{
70 struct sysfs_dirent *parent_sd = NULL; 70 struct kernfs_node *parent = NULL;
71 71
72 if (!kobj) 72 if (!kobj)
73 parent_sd = sysfs_root_sd; 73 parent = sysfs_root_kn;
74 else 74 else
75 parent_sd = kobj->sd; 75 parent = kobj->sd;
76 76
77 if (!parent_sd) 77 if (!parent)
78 return -EFAULT; 78 return -EFAULT;
79 79
80 return sysfs_do_create_link_sd(parent_sd, target, name, warn); 80 return sysfs_do_create_link_sd(parent, target, name, warn);
81} 81}
82 82
83/** 83/**
@@ -141,14 +141,14 @@ void sysfs_delete_link(struct kobject *kobj, struct kobject *targ,
141 */ 141 */
142void sysfs_remove_link(struct kobject *kobj, const char *name) 142void sysfs_remove_link(struct kobject *kobj, const char *name)
143{ 143{
144 struct sysfs_dirent *parent_sd = NULL; 144 struct kernfs_node *parent = NULL;
145 145
146 if (!kobj) 146 if (!kobj)
147 parent_sd = sysfs_root_sd; 147 parent = sysfs_root_kn;
148 else 148 else
149 parent_sd = kobj->sd; 149 parent = kobj->sd;
150 150
151 kernfs_remove_by_name(parent_sd, name); 151 kernfs_remove_by_name(parent, name);
152} 152}
153EXPORT_SYMBOL_GPL(sysfs_remove_link); 153EXPORT_SYMBOL_GPL(sysfs_remove_link);
154 154
@@ -165,33 +165,33 @@ EXPORT_SYMBOL_GPL(sysfs_remove_link);
165int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ, 165int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ,
166 const char *old, const char *new, const void *new_ns) 166 const char *old, const char *new, const void *new_ns)
167{ 167{
168 struct sysfs_dirent *parent_sd, *sd = NULL; 168 struct kernfs_node *parent, *kn = NULL;
169 const void *old_ns = NULL; 169 const void *old_ns = NULL;
170 int result; 170 int result;
171 171
172 if (!kobj) 172 if (!kobj)
173 parent_sd = sysfs_root_sd; 173 parent = sysfs_root_kn;
174 else 174 else
175 parent_sd = kobj->sd; 175 parent = kobj->sd;
176 176
177 if (targ->sd) 177 if (targ->sd)
178 old_ns = targ->sd->s_ns; 178 old_ns = targ->sd->s_ns;
179 179
180 result = -ENOENT; 180 result = -ENOENT;
181 sd = kernfs_find_and_get_ns(parent_sd, old, old_ns); 181 kn = kernfs_find_and_get_ns(parent, old, old_ns);
182 if (!sd) 182 if (!kn)
183 goto out; 183 goto out;
184 184
185 result = -EINVAL; 185 result = -EINVAL;
186 if (sysfs_type(sd) != SYSFS_KOBJ_LINK) 186 if (sysfs_type(kn) != SYSFS_KOBJ_LINK)
187 goto out; 187 goto out;
188 if (sd->s_symlink.target_sd->priv != targ) 188 if (kn->s_symlink.target_kn->priv != targ)
189 goto out; 189 goto out;
190 190
191 result = kernfs_rename_ns(sd, parent_sd, new, new_ns); 191 result = kernfs_rename_ns(kn, parent, new, new_ns);
192 192
193out: 193out:
194 kernfs_put(sd); 194 kernfs_put(kn);
195 return result; 195 return result;
196} 196}
197EXPORT_SYMBOL_GPL(sysfs_rename_link_ns); 197EXPORT_SYMBOL_GPL(sysfs_rename_link_ns);
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index c8e395b49330..0e2f1cccb812 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -16,28 +16,28 @@
16/* 16/*
17 * mount.c 17 * mount.c
18 */ 18 */
19extern struct sysfs_dirent *sysfs_root_sd; 19extern struct kernfs_node *sysfs_root_kn;
20 20
21/* 21/*
22 * dir.c 22 * dir.c
23 */ 23 */
24extern spinlock_t sysfs_symlink_target_lock; 24extern spinlock_t sysfs_symlink_target_lock;
25 25
26void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name); 26void sysfs_warn_dup(struct kernfs_node *parent, const char *name);
27 27
28/* 28/*
29 * file.c 29 * file.c
30 */ 30 */
31int sysfs_add_file(struct sysfs_dirent *dir_sd, 31int sysfs_add_file(struct kernfs_node *parent,
32 const struct attribute *attr, bool is_bin); 32 const struct attribute *attr, bool is_bin);
33int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, 33int sysfs_add_file_mode_ns(struct kernfs_node *parent,
34 const struct attribute *attr, bool is_bin, 34 const struct attribute *attr, bool is_bin,
35 umode_t amode, const void *ns); 35 umode_t amode, const void *ns);
36 36
37/* 37/*
38 * symlink.c 38 * symlink.c
39 */ 39 */
40int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, 40int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target,
41 const char *name); 41 const char *name);
42 42
43#endif /* __SYSFS_INTERNAL_H */ 43#endif /* __SYSFS_INTERNAL_H */
diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
index d65541308419..195d1c6a8b0c 100644
--- a/include/linux/kernfs.h
+++ b/include/linux/kernfs.h
@@ -46,61 +46,61 @@ enum kernfs_node_flag {
46 SYSFS_FLAG_LOCKDEP = 0x0100, 46 SYSFS_FLAG_LOCKDEP = 0x0100,
47}; 47};
48 48
49/* type-specific structures for sysfs_dirent->s_* union members */ 49/* type-specific structures for kernfs_node union members */
50struct sysfs_elem_dir { 50struct kernfs_elem_dir {
51 unsigned long subdirs; 51 unsigned long subdirs;
52 /* children rbtree starts here and goes through sd->s_rb */ 52 /* children rbtree starts here and goes through kn->s_rb */
53 struct rb_root children; 53 struct rb_root children;
54 54
55 /* 55 /*
56 * The kernfs hierarchy this directory belongs to. This fits 56 * The kernfs hierarchy this directory belongs to. This fits
57 * better directly in sysfs_dirent but is here to save space. 57 * better directly in kernfs_node but is here to save space.
58 */ 58 */
59 struct kernfs_root *root; 59 struct kernfs_root *root;
60}; 60};
61 61
62struct sysfs_elem_symlink { 62struct kernfs_elem_symlink {
63 struct sysfs_dirent *target_sd; 63 struct kernfs_node *target_kn;
64}; 64};
65 65
66struct sysfs_elem_attr { 66struct kernfs_elem_attr {
67 const struct kernfs_ops *ops; 67 const struct kernfs_ops *ops;
68 struct sysfs_open_dirent *open; 68 struct sysfs_open_dirent *open;
69 loff_t size; 69 loff_t size;
70}; 70};
71 71
72/* 72/*
73 * sysfs_dirent - the building block of sysfs hierarchy. Each and every 73 * kernfs_node - the building block of kernfs hierarchy. Each and every
74 * sysfs node is represented by single sysfs_dirent. Most fields are 74 * kernfs node is represented by single kernfs_node. Most fields are
75 * private to kernfs and shouldn't be accessed directly by kernfs users. 75 * private to kernfs and shouldn't be accessed directly by kernfs users.
76 * 76 *
77 * As long as s_count reference is held, the sysfs_dirent itself is 77 * As long as s_count reference is held, the kernfs_node itself is
78 * accessible. Dereferencing s_elem or any other outer entity 78 * accessible. Dereferencing elem or any other outer entity requires
79 * requires s_active reference. 79 * active reference.
80 */ 80 */
81struct sysfs_dirent { 81struct kernfs_node {
82 atomic_t s_count; 82 atomic_t s_count;
83 atomic_t s_active; 83 atomic_t s_active;
84#ifdef CONFIG_DEBUG_LOCK_ALLOC 84#ifdef CONFIG_DEBUG_LOCK_ALLOC
85 struct lockdep_map dep_map; 85 struct lockdep_map dep_map;
86#endif 86#endif
87 /* the following two fields are published */ 87 /* the following two fields are published */
88 struct sysfs_dirent *s_parent; 88 struct kernfs_node *s_parent;
89 const char *s_name; 89 const char *s_name;
90 90
91 struct rb_node s_rb; 91 struct rb_node s_rb;
92 92
93 union { 93 union {
94 struct completion *completion; 94 struct completion *completion;
95 struct sysfs_dirent *removed_list; 95 struct kernfs_node *removed_list;
96 } u; 96 } u;
97 97
98 const void *s_ns; /* namespace tag */ 98 const void *s_ns; /* namespace tag */
99 unsigned int s_hash; /* ns + name hash */ 99 unsigned int s_hash; /* ns + name hash */
100 union { 100 union {
101 struct sysfs_elem_dir s_dir; 101 struct kernfs_elem_dir s_dir;
102 struct sysfs_elem_symlink s_symlink; 102 struct kernfs_elem_symlink s_symlink;
103 struct sysfs_elem_attr s_attr; 103 struct kernfs_elem_attr s_attr;
104 }; 104 };
105 105
106 void *priv; 106 void *priv;
@@ -113,7 +113,7 @@ struct sysfs_dirent {
113 113
114struct kernfs_root { 114struct kernfs_root {
115 /* published fields */ 115 /* published fields */
116 struct sysfs_dirent *sd; 116 struct kernfs_node *kn;
117 117
118 /* private fields, do not use outside kernfs proper */ 118 /* private fields, do not use outside kernfs proper */
119 struct ida ino_ida; 119 struct ida ino_ida;
@@ -121,7 +121,7 @@ struct kernfs_root {
121 121
122struct sysfs_open_file { 122struct sysfs_open_file {
123 /* published fields */ 123 /* published fields */
124 struct sysfs_dirent *sd; 124 struct kernfs_node *kn;
125 struct file *file; 125 struct file *file;
126 126
127 /* private fields, do not use outside kernfs proper */ 127 /* private fields, do not use outside kernfs proper */
@@ -170,64 +170,64 @@ struct kernfs_ops {
170 170
171#ifdef CONFIG_SYSFS 171#ifdef CONFIG_SYSFS
172 172
173static inline enum kernfs_node_type sysfs_type(struct sysfs_dirent *sd) 173static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
174{ 174{
175 return sd->s_flags & SYSFS_TYPE_MASK; 175 return kn->s_flags & SYSFS_TYPE_MASK;
176} 176}
177 177
178/** 178/**
179 * kernfs_enable_ns - enable namespace under a directory 179 * kernfs_enable_ns - enable namespace under a directory
180 * @sd: directory of interest, should be empty 180 * @kn: directory of interest, should be empty
181 * 181 *
182 * This is to be called right after @sd is created to enable namespace 182 * This is to be called right after @kn is created to enable namespace
183 * under it. All children of @sd must have non-NULL namespace tags and 183 * under it. All children of @kn must have non-NULL namespace tags and
184 * only the ones which match the super_block's tag will be visible. 184 * only the ones which match the super_block's tag will be visible.
185 */ 185 */
186static inline void kernfs_enable_ns(struct sysfs_dirent *sd) 186static inline void kernfs_enable_ns(struct kernfs_node *kn)
187{ 187{
188 WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); 188 WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR);
189 WARN_ON_ONCE(!RB_EMPTY_ROOT(&sd->s_dir.children)); 189 WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->s_dir.children));
190 sd->s_flags |= SYSFS_FLAG_NS; 190 kn->s_flags |= SYSFS_FLAG_NS;
191} 191}
192 192
193/** 193/**
194 * kernfs_ns_enabled - test whether namespace is enabled 194 * kernfs_ns_enabled - test whether namespace is enabled
195 * @sd: the node to test 195 * @kn: the node to test
196 * 196 *
197 * Test whether namespace filtering is enabled for the children of @ns. 197 * Test whether namespace filtering is enabled for the children of @ns.
198 */ 198 */
199static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd) 199static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
200{ 200{
201 return sd->s_flags & SYSFS_FLAG_NS; 201 return kn->s_flags & SYSFS_FLAG_NS;
202} 202}
203 203
204struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, 204struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
205 const char *name, const void *ns); 205 const char *name, const void *ns);
206void kernfs_get(struct sysfs_dirent *sd); 206void kernfs_get(struct kernfs_node *kn);
207void kernfs_put(struct sysfs_dirent *sd); 207void kernfs_put(struct kernfs_node *kn);
208 208
209struct kernfs_root *kernfs_create_root(void *priv); 209struct kernfs_root *kernfs_create_root(void *priv);
210void kernfs_destroy_root(struct kernfs_root *root); 210void kernfs_destroy_root(struct kernfs_root *root);
211 211
212struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, 212struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
213 const char *name, void *priv, 213 const char *name, void *priv,
214 const void *ns); 214 const void *ns);
215struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, 215struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
216 const char *name, 216 const char *name,
217 umode_t mode, loff_t size, 217 umode_t mode, loff_t size,
218 const struct kernfs_ops *ops, 218 const struct kernfs_ops *ops,
219 void *priv, const void *ns, 219 void *priv, const void *ns,
220 struct lock_class_key *key); 220 struct lock_class_key *key);
221struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, 221struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
222 const char *name, 222 const char *name,
223 struct sysfs_dirent *target); 223 struct kernfs_node *target);
224void kernfs_remove(struct sysfs_dirent *sd); 224void kernfs_remove(struct kernfs_node *kn);
225int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name, 225int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
226 const void *ns); 226 const void *ns);
227int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, 227int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
228 const char *new_name, const void *new_ns); 228 const char *new_name, const void *new_ns);
229int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr); 229int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
230void kernfs_notify(struct sysfs_dirent *sd); 230void kernfs_notify(struct kernfs_node *kn);
231 231
232const void *kernfs_super_ns(struct super_block *sb); 232const void *kernfs_super_ns(struct super_block *sb);
233struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, 233struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
@@ -238,60 +238,60 @@ void kernfs_init(void);
238 238
239#else /* CONFIG_SYSFS */ 239#else /* CONFIG_SYSFS */
240 240
241static inline enum kernfs_node_type sysfs_type(struct sysfs_dirent *sd) 241static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn)
242{ return 0; } /* whatever */ 242{ return 0; } /* whatever */
243 243
244static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { } 244static inline void kernfs_enable_ns(struct kernfs_node *kn) { }
245 245
246static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd) 246static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
247{ return false; } 247{ return false; }
248 248
249static inline struct sysfs_dirent * 249static inline struct kernfs_node *
250kernfs_find_and_get_ns(struct sysfs_dirent *parent, const char *name, 250kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
251 const void *ns) 251 const void *ns)
252{ return NULL; } 252{ return NULL; }
253 253
254static inline void kernfs_get(struct sysfs_dirent *sd) { } 254static inline void kernfs_get(struct kernfs_node *kn) { }
255static inline void kernfs_put(struct sysfs_dirent *sd) { } 255static inline void kernfs_put(struct kernfs_node *kn) { }
256 256
257static inline struct kernfs_root *kernfs_create_root(void *priv) 257static inline struct kernfs_root *kernfs_create_root(void *priv)
258{ return ERR_PTR(-ENOSYS); } 258{ return ERR_PTR(-ENOSYS); }
259 259
260static inline void kernfs_destroy_root(struct kernfs_root *root) { } 260static inline void kernfs_destroy_root(struct kernfs_root *root) { }
261 261
262static inline struct sysfs_dirent * 262static inline struct kernfs_node *
263kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv, 263kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, void *priv,
264 const void *ns) 264 const void *ns)
265{ return ERR_PTR(-ENOSYS); } 265{ return ERR_PTR(-ENOSYS); }
266 266
267static inline struct sysfs_dirent * 267static inline struct kernfs_node *
268kernfs_create_file_ns_key(struct sysfs_dirent *parent, const char *name, 268kernfs_create_file_ns_key(struct kernfs_node *parent, const char *name,
269 umode_t mode, loff_t size, 269 umode_t mode, loff_t size,
270 const struct kernfs_ops *ops, void *priv, 270 const struct kernfs_ops *ops, void *priv,
271 const void *ns, struct lock_class_key *key) 271 const void *ns, struct lock_class_key *key)
272{ return ERR_PTR(-ENOSYS); } 272{ return ERR_PTR(-ENOSYS); }
273 273
274static inline struct sysfs_dirent * 274static inline struct kernfs_node *
275kernfs_create_link(struct sysfs_dirent *parent, const char *name, 275kernfs_create_link(struct kernfs_node *parent, const char *name,
276 struct sysfs_dirent *target) 276 struct kernfs_node *target)
277{ return ERR_PTR(-ENOSYS); } 277{ return ERR_PTR(-ENOSYS); }
278 278
279static inline void kernfs_remove(struct sysfs_dirent *sd) { } 279static inline void kernfs_remove(struct kernfs_node *kn) { }
280 280
281static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, 281static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn,
282 const char *name, const void *ns) 282 const char *name, const void *ns)
283{ return -ENOSYS; } 283{ return -ENOSYS; }
284 284
285static inline int kernfs_rename_ns(struct sysfs_dirent *sd, 285static inline int kernfs_rename_ns(struct kernfs_node *kn,
286 struct sysfs_dirent *new_parent, 286 struct kernfs_node *new_parent,
287 const char *new_name, const void *new_ns) 287 const char *new_name, const void *new_ns)
288{ return -ENOSYS; } 288{ return -ENOSYS; }
289 289
290static inline int kernfs_setattr(struct sysfs_dirent *sd, 290static inline int kernfs_setattr(struct kernfs_node *kn,
291 const struct iattr *iattr) 291 const struct iattr *iattr)
292{ return -ENOSYS; } 292{ return -ENOSYS; }
293 293
294static inline void kernfs_notify(struct sysfs_dirent *sd) { } 294static inline void kernfs_notify(struct kernfs_node *kn) { }
295 295
296static inline const void *kernfs_super_ns(struct super_block *sb) 296static inline const void *kernfs_super_ns(struct super_block *sb)
297{ return NULL; } 297{ return NULL; }
@@ -307,20 +307,20 @@ static inline void kernfs_init(void) { }
307 307
308#endif /* CONFIG_SYSFS */ 308#endif /* CONFIG_SYSFS */
309 309
310static inline struct sysfs_dirent * 310static inline struct kernfs_node *
311kernfs_find_and_get(struct sysfs_dirent *sd, const char *name) 311kernfs_find_and_get(struct kernfs_node *kn, const char *name)
312{ 312{
313 return kernfs_find_and_get_ns(sd, name, NULL); 313 return kernfs_find_and_get_ns(kn, name, NULL);
314} 314}
315 315
316static inline struct sysfs_dirent * 316static inline struct kernfs_node *
317kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv) 317kernfs_create_dir(struct kernfs_node *parent, const char *name, void *priv)
318{ 318{
319 return kernfs_create_dir_ns(parent, name, priv, NULL); 319 return kernfs_create_dir_ns(parent, name, priv, NULL);
320} 320}
321 321
322static inline struct sysfs_dirent * 322static inline struct kernfs_node *
323kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name, 323kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
324 umode_t mode, loff_t size, const struct kernfs_ops *ops, 324 umode_t mode, loff_t size, const struct kernfs_ops *ops,
325 void *priv, const void *ns) 325 void *priv, const void *ns)
326{ 326{
@@ -333,14 +333,14 @@ kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name,
333 ns, key); 333 ns, key);
334} 334}
335 335
336static inline struct sysfs_dirent * 336static inline struct kernfs_node *
337kernfs_create_file(struct sysfs_dirent *parent, const char *name, umode_t mode, 337kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode,
338 loff_t size, const struct kernfs_ops *ops, void *priv) 338 loff_t size, const struct kernfs_ops *ops, void *priv)
339{ 339{
340 return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL); 340 return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL);
341} 341}
342 342
343static inline int kernfs_remove_by_name(struct sysfs_dirent *parent, 343static inline int kernfs_remove_by_name(struct kernfs_node *parent,
344 const char *name) 344 const char *name)
345{ 345{
346 return kernfs_remove_by_name_ns(parent, name, NULL); 346 return kernfs_remove_by_name_ns(parent, name, NULL);
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index e7ba650086ce..926afb6f6b5f 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -64,7 +64,7 @@ struct kobject {
64 struct kobject *parent; 64 struct kobject *parent;
65 struct kset *kset; 65 struct kset *kset;
66 struct kobj_type *ktype; 66 struct kobj_type *ktype;
67 struct sysfs_dirent *sd; 67 struct kernfs_node *sd;
68 struct kref kref; 68 struct kref kref;
69#ifdef CONFIG_DEBUG_KOBJECT_RELEASE 69#ifdef CONFIG_DEBUG_KOBJECT_RELEASE
70 struct delayed_work release; 70 struct delayed_work release;
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index cd8f90bf51a7..30b2ebee6439 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -438,26 +438,26 @@ static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target
438 return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL); 438 return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL);
439} 439}
440 440
441static inline void sysfs_notify_dirent(struct sysfs_dirent *sd) 441static inline void sysfs_notify_dirent(struct kernfs_node *kn)
442{ 442{
443 kernfs_notify(sd); 443 kernfs_notify(kn);
444} 444}
445 445
446static inline struct sysfs_dirent * 446static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent,
447sysfs_get_dirent(struct sysfs_dirent *parent_sd, const unsigned char *name) 447 const unsigned char *name)
448{ 448{
449 return kernfs_find_and_get(parent_sd, name); 449 return kernfs_find_and_get(parent, name);
450} 450}
451 451
452static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) 452static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn)
453{ 453{
454 kernfs_get(sd); 454 kernfs_get(kn);
455 return sd; 455 return kn;
456} 456}
457 457
458static inline void sysfs_put(struct sysfs_dirent *sd) 458static inline void sysfs_put(struct kernfs_node *kn)
459{ 459{
460 kernfs_put(sd); 460 kernfs_put(kn);
461} 461}
462 462
463#endif /* _SYSFS_H_ */ 463#endif /* _SYSFS_H_ */
diff --git a/lib/kobject.c b/lib/kobject.c
index 94b321f4ac67..064451f2a6c3 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -556,7 +556,7 @@ out:
556 */ 556 */
557void kobject_del(struct kobject *kobj) 557void kobject_del(struct kobject *kobj)
558{ 558{
559 struct sysfs_dirent *sd; 559 struct kernfs_node *sd;
560 560
561 if (!kobj) 561 if (!kobj)
562 return; 562 return;