Skip to content

Commit 1b94746

Browse files
Christoph HellwigAl Viro
authored andcommitted
cifs: truncate fallout
Remove the calls to inode_newsize_ok given that we already did it as part of inode_change_ok in the beginning of cifs_setattr_(no)unix. No need to call ->truncate if cifs doesn't have one, so remove the explicit call in cifs_vmtruncate, and replace the calls to vmtruncate with truncate_setsize which is vmtruncate minus inode_newsize_ok and the call to ->truncate. Rename cifs_vmtruncate to cifs_setsize to match the new calling conventions. Question 1: why does cifs do the pagecache munging and i_size update twice for each setattr call, once opencoded in cifs_vmtruncate, and once using the VFS helpers? Question 2: what is supposed to be protected by i_lock in cifs_vmtruncate? Do we need it around the call to inode_change_ok? [AV: fixed build breakage] Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent e566d48 commit 1b94746

1 file changed

Lines changed: 7 additions & 23 deletions

File tree

‎fs/cifs/inode.c‎

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,26 +1679,16 @@ static int cifs_truncate_page(struct address_space *mapping, loff_t from)
16791679
return rc;
16801680
}
16811681

1682-
static int cifs_vmtruncate(struct inode *inode, loff_t offset)
1682+
static void cifs_setsize(struct inode *inode, loff_t offset)
16831683
{
16841684
loff_t oldsize;
1685-
int err;
16861685

16871686
spin_lock(&inode->i_lock);
1688-
err = inode_newsize_ok(inode, offset);
1689-
if (err) {
1690-
spin_unlock(&inode->i_lock);
1691-
goto out;
1692-
}
1693-
16941687
oldsize = inode->i_size;
16951688
i_size_write(inode, offset);
16961689
spin_unlock(&inode->i_lock);
1690+
16971691
truncate_pagecache(inode, oldsize, offset);
1698-
if (inode->i_op->truncate)
1699-
inode->i_op->truncate(inode);
1700-
out:
1701-
return err;
17021692
}
17031693

17041694
static int
@@ -1771,7 +1761,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
17711761

17721762
if (rc == 0) {
17731763
cifsInode->server_eof = attrs->ia_size;
1774-
rc = cifs_vmtruncate(inode, attrs->ia_size);
1764+
cifs_setsize(inode, attrs->ia_size);
17751765
cifs_truncate_page(inode->i_mapping, inode->i_size);
17761766
}
17771767

@@ -1891,11 +1881,8 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
18911881
goto out;
18921882

18931883
if ((attrs->ia_valid & ATTR_SIZE) &&
1894-
attrs->ia_size != i_size_read(inode)) {
1895-
rc = vmtruncate(inode, attrs->ia_size);
1896-
if (rc)
1897-
goto out;
1898-
}
1884+
attrs->ia_size != i_size_read(inode))
1885+
truncate_setsize(inode, attrs->ia_size);
18991886

19001887
setattr_copy(inode, attrs);
19011888
mark_inode_dirty(inode);
@@ -2050,11 +2037,8 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
20502037
goto cifs_setattr_exit;
20512038

20522039
if ((attrs->ia_valid & ATTR_SIZE) &&
2053-
attrs->ia_size != i_size_read(inode)) {
2054-
rc = vmtruncate(inode, attrs->ia_size);
2055-
if (rc)
2056-
goto cifs_setattr_exit;
2057-
}
2040+
attrs->ia_size != i_size_read(inode))
2041+
truncate_setsize(inode, attrs->ia_size);
20582042

20592043
setattr_copy(inode, attrs);
20602044
mark_inode_dirty(inode);

0 commit comments

Comments
 (0)