Skip to content

Commit 04060e7

Browse files
committed
Merge patch series "backing_file accessors cleanup"
Amir Goldstein <[email protected]> says: 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. * patches from https://lore.kernel.org/[email protected]: ovl: remove unneeded non-const conversion fs: constify file ptr in backing_file accessor helpers Link: https://lore.kernel.org/linux-fsdevel/CAOQ4uxgFJCikAi4o4e9vzXTH=cUQGyvoo+cpdtfmBwJzutSCzw@mail.gmail.com/ [1] Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents bc92413 + 3ec2529 commit 04060e7

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

fs/backing-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct file *backing_file_open(const struct path *user_path, int flags,
4141
return f;
4242

4343
path_get(user_path);
44-
*backing_file_user_path(f) = *user_path;
44+
backing_file_set_user_path(f, user_path);
4545
error = vfs_open(real_path, f);
4646
if (error) {
4747
fput(f);
@@ -65,7 +65,7 @@ struct file *backing_tmpfile_open(const struct path *user_path, int flags,
6565
return f;
6666

6767
path_get(user_path);
68-
*backing_file_user_path(f) = *user_path;
68+
backing_file_set_user_path(f, user_path);
6969
error = vfs_tmpfile(real_idmap, real_parentpath, f, mode);
7070
if (error) {
7171
fput(f);

fs/file_table.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ struct backing_file {
5252
};
5353
};
5454

55-
static inline struct backing_file *backing_file(struct file *f)
56-
{
57-
return container_of(f, struct backing_file, file);
58-
}
55+
#define backing_file(f) container_of(f, struct backing_file, file)
5956

60-
struct path *backing_file_user_path(struct file *f)
57+
struct path *backing_file_user_path(const struct file *f)
6158
{
6259
return &backing_file(f)->user_path;
6360
}
6461
EXPORT_SYMBOL_GPL(backing_file_user_path);
6562

63+
void backing_file_set_user_path(struct file *f, const struct path *path)
64+
{
65+
backing_file(f)->user_path = *path;
66+
}
67+
EXPORT_SYMBOL_GPL(backing_file_set_user_path);
68+
6669
static inline void file_free(struct file *f)
6770
{
6871
security_file_free(f);

fs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ extern void chroot_fs_refs(const struct path *, const struct path *);
101101
struct file *alloc_empty_file(int flags, const struct cred *cred);
102102
struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred);
103103
struct file *alloc_empty_backing_file(int flags, const struct cred *cred);
104+
void backing_file_set_user_path(struct file *f, const struct path *path);
104105

105106
static inline void file_put_write_access(struct file *file)
106107
{

fs/overlayfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static struct file *ovl_open_realfile(const struct file *file,
4848
if (!inode_owner_or_capable(real_idmap, realinode))
4949
flags &= ~O_NOATIME;
5050

51-
realfile = backing_file_open(file_user_path((struct file *) file),
51+
realfile = backing_file_open(file_user_path(file),
5252
flags, realpath, current_cred());
5353
}
5454
ovl_revert_creds(old_cred);

include/linux/fs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,7 @@ struct file *dentry_open_nonotify(const struct path *path, int flags,
28642864
const struct cred *cred);
28652865
struct file *dentry_create(const struct path *path, int flags, umode_t mode,
28662866
const struct cred *cred);
2867-
struct path *backing_file_user_path(struct file *f);
2867+
struct path *backing_file_user_path(const struct file *f);
28682868

28692869
/*
28702870
* 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);
28762876
* by fstat() on that same fd.
28772877
*/
28782878
/* Get the path to display in /proc/<pid>/maps */
2879-
static inline const struct path *file_user_path(struct file *f)
2879+
static inline const struct path *file_user_path(const struct file *f)
28802880
{
28812881
if (unlikely(f->f_mode & FMODE_BACKING))
28822882
return backing_file_user_path(f);
28832883
return &f->f_path;
28842884
}
28852885
/* Get the inode whose inode number to display in /proc/<pid>/maps */
2886-
static inline const struct inode *file_user_inode(struct file *f)
2886+
static inline const struct inode *file_user_inode(const struct file *f)
28872887
{
28882888
if (unlikely(f->f_mode & FMODE_BACKING))
28892889
return d_inode(backing_file_user_path(f)->dentry);

0 commit comments

Comments
 (0)