NFSv4: Don't allow posix locking against servers that don't support it

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: stable@kernel.org
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>

+7 -1
+1
fs/nfs/nfs4_fs.h
··· 146 NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */ 147 NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ 148 NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ 149 }; 150 151 struct nfs4_state {
··· 146 NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */ 147 NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ 148 NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ 149 + NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */ 150 }; 151 152 struct nfs4_state {
+6 -1
fs/nfs/nfs4proc.c
··· 1658 status = PTR_ERR(state); 1659 if (IS_ERR(state)) 1660 goto err_opendata_put; 1661 nfs4_opendata_put(opendata); 1662 nfs4_put_state_owner(sp); 1663 *res = state; ··· 4202 { 4203 struct nfs_inode *nfsi = NFS_I(state->inode); 4204 unsigned char fl_flags = request->fl_flags; 4205 - int status; 4206 4207 /* Is this a delegated open? */ 4208 status = nfs4_set_lock_state(state, request); 4209 if (status != 0)
··· 1658 status = PTR_ERR(state); 1659 if (IS_ERR(state)) 1660 goto err_opendata_put; 1661 + if ((opendata->o_res.rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) != 0) 1662 + set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); 1663 nfs4_opendata_put(opendata); 1664 nfs4_put_state_owner(sp); 1665 *res = state; ··· 4200 { 4201 struct nfs_inode *nfsi = NFS_I(state->inode); 4202 unsigned char fl_flags = request->fl_flags; 4203 + int status = -ENOLCK; 4204 4205 + if ((fl_flags & FL_POSIX) && 4206 + !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) 4207 + goto out; 4208 /* Is this a delegated open? */ 4209 status = nfs4_set_lock_state(state, request); 4210 if (status != 0)