Skip to content

Commit

Permalink
ovl: add ovl_fsync()
Browse files Browse the repository at this point in the history
Implement stacked fsync().

Don't sync if lower (noticed by Amir Goldstein).

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Miklos Szeredi committed Jul 18, 2018
1 parent 2a92e07 commit de30dfd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fs/overlayfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,33 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
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,
};

0 comments on commit de30dfd

Please sign in to comment.