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