diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2018-07-18 15:44:42 +0200 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2018-07-18 15:44:42 +0200 |
commit | de30dfd629e2e07e2e9d672b2931bcd60f9a34c0 (patch) | |
tree | f2193050b74ba0d8bbac3d3ec25d87238e753b48 /fs/overlayfs | |
parent | 2a92e07edc5edef44bb7a0b8ede3154476dbb50a (diff) |
ovl: add ovl_fsync()
Implement stacked fsync().
Don't sync if lower (noticed by Amir Goldstein).
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs')
-rw-r--r-- | fs/overlayfs/file.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 53d95c9d976a..8adddee93418 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -233,10 +233,33 @@ out_unlock: return ret; } +static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync) +{ + struct fd real; + const struct cred *old_cred; + int ret; + + ret = ovl_real_fdget(file, &real); + if (ret) + return ret; + + /* Don't sync lower file for fear of receiving EROFS error */ + if (file_inode(real.file) == ovl_inode_upper(file_inode(file))) { + old_cred = ovl_override_creds(file_inode(file)->i_sb); + ret = vfs_fsync_range(real.file, start, end, datasync); + revert_creds(old_cred); + } + + fdput(real); + + return ret; +} + const struct file_operations ovl_file_operations = { .open = ovl_open, .release = ovl_release, .llseek = ovl_llseek, .read_iter = ovl_read_iter, .write_iter = ovl_write_iter, + .fsync = ovl_fsync, }; |