All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fs: proc: store PDE()->data into inode->i_private
@ 2021-11-19  4:11 Muchun Song
  2021-11-19  7:23 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Muchun Song @ 2021-11-19  4:11 UTC (permalink / raw)
  To: akpm, adobriyan, gladkov.alexey; +Cc: linux-kernel, linux-fsdevel, Muchun Song

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.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
Changes in v2:
 - Drop all drivers related changes (do not remove PDE_DATA() completely).
 - Introduce pde_data() suggested by Andrew.

 v1: https://lkml.org/lkml/2021/11/1/575

 fs/proc/generic.c       |  6 ------
 fs/proc/inode.c         |  1 +
 fs/proc/internal.h      |  5 -----
 include/linux/proc_fs.h | 13 ++++++++++++-
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 5b78739e60e4..f2132407e133 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -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
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 599eb724ff2d..f84355c5a36d 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -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;
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 03415f3fb3a8..06a80f78433d 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -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;
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 069c7fd95396..b32fb0ef3308 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -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 *);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs: proc: store PDE()->data into inode->i_private
  2021-11-19  4:11 [PATCH v2] fs: proc: store PDE()->data into inode->i_private Muchun Song
@ 2021-11-19  7:23 ` Christoph Hellwig
  2021-11-19 22:56   ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2021-11-19  7:23 UTC (permalink / raw)
  To: Muchun Song; +Cc: akpm, adobriyan, gladkov.alexey, linux-kernel, linux-fsdevel

On Fri, Nov 19, 2021 at 12:11:04PM +0800, Muchun Song wrote:
> +
> +/*
> + * 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)

What is the point of pde_data?  If we really think changing to lower
case is worth it (I don't think so, using upper case for getting at
private data is a common idiom in file systems), we can just do that
scripted in one go.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs: proc: store PDE()->data into inode->i_private
  2021-11-19  7:23 ` Christoph Hellwig
@ 2021-11-19 22:56   ` Andrew Morton
  2021-11-22  4:13     ` Muchun Song
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2021-11-19 22:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Muchun Song, adobriyan, gladkov.alexey, linux-kernel, linux-fsdevel

On Thu, 18 Nov 2021 23:23:39 -0800 Christoph Hellwig <hch@infradead.org> wrote:

> On Fri, Nov 19, 2021 at 12:11:04PM +0800, Muchun Song wrote:
> > +
> > +/*
> > + * 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)
> 
> What is the point of pde_data?

It's a regular old C function, hence should be in lower case.

I assume the upper case thing is a holdover from when it was
implemented as a macro.

>  If we really think changing to lower
> case is worth it (I don't think so, using upper case for getting at
> private data is a common idiom in file systems),

It is?  How odd.

I find the upper-case thing to be actively misleading.  It's mildly
surprising to discover that it's actually a plain old C function.

> we can just do that
> scripted in one go.

Yes, I'd like to see a followup patch which converts the current
PDE_DATA() callsites.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs: proc: store PDE()->data into inode->i_private
  2021-11-19 22:56   ` Andrew Morton
@ 2021-11-22  4:13     ` Muchun Song
  2021-11-24  3:10       ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Muchun Song @ 2021-11-22  4:13 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Christoph Hellwig, Alexey Dobriyan, gladkov.alexey, LKML, linux-fsdevel

On Sat, Nov 20, 2021 at 6:56 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Thu, 18 Nov 2021 23:23:39 -0800 Christoph Hellwig <hch@infradead.org> wrote:
>
> > On Fri, Nov 19, 2021 at 12:11:04PM +0800, Muchun Song wrote:
> > > +
> > > +/*
> > > + * 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)
> >
> > What is the point of pde_data?
>
> It's a regular old C function, hence should be in lower case.
>
> I assume the upper case thing is a holdover from when it was
> implemented as a macro.
>
> >  If we really think changing to lower
> > case is worth it (I don't think so, using upper case for getting at
> > private data is a common idiom in file systems),
>
> It is?  How odd.
>
> I find the upper-case thing to be actively misleading.  It's mildly
> surprising to discover that it's actually a plain old C function.
>
> > we can just do that
> > scripted in one go.
>
> Yes, I'd like to see a followup patch which converts the current
> PDE_DATA() callsites.
>

You mean replace all PDE_DATA with pde_data in another patch?

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs: proc: store PDE()->data into inode->i_private
  2021-11-22  4:13     ` Muchun Song
@ 2021-11-24  3:10       ` Andrew Morton
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2021-11-24  3:10 UTC (permalink / raw)
  To: Muchun Song
  Cc: Christoph Hellwig, Alexey Dobriyan, gladkov.alexey, LKML, linux-fsdevel

On Mon, 22 Nov 2021 12:13:33 +0800 Muchun Song <songmuchun@bytedance.com> wrote:

> On Sat, Nov 20, 2021 at 6:56 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Thu, 18 Nov 2021 23:23:39 -0800 Christoph Hellwig <hch@infradead.org> wrote:
> >
> > > On Fri, Nov 19, 2021 at 12:11:04PM +0800, Muchun Song wrote:
> > > > +
> > > > +/*
> > > > + * 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)
> > >
> > > What is the point of pde_data?
> >
> > It's a regular old C function, hence should be in lower case.
> >
> > I assume the upper case thing is a holdover from when it was
> > implemented as a macro.
> >
> > >  If we really think changing to lower
> > > case is worth it (I don't think so, using upper case for getting at
> > > private data is a common idiom in file systems),
> >
> > It is?  How odd.
> >
> > I find the upper-case thing to be actively misleading.  It's mildly
> > surprising to discover that it's actually a plain old C function.
> >
> > > we can just do that
> > > scripted in one go.
> >
> > Yes, I'd like to see a followup patch which converts the current
> > PDE_DATA() callsites.
> >
> 
> You mean replace all PDE_DATA with pde_data in another patch?

That is indeed what I meant.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-24  3:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19  4:11 [PATCH v2] fs: proc: store PDE()->data into inode->i_private Muchun Song
2021-11-19  7:23 ` Christoph Hellwig
2021-11-19 22:56   ` Andrew Morton
2021-11-22  4:13     ` Muchun Song
2021-11-24  3:10       ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.