Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Tejun Heo and committed by
Greg Kroah-Hartman
324a56e1 a8b1c019

+773 -772
+2 -2
drivers/gpio/gpiolib.c
··· 393 393 394 394 static 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 398 sysfs_notify_dirent(value_sd); 399 399 return IRQ_HANDLED; ··· 402 402 static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, 403 403 unsigned long gpio_flags) 404 404 { 405 - struct sysfs_dirent *value_sd; 405 + struct kernfs_node *value_sd; 406 406 unsigned long irq_flags; 407 407 int ret, irq, id; 408 408
+1 -1
drivers/md/bitmap.c
··· 1635 1635 sector_t blocks = mddev->resync_max_sectors; 1636 1636 struct file *file = mddev->bitmap_info.file; 1637 1637 int err; 1638 - struct sysfs_dirent *bm = NULL; 1638 + struct kernfs_node *bm = NULL; 1639 1639 1640 1640 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); 1641 1641
+1 -1
drivers/md/bitmap.h
··· 225 225 wait_queue_head_t overflow_wait; 226 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 231 /* the bitmap API */
+5 -5
drivers/md/md.h
··· 106 106 */ 107 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 110 * sysfs entry */ 111 111 112 112 struct badblocks { ··· 376 376 sector_t resync_max; /* resync should pause 377 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 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 384 struct work_struct del_work; /* used for delayed sysfs removal */ 385 385 ··· 498 498 }; 499 499 extern struct attribute_group md_bitmap_group; 500 500 501 - static inline struct sysfs_dirent *sysfs_get_dirent_safe(struct sysfs_dirent *sd, char *name) 501 + static inline struct kernfs_node *sysfs_get_dirent_safe(struct kernfs_node *sd, char *name) 502 502 { 503 503 if (sd) 504 504 return sysfs_get_dirent(sd, name); 505 505 return sd; 506 506 } 507 - static inline void sysfs_notify_dirent_safe(struct sysfs_dirent *sd) 507 + static inline void sysfs_notify_dirent_safe(struct kernfs_node *sd) 508 508 { 509 509 if (sd) 510 510 sysfs_notify_dirent(sd);
+1 -1
drivers/misc/mic/host/mic_device.h
··· 112 112 struct work_struct shutdown_work; 113 113 u8 state; 114 114 u8 shutdown_status; 115 - struct sysfs_dirent *state_sysfs; 115 + struct kernfs_node *state_sysfs; 116 116 struct completion reset_wait; 117 117 void *log_buf_addr; 118 118 int *log_buf_len;
+270 -270
fs/kernfs/dir.c
··· 19 19 20 20 DEFINE_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 25 * sysfs_name_hash ··· 45 45 } 46 46 47 47 static 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) 51 - return hash - sd->s_hash; 52 - if (ns != sd->s_ns) 53 - return ns - sd->s_ns; 54 - return strcmp(name, sd->s_name); 50 + if (hash != kn->s_hash) 51 + return hash - kn->s_hash; 52 + if (ns != kn->s_ns) 53 + return ns - kn->s_ns; 54 + return strcmp(name, kn->s_name); 55 55 } 56 56 57 - static int sysfs_sd_compare(const struct sysfs_dirent *left, 58 - const struct sysfs_dirent *right) 57 + static int sysfs_sd_compare(const struct kernfs_node *left, 58 + const struct kernfs_node *right) 59 59 { 60 60 return sysfs_name_compare(left->s_hash, left->s_name, left->s_ns, 61 61 right); 62 62 } 63 63 64 64 /** 65 - * sysfs_link_sibling - link sysfs_dirent into sibling rbtree 66 - * @sd: sysfs_dirent of interest 65 + * sysfs_link_sibling - link kernfs_node into sibling rbtree 66 + * @kn: kernfs_node of interest 67 67 * 68 - * Link @sd into its sibling rbtree which starts from 69 - * sd->s_parent->s_dir.children. 68 + * Link @kn into its sibling rbtree which starts from 69 + * @kn->s_parent->s_dir.children. 70 70 * 71 71 * Locking: 72 72 * mutex_lock(sysfs_mutex) ··· 74 74 * RETURNS: 75 75 * 0 on susccess -EEXIST on failure. 76 76 */ 77 - static int sysfs_link_sibling(struct sysfs_dirent *sd) 77 + static 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 80 struct rb_node *parent = NULL; 81 81 82 - if (sysfs_type(sd) == SYSFS_DIR) 83 - sd->s_parent->s_dir.subdirs++; 82 + if (sysfs_type(kn) == SYSFS_DIR) 83 + kn->s_parent->s_dir.subdirs++; 84 84 85 85 while (*node) { 86 - struct sysfs_dirent *pos; 86 + struct kernfs_node *pos; 87 87 int result; 88 88 89 - pos = to_sysfs_dirent(*node); 89 + pos = rb_to_kn(*node); 90 90 parent = *node; 91 - result = sysfs_sd_compare(sd, pos); 91 + result = sysfs_sd_compare(kn, pos); 92 92 if (result < 0) 93 93 node = &pos->s_rb.rb_left; 94 94 else if (result > 0) ··· 97 97 return -EEXIST; 98 98 } 99 99 /* add new node and rebalance the tree */ 100 - rb_link_node(&sd->s_rb, parent, node); 101 - rb_insert_color(&sd->s_rb, &sd->s_parent->s_dir.children); 100 + rb_link_node(&kn->s_rb, parent, node); 101 + rb_insert_color(&kn->s_rb, &kn->s_parent->s_dir.children); 102 102 return 0; 103 103 } 104 104 105 105 /** 106 - * sysfs_unlink_sibling - unlink sysfs_dirent from sibling rbtree 107 - * @sd: sysfs_dirent of interest 106 + * sysfs_unlink_sibling - unlink kernfs_node from sibling rbtree 107 + * @kn: kernfs_node of interest 108 108 * 109 - * Unlink @sd from its sibling rbtree which starts from 110 - * sd->s_parent->s_dir.children. 109 + * Unlink @kn from its sibling rbtree which starts from 110 + * kn->s_parent->s_dir.children. 111 111 * 112 112 * Locking: 113 113 * mutex_lock(sysfs_mutex) 114 114 */ 115 - static void sysfs_unlink_sibling(struct sysfs_dirent *sd) 115 + static void sysfs_unlink_sibling(struct kernfs_node *kn) 116 116 { 117 - if (sysfs_type(sd) == SYSFS_DIR) 118 - sd->s_parent->s_dir.subdirs--; 117 + if (sysfs_type(kn) == SYSFS_DIR) 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 125 - * @sd: sysfs_dirent to get an active reference to 124 + * sysfs_get_active - get an active reference to kernfs_node 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 128 * is NULL. 129 129 * 130 130 * RETURNS: 131 - * Pointer to @sd on success, NULL on failure. 131 + * Pointer to @kn on success, NULL on failure. 132 132 */ 133 - struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd) 133 + struct kernfs_node *sysfs_get_active(struct kernfs_node *kn) 134 134 { 135 - if (unlikely(!sd)) 135 + if (unlikely(!kn)) 136 136 return NULL; 137 137 138 - if (!atomic_inc_unless_negative(&sd->s_active)) 138 + if (!atomic_inc_unless_negative(&kn->s_active)) 139 139 return NULL; 140 140 141 - if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 142 - rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_); 143 - return sd; 141 + if (kn->s_flags & SYSFS_FLAG_LOCKDEP) 142 + rwsem_acquire_read(&kn->dep_map, 0, 1, _RET_IP_); 143 + return kn; 144 144 } 145 145 146 146 /** 147 - * sysfs_put_active - put an active reference to sysfs_dirent 148 - * @sd: sysfs_dirent to put an active reference to 147 + * sysfs_put_active - put an active reference to kernfs_node 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 151 * is NULL. 152 152 */ 153 - void sysfs_put_active(struct sysfs_dirent *sd) 153 + void sysfs_put_active(struct kernfs_node *kn) 154 154 { 155 155 int v; 156 156 157 - if (unlikely(!sd)) 157 + if (unlikely(!kn)) 158 158 return; 159 159 160 - if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 161 - rwsem_release(&sd->dep_map, 1, _RET_IP_); 162 - v = atomic_dec_return(&sd->s_active); 160 + if (kn->s_flags & SYSFS_FLAG_LOCKDEP) 161 + rwsem_release(&kn->dep_map, 1, _RET_IP_); 162 + v = atomic_dec_return(&kn->s_active); 163 163 if (likely(v != SD_DEACTIVATED_BIAS)) 164 164 return; 165 165 166 - /* atomic_dec_return() is a mb(), we'll always see the updated 167 - * sd->u.completion. 166 + /* 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 - * @sd: sysfs_dirent to deactivate 174 + * sysfs_deactivate - deactivate kernfs_node 175 + * @kn: kernfs_node to deactivate 175 176 * 176 177 * Deny new active references and drain existing ones. 177 178 */ 178 - static void sysfs_deactivate(struct sysfs_dirent *sd) 179 + static void sysfs_deactivate(struct kernfs_node *kn) 179 180 { 180 181 DECLARE_COMPLETION_ONSTACK(wait); 181 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 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 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 197 if (v != SD_DEACTIVATED_BIAS) { 197 - lock_contended(&sd->dep_map, _RET_IP_); 198 + lock_contended(&kn->dep_map, _RET_IP_); 198 199 wait_for_completion(&wait); 199 200 } 200 201 201 - lock_acquired(&sd->dep_map, _RET_IP_); 202 - rwsem_release(&sd->dep_map, 1, _RET_IP_); 202 + lock_acquired(&kn->dep_map, _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 - * @sd: the target sysfs_dirent 207 + * kernfs_get - get a reference count on a kernfs_node 208 + * @kn: the target kernfs_node 208 209 */ 209 - void kernfs_get(struct sysfs_dirent *sd) 210 + void kernfs_get(struct kernfs_node *kn) 210 211 { 211 - if (sd) { 212 - WARN_ON(!atomic_read(&sd->s_count)); 213 - atomic_inc(&sd->s_count); 212 + if (kn) { 213 + WARN_ON(!atomic_read(&kn->s_count)); 214 + atomic_inc(&kn->s_count); 214 215 } 215 216 } 216 217 EXPORT_SYMBOL_GPL(kernfs_get); 217 218 218 219 /** 219 - * kernfs_put - put a reference count on a sysfs_dirent 220 - * @sd: the target sysfs_dirent 220 + * kernfs_put - put a reference count on a kernfs_node 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 */ 224 - void kernfs_put(struct sysfs_dirent *sd) 225 + void kernfs_put(struct kernfs_node *kn) 225 226 { 226 - struct sysfs_dirent *parent_sd; 227 + struct kernfs_node *parent; 227 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 231 return; 231 - root = kernfs_root(sd); 232 + root = kernfs_root(kn); 232 233 repeat: 233 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 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 - kernfs_put(sd->s_symlink.target_sd); 244 - if (sysfs_type(sd) & SYSFS_COPY_NAME) 245 - kfree(sd->s_name); 246 - if (sd->s_iattr) { 247 - if (sd->s_iattr->ia_secdata) 248 - security_release_secctx(sd->s_iattr->ia_secdata, 249 - sd->s_iattr->ia_secdata_len); 250 - simple_xattrs_free(&sd->s_iattr->xattrs); 243 + if (sysfs_type(kn) == SYSFS_KOBJ_LINK) 244 + kernfs_put(kn->s_symlink.target_kn); 245 + if (sysfs_type(kn) & SYSFS_COPY_NAME) 246 + kfree(kn->s_name); 247 + if (kn->s_iattr) { 248 + if (kn->s_iattr->ia_secdata) 249 + security_release_secctx(kn->s_iattr->ia_secdata, 250 + kn->s_iattr->ia_secdata_len); 251 + simple_xattrs_free(&kn->s_iattr->xattrs); 251 252 } 252 - kfree(sd->s_iattr); 253 - ida_simple_remove(&root->ino_ida, sd->s_ino); 254 - kmem_cache_free(sysfs_dir_cachep, sd); 253 + kfree(kn->s_iattr); 254 + ida_simple_remove(&root->ino_ida, kn->s_ino); 255 + kmem_cache_free(sysfs_dir_cachep, kn); 255 256 256 - sd = parent_sd; 257 - if (sd) { 258 - if (atomic_dec_and_test(&sd->s_count)) 257 + kn = parent; 258 + if (kn) { 259 + if (atomic_dec_and_test(&kn->s_count)) 259 260 goto repeat; 260 261 } else { 261 - /* just released the root sd, free @root too */ 262 + /* just released the root kn, free @root too */ 262 263 ida_destroy(&root->ino_ida); 263 264 kfree(root); 264 265 } ··· 268 267 269 268 static int sysfs_dentry_delete(const struct dentry *dentry) 270 269 { 271 - struct sysfs_dirent *sd = dentry->d_fsdata; 272 - return !(sd && !(sd->s_flags & SYSFS_FLAG_REMOVED)); 270 + struct kernfs_node *kn = dentry->d_fsdata; 271 + return !(kn && !(kn->s_flags & SYSFS_FLAG_REMOVED)); 273 272 } 274 273 275 274 static int sysfs_dentry_revalidate(struct dentry *dentry, unsigned int flags) 276 275 { 277 - struct sysfs_dirent *sd; 276 + struct kernfs_node *kn; 278 277 279 278 if (flags & LOOKUP_RCU) 280 279 return -ECHILD; 281 280 282 - sd = dentry->d_fsdata; 281 + kn = dentry->d_fsdata; 283 282 mutex_lock(&sysfs_mutex); 284 283 285 284 /* The sysfs dirent has been deleted */ 286 - if (sd->s_flags & SYSFS_FLAG_REMOVED) 285 + if (kn->s_flags & SYSFS_FLAG_REMOVED) 287 286 goto out_bad; 288 287 289 288 /* The sysfs dirent has been moved? */ 290 - if (dentry->d_parent->d_fsdata != sd->s_parent) 289 + if (dentry->d_parent->d_fsdata != kn->s_parent) 291 290 goto out_bad; 292 291 293 292 /* The sysfs dirent has been renamed */ 294 - if (strcmp(dentry->d_name.name, sd->s_name) != 0) 293 + if (strcmp(dentry->d_name.name, kn->s_name) != 0) 295 294 goto out_bad; 296 295 297 296 /* The sysfs dirent has been moved to a different namespace */ 298 - if (sd->s_parent && kernfs_ns_enabled(sd->s_parent) && 299 - sysfs_info(dentry->d_sb)->ns != sd->s_ns) 297 + if (kn->s_parent && kernfs_ns_enabled(kn->s_parent) && 298 + sysfs_info(dentry->d_sb)->ns != kn->s_ns) 300 299 goto out_bad; 301 300 302 301 mutex_unlock(&sysfs_mutex); ··· 336 335 .d_release = sysfs_dentry_release, 337 336 }; 338 337 339 - struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, 340 - const char *name, umode_t mode, int type) 338 + struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root, 339 + const char *name, umode_t mode, int type) 341 340 { 342 341 char *dup_name = NULL; 343 - struct sysfs_dirent *sd; 342 + struct kernfs_node *kn; 344 343 int ret; 345 344 346 345 if (type & SYSFS_COPY_NAME) { ··· 349 348 return NULL; 350 349 } 351 350 352 - sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); 353 - if (!sd) 351 + kn = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL); 352 + if (!kn) 354 353 goto err_out1; 355 354 356 355 ret = ida_simple_get(&root->ino_ida, 1, 0, GFP_KERNEL); 357 356 if (ret < 0) 358 357 goto err_out2; 359 - sd->s_ino = ret; 358 + kn->s_ino = ret; 360 359 361 - atomic_set(&sd->s_count, 1); 362 - atomic_set(&sd->s_active, 0); 360 + atomic_set(&kn->s_count, 1); 361 + atomic_set(&kn->s_active, 0); 363 362 364 - sd->s_name = name; 365 - sd->s_mode = mode; 366 - sd->s_flags = type | SYSFS_FLAG_REMOVED; 363 + kn->s_name = name; 364 + kn->s_mode = mode; 365 + kn->s_flags = type | SYSFS_FLAG_REMOVED; 367 366 368 - return sd; 367 + return kn; 369 368 370 369 err_out2: 371 - kmem_cache_free(sysfs_dir_cachep, sd); 370 + kmem_cache_free(sysfs_dir_cachep, kn); 372 371 err_out1: 373 372 kfree(dup_name); 374 373 return NULL; 375 374 } 376 375 377 376 /** 378 - * sysfs_addrm_start - prepare for sysfs_dirent add/remove 377 + * sysfs_addrm_start - prepare for kernfs_node add/remove 379 378 * @acxt: pointer to sysfs_addrm_cxt to be used 380 379 * 381 380 * This function is called when the caller is about to add or remove 382 - * sysfs_dirent. This function acquires sysfs_mutex. @acxt is used 383 - * to keep and pass context to other addrm functions. 381 + * kernfs_node. This function acquires sysfs_mutex. @acxt is used to 382 + * keep and pass context to other addrm functions. 384 383 * 385 384 * LOCKING: 386 385 * Kernel thread context (may sleep). sysfs_mutex is locked on ··· 395 394 } 396 395 397 396 /** 398 - * sysfs_add_one - add sysfs_dirent to parent without warning 397 + * sysfs_add_one - add kernfs_node to parent without warning 399 398 * @acxt: addrm context to use 400 - * @sd: sysfs_dirent to be added 401 - * @parent_sd: the parent sysfs_dirent to add @sd to 399 + * @kn: kernfs_node to be added 400 + * @parent: the parent kernfs_node to add @kn to 402 401 * 403 - * Get @parent_sd and set @sd->s_parent to it and increment nlink of 404 - * the parent inode if @sd is a directory and link into the children 402 + * Get @parent and set @kn->s_parent to it and increment nlink of 403 + * the parent inode if @kn is a directory and link into the children 405 404 * list of the parent. 406 405 * 407 406 * This function should be called between calls to ··· 415 414 * 0 on success, -EEXIST if entry with the given name already 416 415 * exists. 417 416 */ 418 - int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, 419 - struct sysfs_dirent *parent_sd) 417 + int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn, 418 + struct kernfs_node *parent) 420 419 { 421 - bool has_ns = kernfs_ns_enabled(parent_sd); 420 + bool has_ns = kernfs_ns_enabled(parent); 422 421 struct sysfs_inode_attrs *ps_iattr; 423 422 int ret; 424 423 425 - if (has_ns != (bool)sd->s_ns) { 424 + if (has_ns != (bool)kn->s_ns) { 426 425 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", 427 426 has_ns ? "required" : "invalid", 428 - parent_sd->s_name, sd->s_name); 427 + parent->s_name, kn->s_name); 429 428 return -EINVAL; 430 429 } 431 430 432 - if (sysfs_type(parent_sd) != SYSFS_DIR) 431 + if (sysfs_type(parent) != SYSFS_DIR) 433 432 return -EINVAL; 434 433 435 - sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); 436 - sd->s_parent = parent_sd; 437 - kernfs_get(parent_sd); 434 + kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns); 435 + kn->s_parent = parent; 436 + kernfs_get(parent); 438 437 439 - ret = sysfs_link_sibling(sd); 438 + ret = sysfs_link_sibling(kn); 440 439 if (ret) 441 440 return ret; 442 441 443 442 /* Update timestamps on the parent */ 444 - ps_iattr = parent_sd->s_iattr; 443 + ps_iattr = parent->s_iattr; 445 444 if (ps_iattr) { 446 445 struct iattr *ps_iattrs = &ps_iattr->ia_iattr; 447 446 ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME; 448 447 } 449 448 450 449 /* Mark the entry added into directory tree */ 451 - sd->s_flags &= ~SYSFS_FLAG_REMOVED; 450 + kn->s_flags &= ~SYSFS_FLAG_REMOVED; 452 451 453 452 return 0; 454 453 } 455 454 456 455 /** 457 - * sysfs_remove_one - remove sysfs_dirent from parent 456 + * sysfs_remove_one - remove kernfs_node from parent 458 457 * @acxt: addrm context to use 459 - * @sd: sysfs_dirent to be removed 458 + * @kn: kernfs_node to be removed 460 459 * 461 - * Mark @sd removed and drop nlink of parent inode if @sd is a 462 - * directory. @sd is unlinked from the children list. 460 + * Mark @kn removed and drop nlink of parent inode if @kn is a 461 + * directory. @kn is unlinked from the children list. 463 462 * 464 463 * This function should be called between calls to 465 464 * sysfs_addrm_start() and sysfs_addrm_finish() and should be ··· 469 468 * Determined by sysfs_addrm_start(). 470 469 */ 471 470 static void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, 472 - struct sysfs_dirent *sd) 471 + struct kernfs_node *kn) 473 472 { 474 473 struct sysfs_inode_attrs *ps_iattr; 475 474 ··· 477 476 * Removal can be called multiple times on the same node. Only the 478 477 * first invocation is effective and puts the base ref. 479 478 */ 480 - if (sd->s_flags & SYSFS_FLAG_REMOVED) 479 + if (kn->s_flags & SYSFS_FLAG_REMOVED) 481 480 return; 482 481 483 - if (sd->s_parent) { 484 - sysfs_unlink_sibling(sd); 482 + if (kn->s_parent) { 483 + sysfs_unlink_sibling(kn); 485 484 486 485 /* Update timestamps on the parent */ 487 - ps_iattr = sd->s_parent->s_iattr; 486 + ps_iattr = kn->s_parent->s_iattr; 488 487 if (ps_iattr) { 489 488 ps_iattr->ia_iattr.ia_ctime = CURRENT_TIME; 490 489 ps_iattr->ia_iattr.ia_mtime = CURRENT_TIME; 491 490 } 492 491 } 493 492 494 - sd->s_flags |= SYSFS_FLAG_REMOVED; 495 - sd->u.removed_list = acxt->removed; 496 - acxt->removed = sd; 493 + kn->s_flags |= SYSFS_FLAG_REMOVED; 494 + kn->u.removed_list = acxt->removed; 495 + acxt->removed = kn; 497 496 } 498 497 499 498 /** 500 - * sysfs_addrm_finish - finish up sysfs_dirent add/remove 499 + * sysfs_addrm_finish - finish up kernfs_node add/remove 501 500 * @acxt: addrm context to finish up 502 501 * 503 - * Finish up sysfs_dirent add/remove. Resources acquired by 504 - * sysfs_addrm_start() are released and removed sysfs_dirents are 502 + * Finish up kernfs_node add/remove. Resources acquired by 503 + * sysfs_addrm_start() are released and removed kernfs_nodes are 505 504 * cleaned up. 506 505 * 507 506 * LOCKING: ··· 513 512 /* release resources acquired by sysfs_addrm_start() */ 514 513 mutex_unlock(&sysfs_mutex); 515 514 516 - /* kill removed sysfs_dirents */ 515 + /* kill removed kernfs_nodes */ 517 516 while (acxt->removed) { 518 - struct sysfs_dirent *sd = acxt->removed; 517 + struct kernfs_node *kn = acxt->removed; 519 518 520 - acxt->removed = sd->u.removed_list; 519 + acxt->removed = kn->u.removed_list; 521 520 522 - sysfs_deactivate(sd); 523 - sysfs_unmap_bin_file(sd); 524 - kernfs_put(sd); 521 + sysfs_deactivate(kn); 522 + sysfs_unmap_bin_file(kn); 523 + kernfs_put(kn); 525 524 } 526 525 } 527 526 528 527 /** 529 - * kernfs_find_ns - find sysfs_dirent with the given name 530 - * @parent: sysfs_dirent to search under 528 + * kernfs_find_ns - find kernfs_node with the given name 529 + * @parent: kernfs_node to search under 531 530 * @name: name to look for 532 531 * @ns: the namespace tag to use 533 532 * 534 - * Look for sysfs_dirent with name @name under @parent. Returns pointer to 535 - * the found sysfs_dirent on success, %NULL on failure. 533 + * Look for kernfs_node with name @name under @parent. Returns pointer to 534 + * the found kernfs_node on success, %NULL on failure. 536 535 */ 537 - static struct sysfs_dirent *kernfs_find_ns(struct sysfs_dirent *parent, 538 - const unsigned char *name, 539 - const void *ns) 536 + static struct kernfs_node *kernfs_find_ns(struct kernfs_node *parent, 537 + const unsigned char *name, 538 + const void *ns) 540 539 { 541 540 struct rb_node *node = parent->s_dir.children.rb_node; 542 541 bool has_ns = kernfs_ns_enabled(parent); ··· 553 552 554 553 hash = sysfs_name_hash(name, ns); 555 554 while (node) { 556 - struct sysfs_dirent *sd; 555 + struct kernfs_node *kn; 557 556 int result; 558 557 559 - sd = to_sysfs_dirent(node); 560 - result = sysfs_name_compare(hash, name, ns, sd); 558 + kn = rb_to_kn(node); 559 + result = sysfs_name_compare(hash, name, ns, kn); 561 560 if (result < 0) 562 561 node = node->rb_left; 563 562 else if (result > 0) 564 563 node = node->rb_right; 565 564 else 566 - return sd; 565 + return kn; 567 566 } 568 567 return NULL; 569 568 } 570 569 571 570 /** 572 - * kernfs_find_and_get_ns - find and get sysfs_dirent with the given name 573 - * @parent: sysfs_dirent to search under 571 + * kernfs_find_and_get_ns - find and get kernfs_node with the given name 572 + * @parent: kernfs_node to search under 574 573 * @name: name to look for 575 574 * @ns: the namespace tag to use 576 575 * 577 - * Look for sysfs_dirent with name @name under @parent and get a reference 576 + * Look for kernfs_node with name @name under @parent and get a reference 578 577 * if found. This function may sleep and returns pointer to the found 579 - * sysfs_dirent on success, %NULL on failure. 578 + * kernfs_node on success, %NULL on failure. 580 579 */ 581 - struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, 582 - const char *name, const void *ns) 580 + struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, 581 + const char *name, const void *ns) 583 582 { 584 - struct sysfs_dirent *sd; 583 + struct kernfs_node *kn; 585 584 586 585 mutex_lock(&sysfs_mutex); 587 - sd = kernfs_find_ns(parent, name, ns); 588 - kernfs_get(sd); 586 + kn = kernfs_find_ns(parent, name, ns); 587 + kernfs_get(kn); 589 588 mutex_unlock(&sysfs_mutex); 590 589 591 - return sd; 590 + return kn; 592 591 } 593 592 EXPORT_SYMBOL_GPL(kernfs_find_and_get_ns); 594 593 ··· 602 601 struct kernfs_root *kernfs_create_root(void *priv) 603 602 { 604 603 struct kernfs_root *root; 605 - struct sysfs_dirent *sd; 604 + struct kernfs_node *kn; 606 605 607 606 root = kzalloc(sizeof(*root), GFP_KERNEL); 608 607 if (!root) ··· 610 609 611 610 ida_init(&root->ino_ida); 612 611 613 - sd = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR); 614 - if (!sd) { 612 + kn = sysfs_new_dirent(root, "", S_IFDIR | S_IRUGO | S_IXUGO, SYSFS_DIR); 613 + if (!kn) { 615 614 ida_destroy(&root->ino_ida); 616 615 kfree(root); 617 616 return ERR_PTR(-ENOMEM); 618 617 } 619 618 620 - sd->s_flags &= ~SYSFS_FLAG_REMOVED; 621 - sd->priv = priv; 622 - sd->s_dir.root = root; 619 + kn->s_flags &= ~SYSFS_FLAG_REMOVED; 620 + kn->priv = priv; 621 + kn->s_dir.root = root; 623 622 624 - root->sd = sd; 623 + root->kn = kn; 625 624 626 625 return root; 627 626 } ··· 635 634 */ 636 635 void kernfs_destroy_root(struct kernfs_root *root) 637 636 { 638 - kernfs_remove(root->sd); /* will also free @root */ 637 + kernfs_remove(root->kn); /* will also free @root */ 639 638 } 640 639 641 640 /** ··· 647 646 * 648 647 * Returns the created node on success, ERR_PTR() value on failure. 649 648 */ 650 - struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, 651 - const char *name, void *priv, 652 - const void *ns) 649 + struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, 650 + const char *name, void *priv, 651 + const void *ns) 653 652 { 654 653 umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; 655 654 struct sysfs_addrm_cxt acxt; 656 - struct sysfs_dirent *sd; 655 + struct kernfs_node *kn; 657 656 int rc; 658 657 659 658 /* allocate */ 660 - sd = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR); 661 - if (!sd) 659 + kn = sysfs_new_dirent(kernfs_root(parent), name, mode, SYSFS_DIR); 660 + if (!kn) 662 661 return ERR_PTR(-ENOMEM); 663 662 664 - sd->s_dir.root = parent->s_dir.root; 665 - sd->s_ns = ns; 666 - sd->priv = priv; 663 + kn->s_dir.root = parent->s_dir.root; 664 + kn->s_ns = ns; 665 + kn->priv = priv; 667 666 668 667 /* link in */ 669 668 sysfs_addrm_start(&acxt); 670 - rc = sysfs_add_one(&acxt, sd, parent); 669 + rc = sysfs_add_one(&acxt, kn, parent); 671 670 sysfs_addrm_finish(&acxt); 672 671 673 672 if (!rc) 674 - return sd; 673 + return kn; 675 674 676 - kernfs_put(sd); 675 + kernfs_put(kn); 677 676 return ERR_PTR(rc); 678 677 } 679 678 ··· 681 680 unsigned int flags) 682 681 { 683 682 struct dentry *ret = NULL; 684 - struct dentry *parent = dentry->d_parent; 685 - struct sysfs_dirent *parent_sd = parent->d_fsdata; 686 - struct sysfs_dirent *sd; 683 + struct kernfs_node *parent = dentry->d_parent->d_fsdata; 684 + struct kernfs_node *kn; 687 685 struct inode *inode; 688 686 const void *ns = NULL; 689 687 690 688 mutex_lock(&sysfs_mutex); 691 689 692 - if (kernfs_ns_enabled(parent_sd)) 690 + if (kernfs_ns_enabled(parent)) 693 691 ns = sysfs_info(dir->i_sb)->ns; 694 692 695 - sd = kernfs_find_ns(parent_sd, dentry->d_name.name, ns); 693 + kn = kernfs_find_ns(parent, dentry->d_name.name, ns); 696 694 697 695 /* no such entry */ 698 - if (!sd) { 696 + if (!kn) { 699 697 ret = ERR_PTR(-ENOENT); 700 698 goto out_unlock; 701 699 } 702 - kernfs_get(sd); 703 - dentry->d_fsdata = sd; 700 + kernfs_get(kn); 701 + dentry->d_fsdata = kn; 704 702 705 703 /* attach dentry and inode */ 706 - inode = sysfs_get_inode(dir->i_sb, sd); 704 + inode = sysfs_get_inode(dir->i_sb, kn); 707 705 if (!inode) { 708 706 ret = ERR_PTR(-ENOMEM); 709 707 goto out_unlock; ··· 726 726 .listxattr = sysfs_listxattr, 727 727 }; 728 728 729 - static struct sysfs_dirent *sysfs_leftmost_descendant(struct sysfs_dirent *pos) 729 + static 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 733 while (true) { 734 734 struct rb_node *rbn; ··· 742 742 if (!rbn) 743 743 break; 744 744 745 - pos = to_sysfs_dirent(rbn); 745 + pos = rb_to_kn(rbn); 746 746 } 747 747 748 748 return last; ··· 751 751 /** 752 752 * sysfs_next_descendant_post - find the next descendant for post-order walk 753 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 756 * Find the next descendant to visit for post-order traversal of @root's 757 757 * descendants. @root is included in the iteration and the last node to be 758 758 * visited. 759 759 */ 760 - static struct sysfs_dirent *sysfs_next_descendant_post(struct sysfs_dirent *pos, 761 - struct sysfs_dirent *root) 760 + static struct kernfs_node *sysfs_next_descendant_post(struct kernfs_node *pos, 761 + struct kernfs_node *root) 762 762 { 763 763 struct rb_node *rbn; 764 764 ··· 775 775 /* if there's an unvisited sibling, visit its leftmost descendant */ 776 776 rbn = rb_next(&pos->s_rb); 777 777 if (rbn) 778 - return sysfs_leftmost_descendant(to_sysfs_dirent(rbn)); 778 + return sysfs_leftmost_descendant(rb_to_kn(rbn)); 779 779 780 780 /* no sibling left, visit parent */ 781 781 return pos->s_parent; 782 782 } 783 783 784 784 static 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 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 794 next = NULL; 795 795 do { 796 796 pos = next; 797 - next = sysfs_next_descendant_post(pos, sd); 797 + next = sysfs_next_descendant_post(pos, kn); 798 798 if (pos) 799 799 sysfs_remove_one(acxt, pos); 800 800 } while (next); 801 801 } 802 802 803 803 /** 804 - * kernfs_remove - remove a sysfs_dirent recursively 805 - * @sd: the sysfs_dirent to remove 804 + * kernfs_remove - remove a kernfs_node recursively 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 */ 809 - void kernfs_remove(struct sysfs_dirent *sd) 809 + void kernfs_remove(struct kernfs_node *kn) 810 810 { 811 811 struct sysfs_addrm_cxt acxt; 812 812 813 813 sysfs_addrm_start(&acxt); 814 - __kernfs_remove(&acxt, sd); 814 + __kernfs_remove(&acxt, kn); 815 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 820 - * @dir_sd: parent of the target 821 - * @name: name of the sysfs_dirent to remove 822 - * @ns: namespace tag of the sysfs_dirent to remove 819 + * kernfs_remove_by_name_ns - find a kernfs_node by name and remove it 820 + * @parent: parent of the target 821 + * @name: name of the kernfs_node 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 825 - * it. Returns 0 on success, -ENOENT if such entry doesn't exist. 824 + * Look for the kernfs_node with @name and @ns under @parent and remove it. 825 + * Returns 0 on success, -ENOENT if such entry doesn't exist. 826 826 */ 827 - int kernfs_remove_by_name_ns(struct sysfs_dirent *dir_sd, const char *name, 827 + int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, 828 828 const void *ns) 829 829 { 830 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 834 WARN(1, KERN_WARNING "sysfs: can not remove '%s', no directory\n", 835 835 name); 836 836 return -ENOENT; ··· 838 838 839 839 sysfs_addrm_start(&acxt); 840 840 841 - sd = kernfs_find_ns(dir_sd, name, ns); 842 - if (sd) 843 - __kernfs_remove(&acxt, sd); 841 + kn = kernfs_find_ns(parent, name, ns); 842 + if (kn) 843 + __kernfs_remove(&acxt, kn); 844 844 845 845 sysfs_addrm_finish(&acxt); 846 846 847 - if (sd) 847 + if (kn) 848 848 return 0; 849 849 else 850 850 return -ENOENT; ··· 852 852 853 853 /** 854 854 * kernfs_rename_ns - move and rename a kernfs_node 855 - * @sd: target node 855 + * @kn: target node 856 856 * @new_parent: new parent to put @sd under 857 857 * @new_name: new name 858 858 * @new_ns: new namespace tag 859 859 */ 860 - int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, 860 + int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, 861 861 const char *new_name, const void *new_ns) 862 862 { 863 863 int error; ··· 865 865 mutex_lock(&sysfs_mutex); 866 866 867 867 error = 0; 868 - if ((sd->s_parent == new_parent) && (sd->s_ns == new_ns) && 869 - (strcmp(sd->s_name, new_name) == 0)) 868 + if ((kn->s_parent == new_parent) && (kn->s_ns == new_ns) && 869 + (strcmp(kn->s_name, new_name) == 0)) 870 870 goto out; /* nothing to rename */ 871 871 872 872 error = -EEXIST; 873 873 if (kernfs_find_ns(new_parent, new_name, new_ns)) 874 874 goto out; 875 875 876 - /* rename sysfs_dirent */ 877 - if (strcmp(sd->s_name, new_name) != 0) { 876 + /* rename kernfs_node */ 877 + if (strcmp(kn->s_name, new_name) != 0) { 878 878 error = -ENOMEM; 879 879 new_name = kstrdup(new_name, GFP_KERNEL); 880 880 if (!new_name) 881 881 goto out; 882 882 883 - kfree(sd->s_name); 884 - sd->s_name = new_name; 883 + kfree(kn->s_name); 884 + kn->s_name = new_name; 885 885 } 886 886 887 887 /* 888 888 * Move to the appropriate place in the appropriate directories rbtree. 889 889 */ 890 - sysfs_unlink_sibling(sd); 890 + sysfs_unlink_sibling(kn); 891 891 kernfs_get(new_parent); 892 - kernfs_put(sd->s_parent); 893 - sd->s_ns = new_ns; 894 - sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); 895 - sd->s_parent = new_parent; 896 - sysfs_link_sibling(sd); 892 + kernfs_put(kn->s_parent); 893 + kn->s_ns = new_ns; 894 + kn->s_hash = sysfs_name_hash(kn->s_name, kn->s_ns); 895 + kn->s_parent = new_parent; 896 + sysfs_link_sibling(kn); 897 897 898 898 error = 0; 899 899 out: ··· 902 902 } 903 903 904 904 /* Relationship between s_mode and the DT_xxx types */ 905 - static inline unsigned char dt_type(struct sysfs_dirent *sd) 905 + static 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 910 910 static int sysfs_dir_release(struct inode *inode, struct file *filp) ··· 913 913 return 0; 914 914 } 915 915 916 - static struct sysfs_dirent *sysfs_dir_pos(const void *ns, 917 - struct sysfs_dirent *parent_sd, loff_t hash, struct sysfs_dirent *pos) 916 + static struct kernfs_node *sysfs_dir_pos(const void *ns, 917 + struct kernfs_node *parent, loff_t hash, struct kernfs_node *pos) 918 918 { 919 919 if (pos) { 920 920 int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) && 921 - pos->s_parent == parent_sd && 921 + pos->s_parent == parent && 922 922 hash == pos->s_hash; 923 923 kernfs_put(pos); 924 924 if (!valid) 925 925 pos = NULL; 926 926 } 927 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 929 while (node) { 930 - pos = to_sysfs_dirent(node); 930 + pos = rb_to_kn(node); 931 931 932 932 if (hash < pos->s_hash) 933 933 node = node->rb_left; ··· 943 943 if (!node) 944 944 pos = NULL; 945 945 else 946 - pos = to_sysfs_dirent(node); 946 + pos = rb_to_kn(node); 947 947 } 948 948 return pos; 949 949 } 950 950 951 - static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns, 952 - struct sysfs_dirent *parent_sd, ino_t ino, struct sysfs_dirent *pos) 951 + static struct kernfs_node *sysfs_dir_next_pos(const void *ns, 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 955 if (pos) 956 956 do { 957 957 struct rb_node *node = rb_next(&pos->s_rb); 958 958 if (!node) 959 959 pos = NULL; 960 960 else 961 - pos = to_sysfs_dirent(node); 961 + pos = rb_to_kn(node); 962 962 } while (pos && pos->s_ns != ns); 963 963 return pos; 964 964 } ··· 966 966 static int sysfs_readdir(struct file *file, struct dir_context *ctx) 967 967 { 968 968 struct dentry *dentry = file->f_path.dentry; 969 - struct sysfs_dirent *parent_sd = dentry->d_fsdata; 970 - struct sysfs_dirent *pos = file->private_data; 969 + struct kernfs_node *parent = dentry->d_fsdata; 970 + struct kernfs_node *pos = file->private_data; 971 971 const void *ns = NULL; 972 972 973 973 if (!dir_emit_dots(file, ctx)) 974 974 return 0; 975 975 mutex_lock(&sysfs_mutex); 976 976 977 - if (kernfs_ns_enabled(parent_sd)) 977 + if (kernfs_ns_enabled(parent)) 978 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 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 983 const char *name = pos->s_name; 984 984 unsigned int type = dt_type(pos); 985 985 int len = strlen(name);
+93 -93
fs/kernfs/file.c
··· 19 19 20 20 /* 21 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 25 * protected by sysfs_open_dirent_lock. 26 26 * 27 27 * filp->private_data points to seq_file whose ->private points to ··· 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 48 * be called while holding an active reference. 49 49 */ 50 - static const struct kernfs_ops *kernfs_ops(struct sysfs_dirent *sd) 50 + static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn) 51 51 { 52 - if (sd->s_flags & SYSFS_FLAG_LOCKDEP) 53 - lockdep_assert_held(sd); 54 - return sd->s_attr.ops; 52 + if (kn->s_flags & SYSFS_FLAG_LOCKDEP) 53 + lockdep_assert_held(kn); 54 + return kn->s_attr.ops; 55 55 } 56 56 57 57 static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos) ··· 64 64 * the ops aren't called concurrently for the same open file. 65 65 */ 66 66 mutex_lock(&of->mutex); 67 - if (!sysfs_get_active(of->sd)) 67 + if (!sysfs_get_active(of->kn)) 68 68 return ERR_PTR(-ENODEV); 69 69 70 - ops = kernfs_ops(of->sd); 70 + ops = kernfs_ops(of->kn); 71 71 if (ops->seq_start) { 72 72 return ops->seq_start(sf, ppos); 73 73 } else { ··· 82 82 static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos) 83 83 { 84 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 87 if (ops->seq_next) { 88 88 return ops->seq_next(sf, v, ppos); ··· 99 99 static void kernfs_seq_stop(struct seq_file *sf, void *v) 100 100 { 101 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 104 if (ops->seq_stop) 105 105 ops->seq_stop(sf, v); 106 106 107 - sysfs_put_active(of->sd); 107 + sysfs_put_active(of->kn); 108 108 mutex_unlock(&of->mutex); 109 109 } 110 110 ··· 112 112 { 113 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 120 120 static const struct seq_operations kernfs_seq_ops = { ··· 147 147 * the ops aren't called concurrently for the same open file. 148 148 */ 149 149 mutex_lock(&of->mutex); 150 - if (!sysfs_get_active(of->sd)) { 150 + if (!sysfs_get_active(of->kn)) { 151 151 len = -ENODEV; 152 152 mutex_unlock(&of->mutex); 153 153 goto out_free; 154 154 } 155 155 156 - ops = kernfs_ops(of->sd); 156 + ops = kernfs_ops(of->kn); 157 157 if (ops->read) 158 158 len = ops->read(of, buf, len, *ppos); 159 159 else 160 160 len = -EINVAL; 161 161 162 - sysfs_put_active(of->sd); 162 + sysfs_put_active(of->kn); 163 163 mutex_unlock(&of->mutex); 164 164 165 165 if (len < 0) ··· 189 189 { 190 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 193 return seq_read(file, user_buf, count, ppos); 194 194 else 195 195 return kernfs_file_direct_read(of, user_buf, count, ppos); ··· 234 234 * the ops aren't called concurrently for the same open file. 235 235 */ 236 236 mutex_lock(&of->mutex); 237 - if (!sysfs_get_active(of->sd)) { 237 + if (!sysfs_get_active(of->kn)) { 238 238 mutex_unlock(&of->mutex); 239 239 len = -ENODEV; 240 240 goto out_free; 241 241 } 242 242 243 - ops = kernfs_ops(of->sd); 243 + ops = kernfs_ops(of->kn); 244 244 if (ops->write) 245 245 len = ops->write(of, buf, len, *ppos); 246 246 else 247 247 len = -EINVAL; 248 248 249 - sysfs_put_active(of->sd); 249 + sysfs_put_active(of->kn); 250 250 mutex_unlock(&of->mutex); 251 251 252 252 if (len > 0) ··· 264 264 if (!of->vm_ops) 265 265 return; 266 266 267 - if (!sysfs_get_active(of->sd)) 267 + if (!sysfs_get_active(of->kn)) 268 268 return; 269 269 270 270 if (of->vm_ops->open) 271 271 of->vm_ops->open(vma); 272 272 273 - sysfs_put_active(of->sd); 273 + sysfs_put_active(of->kn); 274 274 } 275 275 276 276 static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ··· 282 282 if (!of->vm_ops) 283 283 return VM_FAULT_SIGBUS; 284 284 285 - if (!sysfs_get_active(of->sd)) 285 + if (!sysfs_get_active(of->kn)) 286 286 return VM_FAULT_SIGBUS; 287 287 288 288 ret = VM_FAULT_SIGBUS; 289 289 if (of->vm_ops->fault) 290 290 ret = of->vm_ops->fault(vma, vmf); 291 291 292 - sysfs_put_active(of->sd); 292 + sysfs_put_active(of->kn); 293 293 return ret; 294 294 } 295 295 ··· 303 303 if (!of->vm_ops) 304 304 return VM_FAULT_SIGBUS; 305 305 306 - if (!sysfs_get_active(of->sd)) 306 + if (!sysfs_get_active(of->kn)) 307 307 return VM_FAULT_SIGBUS; 308 308 309 309 ret = 0; ··· 312 312 else 313 313 file_update_time(file); 314 314 315 - sysfs_put_active(of->sd); 315 + sysfs_put_active(of->kn); 316 316 return ret; 317 317 } 318 318 ··· 326 326 if (!of->vm_ops) 327 327 return -EINVAL; 328 328 329 - if (!sysfs_get_active(of->sd)) 329 + if (!sysfs_get_active(of->kn)) 330 330 return -EINVAL; 331 331 332 332 ret = -EINVAL; 333 333 if (of->vm_ops->access) 334 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 337 return ret; 338 338 } 339 339 ··· 348 348 if (!of->vm_ops) 349 349 return 0; 350 350 351 - if (!sysfs_get_active(of->sd)) 351 + if (!sysfs_get_active(of->kn)) 352 352 return -EINVAL; 353 353 354 354 ret = 0; 355 355 if (of->vm_ops->set_policy) 356 356 ret = of->vm_ops->set_policy(vma, new); 357 357 358 - sysfs_put_active(of->sd); 358 + sysfs_put_active(of->kn); 359 359 return ret; 360 360 } 361 361 ··· 369 369 if (!of->vm_ops) 370 370 return vma->vm_policy; 371 371 372 - if (!sysfs_get_active(of->sd)) 372 + if (!sysfs_get_active(of->kn)) 373 373 return vma->vm_policy; 374 374 375 375 pol = vma->vm_policy; 376 376 if (of->vm_ops->get_policy) 377 377 pol = of->vm_ops->get_policy(vma, addr); 378 378 379 - sysfs_put_active(of->sd); 379 + sysfs_put_active(of->kn); 380 380 return pol; 381 381 } 382 382 ··· 391 391 if (!of->vm_ops) 392 392 return 0; 393 393 394 - if (!sysfs_get_active(of->sd)) 394 + if (!sysfs_get_active(of->kn)) 395 395 return 0; 396 396 397 397 ret = 0; 398 398 if (of->vm_ops->migrate) 399 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 402 return ret; 403 403 } 404 404 #endif ··· 428 428 * without grabbing @of->mutex by testing HAS_MMAP flag. See the 429 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 432 return -ENODEV; 433 433 434 434 mutex_lock(&of->mutex); 435 435 436 436 rc = -ENODEV; 437 - if (!sysfs_get_active(of->sd)) 437 + if (!sysfs_get_active(of->kn)) 438 438 goto out_unlock; 439 439 440 - ops = kernfs_ops(of->sd); 440 + ops = kernfs_ops(of->kn); 441 441 rc = ops->mmap(of, vma); 442 442 443 443 /* ··· 465 465 of->vm_ops = vma->vm_ops; 466 466 vma->vm_ops = &kernfs_vm_ops; 467 467 out_put: 468 - sysfs_put_active(of->sd); 468 + sysfs_put_active(of->kn); 469 469 out_unlock: 470 470 mutex_unlock(&of->mutex); 471 471 ··· 474 474 475 475 /** 476 476 * sysfs_get_open_dirent - get or create sysfs_open_dirent 477 - * @sd: target sysfs_dirent 477 + * @kn: target kernfs_node 478 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 481 * otherwise, create one. @of is chained to the files list. 482 482 * 483 483 * LOCKING: ··· 486 486 * RETURNS: 487 487 * 0 on success, -errno on failure. 488 488 */ 489 - static int sysfs_get_open_dirent(struct sysfs_dirent *sd, 489 + static int sysfs_get_open_dirent(struct kernfs_node *kn, 490 490 struct sysfs_open_file *of) 491 491 { 492 492 struct sysfs_open_dirent *od, *new_od = NULL; ··· 495 495 mutex_lock(&sysfs_open_file_mutex); 496 496 spin_lock_irq(&sysfs_open_dirent_lock); 497 497 498 - if (!sd->s_attr.open && new_od) { 499 - sd->s_attr.open = new_od; 498 + if (!kn->s_attr.open && new_od) { 499 + kn->s_attr.open = new_od; 500 500 new_od = NULL; 501 501 } 502 502 503 - od = sd->s_attr.open; 503 + od = kn->s_attr.open; 504 504 if (od) { 505 505 atomic_inc(&od->refcnt); 506 506 list_add_tail(&of->list, &od->files); ··· 528 528 529 529 /** 530 530 * sysfs_put_open_dirent - put sysfs_open_dirent 531 - * @sd: target sysfs_dirent 531 + * @kn: target kernfs_nodet 532 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 535 * reference count reaches zero, disassociate and free it. 536 536 * 537 537 * LOCKING: 538 538 * None. 539 539 */ 540 - static void sysfs_put_open_dirent(struct sysfs_dirent *sd, 540 + static void sysfs_put_open_dirent(struct kernfs_node *kn, 541 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 544 unsigned long flags; 545 545 546 546 mutex_lock(&sysfs_open_file_mutex); ··· 550 550 list_del(&of->list); 551 551 552 552 if (atomic_dec_and_test(&od->refcnt)) 553 - sd->s_attr.open = NULL; 553 + kn->s_attr.open = NULL; 554 554 else 555 555 od = NULL; 556 556 ··· 562 562 563 563 static 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 566 const struct kernfs_ops *ops; 567 567 struct sysfs_open_file *of; 568 568 bool has_read, has_write, has_mmap; 569 569 int error = -EACCES; 570 570 571 - if (!sysfs_get_active(attr_sd)) 571 + if (!sysfs_get_active(kn)) 572 572 return -ENODEV; 573 573 574 - ops = kernfs_ops(attr_sd); 574 + ops = kernfs_ops(kn); 575 575 576 576 has_read = ops->seq_show || ops->read || ops->mmap; 577 577 has_write = ops->write || ops->mmap; ··· 612 612 else 613 613 mutex_init(&of->mutex); 614 614 615 - of->sd = attr_sd; 615 + of->kn = kn; 616 616 of->file = file; 617 617 618 618 /* ··· 634 634 file->f_mode |= FMODE_PWRITE; 635 635 636 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 638 if (error) 639 639 goto err_close; 640 640 641 641 /* open succeeded, put active references */ 642 - sysfs_put_active(attr_sd); 642 + sysfs_put_active(kn); 643 643 return 0; 644 644 645 645 err_close: ··· 647 647 err_free: 648 648 kfree(of); 649 649 err_out: 650 - sysfs_put_active(attr_sd); 650 + sysfs_put_active(kn); 651 651 return error; 652 652 } 653 653 654 654 static 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 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 660 seq_release(inode, filp); 661 661 kfree(of); 662 662 663 663 return 0; 664 664 } 665 665 666 - void sysfs_unmap_bin_file(struct sysfs_dirent *sd) 666 + void sysfs_unmap_bin_file(struct kernfs_node *kn) 667 667 { 668 668 struct sysfs_open_dirent *od; 669 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 672 return; 673 673 674 674 spin_lock_irq(&sysfs_open_dirent_lock); 675 - od = sd->s_attr.open; 675 + od = kn->s_attr.open; 676 676 if (od) 677 677 atomic_inc(&od->refcnt); 678 678 spin_unlock_irq(&sysfs_open_dirent_lock); ··· 686 686 } 687 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 692 /* Sysfs attribute files are pollable. The idea is that you read ··· 705 705 static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait) 706 706 { 707 707 struct sysfs_open_file *of = sysfs_of(filp); 708 - struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; 709 - struct sysfs_open_dirent *od = attr_sd->s_attr.open; 708 + struct kernfs_node *kn = filp->f_path.dentry->d_fsdata; 709 + struct sysfs_open_dirent *od = kn->s_attr.open; 710 710 711 711 /* need parent for the kobj, grab both */ 712 - if (!sysfs_get_active(attr_sd)) 712 + if (!sysfs_get_active(kn)) 713 713 goto trigger; 714 714 715 715 poll_wait(filp, &od->poll, wait); 716 716 717 - sysfs_put_active(attr_sd); 717 + sysfs_put_active(kn); 718 718 719 719 if (of->event != atomic_read(&od->event)) 720 720 goto trigger; ··· 727 727 728 728 /** 729 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 */ 734 - void kernfs_notify(struct sysfs_dirent *sd) 734 + void kernfs_notify(struct kernfs_node *kn) 735 735 { 736 736 struct sysfs_open_dirent *od; 737 737 unsigned long flags; 738 738 739 739 spin_lock_irqsave(&sysfs_open_dirent_lock, flags); 740 740 741 - if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) { 742 - od = sd->s_attr.open; 741 + if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) { 742 + od = kn->s_attr.open; 743 743 if (od) { 744 744 atomic_inc(&od->event); 745 745 wake_up_interruptible(&od->poll); ··· 773 773 * 774 774 * Returns the created node on success, ERR_PTR() value on error. 775 775 */ 776 - struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, 777 - const char *name, 778 - umode_t mode, loff_t size, 779 - const struct kernfs_ops *ops, 780 - void *priv, const void *ns, 781 - struct lock_class_key *key) 776 + struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent, 777 + const char *name, 778 + umode_t mode, loff_t size, 779 + const struct kernfs_ops *ops, 780 + void *priv, const void *ns, 781 + struct lock_class_key *key) 782 782 { 783 783 struct sysfs_addrm_cxt acxt; 784 - struct sysfs_dirent *sd; 784 + struct kernfs_node *kn; 785 785 int rc; 786 786 787 - sd = sysfs_new_dirent(kernfs_root(parent), name, 787 + kn = sysfs_new_dirent(kernfs_root(parent), name, 788 788 (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR); 789 - if (!sd) 789 + if (!kn) 790 790 return ERR_PTR(-ENOMEM); 791 791 792 - sd->s_attr.ops = ops; 793 - sd->s_attr.size = size; 794 - sd->s_ns = ns; 795 - sd->priv = priv; 792 + kn->s_attr.ops = ops; 793 + kn->s_attr.size = size; 794 + kn->s_ns = ns; 795 + kn->priv = priv; 796 796 797 797 #ifdef CONFIG_DEBUG_LOCK_ALLOC 798 798 if (key) { 799 - lockdep_init_map(&sd->dep_map, "s_active", key, 0); 800 - sd->s_flags |= SYSFS_FLAG_LOCKDEP; 799 + lockdep_init_map(&kn->dep_map, "s_active", key, 0); 800 + kn->s_flags |= SYSFS_FLAG_LOCKDEP; 801 801 } 802 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 806 * need to know whether some ops are implemented outside active 807 807 * ref. Cache their existence in flags. 808 808 */ 809 809 if (ops->seq_show) 810 - sd->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW; 810 + kn->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW; 811 811 if (ops->mmap) 812 - sd->s_flags |= SYSFS_FLAG_HAS_MMAP; 812 + kn->s_flags |= SYSFS_FLAG_HAS_MMAP; 813 813 814 814 sysfs_addrm_start(&acxt); 815 - rc = sysfs_add_one(&acxt, sd, parent); 815 + rc = sysfs_add_one(&acxt, kn, parent); 816 816 sysfs_addrm_finish(&acxt); 817 817 818 818 if (rc) { 819 - kernfs_put(sd); 819 + kernfs_put(kn); 820 820 return ERR_PTR(rc); 821 821 } 822 - return sd; 822 + return kn; 823 823 }
+62 -61
fs/kernfs/inode.c
··· 46 46 panic("failed to init sysfs_backing_dev_info"); 47 47 } 48 48 49 - static struct sysfs_inode_attrs *sysfs_inode_attrs(struct sysfs_dirent *sd) 49 + static struct sysfs_inode_attrs *sysfs_inode_attrs(struct kernfs_node *kn) 50 50 { 51 51 struct iattr *iattrs; 52 52 53 - if (sd->s_iattr) 54 - return sd->s_iattr; 53 + if (kn->s_iattr) 54 + return kn->s_iattr; 55 55 56 - sd->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL); 57 - if (!sd->s_iattr) 56 + kn->s_iattr = kzalloc(sizeof(struct sysfs_inode_attrs), GFP_KERNEL); 57 + if (!kn->s_iattr) 58 58 return NULL; 59 - iattrs = &sd->s_iattr->ia_iattr; 59 + iattrs = &kn->s_iattr->ia_iattr; 60 60 61 61 /* assign default attributes */ 62 - iattrs->ia_mode = sd->s_mode; 62 + iattrs->ia_mode = kn->s_mode; 63 63 iattrs->ia_uid = GLOBAL_ROOT_UID; 64 64 iattrs->ia_gid = GLOBAL_ROOT_GID; 65 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 72 - static int __kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) 72 + static int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr) 73 73 { 74 74 struct sysfs_inode_attrs *attrs; 75 75 struct iattr *iattrs; 76 76 unsigned int ia_valid = iattr->ia_valid; 77 77 78 - attrs = sysfs_inode_attrs(sd); 78 + attrs = sysfs_inode_attrs(kn); 79 79 if (!attrs) 80 80 return -ENOMEM; 81 81 ··· 93 93 iattrs->ia_ctime = iattr->ia_ctime; 94 94 if (ia_valid & ATTR_MODE) { 95 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 98 return 0; 99 99 } 100 100 101 101 /** 102 102 * kernfs_setattr - set iattr on a node 103 - * @sd: target node 103 + * @kn: target node 104 104 * @iattr: iattr to set 105 105 * 106 106 * Returns 0 on success, -errno on failure. 107 107 */ 108 - int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr) 108 + int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr) 109 109 { 110 110 int ret; 111 111 112 112 mutex_lock(&sysfs_mutex); 113 - ret = __kernfs_setattr(sd, iattr); 113 + ret = __kernfs_setattr(kn, iattr); 114 114 mutex_unlock(&sysfs_mutex); 115 115 return ret; 116 116 } ··· 118 118 int sysfs_setattr(struct dentry *dentry, struct iattr *iattr) 119 119 { 120 120 struct inode *inode = dentry->d_inode; 121 - struct sysfs_dirent *sd = dentry->d_fsdata; 121 + struct kernfs_node *kn = dentry->d_fsdata; 122 122 int error; 123 123 124 - if (!sd) 124 + if (!kn) 125 125 return -EINVAL; 126 126 127 127 mutex_lock(&sysfs_mutex); ··· 129 129 if (error) 130 130 goto out; 131 131 132 - error = __kernfs_setattr(sd, iattr); 132 + error = __kernfs_setattr(kn, iattr); 133 133 if (error) 134 134 goto out; 135 135 ··· 141 141 return error; 142 142 } 143 143 144 - static int sysfs_sd_setsecdata(struct sysfs_dirent *sd, void **secdata, 144 + static int sysfs_sd_setsecdata(struct kernfs_node *kn, void **secdata, 145 145 u32 *secdata_len) 146 146 { 147 147 struct sysfs_inode_attrs *attrs; 148 148 void *old_secdata; 149 149 size_t old_secdata_len; 150 150 151 - attrs = sysfs_inode_attrs(sd); 151 + attrs = sysfs_inode_attrs(kn); 152 152 if (!attrs) 153 153 return -ENOMEM; 154 154 ··· 166 166 int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value, 167 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 170 struct sysfs_inode_attrs *attrs; 171 171 void *secdata; 172 172 int error; 173 173 u32 secdata_len = 0; 174 174 175 - attrs = sysfs_inode_attrs(sd); 175 + attrs = sysfs_inode_attrs(kn); 176 176 if (!attrs) 177 177 return -ENOMEM; 178 178 ··· 188 188 return error; 189 189 190 190 mutex_lock(&sysfs_mutex); 191 - error = sysfs_sd_setsecdata(sd, &secdata, &secdata_len); 191 + error = sysfs_sd_setsecdata(kn, &secdata, &secdata_len); 192 192 mutex_unlock(&sysfs_mutex); 193 193 194 194 if (secdata) ··· 204 204 205 205 int 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 208 struct sysfs_inode_attrs *attrs; 209 209 210 - attrs = sysfs_inode_attrs(sd); 210 + attrs = sysfs_inode_attrs(kn); 211 211 if (!attrs) 212 212 return -ENOMEM; 213 213 ··· 217 217 ssize_t sysfs_getxattr(struct dentry *dentry, const char *name, void *buf, 218 218 size_t size) 219 219 { 220 - struct sysfs_dirent *sd = dentry->d_fsdata; 220 + struct kernfs_node *kn = dentry->d_fsdata; 221 221 struct sysfs_inode_attrs *attrs; 222 222 223 - attrs = sysfs_inode_attrs(sd); 223 + attrs = sysfs_inode_attrs(kn); 224 224 if (!attrs) 225 225 return -ENOMEM; 226 226 ··· 229 229 230 230 ssize_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 233 struct sysfs_inode_attrs *attrs; 234 234 235 - attrs = sysfs_inode_attrs(sd); 235 + attrs = sysfs_inode_attrs(kn); 236 236 if (!attrs) 237 237 return -ENOMEM; 238 238 ··· 254 254 inode->i_ctime = iattr->ia_ctime; 255 255 } 256 256 257 - static void sysfs_refresh_inode(struct sysfs_dirent *sd, struct inode *inode) 257 + static 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 262 if (attrs) { 263 - /* sysfs_dirent has non-default attributes 264 - * get them from persistent copy in sysfs_dirent 263 + /* 264 + * kernfs_node has non-default attributes get them from 265 + * persistent copy in kernfs_node. 265 266 */ 266 267 set_inode_attr(inode, &attrs->ia_iattr); 267 268 security_inode_notifysecctx(inode, attrs->ia_secdata, 268 269 attrs->ia_secdata_len); 269 270 } 270 271 271 - if (sysfs_type(sd) == SYSFS_DIR) 272 - set_nlink(inode, sd->s_dir.subdirs + 2); 272 + if (sysfs_type(kn) == SYSFS_DIR) 273 + set_nlink(inode, kn->s_dir.subdirs + 2); 273 274 } 274 275 275 276 int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, 276 277 struct kstat *stat) 277 278 { 278 - struct sysfs_dirent *sd = dentry->d_fsdata; 279 + struct kernfs_node *kn = dentry->d_fsdata; 279 280 struct inode *inode = dentry->d_inode; 280 281 281 282 mutex_lock(&sysfs_mutex); 282 - sysfs_refresh_inode(sd, inode); 283 + sysfs_refresh_inode(kn, inode); 283 284 mutex_unlock(&sysfs_mutex); 284 285 285 286 generic_fillattr(inode, stat); 286 287 return 0; 287 288 } 288 289 289 - static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode) 290 + static void sysfs_init_inode(struct kernfs_node *kn, struct inode *inode) 290 291 { 291 - kernfs_get(sd); 292 - inode->i_private = sd; 292 + kernfs_get(kn); 293 + inode->i_private = kn; 293 294 inode->i_mapping->a_ops = &sysfs_aops; 294 295 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 295 296 inode->i_op = &sysfs_inode_operations; 296 297 297 - set_default_inode_attr(inode, sd->s_mode); 298 - sysfs_refresh_inode(sd, inode); 298 + set_default_inode_attr(inode, kn->s_mode); 299 + sysfs_refresh_inode(kn, inode); 299 300 300 301 /* initialize inode according to type */ 301 - switch (sysfs_type(sd)) { 302 + switch (sysfs_type(kn)) { 302 303 case SYSFS_DIR: 303 304 inode->i_op = &sysfs_dir_inode_operations; 304 305 inode->i_fop = &sysfs_dir_operations; 305 306 break; 306 307 case SYSFS_KOBJ_ATTR: 307 - inode->i_size = sd->s_attr.size; 308 + inode->i_size = kn->s_attr.size; 308 309 inode->i_fop = &kernfs_file_operations; 309 310 break; 310 311 case SYSFS_KOBJ_LINK: ··· 319 318 } 320 319 321 320 /** 322 - * sysfs_get_inode - get inode for sysfs_dirent 321 + * sysfs_get_inode - get inode for kernfs_node 323 322 * @sb: super block 324 - * @sd: sysfs_dirent to allocate inode for 323 + * @kn: kernfs_node to allocate inode for 325 324 * 326 - * Get inode for @sd. If such inode doesn't exist, a new inode 327 - * is allocated and basics are initialized. New inode is 328 - * returned locked. 325 + * Get inode for @kn. If such inode doesn't exist, a new inode is 326 + * allocated and basics are initialized. New inode is returned 327 + * locked. 329 328 * 330 329 * LOCKING: 331 330 * Kernel thread context (may sleep). ··· 333 332 * RETURNS: 334 333 * Pointer to allocated inode on success, NULL on failure. 335 334 */ 336 - struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd) 335 + struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn) 337 336 { 338 337 struct inode *inode; 339 338 340 - inode = iget_locked(sb, sd->s_ino); 339 + inode = iget_locked(sb, kn->s_ino); 341 340 if (inode && (inode->i_state & I_NEW)) 342 - sysfs_init_inode(sd, inode); 341 + sysfs_init_inode(kn, inode); 343 342 344 343 return inode; 345 344 } 346 345 347 346 /* 348 - * The sysfs_dirent serves as both an inode and a directory entry for sysfs. 349 - * To prevent the sysfs inode numbers from being freed prematurely we take a 350 - * reference to sysfs_dirent from the sysfs inode. A 347 + * 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 349 + * a reference to kernfs_node from the sysfs inode. A 351 350 * super_operations.evict_inode() implementation is needed to drop that 352 351 * reference upon inode destruction. 353 352 */ 354 353 void sysfs_evict_inode(struct inode *inode) 355 354 { 356 - struct sysfs_dirent *sd = inode->i_private; 355 + struct kernfs_node *kn = inode->i_private; 357 356 358 357 truncate_inode_pages(&inode->i_data, 0); 359 358 clear_inode(inode); 360 - kernfs_put(sd); 359 + kernfs_put(kn); 361 360 } 362 361 363 362 int sysfs_permission(struct inode *inode, int mask) 364 363 { 365 - struct sysfs_dirent *sd; 364 + struct kernfs_node *kn; 366 365 367 366 if (mask & MAY_NOT_BLOCK) 368 367 return -ECHILD; 369 368 370 - sd = inode->i_private; 369 + kn = inode->i_private; 371 370 372 371 mutex_lock(&sysfs_mutex); 373 - sysfs_refresh_inode(sd, inode); 372 + sysfs_refresh_inode(kn, inode); 374 373 mutex_unlock(&sysfs_mutex); 375 374 376 375 return generic_permission(inode, mask);
+20 -20
fs/kernfs/kernfs-internal.h
··· 31 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 35 - * @sd: sysfs_dirent of interest 34 + * kernfs_root - find out the kernfs_root a kernfs_node belongs to 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 */ 39 - static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd) 39 + static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn) 40 40 { 41 41 /* if parent exists, it's always a dir; otherwise, @sd is a dir */ 42 - if (sd->s_parent) 43 - sd = sd->s_parent; 44 - return sd->s_dir.root; 42 + if (kn->s_parent) 43 + kn = kn->s_parent; 44 + return kn->s_dir.root; 45 45 } 46 46 47 47 /* 48 48 * Context structure to be used while adding/removing nodes. 49 49 */ 50 50 struct sysfs_addrm_cxt { 51 - struct sysfs_dirent *removed; 51 + struct kernfs_node *removed; 52 52 }; 53 53 54 54 /* ··· 62 62 struct kernfs_root *root; 63 63 64 64 /* 65 - * Each sb is associated with one namespace tag, currently the network 66 - * namespace of the task which mounted this sysfs instance. If multiple 67 - * tags become necessary, make the following an array and compare 68 - * sysfs_dirent tag against every entry. 65 + * Each sb is associated with one namespace tag, currently the 66 + * network namespace of the task which mounted this sysfs instance. 67 + * If multiple tags become necessary, make the following an array 68 + * and compare kernfs_node tag against every entry. 69 69 */ 70 70 const void *ns; 71 71 }; ··· 76 76 /* 77 77 * inode.c 78 78 */ 79 - struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd); 79 + struct inode *sysfs_get_inode(struct super_block *sb, struct kernfs_node *kn); 80 80 void sysfs_evict_inode(struct inode *inode); 81 81 int sysfs_permission(struct inode *inode, int mask); 82 82 int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); ··· 98 98 extern const struct file_operations sysfs_dir_operations; 99 99 extern const struct inode_operations sysfs_dir_inode_operations; 100 100 101 - struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); 102 - void sysfs_put_active(struct sysfs_dirent *sd); 101 + struct kernfs_node *sysfs_get_active(struct kernfs_node *kn); 102 + void sysfs_put_active(struct kernfs_node *kn); 103 103 void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt); 104 - int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, 105 - struct sysfs_dirent *parent_sd); 104 + int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct kernfs_node *kn, 105 + struct kernfs_node *parent); 106 106 void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); 107 - struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root, 108 - const char *name, umode_t mode, int type); 107 + struct kernfs_node *sysfs_new_dirent(struct kernfs_root *root, 108 + const char *name, umode_t mode, int type); 109 109 110 110 /* 111 111 * file.c 112 112 */ 113 113 extern const struct file_operations kernfs_file_operations; 114 114 115 - void sysfs_unmap_bin_file(struct sysfs_dirent *sd); 115 + void sysfs_unmap_bin_file(struct kernfs_node *kn); 116 116 117 117 /* 118 118 * symlink.c
+6 -6
fs/kernfs/mount.c
··· 39 39 40 40 /* get root inode, initialize and unlock it */ 41 41 mutex_lock(&sysfs_mutex); 42 - inode = sysfs_get_inode(sb, info->root->sd); 42 + inode = sysfs_get_inode(sb, info->root->kn); 43 43 mutex_unlock(&sysfs_mutex); 44 44 if (!inode) { 45 45 pr_debug("sysfs: could not get root inode\n"); ··· 52 52 pr_debug("%s: could not get root dentry!\n", __func__); 53 53 return -ENOMEM; 54 54 } 55 - kernfs_get(info->root->sd); 56 - root->d_fsdata = info->root->sd; 55 + kernfs_get(info->root->kn); 56 + root->d_fsdata = info->root->kn; 57 57 sb->s_root = root; 58 58 sb->s_d_op = &sysfs_dentry_ops; 59 59 return 0; ··· 145 145 void kernfs_kill_sb(struct super_block *sb) 146 146 { 147 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 151 * Remove the superblock from fs_supers/s_instances ··· 153 153 */ 154 154 kill_anon_super(sb); 155 155 kfree(info); 156 - kernfs_put(root_sd); 156 + kernfs_put(root_kn); 157 157 } 158 158 159 159 void __init kernfs_init(void) 160 160 { 161 161 sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache", 162 - sizeof(struct sysfs_dirent), 162 + sizeof(struct kernfs_node), 163 163 0, SLAB_PANIC, NULL); 164 164 sysfs_inode_init(); 165 165 }
+32 -32
fs/kernfs/symlink.c
··· 22 22 * 23 23 * Returns the created node on success, ERR_PTR() value on error. 24 24 */ 25 - struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, 26 - const char *name, 27 - struct sysfs_dirent *target) 25 + struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, 26 + const char *name, 27 + struct kernfs_node *target) 28 28 { 29 - struct sysfs_dirent *sd; 29 + struct kernfs_node *kn; 30 30 struct sysfs_addrm_cxt acxt; 31 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 34 SYSFS_KOBJ_LINK); 35 - if (!sd) 35 + if (!kn) 36 36 return ERR_PTR(-ENOMEM); 37 37 38 38 if (kernfs_ns_enabled(parent)) 39 - sd->s_ns = target->s_ns; 40 - sd->s_symlink.target_sd = target; 39 + kn->s_ns = target->s_ns; 40 + kn->s_symlink.target_kn = target; 41 41 kernfs_get(target); /* ref owned by symlink */ 42 42 43 43 sysfs_addrm_start(&acxt); 44 - error = sysfs_add_one(&acxt, sd, parent); 44 + error = sysfs_add_one(&acxt, kn, parent); 45 45 sysfs_addrm_finish(&acxt); 46 46 47 47 if (!error) 48 - return sd; 48 + return kn; 49 49 50 - kernfs_put(sd); 50 + kernfs_put(kn); 51 51 return ERR_PTR(error); 52 52 } 53 53 54 - static int sysfs_get_target_path(struct sysfs_dirent *parent_sd, 55 - struct sysfs_dirent *target_sd, char *path) 54 + static int sysfs_get_target_path(struct kernfs_node *parent, 55 + struct kernfs_node *target, char *path) 56 56 { 57 - struct sysfs_dirent *base, *sd; 57 + struct kernfs_node *base, *kn; 58 58 char *s = path; 59 59 int len = 0; 60 60 61 61 /* go up to the root, stop at the base */ 62 - base = parent_sd; 62 + base = parent; 63 63 while (base->s_parent) { 64 - sd = target_sd->s_parent; 65 - while (sd->s_parent && base != sd) 66 - sd = sd->s_parent; 64 + kn = target->s_parent; 65 + while (kn->s_parent && base != kn) 66 + kn = kn->s_parent; 67 67 68 - if (base == sd) 68 + if (base == kn) 69 69 break; 70 70 71 71 strcpy(s, "../"); ··· 74 74 } 75 75 76 76 /* determine end of target string for reverse fillup */ 77 - sd = target_sd; 78 - while (sd->s_parent && sd != base) { 79 - len += strlen(sd->s_name) + 1; 80 - sd = sd->s_parent; 77 + kn = target; 78 + while (kn->s_parent && kn != base) { 79 + len += strlen(kn->s_name) + 1; 80 + kn = kn->s_parent; 81 81 } 82 82 83 83 /* check limits */ ··· 88 88 return -ENAMETOOLONG; 89 89 90 90 /* reverse fillup of target string from target to base */ 91 - sd = target_sd; 92 - while (sd->s_parent && sd != base) { 93 - int slen = strlen(sd->s_name); 91 + kn = target; 92 + while (kn->s_parent && kn != base) { 93 + int slen = strlen(kn->s_name); 94 94 95 95 len -= slen; 96 - strncpy(s + len, sd->s_name, slen); 96 + strncpy(s + len, kn->s_name, slen); 97 97 if (len) 98 98 s[--len] = '/'; 99 99 100 - sd = sd->s_parent; 100 + kn = kn->s_parent; 101 101 } 102 102 103 103 return 0; ··· 105 105 106 106 static int sysfs_getlink(struct dentry *dentry, char *path) 107 107 { 108 - struct sysfs_dirent *sd = dentry->d_fsdata; 109 - struct sysfs_dirent *parent_sd = sd->s_parent; 110 - struct sysfs_dirent *target_sd = sd->s_symlink.target_sd; 108 + struct kernfs_node *kn = dentry->d_fsdata; 109 + struct kernfs_node *parent = kn->s_parent; 110 + struct kernfs_node *target = kn->s_symlink.target_kn; 111 111 int error; 112 112 113 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 115 mutex_unlock(&sysfs_mutex); 116 116 117 117 return error;
+33 -33
fs/sysfs/dir.c
··· 21 21 22 22 /** 23 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 25 * @path: caller allocated buffer of size PATH_MAX 26 26 * 27 27 * Gives the name "/" to the sysfs_root entry; any path returned 28 28 * is relative to wherever sysfs is mounted. 29 29 */ 30 - static char *sysfs_pathname(struct sysfs_dirent *sd, char *path) 30 + static char *sysfs_pathname(struct kernfs_node *kn, char *path) 31 31 { 32 - if (sd->s_parent) { 33 - sysfs_pathname(sd->s_parent, path); 32 + if (kn->s_parent) { 33 + sysfs_pathname(kn->s_parent, path); 34 34 strlcat(path, "/", PATH_MAX); 35 35 } 36 - strlcat(path, sd->s_name, PATH_MAX); 36 + strlcat(path, kn->s_name, PATH_MAX); 37 37 return path; 38 38 } 39 39 40 - void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name) 40 + void sysfs_warn_dup(struct kernfs_node *parent, const char *name) 41 41 { 42 42 char *path; 43 43 ··· 61 61 */ 62 62 int 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 66 BUG_ON(!kobj); 67 67 68 68 if (kobj->parent) 69 - parent_sd = kobj->parent->sd; 69 + parent = kobj->parent->sd; 70 70 else 71 - parent_sd = sysfs_root_sd; 71 + parent = sysfs_root_kn; 72 72 73 - if (!parent_sd) 73 + if (!parent) 74 74 return -ENOENT; 75 75 76 - sd = kernfs_create_dir_ns(parent_sd, kobject_name(kobj), kobj, ns); 77 - if (IS_ERR(sd)) { 78 - if (PTR_ERR(sd) == -EEXIST) 79 - sysfs_warn_dup(parent_sd, kobject_name(kobj)); 80 - return PTR_ERR(sd); 76 + kn = kernfs_create_dir_ns(parent, kobject_name(kobj), kobj, ns); 77 + if (IS_ERR(kn)) { 78 + if (PTR_ERR(kn) == -EEXIST) 79 + sysfs_warn_dup(parent, kobject_name(kobj)); 80 + return PTR_ERR(kn); 81 81 } 82 82 83 - kobj->sd = sd; 83 + kobj->sd = kn; 84 84 return 0; 85 85 } 86 86 ··· 94 94 */ 95 95 void 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 100 * In general, kboject owner is responsible for ensuring removal 101 101 * doesn't race with other operations and sysfs doesn't provide any 102 102 * protection; however, when @kobj is used as a symlink target, the 103 103 * symlinking entity usually doesn't own @kobj and thus has no 104 - * control over removal. @kobj->sd may be removed anytime and 105 - * symlink code may end up dereferencing an already freed sd. 104 + * control over removal. @kobj->sd may be removed anytime 105 + * and symlink code may end up dereferencing an already freed node. 106 106 * 107 - * sysfs_symlink_target_lock synchronizes @kobj->sd disassociation 108 - * against symlink operations so that symlink code can safely 109 - * dereference @kobj->sd. 107 + * sysfs_symlink_target_lock synchronizes @kobj->sd 108 + * disassociation against symlink operations so that symlink code 109 + * can safely dereference @kobj->sd. 110 110 */ 111 111 spin_lock(&sysfs_symlink_target_lock); 112 112 kobj->sd = NULL; 113 113 spin_unlock(&sysfs_symlink_target_lock); 114 114 115 - if (sd) { 116 - WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); 117 - kernfs_remove(sd); 115 + if (kn) { 116 + WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR); 117 + kernfs_remove(kn); 118 118 } 119 119 } 120 120 121 121 int sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, 122 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 129 129 int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, 130 130 const void *new_ns) 131 131 { 132 - struct sysfs_dirent *sd = kobj->sd; 133 - struct sysfs_dirent *new_parent_sd; 132 + struct kernfs_node *kn = kobj->sd; 133 + struct kernfs_node *new_parent; 134 134 135 - BUG_ON(!sd->s_parent); 136 - new_parent_sd = new_parent_kobj && new_parent_kobj->sd ? 137 - new_parent_kobj->sd : sysfs_root_sd; 135 + BUG_ON(!kn->s_parent); 136 + new_parent = new_parent_kobj && new_parent_kobj->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 }
+61 -61
fs/sysfs/file.c
··· 22 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 26 * must be called while holding an active reference. 27 27 */ 28 - static const struct sysfs_ops *sysfs_file_ops(struct sysfs_dirent *sd) 28 + static 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) 33 - lockdep_assert_held(sd); 32 + if (kn->s_flags & SYSFS_FLAG_LOCKDEP) 33 + lockdep_assert_held(kn); 34 34 return kobj->ktype ? kobj->ktype->sysfs_ops : NULL; 35 35 } 36 36 ··· 42 42 static int sysfs_kf_seq_show(struct seq_file *sf, void *v) 43 43 { 44 44 struct sysfs_open_file *of = sf->private; 45 - struct kobject *kobj = of->sd->s_parent->priv; 46 - const struct sysfs_ops *ops = sysfs_file_ops(of->sd); 45 + struct kobject *kobj = of->kn->s_parent->priv; 46 + const struct sysfs_ops *ops = sysfs_file_ops(of->kn); 47 47 ssize_t count; 48 48 char *buf; 49 49 ··· 59 59 * if @ops->show() isn't implemented. 60 60 */ 61 61 if (ops->show) { 62 - count = ops->show(kobj, of->sd->priv, buf); 62 + count = ops->show(kobj, of->kn->priv, buf); 63 63 if (count < 0) 64 64 return count; 65 65 } ··· 81 81 static ssize_t sysfs_kf_bin_read(struct sysfs_open_file *of, char *buf, 82 82 size_t count, loff_t pos) 83 83 { 84 - struct bin_attribute *battr = of->sd->priv; 85 - struct kobject *kobj = of->sd->s_parent->priv; 84 + struct bin_attribute *battr = of->kn->priv; 85 + struct kobject *kobj = of->kn->s_parent->priv; 86 86 loff_t size = file_inode(of->file)->i_size; 87 87 88 88 if (!count) ··· 105 105 static ssize_t sysfs_kf_write(struct sysfs_open_file *of, char *buf, 106 106 size_t count, loff_t pos) 107 107 { 108 - const struct sysfs_ops *ops = sysfs_file_ops(of->sd); 109 - struct kobject *kobj = of->sd->s_parent->priv; 108 + const struct sysfs_ops *ops = sysfs_file_ops(of->kn); 109 + struct kobject *kobj = of->kn->s_parent->priv; 110 110 111 111 if (!count) 112 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 117 /* kernfs write callback for bin sysfs files */ 118 118 static ssize_t sysfs_kf_bin_write(struct sysfs_open_file *of, char *buf, 119 119 size_t count, loff_t pos) 120 120 { 121 - struct bin_attribute *battr = of->sd->priv; 122 - struct kobject *kobj = of->sd->s_parent->priv; 121 + struct bin_attribute *battr = of->kn->priv; 122 + struct kobject *kobj = of->kn->s_parent->priv; 123 123 loff_t size = file_inode(of->file)->i_size; 124 124 125 125 if (size) { ··· 139 139 static int sysfs_kf_bin_mmap(struct sysfs_open_file *of, 140 140 struct vm_area_struct *vma) 141 141 { 142 - struct bin_attribute *battr = of->sd->priv; 143 - struct kobject *kobj = of->sd->s_parent->priv; 142 + struct bin_attribute *battr = of->kn->priv; 143 + struct kobject *kobj = of->kn->s_parent->priv; 144 144 145 145 return battr->mmap(of->file, kobj, battr, vma); 146 146 } 147 147 148 - void sysfs_notify(struct kobject *k, const char *dir, const char *attr) 148 + void 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) 153 - sd = kernfs_find_and_get(sd, dir); 152 + if (kn && dir) 153 + kn = kernfs_find_and_get(kn, dir); 154 154 else 155 - kernfs_get(sd); 155 + kernfs_get(kn); 156 156 157 - if (sd && attr) { 158 - tmp = kernfs_find_and_get(sd, attr); 159 - kernfs_put(sd); 160 - sd = tmp; 157 + if (kn && attr) { 158 + tmp = kernfs_find_and_get(kn, attr); 159 + kernfs_put(kn); 160 + kn = tmp; 161 161 } 162 162 163 - if (sd) { 164 - kernfs_notify(sd); 165 - kernfs_put(sd); 163 + if (kn) { 164 + kernfs_notify(kn); 165 + kernfs_put(kn); 166 166 } 167 167 } 168 168 EXPORT_SYMBOL_GPL(sysfs_notify); ··· 202 202 .mmap = sysfs_kf_bin_mmap, 203 203 }; 204 204 205 - int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, 205 + int sysfs_add_file_mode_ns(struct kernfs_node *parent, 206 206 const struct attribute *attr, bool is_bin, 207 207 umode_t mode, const void *ns) 208 208 { 209 209 struct lock_class_key *key = NULL; 210 210 const struct kernfs_ops *ops; 211 - struct sysfs_dirent *sd; 211 + struct kernfs_node *kn; 212 212 loff_t size; 213 213 214 214 if (!is_bin) { 215 - struct kobject *kobj = dir_sd->priv; 215 + struct kobject *kobj = parent->priv; 216 216 const struct sysfs_ops *sysfs_ops = kobj->ktype->sysfs_ops; 217 217 218 218 /* every kobject with an attribute needs a ktype assigned */ ··· 252 252 if (!attr->ignore_lockdep) 253 253 key = attr->key ?: (struct lock_class_key *)&attr->skey; 254 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 256 ops, (void *)attr, ns, key); 257 - if (IS_ERR(sd)) { 258 - if (PTR_ERR(sd) == -EEXIST) 259 - sysfs_warn_dup(dir_sd, attr->name); 260 - return PTR_ERR(sd); 257 + if (IS_ERR(kn)) { 258 + if (PTR_ERR(kn) == -EEXIST) 259 + sysfs_warn_dup(parent, attr->name); 260 + return PTR_ERR(kn); 261 261 } 262 262 return 0; 263 263 } 264 264 265 - int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, 265 + int sysfs_add_file(struct kernfs_node *parent, const struct attribute *attr, 266 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 307 int sysfs_add_file_to_group(struct kobject *kobj, 308 308 const struct attribute *attr, const char *group) 309 309 { 310 - struct sysfs_dirent *dir_sd; 310 + struct kernfs_node *parent; 311 311 int error; 312 312 313 313 if (group) { 314 - dir_sd = kernfs_find_and_get(kobj->sd, group); 314 + parent = kernfs_find_and_get(kobj->sd, group); 315 315 } else { 316 - dir_sd = kobj->sd; 317 - kernfs_get(dir_sd); 316 + parent = kobj->sd; 317 + kernfs_get(parent); 318 318 } 319 319 320 - if (!dir_sd) 320 + if (!parent) 321 321 return -ENOENT; 322 322 323 - error = sysfs_add_file(dir_sd, attr, false); 324 - kernfs_put(dir_sd); 323 + error = sysfs_add_file(parent, attr, false); 324 + kernfs_put(parent); 325 325 326 326 return error; 327 327 } ··· 337 337 int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr, 338 338 umode_t mode) 339 339 { 340 - struct sysfs_dirent *sd; 340 + struct kernfs_node *kn; 341 341 struct iattr newattrs; 342 342 int rc; 343 343 344 - sd = kernfs_find_and_get(kobj->sd, attr->name); 345 - if (!sd) 344 + kn = kernfs_find_and_get(kobj->sd, attr->name); 345 + if (!kn) 346 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 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 354 return rc; 355 355 } 356 356 EXPORT_SYMBOL_GPL(sysfs_chmod_file); ··· 366 366 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, 367 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 } 373 373 EXPORT_SYMBOL_GPL(sysfs_remove_file_ns); 374 374 ··· 389 389 void sysfs_remove_file_from_group(struct kobject *kobj, 390 390 const struct attribute *attr, const char *group) 391 391 { 392 - struct sysfs_dirent *dir_sd; 392 + struct kernfs_node *parent; 393 393 394 394 if (group) { 395 - dir_sd = kernfs_find_and_get(kobj->sd, group); 395 + parent = kernfs_find_and_get(kobj->sd, group); 396 396 } else { 397 - dir_sd = kobj->sd; 398 - kernfs_get(dir_sd); 397 + parent = kobj->sd; 398 + kernfs_get(parent); 399 399 } 400 400 401 - if (dir_sd) { 402 - kernfs_remove_by_name(dir_sd, attr->name); 403 - kernfs_put(dir_sd); 401 + if (parent) { 402 + kernfs_remove_by_name(parent, attr->name); 403 + kernfs_put(parent); 404 404 } 405 405 } 406 406 EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
+48 -48
fs/sysfs/group.c
··· 18 18 #include "sysfs.h" 19 19 20 20 21 - static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 21 + static void remove_files(struct kernfs_node *parent, struct kobject *kobj, 22 22 const struct attribute_group *grp) 23 23 { 24 24 struct attribute *const *attr; ··· 26 26 27 27 if (grp->attrs) 28 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 30 if (grp->bin_attrs) 31 31 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) 32 32 sysfs_remove_bin_file(kobj, *bin_attr); 33 33 } 34 34 35 - static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, 35 + static int create_files(struct kernfs_node *parent, struct kobject *kobj, 36 36 const struct attribute_group *grp, int update) 37 37 { 38 38 struct attribute *const *attr; ··· 49 49 * re-adding (if required) the file. 50 50 */ 51 51 if (update) 52 - kernfs_remove_by_name(dir_sd, (*attr)->name); 52 + kernfs_remove_by_name(parent, (*attr)->name); 53 53 if (grp->is_visible) { 54 54 mode = grp->is_visible(kobj, *attr, i); 55 55 if (!mode) 56 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 59 (*attr)->mode | mode, 60 60 NULL); 61 61 if (unlikely(error)) 62 62 break; 63 63 } 64 64 if (error) { 65 - remove_files(dir_sd, kobj, grp); 65 + remove_files(parent, kobj, grp); 66 66 goto exit; 67 67 } 68 68 } ··· 76 76 break; 77 77 } 78 78 if (error) 79 - remove_files(dir_sd, kobj, grp); 79 + remove_files(parent, kobj, grp); 80 80 } 81 81 exit: 82 82 return error; ··· 86 86 static int internal_create_group(struct kobject *kobj, int update, 87 87 const struct attribute_group *grp) 88 88 { 89 - struct sysfs_dirent *sd; 89 + struct kernfs_node *kn; 90 90 int error; 91 91 92 92 BUG_ON(!kobj || (!update && !kobj->sd)); ··· 100 100 return -EINVAL; 101 101 } 102 102 if (grp->name) { 103 - sd = kernfs_create_dir(kobj->sd, grp->name, kobj); 104 - if (IS_ERR(sd)) { 105 - if (PTR_ERR(sd) == -EEXIST) 103 + kn = kernfs_create_dir(kobj->sd, grp->name, kobj); 104 + if (IS_ERR(kn)) { 105 + if (PTR_ERR(kn) == -EEXIST) 106 106 sysfs_warn_dup(kobj->sd, grp->name); 107 - return PTR_ERR(sd); 107 + return PTR_ERR(kn); 108 108 } 109 109 } else 110 - sd = kobj->sd; 111 - kernfs_get(sd); 112 - error = create_files(sd, kobj, grp, update); 110 + kn = kobj->sd; 111 + kernfs_get(kn); 112 + error = create_files(kn, kobj, grp, update); 113 113 if (error) { 114 114 if (grp->name) 115 - kernfs_remove(sd); 115 + kernfs_remove(kn); 116 116 } 117 - kernfs_put(sd); 117 + kernfs_put(kn); 118 118 return error; 119 119 } 120 120 ··· 204 204 void sysfs_remove_group(struct kobject *kobj, 205 205 const struct attribute_group *grp) 206 206 { 207 - struct sysfs_dirent *dir_sd = kobj->sd; 208 - struct sysfs_dirent *sd; 207 + struct kernfs_node *parent = kobj->sd; 208 + struct kernfs_node *kn; 209 209 210 210 if (grp->name) { 211 - sd = kernfs_find_and_get(dir_sd, grp->name); 212 - if (!sd) { 213 - WARN(!sd, KERN_WARNING 211 + kn = kernfs_find_and_get(parent, grp->name); 212 + if (!kn) { 213 + WARN(!kn, KERN_WARNING 214 214 "sysfs group %p not found for kobject '%s'\n", 215 215 grp, kobject_name(kobj)); 216 216 return; 217 217 } 218 218 } else { 219 - sd = dir_sd; 220 - kernfs_get(sd); 219 + kn = parent; 220 + kernfs_get(kn); 221 221 } 222 222 223 - remove_files(sd, kobj, grp); 223 + remove_files(kn, kobj, grp); 224 224 if (grp->name) 225 - kernfs_remove(sd); 225 + kernfs_remove(kn); 226 226 227 - kernfs_put(sd); 227 + kernfs_put(kn); 228 228 } 229 229 EXPORT_SYMBOL_GPL(sysfs_remove_group); 230 230 ··· 260 260 int sysfs_merge_group(struct kobject *kobj, 261 261 const struct attribute_group *grp) 262 262 { 263 - struct sysfs_dirent *dir_sd; 263 + struct kernfs_node *parent; 264 264 int error = 0; 265 265 struct attribute *const *attr; 266 266 int i; 267 267 268 - dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 269 - if (!dir_sd) 268 + parent = kernfs_find_and_get(kobj->sd, grp->name); 269 + if (!parent) 270 270 return -ENOENT; 271 271 272 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 274 if (error) { 275 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 280 return error; 281 281 } ··· 289 289 void sysfs_unmerge_group(struct kobject *kobj, 290 290 const struct attribute_group *grp) 291 291 { 292 - struct sysfs_dirent *dir_sd; 292 + struct kernfs_node *parent; 293 293 struct attribute *const *attr; 294 294 295 - dir_sd = kernfs_find_and_get(kobj->sd, grp->name); 296 - if (dir_sd) { 295 + parent = kernfs_find_and_get(kobj->sd, grp->name); 296 + if (parent) { 297 297 for (attr = grp->attrs; *attr; ++attr) 298 - kernfs_remove_by_name(dir_sd, (*attr)->name); 299 - kernfs_put(dir_sd); 298 + kernfs_remove_by_name(parent, (*attr)->name); 299 + kernfs_put(parent); 300 300 } 301 301 } 302 302 EXPORT_SYMBOL_GPL(sysfs_unmerge_group); ··· 311 311 int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, 312 312 struct kobject *target, const char *link_name) 313 313 { 314 - struct sysfs_dirent *dir_sd; 314 + struct kernfs_node *parent; 315 315 int error = 0; 316 316 317 - dir_sd = kernfs_find_and_get(kobj->sd, group_name); 318 - if (!dir_sd) 317 + parent = kernfs_find_and_get(kobj->sd, group_name); 318 + if (!parent) 319 319 return -ENOENT; 320 320 321 - error = sysfs_create_link_sd(dir_sd, target, link_name); 322 - kernfs_put(dir_sd); 321 + error = sysfs_create_link_sd(parent, target, link_name); 322 + kernfs_put(parent); 323 323 324 324 return error; 325 325 } ··· 334 334 void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, 335 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); 340 - if (dir_sd) { 341 - kernfs_remove_by_name(dir_sd, link_name); 342 - kernfs_put(dir_sd); 339 + parent = kernfs_find_and_get(kobj->sd, group_name); 340 + if (parent) { 341 + kernfs_remove_by_name(parent, link_name); 342 + kernfs_put(parent); 343 343 } 344 344 } 345 345 EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
+2 -2
fs/sysfs/mount.c
··· 20 20 #include "sysfs.h" 21 21 22 22 static struct kernfs_root *sysfs_root; 23 - struct sysfs_dirent *sysfs_root_sd; 23 + struct kernfs_node *sysfs_root_kn; 24 24 25 25 static struct dentry *sysfs_mount(struct file_system_type *fs_type, 26 26 int flags, const char *dev_name, void *data) ··· 66 66 if (IS_ERR(sysfs_root)) 67 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 71 err = register_filesystem(&sysfs_fs_type); 72 72 if (err) {
+36 -36
fs/sysfs/symlink.c
··· 18 18 19 19 #include "sysfs.h" 20 20 21 - static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd, 22 - struct kobject *target, 21 + static int sysfs_do_create_link_sd(struct kernfs_node *parent, 22 + struct kobject *target_kobj, 23 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 31 * Synchronize using sysfs_symlink_target_lock. See 32 32 * sysfs_remove_dir() for details. 33 33 */ 34 34 spin_lock(&sysfs_symlink_target_lock); 35 - if (target->sd) { 36 - target_sd = target->sd; 37 - kernfs_get(target_sd); 35 + if (target_kobj->sd) { 36 + target = target_kobj->sd; 37 + kernfs_get(target); 38 38 } 39 39 spin_unlock(&sysfs_symlink_target_lock); 40 40 41 - if (!target_sd) 41 + if (!target) 42 42 return -ENOENT; 43 43 44 - sd = kernfs_create_link(parent_sd, name, target_sd); 45 - kernfs_put(target_sd); 44 + kn = kernfs_create_link(parent, name, target); 45 + kernfs_put(target); 46 46 47 - if (!IS_ERR(sd)) 47 + if (!IS_ERR(kn)) 48 48 return 0; 49 49 50 - if (warn && PTR_ERR(sd) == -EEXIST) 51 - sysfs_warn_dup(parent_sd, name); 52 - return PTR_ERR(sd); 50 + if (warn && PTR_ERR(kn) == -EEXIST) 51 + sysfs_warn_dup(parent, name); 52 + return PTR_ERR(kn); 53 53 } 54 54 55 55 /** 56 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 58 * @target: object we're pointing to. 59 59 * @name: name of the symlink. 60 60 */ 61 - int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, 61 + int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target, 62 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 67 67 static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target, 68 68 const char *name, int warn) 69 69 { 70 - struct sysfs_dirent *parent_sd = NULL; 70 + struct kernfs_node *parent = NULL; 71 71 72 72 if (!kobj) 73 - parent_sd = sysfs_root_sd; 73 + parent = sysfs_root_kn; 74 74 else 75 - parent_sd = kobj->sd; 75 + parent = kobj->sd; 76 76 77 - if (!parent_sd) 77 + if (!parent) 78 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 141 */ 142 142 void 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 146 if (!kobj) 147 - parent_sd = sysfs_root_sd; 147 + parent = sysfs_root_kn; 148 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 } 153 153 EXPORT_SYMBOL_GPL(sysfs_remove_link); 154 154 ··· 165 165 int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *targ, 166 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 169 const void *old_ns = NULL; 170 170 int result; 171 171 172 172 if (!kobj) 173 - parent_sd = sysfs_root_sd; 173 + parent = sysfs_root_kn; 174 174 else 175 - parent_sd = kobj->sd; 175 + parent = kobj->sd; 176 176 177 177 if (targ->sd) 178 178 old_ns = targ->sd->s_ns; 179 179 180 180 result = -ENOENT; 181 - sd = kernfs_find_and_get_ns(parent_sd, old, old_ns); 182 - if (!sd) 181 + kn = kernfs_find_and_get_ns(parent, old, old_ns); 182 + if (!kn) 183 183 goto out; 184 184 185 185 result = -EINVAL; 186 - if (sysfs_type(sd) != SYSFS_KOBJ_LINK) 186 + if (sysfs_type(kn) != SYSFS_KOBJ_LINK) 187 187 goto out; 188 - if (sd->s_symlink.target_sd->priv != targ) 188 + if (kn->s_symlink.target_kn->priv != targ) 189 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 193 193 out: 194 - kernfs_put(sd); 194 + kernfs_put(kn); 195 195 return result; 196 196 } 197 197 EXPORT_SYMBOL_GPL(sysfs_rename_link_ns);
+5 -5
fs/sysfs/sysfs.h
··· 16 16 /* 17 17 * mount.c 18 18 */ 19 - extern struct sysfs_dirent *sysfs_root_sd; 19 + extern struct kernfs_node *sysfs_root_kn; 20 20 21 21 /* 22 22 * dir.c 23 23 */ 24 24 extern spinlock_t sysfs_symlink_target_lock; 25 25 26 - void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name); 26 + void sysfs_warn_dup(struct kernfs_node *parent, const char *name); 27 27 28 28 /* 29 29 * file.c 30 30 */ 31 - int sysfs_add_file(struct sysfs_dirent *dir_sd, 31 + int sysfs_add_file(struct kernfs_node *parent, 32 32 const struct attribute *attr, bool is_bin); 33 - int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd, 33 + int sysfs_add_file_mode_ns(struct kernfs_node *parent, 34 34 const struct attribute *attr, bool is_bin, 35 35 umode_t amode, const void *ns); 36 36 37 37 /* 38 38 * symlink.c 39 39 */ 40 - int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target, 40 + int sysfs_create_link_sd(struct kernfs_node *kn, struct kobject *target, 41 41 const char *name); 42 42 43 43 #endif /* __SYSFS_INTERNAL_H */
+83 -83
include/linux/kernfs.h
··· 46 46 SYSFS_FLAG_LOCKDEP = 0x0100, 47 47 }; 48 48 49 - /* type-specific structures for sysfs_dirent->s_* union members */ 50 - struct sysfs_elem_dir { 49 + /* type-specific structures for kernfs_node union members */ 50 + struct kernfs_elem_dir { 51 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 53 struct rb_root children; 54 54 55 55 /* 56 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 59 struct kernfs_root *root; 60 60 }; 61 61 62 - struct sysfs_elem_symlink { 63 - struct sysfs_dirent *target_sd; 62 + struct kernfs_elem_symlink { 63 + struct kernfs_node *target_kn; 64 64 }; 65 65 66 - struct sysfs_elem_attr { 66 + struct kernfs_elem_attr { 67 67 const struct kernfs_ops *ops; 68 68 struct sysfs_open_dirent *open; 69 69 loff_t size; 70 70 }; 71 71 72 72 /* 73 - * sysfs_dirent - the building block of sysfs hierarchy. Each and every 74 - * sysfs node is represented by single sysfs_dirent. Most fields are 73 + * kernfs_node - the building block of kernfs hierarchy. Each and every 74 + * kernfs node is represented by single kernfs_node. Most fields are 75 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 78 - * accessible. Dereferencing s_elem or any other outer entity 79 - * requires s_active reference. 77 + * As long as s_count reference is held, the kernfs_node itself is 78 + * accessible. Dereferencing elem or any other outer entity requires 79 + * active reference. 80 80 */ 81 - struct sysfs_dirent { 81 + struct kernfs_node { 82 82 atomic_t s_count; 83 83 atomic_t s_active; 84 84 #ifdef CONFIG_DEBUG_LOCK_ALLOC 85 85 struct lockdep_map dep_map; 86 86 #endif 87 87 /* the following two fields are published */ 88 - struct sysfs_dirent *s_parent; 88 + struct kernfs_node *s_parent; 89 89 const char *s_name; 90 90 91 91 struct rb_node s_rb; 92 92 93 93 union { 94 94 struct completion *completion; 95 - struct sysfs_dirent *removed_list; 95 + struct kernfs_node *removed_list; 96 96 } u; 97 97 98 98 const void *s_ns; /* namespace tag */ 99 99 unsigned int s_hash; /* ns + name hash */ 100 100 union { 101 - struct sysfs_elem_dir s_dir; 102 - struct sysfs_elem_symlink s_symlink; 103 - struct sysfs_elem_attr s_attr; 101 + struct kernfs_elem_dir s_dir; 102 + struct kernfs_elem_symlink s_symlink; 103 + struct kernfs_elem_attr s_attr; 104 104 }; 105 105 106 106 void *priv; ··· 113 113 114 114 struct kernfs_root { 115 115 /* published fields */ 116 - struct sysfs_dirent *sd; 116 + struct kernfs_node *kn; 117 117 118 118 /* private fields, do not use outside kernfs proper */ 119 119 struct ida ino_ida; ··· 121 121 122 122 struct sysfs_open_file { 123 123 /* published fields */ 124 - struct sysfs_dirent *sd; 124 + struct kernfs_node *kn; 125 125 struct file *file; 126 126 127 127 /* private fields, do not use outside kernfs proper */ ··· 170 170 171 171 #ifdef CONFIG_SYSFS 172 172 173 - static inline enum kernfs_node_type sysfs_type(struct sysfs_dirent *sd) 173 + static 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 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 183 - * under it. All children of @sd must have non-NULL namespace tags and 182 + * This is to be called right after @kn is created to enable namespace 183 + * under it. All children of @kn must have non-NULL namespace tags and 184 184 * only the ones which match the super_block's tag will be visible. 185 185 */ 186 - static inline void kernfs_enable_ns(struct sysfs_dirent *sd) 186 + static inline void kernfs_enable_ns(struct kernfs_node *kn) 187 187 { 188 - WARN_ON_ONCE(sysfs_type(sd) != SYSFS_DIR); 189 - WARN_ON_ONCE(!RB_EMPTY_ROOT(&sd->s_dir.children)); 190 - sd->s_flags |= SYSFS_FLAG_NS; 188 + WARN_ON_ONCE(sysfs_type(kn) != SYSFS_DIR); 189 + WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->s_dir.children)); 190 + kn->s_flags |= SYSFS_FLAG_NS; 191 191 } 192 192 193 193 /** 194 194 * kernfs_ns_enabled - test whether namespace is enabled 195 - * @sd: the node to test 195 + * @kn: the node to test 196 196 * 197 197 * Test whether namespace filtering is enabled for the children of @ns. 198 198 */ 199 - static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd) 199 + static 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 204 - struct sysfs_dirent *kernfs_find_and_get_ns(struct sysfs_dirent *parent, 205 - const char *name, const void *ns); 206 - void kernfs_get(struct sysfs_dirent *sd); 207 - void kernfs_put(struct sysfs_dirent *sd); 204 + struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, 205 + const char *name, const void *ns); 206 + void kernfs_get(struct kernfs_node *kn); 207 + void kernfs_put(struct kernfs_node *kn); 208 208 209 209 struct kernfs_root *kernfs_create_root(void *priv); 210 210 void kernfs_destroy_root(struct kernfs_root *root); 211 211 212 - struct sysfs_dirent *kernfs_create_dir_ns(struct sysfs_dirent *parent, 213 - const char *name, void *priv, 214 - const void *ns); 215 - struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent, 216 - const char *name, 217 - umode_t mode, loff_t size, 218 - const struct kernfs_ops *ops, 219 - void *priv, const void *ns, 220 - struct lock_class_key *key); 221 - struct sysfs_dirent *kernfs_create_link(struct sysfs_dirent *parent, 222 - const char *name, 223 - struct sysfs_dirent *target); 224 - void kernfs_remove(struct sysfs_dirent *sd); 225 - int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, const char *name, 212 + struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, 213 + const char *name, void *priv, 214 + const void *ns); 215 + struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent, 216 + const char *name, 217 + umode_t mode, loff_t size, 218 + const struct kernfs_ops *ops, 219 + void *priv, const void *ns, 220 + struct lock_class_key *key); 221 + struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, 222 + const char *name, 223 + struct kernfs_node *target); 224 + void kernfs_remove(struct kernfs_node *kn); 225 + int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, 226 226 const void *ns); 227 - int kernfs_rename_ns(struct sysfs_dirent *sd, struct sysfs_dirent *new_parent, 227 + int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, 228 228 const char *new_name, const void *new_ns); 229 - int kernfs_setattr(struct sysfs_dirent *sd, const struct iattr *iattr); 230 - void kernfs_notify(struct sysfs_dirent *sd); 229 + int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); 230 + void kernfs_notify(struct kernfs_node *kn); 231 231 232 232 const void *kernfs_super_ns(struct super_block *sb); 233 233 struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, ··· 238 238 239 239 #else /* CONFIG_SYSFS */ 240 240 241 - static inline enum kernfs_node_type sysfs_type(struct sysfs_dirent *sd) 241 + static inline enum kernfs_node_type sysfs_type(struct kernfs_node *kn) 242 242 { return 0; } /* whatever */ 243 243 244 - static inline void kernfs_enable_ns(struct sysfs_dirent *sd) { } 244 + static inline void kernfs_enable_ns(struct kernfs_node *kn) { } 245 245 246 - static inline bool kernfs_ns_enabled(struct sysfs_dirent *sd) 246 + static inline bool kernfs_ns_enabled(struct kernfs_node *kn) 247 247 { return false; } 248 248 249 - static inline struct sysfs_dirent * 250 - kernfs_find_and_get_ns(struct sysfs_dirent *parent, const char *name, 249 + static inline struct kernfs_node * 250 + kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, 251 251 const void *ns) 252 252 { return NULL; } 253 253 254 - static inline void kernfs_get(struct sysfs_dirent *sd) { } 255 - static inline void kernfs_put(struct sysfs_dirent *sd) { } 254 + static inline void kernfs_get(struct kernfs_node *kn) { } 255 + static inline void kernfs_put(struct kernfs_node *kn) { } 256 256 257 257 static inline struct kernfs_root *kernfs_create_root(void *priv) 258 258 { return ERR_PTR(-ENOSYS); } 259 259 260 260 static inline void kernfs_destroy_root(struct kernfs_root *root) { } 261 261 262 - static inline struct sysfs_dirent * 263 - kernfs_create_dir_ns(struct sysfs_dirent *parent, const char *name, void *priv, 262 + static inline struct kernfs_node * 263 + kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, void *priv, 264 264 const void *ns) 265 265 { return ERR_PTR(-ENOSYS); } 266 266 267 - static inline struct sysfs_dirent * 268 - kernfs_create_file_ns_key(struct sysfs_dirent *parent, const char *name, 267 + static inline struct kernfs_node * 268 + kernfs_create_file_ns_key(struct kernfs_node *parent, const char *name, 269 269 umode_t mode, loff_t size, 270 270 const struct kernfs_ops *ops, void *priv, 271 271 const void *ns, struct lock_class_key *key) 272 272 { return ERR_PTR(-ENOSYS); } 273 273 274 - static inline struct sysfs_dirent * 275 - kernfs_create_link(struct sysfs_dirent *parent, const char *name, 276 - struct sysfs_dirent *target) 274 + static inline struct kernfs_node * 275 + kernfs_create_link(struct kernfs_node *parent, const char *name, 276 + struct kernfs_node *target) 277 277 { return ERR_PTR(-ENOSYS); } 278 278 279 - static inline void kernfs_remove(struct sysfs_dirent *sd) { } 279 + static inline void kernfs_remove(struct kernfs_node *kn) { } 280 280 281 - static inline int kernfs_remove_by_name_ns(struct sysfs_dirent *parent, 281 + static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn, 282 282 const char *name, const void *ns) 283 283 { return -ENOSYS; } 284 284 285 - static inline int kernfs_rename_ns(struct sysfs_dirent *sd, 286 - struct sysfs_dirent *new_parent, 285 + static inline int kernfs_rename_ns(struct kernfs_node *kn, 286 + struct kernfs_node *new_parent, 287 287 const char *new_name, const void *new_ns) 288 288 { return -ENOSYS; } 289 289 290 - static inline int kernfs_setattr(struct sysfs_dirent *sd, 290 + static inline int kernfs_setattr(struct kernfs_node *kn, 291 291 const struct iattr *iattr) 292 292 { return -ENOSYS; } 293 293 294 - static inline void kernfs_notify(struct sysfs_dirent *sd) { } 294 + static inline void kernfs_notify(struct kernfs_node *kn) { } 295 295 296 296 static inline const void *kernfs_super_ns(struct super_block *sb) 297 297 { return NULL; } ··· 307 307 308 308 #endif /* CONFIG_SYSFS */ 309 309 310 - static inline struct sysfs_dirent * 311 - kernfs_find_and_get(struct sysfs_dirent *sd, const char *name) 310 + static inline struct kernfs_node * 311 + kernfs_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 316 - static inline struct sysfs_dirent * 317 - kernfs_create_dir(struct sysfs_dirent *parent, const char *name, void *priv) 316 + static inline struct kernfs_node * 317 + kernfs_create_dir(struct kernfs_node *parent, const char *name, void *priv) 318 318 { 319 319 return kernfs_create_dir_ns(parent, name, priv, NULL); 320 320 } 321 321 322 - static inline struct sysfs_dirent * 323 - kernfs_create_file_ns(struct sysfs_dirent *parent, const char *name, 322 + static inline struct kernfs_node * 323 + kernfs_create_file_ns(struct kernfs_node *parent, const char *name, 324 324 umode_t mode, loff_t size, const struct kernfs_ops *ops, 325 325 void *priv, const void *ns) 326 326 { ··· 333 333 ns, key); 334 334 } 335 335 336 - static inline struct sysfs_dirent * 337 - kernfs_create_file(struct sysfs_dirent *parent, const char *name, umode_t mode, 336 + static inline struct kernfs_node * 337 + kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode, 338 338 loff_t size, const struct kernfs_ops *ops, void *priv) 339 339 { 340 340 return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL); 341 341 } 342 342 343 - static inline int kernfs_remove_by_name(struct sysfs_dirent *parent, 343 + static inline int kernfs_remove_by_name(struct kernfs_node *parent, 344 344 const char *name) 345 345 { 346 346 return kernfs_remove_by_name_ns(parent, name, NULL);
+1 -1
include/linux/kobject.h
··· 64 64 struct kobject *parent; 65 65 struct kset *kset; 66 66 struct kobj_type *ktype; 67 - struct sysfs_dirent *sd; 67 + struct kernfs_node *sd; 68 68 struct kref kref; 69 69 #ifdef CONFIG_DEBUG_KOBJECT_RELEASE 70 70 struct delayed_work release;
+10 -10
include/linux/sysfs.h
··· 438 438 return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL); 439 439 } 440 440 441 - static inline void sysfs_notify_dirent(struct sysfs_dirent *sd) 441 + static inline void sysfs_notify_dirent(struct kernfs_node *kn) 442 442 { 443 - kernfs_notify(sd); 443 + kernfs_notify(kn); 444 444 } 445 445 446 - static inline struct sysfs_dirent * 447 - sysfs_get_dirent(struct sysfs_dirent *parent_sd, const unsigned char *name) 446 + static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent, 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 452 - static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) 452 + static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn) 453 453 { 454 - kernfs_get(sd); 455 - return sd; 454 + kernfs_get(kn); 455 + return kn; 456 456 } 457 457 458 - static inline void sysfs_put(struct sysfs_dirent *sd) 458 + static inline void sysfs_put(struct kernfs_node *kn) 459 459 { 460 - kernfs_put(sd); 460 + kernfs_put(kn); 461 461 } 462 462 463 463 #endif /* _SYSFS_H_ */
+1 -1
lib/kobject.c
··· 556 556 */ 557 557 void kobject_del(struct kobject *kobj) 558 558 { 559 - struct sysfs_dirent *sd; 559 + struct kernfs_node *sd; 560 560 561 561 if (!kobj) 562 562 return;