Skip to content

Commit 625acf9

Browse files
committed
eventfs: Consolidate the eventfs_inode update in eventfs_get_inode()
To simplify the code, create a eventfs_get_inode() that is used when an eventfs file or directory is created. Have the internal tracefs_inode updated the appropriate flags in this function and update the inode's mode as well. Link: https://lore.kernel.org/lkml/[email protected] Cc: Linus Torvalds <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 0bcfd9a commit 625acf9

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

fs/tracefs/event_inode.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,25 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode,
412412
inode->i_gid = attr->gid;
413413
}
414414

415+
static struct inode *eventfs_get_inode(struct dentry *dentry, struct eventfs_attr *attr,
416+
umode_t mode, struct eventfs_inode *ei)
417+
{
418+
struct tracefs_inode *ti;
419+
struct inode *inode;
420+
421+
inode = tracefs_get_inode(dentry->d_sb);
422+
if (!inode)
423+
return NULL;
424+
425+
ti = get_tracefs(inode);
426+
ti->private = ei;
427+
ti->flags |= TRACEFS_EVENT_INODE;
428+
429+
update_inode_attr(dentry, inode, attr, mode);
430+
431+
return inode;
432+
}
433+
415434
/**
416435
* lookup_file - look up a file in the tracefs filesystem
417436
* @parent_ei: Pointer to the eventfs_inode that represents parent of the file
@@ -432,7 +451,6 @@ static struct dentry *lookup_file(struct eventfs_inode *parent_ei,
432451
void *data,
433452
const struct file_operations *fop)
434453
{
435-
struct tracefs_inode *ti;
436454
struct inode *inode;
437455

438456
if (!(mode & S_IFMT))
@@ -441,23 +459,18 @@ static struct dentry *lookup_file(struct eventfs_inode *parent_ei,
441459
if (WARN_ON_ONCE(!S_ISREG(mode)))
442460
return ERR_PTR(-EIO);
443461

444-
inode = tracefs_get_inode(dentry->d_sb);
462+
/* Only directories have ti->private set to an ei, not files */
463+
inode = eventfs_get_inode(dentry, attr, mode, NULL);
445464
if (unlikely(!inode))
446465
return ERR_PTR(-ENOMEM);
447466

448-
/* If the user updated the directory's attributes, use them */
449-
update_inode_attr(dentry, inode, attr, mode);
450-
451467
inode->i_op = &eventfs_file_inode_operations;
452468
inode->i_fop = fop;
453469
inode->i_private = data;
454470

455471
/* All files will have the same inode number */
456472
inode->i_ino = EVENTFS_FILE_INODE_INO;
457473

458-
ti = get_tracefs(inode);
459-
ti->flags |= TRACEFS_EVENT_INODE;
460-
461474
// Files have their parent's ei as their fsdata
462475
dentry->d_fsdata = get_ei(parent_ei);
463476

@@ -477,28 +490,19 @@ static struct dentry *lookup_file(struct eventfs_inode *parent_ei,
477490
static struct dentry *lookup_dir_entry(struct dentry *dentry,
478491
struct eventfs_inode *pei, struct eventfs_inode *ei)
479492
{
480-
struct tracefs_inode *ti;
481493
struct inode *inode;
494+
umode_t mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
482495

483-
inode = tracefs_get_inode(dentry->d_sb);
496+
inode = eventfs_get_inode(dentry, &ei->attr, mode, ei);
484497
if (unlikely(!inode))
485498
return ERR_PTR(-ENOMEM);
486499

487-
/* If the user updated the directory's attributes, use them */
488-
update_inode_attr(dentry, inode, &ei->attr,
489-
S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO);
490-
491500
inode->i_op = &eventfs_dir_inode_operations;
492501
inode->i_fop = &eventfs_file_operations;
493502

494503
/* All directories will have the same inode number */
495504
inode->i_ino = eventfs_dir_ino(ei);
496505

497-
ti = get_tracefs(inode);
498-
ti->flags |= TRACEFS_EVENT_INODE;
499-
/* Only directories have ti->private set to an ei, not files */
500-
ti->private = ei;
501-
502506
dentry->d_fsdata = get_ei(ei);
503507

504508
d_add(dentry, inode);

0 commit comments

Comments
 (0)