diff mbox series

[bpf-next,v3,1/4] libfs: move shmem_exchange to simple_rename_exchange

Message ID 20211028094724.59043-2-lmb@cloudflare.com (mailing list archive)
State Accepted
Commit 6429e46304ac7820eebbea2bf5d73b90c18e0e06
Delegated to: BPF
Headers show
Series Support RENAME_EXCHANGE on bpffs | expand

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 5 maintainers not CCed: john.fastabend@gmail.com yhs@fb.com songliubraving@fb.com kafai@fb.com kpsingh@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 16998 this patch: 16998
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch warning CHECK: extern prototypes should be avoided in .h files CHECK: multiple assignments should be avoided WARNING: line length of 83 exceeds 80 columns WARNING: line length of 84 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 16418 this patch: 16418
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Lorenz Bauer Oct. 28, 2021, 9:47 a.m. UTC
Move shmem_exchange and make it available to other callers.

Suggested-by: <mszeredi@redhat.com>
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
---
 fs/libfs.c         | 24 ++++++++++++++++++++++++
 include/linux/fs.h |  2 ++
 mm/shmem.c         | 24 +-----------------------
 3 files changed, 27 insertions(+), 23 deletions(-)

Comments

Daniel Borkmann Oct. 29, 2021, 3:28 p.m. UTC | #1
On 10/28/21 11:47 AM, Lorenz Bauer wrote:
> Move shmem_exchange and make it available to other callers.
> 
> Suggested-by: <mszeredi@redhat.com>

nit: Should say proper name, but we can fix it up while applying.

Miklos, does the below look good to you? Would be good to have an ACK from fs
folks before applying, please take a look if you have a chance. Thanks!

> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> ---
>   fs/libfs.c         | 24 ++++++++++++++++++++++++
>   include/linux/fs.h |  2 ++
>   mm/shmem.c         | 24 +-----------------------
>   3 files changed, 27 insertions(+), 23 deletions(-)
> 
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 51b4de3b3447..1cf144dc9ed2 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -448,6 +448,30 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry)
>   }
>   EXPORT_SYMBOL(simple_rmdir);
>   
> +int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
> +			   struct inode *new_dir, struct dentry *new_dentry)
> +{
> +	bool old_is_dir = d_is_dir(old_dentry);
> +	bool new_is_dir = d_is_dir(new_dentry);
> +
> +	if (old_dir != new_dir && old_is_dir != new_is_dir) {
> +		if (old_is_dir) {
> +			drop_nlink(old_dir);
> +			inc_nlink(new_dir);
> +		} else {
> +			drop_nlink(new_dir);
> +			inc_nlink(old_dir);
> +		}
> +	}
> +	old_dir->i_ctime = old_dir->i_mtime =
> +	new_dir->i_ctime = new_dir->i_mtime =
> +	d_inode(old_dentry)->i_ctime =
> +	d_inode(new_dentry)->i_ctime = current_time(old_dir);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(simple_rename_exchange);
> +
>   int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
>   		  struct dentry *old_dentry, struct inode *new_dir,
>   		  struct dentry *new_dentry, unsigned int flags)
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index e7a633353fd2..333b8af405ce 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3383,6 +3383,8 @@ extern int simple_open(struct inode *inode, struct file *file);
>   extern int simple_link(struct dentry *, struct inode *, struct dentry *);
>   extern int simple_unlink(struct inode *, struct dentry *);
>   extern int simple_rmdir(struct inode *, struct dentry *);
> +extern int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
> +				  struct inode *new_dir, struct dentry *new_dentry);
>   extern int simple_rename(struct user_namespace *, struct inode *,
>   			 struct dentry *, struct inode *, struct dentry *,
>   			 unsigned int);
> diff --git a/mm/shmem.c b/mm/shmem.c
> index b5860f4a2738..a18dde3d3092 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -2945,28 +2945,6 @@ static int shmem_rmdir(struct inode *dir, struct dentry *dentry)
>   	return shmem_unlink(dir, dentry);
>   }
>   
> -static int shmem_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry)
> -{
> -	bool old_is_dir = d_is_dir(old_dentry);
> -	bool new_is_dir = d_is_dir(new_dentry);
> -
> -	if (old_dir != new_dir && old_is_dir != new_is_dir) {
> -		if (old_is_dir) {
> -			drop_nlink(old_dir);
> -			inc_nlink(new_dir);
> -		} else {
> -			drop_nlink(new_dir);
> -			inc_nlink(old_dir);
> -		}
> -	}
> -	old_dir->i_ctime = old_dir->i_mtime =
> -	new_dir->i_ctime = new_dir->i_mtime =
> -	d_inode(old_dentry)->i_ctime =
> -	d_inode(new_dentry)->i_ctime = current_time(old_dir);
> -
> -	return 0;
> -}
> -
>   static int shmem_whiteout(struct user_namespace *mnt_userns,
>   			  struct inode *old_dir, struct dentry *old_dentry)
>   {
> @@ -3012,7 +2990,7 @@ static int shmem_rename2(struct user_namespace *mnt_userns,
>   		return -EINVAL;
>   
>   	if (flags & RENAME_EXCHANGE)
> -		return shmem_exchange(old_dir, old_dentry, new_dir, new_dentry);
> +		return simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry);
>   
>   	if (!simple_empty(new_dentry))
>   		return -ENOTEMPTY;
>
Miklos Szeredi Nov. 2, 2021, 8:58 a.m. UTC | #2
On Thu, 28 Oct 2021 at 11:48, Lorenz Bauer <lmb@cloudflare.com> wrote:
>
> Move shmem_exchange and make it available to other callers.
>
> Suggested-by: <mszeredi@redhat.com>
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>

Acked-by: Miklos Szeredi <mszeredi@redhat.com>
diff mbox series

Patch

diff --git a/fs/libfs.c b/fs/libfs.c
index 51b4de3b3447..1cf144dc9ed2 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -448,6 +448,30 @@  int simple_rmdir(struct inode *dir, struct dentry *dentry)
 }
 EXPORT_SYMBOL(simple_rmdir);
 
