summaryrefslogtreecommitdiff
path: root/fs/overlayfs/file.c
diff options
context:
space:
mode:
authorSargun Dhillon <sargun@sargun.me>2020-11-30 06:00:39 +0300
committerMiklos Szeredi <mszeredi@redhat.com>2021-04-12 13:00:36 +0300
commit1f0cb8bcc7f96bcd816c80618eb0a7a361c70fbd (patch)
tree51adb2d12c155352a78f4e26c56fafb19247e659 /fs/overlayfs/file.c
parente49d033bddf5b565044e2abe4241353959bc9120 (diff)
downloadlinux-1f0cb8bcc7f96bcd816c80618eb0a7a361c70fbd.tar.xz
ovl: plumb through flush method
Filesystems can implement their own flush method that release resources, or manipulate caches. Currently if one of these filesystems is used with overlayfs, the flush method is not called. [Amir: fix fd leak in ovl_flush()] Signed-off-by: Sargun Dhillon <sargun@sargun.me> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs/file.c')
-rw-r--r--fs/overlayfs/file.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index dbfb35fb0ff7..6e454a294046 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -686,6 +686,26 @@ static loff_t ovl_remap_file_range(struct file *file_in, loff_t pos_in,
remap_flags, op);
}
+static int ovl_flush(struct file *file, fl_owner_t id)
+{
+ struct fd real;
+ const struct cred *old_cred;
+ int err;
+
+ err = ovl_real_fdget(file, &real);
+ if (err)
+ return err;
+
+ if (real.file->f_op->flush) {
+ old_cred = ovl_override_creds(file_inode(file)->i_sb);
+ err = real.file->f_op->flush(real.file, id);
+ revert_creds(old_cred);
+ }
+ fdput(real);
+
+ return err;
+}
+
const struct file_operations ovl_file_operations = {
.open = ovl_open,
.release = ovl_release,
@@ -697,6 +717,7 @@ const struct file_operations ovl_file_operations = {
.fallocate = ovl_fallocate,
.fadvise = ovl_fadvise,
.unlocked_ioctl = ovl_ioctl,
+ .flush = ovl_flush,
#ifdef CONFIG_COMPAT
.compat_ioctl = ovl_compat_ioctl,
#endif