]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
NFSv4: Recover locks too when returning a delegation
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 4 Nov 2005 20:38:11 +0000 (15:38 -0500)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Fri, 4 Nov 2005 20:38:11 +0000 (15:38 -0500)
 Delegations allow us to cache posix and BSD locks, however when the
 delegation is recalled, we need to "flush the cache" and send
 the cached LOCK requests to the server.

 This patch sets up the mechanism for doing so.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/delegation.c
fs/nfs/delegation.h
fs/nfs/nfs4proc.c

index 44135af9894cc44bf733546d18513ce360c86fda..3976c177a7d0ed25b87dbf6e26014f25027a3cb7 100644 (file)
@@ -31,11 +31,42 @@ static void nfs_free_delegation(struct nfs_delegation *delegation)
        kfree(delegation);
 }
 
+static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_state *state)
+{
+       struct inode *inode = state->inode;
+       struct file_lock *fl;
+       int status;
+
+       for (fl = inode->i_flock; fl != 0; fl = fl->fl_next) {
+               if (!(fl->fl_flags & (FL_POSIX|FL_FLOCK)))
+                       continue;
+               if ((struct nfs_open_context *)fl->fl_file->private_data != ctx)
+                       continue;
+               status = nfs4_lock_delegation_recall(state, fl);
+               if (status >= 0)
+                       continue;
+               switch (status) {
+                       default:
+                               printk(KERN_ERR "%s: unhandled error %d.\n",
+                                               __FUNCTION__, status);
+                       case -NFS4ERR_EXPIRED:
+                               /* kill_proc(fl->fl_pid, SIGLOST, 1); */
+                       case -NFS4ERR_STALE_CLIENTID:
+                               nfs4_schedule_state_recovery(NFS_SERVER(inode)->nfs4_state);
+                               goto out_err;
+               }
+       }
+       return 0;
+out_err:
+       return status;
+}
+
 static void nfs_delegation_claim_opens(struct inode *inode)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
        struct nfs_open_context *ctx;
        struct nfs4_state *state;
+       int err;
 
 again:
        spin_lock(&inode->i_lock);
@@ -47,9 +78,12 @@ again:
                        continue;
                get_nfs_open_context(ctx);
                spin_unlock(&inode->i_lock);
-               if (nfs4_open_delegation_recall(ctx->dentry, state) < 0)
-                       return;
+               err = nfs4_open_delegation_recall(ctx->dentry, state);
+               if (err >= 0)
+                       err = nfs_delegation_claim_locks(ctx, state);
                put_nfs_open_context(ctx);
+               if (err != 0)
+                       return;
                goto again;
        }
        spin_unlock(&inode->i_lock);
index 8017846b561f9ece35baa6489432b6d721c96e42..2fcc30de924bc4d24006208b23704c6c980145d3 100644 (file)
@@ -38,6 +38,7 @@ void nfs_delegation_reap_unclaimed(struct nfs4_client *clp);
 /* NFSv4 delegation-related procedures */
 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid);
 int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state);
+int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl);
 
 static inline int nfs_have_delegation(struct inode *inode, int flags)
 {
index 54ff465cf7cf3ceaadd39e7fc672c5e0cd7f407d..e6a9322a321f4eb4801b7172c92bf4ec8c140292 100644 (file)
@@ -3124,6 +3124,24 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
        return status;
 }
 
+int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
+{
+       struct nfs_server *server = NFS_SERVER(state->inode);
+       struct nfs4_exception exception = { };
+       int err;
+
+       err = nfs4_set_lock_state(state, fl);
+       if (err != 0)
+               goto out;
+       do {
+               err = _nfs4_do_setlk(state, F_SETLK, fl, 0);
+               if (err != -NFS4ERR_DELAY)
+                       break;
+               err = nfs4_handle_exception(server, err, &exception);
+       } while (exception.retry);
+out:
+       return err;
+}
 
 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"