Skip to content

Commit

Permalink
fs: proc: store PDE()->data into inode->i_private
Browse files Browse the repository at this point in the history
PDE_DATA(inode) is introduced to get user private data and hide the
layout of struct proc_dir_entry.  The inode->i_private is used to do the
same thing as well.  Save a copy of user private data to inode->
i_private when proc inode is allocated.  This means the user also can
get their private data by inode->i_private.

Introduce pde_data() to wrap inode->i_private so that we can remove
PDE_DATA() from fs/proc/generic.c and make PTE_DATE() as a wrapper of
pde_data().  It will be easier if we decide to remove PDE_DATE() in the
future.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Muchun Song <[email protected]>
Acked-by: Christian Brauner <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Cc: Alexey Gladkov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Muchun Song authored and torvalds committed Jan 22, 2022
1 parent a372659 commit 6dfbbae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 0 additions & 6 deletions fs/proc/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,6 @@ void proc_remove(struct proc_dir_entry *de)
}
EXPORT_SYMBOL(proc_remove);

void *PDE_DATA(const struct inode *inode)
{
return __PDE_DATA(inode);
}
EXPORT_SYMBOL(PDE_DATA);

/*
* Pull a user buffer into memory and pass it to the file's write handler if
* one is supplied. The ->write() method is permitted to modify the
Expand Down
1 change: 1 addition & 0 deletions fs/proc/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
return NULL;
}

inode->i_private = de->data;
inode->i_ino = de->low_ino;
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
PROC_I(inode)->pde = de;
Expand Down
5 changes: 0 additions & 5 deletions fs/proc/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ static inline struct proc_dir_entry *PDE(const struct inode *inode)
return PROC_I(inode)->pde;
}

static inline void *__PDE_DATA(const struct inode *inode)
{
return PDE(inode)->data;
}

static inline struct pid *proc_pid(const struct inode *inode)
{
return PROC_I(inode)->pid;
Expand Down
13 changes: 12 additions & 1 deletion include/linux/proc_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,18 @@ extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct proc_ops *proc_ops);
extern void proc_set_size(struct proc_dir_entry *, loff_t);
extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
extern void *PDE_DATA(const struct inode *);

/*
* Obtain the private data passed by user through proc_create_data() or
* related.
*/
static inline void *pde_data(const struct inode *inode)
{
return inode->i_private;
}

#define PDE_DATA(i) pde_data(i)

extern void *proc_get_parent_data(const struct inode *);
extern void proc_remove(struct proc_dir_entry *);
extern void remove_proc_entry(const char *, struct proc_dir_entry *);
Expand Down

0 comments on commit 6dfbbae

Please sign in to comment.