]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/lockd/clntproc.c
fs: replace remaining __FUNCTION__ occurrences
[net-next-2.6.git] / fs / lockd / clntproc.c
index ea1a6940af22f4454becd8a57e84aa7f4e797a28..5df517b81f3f2a7911e1518c33021e9eb557c85e 100644 (file)
@@ -247,7 +247,7 @@ static int nlm_wait_on_grace(wait_queue_head_t *queue)
  * Generic NLM call
  */
 static int
-nlmclnt_call(struct nlm_rqst *req, u32 proc)
+nlmclnt_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc)
 {
        struct nlm_host *host = req->a_host;
        struct rpc_clnt *clnt;
@@ -256,6 +256,7 @@ nlmclnt_call(struct nlm_rqst *req, u32 proc)
        struct rpc_message msg = {
                .rpc_argp       = argp,
                .rpc_resp       = resp,
+               .rpc_cred       = cred,
        };
        int             status;
 
@@ -390,11 +391,12 @@ int nlm_async_reply(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *t
  *      completion in order to be able to correctly track the lock
  *      state.
  */
-static int nlmclnt_async_call(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
+static int nlmclnt_async_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
 {
        struct rpc_message msg = {
                .rpc_argp       = &req->a_args,
                .rpc_resp       = &req->a_res,
+               .rpc_cred       = cred,
        };
        struct rpc_task *task;
        int err;
@@ -415,7 +417,7 @@ nlmclnt_test(struct nlm_rqst *req, struct file_lock *fl)
 {
        int     status;
 
-       status = nlmclnt_call(req, NLMPROC_TEST);
+       status = nlmclnt_call(nfs_file_cred(fl->fl_file), req, NLMPROC_TEST);
        if (status < 0)
                goto out;
 
@@ -506,10 +508,12 @@ static int do_vfs_lock(struct file_lock *fl)
 static int
 nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
 {
+       struct rpc_cred *cred = nfs_file_cred(fl->fl_file);
        struct nlm_host *host = req->a_host;
        struct nlm_res  *resp = &req->a_res;
        struct nlm_wait *block = NULL;
        unsigned char fl_flags = fl->fl_flags;
+       unsigned char fl_type;
        int status = -ENOLCK;
 
        if (nsm_monitor(host) < 0) {
@@ -525,13 +529,16 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
 
        block = nlmclnt_prepare_block(host, fl);
 again:
+       /*
+        * Initialise resp->status to a valid non-zero value,
+        * since 0 == nlm_lck_granted
+        */
+       resp->status = nlm_lck_blocked;
        for(;;) {
                /* Reboot protection */
                fl->fl_u.nfs_fl.state = host->h_state;
-               status = nlmclnt_call(req, NLMPROC_LOCK);
+               status = nlmclnt_call(cred, req, NLMPROC_LOCK);
                if (status < 0)
-                       goto out_unblock;
-               if (!req->a_args.block)
                        break;
                /* Did a reclaimer thread notify us of a server reboot? */
                if (resp->status ==  nlm_lck_denied_grace_period)
@@ -540,15 +547,22 @@ again:
                        break;
                /* Wait on an NLM blocking lock */
                status = nlmclnt_block(block, req, NLMCLNT_POLL_TIMEOUT);
-               /* if we were interrupted. Send a CANCEL request to the server
-                * and exit
-                */
                if (status < 0)
-                       goto out_unblock;
+                       break;
                if (resp->status != nlm_lck_blocked)
                        break;
        }
 
+       /* if we were interrupted while blocking, then cancel the lock request
+        * and exit
+        */
+       if (resp->status == nlm_lck_blocked) {
+               if (!req->a_args.block)
+                       goto out_unlock;
+               if (nlmclnt_cancel(host, req->a_args.block, fl) == 0)
+                       goto out_unblock;
+       }
+
        if (resp->status == nlm_granted) {
                down_read(&host->h_rwsem);
                /* Check whether or not the server has rebooted */
@@ -559,19 +573,33 @@ again:
                /* Ensure the resulting lock will get added to granted list */
                fl->fl_flags |= FL_SLEEP;
                if (do_vfs_lock(fl) < 0)
-                       printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
+                       printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
                up_read(&host->h_rwsem);
                fl->fl_flags = fl_flags;
+               status = 0;
        }
+       if (status < 0)
+               goto out_unlock;
        status = nlm_stat_to_errno(resp->status);
 out_unblock:
        nlmclnt_finish_block(block);
-       /* Cancel the blocked request if it is still pending */
-       if (resp->status == nlm_lck_blocked)
-               nlmclnt_cancel(host, req->a_args.block, fl);
 out:
        nlm_release_call(req);
        return status;
+out_unlock:
+       /* Fatal error: ensure that we remove the lock altogether */
+       dprintk("lockd: lock attempt ended in fatal error.\n"
+               "       Attempting to unlock.\n");
+       nlmclnt_finish_block(block);
+       fl_type = fl->fl_type;
+       fl->fl_type = F_UNLCK;
+       down_read(&host->h_rwsem);
+       do_vfs_lock(fl);
+       up_read(&host->h_rwsem);
+       fl->fl_type = fl_type;
+       fl->fl_flags = fl_flags;
+       nlmclnt_async_call(cred, req, NLMPROC_UNLOCK, &nlmclnt_unlock_ops);
+       return status;
 }
 
 /*
@@ -594,8 +622,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
        nlmclnt_setlockargs(req, fl);
        req->a_args.reclaim = 1;
 
-       if ((status = nlmclnt_call(req, NLMPROC_LOCK)) >= 0
-        && req->a_res.status == nlm_granted)
+       status = nlmclnt_call(nfs_file_cred(fl->fl_file), req, NLMPROC_LOCK);
+       if (status >= 0 && req->a_res.status == nlm_granted)
                return 0;
 
        printk(KERN_WARNING "lockd: failed to reclaim lock for pid %d "
@@ -644,7 +672,8 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
        }
 
        atomic_inc(&req->a_count);
-       status = nlmclnt_async_call(req, NLMPROC_UNLOCK, &nlmclnt_unlock_ops);
+       status = nlmclnt_async_call(nfs_file_cred(fl->fl_file), req,
+                       NLMPROC_UNLOCK, &nlmclnt_unlock_ops);
        if (status < 0)
                goto out;
 
@@ -713,7 +742,8 @@ static int nlmclnt_cancel(struct nlm_host *host, int block, struct file_lock *fl
        req->a_args.block = block;
 
        atomic_inc(&req->a_count);
-       status = nlmclnt_async_call(req, NLMPROC_CANCEL, &nlmclnt_cancel_ops);
+       status = nlmclnt_async_call(nfs_file_cred(fl->fl_file), req,
+                       NLMPROC_CANCEL, &nlmclnt_cancel_ops);
        if (status == 0 && req->a_res.status == nlm_lck_denied)
                status = -ENOLCK;
        nlm_release_call(req);