NFSv4: fix delegated locking

Arnaud Giersch reports that NFSv4 locking is broken when we hold a
delegation since commit 8e469ebd6dc32cbaf620e134d79f740bf0ebab79 (NFSv4:
Don't allow posix locking against servers that don't support it).

According to Arnaud, the lock succeeds the first time he opens the file
(since we cannot do a delegated open) but then fails after we start using
delegated opens.

The following patch fixes it by ensuring that locking behaviour is
governed by a per-filesystem capability flag that is initially set, but
gets cleared if the server ever returns an OPEN without the
NFS4_OPEN_RESULT_LOCKTYPE_POSIX flag being set.

Reported-by: Arnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: stable@kernel.org

+6 -2
+2 -1
fs/nfs/client.c
··· 1294 1294 1295 1295 /* Initialise the client representation from the mount data */ 1296 1296 server->flags = data->flags; 1297 - server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR; 1297 + server->caps |= NFS_CAP_ATOMIC_OPEN|NFS_CAP_CHANGE_ATTR| 1298 + NFS_CAP_POSIX_LOCK; 1298 1299 server->options = data->options; 1299 1300 1300 1301 /* Get a client record */
+3 -1
fs/nfs/nfs4proc.c
··· 1523 1523 nfs_post_op_update_inode(dir, o_res->dir_attr); 1524 1524 } else 1525 1525 nfs_refresh_inode(dir, o_res->dir_attr); 1526 + if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) 1527 + server->caps &= ~NFS_CAP_POSIX_LOCK; 1526 1528 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { 1527 1529 status = _nfs4_proc_open_confirm(data); 1528 1530 if (status != 0) ··· 1666 1664 status = PTR_ERR(state); 1667 1665 if (IS_ERR(state)) 1668 1666 goto err_opendata_put; 1669 - if ((opendata->o_res.rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) != 0) 1667 + if (server->caps & NFS_CAP_POSIX_LOCK) 1670 1668 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); 1671 1669 nfs4_opendata_put(opendata); 1672 1670 nfs4_put_state_owner(sp);
+1
include/linux/nfs_fs_sb.h
··· 176 176 #define NFS_CAP_ATIME (1U << 11) 177 177 #define NFS_CAP_CTIME (1U << 12) 178 178 #define NFS_CAP_MTIME (1U << 13) 179 + #define NFS_CAP_POSIX_LOCK (1U << 14) 179 180 180 181 181 182 /* maximum number of slots to use */