diff mbox series

ceph: Replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE

Message ID 1612165930-110076-1-git-send-email-jiapeng.chong@linux.alibaba.com
State New
Headers show
Series ceph: Replace DEFINE_SIMPLE_ATTRIBUTE with DEFINE_DEBUGFS_ATTRIBUTE | expand

Commit Message

Jiapeng Chong Feb. 1, 2021, 7:52 a.m. UTC
Fix the following coccicheck warning:

./fs/ceph/debugfs.c:347:0-23: WARNING: congestion_kb_fops should be
defined with DEFINE_DEBUGFS_ATTRIBUTE.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 fs/ceph/debugfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Ilya Dryomov Feb. 2, 2021, 12:07 p.m. UTC | #1
On Mon, Feb 1, 2021 at 8:52 AM Jiapeng Chong
<jiapeng.chong@linux.alibaba.com> wrote:
>

> Fix the following coccicheck warning:

>

> ./fs/ceph/debugfs.c:347:0-23: WARNING: congestion_kb_fops should be

> defined with DEFINE_DEBUGFS_ATTRIBUTE.

>

> Reported-by: Abaci Robot <abaci@linux.alibaba.com>

> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>

> ---

>  fs/ceph/debugfs.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)

>

> diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c

> index 66989c8..617327e 100644

> --- a/fs/ceph/debugfs.c

> +++ b/fs/ceph/debugfs.c

> @@ -344,8 +344,8 @@ static int congestion_kb_get(void *data, u64 *val)

>         return 0;

>  }

>

> -DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,

> -                       congestion_kb_set, "%llu\n");

> +DEFINE_DEBUGFS_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,

> +                         congestion_kb_set, "%llu\n");

>

>

>  void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)


Hi Jiapeng,

What is the benefit of this conversion?

From a quick look, with DEFINE_DEBUGFS_ATTRIBUTE writeback_congestion_kb
file would no longer be seekable.  It may not matter much, but something
that should have been mentioned.

Futher, debugfs_create_file() creates a full proxy for fops, protecting
against removal races.  DEFINE_DEBUGFS_ATTRIBUTE adds its own protection
but just for ->read() and ->write().  I don't think we need both.

Thanks,

                Ilya
Jeff Layton Feb. 2, 2021, 12:45 p.m. UTC | #2
On Tue, 2021-02-02 at 13:07 +0100, Ilya Dryomov wrote:
> On Mon, Feb 1, 2021 at 8:52 AM Jiapeng Chong

> <jiapeng.chong@linux.alibaba.com> wrote:

> > 

> > Fix the following coccicheck warning:

> > 

> > ./fs/ceph/debugfs.c:347:0-23: WARNING: congestion_kb_fops should be

> > defined with DEFINE_DEBUGFS_ATTRIBUTE.

> > 

> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>

> > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>

> > ---

> >  fs/ceph/debugfs.c | 4 ++--

> >  1 file changed, 2 insertions(+), 2 deletions(-)

> > 

> > diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c

> > index 66989c8..617327e 100644

> > --- a/fs/ceph/debugfs.c

> > +++ b/fs/ceph/debugfs.c

> > @@ -344,8 +344,8 @@ static int congestion_kb_get(void *data, u64 *val)

> >         return 0;

> >  }

> > 

> > -DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,

> > -                       congestion_kb_set, "%llu\n");

> > +DEFINE_DEBUGFS_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,

> > +                         congestion_kb_set, "%llu\n");

> > 

> > 

> >  void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)

> 

> Hi Jiapeng,

> 

> What is the benefit of this conversion?

> 

> From a quick look, with DEFINE_DEBUGFS_ATTRIBUTE writeback_congestion_kb

> file would no longer be seekable.  It may not matter much, but something

> that should have been mentioned.

> 

> Futher, debugfs_create_file() creates a full proxy for fops, protecting

> against removal races.  DEFINE_DEBUGFS_ATTRIBUTE adds its own protection

> but just for ->read() and ->write().  I don't think we need both.

> 



The coccinelle script clarifies some of this. See the commit log here:

    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5103068eaca290f890a30aae70085fac44cecaf6

That said, it also mentions that the file should be converted to use
debugfs_create_file_unsafe now as well, and that wasn't done in this
patch. Jiapeng, was that intentional? If so, why?

-- 
Jeff Layton <jlayton@kernel.org>
Jeff Layton Feb. 2, 2021, 4:01 p.m. UTC | #3
On Tue, 2021-02-02 at 07:45 -0500, Jeff Layton wrote:
> On Tue, 2021-02-02 at 13:07 +0100, Ilya Dryomov wrote:

> > On Mon, Feb 1, 2021 at 8:52 AM Jiapeng Chong

> > <jiapeng.chong@linux.alibaba.com> wrote:

> > > 

> > > Fix the following coccicheck warning:

> > > 

> > > ./fs/ceph/debugfs.c:347:0-23: WARNING: congestion_kb_fops should be

> > > defined with DEFINE_DEBUGFS_ATTRIBUTE.

> > > 

> > > Reported-by: Abaci Robot <abaci@linux.alibaba.com>

> > > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>

> > > ---

> > >  fs/ceph/debugfs.c | 4 ++--

> > >  1 file changed, 2 insertions(+), 2 deletions(-)

> > > 

> > > diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c

> > > index 66989c8..617327e 100644

> > > --- a/fs/ceph/debugfs.c

> > > +++ b/fs/ceph/debugfs.c

> > > @@ -344,8 +344,8 @@ static int congestion_kb_get(void *data, u64 *val)

> > >         return 0;

> > >  }

> > > 

> > > -DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,

> > > -                       congestion_kb_set, "%llu\n");

> > > +DEFINE_DEBUGFS_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,

> > > +                         congestion_kb_set, "%llu\n");

> > > 

> > > 

> > >  void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)

> > 

> > Hi Jiapeng,

> > 

> > What is the benefit of this conversion?

> > 

> > From a quick look, with DEFINE_DEBUGFS_ATTRIBUTE writeback_congestion_kb

> > file would no longer be seekable.  It may not matter much, but something

> > that should have been mentioned.

> > 

> > Futher, debugfs_create_file() creates a full proxy for fops, protecting

> > against removal races.  DEFINE_DEBUGFS_ATTRIBUTE adds its own protection

> > but just for ->read() and ->write().  I don't think we need both.

> > 

> 

> 

> The coccinelle script clarifies some of this. See the commit log here:

> 

>     https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5103068eaca290f890a30aae70085fac44cecaf6

> 

> That said, it also mentions that the file should be converted to use

> debugfs_create_file_unsafe now as well, and that wasn't done in this

> patch. Jiapeng, was that intentional? If so, why?

> 


For now, I've dropped this patch until the situation with
debugfs_create_file_unsafe is clear.
-- 
Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c
index 66989c8..617327e 100644
--- a/fs/ceph/debugfs.c
+++ b/fs/ceph/debugfs.c
@@ -344,8 +344,8 @@  static int congestion_kb_get(void *data, u64 *val)
 	return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
-			congestion_kb_set, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
+			  congestion_kb_set, "%llu\n");
 
 
 void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)