Skip to content

Commit 99c001c

Browse files
torvaldsrostedt
authored andcommitted
tracefs: Avoid using the ei->dentry pointer unnecessarily
The eventfs_find_events() code tries to walk up the tree to find the event directory that a dentry belongs to, in order to then find the eventfs inode that is associated with that event directory. However, it uses an odd combination of walking the dentry parent, looking up the eventfs inode associated with that, and then looking up the dentry from there. Repeat. But the code shouldn't have back-pointers to dentries in the first place, and it should just walk the dentry parenthood chain directly. Similarly, 'set_top_events_ownership()' looks up the dentry from the eventfs inode, but the only reason it wants a dentry is to look up the superblock in order to look up the root dentry. But it already has the real filesystem inode, which has that same superblock pointer. So just pass in the superblock pointer using the information that's already there, instead of looking up extraneous data that is irrelevant. Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/ Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Al Viro <[email protected]> Cc: Ajay Kaher <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Fixes: c1504e5 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 4fa4b01 commit 99c001c

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

fs/tracefs/event_inode.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,33 +156,30 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
156156
return ret;
157157
}
158158

159-
static void update_top_events_attr(struct eventfs_inode *ei, struct dentry *dentry)
159+
static void update_top_events_attr(struct eventfs_inode *ei, struct super_block *sb)
160160
{
161-
struct inode *inode;
161+
struct inode *root;
162162

163163
/* Only update if the "events" was on the top level */
164164
if (!ei || !(ei->attr.mode & EVENTFS_TOPLEVEL))
165165
return;
166166

167167
/* Get the tracefs root inode. */
168-
inode = d_inode(dentry->d_sb->s_root);
169-
ei->attr.uid = inode->i_uid;
170-
ei->attr.gid = inode->i_gid;
168+
root = d_inode(sb->s_root);
169+
ei->attr.uid = root->i_uid;
170+
ei->attr.gid = root->i_gid;
171171
}
172172

173173
static void set_top_events_ownership(struct inode *inode)
174174
{
175175
struct tracefs_inode *ti = get_tracefs(inode);
176176
struct eventfs_inode *ei = ti->private;
177-
struct dentry *dentry;
178177

179178
/* The top events directory doesn't get automatically updated */
180179
if (!ei || !ei->is_events || !(ei->attr.mode & EVENTFS_TOPLEVEL))
181180
return;
182181

183-
dentry = ei->dentry;
184-
185-
update_top_events_attr(ei, dentry);
182+
update_top_events_attr(ei, inode->i_sb);
186183

187184
if (!(ei->attr.mode & EVENTFS_SAVE_UID))
188185
inode->i_uid = ei->attr.uid;
@@ -235,8 +232,10 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
235232

236233
mutex_lock(&eventfs_mutex);
237234
do {
238-
/* The parent always has an ei, except for events itself */
239-
ei = dentry->d_parent->d_fsdata;
235+
// The parent is stable because we do not do renames
236+
dentry = dentry->d_parent;
237+
// ... and directories always have d_fsdata
238+
ei = dentry->d_fsdata;
240239

241240
/*
242241
* If the ei is being freed, the ownership of the children
@@ -246,12 +245,11 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry)
246245
ei = NULL;
247246
break;
248247
}
249-
250-
dentry = ei->dentry;
248+
// Walk upwards until you find the events inode
251249
} while (!ei->is_events);
252250
mutex_unlock(&eventfs_mutex);
253251

254-
update_top_events_attr(ei, dentry);
252+
update_top_events_attr(ei, dentry->d_sb);
255253

256254
return ei;
257255
}

0 commit comments

Comments
 (0)