Merge tag 'nfs-for-3.20-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
[linux-2.6-block.git] / fs / nfs / delegation.c
index 8cdb2b28a104c89216125c1c274ef94895121f07..da5433230bb1960bc78bafc17ced89f3bca76b65 100644 (file)
@@ -306,6 +306,17 @@ nfs_inode_detach_delegation(struct inode *inode)
        return nfs_detach_delegation(nfsi, delegation, server);
 }
 
+static void
+nfs_update_inplace_delegation(struct nfs_delegation *delegation,
+               const struct nfs_delegation *update)
+{
+       if (nfs4_stateid_is_newer(&update->stateid, &delegation->stateid)) {
+               delegation->stateid.seqid = update->stateid.seqid;
+               smp_wmb();
+               delegation->type = update->type;
+       }
+}
+
 /**
  * nfs_inode_set_delegation - set up a delegation on an inode
  * @inode: inode to which delegation applies
@@ -339,9 +350,12 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
        old_delegation = rcu_dereference_protected(nfsi->delegation,
                                        lockdep_is_held(&clp->cl_lock));
        if (old_delegation != NULL) {
-               if (nfs4_stateid_match(&delegation->stateid,
-                                       &old_delegation->stateid) &&
-                               delegation->type == old_delegation->type) {
+               /* Is this an update of the existing delegation? */
+               if (nfs4_stateid_match_other(&old_delegation->stateid,
+                                       &delegation->stateid)) {
+                       nfs_update_inplace_delegation(old_delegation,
+                                       delegation);
+                       nfsi->delegation_state = old_delegation->type;
                        goto out;
                }
                /*