Message ID | 20230609073239.957184-4-amir73il@gmail.com (mailing list archive) |
---|---|
State | Under Review |
Headers | show |
Series | Reduce impact of overlayfs fake path files | expand |
On Fri, Jun 09, 2023 at 10:32:39AM +0300, Amir Goldstein wrote: > Instead of storing only the fake path in f_path, store the real path > in f_path and the fake path in file_fake container. > > Call sites that use the macro file_fake_path() continue to get the fake > path from its new location. > > Call sites that access f_path directly will now see the overlayfs real > path instead of the fake overlayfs path, which is the desired bahvior > for most users, because it makes f_path consistent with f_inode. > > Signed-off-by: Amir Goldstein <amir73il@gmail.com> > --- If you resend, can you take the chance and refactor this into a slightly more readable pattern, please? So something like struct file *open_with_fake_path(const struct path *fake_path, int flags, const struct path *path, const struct cred *cred) { int error; struct file *f; f = alloc_empty_file_fake(fake_path, flags, cred); if (IS_ERR(f)) return f; f->f_path = *path; error = do_dentry_open(f, d_inode(path->dentry), NULL); if (error) { fput(f); return ERR_PTR(error); } return f; }
On Fri, Jun 9, 2023 at 2:12 PM Christian Brauner <brauner@kernel.org> wrote: > > On Fri, Jun 09, 2023 at 10:32:39AM +0300, Amir Goldstein wrote: > > Instead of storing only the fake path in f_path, store the real path > > in f_path and the fake path in file_fake container. > > > > Call sites that use the macro file_fake_path() continue to get the fake > > path from its new location. > > > > Call sites that access f_path directly will now see the overlayfs real > > path instead of the fake overlayfs path, which is the desired bahvior > > for most users, because it makes f_path consistent with f_inode. > > > > Signed-off-by: Amir Goldstein <amir73il@gmail.com> > > --- > > If you resend, can you take the chance and refactor this into a slightly more > readable pattern, please? So something like > Sure! I like this better myself. Thanks, Amir. > struct file *open_with_fake_path(const struct path *fake_path, int flags, > const struct path *path, > const struct cred *cred) > { > int error; > struct file *f; > > f = alloc_empty_file_fake(fake_path, flags, cred); > if (IS_ERR(f)) > return f; > > f->f_path = *path; > error = do_dentry_open(f, d_inode(path->dentry), NULL); > if (error) { > fput(f); > return ERR_PTR(error); > } > > return f; > }
diff --git a/fs/open.c b/fs/open.c index c9e2300a037d..4f4e7534f515 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1120,11 +1120,11 @@ struct file *open_with_fake_path(const struct path *fake_path, int flags, const struct path *path, const struct cred *cred) { - struct file *f = alloc_empty_file_fake(NULL, flags, cred); + struct file *f = alloc_empty_file_fake(fake_path, flags, cred); if (!IS_ERR(f)) { int error; - f->f_path = *fake_path; + f->f_path = *path; error = do_dentry_open(f, d_inode(path->dentry), NULL); if (error) { fput(f);
Instead of storing only the fake path in f_path, store the real path in f_path and the fake path in file_fake container. Call sites that use the macro file_fake_path() continue to get the fake path from its new location. Call sites that access f_path directly will now see the overlayfs real path instead of the fake overlayfs path, which is the desired bahvior for most users, because it makes f_path consistent with f_inode. Signed-off-by: Amir Goldstein <amir73il@gmail.com> --- fs/open.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)