From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-unionfs@vger.kernel.org,
"André Almeida" <andrealmeid@igalia.com>,
"John Schoenick" <johns@valvesoftware.com>
Subject: [PATCH] vfs: change 'struct file *' argument to 'const struct file *' where possible
Date: Mon, 5 May 2025 17:41:47 +0200 [thread overview]
Message-ID: <20250505154149.301235-1-mszeredi@redhat.com> (raw)
Let file_user_path(), file_user_inode() and file_clone_open() take const
pointer.
This allows removing a cast in ovl_open_realfile() when calling
backing_file_open().
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
This depends on commit 924577e4f6ca ("ovl: Fix nested backing file paths") in
git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs.git ovl-fixes
fs/file_table.c | 10 ++++++----
fs/internal.h | 1 +
fs/overlayfs/file.c | 2 +-
include/linux/fs.h | 12 ++++++------
4 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/fs/file_table.c b/fs/file_table.c
index c04ed94cdc4b..3b3f920a9175 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -52,16 +52,18 @@ struct backing_file {
};
};
-static inline struct backing_file *backing_file(struct file *f)
+#define backing_file(f) container_of(f, struct backing_file, file)
+
+struct path *backing_file_user_path(struct file *f)
{
- return container_of(f, struct backing_file, file);
+ return &backing_file(f)->user_path;
}
-struct path *backing_file_user_path(struct file *f)
+const struct path *backing_file_user_path_c(const struct file *f)
{
return &backing_file(f)->user_path;
}
-EXPORT_SYMBOL_GPL(backing_file_user_path);
+EXPORT_SYMBOL_GPL(backing_file_user_path_c);
static inline void file_free(struct file *f)
{
diff --git a/fs/internal.h b/fs/internal.h
index b9b3e29a73fd..84a330763343 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -100,6 +100,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);
+struct path *backing_file_user_path(struct file *f);
static inline void file_put_write_access(struct file *file)
{
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);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 016b0fe1536e..7db9cd5a4bee 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2813,7 +2813,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);
+const struct path *backing_file_user_path_c(const struct file *f);
/*
* When mmapping a file on a stackable filesystem (e.g., overlayfs), the file
@@ -2825,21 +2825,21 @@ 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 backing_file_user_path_c(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);
+ return d_inode(backing_file_user_path_c(f)->dentry);
return file_inode(f);
}
-static inline struct file *file_clone_open(struct file *file)
+static inline struct file *file_clone_open(const struct file *file)
{
return dentry_open(&file->f_path, file->f_flags, file->f_cred);
}
--
2.49.0
next reply other threads:[~2025-05-05 15:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 15:41 Miklos Szeredi [this message]
2025-05-05 16:27 ` [PATCH] vfs: change 'struct file *' argument to 'const struct file *' where possible Matthew Wilcox
2025-05-05 17:29 ` Al Viro
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=20250505154149.301235-1-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=andrealmeid@igalia.com \
--cc=johns@valvesoftware.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
/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).