Skip to content

Commit d69ac5a

Browse files
htejungregkh
authored andcommitted
sysfs: remove sysfs_addrm_cxt->parent_sd
sysfs_addrm_start/finish() enclose sysfs_dirent additions and deletions and sysfs_addrm_cxt is used to record information necessary to finish the operations. Currently, sysfs_addrm_start() takes @parent_sd, records it in sysfs_addrm_cxt, and assumes that all operations in the block are performed under that @parent_sd. This assumption has been fine until now but we want to make some operations behave recursively and, while having @parent_sd recorded in sysfs_addrm_cxt doesn't necessarily prevents that, it becomes confusing. This patch removes sysfs_addrm_cxt->parent_sd and makes sysfs_add_one() take an explicit @parent_sd parameter. Note that sysfs_remove_one() doesn't need the extra argument as its parent is always known from the target @sd. While at it, add __acquires/releases() notations to sysfs_addrm_start/finish() respectively. This patch doesn't make any functional difference. Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5b88021 commit d69ac5a

File tree

5 files changed

+38
-36
lines changed

5 files changed

+38
-36
lines changed

fs/sysfs/dir.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -406,22 +406,19 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
406406
/**
407407
* sysfs_addrm_start - prepare for sysfs_dirent add/remove
408408
* @acxt: pointer to sysfs_addrm_cxt to be used
409-
* @parent_sd: parent sysfs_dirent
410409
*
411-
* This function is called when the caller is about to add or
412-
* remove sysfs_dirent under @parent_sd. This function acquires
413-
* sysfs_mutex. @acxt is used to keep and pass context to
414-
* other addrm functions.
410+
* This function is called when the caller is about to add or remove
411+
* sysfs_dirent. This function acquires sysfs_mutex. @acxt is used
412+
* to keep and pass context to other addrm functions.
415413
*
416414
* LOCKING:
417415
* Kernel thread context (may sleep). sysfs_mutex is locked on
418416
* return.
419417
*/
420-
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
421-
struct sysfs_dirent *parent_sd)
418+
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt)
419+
__acquires(sysfs_mutex)
422420
{
423421
memset(acxt, 0, sizeof(*acxt));
424-
acxt->parent_sd = parent_sd;
425422

426423
mutex_lock(&sysfs_mutex);
427424
}
@@ -430,10 +427,11 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
430427
* __sysfs_add_one - add sysfs_dirent to parent without warning
431428
* @acxt: addrm context to use
432429
* @sd: sysfs_dirent to be added
430+
* @parent_sd: the parent sysfs_dirent to add @sd to
433431
*
434-
* Get @acxt->parent_sd and set sd->s_parent to it and increment
435-
* nlink of parent inode if @sd is a directory and link into the
436-
* children list of the parent.
432+
* Get @parent_sd and set @sd->s_parent to it and increment nlink of
433+
* the parent inode if @sd is a directory and link into the children
434+
* list of the parent.
437435
*
438436
* This function should be called between calls to
439437
* sysfs_addrm_start() and sysfs_addrm_finish() and should be
@@ -446,20 +444,21 @@ void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
446444
* 0 on success, -EEXIST if entry with the given name already
447445
* exists.
448446
*/
449-
int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
447+
int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
448+
struct sysfs_dirent *parent_sd)
450449
{
451450
struct sysfs_inode_attrs *ps_iattr;
452451
int ret;
453452

454453
sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns);
455-
sd->s_parent = sysfs_get(acxt->parent_sd);
454+
sd->s_parent = sysfs_get(parent_sd);
456455

457456
ret = sysfs_link_sibling(sd);
458457
if (ret)
459458
return ret;
460459

