NFSv4: Fail the truncate() if the lock/open stateid is invalid

If the open stateid could not be recovered, or the file locks were lost,
then we should fail the truncate() operation altogether.

Reported-by: Andy Adamson <andros@netapp.com>
Link: http://lkml.kernel.org/r/1393954269-3974-1-git-send-email-andros@netapp.com
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
This commit is contained in:
Trond Myklebust 2014-03-04 13:48:16 -05:00
parent 869a9d375d
commit 0418dae105
1 changed files with 6 additions and 3 deletions

View File

@ -2398,13 +2398,16 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) { if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) {
/* Use that stateid */ /* Use that stateid */
} else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) { } else if (truncate && state != NULL) {
struct nfs_lockowner lockowner = { struct nfs_lockowner lockowner = {
.l_owner = current->files, .l_owner = current->files,
.l_pid = current->tgid, .l_pid = current->tgid,
}; };
nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, if (!nfs4_valid_open_stateid(state))
&lockowner); return -EBADF;
if (nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
&lockowner) == -EIO)
return -EBADF;
} else } else
nfs4_stateid_copy(&arg.stateid, &zero_stateid); nfs4_stateid_copy(&arg.stateid, &zero_stateid);