bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Lorenz Bauer <lmb@cloudflare.com>,
	viro@zeniv.linux.org.uk, Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: mszeredi@redhat.com, gregkh@linuxfoundation.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 1/4] libfs: move shmem_exchange to simple_rename_exchange
Date: Fri, 29 Oct 2021 17:28:17 +0200	[thread overview]
Message-ID: <0c957c87-cfd1-fceb-ce18-54274eee9fc2@iogearbox.net> (raw)
In-Reply-To: <20211028094724.59043-2-lmb@cloudflare.com>

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;
> 


  reply	other threads:[~2021-10-29 15:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-28  9:47 [PATCH bpf-next v3 0/4] Support RENAME_EXCHANGE on bpffs Lorenz Bauer
2021-10-28  9:47 ` [PATCH bpf-next v3 1/4] libfs: move shmem_exchange to simple_rename_exchange Lorenz Bauer
2021-10-29 15:28   ` Daniel Borkmann [this message]
2021-11-02  8:58   ` Miklos Szeredi
2021-10-28  9:47 ` [PATCH bpf-next v3 2/4] libfs: support RENAME_EXCHANGE in simple_rename() Lorenz Bauer
2021-11-02  9:25   ` Miklos Szeredi
2021-11-02 10:11     ` Daniel Borkmann
2021-11-02 11:36       ` Christian Brauner
2021-10-28  9:47 ` [PATCH bpf-next v3 3/4] selftests: bpf: convert test_bpffs to ASSERT macros Lorenz Bauer
2021-10-28  9:47 ` [PATCH bpf-next v3 4/4] selftests: bpf: test RENAME_EXCHANGE and RENAME_NOREPLACE on bpffs Lorenz Bauer
2021-11-03 15:00 ` [PATCH bpf-next v3 0/4] Support RENAME_EXCHANGE " patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c957c87-cfd1-fceb-ce18-54274eee9fc2@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hughd@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lmb@cloudflare.com \
    --cc=mszeredi@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).