Skip to content

Commit 704f960

Browse files
committed
eventfs: Read ei->entries before ei->children in eventfs_iterate()
In order to apply a shortcut to skip over the current ctx->pos immediately, by using the ei->entries array, the reading of that array should be first. Moving the array reading before the linked list reading will make the shortcut change diff nicer to read. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.333115095@goodmis.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 1e4624e commit 704f960

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

fs/tracefs/event_inode.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)
752752
* Need to create the dentries and inodes to have a consistent
753753
* inode number.
754754
*/
755-
list_for_each_entry_srcu(ei_child, &ei->children, list,
756-
srcu_read_lock_held(&eventfs_srcu)) {
755+
for (i = 0; i < ei->nr_entries; i++) {
756+
void *cdata = ei->data;
757757

758758
if (c > 0) {
759759
c--;
@@ -762,23 +762,32 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)
762762

763763
ctx->pos++;
764764

765-
if (ei_child->is_freed)
766-
continue;
765+
entry = &ei->entries[i];
766+
name = entry->name;
767767

768-
name = ei_child->name;
768+
mutex_lock(&eventfs_mutex);
769+
/* If ei->is_freed then just bail here, nothing more to do */
770+
if (ei->is_freed) {
771+
mutex_unlock(&eventfs_mutex);
772+
goto out_dec;
773+
}
774+
r = entry->callback(name, &mode, &cdata, &fops);
775+
mutex_unlock(&eventfs_mutex);
776+
if (r <= 0)
777+
continue;
769778

770-
dentry = create_dir_dentry(ei, ei_child, ei_dentry);
779+
dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops);
771780
if (!dentry)
772781
goto out_dec;
773782
ino = dentry->d_inode->i_ino;
774783
dput(dentry);
775784

776-
if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR))
785+
if (!dir_emit(ctx, name, strlen(name), ino, DT_REG))
777786
goto out_dec;
778787
}
779788

780-
for (i = 0; i < ei->nr_entries; i++) {
781-
void *cdata = ei->data;
789+
list_for_each_entry_srcu(ei_child, &ei->children, list,
790+
srcu_read_lock_held(&eventfs_srcu)) {
782791

783792
if (c > 0) {
784793
c--;
@@ -787,27 +796,18 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)
787796

788797
ctx->pos++;
789798

790-
entry = &ei->entries[i];
791-
name = entry->name;
792-
793-
mutex_lock(&eventfs_mutex);
794-
/* If ei->is_freed then just bail here, nothing more to do */
795-
if (ei->is_freed) {
796-
mutex_unlock(&eventfs_mutex);
797-
goto out_dec;
798-
}
799-
r = entry->callback(name, &mode, &cdata, &fops);
800-
mutex_unlock(&eventfs_mutex);
801-
if (r <= 0)
799+
if (ei_child->is_freed)
802800
continue;
803801

804-
dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops);
802+
name = ei_child->name;
803+
804+
dentry = create_dir_dentry(ei, ei_child, ei_dentry);
805805
if (!dentry)
806806
goto out_dec;
807807
ino = dentry->d_inode->i_ino;
808808
dput(dentry);
809809

810-
if (!dir_emit(ctx, name, strlen(name), ino, DT_REG))
810+
if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR))
811811
goto out_dec;
812812
}
813813
ret = 1;

0 commit comments

Comments
 (0)