diff options
author | Omar Sandoval <osandov@osandov.com> | 2015-01-08 04:18:30 -0500 |
---|---|---|
committer | Trond Myklebust <trond.myklebust@primarydata.com> | 2015-01-30 20:43:29 -0500 |
commit | 3a7ed3fff3bb22828f7d7ba6b75c7d22ee54df38 (patch) | |
tree | cb80dba1908b48a6b552ed2b0eaa271f3296582c | |
parent | 6ffa30d3f734d4f6b478081dfc09592021028f90 (diff) |
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: Omar Sandoval <osandov@osandov.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
-rw-r--r-- | fs/nfs/inode.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 2211f6ba8736..d2398c193bda 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -507,10 +507,15 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
507 | attr->ia_valid &= ~ATTR_MODE; | 507 | attr->ia_valid &= ~ATTR_MODE; |
508 | 508 | ||
509 | if (attr->ia_valid & ATTR_SIZE) { | 509 | if (attr->ia_valid & ATTR_SIZE) { |
510 | loff_t i_size; | ||
511 | |||
510 | BUG_ON(!S_ISREG(inode->i_mode)); | 512 | BUG_ON(!S_ISREG(inode->i_mode)); |
511 | 513 | ||
512 | if (attr->ia_size == i_size_read(inode)) | 514 | i_size = i_size_read(inode); |
515 | if (attr->ia_size == i_size) | ||
513 | attr->ia_valid &= ~ATTR_SIZE; | 516 | attr->ia_valid &= ~ATTR_SIZE; |
517 | else if (attr->ia_size < i_size && IS_SWAPFILE(inode)) | ||
518 | return -ETXTBSY; | ||
514 | } | 519 | } |
515 | 520 | ||
516 | /* Optimization: if the end result is no change, don't RPC */ | 521 | /* Optimization: if the end result is no change, don't RPC */ |