* [PATCH 0/2] backing_file accessors cleanup
@ 2025-06-07 11:53 Amir Goldstein
2025-06-07 11:53 ` [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers Amir Goldstein
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Amir Goldstein @ 2025-06-07 11:53 UTC (permalink / raw)
To: Christian Brauner
Cc: Miklos Szeredi, Al Viro, Jan Kara, Linus Torvalds, linux-fsdevel
Christian,
As promissed, here is the backing_file accessors cleanup that
was dicussed on the overlayfs pr [1].
I have kept the ovl patch separate from the vfs patch, so that
the vfs patch could be backported to stable kernels, because
the ovl patch depends on master of today.
Thanks,
Amir.
[1] https://lore.kernel.org/linux-fsdevel/CAOQ4uxgFJCikAi4o4e9vzXTH=cUQGyvoo+cpdtfmBwJzutSCzw@mail.gmail.com/
Amir Goldstein (2):
fs: constify file ptr in backing_file accessor helpers
ovl: remove unneeded non-const conversion
fs/backing-file.c | 4 ++--
fs/file_table.c | 13 ++++++++-----
fs/internal.h | 1 +
fs/overlayfs/file.c | 2 +-
include/linux/fs.h | 6 +++---
5 files changed, 15 insertions(+), 11 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers
2025-06-07 11:53 [PATCH 0/2] backing_file accessors cleanup Amir Goldstein
@ 2025-06-07 11:53 ` Amir Goldstein
2025-06-11 18:57 ` Al Viro
2025-06-07 11:53 ` [PATCH 2/2] ovl: remove unneeded non-const conversion Amir Goldstein
2025-06-11 9:13 ` [PATCH 0/2] backing_file accessors cleanup Christian Brauner
2 siblings, 1 reply; 6+ messages in thread
From: Amir Goldstein @ 2025-06-07 11:53 UTC (permalink / raw)
To: Christian Brauner
Cc: Miklos Szeredi, Al Viro, Jan Kara, Linus Torvalds, linux-fsdevel
Add internal helper backing_file_set_user_path() for the only
two cases that need to modify backing_file fields.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/backing-file.c | 4 ++--
fs/file_table.c | 13 ++++++++-----
fs/internal.h | 1 +
include/linux/fs.h | 6 +++---
4 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/fs/backing-file.c b/fs/backing-file.c
index 763fbe9b72b2..8c7396bff121 100644
--- a/fs/backing-file.c
+++ b/fs/backing-file.c
@@ -41,7 +41,7 @@ struct file *backing_file_open(const struct path *user_path, int flags,
return f;
path_get(user_path);
- *backing_file_user_path(f) = *user_path;
+ backing_file_set_user_path(f, user_path);
error = vfs_open(real_path, f);
if (error) {
fput(f);
@@ -65,7 +65,7 @@ struct file *backing_tmpfile_open(const struct path *user_path, int flags,
return f;
path_get(user_path);
- *backing_file_user_path(f) = *user_path;
+ backing_file_set_user_path(f, user_path);
error = vfs_tmpfile(real_idmap, real_parentpath, f, mode);
if (error) {
fput(f);
diff --git a/fs/file_table.c b/fs/file_table.c
index 138114d64307..f09d79a98111 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -52,17 +52,20 @@ struct backing_file {
};
};
-static inline struct backing_file *backing_file(struct file *f)
-{
- return container_of(f, struct backing_file, file);
-}
+#define backing_file(f) container_of(f, struct backing_file, file)
-struct path *backing_file_user_path(struct file *f)
+struct path *backing_file_user_path(const struct file *f)
{
return &backing_file(f)->user_path;
}
EXPORT_SYMBOL_GPL(backing_file_user_path);
+void backing_file_set_user_path(struct file *f, const struct path *path)
+{
+ backing_file(f)->user_path = *path;
+}
+EXPORT_SYMBOL_GPL(backing_file_set_user_path);
+
static inline void file_free(struct file *f)
{
security_file_free(f);
diff --git a/fs/internal.h b/fs/internal.h
index 393f6c5c24f6..d733d8bb3d1f 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -101,6 +101,7 @@ extern void chroot_fs_refs(const struct path *, const struct path *);
struct file *alloc_empty_file(int flags, const struct cred *cred);
struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred);
struct file *alloc_empty_backing_file(int flags, const struct cred *cred);
+void backing_file_set_user_path(struct file *f, const struct path *path);
static inline void file_put_write_access(struct file *file)
{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 96c7925a6551..fbcd74ae2a50 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2864,7 +2864,7 @@ struct file *dentry_open_nonotify(const struct path *path, int flags,
const struct cred *cred);
struct file *dentry_create(const struct path *path, int flags, umode_t mode,
const struct cred *cred);
-struct path *backing_file_user_path(struct file *f);
+struct path *backing_file_user_path(const struct file *f);
/*
* When mmapping a file on a stackable filesystem (e.g., overlayfs), the file
@@ -2876,14 +2876,14 @@ struct path *backing_file_user_path(struct file *f);
* by fstat() on that same fd.
*/
/* Get the path to display in /proc/<pid>/maps */
-static inline const struct path *file_user_path(struct file *f)
+static inline const struct path *file_user_path(const struct file *f)
{
if (unlikely(f->f_mode & FMODE_BACKING))
return backing_file_user_path(f);
return &f->f_path;
}
/* Get the inode whose inode number to display in /proc/<pid>/maps */
-static inline const struct inode *file_user_inode(struct file *f)
+static inline const struct inode *file_user_inode(const struct file *f)
{
if (unlikely(f->f_mode & FMODE_BACKING))
return d_inode(backing_file_user_path(f)->dentry);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] ovl: remove unneeded non-const conversion
2025-06-07 11:53 [PATCH 0/2] backing_file accessors cleanup Amir Goldstein
2025-06-07 11:53 ` [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers Amir Goldstein
@ 2025-06-07 11:53 ` Amir Goldstein
2025-06-11 9:13 ` [PATCH 0/2] backing_file accessors cleanup Christian Brauner
2 siblings, 0 replies; 6+ messages in thread
From: Amir Goldstein @ 2025-06-07 11:53 UTC (permalink / raw)
To: Christian Brauner
Cc: Miklos Szeredi, Al Viro, Jan Kara, Linus Torvalds, linux-fsdevel
file_user_path() now takes a const file ptr.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index dfea7bd800cb..f5b8877d5fe2 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -48,7 +48,7 @@ static struct file *ovl_open_realfile(const struct file *file,
if (!inode_owner_or_capable(real_idmap, realinode))
flags &= ~O_NOATIME;
- realfile = backing_file_open(file_user_path((struct file *) file),
+ realfile = backing_file_open(file_user_path(file),
flags, realpath, current_cred());
}
ovl_revert_creds(old_cred);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] backing_file accessors cleanup
2025-06-07 11:53 [PATCH 0/2] backing_file accessors cleanup Amir Goldstein
2025-06-07 11:53 ` [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers Amir Goldstein
2025-06-07 11:53 ` [PATCH 2/2] ovl: remove unneeded non-const conversion Amir Goldstein
@ 2025-06-11 9:13 ` Christian Brauner
2 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2025-06-11 9:13 UTC (permalink / raw)
To: Amir Goldstein
Cc: Christian Brauner, Miklos Szeredi, Al Viro, Jan Kara,
Linus Torvalds, linux-fsdevel
On Sat, 07 Jun 2025 13:53:02 +0200, Amir Goldstein wrote:
> Christian,
>
> As promissed, here is the backing_file accessors cleanup that
> was dicussed on the overlayfs pr [1].
>
> I have kept the ovl patch separate from the vfs patch, so that
> the vfs patch could be backported to stable kernels, because
> the ovl patch depends on master of today.
>
> [...]
Applied to the vfs-6.17.file branch of the vfs/vfs.git tree.
Patches in the vfs-6.17.file branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.17.file
[1/2] fs: constify file ptr in backing_file accessor helpers
https://git.kernel.org/vfs/vfs/c/52e50bf764e0
[2/2] ovl: remove unneeded non-const conversion
https://git.kernel.org/vfs/vfs/c/9445dc8817b5
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers
2025-06-07 11:53 ` [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers Amir Goldstein
@ 2025-06-11 18:57 ` Al Viro
2025-06-11 20:59 ` Amir Goldstein
0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2025-06-11 18:57 UTC (permalink / raw)
To: Amir Goldstein
Cc: Christian Brauner, Miklos Szeredi, Jan Kara, Linus Torvalds,
linux-fsdevel
On Sat, Jun 07, 2025 at 01:53:03PM +0200, Amir Goldstein wrote:
> -struct path *backing_file_user_path(struct file *f)
> +struct path *backing_file_user_path(const struct file *f)
> {
> return &backing_file(f)->user_path;
> }
> EXPORT_SYMBOL_GPL(backing_file_user_path);
const struct path *, hopefully? With separate backing_file_set_user_path()
you shouldn't need to modify that struct path via that functions...
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers
2025-06-11 18:57 ` Al Viro
@ 2025-06-11 20:59 ` Amir Goldstein
0 siblings, 0 replies; 6+ messages in thread
From: Amir Goldstein @ 2025-06-11 20:59 UTC (permalink / raw)
To: Al Viro
Cc: Christian Brauner, Miklos Szeredi, Jan Kara, Linus Torvalds,
linux-fsdevel
On Wed, Jun 11, 2025 at 8:57 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
>
> On Sat, Jun 07, 2025 at 01:53:03PM +0200, Amir Goldstein wrote:
>
> > -struct path *backing_file_user_path(struct file *f)
> > +struct path *backing_file_user_path(const struct file *f)
> > {
> > return &backing_file(f)->user_path;
> > }
> > EXPORT_SYMBOL_GPL(backing_file_user_path);
>
> const struct path *, hopefully? With separate backing_file_set_user_path()
> you shouldn't need to modify that struct path via that functions...
Doh! of course. overlooked.
Christian,
Could you please apply this (compile tested) change in your tree?
Thanks,
Amir.
diff --git a/fs/file_table.c b/fs/file_table.c
index f09d79a98111..b28bbfa07cb8 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -54,7 +54,7 @@ struct backing_file {
#define backing_file(f) container_of(f, struct backing_file, file)
-struct path *backing_file_user_path(const struct file *f)
+const struct path *backing_file_user_path(const struct file *f)
{
return &backing_file(f)->user_path;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index fbcd74ae2a50..7845d029a4c0 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2864,7 +2864,7 @@ struct file *dentry_open_nonotify(const struct
path *path, int flags,
const struct cred *cred);
struct file *dentry_create(const struct path *path, int flags, umode_t mode,
const struct cred *cred);
-struct path *backing_file_user_path(const struct file *f);
+const struct path *backing_file_user_path(const struct file *f);
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-06-11 20:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-07 11:53 [PATCH 0/2] backing_file accessors cleanup Amir Goldstein
2025-06-07 11:53 ` [PATCH 1/2] fs: constify file ptr in backing_file accessor helpers Amir Goldstein
2025-06-11 18:57 ` Al Viro
2025-06-11 20:59 ` Amir Goldstein
2025-06-07 11:53 ` [PATCH 2/2] ovl: remove unneeded non-const conversion Amir Goldstein
2025-06-11 9:13 ` [PATCH 0/2] backing_file accessors cleanup Christian Brauner
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).