Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lockd: rip out deferred lock handling from testlock codepath

As Kinglong points out, the nlm_block->b_fl field is no longer used at
all. Also, vfs_test_lock in the generic locking code will only return
FILE_LOCK_DEFERRED if FL_SLEEP is set, and it isn't here.

The only other place that returns that value is the DLM lock code, but
it only does that in dlm_posix_lock, never in dlm_posix_get.

Remove all of the deferred locking code from the testlock codepath
since it doesn't appear to ever be used anyway.

I do have a small concern that this might cause a behavior change in the
case where you have a block already sitting on the list when the
testlock request comes in, but that looks like it doesn't really work
properly anyway. I think it's best to just pass that down to
vfs_test_lock and let the filesystem report that instead of trying to
infer what's going on with the lock by looking at an existing block.

Cc: cluster-devel@redhat.com
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Reviewed-by: Kinglong Mee <kinglongmee@gmail.com>

+6 -50
+6 -49
fs/lockd/svclock.c
··· 245 245 block->b_daemon = rqstp->rq_server; 246 246 block->b_host = host; 247 247 block->b_file = file; 248 - block->b_fl = NULL; 249 248 file->f_count++; 250 249 251 250 /* Add to file's list of blocks */ ··· 294 295 nlmsvc_freegrantargs(block->b_call); 295 296 nlmsvc_release_call(block->b_call); 296 297 nlm_release_file(block->b_file); 297 - kfree(block->b_fl); 298 298 kfree(block); 299 299 } 300 300 ··· 506 508 struct nlm_host *host, struct nlm_lock *lock, 507 509 struct nlm_lock *conflock, struct nlm_cookie *cookie) 508 510 { 509 - struct nlm_block *block = NULL; 510 511 int error; 511 512 __be32 ret; 512 513 ··· 516 519 (long long)lock->fl.fl_start, 517 520 (long long)lock->fl.fl_end); 518 521 519 - /* Get existing block (in case client is busy-waiting) */ 520 - block = nlmsvc_lookup_block(file, lock); 521 - 522 - if (block == NULL) { 523 - struct file_lock *conf = kzalloc(sizeof(*conf), GFP_KERNEL); 524 - 525 - if (conf == NULL) 526 - return nlm_granted; 527 - block = nlmsvc_create_block(rqstp, host, file, lock, cookie); 528 - if (block == NULL) { 529 - kfree(conf); 530 - return nlm_granted; 531 - } 532 - block->b_fl = conf; 533 - } 534 - if (block->b_flags & B_QUEUED) { 535 - dprintk("lockd: nlmsvc_testlock deferred block %p flags %d fl %p\n", 536 - block, block->b_flags, block->b_fl); 537 - if (block->b_flags & B_TIMED_OUT) { 538 - nlmsvc_unlink_block(block); 539 - ret = nlm_lck_denied; 540 - goto out; 541 - } 542 - if (block->b_flags & B_GOT_CALLBACK) { 543 - nlmsvc_unlink_block(block); 544 - if (block->b_fl != NULL 545 - && block->b_fl->fl_type != F_UNLCK) { 546 - lock->fl = *block->b_fl; 547 - goto conf_lock; 548 - } else { 549 - ret = nlm_granted; 550 - goto out; 551 - } 552 - } 553 - ret = nlm_drop_reply; 554 - goto out; 555 - } 556 - 557 522 if (locks_in_grace(SVC_NET(rqstp))) { 558 523 ret = nlm_lck_denied_grace_period; 559 524 goto out; 560 525 } 526 + 561 527 error = vfs_test_lock(file->f_file, &lock->fl); 562 - if (error == FILE_LOCK_DEFERRED) { 563 - ret = nlmsvc_defer_lock_rqst(rqstp, block); 564 - goto out; 565 - } 566 528 if (error) { 529 + /* We can't currently deal with deferred test requests */ 530 + if (error == FILE_LOCK_DEFERRED) 531 + WARN_ON_ONCE(1); 532 + 567 533 ret = nlm_lck_denied_nolocks; 568 534 goto out; 569 535 } 536 + 570 537 if (lock->fl.fl_type == F_UNLCK) { 571 538 ret = nlm_granted; 572 539 goto out; 573 540 } 574 541 575 - conf_lock: 576 542 dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n", 577 543 lock->fl.fl_type, (long long)lock->fl.fl_start, 578 544 (long long)lock->fl.fl_end); ··· 549 589 locks_release_private(&lock->fl); 550 590 ret = nlm_lck_denied; 551 591 out: 552 - if (block) 553 - nlmsvc_release_block(block); 554 592 return ret; 555 593 } 556 594 ··· 619 661 * This is a callback from the filesystem for VFS file lock requests. 620 662 * It will be used if lm_grant is defined and the filesystem can not 621 663 * respond to the request immediately. 622 - * For GETLK request it will copy the reply to the nlm_block. 623 664 * For SETLK or SETLKW request it will get the local posix lock. 624 665 * In all cases it will move the block to the head of nlm_blocked q where 625 666 * nlmsvc_retry_blocked() can send back a reply for SETLKW or revisit the
-1
include/linux/lockd/lockd.h
··· 178 178 unsigned char b_granted; /* VFS granted lock */ 179 179 struct nlm_file * b_file; /* file in question */ 180 180 struct cache_req * b_cache_req; /* deferred request handling */ 181 - struct file_lock * b_fl; /* set for GETLK */ 182 181 struct cache_deferred_req * b_deferred_req; 183 182 unsigned int b_flags; /* block flags */ 184 183 #define B_QUEUED 1 /* lock queued */