* [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() [not found] <20211021151528.116818-1-lmb@cloudflare.com> @ 2021-10-21 15:15 ` Lorenz Bauer 2021-10-22 0:34 ` Alexei Starovoitov 2021-10-27 23:21 ` Daniel Borkmann 0 siblings, 2 replies; 5+ messages in thread From: Lorenz Bauer @ 2021-10-21 15:15 UTC (permalink / raw) To: Alexander Viro, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: kernel-team, Lorenz Bauer, linux-fsdevel, linux-kernel, netdev, bpf Allow atomic exchange via RENAME_EXCHANGE when using simple_rename. This affects binderfs, ramfs, hubetlbfs and bpffs. There isn't much to do except update the various *time fields. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> --- fs/libfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/libfs.c b/fs/libfs.c index 51b4de3b3447..93c03d593749 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -455,9 +455,12 @@ int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir, struct inode *inode = d_inode(old_dentry); int they_are_dirs = d_is_dir(old_dentry); - if (flags & ~RENAME_NOREPLACE) + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) return -EINVAL; + if (flags & RENAME_EXCHANGE) + goto done; + if (!simple_empty(new_dentry)) return -ENOTEMPTY; @@ -472,6 +475,7 @@ int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir, inc_nlink(new_dir); } +done: old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime = new_dir->i_mtime = inode->i_ctime = current_time(old_dir); -- 2.32.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() 2021-10-21 15:15 ` [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() Lorenz Bauer @ 2021-10-22 0:34 ` Alexei Starovoitov 2021-10-27 23:21 ` Daniel Borkmann 1 sibling, 0 replies; 5+ messages in thread From: Alexei Starovoitov @ 2021-10-22 0:34 UTC (permalink / raw) To: Lorenz Bauer Cc: Alexander Viro, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, kernel-team, Linux-Fsdevel, LKML, Network Development, bpf On Thu, Oct 21, 2021 at 8:16 AM Lorenz Bauer <lmb@cloudflare.com> wrote: > > Allow atomic exchange via RENAME_EXCHANGE when using simple_rename. > This affects binderfs, ramfs, hubetlbfs and bpffs. There isn't much > to do except update the various *time fields. > > Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> Al, could you please Ack this patch so we can route the whole set through bpf-next tree? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() 2021-10-21 15:15 ` [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() Lorenz Bauer 2021-10-22 0:34 ` Alexei Starovoitov @ 2021-10-27 23:21 ` Daniel Borkmann 2021-10-28 8:43 ` Miklos Szeredi 1 sibling, 1 reply; 5+ messages in thread From: Daniel Borkmann @ 2021-10-27 23:21 UTC (permalink / raw) To: Lorenz Bauer, Alexander Viro, Alexei Starovoitov, Andrii Nakryiko Cc: kernel-team, linux-fsdevel, linux-kernel, netdev, bpf, mszeredi, gregkh [ Adding Miklos & Greg to Cc for review given e0e0be8a8355 ("libfs: support RENAME_NOREPLACE in simple_rename()"). If you have a chance, would be great if you could take a look, thanks! ] On 10/21/21 5:15 PM, Lorenz Bauer wrote: > Allow atomic exchange via RENAME_EXCHANGE when using simple_rename. > This affects binderfs, ramfs, hubetlbfs and bpffs. There isn't much > to do except update the various *time fields. > > Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> > --- > fs/libfs.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/fs/libfs.c b/fs/libfs.c > index 51b4de3b3447..93c03d593749 100644 > --- a/fs/libfs.c > +++ b/fs/libfs.c > @@ -455,9 +455,12 @@ int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir, > struct inode *inode = d_inode(old_dentry); > int they_are_dirs = d_is_dir(old_dentry); > > - if (flags & ~RENAME_NOREPLACE) > + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) > return -EINVAL; > > + if (flags & RENAME_EXCHANGE) > + goto done; > + > if (!simple_empty(new_dentry)) > return -ENOTEMPTY; > > @@ -472,6 +475,7 @@ int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir, > inc_nlink(new_dir); > } > > +done: > old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime = > new_dir->i_mtime = inode->i_ctime = current_time(old_dir); > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() 2021-10-27 23:21 ` Daniel Borkmann @ 2021-10-28 8:43 ` Miklos Szeredi 2021-10-28 9:49 ` Lorenz Bauer 0 siblings, 1 reply; 5+ messages in thread From: Miklos Szeredi @ 2021-10-28 8:43 UTC (permalink / raw) To: Daniel Borkmann Cc: Lorenz Bauer, Alexander Viro, Alexei Starovoitov, Andrii Nakryiko, kernel-team, linux-fsdevel, lkml, netdev, bpf, Greg Kroah-Hartman On Thu, Oct 28, 2021 at 1:46 AM Daniel Borkmann <daniel@iogearbox.net> wrote: > > [ Adding Miklos & Greg to Cc for review given e0e0be8a8355 ("libfs: support RENAME_NOREPLACE in > simple_rename()"). If you have a chance, would be great if you could take a look, thanks! ] > > On 10/21/21 5:15 PM, Lorenz Bauer wrote: > > Allow atomic exchange via RENAME_EXCHANGE when using simple_rename. > > This affects binderfs, ramfs, hubetlbfs and bpffs. There isn't much > > to do except update the various *time fields. > > > > Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> > > --- > > fs/libfs.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/fs/libfs.c b/fs/libfs.c > > index 51b4de3b3447..93c03d593749 100644 > > --- a/fs/libfs.c > > +++ b/fs/libfs.c > > @@ -455,9 +455,12 @@ int simple_rename(struct user_namespace *mnt_userns, struct inode *old_dir, > > struct inode *inode = d_inode(old_dentry); > > int they_are_dirs = d_is_dir(old_dentry); > > > > - if (flags & ~RENAME_NOREPLACE) > > + if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) > > return -EINVAL; > > > > + if (flags & RENAME_EXCHANGE) > > + goto done; > > + This is not sufficient. RENAME_EXCHANGE can swap a dir and a non-dir, in which case the parent nlink counters need to be fixed up. See shmem_exchange(). My suggestion is to move that function to libfs.c:simple_rename_exchange(). Thanks, Miklos ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() 2021-10-28 8:43 ` Miklos Szeredi @ 2021-10-28 9:49 ` Lorenz Bauer 0 siblings, 0 replies; 5+ messages in thread From: Lorenz Bauer @ 2021-10-28 9:49 UTC (permalink / raw) To: Miklos Szeredi Cc: Daniel Borkmann, Alexander Viro, Alexei Starovoitov, Andrii Nakryiko, kernel-team, linux-fsdevel, lkml, Networking, bpf, Greg Kroah-Hartman On Thu, 28 Oct 2021 at 09:43, Miklos Szeredi <mszeredi@redhat.com> wrote: > > This is not sufficient. RENAME_EXCHANGE can swap a dir and a > non-dir, in which case the parent nlink counters need to be fixed up. > > See shmem_exchange(). My suggestion is to move that function to > libfs.c:simple_rename_exchange(). Thanks for the pointer, I sent a v3. Lorenz -- Lorenz Bauer | Systems Engineer 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK www.cloudflare.com ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-10-28 9:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20211021151528.116818-1-lmb@cloudflare.com>
2021-10-21 15:15 ` [PATCH bpf-next v2 1/3] libfs: support RENAME_EXCHANGE in simple_rename() Lorenz Bauer
2021-10-22 0:34 ` Alexei Starovoitov
2021-10-27 23:21 ` Daniel Borkmann
2021-10-28 8:43 ` Miklos Szeredi
2021-10-28 9:49 ` Lorenz Bauer
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).