History

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.

Jeff Layton committed 12 years ago

Commit 09802fd1 parent aef95832 files · +6 −50Browse files

Unified · Split

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