Skip to content

Commit

Permalink
ovl: Do not do metadata only copy-up for truncate operation
Browse files Browse the repository at this point in the history
truncate should copy up full file (and not do metacopy only), otherwise it
will be broken.  For example, use truncate to increase size of a file so
that any read beyong existing size will return null bytes.  If we don't
copy up full file, then we end up opening lower file and read from it only
reads upto the old size (and not new size after truncate).  Hence to avoid
such situations, copy up data as well when file size changes.

So far it was being done by d_real(O_WRONLY) call in truncate() path.  Now
that patch has been reverted.  So force full copy up in ovl_setattr() if
size of file is changing.

Signed-off-by: Vivek Goyal <[email protected]>
Reviewed-by: Amir Goldstein <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
  • Loading branch information
rhvgoyal authored and Miklos Szeredi committed Jul 20, 2018
1 parent d1e6f6a commit 997336f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fs/overlayfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
int ovl_setattr(struct dentry *dentry, struct iattr *attr)
{
int err;
bool full_copy_up = false;
struct dentry *upperdentry;
const struct cred *old_cred;

Expand All @@ -36,9 +37,15 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr)
err = -ETXTBSY;
if (atomic_read(&realinode->i_writecount) < 0)
goto out_drop_write;

/* Truncate should trigger data copy up as well */
full_copy_up = true;
}

err = ovl_copy_up(dentry);
if (!full_copy_up)
err = ovl_copy_up(dentry);
else
err = ovl_copy_up_with_data(dentry);
if (!err) {
struct inode *winode = NULL;

Expand Down

0 comments on commit 997336f

Please sign in to comment.