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()
823 struct file_lock *fl; in __locks_insert_block() local
827 list_for_each_entry(fl, &blocker->fl_blocked_requests, fl_blocked_member) in __locks_insert_block()
828 if (conflict(fl, waiter)) { in __locks_insert_block()
829 blocker = fl; in __locks_insert_block()
878 locks_insert_lock_ctx(struct file_lock *fl, struct list_head *before) in locks_insert_lock_ctx() argument
880 list_add_tail(&fl->fl_list, before); in locks_insert_lock_ctx()
881 locks_insert_global_locks(fl); in locks_insert_lock_ctx()
885 locks_unlink_lock_ctx(struct file_lock *fl) in locks_unlink_lock_ctx() argument
887 locks_delete_global_locks(fl); in locks_unlink_lock_ctx()
888 list_del_init(&fl->fl_list); in locks_unlink_lock_ctx()
889 locks_wake_up_blocks(fl); in locks_unlink_lock_ctx()
893 locks_delete_lock_ctx(struct file_lock *fl, struct list_head *dispose) in locks_delete_lock_ctx() argument
895 locks_unlink_lock_ctx(fl); in locks_delete_lock_ctx()
897 list_add(&fl->fl_list, dispose); in locks_delete_lock_ctx()
899 locks_free_lock(fl); in locks_delete_lock_ctx()
952 posix_test_lock(struct file *filp, struct file_lock *fl) in posix_test_lock() argument
960 fl->fl_type = F_UNLCK; in posix_test_lock()
966 if (posix_locks_conflict(fl, cfl)) { in posix_test_lock()
967 locks_copy_conflock(fl, cfl); in posix_test_lock()
971 fl->fl_type = F_UNLCK; in posix_test_lock()
1016 struct file_lock *fl; in what_owner_is_waiting_for() local
1018 hash_for_each_possible(blocked_hash, fl, fl_link, posix_owner_key(block_fl)) { in what_owner_is_waiting_for()
1019 if (posix_same_owner(fl, block_fl)) { in what_owner_is_waiting_for()
1020 while (fl->fl_blocker) in what_owner_is_waiting_for()
1021 fl = fl->fl_blocker; in what_owner_is_waiting_for()
1022 return fl; in what_owner_is_waiting_for()
1062 struct file_lock *fl; in flock_lock_inode() local
1086 list_for_each_entry(fl, &ctx->flc_flock, fl_list) { in flock_lock_inode()
1087 if (request->fl_file != fl->fl_file) in flock_lock_inode()
1089 if (request->fl_type == fl->fl_type) in flock_lock_inode()
1092 locks_delete_lock_ctx(fl, &dispose); in flock_lock_inode()
1103 list_for_each_entry(fl, &ctx->flc_flock, fl_list) { in flock_lock_inode()
1104 if (!flock_locks_conflict(request, fl)) in flock_lock_inode()
1110 locks_insert_block(fl, request, flock_locks_conflict); in flock_lock_inode()
1134 struct file_lock *fl, *tmp; in posix_lock_inode() local
1169 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1170 if (!posix_locks_conflict(request, fl)) in posix_lock_inode()
1173 locks_copy_conflock(conflock, fl); in posix_lock_inode()
1188 if (likely(!posix_locks_deadlock(request, fl))) { in posix_lock_inode()
1190 __locks_insert_block(fl, request, in posix_lock_inode()
1204 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1205 if (posix_same_owner(request, fl)) in posix_lock_inode()
1210 list_for_each_entry_safe_from(fl, tmp, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1211 if (!posix_same_owner(request, fl)) in posix_lock_inode()
1215 if (request->fl_type == fl->fl_type) { in posix_lock_inode()
1220 if (fl->fl_end < request->fl_start - 1) in posix_lock_inode()
1225 if (fl->fl_start - 1 > request->fl_end) in posix_lock_inode()
1233 if (fl->fl_start > request->fl_start) in posix_lock_inode()
1234 fl->fl_start = request->fl_start; in posix_lock_inode()
1236 request->fl_start = fl->fl_start; in posix_lock_inode()
1237 if (fl->fl_end < request->fl_end) in posix_lock_inode()
1238 fl->fl_end = request->fl_end; in posix_lock_inode()
1240 request->fl_end = fl->fl_end; in posix_lock_inode()
1242 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1245 request = fl; in posix_lock_inode()
1251 if (fl->fl_end < request->fl_start) in posix_lock_inode()
1253 if (fl->fl_start > request->fl_end) in posix_lock_inode()
1257 if (fl->fl_start < request->fl_start) in posix_lock_inode()
1258 left = fl; in posix_lock_inode()
1262 if (fl->fl_end > request->fl_end) { in posix_lock_inode()
1263 right = fl; in posix_lock_inode()
1266 if (fl->fl_start >= request->fl_start) { in posix_lock_inode()
1271 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1288 locks_insert_lock_ctx(request, &fl->fl_list); in posix_lock_inode()
1289 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1318 locks_insert_lock_ctx(new_fl, &fl->fl_list); in posix_lock_inode()
1319 fl = new_fl; in posix_lock_inode()
1330 locks_insert_lock_ctx(left, &fl->fl_list); in posix_lock_inode()
1369 int posix_lock_file(struct file *filp, struct file_lock *fl, in posix_lock_file() argument
1372 return posix_lock_inode(locks_inode(filp), fl, conflock); in posix_lock_file()
1383 static int posix_lock_inode_wait(struct inode *inode, struct file_lock *fl) in posix_lock_inode_wait() argument
1388 error = posix_lock_inode(inode, fl, NULL); in posix_lock_inode_wait()
1391 error = wait_event_interruptible(fl->fl_wait, in posix_lock_inode_wait()
1392 list_empty(&fl->fl_blocked_member)); in posix_lock_inode_wait()
1396 locks_delete_block(fl); in posix_lock_inode_wait()
1413 struct file_lock *fl; in locks_mandatory_locked() local
1424 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in locks_mandatory_locked()
1425 if (fl->fl_owner != current->files && in locks_mandatory_locked()
1426 fl->fl_owner != file) { in locks_mandatory_locked()
1448 struct file_lock fl; in locks_mandatory_area() local
1452 locks_init_lock(&fl); in locks_mandatory_area()
1453 fl.fl_pid = current->tgid; in locks_mandatory_area()
1454 fl.fl_file = filp; in locks_mandatory_area()
1455 fl.fl_flags = FL_POSIX | FL_ACCESS; in locks_mandatory_area()
1458 fl.fl_type = type; in locks_mandatory_area()
1459 fl.fl_start = start; in locks_mandatory_area()
1460 fl.fl_end = end; in locks_mandatory_area()
1464 fl.fl_owner = filp; in locks_mandatory_area()
1465 fl.fl_flags &= ~FL_SLEEP; in locks_mandatory_area()
1466 error = posix_lock_inode(inode, &fl, NULL); in locks_mandatory_area()
1472 fl.fl_flags |= FL_SLEEP; in locks_mandatory_area()
1473 fl.fl_owner = current->files; in locks_mandatory_area()
1474 error = posix_lock_inode(inode, &fl, NULL); in locks_mandatory_area()
1477 error = wait_event_interruptible(fl.fl_wait, in locks_mandatory_area()
1478 list_empty(&fl.fl_blocked_member)); in locks_mandatory_area()
1490 locks_delete_block(&fl); in locks_mandatory_area()
1497 static void lease_clear_pending(struct file_lock *fl, int arg) in lease_clear_pending() argument
1501 fl->fl_flags &= ~FL_UNLOCK_PENDING; in lease_clear_pending()
1504 fl->fl_flags &= ~FL_DOWNGRADE_PENDING; in lease_clear_pending()
1509 int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose) in lease_modify() argument
1511 int error = assign_type(fl, arg); in lease_modify()
1515 lease_clear_pending(fl, arg); in lease_modify()
1516 locks_wake_up_blocks(fl); in lease_modify()
1518 struct file *filp = fl->fl_file; in lease_modify()
1522 fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync); in lease_modify()
1523 if (fl->fl_fasync != NULL) { in lease_modify()
1524 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync); in lease_modify()
1525 fl->fl_fasync = NULL; in lease_modify()
1527 locks_delete_lock_ctx(fl, dispose); in lease_modify()
1544 struct file_lock *fl, *tmp; in time_out_leases() local
1548 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) { in time_out_leases()
1549 trace_time_out_leases(inode, fl); in time_out_leases()
1550 if (past_time(fl->fl_downgrade_time)) in time_out_leases()
1551 lease_modify(fl, F_RDLCK, dispose); in time_out_leases()
1552 if (past_time(fl->fl_break_time)) in time_out_leases()
1553 lease_modify(fl, F_UNLCK, dispose); in time_out_leases()
1583 struct file_lock *fl; in any_leases_conflict() local
1587 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in any_leases_conflict()
1588 if (leases_conflict(fl, breaker)) in any_leases_conflict()
1611 struct file_lock *new_fl, *fl, *tmp; in __break_lease() local
1643 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) { in __break_lease()
1644 if (!leases_conflict(fl, new_fl)) in __break_lease()
1647 if (fl->fl_flags & FL_UNLOCK_PENDING) in __break_lease()
1649 fl->fl_flags |= FL_UNLOCK_PENDING; in __break_lease()
1650 fl->fl_break_time = break_time; in __break_lease()
1652 if (lease_breaking(fl)) in __break_lease()
1654 fl->fl_flags |= FL_DOWNGRADE_PENDING; in __break_lease()
1655 fl->fl_downgrade_time = break_time; in __break_lease()
1657 if (fl->fl_lmops->lm_break(fl)) in __break_lease()
1658 locks_delete_lock_ctx(fl, &dispose); in __break_lease()
1671 fl = list_first_entry(&ctx->flc_lease, struct file_lock, fl_list); in __break_lease()
1672 break_time = fl->fl_break_time; in __break_lease()
1677 locks_insert_block(fl, new_fl, leases_conflict); in __break_lease()
1725 struct file_lock *fl; in lease_get_mtime() local
1730 fl = list_first_entry_or_null(&ctx->flc_lease, in lease_get_mtime()
1732 if (fl && (fl->fl_type == F_WRLCK)) in lease_get_mtime()
1767 struct file_lock *fl; in fcntl_getlease() local
1778 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in fcntl_getlease()
1779 if (fl->fl_file != filp) in fcntl_getlease()
1781 type = target_leasetype(fl); in fcntl_getlease()
1838 struct file_lock *fl, *my_fl = NULL, *lease; in generic_add_lease() local
1887 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in generic_add_lease()
1888 if (fl->fl_file == filp && in generic_add_lease()
1889 fl->fl_owner == lease->fl_owner) { in generic_add_lease()
1890 my_fl = fl; in generic_add_lease()
1904 if (fl->fl_flags & FL_UNLOCK_PENDING) in generic_add_lease()
1954 struct file_lock *fl, *victim = NULL; in generic_delete_lease() local
1967 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in generic_delete_lease()
1968 if (fl->fl_file == filp && in generic_delete_lease()
1969 fl->fl_owner == owner) { in generic_delete_lease()
1970 victim = fl; in generic_delete_lease()
1976 error = fl->fl_lmops->lm_change(victim, F_UNLCK, &dispose); in generic_delete_lease()
2114 struct file_lock *fl; in do_fcntl_add_lease() local
2118 fl = lease_alloc(filp, arg); in do_fcntl_add_lease()
2119 if (IS_ERR(fl)) in do_fcntl_add_lease()
2120 return PTR_ERR(fl); in do_fcntl_add_lease()
2124 locks_free_lock(fl); in do_fcntl_add_lease()
2129 error = vfs_setlease(filp, arg, &fl, (void **)&new); in do_fcntl_add_lease()
2130 if (fl) in do_fcntl_add_lease()
2131 locks_free_lock(fl); in do_fcntl_add_lease()
2161 static int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl) in flock_lock_inode_wait() argument
2166 error = flock_lock_inode(inode, fl); in flock_lock_inode_wait()
2169 error = wait_event_interruptible(fl->fl_wait, in flock_lock_inode_wait()
2170 list_empty(&fl->fl_blocked_member)); in flock_lock_inode_wait()
2174 locks_delete_block(fl); in flock_lock_inode_wait()
2185 int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl) in locks_lock_inode_wait() argument
2188 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { in locks_lock_inode_wait()
2190 res = posix_lock_inode_wait(inode, fl); in locks_lock_inode_wait()
2193 res = flock_lock_inode_wait(inode, fl); in locks_lock_inode_wait()
2275 int vfs_test_lock(struct file *filp, struct file_lock *fl) in vfs_test_lock() argument
2278 return filp->f_op->lock(filp, F_GETLK, fl); in vfs_test_lock()
2279 posix_test_lock(filp, fl); in vfs_test_lock()
2291 static pid_t locks_translate_pid(struct file_lock *fl, struct pid_namespace *ns) in locks_translate_pid() argument
2296 if (IS_OFDLCK(fl)) in locks_translate_pid()
2298 if (IS_REMOTELCK(fl)) in locks_translate_pid()
2299 return fl->fl_pid; in locks_translate_pid()
2306 return (pid_t)fl->fl_pid; in locks_translate_pid()
2309 pid = find_pid_ns(fl->fl_pid, &init_pid_ns); in locks_translate_pid()
2315 static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl) in posix_lock_to_flock() argument
2317 flock->l_pid = locks_translate_pid(fl, task_active_pid_ns(current)); in posix_lock_to_flock()
2323 if (fl->fl_start > OFFT_OFFSET_MAX) in posix_lock_to_flock()
2325 if (fl->fl_end != OFFSET_MAX && fl->fl_end > OFFT_OFFSET_MAX) in posix_lock_to_flock()
2328 flock->l_start = fl->fl_start; in posix_lock_to_flock()
2329 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 : in posix_lock_to_flock()
2330 fl->fl_end - fl->fl_start + 1; in posix_lock_to_flock()
2332 flock->l_type = fl->fl_type; in posix_lock_to_flock()
2337 static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl) in posix_lock_to_flock64() argument
2339 flock->l_pid = locks_translate_pid(fl, task_active_pid_ns(current)); in posix_lock_to_flock64()
2340 flock->l_start = fl->fl_start; in posix_lock_to_flock64()
2341 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 : in posix_lock_to_flock64()
2342 fl->fl_end - fl->fl_start + 1; in posix_lock_to_flock64()
2344 flock->l_type = fl->fl_type; in posix_lock_to_flock64()
2353 struct file_lock *fl; in fcntl_getlk() local
2356 fl = locks_alloc_lock(); in fcntl_getlk()
2357 if (fl == NULL) in fcntl_getlk()
2363 error = flock_to_posix_lock(filp, fl, flock); in fcntl_getlk()
2373 fl->fl_flags |= FL_OFDLCK; in fcntl_getlk()
2374 fl->fl_owner = filp; in fcntl_getlk()
2377 error = vfs_test_lock(filp, fl); in fcntl_getlk()
2381 flock->l_type = fl->fl_type; in fcntl_getlk()
2382 if (fl->fl_type != F_UNLCK) { in fcntl_getlk()
2383 error = posix_lock_to_flock(flock, fl); in fcntl_getlk()
2388 locks_free_lock(fl); in fcntl_getlk()
2425 int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf) in vfs_lock_file() argument
2428 return filp->f_op->lock(filp, cmd, fl); in vfs_lock_file()
2430 return posix_lock_file(filp, fl, conf); in vfs_lock_file()
2435 struct file_lock *fl) in do_lock_file_wait() argument
2439 error = security_file_lock(filp, fl->fl_type); in do_lock_file_wait()
2444 error = vfs_lock_file(filp, cmd, fl, NULL); in do_lock_file_wait()
2447 error = wait_event_interruptible(fl->fl_wait, in do_lock_file_wait()
2448 list_empty(&fl->fl_blocked_member)); in do_lock_file_wait()
2452 locks_delete_block(fl); in do_lock_file_wait()
2459 check_fmode_for_setlk(struct file_lock *fl) in check_fmode_for_setlk() argument
2461 switch (fl->fl_type) { in check_fmode_for_setlk()
2463 if (!(fl->fl_file->f_mode & FMODE_READ)) in check_fmode_for_setlk()
2467 if (!(fl->fl_file->f_mode & FMODE_WRITE)) in check_fmode_for_setlk()
2566 struct file_lock *fl; in fcntl_getlk64() local
2569 fl = locks_alloc_lock(); in fcntl_getlk64()
2570 if (fl == NULL) in fcntl_getlk64()
2577 error = flock64_to_posix_lock(filp, fl, flock); in fcntl_getlk64()
2587 fl->fl_flags |= FL_OFDLCK; in fcntl_getlk64()
2588 fl->fl_owner = filp; in fcntl_getlk64()
2591 error = vfs_test_lock(filp, fl); in fcntl_getlk64()
2595 flock->l_type = fl->fl_type; in fcntl_getlk64()
2596 if (fl->fl_type != F_UNLCK) in fcntl_getlk64()
2597 posix_lock_to_flock64(flock, fl); in fcntl_getlk64()
2600 locks_free_lock(fl); in fcntl_getlk64()
2735 struct file_lock fl; in locks_remove_flock() local
2741 flock_make_lock(filp, LOCK_UN, &fl); in locks_remove_flock()
2742 fl.fl_flags |= FL_CLOSE; in locks_remove_flock()
2745 filp->f_op->flock(filp, F_SETLKW, &fl); in locks_remove_flock()
2747 flock_lock_inode(inode, &fl); in locks_remove_flock()
2749 if (fl.fl_ops && fl.fl_ops->fl_release_private) in locks_remove_flock()
2750 fl.fl_ops->fl_release_private(&fl); in locks_remove_flock()
2757 struct file_lock *fl, *tmp; in locks_remove_lease() local
2765 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) in locks_remove_lease()
2766 if (filp == fl->fl_file) in locks_remove_lease()
2767 lease_modify(fl, F_UNLCK, &dispose); in locks_remove_lease()
2808 int vfs_cancel_lock(struct file *filp, struct file_lock *fl) in vfs_cancel_lock() argument
2811 return filp->f_op->lock(filp, F_CANCELLK, fl); in vfs_cancel_lock()
2825 static void lock_get_status(struct seq_file *f, struct file_lock *fl, in lock_get_status() argument
2832 fl_pid = locks_translate_pid(fl, proc_pidns); in lock_get_status()
2839 if (fl->fl_file != NULL) in lock_get_status()
2840 inode = locks_inode(fl->fl_file); in lock_get_status()
2843 if (IS_POSIX(fl)) { in lock_get_status()
2844 if (fl->fl_flags & FL_ACCESS) in lock_get_status()
2846 else if (IS_OFDLCK(fl)) in lock_get_status()
2854 } else if (IS_FLOCK(fl)) { in lock_get_status()
2855 if (fl->fl_type & LOCK_MAND) { in lock_get_status()
2860 } else if (IS_LEASE(fl)) { in lock_get_status()
2861 if (fl->fl_flags & FL_DELEG) in lock_get_status()
2866 if (lease_breaking(fl)) in lock_get_status()
2868 else if (fl->fl_file) in lock_get_status()
2875 if (fl->fl_type & LOCK_MAND) { in lock_get_status()
2877 (fl->fl_type & LOCK_READ) in lock_get_status()
2878 ? (fl->fl_type & LOCK_WRITE) ? "RW " : "READ " in lock_get_status()
2879 : (fl->fl_type & LOCK_WRITE) ? "WRITE" : "NONE "); in lock_get_status()
2881 int type = IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_type; in lock_get_status()
2894 if (IS_POSIX(fl)) { in lock_get_status()
2895 if (fl->fl_end == OFFSET_MAX) in lock_get_status()
2896 seq_printf(f, "%Ld EOF\n", fl->fl_start); in lock_get_status()
2898 seq_printf(f, "%Ld %Ld\n", fl->fl_start, fl->fl_end); in lock_get_status()
2907 struct file_lock *fl, *bfl; in locks_show() local
2910 fl = hlist_entry(v, struct file_lock, fl_link); in locks_show()
2912 if (locks_translate_pid(fl, proc_pidns) == 0) in locks_show()
2915 lock_get_status(f, fl, iter->li_pos, ""); in locks_show()
2917 list_for_each_entry(bfl, &fl->fl_blocked_requests, fl_blocked_member) in locks_show()
2927 struct file_lock *fl; in __show_fd_locks() local
2929 list_for_each_entry(fl, head, fl_list) { in __show_fd_locks()
2931 if (filp != fl->fl_file) in __show_fd_locks()
2933 if (fl->fl_owner != files && in __show_fd_locks()
2934 fl->fl_owner != filp) in __show_fd_locks()
2939 lock_get_status(f, fl, *id, ""); in __show_fd_locks()