Lines Matching refs:fl

136 #define IS_POSIX(fl)	(fl->fl_flags & FL_POSIX)  argument
137 #define IS_FLOCK(fl) (fl->fl_flags & FL_FLOCK) argument
138 #define IS_LEASE(fl) (fl->fl_flags & (FL_LEASE|FL_DELEG|FL_LAYOUT)) argument
139 #define IS_OFDLCK(fl) (fl->fl_flags & FL_OFDLCK) argument
140 #define IS_REMOTELCK(fl) (fl->fl_pid <= 0) argument
142 static bool lease_breaking(struct file_lock *fl) in lease_breaking() argument
144 return fl->fl_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING); in lease_breaking()
147 static int target_leasetype(struct file_lock *fl) in target_leasetype() argument
149 if (fl->fl_flags & FL_UNLOCK_PENDING) in target_leasetype()
151 if (fl->fl_flags & FL_DOWNGRADE_PENDING) in target_leasetype()
153 return fl->fl_type; in target_leasetype()
241 struct file_lock *fl; in locks_dump_ctx_list() local
243 list_for_each_entry(fl, list, fl_list) { in locks_dump_ctx_list()
244 …%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()
269 struct file_lock *fl; in locks_check_ctx_file_list() local
272 list_for_each_entry(fl, list, fl_list) in locks_check_ctx_file_list()
273 if (fl->fl_file == filp) in locks_check_ctx_file_list()
278 fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid); in locks_check_ctx_file_list()
292 static void locks_init_lock_heads(struct file_lock *fl) in locks_init_lock_heads() argument
294 INIT_HLIST_NODE(&fl->fl_link); in locks_init_lock_heads()
295 INIT_LIST_HEAD(&fl->fl_list); in locks_init_lock_heads()
296 INIT_LIST_HEAD(&fl->fl_block); in locks_init_lock_heads()
297 init_waitqueue_head(&fl->fl_wait); in locks_init_lock_heads()
303 struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL); in locks_alloc_lock() local
305 if (fl) in locks_alloc_lock()
306 locks_init_lock_heads(fl); in locks_alloc_lock()
308 return fl; in locks_alloc_lock()
312 void locks_release_private(struct file_lock *fl) in locks_release_private() argument
314 if (fl->fl_ops) { in locks_release_private()
315 if (fl->fl_ops->fl_release_private) in locks_release_private()
316 fl->fl_ops->fl_release_private(fl); in locks_release_private()
317 fl->fl_ops = NULL; in locks_release_private()
320 if (fl->fl_lmops) { in locks_release_private()
321 if (fl->fl_lmops->lm_put_owner) { in locks_release_private()
322 fl->fl_lmops->lm_put_owner(fl->fl_owner); in locks_release_private()
323 fl->fl_owner = NULL; in locks_release_private()
325 fl->fl_lmops = NULL; in locks_release_private()
331 void locks_free_lock(struct file_lock *fl) in locks_free_lock() argument
333 BUG_ON(waitqueue_active(&fl->fl_wait)); in locks_free_lock()
334 BUG_ON(!list_empty(&fl->fl_list)); in locks_free_lock()
335 BUG_ON(!list_empty(&fl->fl_block)); in locks_free_lock()
336 BUG_ON(!hlist_unhashed(&fl->fl_link)); in locks_free_lock()
338 locks_release_private(fl); in locks_free_lock()
339 kmem_cache_free(filelock_cache, fl); in locks_free_lock()
346 struct file_lock *fl; in locks_dispose_list() local
349 fl = list_first_entry(dispose, struct file_lock, fl_list); in locks_dispose_list()
350 list_del_init(&fl->fl_list); in locks_dispose_list()
351 locks_free_lock(fl); in locks_dispose_list()
355 void locks_init_lock(struct file_lock *fl) in locks_init_lock() argument
357 memset(fl, 0, sizeof(struct file_lock)); in locks_init_lock()
358 locks_init_lock_heads(fl); in locks_init_lock()
366 void locks_copy_conflock(struct file_lock *new, struct file_lock *fl) in locks_copy_conflock() argument
368 new->fl_owner = fl->fl_owner; in locks_copy_conflock()
369 new->fl_pid = fl->fl_pid; in locks_copy_conflock()
371 new->fl_flags = fl->fl_flags; in locks_copy_conflock()
372 new->fl_type = fl->fl_type; in locks_copy_conflock()
373 new->fl_start = fl->fl_start; in locks_copy_conflock()
374 new->fl_end = fl->fl_end; in locks_copy_conflock()
375 new->fl_lmops = fl->fl_lmops; in locks_copy_conflock()
378 if (fl->fl_lmops) { in locks_copy_conflock()
379 if (fl->fl_lmops->lm_get_owner) in locks_copy_conflock()
380 fl->fl_lmops->lm_get_owner(fl->fl_owner); in locks_copy_conflock()
385 void locks_copy_lock(struct file_lock *new, struct file_lock *fl) in locks_copy_lock() argument
390 locks_copy_conflock(new, fl); in locks_copy_lock()
392 new->fl_file = fl->fl_file; in locks_copy_lock()
393 new->fl_ops = fl->fl_ops; in locks_copy_lock()
395 if (fl->fl_ops) { in locks_copy_lock()
396 if (fl->fl_ops->fl_copy_lock) in locks_copy_lock()
397 fl->fl_ops->fl_copy_lock(new, fl); in locks_copy_lock()
421 struct file_lock *fl; in flock_make_lock() local
427 fl = locks_alloc_lock(); in flock_make_lock()
428 if (fl == NULL) in flock_make_lock()
431 fl->fl_file = filp; in flock_make_lock()
432 fl->fl_owner = filp; in flock_make_lock()
433 fl->fl_pid = current->tgid; in flock_make_lock()
434 fl->fl_flags = FL_FLOCK; in flock_make_lock()
435 fl->fl_type = type; in flock_make_lock()
436 fl->fl_end = OFFSET_MAX; in flock_make_lock()
438 return fl; in flock_make_lock()
441 static int assign_type(struct file_lock *fl, long type) in assign_type() argument
447 fl->fl_type = type; in assign_type()
455 static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl, in flock64_to_posix_lock() argument
460 fl->fl_start = 0; in flock64_to_posix_lock()
463 fl->fl_start = filp->f_pos; in flock64_to_posix_lock()
466 fl->fl_start = i_size_read(file_inode(filp)); in flock64_to_posix_lock()
471 if (l->l_start > OFFSET_MAX - fl->fl_start) in flock64_to_posix_lock()
473 fl->fl_start += l->l_start; in flock64_to_posix_lock()
474 if (fl->fl_start < 0) in flock64_to_posix_lock()
480 if (l->l_len - 1 > OFFSET_MAX - fl->fl_start) in flock64_to_posix_lock()
482 fl->fl_end = fl->fl_start + l->l_len - 1; in flock64_to_posix_lock()
485 if (fl->fl_start + l->l_len < 0) in flock64_to_posix_lock()
487 fl->fl_end = fl->fl_start - 1; in flock64_to_posix_lock()
488 fl->fl_start += l->l_len; in flock64_to_posix_lock()
490 fl->fl_end = OFFSET_MAX; in flock64_to_posix_lock()
492 fl->fl_owner = current->files; in flock64_to_posix_lock()
493 fl->fl_pid = current->tgid; in flock64_to_posix_lock()
494 fl->fl_file = filp; in flock64_to_posix_lock()
495 fl->fl_flags = FL_POSIX; in flock64_to_posix_lock()
496 fl->fl_ops = NULL; in flock64_to_posix_lock()
497 fl->fl_lmops = NULL; in flock64_to_posix_lock()
499 return assign_type(fl, l->l_type); in flock64_to_posix_lock()
505 static int flock_to_posix_lock(struct file *filp, struct file_lock *fl, in flock_to_posix_lock() argument
515 return flock64_to_posix_lock(filp, fl, &ll); in flock_to_posix_lock()
520 lease_break_callback(struct file_lock *fl) in lease_break_callback() argument
522 kill_fasync(&fl->fl_fasync, SIGIO, POLL_MSG); in lease_break_callback()
527 lease_setup(struct file_lock *fl, void **priv) in lease_setup() argument
529 struct file *filp = fl->fl_file; in lease_setup()
537 if (!fasync_insert_entry(fa->fa_fd, filp, &fl->fl_fasync, fa)) in lease_setup()
552 static int lease_init(struct file *filp, long type, struct file_lock *fl) in lease_init() argument
554 if (assign_type(fl, type) != 0) in lease_init()
557 fl->fl_owner = filp; in lease_init()
558 fl->fl_pid = current->tgid; in lease_init()
560 fl->fl_file = filp; in lease_init()
561 fl->fl_flags = FL_LEASE; in lease_init()
562 fl->fl_start = 0; in lease_init()
563 fl->fl_end = OFFSET_MAX; in lease_init()
564 fl->fl_ops = NULL; in lease_init()
565 fl->fl_lmops = &lease_manager_ops; in lease_init()
572 struct file_lock *fl = locks_alloc_lock(); in lease_alloc() local
575 if (fl == NULL) in lease_alloc()
578 error = lease_init(filp, type, fl); in lease_alloc()
580 locks_free_lock(fl); in lease_alloc()
583 return fl; in lease_alloc()
606 static void locks_insert_global_locks(struct file_lock *fl) in locks_insert_global_locks() argument
613 fl->fl_link_cpu = smp_processor_id(); in locks_insert_global_locks()
614 hlist_add_head(&fl->fl_link, &fll->hlist); in locks_insert_global_locks()
619 static void locks_delete_global_locks(struct file_lock *fl) in locks_delete_global_locks() argument
630 if (hlist_unhashed(&fl->fl_link)) in locks_delete_global_locks()
633 fll = per_cpu_ptr(&file_lock_list, fl->fl_link_cpu); in locks_delete_global_locks()
635 hlist_del_init(&fl->fl_link); in locks_delete_global_locks()
640 posix_owner_key(struct file_lock *fl) in posix_owner_key() argument
642 if (fl->fl_lmops && fl->fl_lmops->lm_owner_key) in posix_owner_key()
643 return fl->fl_lmops->lm_owner_key(fl); in posix_owner_key()
644 return (unsigned long)fl->fl_owner; in posix_owner_key()
742 locks_insert_lock_ctx(struct file_lock *fl, struct list_head *before) in locks_insert_lock_ctx() argument
744 list_add_tail(&fl->fl_list, before); in locks_insert_lock_ctx()
745 locks_insert_global_locks(fl); in locks_insert_lock_ctx()
749 locks_unlink_lock_ctx(struct file_lock *fl) in locks_unlink_lock_ctx() argument
751 locks_delete_global_locks(fl); in locks_unlink_lock_ctx()
752 list_del_init(&fl->fl_list); in locks_unlink_lock_ctx()
753 locks_wake_up_blocks(fl); in locks_unlink_lock_ctx()
757 locks_delete_lock_ctx(struct file_lock *fl, struct list_head *dispose) in locks_delete_lock_ctx() argument
759 locks_unlink_lock_ctx(fl); in locks_delete_lock_ctx()
761 list_add(&fl->fl_list, dispose); in locks_delete_lock_ctx()
763 locks_free_lock(fl); in locks_delete_lock_ctx()
813 posix_test_lock(struct file *filp, struct file_lock *fl) in posix_test_lock() argument
821 fl->fl_type = F_UNLCK; in posix_test_lock()
827 if (posix_locks_conflict(fl, cfl)) { in posix_test_lock()
828 locks_copy_conflock(fl, cfl); in posix_test_lock()
832 fl->fl_type = F_UNLCK; in posix_test_lock()
877 struct file_lock *fl; in what_owner_is_waiting_for() local
879 hash_for_each_possible(blocked_hash, fl, fl_link, posix_owner_key(block_fl)) { in what_owner_is_waiting_for()
880 if (posix_same_owner(fl, block_fl)) in what_owner_is_waiting_for()
881 return fl->fl_next; in what_owner_is_waiting_for()
920 struct file_lock *fl; in flock_lock_inode() local
944 list_for_each_entry(fl, &ctx->flc_flock, fl_list) { in flock_lock_inode()
945 if (request->fl_file != fl->fl_file) in flock_lock_inode()
947 if (request->fl_type == fl->fl_type) in flock_lock_inode()
950 locks_delete_lock_ctx(fl, &dispose); in flock_lock_inode()
961 list_for_each_entry(fl, &ctx->flc_flock, fl_list) { in flock_lock_inode()
962 if (!flock_locks_conflict(request, fl)) in flock_lock_inode()
968 locks_insert_block(fl, request); in flock_lock_inode()
991 struct file_lock *fl, *tmp; in posix_lock_inode() local
1026 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1027 if (!posix_locks_conflict(request, fl)) in posix_lock_inode()
1030 locks_copy_conflock(conflock, fl); in posix_lock_inode()
1040 if (likely(!posix_locks_deadlock(request, fl))) { in posix_lock_inode()
1042 __locks_insert_block(fl, request); in posix_lock_inode()
1055 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1056 if (posix_same_owner(request, fl)) in posix_lock_inode()
1061 list_for_each_entry_safe_from(fl, tmp, &ctx->flc_posix, fl_list) { in posix_lock_inode()
1062 if (!posix_same_owner(request, fl)) in posix_lock_inode()
1066 if (request->fl_type == fl->fl_type) { in posix_lock_inode()
1071 if (fl->fl_end < request->fl_start - 1) in posix_lock_inode()
1076 if (fl->fl_start - 1 > request->fl_end) in posix_lock_inode()
1084 if (fl->fl_start > request->fl_start) in posix_lock_inode()
1085 fl->fl_start = request->fl_start; in posix_lock_inode()
1087 request->fl_start = fl->fl_start; in posix_lock_inode()
1088 if (fl->fl_end < request->fl_end) in posix_lock_inode()
1089 fl->fl_end = request->fl_end; in posix_lock_inode()
1091 request->fl_end = fl->fl_end; in posix_lock_inode()
1093 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1096 request = fl; in posix_lock_inode()
1102 if (fl->fl_end < request->fl_start) in posix_lock_inode()
1104 if (fl->fl_start > request->fl_end) in posix_lock_inode()
1108 if (fl->fl_start < request->fl_start) in posix_lock_inode()
1109 left = fl; in posix_lock_inode()
1113 if (fl->fl_end > request->fl_end) { in posix_lock_inode()
1114 right = fl; in posix_lock_inode()
1117 if (fl->fl_start >= request->fl_start) { in posix_lock_inode()
1122 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1138 locks_insert_lock_ctx(request, &fl->fl_list); in posix_lock_inode()
1139 locks_delete_lock_ctx(fl, &dispose); in posix_lock_inode()
1167 locks_insert_lock_ctx(new_fl, &fl->fl_list); in posix_lock_inode()
1168 fl = new_fl; in posix_lock_inode()
1179 locks_insert_lock_ctx(left, &fl->fl_list); in posix_lock_inode()
1218 int posix_lock_file(struct file *filp, struct file_lock *fl, in posix_lock_file() argument
1221 return posix_lock_inode(locks_inode(filp), fl, conflock); in posix_lock_file()
1232 static int posix_lock_inode_wait(struct inode *inode, struct file_lock *fl) in posix_lock_inode_wait() argument
1237 error = posix_lock_inode(inode, fl, NULL); in posix_lock_inode_wait()
1240 error = wait_event_interruptible(fl->fl_wait, !fl->fl_next); in posix_lock_inode_wait()
1244 locks_delete_block(fl); in posix_lock_inode_wait()
1263 struct file_lock *fl; in locks_mandatory_locked() local
1274 list_for_each_entry(fl, &ctx->flc_posix, fl_list) { in locks_mandatory_locked()
1275 if (fl->fl_owner != current->files && in locks_mandatory_locked()
1276 fl->fl_owner != file) { in locks_mandatory_locked()
1298 struct file_lock fl; in locks_mandatory_area() local
1302 locks_init_lock(&fl); in locks_mandatory_area()
1303 fl.fl_pid = current->tgid; in locks_mandatory_area()
1304 fl.fl_file = filp; in locks_mandatory_area()
1305 fl.fl_flags = FL_POSIX | FL_ACCESS; in locks_mandatory_area()
1308 fl.fl_type = type; in locks_mandatory_area()
1309 fl.fl_start = start; in locks_mandatory_area()
1310 fl.fl_end = end; in locks_mandatory_area()
1314 fl.fl_owner = filp; in locks_mandatory_area()
1315 fl.fl_flags &= ~FL_SLEEP; in locks_mandatory_area()
1316 error = posix_lock_inode(inode, &fl, NULL); in locks_mandatory_area()
1322 fl.fl_flags |= FL_SLEEP; in locks_mandatory_area()
1323 fl.fl_owner = current->files; in locks_mandatory_area()
1324 error = posix_lock_inode(inode, &fl, NULL); in locks_mandatory_area()
1327 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next); in locks_mandatory_area()
1337 locks_delete_block(&fl); in locks_mandatory_area()
1347 static void lease_clear_pending(struct file_lock *fl, int arg) in lease_clear_pending() argument
1351 fl->fl_flags &= ~FL_UNLOCK_PENDING; in lease_clear_pending()
1354 fl->fl_flags &= ~FL_DOWNGRADE_PENDING; in lease_clear_pending()
1359 int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose) in lease_modify() argument
1361 int error = assign_type(fl, arg); in lease_modify()
1365 lease_clear_pending(fl, arg); in lease_modify()
1366 locks_wake_up_blocks(fl); in lease_modify()
1368 struct file *filp = fl->fl_file; in lease_modify()
1372 fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync); in lease_modify()
1373 if (fl->fl_fasync != NULL) { in lease_modify()
1374 printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync); in lease_modify()
1375 fl->fl_fasync = NULL; in lease_modify()
1377 locks_delete_lock_ctx(fl, dispose); in lease_modify()
1394 struct file_lock *fl, *tmp; in time_out_leases() local
1398 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) { in time_out_leases()
1399 trace_time_out_leases(inode, fl); in time_out_leases()
1400 if (past_time(fl->fl_downgrade_time)) in time_out_leases()
1401 lease_modify(fl, F_RDLCK, dispose); in time_out_leases()
1402 if (past_time(fl->fl_break_time)) in time_out_leases()
1403 lease_modify(fl, F_UNLCK, dispose); in time_out_leases()
1420 struct file_lock *fl; in any_leases_conflict() local
1424 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in any_leases_conflict()
1425 if (leases_conflict(fl, breaker)) in any_leases_conflict()
1448 struct file_lock *new_fl, *fl, *tmp; in __break_lease() local
1480 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) { in __break_lease()
1481 if (!leases_conflict(fl, new_fl)) in __break_lease()
1484 if (fl->fl_flags & FL_UNLOCK_PENDING) in __break_lease()
1486 fl->fl_flags |= FL_UNLOCK_PENDING; in __break_lease()
1487 fl->fl_break_time = break_time; in __break_lease()
1489 if (lease_breaking(fl)) in __break_lease()
1491 fl->fl_flags |= FL_DOWNGRADE_PENDING; in __break_lease()
1492 fl->fl_downgrade_time = break_time; in __break_lease()
1494 if (fl->fl_lmops->lm_break(fl)) in __break_lease()
1495 locks_delete_lock_ctx(fl, &dispose); in __break_lease()
1508 fl = list_first_entry(&ctx->flc_lease, struct file_lock, fl_list); in __break_lease()
1509 break_time = fl->fl_break_time; in __break_lease()
1514 locks_insert_block(fl, new_fl); in __break_lease()
1561 struct file_lock *fl; in lease_get_mtime() local
1566 fl = list_first_entry_or_null(&ctx->flc_lease, in lease_get_mtime()
1568 if (fl && (fl->fl_type == F_WRLCK)) in lease_get_mtime()
1604 struct file_lock *fl; in fcntl_getlease() local
1615 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in fcntl_getlease()
1616 if (fl->fl_file != filp) in fcntl_getlease()
1618 type = target_leasetype(fl); in fcntl_getlease()
1662 struct file_lock *fl, *my_fl = NULL, *lease; in generic_add_lease() local
1712 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in generic_add_lease()
1713 if (fl->fl_file == filp && in generic_add_lease()
1714 fl->fl_owner == lease->fl_owner) { in generic_add_lease()
1715 my_fl = fl; in generic_add_lease()
1729 if (fl->fl_flags & FL_UNLOCK_PENDING) in generic_add_lease()
1779 struct file_lock *fl, *victim = NULL; in generic_delete_lease() local
1792 list_for_each_entry(fl, &ctx->flc_lease, fl_list) { in generic_delete_lease()
1793 if (fl->fl_file == filp && in generic_delete_lease()
1794 fl->fl_owner == owner) { in generic_delete_lease()
1795 victim = fl; in generic_delete_lease()
1801 error = fl->fl_lmops->lm_change(victim, F_UNLCK, &dispose); in generic_delete_lease()
1879 struct file_lock *fl; in do_fcntl_add_lease() local
1883 fl = lease_alloc(filp, arg); in do_fcntl_add_lease()
1884 if (IS_ERR(fl)) in do_fcntl_add_lease()
1885 return PTR_ERR(fl); in do_fcntl_add_lease()
1889 locks_free_lock(fl); in do_fcntl_add_lease()
1894 error = vfs_setlease(filp, arg, &fl, (void **)&new); in do_fcntl_add_lease()
1895 if (fl) in do_fcntl_add_lease()
1896 locks_free_lock(fl); in do_fcntl_add_lease()
1926 static int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl) in flock_lock_inode_wait() argument
1931 error = flock_lock_inode(inode, fl); in flock_lock_inode_wait()
1934 error = wait_event_interruptible(fl->fl_wait, !fl->fl_next); in flock_lock_inode_wait()
1938 locks_delete_block(fl); in flock_lock_inode_wait()
1951 int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl) in locks_lock_inode_wait() argument
1954 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { in locks_lock_inode_wait()
1956 res = posix_lock_inode_wait(inode, fl); in locks_lock_inode_wait()
1959 res = flock_lock_inode_wait(inode, fl); in locks_lock_inode_wait()
2041 int vfs_test_lock(struct file *filp, struct file_lock *fl) in vfs_test_lock() argument
2044 return filp->f_op->lock(filp, F_GETLK, fl); in vfs_test_lock()
2045 posix_test_lock(filp, fl); in vfs_test_lock()
2057 static pid_t locks_translate_pid(struct file_lock *fl, struct pid_namespace *ns) in locks_translate_pid() argument
2062 if (IS_OFDLCK(fl)) in locks_translate_pid()
2064 if (IS_REMOTELCK(fl)) in locks_translate_pid()
2065 return fl->fl_pid; in locks_translate_pid()
2072 return (pid_t)fl->fl_pid; in locks_translate_pid()
2075 pid = find_pid_ns(fl->fl_pid, &init_pid_ns); in locks_translate_pid()
2081 static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl) in posix_lock_to_flock() argument
2083 flock->l_pid = locks_translate_pid(fl, task_active_pid_ns(current)); in posix_lock_to_flock()
2089 if (fl->fl_start > OFFT_OFFSET_MAX) in posix_lock_to_flock()
2091 if (fl->fl_end != OFFSET_MAX && fl->fl_end > OFFT_OFFSET_MAX) in posix_lock_to_flock()
2094 flock->l_start = fl->fl_start; in posix_lock_to_flock()
2095 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 : in posix_lock_to_flock()
2096 fl->fl_end - fl->fl_start + 1; in posix_lock_to_flock()
2098 flock->l_type = fl->fl_type; in posix_lock_to_flock()
2103 static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl) in posix_lock_to_flock64() argument
2105 flock->l_pid = locks_translate_pid(fl, task_active_pid_ns(current)); in posix_lock_to_flock64()
2106 flock->l_start = fl->fl_start; in posix_lock_to_flock64()
2107 flock->l_len = fl->fl_end == OFFSET_MAX ? 0 : in posix_lock_to_flock64()
2108 fl->fl_end - fl->fl_start + 1; in posix_lock_to_flock64()
2110 flock->l_type = fl->fl_type; in posix_lock_to_flock64()
2119 struct file_lock *fl; in fcntl_getlk() local
2122 fl = locks_alloc_lock(); in fcntl_getlk()
2123 if (fl == NULL) in fcntl_getlk()
2129 error = flock_to_posix_lock(filp, fl, flock); in fcntl_getlk()
2139 fl->fl_flags |= FL_OFDLCK; in fcntl_getlk()
2140 fl->fl_owner = filp; in fcntl_getlk()
2143 error = vfs_test_lock(filp, fl); in fcntl_getlk()
2147 flock->l_type = fl->fl_type; in fcntl_getlk()
2148 if (fl->fl_type != F_UNLCK) { in fcntl_getlk()
2149 error = posix_lock_to_flock(flock, fl); in fcntl_getlk()
2154 locks_free_lock(fl); in fcntl_getlk()
2191 int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, struct file_lock *conf) in vfs_lock_file() argument
2194 return filp->f_op->lock(filp, cmd, fl); in vfs_lock_file()
2196 return posix_lock_file(filp, fl, conf); in vfs_lock_file()
2201 struct file_lock *fl) in do_lock_file_wait() argument
2205 error = security_file_lock(filp, fl->fl_type); in do_lock_file_wait()
2210 error = vfs_lock_file(filp, cmd, fl, NULL); in do_lock_file_wait()
2213 error = wait_event_interruptible(fl->fl_wait, !fl->fl_next); in do_lock_file_wait()
2217 locks_delete_block(fl); in do_lock_file_wait()
2226 check_fmode_for_setlk(struct file_lock *fl) in check_fmode_for_setlk() argument
2228 switch (fl->fl_type) { in check_fmode_for_setlk()
2230 if (!(fl->fl_file->f_mode & FMODE_READ)) in check_fmode_for_setlk()
2234 if (!(fl->fl_file->f_mode & FMODE_WRITE)) in check_fmode_for_setlk()
2333 struct file_lock *fl; in fcntl_getlk64() local
2336 fl = locks_alloc_lock(); in fcntl_getlk64()
2337 if (fl == NULL) in fcntl_getlk64()
2344 error = flock64_to_posix_lock(filp, fl, flock); in fcntl_getlk64()
2354 fl->fl_flags |= FL_OFDLCK; in fcntl_getlk64()
2355 fl->fl_owner = filp; in fcntl_getlk64()
2358 error = vfs_test_lock(filp, fl); in fcntl_getlk64()
2362 flock->l_type = fl->fl_type; in fcntl_getlk64()
2363 if (fl->fl_type != F_UNLCK) in fcntl_getlk64()
2364 posix_lock_to_flock64(flock, fl); in fcntl_getlk64()
2367 locks_free_lock(fl); in fcntl_getlk64()
2502 struct file_lock fl = { in locks_remove_flock() local
2516 filp->f_op->flock(filp, F_SETLKW, &fl); in locks_remove_flock()
2518 flock_lock_inode(inode, &fl); in locks_remove_flock()
2520 if (fl.fl_ops && fl.fl_ops->fl_release_private) in locks_remove_flock()
2521 fl.fl_ops->fl_release_private(&fl); in locks_remove_flock()
2528 struct file_lock *fl, *tmp; in locks_remove_lease() local
2536 list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) in locks_remove_lease()
2537 if (filp == fl->fl_file) in locks_remove_lease()
2538 lease_modify(fl, F_UNLCK, &dispose); in locks_remove_lease()
2600 int vfs_cancel_lock(struct file *filp, struct file_lock *fl) in vfs_cancel_lock() argument
2603 return filp->f_op->lock(filp, F_CANCELLK, fl); in vfs_cancel_lock()
2618 static void lock_get_status(struct seq_file *f, struct file_lock *fl, in lock_get_status() argument
2625 fl_pid = locks_translate_pid(fl, proc_pidns); in lock_get_status()
2632 if (fl->fl_file != NULL) in lock_get_status()
2633 inode = locks_inode(fl->fl_file); in lock_get_status()
2636 if (IS_POSIX(fl)) { in lock_get_status()
2637 if (fl->fl_flags & FL_ACCESS) in lock_get_status()
2639 else if (IS_OFDLCK(fl)) in lock_get_status()
2647 } else if (IS_FLOCK(fl)) { in lock_get_status()
2648 if (fl->fl_type & LOCK_MAND) { in lock_get_status()
2653 } else if (IS_LEASE(fl)) { in lock_get_status()
2654 if (fl->fl_flags & FL_DELEG) in lock_get_status()
2659 if (lease_breaking(fl)) in lock_get_status()
2661 else if (fl->fl_file) in lock_get_status()
2668 if (fl->fl_type & LOCK_MAND) { in lock_get_status()
2670 (fl->fl_type & LOCK_READ) in lock_get_status()
2671 ? (fl->fl_type & LOCK_WRITE) ? "RW " : "READ " in lock_get_status()
2672 : (fl->fl_type & LOCK_WRITE) ? "WRITE" : "NONE "); in lock_get_status()
2675 (lease_breaking(fl)) in lock_get_status()
2676 ? (fl->fl_type == F_UNLCK) ? "UNLCK" : "READ " in lock_get_status()
2677 : (fl->fl_type == F_WRLCK) ? "WRITE" : "READ "); in lock_get_status()
2687 if (IS_POSIX(fl)) { in lock_get_status()
2688 if (fl->fl_end == OFFSET_MAX) in lock_get_status()
2689 seq_printf(f, "%Ld EOF\n", fl->fl_start); in lock_get_status()
2691 seq_printf(f, "%Ld %Ld\n", fl->fl_start, fl->fl_end); in lock_get_status()
2700 struct file_lock *fl, *bfl; in locks_show() local
2703 fl = hlist_entry(v, struct file_lock, fl_link); in locks_show()
2705 if (locks_translate_pid(fl, proc_pidns) == 0) in locks_show()
2708 lock_get_status(f, fl, iter->li_pos, ""); in locks_show()
2710 list_for_each_entry(bfl, &fl->fl_block, fl_block) in locks_show()
2720 struct file_lock *fl; in __show_fd_locks() local
2722 list_for_each_entry(fl, head, fl_list) { in __show_fd_locks()
2724 if (filp != fl->fl_file) in __show_fd_locks()
2726 if (fl->fl_owner != files && in __show_fd_locks()
2727 fl->fl_owner != filp) in __show_fd_locks()
2732 lock_get_status(f, fl, *id, ""); in __show_fd_locks()