461460
/* Update timestamps on the parent */
462-
ps_iattr = acxt->parent_sd->s_iattr;
461+
ps_iattr = parent_sd->s_iattr;
463462
if (ps_iattr) {
464463
struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
465464
ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
@@ -493,10 +492,11 @@ static char *sysfs_pathname(struct sysfs_dirent *sd, char *path)
493492
* sysfs_add_one - add sysfs_dirent to parent
494493
* @acxt: addrm context to use
495494
* @sd: sysfs_dirent to be added
495+
* @parent_sd: the parent sysfs_dirent to add @sd to
496496
*
497-
* Get @acxt->parent_sd and set sd->s_parent to it and increment
498-
* nlink of parent inode if @sd is a directory and link into the
499-
* children list of the parent.
497+
* Get @parent_sd and set @sd->s_parent to it and increment nlink of
498+
* the parent inode if @sd is a directory and link into the children
499+
* list of the parent.
500500
*
501501
* This function should be called between calls to
502502
* sysfs_addrm_start() and sysfs_addrm_finish() and should be
@@ -509,17 +509,18 @@ static char *sysfs_pathname(struct sysfs_dirent *sd, char *path)
509509
* 0 on success, -EEXIST if entry with the given name already
510510
* exists.
511511
*/
512-
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
512+
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
513+
struct sysfs_dirent *parent_sd)
513514
{
514515
int ret;
515516

516-
ret = __sysfs_add_one(acxt, sd);
517+
ret = __sysfs_add_one(acxt, sd, parent_sd);
517518
if (ret == -EEXIST) {
518519
char *path = kzalloc(PATH_MAX, GFP_KERNEL);
519520
WARN(1, KERN_WARNING
520521
"sysfs: cannot create duplicate filename '%s'\n",
521522
(path == NULL) ? sd->s_name
522-
: (sysfs_pathname(acxt->parent_sd, path),
523+
: (sysfs_pathname(parent_sd, path),
523524
strlcat(path, "/", PATH_MAX),
524525
strlcat(path, sd->s_name, PATH_MAX),
525526
path));
@@ -553,7 +554,7 @@ void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
553554
sysfs_unlink_sibling(sd);
554555

555556
/* Update timestamps on the parent */
556-
ps_iattr = acxt->parent_sd->s_iattr;
557+
ps_iattr = sd->s_parent->s_iattr;
557558
if (ps_iattr) {
558559
struct iattr *ps_iattrs = &ps_iattr->ia_iattr;
559560
ps_iattrs->ia_ctime = ps_iattrs->ia_mtime = CURRENT_TIME;
@@ -576,6 +577,7 @@ void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
576577
* sysfs_mutex is released.
577578
*/
578579
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
580+
__releases(sysfs_mutex)
579581
{
580582
/* release resources acquired by sysfs_addrm_start() */
581583
mutex_unlock(&sysfs_mutex);
@@ -678,8 +680,8 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
678680
sd->s_dir.kobj = kobj;
679681

680682
/* link in */
681-
sysfs_addrm_start(&acxt, parent_sd);
682-
rc = sysfs_add_one(&acxt, sd);
683+
sysfs_addrm_start(&acxt);
684+
rc = sysfs_add_one(&acxt, sd, parent_sd);
683685
sysfs_addrm_finish(&acxt);
684686

685687
if (rc == 0)
@@ -772,7 +774,7 @@ static void remove_dir(struct sysfs_dirent *sd)
772774
{
773775
struct sysfs_addrm_cxt acxt;
774776

775-
sysfs_addrm_start(&acxt, sd->s_parent);
777+
sysfs_addrm_start(&acxt);
776778
sysfs_remove_one(&acxt, sd);
777779
sysfs_addrm_finish(&acxt);
778780
}
@@ -792,7 +794,7 @@ static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
792794
return;
793795

794796
pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
795-
sysfs_addrm_start(&acxt, dir_sd);
797+
sysfs_addrm_start(&acxt);
796798
pos = rb_first(&dir_sd->s_dir.children);
797799
while (pos) {
798800
struct sysfs_dirent *sd = to_sysfs_dirent(pos);

fs/sysfs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ int sysfs_add_file_mode_ns(struct sysfs_dirent *dir_sd,
502502
sd->s_attr.attr = (void *)attr;
503503
sysfs_dirent_init_lockdep(sd);
504504

505-
sysfs_addrm_start(&acxt, dir_sd);
506-
rc = sysfs_add_one(&acxt, sd);
505+
sysfs_addrm_start(&acxt);
506+
rc = sysfs_add_one(&acxt, sd, dir_sd);
507507
sysfs_addrm_finish(&acxt);
508508

509509
if (rc)

fs/sysfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name,
326326
return -ENOENT;
327327
}
328328

329-
sysfs_addrm_start(&acxt, dir_sd);
329+
sysfs_addrm_start(&acxt);
330330

331331
sd = sysfs_find_dirent(dir_sd, name, ns);
332332
if (sd)

fs/sysfs/symlink.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
5353
sd->s_symlink.target_sd = target_sd;
5454
target_sd = NULL; /* reference is now owned by the symlink */
5555

56-
sysfs_addrm_start(&acxt, parent_sd);
56+
sysfs_addrm_start(&acxt);
5757
if (warn)
58-
error = sysfs_add_one(&acxt, sd);
58+
error = sysfs_add_one(&acxt, sd, parent_sd);
5959
else
60-
error = __sysfs_add_one(&acxt, sd);
60+
error = __sysfs_add_one(&acxt, sd, parent_sd);
6161
sysfs_addrm_finish(&acxt);
6262

6363
if (error)

fs/sysfs/sysfs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ do { \
120120
* Context structure to be used while adding/removing nodes.
121121
*/
122122
struct sysfs_addrm_cxt {
123-
struct sysfs_dirent *parent_sd;
124123
struct sysfs_dirent *removed;
125124
};
126125

@@ -154,10 +153,11 @@ extern const struct inode_operations sysfs_dir_inode_operations;
154153
struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
155154
struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
156155
void sysfs_put_active(struct sysfs_dirent *sd);
157-
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
158-
struct sysfs_dirent *parent_sd);
159-
int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
160-
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
156+
void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
157+
int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
158+
struct sysfs_dirent *parent_sd);
159+
int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
160+
struct sysfs_dirent *parent_sd);
161161
void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
162162
void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
163163

0 commit comments

Comments
 (0)