diff mbox series

[v3,06/10] debugfs: simplify __debugfs_remove_file()

Message ID 20190526143411.11244-7-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show
Series Sort out fsnotify_nameremove() mess | expand

Commit Message

Amir Goldstein May 26, 2019, 2:34 p.m. UTC
Move simple_unlink()+d_delete() from __debugfs_remove_file() into
caller __debugfs_remove() and rename helper for post remove file to
__debugfs_file_removed().

This will simplify adding fsnotify_unlink() hook.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/debugfs/inode.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Amir Goldstein May 30, 2019, 5:49 a.m. UTC | #1
On Sun, May 26, 2019 at 5:34 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> Move simple_unlink()+d_delete() from __debugfs_remove_file() into
> caller __debugfs_remove() and rename helper for post remove file to
> __debugfs_file_removed().
>
> This will simplify adding fsnotify_unlink() hook.
>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Hi Greg,

Will be you be able to provide an ACK on this debugfs patch and the next one.

Thanks,
Amir.

> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  fs/debugfs/inode.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
> index acef14ad53db..d89874da9791 100644
> --- a/fs/debugfs/inode.c
> +++ b/fs/debugfs/inode.c
> @@ -617,13 +617,10 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
>  }
>  EXPORT_SYMBOL_GPL(debugfs_create_symlink);
>
> -static void __debugfs_remove_file(struct dentry *dentry, struct dentry *parent)
> +static void __debugfs_file_removed(struct dentry *dentry)
>  {
>         struct debugfs_fsdata *fsd;
>
> -       simple_unlink(d_inode(parent), dentry);
> -       d_delete(dentry);
> -
>         /*
>          * Paired with the closing smp_mb() implied by a successful
>          * cmpxchg() in debugfs_file_get(): either
> @@ -644,16 +641,15 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
>
>         if (simple_positive(dentry)) {
>                 dget(dentry);
> -               if (!d_is_reg(dentry)) {
> -                       if (d_is_dir(dentry))
> -                               ret = simple_rmdir(d_inode(parent), dentry);
> -                       else
> -                               simple_unlink(d_inode(parent), dentry);
> -                       if (!ret)
> -                               d_delete(dentry);
> +               if (d_is_dir(dentry)) {
> +                       ret = simple_rmdir(d_inode(parent), dentry);
>                 } else {
> -                       __debugfs_remove_file(dentry, parent);
> +                       simple_unlink(d_inode(parent), dentry);
>                 }
> +               if (!ret)
> +                       d_delete(dentry);
> +               if (d_is_reg(dentry))
> +                       __debugfs_file_removed(dentry);
>                 dput(dentry);
>         }
>         return ret;
> --
> 2.17.1
>
Greg Kroah-Hartman May 30, 2019, 12:27 p.m. UTC | #2
On Thu, May 30, 2019 at 08:49:52AM +0300, Amir Goldstein wrote:
> On Sun, May 26, 2019 at 5:34 PM Amir Goldstein <amir73il@gmail.com> wrote:
> >
> > Move simple_unlink()+d_delete() from __debugfs_remove_file() into
> > caller __debugfs_remove() and rename helper for post remove file to
> > __debugfs_file_removed().
> >
> > This will simplify adding fsnotify_unlink() hook.
> >
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Hi Greg,
> 
> Will be you be able to provide an ACK on this debugfs patch and the next one.

It's only been 4 days, and I'm traveling this week, give me a chance...
Greg Kroah-Hartman June 3, 2019, 1:31 p.m. UTC | #3
On Sun, May 26, 2019 at 05:34:07PM +0300, Amir Goldstein wrote:
> Move simple_unlink()+d_delete() from __debugfs_remove_file() into
> caller __debugfs_remove() and rename helper for post remove file to
> __debugfs_file_removed().
> 
> This will simplify adding fsnotify_unlink() hook.
> 
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  fs/debugfs/inode.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
> index acef14ad53db..d89874da9791 100644
> --- a/fs/debugfs/inode.c
> +++ b/fs/debugfs/inode.c
> @@ -617,13 +617,10 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
>  }
>  EXPORT_SYMBOL_GPL(debugfs_create_symlink);
>  
> -static void __debugfs_remove_file(struct dentry *dentry, struct dentry *parent)
> +static void __debugfs_file_removed(struct dentry *dentry)
>  {
>  	struct debugfs_fsdata *fsd;
>  
> -	simple_unlink(d_inode(parent), dentry);
> -	d_delete(dentry);
> -
>  	/*
>  	 * Paired with the closing smp_mb() implied by a successful
>  	 * cmpxchg() in debugfs_file_get(): either
> @@ -644,16 +641,15 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
>  
>  	if (simple_positive(dentry)) {
>  		dget(dentry);
> -		if (!d_is_reg(dentry)) {
> -			if (d_is_dir(dentry))
> -				ret = simple_rmdir(d_inode(parent), dentry);
> -			else
> -				simple_unlink(d_inode(parent), dentry);
> -			if (!ret)
> -				d_delete(dentry);
> +		if (d_is_dir(dentry)) {
> +			ret = simple_rmdir(d_inode(parent), dentry);
>  		} else {
> -			__debugfs_remove_file(dentry, parent);
> +			simple_unlink(d_inode(parent), dentry);
>  		}
> +		if (!ret)
> +			d_delete(dentry);
> +		if (d_is_reg(dentry))
> +			__debugfs_file_removed(dentry);
>  		dput(dentry);
>  	}
>  	return ret;

Ugh, I had to stare at this for a long time.  I _think_ it all looks
equalivant now, but if this breaks, I know who to blame :)

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff mbox series

Patch

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index acef14ad53db..d89874da9791 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -617,13 +617,10 @@  struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 }
 EXPORT_SYMBOL_GPL(debugfs_create_symlink);
 
-static void __debugfs_remove_file(struct dentry *dentry, struct dentry *parent)
+static void __debugfs_file_removed(struct dentry *dentry)
 {
 	struct debugfs_fsdata *fsd;
 
-	simple_unlink(d_inode(parent), dentry);
-	d_delete(dentry);
-
 	/*
 	 * Paired with the closing smp_mb() implied by a successful
 	 * cmpxchg() in debugfs_file_get(): either
@@ -644,16 +641,15 @@  static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
 
 	if (simple_positive(dentry)) {
 		dget(dentry);
-		if (!d_is_reg(dentry)) {
-			if (d_is_dir(dentry))
-				ret = simple_rmdir(d_inode(parent), dentry);
-			else
-				simple_unlink(d_inode(parent), dentry);
-			if (!ret)
-				d_delete(dentry);
+		if (d_is_dir(dentry)) {
+			ret = simple_rmdir(d_inode(parent), dentry);
 		} else {
-			__debugfs_remove_file(dentry, parent);
+			simple_unlink(d_inode(parent), dentry);
 		}
+		if (!ret)
+			d_delete(dentry);
+		if (d_is_reg(dentry))
+			__debugfs_file_removed(dentry);
 		dput(dentry);
 	}
 	return ret;