提交 3a7ed3ff 编写于 作者: O Omar Sandoval 提交者: Trond Myklebust

nfs: prevent truncate on active swapfile

Most filesystems prevent truncation of an active swapfile by way of
inode_newsize_ok, called from inode_change_ok. NFS doesn't call either
from nfs_setattr, presumably because most of these checks are expected
to be done server-side. However, the IS_SWAPFILE check can only be done
client-side, and truncating a swapfile can't possibly be good.
Signed-off-by: NOmar Sandoval <osandov@osandov.com>
Signed-off-by: NTrond Myklebust <trond.myklebust@primarydata.com>
上级 6ffa30d3
...@@ -507,10 +507,15 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) ...@@ -507,10 +507,15 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
attr->ia_valid &= ~ATTR_MODE; attr->ia_valid &= ~ATTR_MODE;
if (attr->ia_valid & ATTR_SIZE) { if (attr->ia_valid & ATTR_SIZE) {
loff_t i_size;
BUG_ON(!S_ISREG(inode->i_mode)); BUG_ON(!S_ISREG(inode->i_mode));
if (attr->ia_size == i_size_read(inode)) i_size = i_size_read(inode);
if (attr->ia_size == i_size)
attr->ia_valid &= ~ATTR_SIZE; attr->ia_valid &= ~ATTR_SIZE;
else if (attr->ia_size < i_size && IS_SWAPFILE(inode))
return -ETXTBSY;
} }
/* Optimization: if the end result is no change, don't RPC */ /* Optimization: if the end result is no change, don't RPC */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册