Lines Matching refs:fl
177 #define IS_POSIX(fl) (fl->fl_flags & FL_POSIX) argument
178 #define IS_FLOCK(fl) (fl->fl_flags & FL_FLOCK) argument
179 #define IS_LEASE(fl) (fl->fl_flags & (FL_LEASE|FL_DELEG|FL_LAYOUT)) argument
180 #define IS_OFDLCK(fl) (fl->fl_flags & FL_OFDLCK) argument
181 #define IS_REMOTELCK(fl) (fl->fl_pid <= 0) argument
183 static bool lease_breaking(struct file_lock *fl) in lease_breaking() argument
185 return fl->fl_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING); in lease_breaking()
188 static int target_leasetype(struct file_lock *fl) in target_leasetype() argument
190 if (fl->fl_flags & FL_UNLOCK_PENDING) in target_leasetype()
192 if (fl->fl_flags & FL_DOWNGRADE_PENDING) in target_leasetype()
194 return fl->fl_type; in target_leasetype()
283 struct file_lock *fl; in locks_dump_ctx_list() local
285 list_for_each_entry(fl, list, fl_list) { in locks_dump_ctx_list()
286 …%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n", list_type, fl->fl_owner, fl->fl_flags, fl->fl_type, fl… in locks_dump_ctx_list()
311 struct file_lock *fl; in locks_check_ctx_file_list() local
314 list_for_each_entry(fl, list, fl_list) in locks_check_ctx_file_list()
315 if (fl->fl_file == filp) in locks_check_ctx_file_list()
320 fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid); in locks_check_ctx_file_list()
334 static void locks_init_lock_heads(struct file_lock *fl) in locks_init_lock_heads() argument
336 INIT_HLIST_NODE(&fl->fl_link); in locks_init_lock_heads()
337 INIT_LIST_HEAD(&fl->fl_list); in locks_init_lock_heads()
338 INIT_LIST_HEAD(&fl->fl_blocked_requests); in locks_init_lock_heads()
339 INIT_LIST_HEAD(&fl->fl_blocked_member); in locks_init_lock_heads()
340 init_waitqueue_head(&fl->fl_wait); in locks_init_lock_heads()
346 struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL); in locks_alloc_lock() local
348 if (fl) in locks_alloc_lock()
349 locks_init_lock_heads(fl); in locks_alloc_lock()
351 return fl; in locks_alloc_lock()
355 void locks_release_private(struct file_lock *fl) in locks_release_private() argument
357 BUG_ON(waitqueue_active(&fl->fl_wait)); in locks_release_private()
358 BUG_ON(!list_empty(&fl->fl_list)); in locks_release_private()
359 BUG_ON(!list_empty(&fl->fl_blocked_requests)); in locks_release_private()
360 BUG_ON(!list_empty(&fl->fl_blocked_member)); in locks_release_private()
361 BUG_ON(!hlist_unhashed(&fl->fl_link)); in locks_release_private()
363 if (fl->fl_ops) { in locks_release_private()
364 if (fl->fl_ops->fl_release_private) in locks_release_private()
365 fl->fl_ops->fl_release_private(fl); in locks_release_private()
366 fl->fl_ops = NULL; in locks_release_private()
369 if (fl->fl_lmops) { in locks_release_private()
370 if (fl->fl_lmops->lm_put_owner) { in locks_release_private()
371 fl->fl_lmops->lm_put_owner(fl->fl_owner); in locks_release_private()
372 fl->fl_owner = NULL; in locks_release_private()
374 fl->fl_lmops = NULL; in locks_release_private()
380 void locks_free_lock(struct file_lock *fl) in locks_free_lock() argument
382 locks_release_private(fl); in locks_free_lock()
383 kmem_cache_free(filelock_cache, fl); in locks_free_lock()
390 struct file_lock *fl; in locks_dispose_list() local
393 fl = list_first_entry(dispose, struct file_lock, fl_list); in locks_dispose_list()
394 list_del_init(&fl->fl_list); in locks_dispose_list()
395 locks_free_lock(fl); in locks_dispose_list()
399 void locks_init_lock(struct file_lock *fl) in locks_init_lock() argument
401 memset(fl, 0, sizeof(struct file_lock)); in locks_init_lock()
402 locks_init_lock_heads(fl); in locks_init_lock()
409 void locks_copy_conflock(struct file_lock *new, struct file_lock *fl) in locks_copy_conflock() argument
411 new->fl_owner = fl->fl_owner; in locks_copy_conflock()
412 new->fl_pid = fl->fl_pid; in locks_copy_conflock()
414 new->fl_flags = fl->fl_flags; in locks_copy_conflock()
415 new->fl_type = fl->fl_type; in locks_copy_conflock()
416 new->fl_start = fl->fl_start; in locks_copy_conflock()
417 new->fl_end = fl->fl_end; in locks_copy_conflock()
418 new->fl_lmops = fl->fl_lmops; in locks_copy_conflock()
421 if (fl->fl_lmops) { in locks_copy_conflock()
422 if (fl->fl_lmops->lm_get_owner) in locks_copy_conflock()
423 fl->fl_lmops->lm_get_owner(fl->fl_owner); in locks_copy_conflock()
428 void locks_copy_lock(struct file_lock *new, struct file_lock *fl) in locks_copy_lock() argument
433 locks_copy_conflock(new, fl); in locks_copy_lock()
435 new->fl_file = fl->fl_file; in locks_copy_lock()
436 new->fl_ops = fl->fl_ops; in locks_copy_lock()
438 if (fl->fl_ops) { in locks_copy_lock()
439 if (fl->fl_ops->fl_copy_lock) in locks_copy_lock()
440 fl->fl_ops->fl_copy_lock(new, fl); in locks_copy_lock()
445 static void locks_move_blocks(struct file_lock *new, struct file_lock *fl) in locks_move_blocks() argument
454 if (list_empty(&fl->fl_blocked_requests)) in locks_move_blocks()
457 list_splice_init(&fl->fl_blocked_requests, &new->fl_blocked_requests); in locks_move_blocks()
479 flock_make_lock(struct file *filp, unsigned int cmd, struct file_lock *fl) in flock_make_lock() argument
486 if (fl == NULL) { in flock_make_lock()
487 fl = locks_alloc_lock(); in flock_make_lock()
488 if (fl == NULL) in flock_make_lock()
491 locks_init_lock(fl); in flock_make_lock()
494 fl->fl_file = filp; in flock_make_lock()
495 fl->fl_owner = filp; in flock_make_lock()
496 fl->fl_pid = current->tgid; in flock_make_lock()
497 fl->fl_flags = FL_FLOCK; in flock_make_lock()
498 fl->fl_type = type; in flock_make_lock()
499 fl->fl_end = OFFSET_MAX; in flock_make_lock()
501 return fl; in flock_make_lock()
504 static int assign_type(struct file_lock *fl, long type) in assign_type() argument
510 fl->fl_type = type; in assign_type()
518 static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl, in flock64_to_posix_lock() argument
523 fl->fl_start = 0; in flock64_to_posix_lock()
526 fl->fl_start = filp->f_pos; in flock64_to_posix_lock()
529 fl->fl_start = i_size_read(file_inode(filp)); in flock64_to_posix_lock()
534 if (l->l_start > OFFSET_MAX - fl->fl_start) in flock64_to_posix_lock()
536 fl->fl_start += l->l_start; in flock64_to_posix_lock()
537 if (fl->fl_start < 0) in flock64_to_posix_lock()
543 if (l->l_len - 1 > OFFSET_MAX - fl->fl_start) in flock64_to_posix_lock()
545 fl->fl_end = fl->fl_start + l->l_len - 1; in flock64_to_posix_lock()
548 if (fl->fl_start + l->l_len < 0) in flock64_to_posix_lock()
550 fl->fl_end = fl->fl_start - 1; in flock64_to_posix_lock()
551 fl->fl_start += l->l_len; in flock64_to_posix_lock()
553 fl->fl_end = OFFSET_MAX; in flock64_to_posix_lock()
555 fl->fl_owner = current->files; in flock64_to_posix_lock()
556 fl->fl_pid = current->tgid; in flock64_to_posix_lock()
557 fl->fl_file = filp; in flock64_to_posix_lock()
558 fl->fl_flags = FL_POSIX; in flock64_to_posix_lock()
559 fl->fl_ops = NULL; in flock64_to_posix_lock()
560 fl->fl_lmops = NULL; in flock64_to_posix_lock()
562 return assign_type(fl, l->l_type); in flock64_to_posix_lock()
568 static int flock_to_posix_lock(struct file *filp, struct file_lock *fl, in flock_to_posix_lock() argument
578 return flock64_to_posix_lock(filp, fl, &ll); in flock_to_posix_lock()
583 lease_break_callback(struct file_lock *fl) in lease_break_callback() argument
585 kill_fasync(&fl->fl_fasync, SIGIO, POLL_MSG); in lease_break_callback()
590 lease_setup(struct file_lock *fl, void **priv) in lease_setup() argument
592 struct file *filp = fl->fl_file; in lease_setup()
600 if (!fasync_insert_entry(fa->fa_fd, filp, &fl->fl_fasync, fa)) in lease_setup()
615 static int lease_init(struct file *filp, long type, struct file_lock *fl) in lease_init() argument
617 if (assign_type(fl, type) != 0) in lease_init()
620 fl->fl_owner = filp; in lease_init()
621 fl->fl_pid = current->tgid; in lease_init()
623 fl->fl_file = filp; in lease_init()
624 fl->fl_flags = FL_LEASE; in lease_init()
625 fl->fl_start = 0; in lease_init()
626 fl->fl_end = OFFSET_MAX; in lease_init()
627 fl->fl_ops = NULL; in lease_init()
628 fl->fl_lmops = &lease_manager_ops; in lease_init()
635 struct file_lock *fl = locks_alloc_lock(); in lease_alloc() local
638 if (fl == NULL) in lease_alloc()
641 error = lease_init(filp, type, fl); in lease_alloc()
643 locks_free_lock(fl); in lease_alloc()
646 return fl; in lease_alloc()
666 static void locks_insert_global_locks(struct file_lock *fl) in locks_insert_global_locks() argument
673 fl->fl_link_cpu = smp_processor_id(); in locks_insert_global_locks()
674 hlist_add_head(&fl->fl_link, &fll->hlist); in locks_insert_global_locks()
679 static void locks_delete_global_locks(struct file_lock *fl) in locks_delete_global_locks() argument
690 if (hlist_unhashed(&fl->fl_link)) in locks_delete_global_locks()
693 fll = per_cpu_ptr(&file_lock_list, fl->fl_link_cpu); in locks_delete_global_locks()
695 hlist_del_init(&fl->fl_link); in locks_delete_global_locks()
700 posix_owner_key(struct file_lock *fl) in posix_owner_key() argument
702 return (unsigned long)fl->fl_owner; in posix_owner_key()
800 struct file_lock *fl; in __locks_insert_block() local
804 list_for_each_entry(fl, &blocker->fl_blocked_requests, fl_blocked_member) in __locks_insert_block()
805 if (conflict(fl, waiter)) { in __locks_insert_block()
806 blocker = fl; in __locks_insert_block()
855 locks_insert_lock_ctx(struct file_lock *fl, struct list_head *before) in locks_insert_lock_ctx() argument
857 list_add_tail(&fl->fl_list, before); in locks_insert_lock_ctx()
858 locks_insert_global_locks(fl); in locks_insert_lock_ctx()
862 locks_unlink_lock_ctx(struct file_lock *fl) in locks_unlink_lock_ctx() argument
864 locks_delete_global_locks(fl); in locks_unlink_lock_ctx()
865 list_del_init(&fl->fl_list); in locks_unlink_lock_ctx()
866 locks_wake_up_blocks(fl); in locks_unlink_lock_ctx()
870 locks_delete_lock_ctx(struct file_lock *fl, struct list_head *dispose) in locks_delete_lock_ctx() argument
872 locks_unlink_lock_ctx(fl); in locks_delete_lock_ctx()
874 list_add(&fl->fl_list, dispose); in locks_delete_lock_ctx()
876 locks_free_lock(fl); in locks_delete_lock_ctx()
929 posix_test_lock(struct file *filp, struct file_lock *fl) in posix_test_lock() argument
937 fl->fl_type = F_UNLCK; in posix_test_lock()
943 if (posix_locks_conflict(fl, cfl)) { in posix_test_lock()
944 locks_copy_conflock(fl, cfl); in posix_test_lock()
948 fl->fl_type = F_UNLCK; in posix_test_lock()
993 struct file_lock *fl; in what_owner_is_waiting_for() local
995 hash_for_each_possible(blocked_hash, fl, fl_link, posix_owner_key(block_fl)) { in what_owner_is_waiting_for()
996 if (posix_same_owner(fl, block_fl)) { in what_owner_is_waiting_for()
997 while (fl->fl_blocker) in what_owner_is_waiting_for()
998 fl = fl->fl_blocker; in what_owner_is_waiting_for()
999 return fl; in what_owner_is_waiting_for()
1039 struct file_lock *fl; in flock_lock_inode() local
1063 list_for_each_entry(fl, &ctx->flc_flock, fl_list) { in flock_lock_inode()
1064 if (request->fl_file != fl->fl_file) in flock_lock_inode()
1066 if (request->fl_type == fl->fl_type) in flock_lock_inode()
1069 locks_delete_lock_ctx(fl, &dispose); in flock_lock_inode()
1080 list_for_each_entry(fl, &ctx->flc_flock, fl_list) { in flock_lock_inode()
1081 if (!flock_locks_conflict(request, fl)) in flock_lock_inode()
1087 locks_insert_block(fl, request, flock_locks_conflict); in flock_lock_inode()
1111 struct file_lock *fl, *tmp; in posix_lock_inode() local
1146 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1147 if (!posix_locks_conflict(request, fl)) in posix_lock_inode()
1150 locks_copy_conflock(conflock, fl); in posix_lock_inode()
1165 if (likely(!posix_locks_deadlock(request, fl))) { in posix_lock_inode()
1167 __locks_insert_block(fl, request, in posix_lock_inode()
1181 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1182 if (posix_same_owner(request, fl)) in posix_lock_inode()
1187 list_for_each_entry_safe_from(fl, tmp, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1188 if (!posix_same_owner(request, fl)) in posix_lock_inode()
1192 if (request->fl_type == fl->fl_type) { in posix_lock_inode()
1197 if (fl->fl_end < request->fl_start - 1) in posix_lock_inode()
1202 if (fl->fl_start - 1 > request->fl_end) in posix_lock_inode()
1210 if (fl->fl_start > request->fl_start) in posix_lock_inode()
1211 fl->fl_start = request->fl_start; in posix_lock_inode()
1213 request->fl_start = fl->fl_start; in posix_lock_inode()
1214 if (fl->fl_end < request->fl_end) in posix_lock_inode()
1215 fl->fl_end = request->fl_end; in posix_lock_inode()
1217 request->fl_end = fl->fl_end; in posix_lock_inode()
1219 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1222 request = fl; in posix_lock_inode()
1228 if (fl->fl_end < request->fl_start) in posix_lock_inode()
1230 if (fl->fl_start > request->fl_end) in posix_lock_inode()
1234 if (fl->fl_start < request->fl_start) in posix_lock_inode()
1235 left = fl; in posix_lock_inode()
1239 if (fl->fl_end > request->fl_end) { in posix_lock_inode()
1240 right = fl; in posix_lock_inode()
1243 if (fl->fl_start >= request->fl_start) { in posix_lock_inode()
1248 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1264 locks_insert_lock_ctx(request, &fl->fl_list); in posix_lock_inode()
1265 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1294 locks_insert_lock_ctx(new_fl, &fl->fl_list); in posix_lock_inode()
1295 fl = new_fl; in posix_lock_inode()
1306 locks_insert_lock_ctx(left, &fl->fl_list); in posix_lock_inode()
1345 int posix_lock_file(struct file *filp, struct file_lock *fl, in posix_lock_file() argument
1348 return posix_lock_inode(locks_inode(filp), fl, conflock); in posix_lock_file()
1359 static int posix_lock_inode_wait(struct inode *inode, struct file_lock *fl) in posix_lock_inode_wait() argument
1364 error = posix_lock_inode(inode, fl, NULL); in posix_lock_inode_wait()
1367 error = wait_event_interruptible(fl->fl_wait, !fl->fl_blocker); in posix_lock_inode_wait()
1371 locks_delete_block(fl); in posix_lock_inode_wait()
1388 struct file_lock *fl; in locks_mandatory_locked() local
1399 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in locks_mandatory_locked()
1400 if (fl->fl_owner != current->files && in locks_mandatory_locked()
1401 fl->fl_owner != file) { in locks_mandatory_locked()
1423 struct file_lock fl; in locks_mandatory_area() local
1427 locks_init_lock(&fl); in locks_mandatory_area()
1428 fl.fl_pid = current->tgid; in locks_mandatory_area()
1429 fl.fl_file = filp; in locks_mandatory_area()
1430 fl.fl_flags = FL_POSIX | FL_ACCESS; in locks_mandatory_area()
1433 fl.fl_type = type; in locks_mandatory_area()
1434 fl.fl_start = start; in locks_mandatory_area()
1435 fl.fl_end = end; in locks_mandatory_area()
1439 fl.fl_owner = filp; in locks_mandatory_area()
1440 fl.fl_flags &= ~FL_SLEEP; in locks_mandatory_area()
1441 error = posix_lock_inode(inode, &fl, NULL); in locks_mandatory_area()
1447 fl.fl_flags |= FL_SLEEP; in locks_mandatory_area()
1448 fl.fl_owner = current->files; in locks_mandatory_area()
1449 error = posix_lock_inode(inode, &fl, NULL); in locks_mandatory_area()
1452 error = wait_event_interruptible(fl.fl_wait, !fl.fl_blocker); in locks_mandatory_area()
1464 locks_delete_block(&fl); in locks_mandatory_area()
1471 static void lease_clear_pending(struct file_lock *fl, int arg) in lease_clear_pending() argument
1475 fl->fl_flags &= ~FL_UNLOCK_PENDING; in lease_clear_pending()
1478 fl->fl_flags &= ~FL_DOWNGRADE_PENDING; in lease_clear_pending()
1483 int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose) in lease_modify() argument
1485 int error = assign_type(fl, arg); in lease_modify()
1489 lease_clear_pending(fl, arg); in lease_modify()
1490 locks_wake_up_blocks(fl); in lease_modify()
1492 struct file *filp = fl->fl_file; in lease_modify()
1496 fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync); in lease_modify()
1497 if (fl->fl_fasync != NULL) { in lease_modify()
1498 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync); in lease_modify()
1499 fl->fl_fasync = NULL; in lease_modify()
1501 locks_delete_lock_ctx(fl, dispose); in lease_modify()
1518 struct file_lock *fl, *tmp; in time_out_leases() local
1522 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) { in time_out_leases()
1523 trace_time_out_leases(inode, fl); in time_out_leases()
1524 if (past_time(fl->fl_downgrade_time)) in time_out_leases()
1525 lease_modify(fl, F_RDLCK, dispose); in time_out_leases()
1526 if (past_time(fl->fl_break_time)) in time_out_leases()
1527 lease_modify(fl, F_UNLCK, dispose); in time_out_leases()
1554 struct file_lock *fl; in any_leases_conflict() local
1558 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in any_leases_conflict()
1559 if (leases_conflict(fl, breaker)) in any_leases_conflict()
1582 struct file_lock *new_fl, *fl, *tmp; in __break_lease() local
1614 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) { in __break_lease()
1615 if (!leases_conflict(fl, new_fl)) in __break_lease()
1618 if (fl->fl_flags & FL_UNLOCK_PENDING) in __break_lease()
1620 fl->fl_flags |= FL_UNLOCK_PENDING; in __break_lease()
1621 fl->fl_break_time = break_time; in __break_lease()
1623 if (lease_breaking(fl)) in __break_lease()
1625 fl->fl_flags |= FL_DOWNGRADE_PENDING; in __break_lease()
1626 fl->fl_downgrade_time = break_time; in __break_lease()
1628 if (fl->fl_lmops->lm_break(fl)) in __break_lease()
1629 locks_delete_lock_ctx(fl, &dispose); in __break_lease()
1642 fl = list_first_entry(&ctx->flc_lease, struct file_lock, fl_list); in __break_lease()
1643 break_time = fl->fl_break_time; in __break_lease()
1648 locks_insert_block(fl, new_fl, leases_conflict); in __break_lease()
1695 struct file_lock *fl; in lease_get_mtime() local
1700 fl = list_first_entry_or_null(&ctx->flc_lease, in lease_get_mtime()
1702 if (fl && (fl->fl_type == F_WRLCK)) in lease_get_mtime()
1737 struct file_lock *fl; in fcntl_getlease() local
1748 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in fcntl_getlease()
1749 if (fl->fl_file != filp) in fcntl_getlease()
1751 type = target_leasetype(fl); in fcntl_getlease()
1808 struct file_lock *fl, *my_fl = NULL, *lease; in generic_add_lease() local
1857 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in generic_add_lease()
1858 if (fl->fl_file == filp && in generic_add_lease()
1859 fl->fl_owner == lease->fl_owner) { in generic_add_lease()
1860 my_fl = fl; in generic_add_lease()
1874 if (fl->fl_flags & FL_UNLOCK_PENDING) in generic_add_lease()
1924 struct file_lock *fl, *victim = NULL; in generic_delete_lease() local
1937 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in generic_delete_lease()
1938 if (fl->fl_file == filp && in generic_delete_lease()
1939 fl->fl_owner == owner) { in generic_delete_lease()
1940 victim = fl; in generic_delete_lease()
1946 error = fl->fl_lmops->lm_change(victim, F_UNLCK, &dispose); in generic_delete_lease()
2084 struct file_lock *fl; in do_fcntl_add_lease() local
2088 fl = lease_alloc(filp, arg); in do_fcntl_add_lease()
2089 if (IS_ERR(fl)) in do_fcntl_add_lease()
2090 return PTR_ERR(fl); in do_fcntl_add_lease()
2094 locks_free_lock(fl); in do_fcntl_add_lease()
2099 error = vfs_setlease(filp, arg, &fl, (void **)&new); in do_fcntl_add_lease()
2100 if (fl) in do_fcntl_add_lease()
2101 locks_free_lock(fl); in do_fcntl_add_lease()
2131 static int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl) in flock_lock_inode_wait() argument
2136 error = flock_lock_inode(inode, fl); in flock_lock_inode_wait()
2139 error = wait_event_interruptible(fl->fl_wait, !fl->fl_blocker); in flock_lock_inode_wait()
2143 locks_delete_block(fl); in flock_lock_inode_wait()
2154 int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl) in locks_lock_inode_wait() argument
2157 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { in locks_lock_inode_wait()
2159 res = posix_lock_inode_wait(inode, fl); in locks_lock_inode_wait()
2162 res = flock_lock_inode_wait(inode, fl); in locks_lock_inode_wait()
2244 int vfs_test_lock(struct file *filp, struct file_lock *fl) in vfs_test_lock() argument
2247 return filp->f_op->lock(filp, F_GETLK, fl); in vfs_test_lock()
2248 posix_test_lock(filp, fl); in vfs_test_lock()
2260 static pid_t locks_translate_pid(struct file_lock *fl, struct pid_namespace *ns) in locks_translate_pid() argument
2265 if (IS_OFDLCK(fl)) in locks_translate_pid()
2267 if (IS_REMOTELCK(fl)) in locks_translate_pid()
2268 return fl->fl_pid; in locks_translate_pid()
2275 return (pid_t)fl->fl_pid; in locks_translate_pid()
2278 pid = find_pid_ns(fl->fl_pid, &init_pid_ns); in locks_translate_pid()
2284 static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl) in posix_lock_to_flock() argument
2286 flock->l_pid = locks_translate_pid(fl, task_active_pid_ns(current)); in posix_lock_to_flock()
2292 if (fl->fl_start > OFFT_OFFSET_MAX) in posix_lock_to_flock()
2294 if (fl->fl_end != OFFSET_MAX && fl->fl_end > OFFT_OFFSET_MAX) in posix_lock_to_flock()
2297 flock->l_start = fl->fl_start; in posix_lock_to_flock()
2298 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 : in posix_lock_to_flock()
2299 fl->fl_end - fl->fl_start + 1; in posix_lock_to_flock()
2301 flock->l_type = fl->fl_type; in posix_lock_to_flock()
2306 static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl) in posix_lock_to_flock64() argument
2308 flock->l_pid = locks_translate_pid(fl, task_active_pid_ns(current)); in posix_lock_to_flock64()
2309 flock->l_start = fl->fl_start; in posix_lock_to_flock64()
2310 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 : in posix_lock_to_flock64()
2311 fl->fl_end - fl->fl_start + 1; in posix_lock_to_flock64()
2313 flock->l_type = fl->fl_type; in posix_lock_to_flock64()
2322 struct file_lock *fl; in fcntl_getlk() local
2325 fl = locks_alloc_lock(); in fcntl_getlk()
2326 if (fl == NULL) in fcntl_getlk()
2332 error = flock_to_posix_lock(filp, fl, flock); in fcntl_getlk()
2342 fl->fl_flags |= FL_OFDLCK; in fcntl_getlk()
2343 fl->fl_owner = filp; in fcntl_getlk()
2346 error = vfs_test_lock(filp, fl); in fcntl_getlk()
2350 flock->l_type = fl->fl_type; in fcntl_getlk()
2351 if (fl->fl_type != F_UNLCK) { in fcntl_getlk()
2352 error = posix_lock_to_flock(flock, fl); in fcntl_getlk()
2357 locks_free_lock(fl); in fcntl_getlk()
2394 int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf) in vfs_lock_file() argument
2397 return filp->f_op->lock(filp, cmd, fl); in vfs_lock_file()
2399 return posix_lock_file(filp, fl, conf); in vfs_lock_file()
2404 struct file_lock *fl) in do_lock_file_wait() argument
2408 error = security_file_lock(filp, fl->fl_type); in do_lock_file_wait()
2413 error = vfs_lock_file(filp, cmd, fl, NULL); in do_lock_file_wait()
2416 error = wait_event_interruptible(fl->fl_wait, !fl->fl_blocker); in do_lock_file_wait()
2420 locks_delete_block(fl); in do_lock_file_wait()
2427 check_fmode_for_setlk(struct file_lock *fl) in check_fmode_for_setlk() argument
2429 switch (fl->fl_type) { in check_fmode_for_setlk()
2431 if (!(fl->fl_file->f_mode & FMODE_READ)) in check_fmode_for_setlk()
2435 if (!(fl->fl_file->f_mode & FMODE_WRITE)) in check_fmode_for_setlk()
2534 struct file_lock *fl; in fcntl_getlk64() local
2537 fl = locks_alloc_lock(); in fcntl_getlk64()
2538 if (fl == NULL) in fcntl_getlk64()
2545 error = flock64_to_posix_lock(filp, fl, flock); in fcntl_getlk64()
2555 fl->fl_flags |= FL_OFDLCK; in fcntl_getlk64()
2556 fl->fl_owner = filp; in fcntl_getlk64()
2559 error = vfs_test_lock(filp, fl); in fcntl_getlk64()
2563 flock->l_type = fl->fl_type; in fcntl_getlk64()
2564 if (fl->fl_type != F_UNLCK) in fcntl_getlk64()
2565 posix_lock_to_flock64(flock, fl); in fcntl_getlk64()
2568 locks_free_lock(fl); in fcntl_getlk64()
2703 struct file_lock fl; in locks_remove_flock() local
2709 flock_make_lock(filp, LOCK_UN, &fl); in locks_remove_flock()
2710 fl.fl_flags |= FL_CLOSE; in locks_remove_flock()
2713 filp->f_op->flock(filp, F_SETLKW, &fl); in locks_remove_flock()
2715 flock_lock_inode(inode, &fl); in locks_remove_flock()
2717 if (fl.fl_ops && fl.fl_ops->fl_release_private) in locks_remove_flock()
2718 fl.fl_ops->fl_release_private(&fl); in locks_remove_flock()
2725 struct file_lock *fl, *tmp; in locks_remove_lease() local
2733 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) in locks_remove_lease()
2734 if (filp == fl->fl_file) in locks_remove_lease()
2735 lease_modify(fl, F_UNLCK, &dispose); in locks_remove_lease()
2776 int vfs_cancel_lock(struct file *filp, struct file_lock *fl) in vfs_cancel_lock() argument
2779 return filp->f_op->lock(filp, F_CANCELLK, fl); in vfs_cancel_lock()
2793 static void lock_get_status(struct seq_file *f, struct file_lock *fl, in lock_get_status() argument
2800 fl_pid = locks_translate_pid(fl, proc_pidns); in lock_get_status()
2807 if (fl->fl_file != NULL) in lock_get_status()
2808 inode = locks_inode(fl->fl_file); in lock_get_status()
2811 if (IS_POSIX(fl)) { in lock_get_status()
2812 if (fl->fl_flags & FL_ACCESS) in lock_get_status()
2814 else if (IS_OFDLCK(fl)) in lock_get_status()
2822 } else if (IS_FLOCK(fl)) { in lock_get_status()
2823 if (fl->fl_type & LOCK_MAND) { in lock_get_status()
2828 } else if (IS_LEASE(fl)) { in lock_get_status()
2829 if (fl->fl_flags & FL_DELEG) in lock_get_status()
2834 if (lease_breaking(fl)) in lock_get_status()
2836 else if (fl->fl_file) in lock_get_status()
2843 if (fl->fl_type & LOCK_MAND) { in lock_get_status()
2845 (fl->fl_type & LOCK_READ) in lock_get_status()
2846 ? (fl->fl_type & LOCK_WRITE) ? "RW " : "READ " in lock_get_status()
2847 : (fl->fl_type & LOCK_WRITE) ? "WRITE" : "NONE "); in lock_get_status()
2849 int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type; in lock_get_status()
2862 if (IS_POSIX(fl)) { in lock_get_status()
2863 if (fl->fl_end == OFFSET_MAX) in lock_get_status()
2864 seq_printf(f, "%Ld EOF\n", fl->fl_start); in lock_get_status()
2866 seq_printf(f, "%Ld %Ld\n", fl->fl_start, fl->fl_end); in lock_get_status()
2875 struct file_lock *fl, *bfl; in locks_show() local
2878 fl = hlist_entry(v, struct file_lock, fl_link); in locks_show()
2880 if (locks_translate_pid(fl, proc_pidns) == 0) in locks_show()
2883 lock_get_status(f, fl, iter->li_pos, ""); in locks_show()
2885 list_for_each_entry(bfl, &fl->fl_blocked_requests, fl_blocked_member) in locks_show()
2895 struct file_lock *fl; in __show_fd_locks() local
2897 list_for_each_entry(fl, head, fl_list) { in __show_fd_locks()
2899 if (filp != fl->fl_file) in __show_fd_locks()
2901 if (fl->fl_owner != files && in __show_fd_locks()
2902 fl->fl_owner != filp) in __show_fd_locks()
2907 lock_get_status(f, fl, *id, ""); in __show_fd_locks()