Lines Matching full:lock

40 static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct lockd_lock *lock);
51 * Insert a blocked lock into the global list
108 * Find a block for a given lock
111 nlmsvc_lookup_block(struct nlm_file *file, struct lockd_lock *lock) in nlmsvc_lookup_block() argument
117 file, lock->fl.c.flc_pid, in nlmsvc_lookup_block()
118 (long long)lock->fl.fl_start, in nlmsvc_lookup_block()
119 (long long)lock->fl.fl_end, in nlmsvc_lookup_block()
120 lock->fl.c.flc_type); in nlmsvc_lookup_block()
123 fl = &block->b_call->a_args.lock.fl; in nlmsvc_lookup_block()
130 if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) { in nlmsvc_lookup_block()
179 * the blocked lock request. The spec explicitly mentions that the client
192 struct nlm_file *file, struct lockd_lock *lock, in nlmsvc_create_block() argument
210 if (!nlmsvc_setgrantargs(call, lock)) in nlmsvc_create_block()
214 call->a_args.lock.fl.c.flc_flags |= FL_SLEEP; in nlmsvc_create_block()
215 call->a_args.lock.fl.fl_lmops = &nlmsvc_lock_operations; in nlmsvc_create_block()
254 status = locks_delete_block(&block->b_call->a_args.lock.fl); in nlmsvc_unlink_block()
370 nlmsvc_release_lockowner(struct lockd_lock *lock) in nlmsvc_release_lockowner() argument
372 if (lock->fl.c.flc_owner) in nlmsvc_release_lockowner()
373 nlmsvc_put_lockowner(lock->fl.c.flc_owner); in nlmsvc_release_lockowner()
386 static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct lockd_lock *lock) in nlmsvc_setgrantargs() argument
388 locks_copy_lock(&call->a_args.lock.fl, &lock->fl); in nlmsvc_setgrantargs()
389 memcpy(&call->a_args.lock.fh, &lock->fh, sizeof(call->a_args.lock.fh)); in nlmsvc_setgrantargs()
390 call->a_args.lock.caller = utsname()->nodename; in nlmsvc_setgrantargs()
391 call->a_args.lock.oh.len = lock->oh.len; in nlmsvc_setgrantargs()
394 call->a_args.lock.oh.data = call->a_owner; in nlmsvc_setgrantargs()
395 call->a_args.lock.svid = ((struct nlm_lockowner *) lock->fl.c.flc_owner)->pid; in nlmsvc_setgrantargs()
397 if (lock->oh.len > NLMCLNT_OHSIZE) { in nlmsvc_setgrantargs()
398 void *data = kmalloc(lock->oh.len, GFP_KERNEL); in nlmsvc_setgrantargs()
401 call->a_args.lock.oh.data = (u8 *) data; in nlmsvc_setgrantargs()
404 memcpy(call->a_args.lock.oh.data, lock->oh.data, lock->oh.len); in nlmsvc_setgrantargs()
410 if (call->a_args.lock.oh.data != call->a_owner) in nlmsvc_freegrantargs()
411 kfree(call->a_args.lock.oh.data); in nlmsvc_freegrantargs()
413 locks_release_private(&call->a_args.lock.fl); in nlmsvc_freegrantargs()
417 * Deferred lock request handling for non-blocking lock
442 * Attempt to establish a lock, and if it can't be granted, block it
447 struct nlm_host *host, struct lockd_lock *lock, int wait, in nlmsvc_lock() argument
459 lock->fl.c.flc_type, in nlmsvc_lock()
460 lock->fl.c.flc_pid, in nlmsvc_lock()
461 (long long)lock->fl.fl_start, in nlmsvc_lock()
462 (long long)lock->fl.fl_end, in nlmsvc_lock()
473 /* Lock file against concurrent access */ in nlmsvc_lock()
478 block = nlmsvc_lookup_block(file, lock); in nlmsvc_lock()
480 block = nlmsvc_create_block(rqstp, host, file, lock, cookie); in nlmsvc_lock()
484 lock = &block->b_call->a_args.lock; in nlmsvc_lock()
486 lock->fl.c.flc_flags &= ~FL_SLEEP; in nlmsvc_lock()
516 * If this is a lock request for an already pending in nlmsvc_lock()
517 * lock request we return nlm_lck_blocked without calling in nlmsvc_lock()
519 * requests on the underlaying ->lock() implementation but in nlmsvc_lock()
534 lock->fl.c.flc_flags &= ~FL_SLEEP; in nlmsvc_lock()
535 mode = lock_to_openmode(&lock->fl); in nlmsvc_lock()
536 error = vfs_lock_file(file->f_file[mode], F_SETLK, &lock->fl, NULL); in nlmsvc_lock()
537 lock->fl.c.flc_flags &= ~FL_SLEEP; in nlmsvc_lock()
553 /* Filesystem lock operation is in progress in nlmsvc_lock()
576 * Test for presence of a conflicting lock.
580 struct nlm_host *host, struct lockd_lock *lock, in nlmsvc_testlock() argument
589 lock->fl.c.flc_type, in nlmsvc_testlock()
590 (long long)lock->fl.fl_start, in nlmsvc_testlock()
591 (long long)lock->fl.fl_end); in nlmsvc_testlock()
603 conflock->fl.c.flc_file = lock->fl.c.flc_file; in nlmsvc_testlock()
604 conflock->fl.fl_start = lock->fl.fl_start; in nlmsvc_testlock()
605 conflock->fl.fl_end = lock->fl.fl_end; in nlmsvc_testlock()
606 conflock->fl.c.flc_owner = lock->fl.c.flc_owner; in nlmsvc_testlock()
607 error = vfs_test_lock(lock->fl.c.flc_file, &conflock->fl); in nlmsvc_testlock()
618 dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n", in nlmsvc_testlock()
633 * Remove a lock.
640 nlmsvc_unlock(struct net *net, struct nlm_file *file, struct lockd_lock *lock) in nlmsvc_unlock() argument
647 lock->fl.c.flc_pid, in nlmsvc_unlock()
648 (long long)lock->fl.fl_start, in nlmsvc_unlock()
649 (long long)lock->fl.fl_end); in nlmsvc_unlock()
654 /* First, cancel any lock that might be there */ in nlmsvc_unlock()
655 nlmsvc_cancel_blocked(net, file, lock); in nlmsvc_unlock()
657 lock->fl.c.flc_type = F_UNLCK; in nlmsvc_unlock()
658 lock->fl.c.flc_file = file->f_file[O_RDONLY]; in nlmsvc_unlock()
659 if (lock->fl.c.flc_file) in nlmsvc_unlock()
660 error = vfs_lock_file(lock->fl.c.flc_file, F_SETLK, in nlmsvc_unlock()
661 &lock->fl, NULL); in nlmsvc_unlock()
662 lock->fl.c.flc_file = file->f_file[O_WRONLY]; in nlmsvc_unlock()
663 if (lock->fl.c.flc_file) in nlmsvc_unlock()
664 error |= vfs_lock_file(lock->fl.c.flc_file, F_SETLK, in nlmsvc_unlock()
665 &lock->fl, NULL); in nlmsvc_unlock()
678 nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct lockd_lock *lock) in nlmsvc_cancel_blocked() argument
687 lock->fl.c.flc_pid, in nlmsvc_cancel_blocked()
688 (long long)lock->fl.fl_start, in nlmsvc_cancel_blocked()
689 (long long)lock->fl.fl_end); in nlmsvc_cancel_blocked()
698 block = nlmsvc_lookup_block(file, lock); in nlmsvc_cancel_blocked()
701 struct file_lock *fl = &block->b_call->a_args.lock.fl; in nlmsvc_cancel_blocked()
712 * This is a callback from the filesystem for VFS file lock requests.
715 * For SETLK or SETLKW request it will get the local posix lock.
737 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) { in nlmsvc_grant_deferred()
762 * Unblock a blocked lock request. This is a callback invoked from the
763 * VFS layer when a lock on which we blocked is removed.
765 * This function doesn't grant the blocked lock instantly, but rather moves
776 if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) { in nlmsvc_notify_blocked()
805 * Try to claim a lock that was previously blocked.
819 struct lockd_lock *lock = &block->b_call->a_args.lock; in nlmsvc_grant_blocked() local
824 dprintk("lockd: grant blocked lock %p\n", block); in nlmsvc_grant_blocked()
839 /* Try the lock operation again */ in nlmsvc_grant_blocked()
843 lock->fl.c.flc_flags |= FL_SLEEP; in nlmsvc_grant_blocked()
844 fl_start = lock->fl.fl_start; in nlmsvc_grant_blocked()
845 fl_end = lock->fl.fl_end; in nlmsvc_grant_blocked()
846 mode = lock_to_openmode(&lock->fl); in nlmsvc_grant_blocked()
847 error = vfs_lock_file(file->f_file[mode], F_SETLK, &lock->fl, NULL); in nlmsvc_grant_blocked()
848 lock->fl.c.flc_flags &= ~FL_SLEEP; in nlmsvc_grant_blocked()
849 lock->fl.fl_start = fl_start; in nlmsvc_grant_blocked()
850 lock->fl.fl_end = fl_end; in nlmsvc_grant_blocked()
856 dprintk("lockd: lock still blocked error %d\n", error); in nlmsvc_grant_blocked()
869 /* Lock was granted by VFS. */ in nlmsvc_grant_blocked()
870 dprintk("lockd: GRANTing blocked lock.\n"); in nlmsvc_grant_blocked()
893 * better not sleep. Therefore, we put the blocked lock on the nlm_blocked
972 fl = &block->b_call->a_args.lock.fl; in nlmsvc_grant_reply()
976 pr_warn("lockd: unable to unlock lock rejected by client!\n"); in nlmsvc_grant_reply()
989 * If it is a blocking lock, call grant_blocked.
990 * For a non-blocking lock or test lock, revisit the request.