Skip to content

Commit b0f7e2d

Browse files
committed
eventfs: Remove "lookup" parameter from create_dir/file_dentry()
The "lookup" parameter is a way to differentiate the call to create_file/dir_dentry() from when it's just a lookup (no need to up the dentry refcount) and accessed via a readdir (need to up the refcount). But reality, it just makes the code more complex. Just up the refcount and let the caller decide to dput() the result or not. Link: https://lore.kernel.org/linux-trace-kernel/20240103102553.17a19cea@gandalf.local.home Link: https://lore.kernel.org/linux-trace-kernel/20240104015435.517502710@goodmis.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Ajay Kaher <akaher@vmware.com> Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent fd56cd5 commit b0f7e2d

1 file changed

Lines changed: 20 additions & 35 deletions

File tree

fs/tracefs/event_inode.c

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -390,16 +390,14 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry)
390390
* @mode: The mode of the file.
391391
* @data: The data to use to set the inode of the file with on open()
392392
* @fops: The fops of the file to be created.
393-
* @lookup: If called by the lookup routine, in which case, dput() the created dentry.
394393
*
395394
* Create a dentry for a file of an eventfs_inode @ei and place it into the
396-
* address located at @e_dentry. If the @e_dentry already has a dentry, then
397-
* just do a dget() on it and return. Otherwise create the dentry and attach it.
395+
* address located at @e_dentry.
398396
*/
399397
static struct dentry *
400398
create_file_dentry(struct eventfs_inode *ei, int idx,
401399
struct dentry *parent, const char *name, umode_t mode, void *data,
402-
const struct file_operations *fops, bool lookup)
400+
const struct file_operations *fops)
403401
{
404402
struct eventfs_attr *attr = NULL;
405403
struct dentry **e_dentry = &ei->d_children[idx];
@@ -414,9 +412,7 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
414412
}
415413
/* If the e_dentry already has a dentry, use it */
416414
if (*e_dentry) {
417-
/* lookup does not need to up the ref count */
418-
if (!lookup)
419-
dget(*e_dentry);
415+
dget(*e_dentry);
420416
mutex_unlock(&eventfs_mutex);
421417
return *e_dentry;
422418
}
@@ -441,13 +437,12 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
441437
* way to being freed, don't return it. If e_dentry is NULL
442438
* it means it was already freed.
443439
*/
444-
if (ei->is_freed)
440+
if (ei->is_freed) {
445441
dentry = NULL;
446-
else
442+
} else {
447443
dentry = *e_dentry;
448-
/* The lookup does not need to up the dentry refcount */
449-
if (dentry && !lookup)
450444
dget(dentry);
445+
}
451446
mutex_unlock(&eventfs_mutex);
452447
return dentry;
453448
}
@@ -465,9 +460,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
465460
}
466461
mutex_unlock(&eventfs_mutex);
467462

468-
if (lookup)
469-
dput(dentry);
470-
471463
return dentry;
472464
}
473465

@@ -500,13 +492,12 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei)
500492
* @pei: The eventfs_inode parent of ei.
501493
* @ei: The eventfs_inode to create the directory for
502494
* @parent: The dentry of the parent of this directory
503-
* @lookup: True if this is called by the lookup code
504495
*
505496
* This creates and attaches a directory dentry to the eventfs_inode @ei.
506497
*/
507498
static struct dentry *
508499
create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
509-
struct dentry *parent, bool lookup)
500+
struct dentry *parent)
510501
{
511502
struct dentry *dentry = NULL;
512503

@@ -518,11 +509,9 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
518509
return NULL;
519510
}
520511
if (ei->dentry) {
521-
/* If the dentry already has a dentry, use it */
512+
/* If the eventfs_inode already has a dentry, use it */
522513
dentry = ei->dentry;
523-
/* lookup does not need to up the ref count */
524-
if (!lookup)
525-
dget(dentry);
514+
dget(dentry);
526515
mutex_unlock(&eventfs_mutex);
527516
return dentry;
528517
}
@@ -542,7 +531,7 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
542531
* way to being freed.
543532
*/
544533
dentry = ei->dentry;
545-
if (dentry && !lookup)
534+
if (dentry)
546535
dget(dentry);
547536
mutex_unlock(&eventfs_mutex);
548537
return dentry;
@@ -562,9 +551,6 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
562551
}
563552
mutex_unlock(&eventfs_mutex);
564553

565-
if (lookup)
566-
dput(dentry);
567-
568554
return dentry;
569555
}
570556

@@ -589,8 +575,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
589575
struct eventfs_inode *ei;
590576
struct dentry *ei_dentry = NULL;
591577
struct dentry *ret = NULL;
578+
struct dentry *d;
592579
const char *name = dentry->d_name.name;
593-
bool created = false;
594580
umode_t mode;
595581
void *data;
596582
int idx;
@@ -626,13 +612,10 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
626612
ret = simple_lookup(dir, dentry, flags);
627613
if (IS_ERR(ret))
628614
goto out;
629-
create_dir_dentry(ei, ei_child, ei_dentry, true);
630-
created = true;
631-
break;
632-
}
633-
634-
if (created)
615+
d = create_dir_dentry(ei, ei_child, ei_dentry);
616+
dput(d);
635617
goto out;
618+
}
636619

637620
for (i = 0; i < ei->nr_entries; i++) {
638621
entry = &ei->entries[i];
@@ -650,8 +633,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir,
650633
ret = simple_lookup(dir, dentry, flags);
651634
if (IS_ERR(ret))
652635
goto out;
653-
create_file_dentry(ei, i, ei_dentry, name, mode, cdata,
654-
fops, true);
636+
d = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops);
637+
dput(d);
655638
break;
656639
}
657640
}
@@ -768,9 +751,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
768751
inode_lock(parent->d_inode);
769752
list_for_each_entry_srcu(ei_child, &ei->children, list,
770753
srcu_read_lock_held(&eventfs_srcu)) {
771-
d = create_dir_dentry(ei, ei_child, parent, false);
754+
d = create_dir_dentry(ei, ei_child, parent);
772755
if (d) {
773756
ret = add_dentries(&dentries, d, cnt);
757+
dput(d);
774758
if (ret < 0)
775759
break;
776760
cnt++;
@@ -790,9 +774,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
790774
mutex_unlock(&eventfs_mutex);
791775
if (r <= 0)
792776
continue;
793-
d = create_file_dentry(ei, i, parent, name, mode, cdata, fops, false);
777+
d = create_file_dentry(ei, i, parent, name, mode, cdata, fops);
794778
if (d) {
795779
ret = add_dentries(&dentries, d, cnt);
780+
dput(d);
796781
if (ret < 0)
797782
break;
798783
cnt++;

0 commit comments

Comments
 (0)