NLM,NFSv4: Don't put UNLOCK requests on the wire unless we hold a lock

Use the new behaviour of {flock,posix}_file_lock(F_UNLCK) to determine if
we held a lock, and only send the RPC request to the server if this was the
case.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

+22 -27
+10 -8
fs/lockd/clntproc.c
··· 454 454 fl->fl_ops = &nlmclnt_lock_ops; 455 455 } 456 456 457 - static void do_vfs_lock(struct file_lock *fl) 457 + static int do_vfs_lock(struct file_lock *fl) 458 458 { 459 459 int res = 0; 460 460 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { ··· 467 467 default: 468 468 BUG(); 469 469 } 470 - if (res < 0) 471 - printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", 472 - __FUNCTION__); 470 + return res; 473 471 } 474 472 475 473 /* ··· 539 541 } 540 542 fl->fl_flags |= FL_SLEEP; 541 543 /* Ensure the resulting lock will get added to granted list */ 542 - do_vfs_lock(fl); 544 + if (do_vfs_lock(fl) < 0) 545 + printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__); 543 546 up_read(&host->h_rwsem); 544 547 } 545 548 status = nlm_stat_to_errno(resp->status); ··· 605 606 { 606 607 struct nlm_host *host = req->a_host; 607 608 struct nlm_res *resp = &req->a_res; 608 - int status; 609 + int status = 0; 609 610 610 611 /* 611 612 * Note: the server is supposed to either grant us the unlock 612 613 * request, or to deny it with NLM_LCK_DENIED_GRACE_PERIOD. In either 613 614 * case, we want to unlock. 614 615 */ 616 + fl->fl_flags |= FL_EXISTS; 615 617 down_read(&host->h_rwsem); 616 - do_vfs_lock(fl); 618 + if (do_vfs_lock(fl) == -ENOENT) { 619 + up_read(&host->h_rwsem); 620 + goto out; 621 + } 617 622 up_read(&host->h_rwsem); 618 623 619 624 if (req->a_flags & RPC_TASK_ASYNC) ··· 627 624 if (status < 0) 628 625 goto out; 629 626 630 - status = 0; 631 627 if (resp->status == NLM_LCK_GRANTED) 632 628 goto out; 633 629
+12 -19
fs/nfs/nfs4proc.c
··· 3144 3144 default: 3145 3145 BUG(); 3146 3146 } 3147 - if (res < 0) 3148 - printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", 3149 - __FUNCTION__); 3150 3147 return res; 3151 3148 } 3152 3149 ··· 3255 3258 return ERR_PTR(-ENOMEM); 3256 3259 } 3257 3260 3258 - /* Unlock _before_ we do the RPC call */ 3259 - do_vfs_lock(fl->fl_file, fl); 3260 3261 return rpc_run_task(NFS_CLIENT(lsp->ls_state->inode), RPC_TASK_ASYNC, &nfs4_locku_ops, data); 3261 3262 } 3262 3263 ··· 3265 3270 struct rpc_task *task; 3266 3271 int status = 0; 3267 3272 3273 + status = nfs4_set_lock_state(state, request); 3274 + /* Unlock _before_ we do the RPC call */ 3275 + request->fl_flags |= FL_EXISTS; 3276 + if (do_vfs_lock(request->fl_file, request) == -ENOENT) 3277 + goto out; 3278 + if (status != 0) 3279 + goto out; 3268 3280 /* Is this a delegated lock? */ 3269 3281 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) 3270 - goto out_unlock; 3271 - /* Is this open_owner holding any locks on the server? */ 3272 - if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) 3273 - goto out_unlock; 3274 - 3275 - status = nfs4_set_lock_state(state, request); 3276 - if (status != 0) 3277 - goto out_unlock; 3282 + goto out; 3278 3283 lsp = request->fl_u.nfs4_fl.owner; 3279 - status = -ENOMEM; 3280 3284 seqid = nfs_alloc_seqid(&lsp->ls_seqid); 3285 + status = -ENOMEM; 3281 3286 if (seqid == NULL) 3282 - goto out_unlock; 3287 + goto out; 3283 3288 task = nfs4_do_unlck(request, request->fl_file->private_data, lsp, seqid); 3284 3289 status = PTR_ERR(task); 3285 3290 if (IS_ERR(task)) 3286 - goto out_unlock; 3291 + goto out; 3287 3292 status = nfs4_wait_for_completion_rpc_task(task); 3288 3293 rpc_release_task(task); 3289 - return status; 3290 - out_unlock: 3291 - do_vfs_lock(request->fl_file, request); 3294 + out: 3292 3295 return status; 3293 3296 } 3294 3297