+int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
+			   struct inode *new_dir, struct dentry *new_dentry)
+{
+	bool old_is_dir = d_is_dir(old_dentry);
+	bool new_is_dir = d_is_dir(new_dentry);
+
+	if (old_dir != new_dir && old_is_dir != new_is_dir) {
+		if (old_is_dir) {
+			drop_nlink(old_dir);
+			inc_nlink(new_dir);
+		} else {
+			drop_nlink(new_dir);
+			inc_nlink(old_dir);
+		}
+	}
+	old_dir->i_ctime = old_dir->i_mtime =
+	new_dir->i_ctime = new_dir->i_mtime =
+	d_inode(old_dentry)->i_ctime =
+	d_inode(new_dentry)->i_ctime = current_time(old_dir);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(simple_rename_exchange);
+
 int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
 		  struct dentry *old_dentry, struct inode *new_dir,
 		  struct dentry *new_dentry, unsigned int flags)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e7a633353fd2..333b8af405ce 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3383,6 +3383,8 @@  extern int simple_open(struct inode *inode, struct file *file);
 extern int simple_link(struct dentry *, struct inode *, struct dentry *);
 extern int simple_unlink(struct inode *, struct dentry *);
 extern int simple_rmdir(struct inode *, struct dentry *);
+extern int simple_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
+				  struct inode *new_dir, struct dentry *new_dentry);
 extern int simple_rename(struct user_namespace *, struct inode *,
 			 struct dentry *, struct inode *, struct dentry *,
 			 unsigned int);
diff --git a/mm/shmem.c b/mm/shmem.c
index b5860f4a2738..a18dde3d3092 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2945,28 +2945,6 @@  static int shmem_rmdir(struct inode *dir, struct dentry *dentry)
 	return shmem_unlink(dir, dentry);
 }
 
-static int shmem_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry)
-{
-	bool old_is_dir = d_is_dir(old_dentry);
-	bool new_is_dir = d_is_dir(new_dentry);
-
-	if (old_dir != new_dir && old_is_dir != new_is_dir) {
-		if (old_is_dir) {
-			drop_nlink(old_dir);
-			inc_nlink(new_dir);
-		} else {
-			drop_nlink(new_dir);
-			inc_nlink(old_dir);
-		}
-	}
-	old_dir->i_ctime = old_dir->i_mtime =
-	new_dir->i_ctime = new_dir->i_mtime =
-	d_inode(old_dentry)->i_ctime =
-	d_inode(new_dentry)->i_ctime = current_time(old_dir);
-
-	return 0;
-}
-
 static int shmem_whiteout(struct user_namespace *mnt_userns,
 			  struct inode *old_dir, struct dentry *old_dentry)
 {
@@ -3012,7 +2990,7 @@  static int shmem_rename2(struct user_namespace *mnt_userns,
 		return -EINVAL;
 
 	if (flags & RENAME_EXCHANGE)
-		return shmem_exchange(old_dir, old_dentry, new_dir, new_dentry);
+		return simple_rename_exchange(old_dir, old_dentry, new_dir, new_dentry);
 
 	if (!simple_empty(new_dentry))
 		return -ENOTEMPTY;